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