7 #include <packager/mpd/base/simple_mpd_notifier.h>
9 #include <absl/log/check.h>
10 #include <absl/log/log.h>
12 #include <packager/mpd/base/adaptation_set.h>
13 #include <packager/mpd/base/mpd_builder.h>
14 #include <packager/mpd/base/mpd_notifier_util.h>
15 #include <packager/mpd/base/mpd_utils.h>
16 #include <packager/mpd/base/period.h>
17 #include <packager/mpd/base/representation.h>
21 SimpleMpdNotifier::SimpleMpdNotifier(
const MpdOptions& mpd_options)
22 : MpdNotifier(mpd_options),
23 output_path_(mpd_options.mpd_params.mpd_output),
24 mpd_builder_(new MpdBuilder(mpd_options)),
25 content_protection_in_adaptation_set_(
26 mpd_options.mpd_params.generate_dash_if_iop_compliant_mpd) {
27 for (
const std::string& base_url : mpd_options.mpd_params.base_urls)
28 mpd_builder_->AddBaseUrl(base_url);
31 SimpleMpdNotifier::~SimpleMpdNotifier() {}
33 bool SimpleMpdNotifier::Init() {
37 bool SimpleMpdNotifier::NotifyNewContainer(
const MediaInfo& media_info,
38 uint32_t* container_id) {
42 if (content_type == kContentTypeUnknown)
45 MediaInfo adjusted_media_info(media_info);
46 MpdBuilder::MakePathsRelativeToMpd(output_path_, &adjusted_media_info);
48 absl::MutexLock auto_lock(&lock_);
49 const double kPeriodStartTimeSeconds = 0.0;
50 Period* period = mpd_builder_->GetOrCreatePeriod(kPeriodStartTimeSeconds);
53 media_info, content_protection_in_adaptation_set_);
54 DCHECK(adaptation_set);
55 if (!adaptation_set->
has_id())
56 adaptation_set->
set_id(next_adaptation_set_id_++);
62 *container_id = representation->
id();
63 if (content_protection_in_adaptation_set_) {
67 representation_id_to_adaptation_set_[representation->
id()] = adaptation_set;
71 representation_map_[representation->
id()] = representation;
75 bool SimpleMpdNotifier::NotifyAvailabilityTimeOffset(uint32_t container_id) {
76 absl::MutexLock 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->SetAvailabilityTimeOffset();
86 bool SimpleMpdNotifier::NotifySampleDuration(uint32_t container_id,
87 int32_t sample_duration) {
88 absl::MutexLock lock(&lock_);
89 auto it = representation_map_.find(container_id);
90 if (it == representation_map_.end()) {
91 LOG(ERROR) <<
"Unexpected container_id: " << container_id;
94 it->second->SetSampleDuration(sample_duration);
98 bool SimpleMpdNotifier::NotifySegmentDuration(uint32_t container_id) {
99 absl::MutexLock lock(&lock_);
100 auto it = representation_map_.find(container_id);
101 if (it == representation_map_.end()) {
102 LOG(ERROR) <<
"Unexpected container_id: " << container_id;
105 it->second->SetSegmentDuration();
109 bool SimpleMpdNotifier::NotifyNewSegment(uint32_t container_id,
113 int64_t segment_number) {
114 absl::MutexLock lock(&lock_);
115 auto it = representation_map_.find(container_id);
116 if (it == representation_map_.end()) {
117 LOG(ERROR) <<
"Unexpected container_id: " << container_id;
120 it->second->AddNewSegment(start_time, duration, size, segment_number);
124 bool SimpleMpdNotifier::NotifyCompletedSegment(uint32_t container_id,
127 absl::MutexLock lock(&lock_);
128 auto it = representation_map_.find(container_id);
129 if (it == representation_map_.end()) {
130 LOG(ERROR) <<
"Unexpected container_id: " << container_id;
133 it->second->UpdateCompletedSegment(duration, size);
137 bool SimpleMpdNotifier::NotifyCueEvent(uint32_t container_id,
139 absl::MutexLock lock(&lock_);
140 auto it = representation_map_.find(container_id);
141 if (it == representation_map_.end()) {
142 LOG(ERROR) <<
"Unexpected container_id: " << container_id;
147 representation_id_to_adaptation_set_[container_id];
149 const MediaInfo& media_info = original_representation->
GetMediaInfo();
150 const double period_start_time_seconds =
151 static_cast<double>(timestamp) / media_info.reference_time_scale();
153 Period* period = mpd_builder_->GetOrCreatePeriod(period_start_time_seconds);
156 media_info, content_protection_in_adaptation_set_);
157 DCHECK(adaptation_set);
158 if (!adaptation_set->
has_id()) {
159 adaptation_set->
set_id(original_adaptation_set->id());
161 DCHECK_EQ(adaptation_set->id(), original_adaptation_set->id());
169 if (content_protection_in_adaptation_set_) {
173 representation_id_to_adaptation_set_[representation->
id()] = adaptation_set;
177 representation_map_[representation->
id()] = representation;
181 bool SimpleMpdNotifier::NotifyEncryptionUpdate(
182 uint32_t container_id,
183 const std::string& drm_uuid,
184 const std::vector<uint8_t>& new_key_id,
185 const std::vector<uint8_t>& new_pssh) {
186 absl::MutexLock lock(&lock_);
187 auto it = representation_map_.find(container_id);
188 if (it == representation_map_.end()) {
189 LOG(ERROR) <<
"Unexpected container_id: " << container_id;
193 if (content_protection_in_adaptation_set_) {
195 representation_id_to_adaptation_set_[it->second->id()];
199 it->second->UpdateContentProtectionPssh(drm_uuid,
205 bool SimpleMpdNotifier::NotifyMediaInfoUpdate(uint32_t container_id,
206 const MediaInfo& media_info) {
207 absl::MutexLock lock(&lock_);
208 auto it = representation_map_.find(container_id);
209 if (it == representation_map_.end()) {
210 LOG(ERROR) <<
"Unexpected container_id: " << container_id;
214 MediaInfo adjusted_media_info(media_info);
215 MpdBuilder::MakePathsRelativeToMpd(output_path_, &adjusted_media_info);
217 it->second->set_media_info(adjusted_media_info);
221 bool SimpleMpdNotifier::Flush() {
222 absl::MutexLock lock(&lock_);
virtual Representation * AddRepresentation(const MediaInfo &media_info)
virtual Representation * CopyRepresentation(const Representation &representation)
virtual void UpdateContentProtectionPssh(const std::string &drm_uuid, const std::string &pssh)
virtual AdaptationSet * GetOrCreateAdaptationSet(const MediaInfo &media_info, bool content_protection_in_adaptation_set)
virtual const MediaInfo & GetMediaInfo() const
All the methods that are virtual are virtual for mocking.
std::string Uint8VectorToBase64(const std::vector< uint8_t > &input)
Converts uint8 vector into base64 encoded string.
ContentType GetContentType(const MediaInfo &media_info)
bool WriteMpdToFile(const std::string &output_path, MpdBuilder *mpd_builder)
void AddContentProtectionElements(const MediaInfo &media_info, Representation *parent)