diff --git a/packager/app/test/packager_test.py b/packager/app/test/packager_test.py index 0bdde8e1a3b..695ed5b38a0 100755 --- a/packager/app/test/packager_test.py +++ b/packager/app/test/packager_test.py @@ -1704,7 +1704,9 @@ def testLiveStaticProfileWithTimeInSegmentName(self): def testAllowCodecSwitching(self): streams = [ + self._GetStream('video', test_file='bear-1280x720-hevc.mp4'), self._GetStream('video', test_file='bear-640x360-hevc.mp4'), + self._GetStream('video', test_file='bear-640x360-vp9.mp4'), self._GetStream('video', test_file='bear-640x360.mp4'), self._GetStream('video', test_file='bear-1280x720.mp4'), self._GetStream('audio', test_file='bear-640x360.mp4'), diff --git a/packager/app/test/testdata/audio-video-with-codec-switching-and-forced-commandline_order/output.mpd b/packager/app/test/testdata/audio-video-with-codec-switching-and-forced-commandline_order/output.mpd index 3ff2faa158d..95da685a0f2 100644 --- a/packager/app/test/testdata/audio-video-with-codec-switching-and-forced-commandline_order/output.mpd +++ b/packager/app/test/testdata/audio-video-with-codec-switching-and-forced-commandline_order/output.mpd @@ -12,7 +12,7 @@ - + bear-640x360-hevc-video.mp4 diff --git a/packager/app/test/testdata/audio-video-with-codec-switching-encryption-trick-play/output.mpd b/packager/app/test/testdata/audio-video-with-codec-switching-encryption-trick-play/output.mpd index b5b8344745c..0519cd9ef50 100644 --- a/packager/app/test/testdata/audio-video-with-codec-switching-encryption-trick-play/output.mpd +++ b/packager/app/test/testdata/audio-video-with-codec-switching-encryption-trick-play/output.mpd @@ -7,7 +7,7 @@ AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA== - + bear-640x360-hevc-video.mp4 @@ -21,7 +21,7 @@ AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA== - + bear-640x360-video.mp4 @@ -41,7 +41,7 @@ AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA== - + bear-1280x720-video-trick_play_factor_1.mp4 diff --git a/packager/app/test/testdata/audio-video-with-codec-switching/bear-1280x720-hevc-video.mp4 b/packager/app/test/testdata/audio-video-with-codec-switching/bear-1280x720-hevc-video.mp4 new file mode 100644 index 00000000000..5d9af3a83b2 Binary files /dev/null and b/packager/app/test/testdata/audio-video-with-codec-switching/bear-1280x720-hevc-video.mp4 differ diff --git a/packager/app/test/testdata/audio-video-with-codec-switching/bear-640x360-vp9-video.mp4 b/packager/app/test/testdata/audio-video-with-codec-switching/bear-640x360-vp9-video.mp4 new file mode 100644 index 00000000000..67ebd7e445f Binary files /dev/null and b/packager/app/test/testdata/audio-video-with-codec-switching/bear-640x360-vp9-video.mp4 differ diff --git a/packager/app/test/testdata/audio-video-with-codec-switching/output.mpd b/packager/app/test/testdata/audio-video-with-codec-switching/output.mpd index 5504466c188..d4db35ce576 100644 --- a/packager/app/test/testdata/audio-video-with-codec-switching/output.mpd +++ b/packager/app/test/testdata/audio-video-with-codec-switching/output.mpd @@ -2,34 +2,50 @@ - - + + - + + bear-1280x720-hevc-video.mp4 + + + + + bear-640x360-hevc-video.mp4 - - + + + + + bear-640x360-vp9-video.mp4 + + + + + + + - + bear-640x360-video.mp4 - + bear-1280x720-video.mp4 - - + + bear-640x360-audio.mp4 diff --git a/packager/app/test/testdata/audio-video-with-trick-play/output.mpd b/packager/app/test/testdata/audio-video-with-trick-play/output.mpd index 05e5387dac5..00f3fe96fee 100644 --- a/packager/app/test/testdata/audio-video-with-trick-play/output.mpd +++ b/packager/app/test/testdata/audio-video-with-trick-play/output.mpd @@ -20,7 +20,7 @@ - + bear-640x360-video-trick_play_factor_1.mp4 diff --git a/packager/app/test/testdata/encryption-and-trick-play/output.mpd b/packager/app/test/testdata/encryption-and-trick-play/output.mpd index 4d289f04421..5c00589ac23 100644 --- a/packager/app/test/testdata/encryption-and-trick-play/output.mpd +++ b/packager/app/test/testdata/encryption-and-trick-play/output.mpd @@ -32,7 +32,7 @@ AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA== - + bear-640x360-video-trick_play_factor_1.mp4 diff --git a/packager/app/test/testdata/encryption-and-two-trick-plays/output.mpd b/packager/app/test/testdata/encryption-and-two-trick-plays/output.mpd index 88e1a8ef0cf..910f1375c72 100644 --- a/packager/app/test/testdata/encryption-and-two-trick-plays/output.mpd +++ b/packager/app/test/testdata/encryption-and-two-trick-plays/output.mpd @@ -32,7 +32,7 @@ AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA== - + bear-640x360-video-trick_play_factor_1.mp4 diff --git a/packager/media/test/data/bear-1280x720-hevc.mp4 b/packager/media/test/data/bear-1280x720-hevc.mp4 new file mode 100644 index 00000000000..8791471b569 Binary files /dev/null and b/packager/media/test/data/bear-1280x720-hevc.mp4 differ diff --git a/packager/media/test/data/bear-640x360-vp9.mp4 b/packager/media/test/data/bear-640x360-vp9.mp4 new file mode 100644 index 00000000000..479de7dd62e Binary files /dev/null and b/packager/media/test/data/bear-640x360-vp9.mp4 differ diff --git a/packager/mpd/base/adaptation_set.cc b/packager/mpd/base/adaptation_set.cc index 52ef7f55690..3ba5f2a814c 100644 --- a/packager/mpd/base/adaptation_set.cc +++ b/packager/mpd/base/adaptation_set.cc @@ -328,8 +328,6 @@ std::optional AdaptationSet::GetXml() { bool suppress_representation_height = false; bool suppress_representation_frame_rate = false; - if (index_.has_value()) - id_ = index_.value(); if (id_ && !adaptation_set.SetId(id_.value())) return std::nullopt; if (!adaptation_set.SetStringAttribute("contentType", content_type_)) @@ -425,10 +423,7 @@ std::optional AdaptationSet::GetXml() { if (!trick_play_reference_ids.empty()) trick_play_reference_ids += ' '; CHECK(tp_adaptation_set->has_id()); - trick_play_reference_ids += - std::to_string(tp_adaptation_set->index_.has_value() - ? tp_adaptation_set->index_.value() - : tp_adaptation_set->id()); + trick_play_reference_ids += std::to_string(tp_adaptation_set->id()); } if (!trick_play_reference_ids.empty() && !adaptation_set.AddEssentialProperty( @@ -442,9 +437,7 @@ std::optional AdaptationSet::GetXml() { if (!switching_ids.empty()) switching_ids += ','; CHECK(s_adaptation_set->has_id()); - switching_ids += std::to_string(s_adaptation_set->index_.has_value() - ? s_adaptation_set->index_.value() - : s_adaptation_set->id()); + switching_ids += std::to_string(s_adaptation_set->id()); } if (!switching_ids.empty() && !adaptation_set.AddSupplementalProperty( diff --git a/packager/mpd/base/adaptation_set.h b/packager/mpd/base/adaptation_set.h index d2bf228a0af..fb02273eb9b 100644 --- a/packager/mpd/base/adaptation_set.h +++ b/packager/mpd/base/adaptation_set.h @@ -143,6 +143,11 @@ class AdaptationSet { /// @return true if id is set, false otherwise. bool has_id() const { return static_cast(id_); } + /// @return true if id is set, false otherwise. + std::optional SortIndex() const { + return index_.has_value() ? index_ : id_; + } + // Must be unique in the Period. uint32_t id() const { return id_.value(); } diff --git a/packager/mpd/base/period.cc b/packager/mpd/base/period.cc index 249bbdb9611..89efceae14c 100644 --- a/packager/mpd/base/period.cc +++ b/packager/mpd/base/period.cc @@ -107,11 +107,14 @@ std::optional Period::GetXml(bool output_period_duration) { adaptation_sets_.sort( [](const std::unique_ptr& adaptation_set_a, const std::unique_ptr& adaptation_set_b) { - if (!adaptation_set_a->has_id()) + auto index_a = adaptation_set_a->SortIndex(); + auto index_b = adaptation_set_b->SortIndex(); + + if (!index_a) return false; - if (!adaptation_set_b->has_id()) + if (!index_b) return true; - return adaptation_set_a->id() < adaptation_set_b->id(); + return index_a < index_b; }); xml::XmlNode period("Period");