7 #include "packager/mpd/base/simple_mpd_notifier.h" 9 #include "packager/base/logging.h" 10 #include "packager/base/stl_util.h" 11 #include "packager/mpd/base/adaptation_set.h" 12 #include "packager/mpd/base/mpd_builder.h" 13 #include "packager/mpd/base/mpd_notifier_util.h" 14 #include "packager/mpd/base/mpd_utils.h" 15 #include "packager/mpd/base/period.h" 16 #include "packager/mpd/base/representation.h" 20 SimpleMpdNotifier::SimpleMpdNotifier(
const MpdOptions& mpd_options)
21 : MpdNotifier(mpd_options),
22 output_path_(mpd_options.mpd_params.mpd_output),
23 mpd_builder_(new MpdBuilder(mpd_options)),
24 content_protection_in_adaptation_set_(
25 mpd_options.mpd_params.generate_dash_if_iop_compliant_mpd) {
26 for (
const std::string& base_url : mpd_options.mpd_params.base_urls)
27 mpd_builder_->AddBaseUrl(base_url);
30 SimpleMpdNotifier::~SimpleMpdNotifier() {}
37 uint32_t* container_id) {
41 if (content_type == kContentTypeUnknown)
44 MediaInfo adjusted_media_info(media_info);
47 base::AutoLock auto_lock(lock_);
48 const double kPeriodStartTimeSeconds = 0.0;
49 Period* period = mpd_builder_->GetOrCreatePeriod(kPeriodStartTimeSeconds);
52 media_info, content_protection_in_adaptation_set_);
53 DCHECK(adaptation_set);
54 if (!adaptation_set->
has_id())
55 adaptation_set->
set_id(next_adaptation_set_id_++);
61 *container_id = representation->
id();
62 if (content_protection_in_adaptation_set_) {
66 representation_id_to_adaptation_set_[representation->
id()] = adaptation_set;
70 representation_map_[representation->
id()] = representation;
75 uint32_t sample_duration) {
76 base::AutoLock auto_lock(lock_);
77 auto it = representation_map_.find(container_id);
78 if (it == representation_map_.end()) {
79 LOG(ERROR) <<
"Unexpected container_id: " << container_id;
82 it->second->SetSampleDuration(sample_duration);
90 base::AutoLock auto_lock(lock_);
91 auto it = representation_map_.find(container_id);
92 if (it == representation_map_.end()) {
93 LOG(ERROR) <<
"Unexpected container_id: " << container_id;
96 it->second->AddNewSegment(start_time, duration, size);
101 uint64_t timestamp) {
102 base::AutoLock auto_lock(lock_);
103 auto it = representation_map_.find(container_id);
104 if (it == representation_map_.end()) {
105 LOG(ERROR) <<
"Unexpected container_id: " << container_id;
110 representation_id_to_adaptation_set_[container_id];
112 const MediaInfo& media_info = original_representation->
GetMediaInfo();
113 const double period_start_time_seconds =
114 static_cast<double>(timestamp) / media_info.reference_time_scale();
116 Period* period = mpd_builder_->GetOrCreatePeriod(period_start_time_seconds);
119 media_info, content_protection_in_adaptation_set_);
120 DCHECK(adaptation_set);
121 if (!adaptation_set->
has_id()) {
122 adaptation_set->
set_id(original_adaptation_set->id());
124 DCHECK_EQ(adaptation_set->id(), original_adaptation_set->id());
132 if (content_protection_in_adaptation_set_) {
136 representation_id_to_adaptation_set_[representation->id()] = adaptation_set;
140 representation_map_[representation->id()] = representation;
145 uint32_t container_id,
146 const std::string& drm_uuid,
147 const std::vector<uint8_t>& new_key_id,
148 const std::vector<uint8_t>& new_pssh) {
149 base::AutoLock auto_lock(lock_);
150 auto it = representation_map_.find(container_id);
151 if (it == representation_map_.end()) {
152 LOG(ERROR) <<
"Unexpected container_id: " << container_id;
156 if (content_protection_in_adaptation_set_) {
158 representation_id_to_adaptation_set_[it->second->id()];
162 it->second->UpdateContentProtectionPssh(drm_uuid,
169 const MediaInfo& media_info) {
170 base::AutoLock auto_lock(lock_);
171 auto it = representation_map_.find(container_id);
172 if (it == representation_map_.end()) {
173 LOG(ERROR) <<
"Unexpected container_id: " << container_id;
177 MediaInfo adjusted_media_info(media_info);
180 it->second->set_media_info(adjusted_media_info);
185 base::AutoLock auto_lock(lock_);
virtual const MediaInfo & GetMediaInfo() const
virtual AdaptationSet * GetOrCreateAdaptationSet(const MediaInfo &media_info, bool content_protection_in_adaptation_set)
virtual Representation * AddRepresentation(const MediaInfo &media_info)
All the methods that are virtual are virtual for mocking.
virtual Representation * CopyRepresentation(const Representation &representation)
bool NotifyCueEvent(uint32_t container_id, uint64_t timestamp) override
void AddContentProtectionElements(const MediaInfo &media_info, Representation *parent)
virtual void UpdateContentProtectionPssh(const std::string &drm_uuid, const std::string &pssh)
std::string Uint8VectorToBase64(const std::vector< uint8_t > &input)
Converts uint8 vector into base64 encoded string.
bool NotifySampleDuration(uint32_t container_id, uint32_t sample_duration) override
bool NotifyEncryptionUpdate(uint32_t container_id, const std::string &drm_uuid, const std::vector< uint8_t > &new_key_id, const std::vector< uint8_t > &new_pssh) override
static void MakePathsRelativeToMpd(const std::string &mpd_path, MediaInfo *media_info)
bool NotifyMediaInfoUpdate(uint32_t container_id, const MediaInfo &media_info) override
ContentType GetContentType(const MediaInfo &media_info)
bool NotifyNewSegment(uint32_t container_id, uint64_t start_time, uint64_t duration, uint64_t size) override
bool WriteMpdToFile(const std::string &output_path, MpdBuilder *mpd_builder)
bool NotifyNewContainer(const MediaInfo &media_info, uint32_t *id) override