2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2015 Google LLC. All rights reserved.
|
2015-07-22 06:57:21 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/mpd/base/mpd_notifier_util.h>
|
2015-07-22 06:57:21 +00:00
|
|
|
|
2023-10-13 19:42:47 +00:00
|
|
|
#include <absl/log/check.h>
|
|
|
|
#include <absl/log/log.h>
|
2023-10-11 08:49:50 +00:00
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/file/file.h>
|
|
|
|
#include <packager/mpd/base/mpd_utils.h>
|
2015-07-22 06:57:21 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2015-07-22 06:57:21 +00:00
|
|
|
|
|
|
|
bool WriteMpdToFile(const std::string& output_path, MpdBuilder* mpd_builder) {
|
|
|
|
CHECK(!output_path.empty());
|
|
|
|
|
|
|
|
std::string mpd;
|
|
|
|
if (!mpd_builder->ToString(&mpd)) {
|
|
|
|
LOG(ERROR) << "Failed to write MPD to string.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-10 18:26:22 +00:00
|
|
|
if (!File::WriteFileAtomically(output_path.c_str(), mpd)) {
|
2017-06-15 20:00:28 +00:00
|
|
|
LOG(ERROR) << "Failed to write mpd to: " << output_path;
|
2015-07-22 06:57:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-06-15 20:00:28 +00:00
|
|
|
return true;
|
2015-07-22 06:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ContentType GetContentType(const MediaInfo& media_info) {
|
|
|
|
const bool has_video = media_info.has_video_info();
|
|
|
|
const bool has_audio = media_info.has_audio_info();
|
|
|
|
const bool has_text = media_info.has_text_info();
|
|
|
|
|
|
|
|
if (MoreThanOneTrue(has_video, has_audio, has_text)) {
|
|
|
|
NOTIMPLEMENTED() << "MediaInfo with more than one stream is not supported.";
|
|
|
|
return kContentTypeUnknown;
|
|
|
|
}
|
|
|
|
if (!AtLeastOneTrue(has_video, has_audio, has_text)) {
|
|
|
|
LOG(ERROR) << "MediaInfo should contain one audio, video, or text stream.";
|
|
|
|
return kContentTypeUnknown;
|
|
|
|
}
|
|
|
|
return has_video ? kContentTypeVideo
|
|
|
|
: (has_audio ? kContentTypeAudio : kContentTypeText);
|
|
|
|
}
|
|
|
|
|
2015-08-26 20:25:29 +00:00
|
|
|
std::string Uint8VectorToBase64(const std::vector<uint8_t>& input) {
|
|
|
|
std::string output;
|
|
|
|
std::string input_in_string(input.begin(), input.end());
|
2023-08-05 03:45:21 +00:00
|
|
|
absl::Base64Escape(input_in_string, &output);
|
2015-08-26 20:25:29 +00:00
|
|
|
return output;
|
2015-07-22 06:57:21 +00:00
|
|
|
}
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|