7 #include <packager/mpd/util/mpd_writer.h>
11 #include <absl/flags/flag.h>
12 #include <absl/log/check.h>
13 #include <absl/log/log.h>
14 #include <google/protobuf/text_format.h>
16 #include <packager/file.h>
17 #include <packager/mpd/base/mpd_builder.h>
18 #include <packager/mpd/base/mpd_notifier.h>
19 #include <packager/mpd/base/mpd_utils.h>
20 #include <packager/mpd/base/simple_mpd_notifier.h>
23 generate_dash_if_iop_compliant_mpd,
25 "Try to generate DASH-IF IOP compliant MPD. This is best effort "
26 "and does not guarantee compliance.");
33 class SimpleMpdNotifierFactory :
public MpdNotifierFactory {
35 SimpleMpdNotifierFactory() {}
36 ~SimpleMpdNotifierFactory()
override {}
38 std::unique_ptr<MpdNotifier> Create(
const MpdOptions& mpd_options)
override {
39 return std::unique_ptr<MpdNotifier>(
new SimpleMpdNotifier(mpd_options));
45 MpdWriter::MpdWriter() : notifier_factory_(new SimpleMpdNotifierFactory()) {}
46 MpdWriter::~MpdWriter() {}
48 bool MpdWriter::AddFile(
const std::string& media_info_path) {
49 std::string file_content;
50 if (!File::ReadFileToString(media_info_path.c_str(), &file_content)) {
51 LOG(ERROR) <<
"Failed to read " << media_info_path <<
" to string.";
56 if (!::google::protobuf::TextFormat::ParseFromString(file_content,
58 LOG(ERROR) <<
"Failed to parse " << file_content <<
" to MediaInfo.";
62 media_infos_.push_back(media_info);
66 void MpdWriter::AddBaseUrl(
const std::string& base_url) {
67 base_urls_.push_back(base_url);
70 bool MpdWriter::WriteMpdToFile(
const char* file_name) {
72 MpdOptions mpd_options;
73 mpd_options.mpd_params.base_urls = base_urls_;
74 mpd_options.mpd_params.mpd_output = file_name;
75 mpd_options.mpd_params.generate_dash_if_iop_compliant_mpd =
76 absl::GetFlag(FLAGS_generate_dash_if_iop_compliant_mpd);
77 std::unique_ptr<MpdNotifier> notifier =
78 notifier_factory_->Create(mpd_options);
79 if (!notifier->Init()) {
80 LOG(ERROR) <<
"failed to initialize MpdNotifier.";
84 for (
const MediaInfo& media_info : media_infos_) {
85 uint32_t unused_conatiner_id;
86 if (!notifier->NotifyNewContainer(media_info, &unused_conatiner_id)) {
87 LOG(ERROR) <<
"Failed to add MediaInfo for media file: "
88 << media_info.media_file_name();
93 if (!notifier->Flush()) {
94 LOG(ERROR) <<
"Failed to flush MPD notifier.";
100 void MpdWriter::SetMpdNotifierFactoryForTest(
101 std::unique_ptr<MpdNotifierFactory> factory) {
102 notifier_factory_ = std::move(factory);
All the methods that are virtual are virtual for mocking.