Shaka Packager SDK
mpd_notifier_util.cc
1 // Copyright 2015 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #include "packager/mpd/base/mpd_notifier_util.h"
8 
9 #include "packager/base/strings/string_number_conversions.h"
10 #include "packager/base/strings/string_util.h"
11 #include "packager/file/file.h"
12 #include "packager/mpd/base/mpd_utils.h"
13 
14 namespace shaka {
15 
16 bool WriteMpdToFile(const std::string& output_path, MpdBuilder* mpd_builder) {
17  CHECK(!output_path.empty());
18 
19  std::string mpd;
20  if (!mpd_builder->ToString(&mpd)) {
21  LOG(ERROR) << "Failed to write MPD to string.";
22  return false;
23  }
24 
25  if (!File::WriteFileAtomically(output_path.c_str(), mpd)) {
26  LOG(ERROR) << "Failed to write mpd to: " << output_path;
27  return false;
28  }
29  return true;
30 }
31 
32 ContentType GetContentType(const MediaInfo& media_info) {
33  const bool has_video = media_info.has_video_info();
34  const bool has_audio = media_info.has_audio_info();
35  const bool has_text = media_info.has_text_info();
36 
37  if (MoreThanOneTrue(has_video, has_audio, has_text)) {
38  NOTIMPLEMENTED() << "MediaInfo with more than one stream is not supported.";
39  return kContentTypeUnknown;
40  }
41  if (!AtLeastOneTrue(has_video, has_audio, has_text)) {
42  LOG(ERROR) << "MediaInfo should contain one audio, video, or text stream.";
43  return kContentTypeUnknown;
44  }
45  return has_video ? kContentTypeVideo
46  : (has_audio ? kContentTypeAudio : kContentTypeText);
47 }
48 
49 std::string Uint8VectorToBase64(const std::vector<uint8_t>& input) {
50  std::string output;
51  std::string input_in_string(input.begin(), input.end());
52  base::Base64Encode(input_in_string, &output);
53  return output;
54 }
55 
56 } // namespace shaka
This class generates DASH MPDs (Media Presentation Descriptions).
Definition: mpd_builder.h:38
All the methods that are virtual are virtual for mocking.
std::string Uint8VectorToBase64(const std::vector< uint8_t > &input)
Converts uint8 vector into base64 encoded string.
virtual bool ToString(std::string *output)
Definition: mpd_builder.cc:139
static bool WriteFileAtomically(const char *file_name, const std::string &contents)
Definition: file.cc:262
ContentType GetContentType(const MediaInfo &media_info)
bool WriteMpdToFile(const std::string &output_path, MpdBuilder *mpd_builder)