7 #include "packager/mpd/util/mpd_writer.h"
9 #include <gflags/gflags.h>
10 #include <google/protobuf/text_format.h>
13 #include "packager/base/files/file_path.h"
14 #include "packager/base/files/file_util.h"
15 #include "packager/file/file.h"
16 #include "packager/mpd/base/mpd_builder.h"
17 #include "packager/mpd/base/mpd_notifier.h"
18 #include "packager/mpd/base/mpd_utils.h"
19 #include "packager/mpd/base/simple_mpd_notifier.h"
21 DEFINE_bool(generate_dash_if_iop_compliant_mpd,
23 "Try to generate DASH-IF IOP compliant MPD. This is best effort "
24 "and does not guarantee compliance.");
31 class SimpleMpdNotifierFactory :
public MpdNotifierFactory {
33 SimpleMpdNotifierFactory() {}
34 ~SimpleMpdNotifierFactory()
override {}
36 std::unique_ptr<MpdNotifier> Create(
const MpdOptions& mpd_options)
override {
37 return std::unique_ptr<MpdNotifier>(
new SimpleMpdNotifier(mpd_options));
43 MpdWriter::MpdWriter() : notifier_factory_(new SimpleMpdNotifierFactory()) {}
44 MpdWriter::~MpdWriter() {}
46 bool MpdWriter::AddFile(
const std::string& media_info_path) {
47 std::string file_content;
49 LOG(ERROR) <<
"Failed to read " << media_info_path <<
" to string.";
54 if (!::google::protobuf::TextFormat::ParseFromString(file_content,
56 LOG(ERROR) <<
"Failed to parse " << file_content <<
" to MediaInfo.";
60 media_infos_.push_back(media_info);
64 void MpdWriter::AddBaseUrl(
const std::string& base_url) {
65 base_urls_.push_back(base_url);
68 bool MpdWriter::WriteMpdToFile(
const char* file_name) {
70 MpdOptions mpd_options;
71 mpd_options.mpd_params.base_urls = base_urls_;
72 mpd_options.mpd_params.mpd_output = file_name;
73 mpd_options.mpd_params.generate_dash_if_iop_compliant_mpd =
74 FLAGS_generate_dash_if_iop_compliant_mpd;
75 std::unique_ptr<MpdNotifier> notifier =
76 notifier_factory_->Create(mpd_options);
77 if (!notifier->Init()) {
78 LOG(ERROR) <<
"failed to initialize MpdNotifier.";
82 for (
const MediaInfo& media_info : media_infos_) {
83 uint32_t unused_conatiner_id;
84 if (!notifier->NotifyNewContainer(media_info, &unused_conatiner_id)) {
85 LOG(ERROR) <<
"Failed to add MediaInfo for media file: "
86 << media_info.media_file_name();
91 if (!notifier->Flush()) {
92 LOG(ERROR) <<
"Failed to flush MPD notifier.";
98 void MpdWriter::SetMpdNotifierFactoryForTest(
99 std::unique_ptr<MpdNotifierFactory> factory) {
100 notifier_factory_ = std::move(factory);