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 "
33 class DashIopMpdNotifierFactory :
public MpdNotifierFactory {
35 DashIopMpdNotifierFactory() {}
36 ~DashIopMpdNotifierFactory()
override {}
38 scoped_ptr<MpdNotifier> Create(DashProfile dash_profile,
39 const MpdOptions& mpd_options,
40 const std::vector<std::string>& base_urls,
41 const std::string& output_path)
override {
42 return scoped_ptr<MpdNotifier>(
new DashIopMpdNotifier(
43 dash_profile, mpd_options, base_urls, output_path));
48 class SimpleMpdNotifierFactory :
public MpdNotifierFactory {
50 SimpleMpdNotifierFactory() {}
51 ~SimpleMpdNotifierFactory()
override {}
53 scoped_ptr<MpdNotifier> Create(DashProfile dash_profile,
54 const MpdOptions& mpd_options,
55 const std::vector<std::string>& base_urls,
56 const std::string& output_path)
override {
57 return scoped_ptr<MpdNotifier>(
new SimpleMpdNotifier(
58 dash_profile, mpd_options, base_urls, output_path));
64 MpdWriter::MpdWriter()
65 : notifier_factory_(FLAGS_generate_dash_if_iop_compliant_mpd
66 ? static_cast<MpdNotifierFactory*>(
67 new DashIopMpdNotifierFactory())
68 : static_cast<MpdNotifierFactory*>(
69 new SimpleMpdNotifierFactory())) {}
70 MpdWriter::~MpdWriter() {}
72 bool MpdWriter::AddFile(
const std::string& media_info_path,
73 const std::string& mpd_path) {
74 std::string file_content;
77 LOG(ERROR) <<
"Failed to read " << media_info_path <<
" to string.";
82 if (!::google::protobuf::TextFormat::ParseFromString(file_content,
84 LOG(ERROR) <<
"Failed to parse " << file_content <<
" to MediaInfo.";
89 media_infos_.push_back(media_info);
93 void MpdWriter::AddBaseUrl(
const std::string& base_url) {
94 base_urls_.push_back(base_url);
97 bool MpdWriter::WriteMpdToFile(
const char* file_name) {
99 scoped_ptr<MpdNotifier> notifier = notifier_factory_->Create(
100 kOnDemandProfile, MpdOptions(), base_urls_, file_name);
101 if (!notifier->Init()) {
102 LOG(ERROR) <<
"failed to initialize MpdNotifier.";
106 for (std::list<MediaInfo>::const_iterator it = media_infos_.begin();
107 it != media_infos_.end();
109 uint32_t unused_conatiner_id;
110 if (!notifier->NotifyNewContainer(*it, &unused_conatiner_id)) {
111 LOG(ERROR) <<
"Failed to add MediaInfo for media file: "
112 << it->media_file_name();
117 if (!notifier->Flush()) {
118 LOG(ERROR) <<
"Failed to flush MPD notifier.";
124 void MpdWriter::SetMpdNotifierFactoryForTest(
125 scoped_ptr<MpdNotifierFactory> factory) {
126 notifier_factory_ = factory.Pass();
static void MakePathsRelativeToMpd(const std::string &mpd_path, MediaInfo *media_info)