diff --git a/packager/app/test/packager_test.py b/packager/app/test/packager_test.py index 0bdde8e1a3..695ed5b38a 100755 --- a/packager/app/test/packager_test.py +++ b/packager/app/test/packager_test.py @@ -1704,7 +1704,9 @@ class PackagerFunctionalTest(PackagerAppTest): 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 3ff2faa158..95da685a0f 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 b5b8344745..0519cd9ef5 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 0000000000..5d9af3a83b 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 0000000000..67ebd7e445 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 5504466c18..d4db35ce57 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 05e5387dac..00f3fe96fe 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 4d289f0442..5c00589ac2 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 88e1a8ef0c..910f1375c7 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 0000000000..8791471b56 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 0000000000..479de7dd62 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 52ef7f5569..3ba5f2a814 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 d2bf228a0a..fb02273eb9 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 249bbdb961..89efceae14 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");