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 IOPv3 compliant MPD. This is best effort " 24 "and does not guarantee compliance. Off by default until players " 32 class SimpleMpdNotifierFactory :
public MpdNotifierFactory {
34 SimpleMpdNotifierFactory() {}
35 ~SimpleMpdNotifierFactory()
override {}
37 std::unique_ptr<MpdNotifier> Create(
const MpdOptions& mpd_options)
override {
38 return std::unique_ptr<MpdNotifier>(
new SimpleMpdNotifier(mpd_options));
44 MpdWriter::MpdWriter() : notifier_factory_(new SimpleMpdNotifierFactory()) {}
45 MpdWriter::~MpdWriter() {}
47 bool MpdWriter::AddFile(
const std::string& media_info_path) {
48 std::string file_content;
50 LOG(ERROR) <<
"Failed to read " << media_info_path <<
" to string.";
55 if (!::google::protobuf::TextFormat::ParseFromString(file_content,
57 LOG(ERROR) <<
"Failed to parse " << file_content <<
" to MediaInfo.";
61 media_infos_.push_back(media_info);
65 void MpdWriter::AddBaseUrl(
const std::string& base_url) {
66 base_urls_.push_back(base_url);
69 bool MpdWriter::WriteMpdToFile(
const char* file_name) {
71 MpdOptions mpd_options;
72 mpd_options.mpd_params.base_urls = base_urls_;
73 mpd_options.mpd_params.mpd_output = file_name;
74 mpd_options.mpd_params.generate_dash_if_iop_compliant_mpd =
75 FLAGS_generate_dash_if_iop_compliant_mpd;
76 std::unique_ptr<MpdNotifier> notifier =
77 notifier_factory_->Create(mpd_options);
78 if (!notifier->Init()) {
79 LOG(ERROR) <<
"failed to initialize MpdNotifier.";
83 for (
const MediaInfo& media_info : media_infos_) {
84 uint32_t unused_conatiner_id;
85 if (!notifier->NotifyNewContainer(media_info, &unused_conatiner_id)) {
86 LOG(ERROR) <<
"Failed to add MediaInfo for media file: " 87 << media_info.media_file_name();
92 if (!notifier->Flush()) {
93 LOG(ERROR) <<
"Failed to flush MPD notifier.";
99 void MpdWriter::SetMpdNotifierFactoryForTest(
100 std::unique_ptr<MpdNotifierFactory> factory) {
101 notifier_factory_ = std::move(factory);
static bool ReadFileToString(const char *file_name, std::string *contents)
All the methods that are virtual are virtual for mocking.