From fd731cb7d99d50a39ea2fd49dd3aa130b8e6b846 Mon Sep 17 00:00:00 2001 From: Sergey Silkin Date: Mon, 11 Dec 2017 17:13:45 +0100 Subject: [PATCH] Allow YUVJ420 format. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FFMpeg H264 decoder uses YUVJ420 when video_full_range_flag=1 in bitstream. Information about color range might be useful for color converter and renderer. But currently there is no way to extract it from the wrapper. Bug: webrtc:8185 Change-Id: Ifd1113f0eee3d7b5906d0cefbc29b4a1061262f6 Reviewed-on: https://webrtc-review.googlesource.com/32000 Reviewed-by: Erik Språng Commit-Queue: Sergey Silkin Cr-Commit-Position: refs/heads/master@{#21246} --- modules/video_coding/codecs/h264/h264_decoder_impl.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/video_coding/codecs/h264/h264_decoder_impl.cc b/modules/video_coding/codecs/h264/h264_decoder_impl.cc index f058e70bd9..2544fb737f 100644 --- a/modules/video_coding/codecs/h264/h264_decoder_impl.cc +++ b/modules/video_coding/codecs/h264/h264_decoder_impl.cc @@ -32,7 +32,8 @@ namespace webrtc { namespace { -const AVPixelFormat kPixelFormat = AV_PIX_FMT_YUV420P; +const AVPixelFormat kPixelFormatDefault = AV_PIX_FMT_YUV420P; +const AVPixelFormat kPixelFormatFullRange = AV_PIX_FMT_YUVJ420P; const size_t kYPlaneIndex = 0; const size_t kUPlaneIndex = 1; const size_t kVPlaneIndex = 2; @@ -95,10 +96,13 @@ int H264DecoderImpl::AVGetBuffer2( H264DecoderImpl* decoder = static_cast(context->opaque); // DCHECK values set in |InitDecode|. RTC_DCHECK(decoder); - RTC_DCHECK_EQ(context->pix_fmt, kPixelFormat); // Necessary capability to be allowed to provide our own buffers. RTC_DCHECK(context->codec->capabilities | AV_CODEC_CAP_DR1); + // Limited or full range YUV420 is expected. + RTC_CHECK(context->pix_fmt == kPixelFormatDefault || + context->pix_fmt == kPixelFormatFullRange); + // |av_frame->width| and |av_frame->height| are set by FFmpeg. These are the // actual image's dimensions and may be different from |context->width| and // |context->coded_width| due to reordering. @@ -225,7 +229,7 @@ int32_t H264DecoderImpl::InitDecode(const VideoCodec* codec_settings, av_context_->coded_width = codec_settings->width; av_context_->coded_height = codec_settings->height; } - av_context_->pix_fmt = kPixelFormat; + av_context_->pix_fmt = kPixelFormatDefault; av_context_->extradata = nullptr; av_context_->extradata_size = 0;