Shaka Packager SDK
mpd_notifier_util.cc
1 // Copyright 2015 Google LLC. 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 <absl/log/check.h>
10 #include <absl/log/log.h>
11 
12 #include <packager/file.h>
13 #include <packager/macros/logging.h>
14 #include <packager/mpd/base/mpd_utils.h>
15 
16 namespace shaka {
17 
18 bool WriteMpdToFile(const std::string& output_path, MpdBuilder* mpd_builder) {
19  CHECK(!output_path.empty());
20 
21  std::string mpd;
22  if (!mpd_builder->ToString(&mpd)) {
23  LOG(ERROR) << "Failed to write MPD to string.";
24  return false;
25  }
26 
27  if (!File::WriteFileAtomically(output_path.c_str(), mpd)) {
28  LOG(ERROR) << "Failed to write mpd to: " << output_path;
29  return false;
30  }
31  return true;
32 }
33 
34 ContentType GetContentType(const MediaInfo& media_info) {
35  const bool has_video = media_info.has_video_info();
36  const bool has_audio = media_info.has_audio_info();
37  const bool has_text = media_info.has_text_info();
38 
39  if (MoreThanOneTrue(has_video, has_audio, has_text)) {
40  NOTIMPLEMENTED() << "MediaInfo with more than one stream is not supported.";
41  return kContentTypeUnknown;
42  }
43  if (!AtLeastOneTrue(has_video, has_audio, has_text)) {
44  LOG(ERROR) << "MediaInfo should contain one audio, video, or text stream.";
45  return kContentTypeUnknown;
46  }
47  return has_video ? kContentTypeVideo
48  : (has_audio ? kContentTypeAudio : kContentTypeText);
49 }
50 
51 std::string Uint8VectorToBase64(const std::vector<uint8_t>& input) {
52  std::string output;
53  std::string input_in_string(input.begin(), input.end());
54  absl::Base64Escape(input_in_string, &output);
55  return output;
56 }
57 
58 } // namespace shaka
This class generates DASH MPDs (Media Presentation Descriptions).
Definition: mpd_builder.h:37
virtual bool ToString(std::string *output)
Definition: mpd_builder.cc:147
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66
std::string Uint8VectorToBase64(const std::vector< uint8_t > &input)
Converts uint8 vector into base64 encoded string.
ContentType GetContentType(const MediaInfo &media_info)
bool WriteMpdToFile(const std::string &output_path, MpdBuilder *mpd_builder)