Migrate software decoders to new VideoDecoder::Configure

Bug: webrtc:13045
Change-Id: I1fa28a7c2dd59f0889d98c8ec5f58161c0ec9f95
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/228380
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34716}
This commit is contained in:
Danil Chapovalov
2021-08-10 14:33:31 +02:00
committed by WebRTC LUCI CQ
parent bf75041b8d
commit 53d4be223b
14 changed files with 98 additions and 110 deletions

View File

@ -69,9 +69,9 @@ ScopedAVPacket MakeScopedAVPacket() {
int H264DecoderImpl::AVGetBuffer2(AVCodecContext* context,
AVFrame* av_frame,
int flags) {
// Set in `InitDecode`.
// Set in `Configure`.
H264DecoderImpl* decoder = static_cast<H264DecoderImpl*>(context->opaque);
// DCHECK values set in `InitDecode`.
// 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);
@ -172,19 +172,18 @@ H264DecoderImpl::~H264DecoderImpl() {
Release();
}
int32_t H264DecoderImpl::InitDecode(const VideoCodec* codec_settings,
int32_t number_of_cores) {
bool H264DecoderImpl::Configure(const Settings& settings) {
ReportInit();
if (codec_settings && codec_settings->codecType != kVideoCodecH264) {
if (settings.codec_type() != kVideoCodecH264) {
ReportError();
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
return false;
}
// Release necessary in case of re-initializing.
int32_t ret = Release();
if (ret != WEBRTC_VIDEO_CODEC_OK) {
ReportError();
return ret;
return false;
}
RTC_DCHECK(!av_context_);
@ -193,9 +192,10 @@ int32_t H264DecoderImpl::InitDecode(const VideoCodec* codec_settings,
av_context_->codec_type = AVMEDIA_TYPE_VIDEO;
av_context_->codec_id = AV_CODEC_ID_H264;
if (codec_settings) {
av_context_->coded_width = codec_settings->width;
av_context_->coded_height = codec_settings->height;
const RenderResolution& resolution = settings.max_render_resolution();
if (resolution.Valid()) {
av_context_->coded_width = resolution.Width();
av_context_->coded_height = resolution.Height();
}
av_context_->pix_fmt = kPixelFormatDefault;
av_context_->extradata = nullptr;
@ -219,25 +219,25 @@ int32_t H264DecoderImpl::InitDecode(const VideoCodec* codec_settings,
RTC_LOG(LS_ERROR) << "FFmpeg H.264 decoder not found.";
Release();
ReportError();
return WEBRTC_VIDEO_CODEC_ERROR;
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 WEBRTC_VIDEO_CODEC_ERROR;
return false;
}
av_frame_.reset(av_frame_alloc());
if (codec_settings && codec_settings->buffer_pool_size) {
if (!ffmpeg_buffer_pool_.Resize(*codec_settings->buffer_pool_size) ||
!output_buffer_pool_.Resize(*codec_settings->buffer_pool_size)) {
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
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 WEBRTC_VIDEO_CODEC_OK;
return true;
}
int32_t H264DecoderImpl::Release() {
@ -261,7 +261,7 @@ int32_t H264DecoderImpl::Decode(const EncodedImage& input_image,
}
if (!decoded_image_callback_) {
RTC_LOG(LS_WARNING)
<< "InitDecode() has been called, but a callback function "
<< "Configure() has been called, but a callback function "
"has not been set with RegisterDecodeCompleteCallback()";
ReportError();
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;