From 22c758ed069a6e626204f11b00faa1cc7f7f3164 Mon Sep 17 00:00:00 2001 From: l-law Date: Fri, 1 Dec 2017 06:34:42 +0800 Subject: [PATCH] Fix order of VPS, SPS, PPS in hvcC box of HEVC/MP4 (#300) Fix order of VPS, SPS, PPS in hvcC box of HEVC/MP4 Fixes #297 --- AUTHORS | 1 + CONTRIBUTORS | 1 + .../codecs/h265_byte_to_unit_stream_converter.cc | 14 +++++++------- ...265_byte_to_unit_stream_converter_unittest.cc | 16 ++++++++-------- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/AUTHORS b/AUTHORS index b8945ee42d..86aa1eafe3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -17,6 +17,7 @@ Anders Hasselqvist Chun-da Chen Google Inc. <*@google.com> Leandro Moreira +Leo Law More Screens Ltd. <*@morescreens.net> Philo Inc. <*@philo.com> Richard Eklycke diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 71fadc886c..300f2ca8a9 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -32,6 +32,7 @@ Jacob Trimble Joey Parrish Kongqun Yang Leandro Moreira +Leo Law Richard Eklycke Rintaro Kuroiwa Sergio Ammirata diff --git a/packager/media/codecs/h265_byte_to_unit_stream_converter.cc b/packager/media/codecs/h265_byte_to_unit_stream_converter.cc index 5c62547cc0..7abd45b458 100644 --- a/packager/media/codecs/h265_byte_to_unit_stream_converter.cc +++ b/packager/media/codecs/h265_byte_to_unit_stream_converter.cc @@ -73,8 +73,14 @@ bool H265ByteToUnitStreamConverter::GetDecoderConfigurationRecord( buffer.AppendInt(static_cast(kUnitStreamNaluLengthSize - 1)); buffer.AppendInt(static_cast(3) /* numOfArrays */); - // SPS + // VPS const uint8_t kArrayCompleteness = 0x80; + buffer.AppendInt(static_cast(kArrayCompleteness | Nalu::H265_VPS)); + buffer.AppendInt(static_cast(1) /* numNalus */); + buffer.AppendInt(static_cast(last_vps_.size())); + buffer.AppendVector(last_vps_); + + // SPS buffer.AppendInt(static_cast(kArrayCompleteness | Nalu::H265_SPS)); buffer.AppendInt(static_cast(1) /* numNalus */); buffer.AppendInt(static_cast(last_sps_.size())); @@ -86,12 +92,6 @@ bool H265ByteToUnitStreamConverter::GetDecoderConfigurationRecord( buffer.AppendInt(static_cast(last_pps_.size())); buffer.AppendVector(last_pps_); - // VPS - buffer.AppendInt(static_cast(kArrayCompleteness | Nalu::H265_VPS)); - buffer.AppendInt(static_cast(1) /* numNalus */); - buffer.AppendInt(static_cast(last_vps_.size())); - buffer.AppendVector(last_vps_); - buffer.SwapBuffer(decoder_config); return true; } diff --git a/packager/media/codecs/h265_byte_to_unit_stream_converter_unittest.cc b/packager/media/codecs/h265_byte_to_unit_stream_converter_unittest.cc index 682085fae3..c37240eab1 100644 --- a/packager/media/codecs/h265_byte_to_unit_stream_converter_unittest.cc +++ b/packager/media/codecs/h265_byte_to_unit_stream_converter_unittest.cc @@ -14,10 +14,10 @@ namespace { const char kExpectedConfigRecord[] = - "01016000000300900000030000f000fcfdf8f800000303a10001002e42010101600000" - "030090000003000003005da0028080241f265999a4932bffc0d5c0d640400000030040" - "00000602a2000100074401c172b46240a00001001840010c01ffff0160000003009000" - "0003000003005d999809"; + "01016000000300900000030000f000fcfdf8f800000303a00001001840010c01ffff01" + "600000030090000003000003005d999809a10001002e42010101600000030090000003" + "000003005da0028080241f265999a4932bffc0d5c0d64040000003004000000602a200" + "0100074401c172b46240"; } namespace shaka { @@ -50,11 +50,11 @@ TEST(H265ByteToUnitStreamConverter, StripParameterSetsNalu) { // Double-check that it can be parsed. HEVCDecoderConfigurationRecord config; ASSERT_TRUE(config.Parse(decoder_config)); - // The order is SPS, PPS, VPS. + // The order is VPS, SPS, PPS. ASSERT_EQ(3u, config.nalu_count()); - EXPECT_EQ(Nalu::H265_SPS, config.nalu(0).type()); - EXPECT_EQ(Nalu::H265_PPS, config.nalu(1).type()); - EXPECT_EQ(Nalu::H265_VPS, config.nalu(2).type()); + EXPECT_EQ(Nalu::H265_VPS, config.nalu(0).type()); + EXPECT_EQ(Nalu::H265_SPS, config.nalu(1).type()); + EXPECT_EQ(Nalu::H265_PPS, config.nalu(2).type()); } TEST(H265ByteToUnitStreamConverter, KeepParameterSetsNalu) {