From ab8fa87d1807e2f8a5756e365f9bf7b41cc4a992 Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Mon, 30 Sep 2019 18:22:21 -0700 Subject: [PATCH] [HLS] Always signal Dolby Vision as PQ Issue #341. Change-Id: I9665ba032b1e069500d866281cb8569ce59876f9 --- .../testdata/dvh1-with-encryption/output.m3u8 | 2 +- packager/hls/base/media_playlist.cc | 4 +++ packager/hls/base/media_playlist_unittest.cc | 33 +++++++++++++++++-- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/packager/app/test/testdata/dvh1-with-encryption/output.m3u8 b/packager/app/test/testdata/dvh1-with-encryption/output.m3u8 index cbf30c150f..059f1dad96 100644 --- a/packager/app/test/testdata/dvh1-with-encryption/output.m3u8 +++ b/packager/app/test/testdata/dvh1-with-encryption/output.m3u8 @@ -1,5 +1,5 @@ #EXTM3U ## Generated with https://github.com/google/shaka-packager version -- -#EXT-X-STREAM-INF:BANDWIDTH=375371,AVERAGE-BANDWIDTH=368196,CODECS="dvh1.05.01",RESOLUTION=426x240 +#EXT-X-STREAM-INF:BANDWIDTH=375371,AVERAGE-BANDWIDTH=368196,CODECS="dvh1.05.01",RESOLUTION=426x240,VIDEO-RANGE=PQ stream_0.m3u8 diff --git a/packager/hls/base/media_playlist.cc b/packager/hls/base/media_playlist.cc index bf2b61d98c..98362a0216 100644 --- a/packager/hls/base/media_playlist.cc +++ b/packager/hls/base/media_playlist.cc @@ -533,6 +533,10 @@ bool MediaPlaylist::GetDisplayResolution(uint32_t* width, } std::string MediaPlaylist::GetVideoRange() const { + // Dolby Vision (dvh1 or dvhe) is always HDR. + if (codec_.find("dvh") == 0) + return "PQ"; + // HLS specification: // https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-02#section-4.4.4.2 switch (media_info_.video_info().transfer_characteristics()) { diff --git a/packager/hls/base/media_playlist_unittest.cc b/packager/hls/base/media_playlist_unittest.cc index 10d4fcad70..f62800e44c 100644 --- a/packager/hls/base/media_playlist_unittest.cc +++ b/packager/hls/base/media_playlist_unittest.cc @@ -1054,9 +1054,38 @@ INSTANTIATE_TEST_CASE_P( std::make_pair("hvc1.2.4.L63.90", "hvc1.2.4.L63.90"), // Replace hev1 with hvc1. std::make_pair("hev1.2.4.L63.90", "hvc1.2.4.L63.90"), - std::make_pair("dvh1.2.4.L63.90", "dvh1.2.4.L63.90"), + std::make_pair("dvh1.05.08", "dvh1.05.08"), // Replace dvhe with dvh1. - std::make_pair("dvhe.2.4.L63.90", "dvh1.2.4.L63.90"))); + std::make_pair("dvhe.05.08", "dvh1.05.08"))); + +struct VideoRangeTestData { + std::string codec; + int transfer_characteristics; + std::string expected_video_range; +}; + +class MediaPlaylistVideoRangeTest + : public MediaPlaylistTest, + public WithParamInterface {}; + +TEST_P(MediaPlaylistVideoRangeTest, GetVideoRange) { + const VideoRangeTestData& test_data = GetParam(); + MediaInfo media_info; + media_info.set_reference_time_scale(kTimeScale); + MediaInfo::VideoInfo* video_info = media_info.mutable_video_info(); + video_info->set_codec(test_data.codec); + video_info->set_transfer_characteristics(test_data.transfer_characteristics); + ASSERT_TRUE(media_playlist_->SetMediaInfo(media_info)); + EXPECT_EQ(test_data.expected_video_range, media_playlist_->GetVideoRange()); +} + +INSTANTIATE_TEST_CASE_P(VideoRanges, + MediaPlaylistVideoRangeTest, + Values(VideoRangeTestData{"hvc1.2.4.L63.90", 0, ""}, + VideoRangeTestData{"hvc1.2.4.L63.90", 1, "SDR"}, + VideoRangeTestData{"hvc1.2.4.L63.90", 16, "PQ"}, + VideoRangeTestData{"hvc1.2.4.L63.90", 18, "PQ"}, + VideoRangeTestData{"dvh1.05.08", 0, "PQ"})); } // namespace hls } // namespace shaka