Skip to content

Commit

Permalink
Fix order of VPS, SPS, PPS in hvcC box of HEVC/MP4 (#300)
Browse files Browse the repository at this point in the history
Fix order of VPS, SPS, PPS in hvcC box of HEVC/MP4

Fixes #297
  • Loading branch information
l-law authored and kqyang committed Nov 30, 2017
1 parent cc778f6 commit 22c758e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -17,6 +17,7 @@ Anders Hasselqvist <anders.hasselqvist@gmail.com>
Chun-da Chen <capitalm.c@gmail.com>
Google Inc. <*@google.com>
Leandro Moreira <leandro.ribeiro.moreira@gmail.com>
Leo Law <leoltlaw.gh@gmail.com>
More Screens Ltd. <*@morescreens.net>
Philo Inc. <*@philo.com>
Richard Eklycke <richard@eklycke.se>
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Expand Up @@ -32,6 +32,7 @@ Jacob Trimble <modmaker@google.com>
Joey Parrish <joeyparrish@google.com>
Kongqun Yang <kqyang@google.com>
Leandro Moreira <leandro.ribeiro.moreira@gmail.com>
Leo Law <leoltlaw.gh@gmail.com>
Richard Eklycke <richard@eklycke.se>
Rintaro Kuroiwa <rkuroiwa@google.com>
Sergio Ammirata <sergio@ammirata.net>
Expand Down
14 changes: 7 additions & 7 deletions packager/media/codecs/h265_byte_to_unit_stream_converter.cc
Expand Up @@ -73,8 +73,14 @@ bool H265ByteToUnitStreamConverter::GetDecoderConfigurationRecord(
buffer.AppendInt(static_cast<uint8_t>(kUnitStreamNaluLengthSize - 1));
buffer.AppendInt(static_cast<uint8_t>(3) /* numOfArrays */);

// SPS
// VPS
const uint8_t kArrayCompleteness = 0x80;
buffer.AppendInt(static_cast<uint8_t>(kArrayCompleteness | Nalu::H265_VPS));
buffer.AppendInt(static_cast<uint16_t>(1) /* numNalus */);
buffer.AppendInt(static_cast<uint16_t>(last_vps_.size()));
buffer.AppendVector(last_vps_);

// SPS
buffer.AppendInt(static_cast<uint8_t>(kArrayCompleteness | Nalu::H265_SPS));
buffer.AppendInt(static_cast<uint16_t>(1) /* numNalus */);
buffer.AppendInt(static_cast<uint16_t>(last_sps_.size()));
Expand All @@ -86,12 +92,6 @@ bool H265ByteToUnitStreamConverter::GetDecoderConfigurationRecord(
buffer.AppendInt(static_cast<uint16_t>(last_pps_.size()));
buffer.AppendVector(last_pps_);

// VPS
buffer.AppendInt(static_cast<uint8_t>(kArrayCompleteness | Nalu::H265_VPS));
buffer.AppendInt(static_cast<uint16_t>(1) /* numNalus */);
buffer.AppendInt(static_cast<uint16_t>(last_vps_.size()));
buffer.AppendVector(last_vps_);

buffer.SwapBuffer(decoder_config);
return true;
}
Expand Down
Expand Up @@ -14,10 +14,10 @@

namespace {
const char kExpectedConfigRecord[] =
"01016000000300900000030000f000fcfdf8f800000303a10001002e42010101600000"
"030090000003000003005da0028080241f265999a4932bffc0d5c0d640400000030040"
"00000602a2000100074401c172b46240a00001001840010c01ffff0160000003009000"
"0003000003005d999809";
"01016000000300900000030000f000fcfdf8f800000303a00001001840010c01ffff01"
"600000030090000003000003005d999809a10001002e42010101600000030090000003"
"000003005da0028080241f265999a4932bffc0d5c0d64040000003004000000602a200"
"0100074401c172b46240";
}

namespace shaka {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 22c758e

Please sign in to comment.