From c223bc9144ac7582804a3aa0100d595a1099943c Mon Sep 17 00:00:00 2001 From: Kongqun Yang Date: Tue, 28 Feb 2017 18:10:28 -0800 Subject: [PATCH] Keep slice data partition NALs in clear CENCv3 recommends only encrypting video data in slice NALs. Slice data partition NALs should not be encrypted. In the code, differentiate is_vcl and is_video_slice. They are the same for H265; for H264, vcl NALs include slice data partition NALs but video_slice NALs do not. Change-Id: I91f4bdd76d25f0eac50e39aed350ebce3f667121 --- packager/media/codecs/nalu_reader.cc | 12 +++++++----- packager/media/codecs/nalu_reader.h | 3 +++ packager/media/formats/mp2t/es_parser_h265.cc | 2 +- packager/media/formats/mp2t/es_parser_h26x.cc | 4 ++-- .../media/formats/mp2t/es_parser_h26x_unittest.cc | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/packager/media/codecs/nalu_reader.cc b/packager/media/codecs/nalu_reader.cc index b93f2314a1..e725995dc5 100644 --- a/packager/media/codecs/nalu_reader.cc +++ b/packager/media/codecs/nalu_reader.cc @@ -79,10 +79,11 @@ bool Nalu::InitializeFromH264(const uint8_t* data, uint64_t size) { } is_aud_ = type_ == H264_AUD; - is_video_slice_ = (type_ >= Nalu::H264_NonIDRSlice && - type_ <= Nalu::H264_IDRSlice); + is_vcl_ = (type_ >= Nalu::H264_NonIDRSlice && type_ <= Nalu::H264_IDRSlice); + is_video_slice_ = + (type_ == Nalu::H264_NonIDRSlice || type_ == Nalu::H264_IDRSlice); can_start_access_unit_ = - (is_video_slice_ || type_ == Nalu::H264_AUD || type_ == Nalu::H264_SPS || + (is_vcl_ || type_ == Nalu::H264_AUD || type_ == Nalu::H264_SPS || type_ == Nalu::H264_PPS || type_ == Nalu::H264_SEIMessage || (type_ >= Nalu::H264_PrefixNALUnit && type_ <= Nalu::H264_Reserved18)); return true; @@ -147,10 +148,11 @@ bool Nalu::InitializeFromH265(const uint8_t* data, uint64_t size) { } is_aud_ = type_ == H265_AUD; - is_video_slice_ = type_ >= Nalu::H265_TRAIL_N && type_ <= Nalu::H265_CRA_NUT; + is_vcl_ = type_ >= Nalu::H265_TRAIL_N && type_ <= Nalu::H265_CRA_NUT; + is_video_slice_ = is_vcl_; can_start_access_unit_ = nuh_layer_id_ == 0 && - (is_video_slice_ || type_ == Nalu::H265_AUD || type_ == Nalu::H265_VPS || + (is_vcl_ || type_ == Nalu::H265_AUD || type_ == Nalu::H265_VPS || type_ == Nalu::H265_SPS || type_ == Nalu::H265_PPS || type_ == Nalu::H265_PREFIX_SEI || (type_ >= Nalu::H265_RSV_NVCL41 && type_ <= Nalu::H265_RSV_NVCL44) || diff --git a/packager/media/codecs/nalu_reader.h b/packager/media/codecs/nalu_reader.h index 552977d0db..2c0fd0c66e 100644 --- a/packager/media/codecs/nalu_reader.h +++ b/packager/media/codecs/nalu_reader.h @@ -111,6 +111,8 @@ class Nalu { /// return value. int type() const { return type_; } bool is_aud() const { return is_aud_; } + bool is_vcl() const { return is_vcl_; } + /// Slice data partition NALs are not considered as slice NALs. bool is_video_slice() const { return is_video_slice_; } bool can_start_access_unit() const { return can_start_access_unit_; } @@ -132,6 +134,7 @@ class Nalu { int nuh_temporal_id_ = 0; int type_ = 0; bool is_aud_ = false; + bool is_vcl_ = false; bool is_video_slice_ = false; bool can_start_access_unit_ = false; diff --git a/packager/media/formats/mp2t/es_parser_h265.cc b/packager/media/formats/mp2t/es_parser_h265.cc index 9fc4681392..31e0cb08ff 100644 --- a/packager/media/formats/mp2t/es_parser_h265.cc +++ b/packager/media/formats/mp2t/es_parser_h265.cc @@ -73,7 +73,7 @@ bool EsParserH265::ProcessNalu(const Nalu& nalu, break; } default: { - if (nalu.is_video_slice() && nalu.nuh_layer_id() == 0) { + if (nalu.is_vcl() && nalu.nuh_layer_id() == 0) { const bool is_key_frame = nalu.type() == Nalu::H265_IDR_W_RADL || nalu.type() == Nalu::H265_IDR_N_LP; DVLOG(LOG_LEVEL_ES) << "Nalu: slice KeyFrame=" << is_key_frame; diff --git a/packager/media/formats/mp2t/es_parser_h26x.cc b/packager/media/formats/mp2t/es_parser_h26x.cc index cb75c3fd74..eefff70ddb 100644 --- a/packager/media/formats/mp2t/es_parser_h26x.cc +++ b/packager/media/formats/mp2t/es_parser_h26x.cc @@ -192,14 +192,14 @@ bool EsParserH26x::ParseInternal() { next_access_unit_position_ = position; } RCHECK(ProcessNalu(nalu, &video_slice_info)); - if (nalu.is_video_slice() && !video_slice_info.valid) { + if (nalu.is_vcl() && !video_slice_info.valid) { // This could happen only if decoder config is not available yet. Drop // this frame. DCHECK(!current_video_slice_info_.valid); next_access_unit_position_set_ = false; continue; } - } else if (nalu.is_video_slice()) { + } else if (nalu.is_vcl()) { // This isn't the first VCL NAL unit. Next access unit should start after // this NAL unit. next_access_unit_position_set_ = false; diff --git a/packager/media/formats/mp2t/es_parser_h26x_unittest.cc b/packager/media/formats/mp2t/es_parser_h26x_unittest.cc index 5298e02630..40a5cf64c4 100644 --- a/packager/media/formats/mp2t/es_parser_h26x_unittest.cc +++ b/packager/media/formats/mp2t/es_parser_h26x_unittest.cc @@ -93,7 +93,7 @@ class TestableEsParser : public EsParserH26x { : (nalu.type() == Nalu::H265_SPS)) { video_slice_info->valid = false; decoder_config_check_pending_ = true; - } else if (nalu.is_video_slice()) { + } else if (nalu.is_vcl()) { video_slice_info->valid = true; // This should be the same as EsParserH26x::ProcessNalu. if (codec_type_ == Nalu::kH264) {