webrtc_m130/modules/video_coding/codecs/h264/h264_decoder_impl.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

414 lines
15 KiB
C++
Raw Normal View History

/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*
*/
// Everything declared/defined in this header is only required when WebRTC is
// build with H264 support, please do not move anything out of the
// #ifdef unless needed and tested.
#ifdef WEBRTC_USE_H264
#include "modules/video_coding/codecs/h264/h264_decoder_impl.h"
#include <algorithm>
#include <limits>
Use std::make_unique instead of absl::make_unique. WebRTC is now using C++14 so there is no need to use the Abseil version of std::make_unique. This CL has been created with the following steps: git grep -l absl::make_unique | sort | uniq > /tmp/make_unique.txt git grep -l absl::WrapUnique | sort | uniq > /tmp/wrap_unique.txt git grep -l "#include <memory>" | sort | uniq > /tmp/memory.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/make_unique.txt /tmp/wrap_unique.txt | sort | \ uniq > /tmp/only_make_unique.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/only_make_unique.txt /tmp/memory.txt | \ xargs grep -l "absl/memory" > /tmp/add-memory.txt git grep -l "\babsl::make_unique\b" | \ xargs sed -i "s/\babsl::make_unique\b/std::make_unique/g" git checkout PRESUBMIT.py abseil-in-webrtc.md cat /tmp/add-memory.txt | \ xargs sed -i \ 's/#include "absl\/memory\/memory.h"/#include <memory>/g' git cl format # Manual fix order of the new inserted #include <memory> cat /tmp/only_make_unique | xargs grep -l "#include <memory>" | \ xargs sed -i '/#include "absl\/memory\/memory.h"/d' git ls-files | grep BUILD.gn | \ xargs sed -i '/\/\/third_party\/abseil-cpp\/absl\/memory/d' python tools_webrtc/gn_check_autofix.py \ -m tryserver.webrtc -b linux_rel # Repead the gn_check_autofix step for other platforms git ls-files | grep BUILD.gn | \ xargs sed -i 's/absl\/memory:memory/absl\/memory/g' git cl format Bug: webrtc:10945 Change-Id: I3fe28ea80f4dd3ba3cf28effd151d5e1f19aff89 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/153221 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29209}
2019-09-17 17:06:18 +02:00
#include <memory>
extern "C" {
#include "third_party/ffmpeg/libavcodec/avcodec.h"
#include "third_party/ffmpeg/libavformat/avformat.h"
#include "third_party/ffmpeg/libavutil/imgutils.h"
} // extern "C"
#include "api/video/color_space.h"
#include "api/video/i010_buffer.h"
#include "api/video/i420_buffer.h"
#include "common_video/include/video_frame_buffer.h"
#include "modules/video_coding/codecs/h264/h264_color_space.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "system_wrappers/include/field_trial.h"
#include "system_wrappers/include/metrics.h"
#include "third_party/libyuv/include/libyuv/convert.h"
namespace webrtc {
namespace {
Revert "Added support for H264 YUV444 (I444) decoding." This reverts commit 3babb8af238a531cbff27951604b09bb78b762cd. Reason for revert: - Causes regressions to transceivers, see https://crbug.com/1291956 for more information, including tests to reproduce the issue. This CL is not a pure revert. While it reverts everything else, it does keep the new enum value (kProfilePredictiveHigh444). This is as to not break Chromium which already depend on it. It is not listed in the kProfilePatterns though so the enum value should never be applicable. Original change's description: > Added support for H264 YUV444 (I444) decoding. > > Added Nutanix Inc. to the AUTHORS file. > > PS#1 is a reland of "Added support for H264 YUV444 (I444) decoding." https://webrtc-review.googlesource.com/c/src/+/234540 > > Bug: chromium:1251096 > Change-Id: I99a1b1e4d8b60192ff96f92334a430240875c66c > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/235340 > Reviewed-by: Niels Moller <nisse@webrtc.org> > Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#35684} # Not skipping CQ checks because original CL landed > 1 day ago. Bug: chromium:1251096, chromium:1291956 Change-Id: Ib4d8ea4898f9832914d88e7076e6b39da0c804ca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249791 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Auto-Submit: Henrik Boström <hbos@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35835}
2022-01-29 10:10:42 +01:00
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;
// Used by histograms. Values of entries should not be changed.
enum H264DecoderImplEvent {
kH264DecoderEventInit = 0,
kH264DecoderEventError = 1,
kH264DecoderEventMax = 16,
};
struct ScopedPtrAVFreePacket {
void operator()(AVPacket* packet) { av_packet_free(&packet); }
};
typedef std::unique_ptr<AVPacket, ScopedPtrAVFreePacket> ScopedAVPacket;
ScopedAVPacket MakeScopedAVPacket() {
ScopedAVPacket packet(av_packet_alloc());
return packet;
}
} // namespace
int H264DecoderImpl::AVGetBuffer2(AVCodecContext* context,
AVFrame* av_frame,
int flags) {
// Set in `Configure`.
H264DecoderImpl* decoder = static_cast<H264DecoderImpl*>(context->opaque);
// DCHECK values set in `Configure`.
RTC_DCHECK(decoder);
// 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.
Revert "Added support for H264 YUV444 (I444) decoding." This reverts commit 3babb8af238a531cbff27951604b09bb78b762cd. Reason for revert: - Causes regressions to transceivers, see https://crbug.com/1291956 for more information, including tests to reproduce the issue. This CL is not a pure revert. While it reverts everything else, it does keep the new enum value (kProfilePredictiveHigh444). This is as to not break Chromium which already depend on it. It is not listed in the kProfilePatterns though so the enum value should never be applicable. Original change's description: > Added support for H264 YUV444 (I444) decoding. > > Added Nutanix Inc. to the AUTHORS file. > > PS#1 is a reland of "Added support for H264 YUV444 (I444) decoding." https://webrtc-review.googlesource.com/c/src/+/234540 > > Bug: chromium:1251096 > Change-Id: I99a1b1e4d8b60192ff96f92334a430240875c66c > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/235340 > Reviewed-by: Niels Moller <nisse@webrtc.org> > Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#35684} # Not skipping CQ checks because original CL landed > 1 day ago. Bug: chromium:1251096, chromium:1291956 Change-Id: Ib4d8ea4898f9832914d88e7076e6b39da0c804ca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249791 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Auto-Submit: Henrik Boström <hbos@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35835}
2022-01-29 10:10:42 +01:00
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.
int width = av_frame->width;
int height = av_frame->height;
// See `lowres`, if used the decoder scales the image by 1/2^(lowres). This
// has implications on which resolutions are valid, but we don't use it.
RTC_CHECK_EQ(context->lowres, 0);
// Adjust the `width` and `height` to values acceptable by the decoder.
// Without this, FFmpeg may overflow the buffer. If modified, `width` and/or
// `height` are larger than the actual image and the image has to be cropped
// (top-left corner) after decoding to avoid visible borders to the right and
// bottom of the actual image.
avcodec_align_dimensions(context, &width, &height);
RTC_CHECK_GE(width, 0);
RTC_CHECK_GE(height, 0);
int ret = av_image_check_size(static_cast<unsigned int>(width),
static_cast<unsigned int>(height), 0, nullptr);
if (ret < 0) {
RTC_LOG(LS_ERROR) << "Invalid picture size " << width << "x" << height;
decoder->ReportError();
return ret;
}
// The video frame is stored in `frame_buffer`. `av_frame` is FFmpeg's version
// of a video frame and will be set up to reference `frame_buffer`'s data.
Partial reland of Delete unused and almost unused frame-related methods. (patchset #1 id:1 of https://codereview.webrtc.org/2076113002/ ) Reason for revert: Taking out the VideoFrameBuffer changes which broke downstream. Original issue's description: > Revert of Delete unused and almost unused frame-related methods. (patchset #12 id:220001 of https://codereview.webrtc.org/2065733003/ ) > > Reason for revert: > Breaks downstream applications which inherits webrtc::VideoFrameBuffer and tries to override deleted methods data(), stride() and MutableData(). > > Original issue's description: > > Delete unused and almost unused frame-related methods. > > > > webrtc::VideoFrame::set_video_frame_buffer > > webrtc::VideoFrame::ConvertNativeToI420Frame > > > > cricket::WebRtcVideoFrame::InitToBlack > > > > VideoFrameBuffer::data > > VideoFrameBuffer::stride > > VideoFrameBuffer::MutableData > > > > TBR=tkchin@webrtc.org # Refactoring affecting RTCVideoFrame > > BUG=webrtc:5682 > > > > Committed: https://crrev.com/76270de4bc2dac188f10f805e6e2fb86693ef864 > > Cr-Commit-Position: refs/heads/master@{#13183} > > TBR=perkj@webrtc.org,pbos@webrtc.org,marpan@webrtc.org,tkchin@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:5682 > > Committed: https://crrev.com/72e735d3867a0fd6ab7e4d0761c7ba5f6c068617 > Cr-Commit-Position: refs/heads/master@{#13184} TBR=perkj@webrtc.org,pbos@webrtc.org,marpan@webrtc.org,tkchin@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=webrtc:5682 Review-Url: https://codereview.webrtc.org/2076123002 Cr-Commit-Position: refs/heads/master@{#13189}
2016-06-17 05:03:04 -07:00
// FFmpeg expects the initial allocation to be zero-initialized according to
// http://crbug.com/390941. Our pool is set up to zero-initialize new buffers.
// TODO(nisse): Delete that feature from the video pool, instead add
// an explicit call to InitializeData here.
Revert "Added support for H264 YUV444 (I444) decoding." This reverts commit 3babb8af238a531cbff27951604b09bb78b762cd. Reason for revert: - Causes regressions to transceivers, see https://crbug.com/1291956 for more information, including tests to reproduce the issue. This CL is not a pure revert. While it reverts everything else, it does keep the new enum value (kProfilePredictiveHigh444). This is as to not break Chromium which already depend on it. It is not listed in the kProfilePatterns though so the enum value should never be applicable. Original change's description: > Added support for H264 YUV444 (I444) decoding. > > Added Nutanix Inc. to the AUTHORS file. > > PS#1 is a reland of "Added support for H264 YUV444 (I444) decoding." https://webrtc-review.googlesource.com/c/src/+/234540 > > Bug: chromium:1251096 > Change-Id: I99a1b1e4d8b60192ff96f92334a430240875c66c > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/235340 > Reviewed-by: Niels Moller <nisse@webrtc.org> > Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#35684} # Not skipping CQ checks because original CL landed > 1 day ago. Bug: chromium:1251096, chromium:1291956 Change-Id: Ib4d8ea4898f9832914d88e7076e6b39da0c804ca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249791 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Auto-Submit: Henrik Boström <hbos@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35835}
2022-01-29 10:10:42 +01:00
rtc::scoped_refptr<I420Buffer> frame_buffer =
decoder->ffmpeg_buffer_pool_.CreateI420Buffer(width, height);
Partial reland of Delete unused and almost unused frame-related methods. (patchset #1 id:1 of https://codereview.webrtc.org/2076113002/ ) Reason for revert: Taking out the VideoFrameBuffer changes which broke downstream. Original issue's description: > Revert of Delete unused and almost unused frame-related methods. (patchset #12 id:220001 of https://codereview.webrtc.org/2065733003/ ) > > Reason for revert: > Breaks downstream applications which inherits webrtc::VideoFrameBuffer and tries to override deleted methods data(), stride() and MutableData(). > > Original issue's description: > > Delete unused and almost unused frame-related methods. > > > > webrtc::VideoFrame::set_video_frame_buffer > > webrtc::VideoFrame::ConvertNativeToI420Frame > > > > cricket::WebRtcVideoFrame::InitToBlack > > > > VideoFrameBuffer::data > > VideoFrameBuffer::stride > > VideoFrameBuffer::MutableData > > > > TBR=tkchin@webrtc.org # Refactoring affecting RTCVideoFrame > > BUG=webrtc:5682 > > > > Committed: https://crrev.com/76270de4bc2dac188f10f805e6e2fb86693ef864 > > Cr-Commit-Position: refs/heads/master@{#13183} > > TBR=perkj@webrtc.org,pbos@webrtc.org,marpan@webrtc.org,tkchin@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:5682 > > Committed: https://crrev.com/72e735d3867a0fd6ab7e4d0761c7ba5f6c068617 > Cr-Commit-Position: refs/heads/master@{#13184} TBR=perkj@webrtc.org,pbos@webrtc.org,marpan@webrtc.org,tkchin@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=webrtc:5682 Review-Url: https://codereview.webrtc.org/2076123002 Cr-Commit-Position: refs/heads/master@{#13189}
2016-06-17 05:03:04 -07:00
int y_size = width * height;
Revert "Revert "Update video_coding/codecs to new VideoFrameBuffer interface"" This reverts commit 88f94fa36aa61f7904d30251205c544ada2c4301. Chromium code has been updated. Original change's description: > Revert "Update video_coding/codecs to new VideoFrameBuffer interface" > > This reverts commit 20ebf4ede803cd4f628ef9378700f60b72f2eab0. > > Reason for revert: > > Suspect of breaking FYI bots. > See https://build.chromium.org/p/chromium.webrtc.fyi/builders/Win7%20Tester/builds/9036 and others. > > Sample logs: > Backtrace: > [5024:1036:0607/173649.857:FATAL:webrtc_video_frame_adapter.cc(98)] Check failed: false. > Backtrace: > base::debug::StackTrace::StackTrace [0x02D04A37+55] > base::debug::StackTrace::StackTrace [0x02CCBB8A+10] > content::WebRtcVideoFrameAdapter::NativeToI420Buffer [0x0508AD71+305] > webrtc::VideoFrameBuffer::ToI420 [0x0230BF67+39] > webrtc::H264EncoderImpl::Encode [0x057E8D0B+267] > webrtc::VCMGenericEncoder::Encode [0x057E0E34+333] > webrtc::vcm::VideoSender::AddVideoFrame [0x057DED9B+796] > webrtc::ViEEncoder::EncodeVideoFrame [0x057C00F6+884] > webrtc::ViEEncoder::EncodeTask::Run [0x057C12D7+215] > rtc::TaskQueue::PostTask [0x03EE5CFB+194] > base::internal::Invoker<base::internal::BindState<enum extensions::`anonymous namespace'::VerificationResult (__cdecl*)(std::unique_ptr<extensions::NetworkingCastPrivateDelegate::Credentials,std::default_delete<extensions::NetworkingCastPrivateDelegate::C [0x02DDCAA5+31] > base::internal::Invoker<base::internal::BindState<enum extensions::`anonymous namespace'::VerificationResult (__cdecl*)(std::unique_ptr<extensions::NetworkingCastPrivateDelegate::Credentials,std::default_delete<extensions::NetworkingCastPrivateDelegate::C [0x02DDEE86+22] > base::debug::TaskAnnotator::RunTask [0x02D08289+409] > base::MessageLoop::RunTask [0x02C8CEC1+1233] > base::MessageLoop::DoWork [0x02C8C1AD+765] > base::MessagePumpDefault::Run [0x02D0A20B+219] > base::MessageLoop::Run [0x02C8C9DB+107] > base::RunLoop::Run [0x02C89583+147] > base::Thread::Run [0x02CBEFCD+173] > base::Thread::ThreadMain [0x02CBFADE+622] > base::PlatformThread::Sleep [0x02C9E1A2+290] > BaseThreadInitThunk [0x75C3338A+18] > RtlInitializeExceptionChain [0x773A9902+99] > RtlInitializeExceptionChain [0x773A98D5+54] > > Original change's description: > > Update video_coding/codecs to new VideoFrameBuffer interface > > > > This is a follow-up cleanup for CL > > https://codereview.webrtc.org/2847383002/. > > > > Bug: webrtc:7632 > > Change-Id: I47861d779968f2fee94db9c017102a8e87e67fb7 > > Reviewed-on: https://chromium-review.googlesource.com/524163 > > Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> > > Reviewed-by: Niels Moller <nisse@webrtc.org> > > Commit-Queue: Magnus Jedvert <magjed@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#18477} > > TBR=magjed@webrtc.org,nisse@webrtc.org,brandtr@webrtc.org > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:7632 > > Change-Id: I3b73fc7d16ff19ceba196e964dcb36a36510912c > Reviewed-on: https://chromium-review.googlesource.com/527793 > Reviewed-by: Guido Urdaneta <guidou@chromium.org> > Commit-Queue: Guido Urdaneta <guidou@chromium.org> > Cr-Commit-Position: refs/heads/master@{#18489} TBR=tterriberry@mozilla.com,mflodman@webrtc.org,magjed@webrtc.org,stefan@webrtc.org,guidou@chromium.org,nisse@webrtc.org,brandtr@webrtc.org,webrtc-reviews@webrtc.org # Not skipping CQ checks because original CL landed > 1 day ago. No-Presubmit: true Bug: webrtc:7632 Change-Id: I0962a704e8a9939d4364ce9069c863c9951654c9 Reviewed-on: https://chromium-review.googlesource.com/530684 Commit-Queue: Magnus Jedvert <magjed@webrtc.org> Reviewed-by: Magnus Jedvert <magjed@webrtc.org> Cr-Commit-Position: refs/heads/master@{#18527}
2017-06-10 17:03:37 +00:00
int uv_size = frame_buffer->ChromaWidth() * frame_buffer->ChromaHeight();
// DCHECK that we have a continuous buffer as is required.
RTC_DCHECK_EQ(frame_buffer->DataU(), frame_buffer->DataY() + y_size);
RTC_DCHECK_EQ(frame_buffer->DataV(), frame_buffer->DataU() + uv_size);
int total_size = y_size + 2 * uv_size;
av_frame->format = context->pix_fmt;
av_frame->reordered_opaque = context->reordered_opaque;
Revert "Added support for H264 YUV444 (I444) decoding." This reverts commit 3babb8af238a531cbff27951604b09bb78b762cd. Reason for revert: - Causes regressions to transceivers, see https://crbug.com/1291956 for more information, including tests to reproduce the issue. This CL is not a pure revert. While it reverts everything else, it does keep the new enum value (kProfilePredictiveHigh444). This is as to not break Chromium which already depend on it. It is not listed in the kProfilePatterns though so the enum value should never be applicable. Original change's description: > Added support for H264 YUV444 (I444) decoding. > > Added Nutanix Inc. to the AUTHORS file. > > PS#1 is a reland of "Added support for H264 YUV444 (I444) decoding." https://webrtc-review.googlesource.com/c/src/+/234540 > > Bug: chromium:1251096 > Change-Id: I99a1b1e4d8b60192ff96f92334a430240875c66c > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/235340 > Reviewed-by: Niels Moller <nisse@webrtc.org> > Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#35684} # Not skipping CQ checks because original CL landed > 1 day ago. Bug: chromium:1251096, chromium:1291956 Change-Id: Ib4d8ea4898f9832914d88e7076e6b39da0c804ca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249791 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Auto-Submit: Henrik Boström <hbos@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35835}
2022-01-29 10:10:42 +01:00
// Set `av_frame` members as required by FFmpeg.
av_frame->data[kYPlaneIndex] = frame_buffer->MutableDataY();
av_frame->linesize[kYPlaneIndex] = frame_buffer->StrideY();
av_frame->data[kUPlaneIndex] = frame_buffer->MutableDataU();
av_frame->linesize[kUPlaneIndex] = frame_buffer->StrideU();
av_frame->data[kVPlaneIndex] = frame_buffer->MutableDataV();
av_frame->linesize[kVPlaneIndex] = frame_buffer->StrideV();
RTC_DCHECK_EQ(av_frame->extended_data, av_frame->data);
// Create a VideoFrame object, to keep a reference to the buffer.
// TODO(nisse): The VideoFrame's timestamp and rotation info is not used.
// Refactor to do not use a VideoFrame object at all.
av_frame->buf[0] = av_buffer_create(
av_frame->data[kYPlaneIndex], total_size, AVFreeBuffer2,
Use std::make_unique instead of absl::make_unique. WebRTC is now using C++14 so there is no need to use the Abseil version of std::make_unique. This CL has been created with the following steps: git grep -l absl::make_unique | sort | uniq > /tmp/make_unique.txt git grep -l absl::WrapUnique | sort | uniq > /tmp/wrap_unique.txt git grep -l "#include <memory>" | sort | uniq > /tmp/memory.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/make_unique.txt /tmp/wrap_unique.txt | sort | \ uniq > /tmp/only_make_unique.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/only_make_unique.txt /tmp/memory.txt | \ xargs grep -l "absl/memory" > /tmp/add-memory.txt git grep -l "\babsl::make_unique\b" | \ xargs sed -i "s/\babsl::make_unique\b/std::make_unique/g" git checkout PRESUBMIT.py abseil-in-webrtc.md cat /tmp/add-memory.txt | \ xargs sed -i \ 's/#include "absl\/memory\/memory.h"/#include <memory>/g' git cl format # Manual fix order of the new inserted #include <memory> cat /tmp/only_make_unique | xargs grep -l "#include <memory>" | \ xargs sed -i '/#include "absl\/memory\/memory.h"/d' git ls-files | grep BUILD.gn | \ xargs sed -i '/\/\/third_party\/abseil-cpp\/absl\/memory/d' python tools_webrtc/gn_check_autofix.py \ -m tryserver.webrtc -b linux_rel # Repead the gn_check_autofix step for other platforms git ls-files | grep BUILD.gn | \ xargs sed -i 's/absl\/memory:memory/absl\/memory/g' git cl format Bug: webrtc:10945 Change-Id: I3fe28ea80f4dd3ba3cf28effd151d5e1f19aff89 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/153221 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29209}
2019-09-17 17:06:18 +02:00
static_cast<void*>(
std::make_unique<VideoFrame>(VideoFrame::Builder()
.set_video_frame_buffer(frame_buffer)
.set_rotation(kVideoRotation_0)
.set_timestamp_us(0)
.build())
.release()),
0);
RTC_CHECK(av_frame->buf[0]);
return 0;
}
void H264DecoderImpl::AVFreeBuffer2(void* opaque, uint8_t* data) {
// The buffer pool recycles the buffer used by `video_frame` when there are no
// more references to it. `video_frame` is a thin buffer holder and is not
// recycled.
VideoFrame* video_frame = static_cast<VideoFrame*>(opaque);
delete video_frame;
}
H264DecoderImpl::H264DecoderImpl()
: ffmpeg_buffer_pool_(true),
decoded_image_callback_(nullptr),
has_reported_init_(false),
has_reported_error_(false),
preferred_output_format_(field_trial::IsEnabled("WebRTC-NV12Decode")
? VideoFrameBuffer::Type::kNV12
: VideoFrameBuffer::Type::kI420) {}
H264DecoderImpl::~H264DecoderImpl() {
Release();
}
bool H264DecoderImpl::Configure(const Settings& settings) {
ReportInit();
if (settings.codec_type() != kVideoCodecH264) {
ReportError();
return false;
}
// Release necessary in case of re-initializing.
int32_t ret = Release();
if (ret != WEBRTC_VIDEO_CODEC_OK) {
ReportError();
return false;
}
RTC_DCHECK(!av_context_);
// Initialize AVCodecContext.
av_context_.reset(avcodec_alloc_context3(nullptr));
av_context_->codec_type = AVMEDIA_TYPE_VIDEO;
av_context_->codec_id = AV_CODEC_ID_H264;
const RenderResolution& resolution = settings.max_render_resolution();
if (resolution.Valid()) {
av_context_->coded_width = resolution.Width();
av_context_->coded_height = resolution.Height();
}
Revert "Added support for H264 YUV444 (I444) decoding." This reverts commit 3babb8af238a531cbff27951604b09bb78b762cd. Reason for revert: - Causes regressions to transceivers, see https://crbug.com/1291956 for more information, including tests to reproduce the issue. This CL is not a pure revert. While it reverts everything else, it does keep the new enum value (kProfilePredictiveHigh444). This is as to not break Chromium which already depend on it. It is not listed in the kProfilePatterns though so the enum value should never be applicable. Original change's description: > Added support for H264 YUV444 (I444) decoding. > > Added Nutanix Inc. to the AUTHORS file. > > PS#1 is a reland of "Added support for H264 YUV444 (I444) decoding." https://webrtc-review.googlesource.com/c/src/+/234540 > > Bug: chromium:1251096 > Change-Id: I99a1b1e4d8b60192ff96f92334a430240875c66c > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/235340 > Reviewed-by: Niels Moller <nisse@webrtc.org> > Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#35684} # Not skipping CQ checks because original CL landed > 1 day ago. Bug: chromium:1251096, chromium:1291956 Change-Id: Ib4d8ea4898f9832914d88e7076e6b39da0c804ca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249791 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Auto-Submit: Henrik Boström <hbos@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35835}
2022-01-29 10:10:42 +01:00
av_context_->pix_fmt = kPixelFormatDefault;
av_context_->extradata = nullptr;
av_context_->extradata_size = 0;
// If this is ever increased, look at `av_context_->thread_safe_callbacks` and
// make it possible to disable the thread checker in the frame buffer pool.
av_context_->thread_count = 1;
av_context_->thread_type = FF_THREAD_SLICE;
// Function used by FFmpeg to get buffers to store decoded frames in.
av_context_->get_buffer2 = AVGetBuffer2;
// `get_buffer2` is called with the context, there `opaque` can be used to get
// a pointer `this`.
av_context_->opaque = this;
const AVCodec* codec = avcodec_find_decoder(av_context_->codec_id);
if (!codec) {
// This is an indication that FFmpeg has not been initialized or it has not
// been compiled/initialized with the correct set of codecs.
RTC_LOG(LS_ERROR) << "FFmpeg H.264 decoder not found.";
Release();
ReportError();
return false;
}
int res = avcodec_open2(av_context_.get(), codec, nullptr);
if (res < 0) {
RTC_LOG(LS_ERROR) << "avcodec_open2 error: " << res;
Release();
ReportError();
return false;
}
av_frame_.reset(av_frame_alloc());
if (absl::optional<int> buffer_pool_size = settings.buffer_pool_size()) {
if (!ffmpeg_buffer_pool_.Resize(*buffer_pool_size) ||
!output_buffer_pool_.Resize(*buffer_pool_size)) {
return false;
}
}
return true;
}
int32_t H264DecoderImpl::Release() {
av_context_.reset();
av_frame_.reset();
return WEBRTC_VIDEO_CODEC_OK;
}
int32_t H264DecoderImpl::RegisterDecodeCompleteCallback(
DecodedImageCallback* callback) {
decoded_image_callback_ = callback;
return WEBRTC_VIDEO_CODEC_OK;
}
int32_t H264DecoderImpl::Decode(const EncodedImage& input_image,
bool /*missing_frames*/,
int64_t /*render_time_ms*/) {
if (!IsInitialized()) {
ReportError();
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
}
if (!decoded_image_callback_) {
RTC_LOG(LS_WARNING)
<< "Configure() has been called, but a callback function "
"has not been set with RegisterDecodeCompleteCallback()";
ReportError();
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
}
if (!input_image.data() || !input_image.size()) {
ReportError();
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
}
ScopedAVPacket packet = MakeScopedAVPacket();
if (!packet) {
ReportError();
return WEBRTC_VIDEO_CODEC_ERROR;
}
// packet.data has a non-const type, but isn't modified by
// avcodec_send_packet.
packet->data = const_cast<uint8_t*>(input_image.data());
if (input_image.size() >
static_cast<size_t>(std::numeric_limits<int>::max())) {
ReportError();
return WEBRTC_VIDEO_CODEC_ERROR;
}
packet->size = static_cast<int>(input_image.size());
int64_t frame_timestamp_us = input_image.ntp_time_ms_ * 1000; // ms -> μs
av_context_->reordered_opaque = frame_timestamp_us;
int result = avcodec_send_packet(av_context_.get(), packet.get());
if (result < 0) {
RTC_LOG(LS_ERROR) << "avcodec_send_packet error: " << result;
ReportError();
return WEBRTC_VIDEO_CODEC_ERROR;
}
result = avcodec_receive_frame(av_context_.get(), av_frame_.get());
if (result < 0) {
RTC_LOG(LS_ERROR) << "avcodec_receive_frame error: " << result;
ReportError();
return WEBRTC_VIDEO_CODEC_ERROR;
}
// We don't expect reordering. Decoded frame timestamp should match
// the input one.
RTC_DCHECK_EQ(av_frame_->reordered_opaque, frame_timestamp_us);
// TODO(sakal): Maybe it is possible to get QP directly from FFmpeg.
h264_bitstream_parser_.ParseBitstream(input_image);
absl::optional<int> qp = h264_bitstream_parser_.GetLastSliceQp();
Partial reland of Delete unused and almost unused frame-related methods. (patchset #1 id:1 of https://codereview.webrtc.org/2076113002/ ) Reason for revert: Taking out the VideoFrameBuffer changes which broke downstream. Original issue's description: > Revert of Delete unused and almost unused frame-related methods. (patchset #12 id:220001 of https://codereview.webrtc.org/2065733003/ ) > > Reason for revert: > Breaks downstream applications which inherits webrtc::VideoFrameBuffer and tries to override deleted methods data(), stride() and MutableData(). > > Original issue's description: > > Delete unused and almost unused frame-related methods. > > > > webrtc::VideoFrame::set_video_frame_buffer > > webrtc::VideoFrame::ConvertNativeToI420Frame > > > > cricket::WebRtcVideoFrame::InitToBlack > > > > VideoFrameBuffer::data > > VideoFrameBuffer::stride > > VideoFrameBuffer::MutableData > > > > TBR=tkchin@webrtc.org # Refactoring affecting RTCVideoFrame > > BUG=webrtc:5682 > > > > Committed: https://crrev.com/76270de4bc2dac188f10f805e6e2fb86693ef864 > > Cr-Commit-Position: refs/heads/master@{#13183} > > TBR=perkj@webrtc.org,pbos@webrtc.org,marpan@webrtc.org,tkchin@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:5682 > > Committed: https://crrev.com/72e735d3867a0fd6ab7e4d0761c7ba5f6c068617 > Cr-Commit-Position: refs/heads/master@{#13184} TBR=perkj@webrtc.org,pbos@webrtc.org,marpan@webrtc.org,tkchin@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=webrtc:5682 Review-Url: https://codereview.webrtc.org/2076123002 Cr-Commit-Position: refs/heads/master@{#13189}
2016-06-17 05:03:04 -07:00
// Obtain the `video_frame` containing the decoded image.
VideoFrame* input_frame =
static_cast<VideoFrame*>(av_buffer_get_opaque(av_frame_->buf[0]));
RTC_DCHECK(input_frame);
rtc::scoped_refptr<VideoFrameBuffer> frame_buffer =
input_frame->video_frame_buffer();
Revert "Added support for H264 YUV444 (I444) decoding." This reverts commit 3babb8af238a531cbff27951604b09bb78b762cd. Reason for revert: - Causes regressions to transceivers, see https://crbug.com/1291956 for more information, including tests to reproduce the issue. This CL is not a pure revert. While it reverts everything else, it does keep the new enum value (kProfilePredictiveHigh444). This is as to not break Chromium which already depend on it. It is not listed in the kProfilePatterns though so the enum value should never be applicable. Original change's description: > Added support for H264 YUV444 (I444) decoding. > > Added Nutanix Inc. to the AUTHORS file. > > PS#1 is a reland of "Added support for H264 YUV444 (I444) decoding." https://webrtc-review.googlesource.com/c/src/+/234540 > > Bug: chromium:1251096 > Change-Id: I99a1b1e4d8b60192ff96f92334a430240875c66c > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/235340 > Reviewed-by: Niels Moller <nisse@webrtc.org> > Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#35684} # Not skipping CQ checks because original CL landed > 1 day ago. Bug: chromium:1251096, chromium:1291956 Change-Id: Ib4d8ea4898f9832914d88e7076e6b39da0c804ca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249791 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Auto-Submit: Henrik Boström <hbos@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35835}
2022-01-29 10:10:42 +01:00
const webrtc::I420BufferInterface* i420_buffer = frame_buffer->GetI420();
// When needed, FFmpeg applies cropping by moving plane pointers and adjusting
// frame width/height. Ensure that cropped buffers lie within the allocated
// memory.
Revert "Added support for H264 YUV444 (I444) decoding." This reverts commit 3babb8af238a531cbff27951604b09bb78b762cd. Reason for revert: - Causes regressions to transceivers, see https://crbug.com/1291956 for more information, including tests to reproduce the issue. This CL is not a pure revert. While it reverts everything else, it does keep the new enum value (kProfilePredictiveHigh444). This is as to not break Chromium which already depend on it. It is not listed in the kProfilePatterns though so the enum value should never be applicable. Original change's description: > Added support for H264 YUV444 (I444) decoding. > > Added Nutanix Inc. to the AUTHORS file. > > PS#1 is a reland of "Added support for H264 YUV444 (I444) decoding." https://webrtc-review.googlesource.com/c/src/+/234540 > > Bug: chromium:1251096 > Change-Id: I99a1b1e4d8b60192ff96f92334a430240875c66c > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/235340 > Reviewed-by: Niels Moller <nisse@webrtc.org> > Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#35684} # Not skipping CQ checks because original CL landed > 1 day ago. Bug: chromium:1251096, chromium:1291956 Change-Id: Ib4d8ea4898f9832914d88e7076e6b39da0c804ca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249791 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Auto-Submit: Henrik Boström <hbos@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35835}
2022-01-29 10:10:42 +01:00
RTC_DCHECK_LE(av_frame_->width, i420_buffer->width());
RTC_DCHECK_LE(av_frame_->height, i420_buffer->height());
RTC_DCHECK_GE(av_frame_->data[kYPlaneIndex], i420_buffer->DataY());
RTC_DCHECK_LE(
av_frame_->data[kYPlaneIndex] +
av_frame_->linesize[kYPlaneIndex] * av_frame_->height,
i420_buffer->DataY() + i420_buffer->StrideY() * i420_buffer->height());
RTC_DCHECK_GE(av_frame_->data[kUPlaneIndex], i420_buffer->DataU());
RTC_DCHECK_LE(av_frame_->data[kUPlaneIndex] +
av_frame_->linesize[kUPlaneIndex] * av_frame_->height / 2,
Revert "Added support for H264 YUV444 (I444) decoding." This reverts commit 3babb8af238a531cbff27951604b09bb78b762cd. Reason for revert: - Causes regressions to transceivers, see https://crbug.com/1291956 for more information, including tests to reproduce the issue. This CL is not a pure revert. While it reverts everything else, it does keep the new enum value (kProfilePredictiveHigh444). This is as to not break Chromium which already depend on it. It is not listed in the kProfilePatterns though so the enum value should never be applicable. Original change's description: > Added support for H264 YUV444 (I444) decoding. > > Added Nutanix Inc. to the AUTHORS file. > > PS#1 is a reland of "Added support for H264 YUV444 (I444) decoding." https://webrtc-review.googlesource.com/c/src/+/234540 > > Bug: chromium:1251096 > Change-Id: I99a1b1e4d8b60192ff96f92334a430240875c66c > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/235340 > Reviewed-by: Niels Moller <nisse@webrtc.org> > Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#35684} # Not skipping CQ checks because original CL landed > 1 day ago. Bug: chromium:1251096, chromium:1291956 Change-Id: Ib4d8ea4898f9832914d88e7076e6b39da0c804ca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249791 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Auto-Submit: Henrik Boström <hbos@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35835}
2022-01-29 10:10:42 +01:00
i420_buffer->DataU() +
i420_buffer->StrideU() * i420_buffer->height() / 2);
RTC_DCHECK_GE(av_frame_->data[kVPlaneIndex], i420_buffer->DataV());
RTC_DCHECK_LE(av_frame_->data[kVPlaneIndex] +
av_frame_->linesize[kVPlaneIndex] * av_frame_->height / 2,
Revert "Added support for H264 YUV444 (I444) decoding." This reverts commit 3babb8af238a531cbff27951604b09bb78b762cd. Reason for revert: - Causes regressions to transceivers, see https://crbug.com/1291956 for more information, including tests to reproduce the issue. This CL is not a pure revert. While it reverts everything else, it does keep the new enum value (kProfilePredictiveHigh444). This is as to not break Chromium which already depend on it. It is not listed in the kProfilePatterns though so the enum value should never be applicable. Original change's description: > Added support for H264 YUV444 (I444) decoding. > > Added Nutanix Inc. to the AUTHORS file. > > PS#1 is a reland of "Added support for H264 YUV444 (I444) decoding." https://webrtc-review.googlesource.com/c/src/+/234540 > > Bug: chromium:1251096 > Change-Id: I99a1b1e4d8b60192ff96f92334a430240875c66c > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/235340 > Reviewed-by: Niels Moller <nisse@webrtc.org> > Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#35684} # Not skipping CQ checks because original CL landed > 1 day ago. Bug: chromium:1251096, chromium:1291956 Change-Id: Ib4d8ea4898f9832914d88e7076e6b39da0c804ca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249791 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Auto-Submit: Henrik Boström <hbos@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35835}
2022-01-29 10:10:42 +01:00
i420_buffer->DataV() +
i420_buffer->StrideV() * i420_buffer->height() / 2);
rtc::scoped_refptr<webrtc::VideoFrameBuffer> cropped_buffer = WrapI420Buffer(
av_frame_->width, av_frame_->height, av_frame_->data[kYPlaneIndex],
av_frame_->linesize[kYPlaneIndex], av_frame_->data[kUPlaneIndex],
av_frame_->linesize[kUPlaneIndex], av_frame_->data[kVPlaneIndex],
av_frame_->linesize[kVPlaneIndex],
// To keep reference alive.
[frame_buffer] {});
if (preferred_output_format_ == VideoFrameBuffer::Type::kNV12) {
Revert "Added support for H264 YUV444 (I444) decoding." This reverts commit 3babb8af238a531cbff27951604b09bb78b762cd. Reason for revert: - Causes regressions to transceivers, see https://crbug.com/1291956 for more information, including tests to reproduce the issue. This CL is not a pure revert. While it reverts everything else, it does keep the new enum value (kProfilePredictiveHigh444). This is as to not break Chromium which already depend on it. It is not listed in the kProfilePatterns though so the enum value should never be applicable. Original change's description: > Added support for H264 YUV444 (I444) decoding. > > Added Nutanix Inc. to the AUTHORS file. > > PS#1 is a reland of "Added support for H264 YUV444 (I444) decoding." https://webrtc-review.googlesource.com/c/src/+/234540 > > Bug: chromium:1251096 > Change-Id: I99a1b1e4d8b60192ff96f92334a430240875c66c > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/235340 > Reviewed-by: Niels Moller <nisse@webrtc.org> > Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#35684} # Not skipping CQ checks because original CL landed > 1 day ago. Bug: chromium:1251096, chromium:1291956 Change-Id: Ib4d8ea4898f9832914d88e7076e6b39da0c804ca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249791 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Auto-Submit: Henrik Boström <hbos@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35835}
2022-01-29 10:10:42 +01:00
const I420BufferInterface* cropped_i420 = cropped_buffer->GetI420();
auto nv12_buffer = output_buffer_pool_.CreateNV12Buffer(
Revert "Added support for H264 YUV444 (I444) decoding." This reverts commit 3babb8af238a531cbff27951604b09bb78b762cd. Reason for revert: - Causes regressions to transceivers, see https://crbug.com/1291956 for more information, including tests to reproduce the issue. This CL is not a pure revert. While it reverts everything else, it does keep the new enum value (kProfilePredictiveHigh444). This is as to not break Chromium which already depend on it. It is not listed in the kProfilePatterns though so the enum value should never be applicable. Original change's description: > Added support for H264 YUV444 (I444) decoding. > > Added Nutanix Inc. to the AUTHORS file. > > PS#1 is a reland of "Added support for H264 YUV444 (I444) decoding." https://webrtc-review.googlesource.com/c/src/+/234540 > > Bug: chromium:1251096 > Change-Id: I99a1b1e4d8b60192ff96f92334a430240875c66c > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/235340 > Reviewed-by: Niels Moller <nisse@webrtc.org> > Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#35684} # Not skipping CQ checks because original CL landed > 1 day ago. Bug: chromium:1251096, chromium:1291956 Change-Id: Ib4d8ea4898f9832914d88e7076e6b39da0c804ca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249791 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Auto-Submit: Henrik Boström <hbos@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35835}
2022-01-29 10:10:42 +01:00
cropped_i420->width(), cropped_i420->height());
libyuv::I420ToNV12(cropped_i420->DataY(), cropped_i420->StrideY(),
cropped_i420->DataU(), cropped_i420->StrideU(),
cropped_i420->DataV(), cropped_i420->StrideV(),
nv12_buffer->MutableDataY(), nv12_buffer->StrideY(),
nv12_buffer->MutableDataUV(), nv12_buffer->StrideUV(),
i420_buffer->width(), i420_buffer->height());
cropped_buffer = nv12_buffer;
}
// Pass on color space from input frame if explicitly specified.
const ColorSpace& color_space =
input_image.ColorSpace() ? *input_image.ColorSpace()
: ExtractH264ColorSpace(av_context_.get());
VideoFrame decoded_frame = VideoFrame::Builder()
.set_video_frame_buffer(cropped_buffer)
.set_timestamp_rtp(input_image.Timestamp())
.set_color_space(color_space)
.build();
// Return decoded frame.
// TODO(nisse): Timestamp and rotation are all zero here. Change decoder
// interface to pass a VideoFrameBuffer instead of a VideoFrame?
decoded_image_callback_->Decoded(decoded_frame, absl::nullopt, qp);
// Stop referencing it, possibly freeing `input_frame`.
av_frame_unref(av_frame_.get());
input_frame = nullptr;
return WEBRTC_VIDEO_CODEC_OK;
}
const char* H264DecoderImpl::ImplementationName() const {
return "FFmpeg";
}
bool H264DecoderImpl::IsInitialized() const {
return av_context_ != nullptr;
}
void H264DecoderImpl::ReportInit() {
if (has_reported_init_)
return;
RTC_HISTOGRAM_ENUMERATION("WebRTC.Video.H264DecoderImpl.Event",
kH264DecoderEventInit, kH264DecoderEventMax);
has_reported_init_ = true;
}
void H264DecoderImpl::ReportError() {
if (has_reported_error_)
return;
RTC_HISTOGRAM_ENUMERATION("WebRTC.Video.H264DecoderImpl.Event",
kH264DecoderEventError, kH264DecoderEventMax);
has_reported_error_ = true;
}
} // namespace webrtc
#endif // WEBRTC_USE_H264