7 #include "packager/mpd/util/mpd_writer.h"
9 #include <gflags/gflags.h>
10 #include <google/protobuf/text_format.h>
13 #include "packager/base/file_util.h"
14 #include "packager/base/files/file_path.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 virtual ~DashIopMpdNotifierFactory() OVERRIDE {}
40 virtual scoped_ptr<MpdNotifier> Create(
41 DashProfile dash_profile,
42 const MpdOptions& mpd_options,
43 const std::vector<std::string>& base_urls,
44 const std::string& output_path) OVERRIDE {
45 return scoped_ptr<MpdNotifier>(
new DashIopMpdNotifier(
46 dash_profile, mpd_options, base_urls, output_path));
51 class SimpleMpdNotifierFactory :
public MpdNotifierFactory {
53 SimpleMpdNotifierFactory() {}
54 virtual ~SimpleMpdNotifierFactory() OVERRIDE {}
56 virtual scoped_ptr<MpdNotifier> Create(
57 DashProfile dash_profile,
58 const MpdOptions& mpd_options,
59 const std::vector<std::string>& base_urls,
60 const std::string& output_path) OVERRIDE {
61 return scoped_ptr<MpdNotifier>(
new SimpleMpdNotifier(
62 dash_profile, mpd_options, base_urls, output_path));
68 MpdWriter::MpdWriter()
69 : notifier_factory_(FLAGS_generate_dash_if_iop_compliant_mpd
70 ? static_cast<MpdNotifierFactory*>(
71 new DashIopMpdNotifierFactory())
72 : static_cast<MpdNotifierFactory*>(
73 new SimpleMpdNotifierFactory())) {}
74 MpdWriter::~MpdWriter() {}
76 bool MpdWriter::AddFile(
const std::string& media_info_path,
77 const std::string& mpd_path) {
78 std::string file_content;
81 LOG(ERROR) <<
"Failed to read " << media_info_path <<
" to string.";
86 if (!::google::protobuf::TextFormat::ParseFromString(file_content,
88 LOG(ERROR) <<
"Failed to parse " << file_content <<
" to MediaInfo.";
93 media_infos_.push_back(media_info);
97 void MpdWriter::AddBaseUrl(
const std::string& base_url) {
98 base_urls_.push_back(base_url);
101 bool MpdWriter::WriteMpdToFile(
const char* file_name) {
103 scoped_ptr<MpdNotifier> notifier = notifier_factory_->Create(
104 kOnDemandProfile, MpdOptions(), base_urls_, file_name);
105 if (!notifier->Init()) {
106 LOG(ERROR) <<
"failed to initialize MpdNotifier.";
110 for (std::list<MediaInfo>::const_iterator it = media_infos_.begin();
111 it != media_infos_.end();
113 uint32_t unused_conatiner_id;
114 if (!notifier->NotifyNewContainer(*it, &unused_conatiner_id)) {
115 LOG(ERROR) <<
"Failed to add MediaInfo for media file: "
116 << it->media_file_name();
121 if (!notifier->Flush()) {
122 LOG(ERROR) <<
"Failed to flush MPD notifier.";
128 void MpdWriter::SetMpdNotifierFactoryForTest(
129 scoped_ptr<MpdNotifierFactory> factory) {
130 notifier_factory_ = factory.Pass();
static void MakePathsRelativeToMpd(const std::string &mpd_path, MediaInfo *media_info)