15 #ifndef MPD_BASE_MPD_BUILDER_H_
16 #define MPD_BASE_MPD_BUILDER_H_
25 #include "packager/base/atomic_sequence_num.h"
26 #include "packager/base/gtest_prod_util.h"
27 #include "packager/base/stl_util.h"
28 #include "packager/base/synchronization/lock.h"
29 #include "packager/mpd/base/bandwidth_estimator.h"
30 #include "packager/mpd/base/content_protection_element.h"
31 #include "packager/mpd/base/media_info.pb.h"
32 #include "packager/mpd/base/mpd_options.h"
33 #include "packager/mpd/base/segment_info.h"
34 #include "packager/mpd/base/xml/scoped_xml_ptr.h"
39 namespace edash_packager {
51 class RepresentationXmlNode;
88 virtual bool ToString(std::string* output);
91 MpdType
type()
const {
return type_; }
99 MediaInfo* media_info);
104 friend class DynamicMpdBuilderTest;
106 bool ToStringImpl(std::string* output);
110 template <
typename OutputType>
111 bool WriteMpdToOutput(OutputType* output);
116 xmlDocPtr GenerateMpd();
137 bool GetEarliestTimestamp(
double* timestamp_seconds);
141 std::list<AdaptationSet*> adaptation_sets_;
142 ::STLElementDeleter<std::list<AdaptationSet*> > adaptation_sets_deleter_;
144 std::list<std::string> base_urls_;
145 std::string availability_start_time_;
148 base::AtomicSequenceNumber adaptation_set_counter_;
149 base::AtomicSequenceNumber representation_counter_;
204 const std::string& pssh);
210 virtual void AddRole(Role role);
216 xml::ScopedXmlPtr<xmlNode>::type
GetXml();
230 virtual void SetGroup(
int group_number);
233 virtual int Group()
const;
236 uint32_t id()
const {
return id_; }
266 uint32_t frame_duration,
278 const std::string& lang,
280 MpdBuilder::MpdType mpd_type,
281 base::AtomicSequenceNumber* representation_counter);
291 enum SegmentAligmentStatus {
292 kSegmentAlignmentUnknown,
293 kSegmentAlignmentTrue,
294 kSegmentAlignmentFalse
303 typedef std::map<uint32_t, std::list<uint64_t> > RepresentationTimeline;
307 FRIEND_TEST_ALL_PREFIXES(CommonMpdBuilderTest, CheckAdaptationSetId);
308 FRIEND_TEST_ALL_PREFIXES(CommonMpdBuilderTest,
309 CheckAdaptationSetVideoContentType);
310 FRIEND_TEST_ALL_PREFIXES(CommonMpdBuilderTest,
311 CheckAdaptationSetAudioContentType);
312 FRIEND_TEST_ALL_PREFIXES(CommonMpdBuilderTest,
313 CheckAdaptationSetTextContentType);
314 FRIEND_TEST_ALL_PREFIXES(CommonMpdBuilderTest, SetAdaptationSetGroup);
315 FRIEND_TEST_ALL_PREFIXES(StaticMpdBuilderTest, SubSegmentAlignment);
316 FRIEND_TEST_ALL_PREFIXES(StaticMpdBuilderTest, ForceSetSubSegmentAlignment);
317 FRIEND_TEST_ALL_PREFIXES(DynamicMpdBuilderTest, SegmentAlignment);
318 FRIEND_TEST_ALL_PREFIXES(
319 CommonMpdBuilderTest,
320 SetAdaptationFrameRateUsingRepresentationSetSampleDuration);
324 bool GetEarliestTimestamp(
double* timestamp_seconds);
333 void CheckLiveSegmentAlignment(uint32_t representation_id,
339 void CheckVodSegmentAlignment();
342 void RecordFrameRate(uint32_t frame_duration, uint32_t timescale);
344 std::list<ContentProtectionElement> content_protection_elements_;
345 std::list<Representation*> representations_;
346 ::STLElementDeleter<std::list<Representation*> > representations_deleter_;
350 base::AtomicSequenceNumber*
const representation_counter_;
353 const std::string lang_;
355 const MpdBuilder::MpdType mpd_type_;
365 std::set<uint32_t> video_widths_;
366 std::set<uint32_t> video_heights_;
374 std::map<double, std::string> video_frame_rates_;
378 std::string content_type_;
388 std::set<std::string> picture_aspect_ratio_;
391 std::set<Role> roles_;
394 SegmentAligmentStatus segments_aligned_;
395 bool force_set_segment_alignment_;
404 RepresentationTimeline representation_segment_start_times_;
419 uint64_t duration) = 0;
426 uint32_t timescale) = 0;
465 const std::string& pssh);
487 xml::ScopedXmlPtr<xmlNode>::type
GetXml();
490 uint32_t
id()
const {
return id_; }
502 const MediaInfo& media_info,
504 uint32_t representation_id,
505 scoped_ptr<RepresentationStateChangeListener> state_change_listener);
512 FRIEND_TEST_ALL_PREFIXES(CommonMpdBuilderTest, ValidMediaInfo);
513 FRIEND_TEST_ALL_PREFIXES(CommonMpdBuilderTest, InvalidMediaInfo);
514 FRIEND_TEST_ALL_PREFIXES(CommonMpdBuilderTest, CheckVideoInfoReflectedInXml);
515 FRIEND_TEST_ALL_PREFIXES(CommonMpdBuilderTest, CheckRepresentationId);
516 FRIEND_TEST_ALL_PREFIXES(CommonMpdBuilderTest, SetSampleDuration);
517 FRIEND_TEST_ALL_PREFIXES(
518 CommonMpdBuilderTest,
519 RepresentationStateChangeListenerOnNewSegmentForRepresentation);
520 FRIEND_TEST_ALL_PREFIXES(
521 CommonMpdBuilderTest,
522 RepresentationStateChangeListenerOnSetFrameRateForRepresentation);
528 bool HasRequiredMediaInfoFields();
532 bool IsContiguous(uint64_t start_time,
534 uint64_t size)
const;
543 std::string GetVideoMimeType()
const;
544 std::string GetAudioMimeType()
const;
548 bool GetEarliestTimestamp(
double* timestamp_seconds);
550 MediaInfo media_info_;
551 std::list<ContentProtectionElement> content_protection_elements_;
552 std::list<SegmentInfo> segment_infos_;
557 std::string mime_type_;
564 uint32_t start_number_;
568 scoped_ptr<RepresentationStateChangeListener> state_change_listener_;
575 #endif // MPD_BASE_MPD_BUILDER_H_
virtual void AddNewSegment(uint64_t start_time, uint64_t duration, uint64_t size)
AdaptationSet(uint32_t adaptation_set_id, const std::string &lang, const MpdOptions &mpd_options, MpdBuilder::MpdType mpd_type, base::AtomicSequenceNumber *representation_counter)
virtual int Group() const
virtual AdaptationSet * AddAdaptationSet(const std::string &lang)
xml::ScopedXmlPtr< xmlNode >::type GetXml()
static void MakePathsRelativeToMpd(const std::string &mpd_path, MediaInfo *media_info)
This class generates DASH MPDs (Media Presentation Descriptions).
void ForceSetSegmentAlignment(bool segment_alignment)
virtual void SetSampleDuration(uint32_t sample_duration)
void AddBaseUrl(const std::string &base_url)
virtual void UpdateContentProtectionPssh(const std::string &drm_uuid, const std::string &pssh)
Representation(const MediaInfo &media_info, const MpdOptions &mpd_options, uint32_t representation_id, scoped_ptr< RepresentationStateChangeListener > state_change_listener)
virtual void SetGroup(int group_number)
virtual void OnNewSegmentForRepresentation(uint64_t start_time, uint64_t duration)=0
xml::ScopedXmlPtr< xmlNode >::type GetXml()
virtual void AddContentProtectionElement(const ContentProtectionElement &element)
virtual void OnSetFrameRateForRepresentation(uint32_t frame_duration, uint32_t timescale)=0
RepresentationType in MPD.
bool WriteMpdToFile(media::File *output_file)
void OnSetFrameRateForRepresentation(uint32_t representation_id, uint32_t frame_duration, uint32_t timescale)
virtual Representation * AddRepresentation(const MediaInfo &media_info)
virtual void UpdateContentProtectionPssh(const std::string &drm_uuid, const std::string &pssh)
virtual bool ToString(std::string *output)
virtual void AddRole(Role role)
MpdBuilder(MpdType type, const MpdOptions &mpd_options)
virtual void AddContentProtectionElement(const ContentProtectionElement &element)
void OnNewSegmentForRepresentation(uint32_t representation_id, uint64_t start_time, uint64_t duration)