From patchwork Wed Jul 12 22:07:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 42618 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp2496233pzb; Wed, 12 Jul 2023 15:08:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlH/SNEAcQPj9+ed6+UJiVASuRgB4wkPT/RtrdKMmMNt93ONnKl3Xxq2sbk58U84mAM6biIr X-Received: by 2002:a05:6512:b8c:b0:4f9:556b:93c2 with SMTP id b12-20020a0565120b8c00b004f9556b93c2mr20706627lfv.1.1689199692363; Wed, 12 Jul 2023 15:08:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689199692; cv=none; d=google.com; s=arc-20160816; b=N+Re1MzfWLBHmrb5PTC7VJNg/z4S13cU0FYZ5F4SyQjWNpL9f3mkkEzhDTc2Bbvzmg Pr0CmHWq7vLkCMNXKtDF0mJ1CPNmVu9UgPDBZphWAiHXhjRwRPSYptCD+jI6/YasLWHb /OqklbAGVt11I4nhs/DdVjfIEP1Ot0RMqtvnaf42sf48IWpzF3/L6sx4BDYGFwDnNTDd uT0iYOTt9RC9as/hrEKrAZKFahg/4374MTzBAXu7YSr13Ni4sxPh9z2aLjgJcrBwRmQt oX00nBXiqq1IYcR+2WGGqPFY3/UPk4DgWTQx9tSWJyY/2ipomuWjpQc69pI/E0Xj3Vj4 SCjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=ry1Kc7mmxvH3v9E23EbCk9L+O4uQH4CtDjQrsV1wD8k=; fh=J3zlMo7rVW2t2IQYogliBcMNuBh6YQg7NRChcrschf4=; b=n2vWOscTTj/IFWAG/mR/cI+vef7Sru5EvjTk8ThOewexRLdIV4tS1TplXa02RN2rc9 OvKPpE+jwBhXEvOIxdsVRfnUZt0KkesERu6nZ7wlPuKSR3OaaGSUptiteGRarK86aZWY hCtPL1yrdMOv1BokqPk3GvIj6nEmmf1D3lUrHHBn5fWp9yKwalgNxayOmXq2YlW9dKrd kV6SV/V/js/U1r243x2PfG9jIBWOqNTqlQnYqkRhDUG4jD7be9Jn9/D5EgxRBPbwc263 +Ga4TLmOgQOAdsguqdc/FqUhSr6B26Yli5iOTSqhJqYic6Ib4uV+OiW7p4tkg/4rNTaI zDfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=KT4b7Rf7; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id x26-20020aa7d6da000000b0051e0591969dsi5423187edr.345.2023.07.12.15.08.12; Wed, 12 Jul 2023 15:08:12 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=KT4b7Rf7; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4B74D68C5F6; Thu, 13 Jul 2023 01:07:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oa1-f54.google.com (mail-oa1-f54.google.com [209.85.160.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ABE2268C499 for ; Thu, 13 Jul 2023 01:07:41 +0300 (EEST) Received: by mail-oa1-f54.google.com with SMTP id 586e51a60fabf-1b012c3ce43so6021076fac.3 for ; Wed, 12 Jul 2023 15:07:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689199660; x=1691791660; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=OHtmE5iig4GoTiyr6qu+dMlS6NqZFb4rMUxewH8MsGc=; b=KT4b7Rf7VpvIjnjViRHYf39oxLcEaaMihXAC2qne3CHsh2NiZoxtOpVbWvErTFQbDn XdeTMZ12/UkQNzYRSmgCB1hzc2l3AoAX2555ohEgp/KFAI8VKqdXHB9pw1lAYLsBjRsG JuIt4CG8WpeQXE0hhquo34yk8kmHBw1ECzJS/9yGRMViYYyp1mjz92QuLeAoRevmCbu2 ycaVbH0eR5Jbrow6OfwvJeUVGFUrgTrnUJ6X8zHUkH6zDf2lZGgpK/VETbmv+ePmEjCM BplqYKOzF0GOp4AMtJmgEoQpoDVBDExHFFTkPVs50AryoOxOm7lg7P2FwarN6U0tquQh Mu4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689199660; x=1691791660; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OHtmE5iig4GoTiyr6qu+dMlS6NqZFb4rMUxewH8MsGc=; b=FYUw13BiwyJGqY+McgiQLfXNpSKYFW8xmJL1qOE8PhAhkKkoAjKjRP8QXuqRZK8l4Q II8dXvHpY4xIzV9Q45Bt86VSefzeIiLiJFH7E4TnyTl9DmnJfbl+OT3FDFUENQsFd4gI KoOff2Jf3Pssc1Zycjga14QSzSl0nMnBx7NgMiUBmpTirlPJ/qO/DvjSTWvLo6HLkB3l RJsPfDqFCfFk7YnXpOcxAh/FTr0PnKCTfZmSbXphPOeDAHozB97FzYzy9Wg3OGloQaRR oWOTPjaohAofKLsB8E0wxzlajt2llM6DEQD7OjHQjdlR7VpB1i/zpNycXPmf4FNvaF52 EzGQ== X-Gm-Message-State: ABy/qLZiqnn/sVx4ojSPUQph7CX2YnfybqvS1LDRb6UHuYgyuSOs67Oe 195cnIbhJ1iGBMehrjVd1iljyfNFks4= X-Received: by 2002:a05:6870:ac1f:b0:1a9:caa1:9571 with SMTP id kw31-20020a056870ac1f00b001a9caa19571mr22281776oab.34.1689199660039; Wed, 12 Jul 2023 15:07:40 -0700 (PDT) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id v13-20020a056870e28d00b001b3d5b06b6asm2433756oad.23.2023.07.12.15.07.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 15:07:39 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jul 2023 19:07:11 -0300 Message-ID: <20230712220712.46338-3-jamrial@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230712220712.46338-1-jamrial@gmail.com> References: <20230712220712.46338-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 3/4] avcodec/decode: fill missing frame fields for all decoders X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: TxciWtRYPS5u And not just those with the old decode() API. Signed-off-by: James Almer --- libavcodec/decode.c | 65 ++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 57d38cbc54..d1aa183b78 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -292,7 +292,6 @@ static int64_t guess_correct_pts(AVCodecContext *ctx, static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples) { AVCodecInternal *avci = avctx->internal; - int ret = 0; AVFrameSideData *side; uint32_t discard_padding = 0; @@ -305,26 +304,6 @@ static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *disca avci->skip_samples, (int)discard_padding); } - if (frame->format == AV_SAMPLE_FMT_NONE) - frame->format = avctx->sample_fmt; - if (!frame->ch_layout.nb_channels) { - int ret2 = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout); - if (ret2 < 0) { - ret = ret2; - } - } -#if FF_API_OLD_CHANNEL_LAYOUT -FF_DISABLE_DEPRECATION_WARNINGS - if (!frame->channel_layout) - frame->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? - avctx->ch_layout.u.mask : 0; - if (!frame->channels) - frame->channels = avctx->ch_layout.nb_channels; -FF_ENABLE_DEPRECATION_WARNINGS -#endif - if (!frame->sample_rate) - frame->sample_rate = avctx->sample_rate; - if ((frame->flags & AV_FRAME_FLAG_DISCARD) && !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) { avci->skip_samples = FFMAX(0, avci->skip_samples - frame->nb_samples); @@ -387,7 +366,7 @@ FF_ENABLE_DEPRECATION_WARNINGS if (!(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) av_frame_remove_side_data(frame, AV_FRAME_DATA_SKIP_SAMPLES); - return ret; + return 0; } /* @@ -437,14 +416,6 @@ FF_DISABLE_DEPRECATION_WARNINGS frame->pkt_pos = pkt->pos; FF_ENABLE_DEPRECATION_WARNINGS #endif - //FIXME these should be under if(!avctx->has_b_frames) - /* get_buffer is supposed to set frame parameters */ - if (!(avctx->codec->capabilities & AV_CODEC_CAP_DR1)) { - if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio; - if (!frame->width) frame->width = avctx->width; - if (!frame->height) frame->height = avctx->height; - if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt; - } } } emms_c(); @@ -599,8 +570,40 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) } if (!ret) { - if (avctx->codec_type != AVMEDIA_TYPE_VIDEO) + if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { + //FIXME these should be under if(!avctx->has_b_frames) + /* get_buffer is supposed to set frame parameters */ + if (!(avctx->codec->capabilities & AV_CODEC_CAP_DR1)) { + if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio; + if (!frame->width) frame->width = avctx->width; + if (!frame->height) frame->height = avctx->height; + if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt; + } + } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) { + if (frame->format == AV_SAMPLE_FMT_NONE) + frame->format = avctx->sample_fmt; + if (!frame->ch_layout.nb_channels) { + ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout); + if (ret < 0) { + av_frame_unref(frame); + return ret; + } + } +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (!frame->channel_layout) + frame->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? + avctx->ch_layout.u.mask : 0; + if (!frame->channels) + frame->channels = avctx->ch_layout.nb_channels; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if (!frame->sample_rate) + frame->sample_rate = avctx->sample_rate; + frame->flags |= AV_FRAME_FLAG_KEY; + } + #if FF_API_FRAME_KEY FF_DISABLE_DEPRECATION_WARNINGS frame->key_frame = !!(frame->flags & AV_FRAME_FLAG_KEY);