7 #include "packager/mpd/base/simple_mpd_notifier.h" 9 #include <gflags/gflags.h> 11 #include "packager/base/logging.h" 12 #include "packager/base/stl_util.h" 13 #include "packager/mpd/base/adaptation_set.h" 14 #include "packager/mpd/base/mpd_builder.h" 15 #include "packager/mpd/base/mpd_notifier_util.h" 16 #include "packager/mpd/base/mpd_utils.h" 17 #include "packager/mpd/base/period.h" 18 #include "packager/mpd/base/representation.h" 23 "There could be rounding errors in MSE which could cut the first key frame " 24 "of the representation and thus cut all the frames until the next key " 25 "frame, which then leads to a big gap in presentation timeline which " 26 "stalls playback. A small back off may be necessary to compensate for the " 27 "possible rounding error. It should not cause any playback issues if it is " 28 "small enough. The workaround can be removed once the problem is handled " 33 SimpleMpdNotifier::SimpleMpdNotifier(
const MpdOptions& mpd_options)
34 : MpdNotifier(mpd_options),
35 output_path_(mpd_options.mpd_params.mpd_output),
36 mpd_builder_(new MpdBuilder(mpd_options)),
37 content_protection_in_adaptation_set_(
38 mpd_options.mpd_params.generate_dash_if_iop_compliant_mpd) {
39 for (
const std::string& base_url : mpd_options.mpd_params.base_urls)
40 mpd_builder_->AddBaseUrl(base_url);
43 SimpleMpdNotifier::~SimpleMpdNotifier() {}
50 uint32_t* container_id) {
54 if (content_type == kContentTypeUnknown)
57 MediaInfo adjusted_media_info(media_info);
60 const double kPeriodStartTimeSeconds = 0.0;
62 base::AutoLock auto_lock(lock_);
64 adjusted_media_info, kNoOriginalRepresentation, kPeriodStartTimeSeconds);
67 *container_id = representation->
id();
72 uint32_t sample_duration) {
73 base::AutoLock auto_lock(lock_);
74 auto it = representation_map_.find(container_id);
75 if (it == representation_map_.end()) {
76 LOG(ERROR) <<
"Unexpected container_id: " << container_id;
79 it->second->SetSampleDuration(sample_duration);
87 base::AutoLock auto_lock(lock_);
88 auto it = representation_map_.find(container_id);
89 if (it == representation_map_.end()) {
90 LOG(ERROR) <<
"Unexpected container_id: " << container_id;
93 it->second->AddNewSegment(start_time, duration, size);
99 base::AutoLock auto_lock(lock_);
100 auto it = representation_map_.find(container_id);
101 if (it == representation_map_.end()) {
102 LOG(ERROR) <<
"Unexpected container_id: " << container_id;
107 representation_id_to_adaptation_set_[container_id];
109 const MediaInfo& media_info = original_representation->
GetMediaInfo();
110 const double period_start_time_seconds =
111 static_cast<double>(timestamp) / media_info.reference_time_scale();
112 const Representation* new_representation = AddRepresentationToPeriod(
113 media_info, original_representation, period_start_time_seconds);
114 if (!new_representation)
119 representation_id_to_adaptation_set_[container_id];
120 DCHECK(new_adaptation_set);
121 new_adaptation_set->
set_id(original_adaptation_set->id());
126 uint32_t container_id,
127 const std::string& drm_uuid,
128 const std::vector<uint8_t>& new_key_id,
129 const std::vector<uint8_t>& new_pssh) {
130 base::AutoLock auto_lock(lock_);
131 auto it = representation_map_.find(container_id);
132 if (it == representation_map_.end()) {
133 LOG(ERROR) <<
"Unexpected container_id: " << container_id;
137 if (content_protection_in_adaptation_set_) {
139 representation_id_to_adaptation_set_[it->second->id()];
143 it->second->UpdateContentProtectionPssh(drm_uuid,
150 base::AutoLock auto_lock(lock_);
155 const MediaInfo& media_info,
157 double period_start_time_seconds) {
158 Period* period = mpd_builder_->GetOrCreatePeriod(period_start_time_seconds);
162 media_info, content_protection_in_adaptation_set_);
163 DCHECK(adaptation_set);
166 if (original_representation) {
167 uint64_t presentation_time_offset =
169 if (presentation_time_offset > 0) {
170 presentation_time_offset += FLAGS_pto_adjustment;
173 *original_representation, presentation_time_offset);
180 if (content_protection_in_adaptation_set_) {
184 representation_id_to_adaptation_set_[representation->
id()] = adaptation_set;
188 representation_map_[representation->
id()] = representation;
189 return representation;
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.
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)
virtual Representation * CopyRepresentationWithTimeOffset(const Representation &representation, uint64_t presentation_time_offset)
double start_time_in_seconds() const
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