diff --git a/packager/media/filters/h264_byte_to_unit_stream_converter.cc b/packager/media/filters/h264_byte_to_unit_stream_converter.cc index 0b72b433d3..34127faa86 100644 --- a/packager/media/filters/h264_byte_to_unit_stream_converter.cc +++ b/packager/media/filters/h264_byte_to_unit_stream_converter.cc @@ -54,8 +54,8 @@ void H264ByteToUnitStreamConverter::ProcessNalu(const Nalu& nalu, DCHECK(output_buffer); // Skip the start code, but keep the 1-byte NALU type. - const uint8_t* nalu_ptr = nalu.data() + nalu.header_size() - 1; - const uint64_t nalu_size = nalu.data_size() + 1; + const uint8_t* nalu_ptr = nalu.data(); + const uint64_t nalu_size = nalu.payload_size() + nalu.header_size(); DCHECK_LE(nalu_size, std::numeric_limits::max()); switch (nalu.type()) { diff --git a/packager/media/filters/h264_parser.cc b/packager/media/filters/h264_parser.cc index ccd59298fa..ea87168fcd 100644 --- a/packager/media/filters/h264_parser.cc +++ b/packager/media/filters/h264_parser.cc @@ -635,7 +635,7 @@ H264Parser::Result H264Parser::ParseSPS(const Nalu& nalu, int* sps_id) { int data; Result res; H264BitReader reader; - reader.Initialize(nalu.data() + nalu.header_size(), nalu.data_size()); + reader.Initialize(nalu.data() + nalu.header_size(), nalu.payload_size()); H264BitReader* br = &reader; *sps_id = -1; @@ -760,7 +760,7 @@ H264Parser::Result H264Parser::ParsePPS(const Nalu& nalu, int* pps_id) { const H264SPS* sps; Result res; H264BitReader reader; - reader.Initialize(nalu.data() + nalu.header_size(), nalu.data_size()); + reader.Initialize(nalu.data() + nalu.header_size(), nalu.payload_size()); H264BitReader* br = &reader; *pps_id = -1; @@ -1031,7 +1031,7 @@ H264Parser::Result H264Parser::ParseSliceHeader(const Nalu& nalu, const H264PPS* pps; Result res; H264BitReader reader; - reader.Initialize(nalu.data() + nalu.header_size(), nalu.data_size()); + reader.Initialize(nalu.data() + nalu.header_size(), nalu.payload_size()); H264BitReader* br = &reader; memset(shdr, 0, sizeof(*shdr)); @@ -1039,7 +1039,7 @@ H264Parser::Result H264Parser::ParseSliceHeader(const Nalu& nalu, shdr->idr_pic_flag = (nalu.type() == 5); shdr->nal_ref_idc = nalu.ref_idc(); shdr->nalu_data = nalu.data() + nalu.header_size(); - shdr->nalu_size = nalu.data_size(); + shdr->nalu_size = nalu.payload_size(); READ_UE_OR_RETURN(&shdr->first_mb_in_slice); READ_UE_OR_RETURN(&shdr->slice_type); @@ -1179,7 +1179,7 @@ H264Parser::Result H264Parser::ParseSEI(const Nalu& nalu, H264SEIMessage* sei_msg) { int byte; H264BitReader reader; - reader.Initialize(nalu.data() + nalu.header_size(), nalu.data_size()); + reader.Initialize(nalu.data() + nalu.header_size(), nalu.payload_size()); H264BitReader* br = &reader; memset(sei_msg, 0, sizeof(*sei_msg)); diff --git a/packager/media/filters/nalu_reader.cc b/packager/media/filters/nalu_reader.cc index f5794c7f00..54cc8e0947 100644 --- a/packager/media/filters/nalu_reader.cc +++ b/packager/media/filters/nalu_reader.cc @@ -21,8 +21,8 @@ inline bool IsStartCode(const uint8_t* data) { Nalu::Nalu() : data_(nullptr), - data_size_(0), header_size_(0), + payload_size_(0), ref_idc_(0), type_(0), is_video_slice_(false) {} @@ -36,7 +36,7 @@ bool Nalu::InitializeFromH264(const uint8_t* data, uint64_t size) { data_ = data; header_size_ = 1; - data_size_ = size - 1; + payload_size_ = size - 1; ref_idc_ = (header >> 5) & 0x3; type_ = header & 0x1F; is_video_slice_ = (type_ >= Nalu::H264_NonIDRSlice && @@ -103,7 +103,7 @@ NaluReader::Result NaluReader::Advance(Nalu* nalu) { DVLOG(4) << "NALU type: " << static_cast(nalu->type()) << " at: " << reinterpret_cast(nalu->data()) - << " data size: " << nalu->data_size() + << " data size: " << nalu->payload_size() << " ref: " << static_cast(nalu->ref_idc()); return NaluReader::kOk; diff --git a/packager/media/filters/nalu_reader.h b/packager/media/filters/nalu_reader.h index d6cc548dbc..43606ebd21 100644 --- a/packager/media/filters/nalu_reader.h +++ b/packager/media/filters/nalu_reader.h @@ -43,8 +43,8 @@ class Nalu { uint64_t size) WARN_UNUSED_RESULT; const uint8_t* data() const { return data_; } - uint64_t data_size() const { return data_size_; } uint64_t header_size() const { return header_size_; } + uint64_t payload_size() const { return payload_size_; } int ref_idc() const { return ref_idc_; } int type() const { return type_; } @@ -54,8 +54,11 @@ class Nalu { // A pointer to the NALU (i.e. points to the header). This pointer is not // owned by this instance. const uint8_t* data_; - uint64_t data_size_; + // NALU header size (e.g. 1 byte for H.264). Note that it does not include + // header extension data in some NAL units. uint64_t header_size_; + // Size of data after the header. + uint64_t payload_size_; int ref_idc_; int type_; diff --git a/packager/media/filters/nalu_reader_unittest.cc b/packager/media/filters/nalu_reader_unittest.cc index 7cf1473017..7552dcf7d4 100644 --- a/packager/media/filters/nalu_reader_unittest.cc +++ b/packager/media/filters/nalu_reader_unittest.cc @@ -25,14 +25,14 @@ TEST(NaluReaderTest, StartCodeSearch) { Nalu nalu; ASSERT_EQ(NaluReader::kOk, reader.Advance(&nalu)); EXPECT_EQ(kNaluData + 9, nalu.data()); - EXPECT_EQ(3u, nalu.data_size()); + EXPECT_EQ(3u, nalu.payload_size()); EXPECT_EQ(1u, nalu.header_size()); EXPECT_EQ(0, nalu.ref_idc()); EXPECT_EQ(0x12, nalu.type()); ASSERT_EQ(NaluReader::kOk, reader.Advance(&nalu)); EXPECT_EQ(kNaluData + 17, nalu.data()); - EXPECT_EQ(3u, nalu.data_size()); + EXPECT_EQ(3u, nalu.payload_size()); EXPECT_EQ(1u, nalu.header_size()); EXPECT_EQ(3, nalu.ref_idc()); EXPECT_EQ(7, nalu.type()); @@ -53,14 +53,14 @@ TEST(NaluReaderTest, OneByteNaluLength) { Nalu nalu; ASSERT_EQ(NaluReader::kOk, reader.Advance(&nalu)); EXPECT_EQ(kNaluData + 1, nalu.data()); - EXPECT_EQ(4u, nalu.data_size()); + EXPECT_EQ(4u, nalu.payload_size()); EXPECT_EQ(1u, nalu.header_size()); EXPECT_EQ(0, nalu.ref_idc()); EXPECT_EQ(8, nalu.type()); ASSERT_EQ(NaluReader::kOk, reader.Advance(&nalu)); EXPECT_EQ(kNaluData + 7, nalu.data()); - EXPECT_EQ(5u, nalu.data_size()); + EXPECT_EQ(5u, nalu.payload_size()); EXPECT_EQ(1u, nalu.header_size()); EXPECT_EQ(3, nalu.ref_idc()); EXPECT_EQ(7, nalu.type()); @@ -81,14 +81,14 @@ TEST(NaluReaderTest, FourByteNaluLength) { Nalu nalu; ASSERT_EQ(NaluReader::kOk, reader.Advance(&nalu)); EXPECT_EQ(kNaluData + 4, nalu.data()); - EXPECT_EQ(6u, nalu.data_size()); + EXPECT_EQ(6u, nalu.payload_size()); EXPECT_EQ(1u, nalu.header_size()); EXPECT_EQ(0, nalu.ref_idc()); EXPECT_EQ(8, nalu.type()); ASSERT_EQ(NaluReader::kOk, reader.Advance(&nalu)); EXPECT_EQ(kNaluData + 15, nalu.data()); - EXPECT_EQ(2u, nalu.data_size()); + EXPECT_EQ(2u, nalu.payload_size()); EXPECT_EQ(1u, nalu.header_size()); EXPECT_EQ(3, nalu.ref_idc()); EXPECT_EQ(7, nalu.type()); diff --git a/packager/media/formats/mp4/encrypting_fragmenter.cc b/packager/media/formats/mp4/encrypting_fragmenter.cc index bfdcd2d541..0f42c35379 100644 --- a/packager/media/formats/mp4/encrypting_fragmenter.cc +++ b/packager/media/formats/mp4/encrypting_fragmenter.cc @@ -244,7 +244,7 @@ Status EncryptingFragmenter::EncryptSample(scoped_refptr sample) { const uint64_t current_clear_bytes = nalu.header_size() + video_slice_header_size; const uint64_t cipher_bytes = - nalu.data_size() - video_slice_header_size; + nalu.payload_size() - video_slice_header_size; const uint8_t* nalu_data = nalu.data() + current_clear_bytes; EncryptBytes(const_cast(nalu_data), cipher_bytes); @@ -254,7 +254,7 @@ Status EncryptingFragmenter::EncryptSample(scoped_refptr sample) { accumulated_clear_bytes = 0; } else { // For non-video-slice NAL units, don't encrypt. - accumulated_clear_bytes += nalu.header_size() + nalu.data_size(); + accumulated_clear_bytes += nalu.header_size() + nalu.payload_size(); } } if (result != NaluReader::kEOStream)