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/media/file/file.h"
16 #include "packager/mpd/base/dash_iop_mpd_notifier.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"
22 DEFINE_bool(generate_dash_if_iop_compliant_mpd,
24 "Try to generate DASH-IF IOPv3 compliant MPD. This is best effort "
25 "and does not guarantee compliance. Off by default until players "
30 namespace edash_packager {
35 class DashIopMpdNotifierFactory :
public MpdNotifierFactory {
37 DashIopMpdNotifierFactory() {}
38 ~DashIopMpdNotifierFactory()
override {}
40 scoped_ptr<MpdNotifier> Create(DashProfile dash_profile,
41 const MpdOptions& mpd_options,
42 const std::vector<std::string>& base_urls,
43 const std::string& output_path)
override {
44 return scoped_ptr<MpdNotifier>(
new DashIopMpdNotifier(
45 dash_profile, mpd_options, base_urls, output_path));
50 class SimpleMpdNotifierFactory :
public MpdNotifierFactory {
52 SimpleMpdNotifierFactory() {}
53 ~SimpleMpdNotifierFactory()
override {}
55 scoped_ptr<MpdNotifier> Create(DashProfile dash_profile,
56 const MpdOptions& mpd_options,
57 const std::vector<std::string>& base_urls,
58 const std::string& output_path)
override {
59 return scoped_ptr<MpdNotifier>(
new SimpleMpdNotifier(
60 dash_profile, mpd_options, base_urls, output_path));
66 MpdWriter::MpdWriter()
67 : notifier_factory_(FLAGS_generate_dash_if_iop_compliant_mpd
68 ? static_cast<MpdNotifierFactory*>(
69 new DashIopMpdNotifierFactory())
70 : static_cast<MpdNotifierFactory*>(
71 new SimpleMpdNotifierFactory())) {}
72 MpdWriter::~MpdWriter() {}
74 bool MpdWriter::AddFile(
const std::string& media_info_path,
75 const std::string& mpd_path) {
76 std::string file_content;
79 LOG(ERROR) <<
"Failed to read " << media_info_path <<
" to string.";
84 if (!::google::protobuf::TextFormat::ParseFromString(file_content,
86 LOG(ERROR) <<
"Failed to parse " << file_content <<
" to MediaInfo.";
91 media_infos_.push_back(media_info);
95 void MpdWriter::AddBaseUrl(
const std::string& base_url) {
96 base_urls_.push_back(base_url);
99 bool MpdWriter::WriteMpdToFile(
const char* file_name) {
101 scoped_ptr<MpdNotifier> notifier = notifier_factory_->Create(
102 kOnDemandProfile, MpdOptions(), base_urls_, file_name);
103 if (!notifier->Init()) {
104 LOG(ERROR) <<
"failed to initialize MpdNotifier.";
108 for (std::list<MediaInfo>::const_iterator it = media_infos_.begin();
109 it != media_infos_.end();
111 uint32_t unused_conatiner_id;
112 if (!notifier->NotifyNewContainer(*it, &unused_conatiner_id)) {
113 LOG(ERROR) <<
"Failed to add MediaInfo for media file: "
114 << it->media_file_name();
119 if (!notifier->Flush()) {
120 LOG(ERROR) <<
"Failed to flush MPD notifier.";
126 void MpdWriter::SetMpdNotifierFactoryForTest(
127 scoped_ptr<MpdNotifierFactory> factory) {
128 notifier_factory_ = factory.Pass();
static void MakePathsRelativeToMpd(const std::string &mpd_path, MediaInfo *media_info)