diff --git a/packager/mpd/base/mpd_builder.cc b/packager/mpd/base/mpd_builder.cc index 3f8ed98ef9..7ccdaf7e2d 100644 --- a/packager/mpd/base/mpd_builder.cc +++ b/packager/mpd/base/mpd_builder.cc @@ -35,6 +35,8 @@ using xml::AdaptationSetXmlNode; namespace { +const int kAdaptationSetGroupNotSet = -1; + std::string GetMimeType(const std::string& prefix, MediaInfo::ContainerType container_type) { switch (container_type) { @@ -565,7 +567,8 @@ AdaptationSet::AdaptationSet(uint32_t adaptation_set_id, representation_counter_(counter), id_(adaptation_set_id), lang_(lang), - mpd_options_(mpd_options) { + mpd_options_(mpd_options), + group_(kAdaptationSetGroupNotSet) { DCHECK(counter); } @@ -664,6 +667,9 @@ xml::ScopedXmlPtr::type AdaptationSet::GetXml() { if (picture_aspect_ratio_.size() == 1) adaptation_set.SetStringAttribute("par", *picture_aspect_ratio_.begin()); + + if (group_ >= 0) + adaptation_set.SetIntegerAttribute("group", group_); return adaptation_set.PassScopedPtr(); } diff --git a/packager/mpd/base/mpd_builder.h b/packager/mpd/base/mpd_builder.h index 6176b62406..d4794e1a37 100644 --- a/packager/mpd/base/mpd_builder.h +++ b/packager/mpd/base/mpd_builder.h @@ -175,6 +175,15 @@ class AdaptationSet { /// NULL ScopedXmlPtr. xml::ScopedXmlPtr::type GetXml(); + /// Sets the AdaptationSet@group attribute. + /// Passing a negative value to this method will unset the attribute. + /// Note that group=0 is a special group, as mentioned in the DASH MPD + /// specification. + /// @param group_number is the value of AdaptatoinSet@group. + void set_group(int group_number) { + group_ = group_number; + } + // Must be unique in the Period. uint32_t id() const { return id_; } @@ -187,6 +196,7 @@ class AdaptationSet { CheckAdaptationSetAudioContentType); FRIEND_TEST_ALL_PREFIXES(CommonMpdBuilderTest, CheckAdaptationSetTextContentType); + FRIEND_TEST_ALL_PREFIXES(CommonMpdBuilderTest, SetAdaptationSetGroup); /// @param adaptation_set_id is an ID number for this AdaptationSet. /// @param representation_counter is a Counter for assigning ID numbers to @@ -212,6 +222,11 @@ class AdaptationSet { const std::string lang_; const MpdOptions& mpd_options_; + // The group attribute for the AdaptationSet. If the value is negative, + // no group number is specified. + // Note that group 0 is a special group number. + int group_; + // Video widths and heights of Representations. Note that this is a set; if // there is only 1 resolution, then @width & @height should be set, otherwise // @maxWidth & @maxHeight should be set for DASH IOP. diff --git a/packager/mpd/base/mpd_builder_unittest.cc b/packager/mpd/base/mpd_builder_unittest.cc index 8d683072bf..b7c45de722 100644 --- a/packager/mpd/base/mpd_builder_unittest.cc +++ b/packager/mpd/base/mpd_builder_unittest.cc @@ -325,6 +325,24 @@ class TimeShiftBufferDepthTest : public SegmentTemplateTest { } }; +// Verify that AdaptationSet@group can be set and unset. +TEST_F(CommonMpdBuilderTest, SetAdaptationSetGroup) { + base::AtomicSequenceNumber sequence_counter; + AdaptationSet adaptation_set( + kAnyAdaptationSetId, "", MpdOptions(), &sequence_counter); + adaptation_set.set_group(1); + + xml::ScopedXmlPtr::type xml_with_group(adaptation_set.GetXml()); + EXPECT_NO_FATAL_FAILURE( + ExpectAttributeEqString("group", "1", xml_with_group.get())); + + // Unset by passing a negative value. + adaptation_set.set_group(-1); + xml::ScopedXmlPtr::type xml_without_group(adaptation_set.GetXml()); + EXPECT_NO_FATAL_FAILURE( + ExpectAttributeNotSet("group", xml_without_group.get())); +} + // Verify that Representation::Init() works with all "required" fields of // MedieInfo proto. TEST_F(CommonMpdBuilderTest, ValidMediaInfo) {