Skip to content

Commit

Permalink
media: Add H265NaluParser
Browse files Browse the repository at this point in the history
This puts back what was essentially the original version of the
H265Parser that contains the pieces needed for demuxing only. We will
want this for Lacros so we only need to include H265 NALU parsing along
with H265 demuxing rather than including the full H265 parser.

BUG=b:194429120
TEST=Builds, unit tests pass

Change-Id: I2911e874e6f0b281596ff07f41558c84b3431ad7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3053454
Reviewed-by: Xiaohan Wang <xhwang@chromium.org>
Commit-Queue: Jeffrey Kardatzke <jkardatzke@google.com>
Cr-Commit-Position: refs/heads/master@{#905501}
  • Loading branch information
Narflex authored and Chromium LUCI CQ committed Jul 27, 2021
1 parent 6d2d002 commit 022f1b5
Show file tree
Hide file tree
Showing 17 changed files with 644 additions and 455 deletions.
1 change: 1 addition & 0 deletions media/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ buildflag_header("media_buildflags") {
"ENABLE_FFMPEG=$media_use_ffmpeg",
"ENABLE_FFMPEG_VIDEO_DECODERS=$enable_ffmpeg_video_decoders",
"ENABLE_PLATFORM_HEVC=$enable_platform_hevc",
"ENABLE_PLATFORM_HEVC_DECODING=$enable_platform_hevc_decoding",
"ENABLE_PLATFORM_ENCRYPTED_HEVC=$enable_platform_encrypted_hevc",
"ENABLE_HLS_SAMPLE_AES=$enable_hls_sample_aes",
"ENABLE_LIBGAV1_DECODER=$enable_libgav1_decoder",
Expand Down
16 changes: 8 additions & 8 deletions media/formats/mp4/hevc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "media/formats/mp4/avc.h"
#include "media/formats/mp4/box_definitions.h"
#include "media/formats/mp4/box_reader.h"
#include "media/video/h265_parser.h"
#include "media/video/h265_nalu_parser.h"

namespace media {
namespace mp4 {
Expand Down Expand Up @@ -146,12 +146,12 @@ bool HEVC::InsertParamSetsAnnexB(
DCHECK(HEVC::AnalyzeAnnexB(buffer->data(), buffer->size(), *subsamples)
.is_conformant.value_or(true));

std::unique_ptr<H265Parser> parser(new H265Parser());
std::unique_ptr<H265NaluParser> parser(new H265NaluParser());
const uint8_t* start = buffer->data();
parser->SetEncryptedStream(start, buffer->size(), *subsamples);

H265NALU nalu;
if (parser->AdvanceToNextNALU(&nalu) != H265Parser::kOk)
if (parser->AdvanceToNextNALU(&nalu) != H265NaluParser::kOk)
return false;

std::vector<uint8_t>::iterator config_insert_point = buffer->begin();
Expand Down Expand Up @@ -225,7 +225,7 @@ BitstreamConverter::AnalysisResult HEVC::AnalyzeAnnexB(
return result;
}

H265Parser parser;
H265NaluParser parser;
parser.SetEncryptedStream(buffer, size, subsamples);

enum NALUOrderState {
Expand All @@ -243,13 +243,13 @@ BitstreamConverter::AnalysisResult HEVC::AnalyzeAnnexB(
// 7.4.2.4.4 Order of NAL units and coded pictures and their association to
// access units
while (true) {
H265Parser::Result h265_result = parser.AdvanceToNextNALU(&nalu);
if (h265_result == H265Parser::kEOStream) {
H265NaluParser::Result h265_result = parser.AdvanceToNextNALU(&nalu);
if (h265_result == H265NaluParser::kEOStream) {
break;
}

if (h265_result != H265Parser::kOk) {
DCHECK_NE(h265_result, H265Parser::kUnsupportedStream)
if (h265_result != H265NaluParser::kOk) {
DCHECK_NE(h265_result, H265NaluParser::kUnsupportedStream)
<< "AdvanceToNextNALU() returned kUnsupportedStream!";
return result;
}
Expand Down
6 changes: 3 additions & 3 deletions media/gpu/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ source_set("common") {
"vp9_reference_frame_vector.h",
]

if (proprietary_codecs && enable_platform_hevc) {
if (enable_platform_hevc_decoding) {
sources += [
"h265_decoder.cc",
"h265_decoder.h",
Expand Down Expand Up @@ -487,7 +487,7 @@ source_set("unit_tests") {
"//ui/gl:test_support",
]
sources = [ "h264_decoder_unittest.cc" ]
if (proprietary_codecs && enable_platform_hevc) {
if (enable_platform_hevc_decoding) {
sources += [ "h265_decoder_unittest.cc" ]
}
if (is_chromeos_ash && (use_v4l2_codec || use_vaapi)) {
Expand Down Expand Up @@ -604,7 +604,7 @@ if (use_v4l2_codec || use_vaapi) {
}
}

if (proprietary_codecs && enable_platform_hevc) {
if (enable_platform_hevc_decoding) {
fuzzer_test("media_h265_decoder_fuzzer") {
sources = [ "h265_decoder_fuzzertest.cc" ]
deps = [
Expand Down
2 changes: 1 addition & 1 deletion media/gpu/vaapi/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ source_set("vaapi") {
"vp9_vaapi_video_encoder_delegate.cc",
"vp9_vaapi_video_encoder_delegate.h",
]
if (proprietary_codecs && enable_platform_hevc) {
if (enable_platform_hevc_decoding) {
sources += [
"h265_vaapi_video_decoder_delegate.cc",
"h265_vaapi_video_decoder_delegate.h",
Expand Down
4 changes: 2 additions & 2 deletions media/gpu/vaapi/vaapi_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void VaapiH264Picture::SetDecodeSurface(
decode_va_surface_ = std::move(decode_va_surface);
}

#if BUILDFLAG(ENABLE_PLATFORM_HEVC)
#if BUILDFLAG(ENABLE_PLATFORM_HEVC_DECODING)
VaapiH265Picture::VaapiH265Picture(scoped_refptr<VASurface> va_surface)
: va_surface_(va_surface) {}

Expand All @@ -37,7 +37,7 @@ void VaapiH265Picture::SetDecodeSurface(
decode_va_surface_ = std::move(decode_va_surface);
}

#endif // BUILDFLAG(ENABLE_PLATFORM_HEVC)
#endif // BUILDFLAG(ENABLE_PLATFORM_HEVC_DECODING)

VaapiVP8Picture::VaapiVP8Picture(scoped_refptr<VASurface> va_surface)
: va_surface_(va_surface) {}
Expand Down
6 changes: 3 additions & 3 deletions media/gpu/vaapi/vaapi_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "media/gpu/vp9_picture.h"
#include "media/media_buildflags.h"

#if BUILDFLAG(ENABLE_PLATFORM_HEVC)
#if BUILDFLAG(ENABLE_PLATFORM_HEVC_DECODING)
#include "media/gpu/h265_dpb.h"
#endif

Expand Down Expand Up @@ -49,7 +49,7 @@ class VaapiH264Picture : public H264Picture {
DISALLOW_COPY_AND_ASSIGN(VaapiH264Picture);
};

#if BUILDFLAG(ENABLE_PLATFORM_HEVC)
#if BUILDFLAG(ENABLE_PLATFORM_HEVC_DECODING)
class VaapiH265Picture : public H265Picture {
public:
explicit VaapiH265Picture(scoped_refptr<VASurface> va_surface);
Expand Down Expand Up @@ -77,7 +77,7 @@ class VaapiH265Picture : public H265Picture {
scoped_refptr<VASurface> va_surface_;
scoped_refptr<VASurface> decode_va_surface_;
};
#endif // BUILDFLAG(ENABLE_PLATFORM_HEVC)
#endif // BUILDFLAG(ENABLE_PLATFORM_HEVC_DECODING)

class VaapiVP8Picture : public VP8Picture {
public:
Expand Down
4 changes: 2 additions & 2 deletions media/gpu/vaapi/vaapi_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ absl::optional<VAProfile> ConvertToVAProfile(VideoCodecProfile profile) {
{VP9PROFILE_PROFILE0, VAProfileVP9Profile0},
{VP9PROFILE_PROFILE2, VAProfileVP9Profile2},
{AV1PROFILE_PROFILE_MAIN, VAProfileAV1Profile0},
#if BUILDFLAG(ENABLE_PLATFORM_HEVC)
#if BUILDFLAG(ENABLE_PLATFORM_HEVC_DECODING)
{HEVCPROFILE_MAIN, VAProfileHEVCMain},
{HEVCPROFILE_MAIN10, VAProfileHEVCMain10},
#endif
Expand All @@ -71,7 +71,7 @@ absl::optional<VAProfile> StringToVAProfile(const std::string& va_profile) {
{"VAProfileVP9Profile0", VAProfileVP9Profile0},
{"VAProfileVP9Profile2", VAProfileVP9Profile2},
{"VAProfileAV1Profile0", VAProfileAV1Profile0},
#if BUILDFLAG(ENABLE_PLATFORM_HEVC)
#if BUILDFLAG(ENABLE_PLATFORM_HEVC_DECODING)
{"VAProfileHEVCMain", VAProfileHEVCMain},
{"VAProfileHEVCMain10", VAProfileHEVCMain10},
#endif
Expand Down
11 changes: 5 additions & 6 deletions media/gpu/vaapi/vaapi_video_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "media/gpu/vaapi/vp9_vaapi_video_decoder_delegate.h"
#include "media/media_buildflags.h"

#if BUILDFLAG(ENABLE_PLATFORM_HEVC)
#if BUILDFLAG(ENABLE_PLATFORM_HEVC_DECODING)
#include "media/gpu/vaapi/h265_vaapi_video_decoder_delegate.h"
#endif

Expand Down Expand Up @@ -244,7 +244,7 @@ void VaapiVideoDecoder::Initialize(const VideoDecoderConfig& config,
transcryption_ = (VaapiWrapper::GetImplementationType() ==
VAImplementation::kMesaGallium);
#endif
#if BUILDFLAG(ENABLE_PLATFORM_HEVC)
#if BUILDFLAG(ENABLE_PLATFORM_HEVC_DECODING)
} else if (config.codec() == kCodecHEVC &&
!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableClearHevcForTesting)) {
Expand Down Expand Up @@ -978,7 +978,7 @@ Status VaapiVideoDecoder::CreateAcceleratedVideoDecoder() {
decoder_.reset(
new VP9Decoder(std::move(accelerator), profile_, color_space_));
}
#if BUILDFLAG(ENABLE_PLATFORM_HEVC)
#if BUILDFLAG(ENABLE_PLATFORM_HEVC_DECODING)
else if (profile_ >= HEVCPROFILE_MIN && profile_ <= HEVCPROFILE_MAX) {
auto accelerator = std::make_unique<H265VaapiVideoDecoderDelegate>(
this, vaapi_wrapper_, std::move(protected_update_cb),
Expand All @@ -989,15 +989,14 @@ Status VaapiVideoDecoder::CreateAcceleratedVideoDecoder() {
decoder_.reset(
new H265Decoder(std::move(accelerator), profile_, color_space_));
}
#endif // BUILDFLAG(ENABLE_PLATFORM_HEVC)
#endif // BUILDFLAG(ENABLE_PLATFORM_HEVC_DECODING)
else if (profile_ >= AV1PROFILE_MIN && profile_ <= AV1PROFILE_MAX) {
auto accelerator =
std::make_unique<AV1VaapiVideoDecoderDelegate>(this, vaapi_wrapper_);
decoder_delegate_ = accelerator.get();

decoder_.reset(new AV1Decoder(std::move(accelerator), profile_));
}
else {
} else {
return Status(StatusCode::kDecoderUnsupportedProfile)
.WithData("profile", profile_);
}
Expand Down
2 changes: 1 addition & 1 deletion media/gpu/vaapi/vaapi_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ const ProfileCodecMap& GetProfileCodecMap() {
{AV1PROFILE_PROFILE_MAIN, VAProfileAV1Profile0},
// VaapiWrapper does not support AV1 Profile 1.
// {AV1PROFILE_PROFILE_HIGH, VAProfileAV1Profile1},
#if BUILDFLAG(ENABLE_PLATFORM_HEVC)
#if BUILDFLAG(ENABLE_PLATFORM_HEVC_DECODING)
{HEVCPROFILE_MAIN, VAProfileHEVCMain},
{HEVCPROFILE_MAIN10, VAProfileHEVCMain10},
#endif
Expand Down
7 changes: 7 additions & 0 deletions media/media_options.gni
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ declare_args() {
enable_platform_hevc =
proprietary_codecs &&
(is_chromecast || use_fuzzing_engine || enable_platform_encrypted_hevc)

# Enable HEVC/H265 decoding with hardware acceleration assist. Enabled by
# default for fuzzer builds and protected video on ChromeOS. It is also
# enabled for Chromecast by default so the unit tests get run in Chrome CQ.
enable_platform_hevc_decoding =
proprietary_codecs &&
(is_chromecast || use_fuzzing_engine || use_chromeos_protected_media)
}

assert(
Expand Down
19 changes: 14 additions & 5 deletions media/video/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,17 @@ source_set("video") {
"video_encoder_info.h",
]

if (proprietary_codecs && enable_platform_hevc) {
if (enable_platform_hevc) {
sources += [
"h265_parser.cc",
"h265_parser.h",
"h265_nalu_parser.cc",
"h265_nalu_parser.h",
]
if (enable_platform_hevc_decoding) {
sources += [
"h265_parser.cc",
"h265_parser.h",
]
}
}

public_deps = [ "//gpu/command_buffer/client:gles2_interface" ]
Expand Down Expand Up @@ -132,7 +138,10 @@ source_set("unit_tests") {
"video_encode_accelerator_adapter_test.cc",
]
if (enable_platform_hevc) {
sources += [ "h265_parser_unittest.cc" ]
sources += [ "h265_nalu_parser_unittest.cc" ]
if (enable_platform_hevc_decoding) {
sources += [ "h265_parser_unittest.cc" ]
}
}

configs += [ "//media:media_config" ]
Expand Down Expand Up @@ -160,7 +169,7 @@ fuzzer_test("media_h264_parser_fuzzer") {
]
}

if (proprietary_codecs && enable_platform_hevc) {
if (enable_platform_hevc_decoding) {
fuzzer_test("media_h265_parser_fuzzer") {
sources = [ "h265_parser_fuzzertest.cc" ]
deps = [
Expand Down
Loading

0 comments on commit 022f1b5

Please sign in to comment.