From patchwork Sun Dec 4 21:52:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 39589 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp2818313pzb; Sun, 4 Dec 2022 13:53:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf614iqf1WRQcKtbxBc+YfkHAkRlTZB0auaRe2L47h6SR+4DlyGY4pb4nDERuYaVW0anu3MH X-Received: by 2002:aa7:c98e:0:b0:46c:2cf2:e89f with SMTP id c14-20020aa7c98e000000b0046c2cf2e89fmr10410491edt.267.1670190804035; Sun, 04 Dec 2022 13:53:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670190804; cv=none; d=google.com; s=arc-20160816; b=zx3VxuoEnkXy74TzfvDWm2pz2d6pdf7bsruHUL5k15Hh347k8h/gSwD3DQa6vxdWv1 IOADUPf9IF9/azazwa61qLWTSN3UwgdmFVkUrVEFn7vUfKRDezbMuQpGrppu85I2LIW6 /eBngf7KIgHEgTAI7AvgHpHitkvAYloP0CKoX8U90HOuNSNeETsyMbX52zvg+Q4rIUeF 16HUqhKQpxDunllz3JtTX6lJU0pvDJVVoEmvV6cErZm2uiIdXqfPcu/UcaJwYXPFcZZy yAcqV+bIMytP9wWOqSHOpG2kxRI6QsuMgEH/qcF3pdjjNP/f2fbF8bcWSJAxkjO+aAtp /rXA== 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=PS6GsPordIi38iWpSQqw0TfIcj2lUL7LUSII3jxJK9Q=; b=lwhJP0W02IL2ppInvi8cR8J56KyJmWqOrda3woIsY2oaKdOJHQW1AwvdXQTG6TZieP k4vTXCa/FADvSpH0dIRbMnPpJHwZEF2jHguFnfWDUWRC1RRMrSiDkTYeosEBDmNbDgiE 6aBT1+SWDOqZTlE0t2T+8Y/TKFsSTZ8R3qWE4z4LG99qp4HNh2LTGa7AReBf4ylmZOZS pDgkhcN/6Bs2haAxxziDOYM/GXjTtu8q1I3E90I7pTY10le/H3ExUcDVo1vCk7feF03t q8sVY1lKU49m9yuC9EhO4phVJkB+/PF7GnJEBBKqZhIjk+govBUZ1OzWza2zcwWcGQnX fKyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=mDZrss0p; 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 cw20-20020a056402229400b0046b7d1b9d79si4232352edb.328.2022.12.04.13.53.23; Sun, 04 Dec 2022 13:53:24 -0800 (PST) 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=20210112 header.b=mDZrss0p; 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 2FB2668BBE5; Sun, 4 Dec 2022 23:53:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oa1-f48.google.com (mail-oa1-f48.google.com [209.85.160.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5525368B315 for ; Sun, 4 Dec 2022 23:53:07 +0200 (EET) Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-1432a5f6468so11421510fac.12 for ; Sun, 04 Dec 2022 13:53:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=0xu9gRIHT3NZVhZccNOKm3yDutuEKHoE6HpB042QLdU=; b=mDZrss0pcqrtio9d5XD3pFdQxoRmC5wJQjab9az7yli6Plt/vKy5h687L26bI4jnuK f/SJJKyUeVBoIQv6a/rr2RIs+G7JjUIxdhS4E7rCnNoPAJ+F29MI/X6Ew6WdkCKqASzj HQnf+9wS/OyLy0o5nTEq7AeLxvAp9XgkLhKmz+uaIhdVWGmYwDJqTH/cqgngbvqTChwT nd/RZy8VzLIpqD6yJpTViWfoZhIL8c0zp3SYahQQ1ZInmjEJ0v8uglzbkOgHOmyyZ79V VygehzlLXftFwB3N7Hua9GLbVIvr9QrrjWUriGyM7MLiO98yygIGwvjHRu8q4MmmIscd y7jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=0xu9gRIHT3NZVhZccNOKm3yDutuEKHoE6HpB042QLdU=; b=zt5u+4EqTGytRRLw2o8zSoIdeN2JOF9OYrE9JcIxm7yvW82qIliQTIahopqy8tCkII AYUYimtB8NCBNjrCNxIfdgZjze3jOkw7W3lriLVZjEt44TDqM20EDRhjvDpQebCXJ7yh VJ5UolTtM6w18p+Hw/X8H2ZgsSdl8cVNLk5gObF1IPT6bD+2uR5z84aLkJaeRLcI/yAO E+Rn3pl82RpA/yf6aUxsbAFIycmVgjxjtp/Whyh2YQbQJUNpBY9wCzQDWdH+Qa7EFtTl sQeM/O4C8lBYSuvjXGzb2MPLKWo6C6QhmOFLqA+X0Wx5/VCohyJsRhfuc/HwKGy3gqnV eNsQ== X-Gm-Message-State: ANoB5plSz4Wf6oOHO3NTLoVtCr+MtmTRmRAsZEZsf7eGPiw11DZ1VRGh H58p2cbSTOpjgEa181N2Zoi3Kw+mlTs= X-Received: by 2002:a05:6870:2e06:b0:142:e523:91c1 with SMTP id oi6-20020a0568702e0600b00142e52391c1mr36772555oab.167.1670190785617; Sun, 04 Dec 2022 13:53:05 -0800 (PST) Received: from localhost.localdomain ([181.85.72.69]) by smtp.gmail.com with ESMTPSA id s16-20020a056830439000b0066c7733be43sm6823100otv.30.2022.12.04.13.53.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Dec 2022 13:53:05 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 4 Dec 2022 18:52:24 -0300 Message-Id: <20221204215227.4186-2-jamrial@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221204215227.4186-1-jamrial@gmail.com> References: <20221204215227.4186-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/5] Revert "avcodec/decode: use a packet list to store packet properties" 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: V5sbKsv8mtf0 The idea behind last_pkt_props was to store the properties of the last packet fed to the decoder. Any sort of queueing required by decoders that consume several packets before they start outputting frames should be done by the decoders in question. An example of this is in the libdav1d wrapper. This is required to maintain its contents during flush, and for the following commits that will fix last_pkt_props in frame threading scenarios. This revers commit 022a12b306ab2096e6ac9fc9b149828a849d65b2. Signed-off-by: James Almer --- libavcodec/avcodec.c | 10 --------- libavcodec/decode.c | 47 ++++++----------------------------------- libavcodec/internal.h | 1 - tests/ref/fate/flcl1905 | 2 +- 4 files changed, 8 insertions(+), 52 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index a85d3c2309..efa76d2740 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -386,9 +386,6 @@ void avcodec_flush_buffers(AVCodecContext *avctx) av_frame_unref(avci->recon_frame); } else { av_packet_unref(avci->last_pkt_props); - while (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) >= 0) - av_packet_unref(avci->last_pkt_props); - av_packet_unref(avci->in_pkt); avctx->pts_correction_last_pts = @@ -453,13 +450,6 @@ av_cold int avcodec_close(AVCodecContext *avctx) av_freep(&avci->byte_buffer); av_frame_free(&avci->buffer_frame); av_packet_free(&avci->buffer_pkt); - if (avci->pkt_props) { - while (av_fifo_can_read(avci->pkt_props)) { - av_packet_unref(avci->last_pkt_props); - av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1); - } - av_fifo_freep2(&avci->pkt_props); - } av_packet_free(&avci->last_pkt_props); av_packet_free(&avci->in_pkt); diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 6be2d3d6ed..c94d9aa33c 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -132,38 +132,16 @@ fail2: return 0; } -#define IS_EMPTY(pkt) (!(pkt)->data) - -static int copy_packet_props(AVPacket *dst, const AVPacket *src) -{ - int ret = av_packet_copy_props(dst, src); - if (ret < 0) - return ret; - - dst->size = src->size; // HACK: Needed for ff_decode_frame_props(). - dst->data = (void*)1; // HACK: Needed for IS_EMPTY(). - - return 0; -} - static int extract_packet_props(AVCodecInternal *avci, const AVPacket *pkt) { - AVPacket tmp = { 0 }; int ret = 0; - if (IS_EMPTY(avci->last_pkt_props)) { - if (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) < 0) - return copy_packet_props(avci->last_pkt_props, pkt); + av_packet_unref(avci->last_pkt_props); + if (pkt) { + ret = av_packet_copy_props(avci->last_pkt_props, pkt); + if (!ret) + avci->last_pkt_props->size = pkt->size; // HACK: Needed for ff_decode_frame_props(). } - - ret = copy_packet_props(&tmp, pkt); - if (ret < 0) - return ret; - - ret = av_fifo_write(avci->pkt_props, &tmp, 1); - if (ret < 0) - av_packet_unref(&tmp); - return ret; } @@ -483,7 +461,6 @@ FF_ENABLE_DEPRECATION_WARNINGS if (ret >= pkt->size || ret < 0) { av_packet_unref(pkt); - av_packet_unref(avci->last_pkt_props); } else { int consumed = ret; @@ -578,8 +555,6 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) { ret = codec->cb.receive_frame(avctx, frame); - if (ret != AVERROR(EAGAIN)) - av_packet_unref(avci->last_pkt_props); } else ret = decode_simple_receive_frame(avctx, frame); @@ -593,12 +568,6 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) return ok; } - if (!(codec->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS) && - IS_EMPTY(avci->last_pkt_props)) { - // May fail if the FIFO is empty. - av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1); - } - if (!ret) { frame->best_effort_timestamp = guess_correct_pts(avctx, frame->pts, @@ -1293,7 +1262,7 @@ static int add_metadata_from_side_data(const AVPacket *avpkt, AVFrame *frame) int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame) { - AVPacket *pkt = avctx->internal->last_pkt_props; + const AVPacket *pkt = avctx->internal->last_pkt_props; static const struct { enum AVPacketSideDataType packet; enum AVFrameSideDataType frame; @@ -1651,9 +1620,7 @@ FF_ENABLE_DEPRECATION_WARNINGS avci->in_pkt = av_packet_alloc(); avci->last_pkt_props = av_packet_alloc(); - avci->pkt_props = av_fifo_alloc2(1, sizeof(*avci->last_pkt_props), - AV_FIFO_FLAG_AUTO_GROW); - if (!avci->in_pkt || !avci->last_pkt_props || !avci->pkt_props) + if (!avci->in_pkt || !avci->last_pkt_props) return AVERROR(ENOMEM); ret = decode_bsfs_init(avctx); diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 76a6ea6bc6..a283c52e01 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -88,7 +88,6 @@ typedef struct AVCodecInternal { * for decoding. */ AVPacket *last_pkt_props; - struct AVFifo *pkt_props; /** * temporary buffer used for encoders to store their bitstream diff --git a/tests/ref/fate/flcl1905 b/tests/ref/fate/flcl1905 index 59cee95459..4500117993 100644 --- a/tests/ref/fate/flcl1905 +++ b/tests/ref/fate/flcl1905 @@ -189,4 +189,4 @@ frame|media_type=audio|stream_index=0|key_frame=1|pts=N/A|pts_time=N/A|pkt_dts=N frame|media_type=audio|stream_index=0|key_frame=1|pts=N/A|pts_time=N/A|pkt_dts=N/A|pkt_dts_time=N/A|best_effort_timestamp=N/A|best_effort_timestamp_time=N/A|pkt_duration=22528|pkt_duration_time=0.510839|duration=22528|duration_time=0.510839|pkt_pos=61436|pkt_size=744|sample_fmt=fltp|nb_samples=2048|channels=2|channel_layout=unknown frame|media_type=audio|stream_index=0|key_frame=1|pts=N/A|pts_time=N/A|pkt_dts=N/A|pkt_dts_time=N/A|best_effort_timestamp=N/A|best_effort_timestamp_time=N/A|pkt_duration=22528|pkt_duration_time=0.510839|duration=22528|duration_time=0.510839|pkt_pos=61436|pkt_size=372|sample_fmt=fltp|nb_samples=2048|channels=2|channel_layout=unknown packet|codec_type=audio|stream_index=0|pts=360448|pts_time=8.173424|dts=360448|dts_time=8.173424|duration=44|duration_time=0.000998|size=8|pos=65528|flags=K_ -frame|media_type=audio|stream_index=0|key_frame=1|pts=N/A|pts_time=N/A|pkt_dts=N/A|pkt_dts_time=N/A|best_effort_timestamp=N/A|best_effort_timestamp_time=N/A|pkt_duration=N/A|pkt_duration_time=N/A|duration=N/A|duration_time=N/A|pkt_pos=N/A|pkt_size=0|sample_fmt=fltp|nb_samples=2048|channels=2|channel_layout=unknown +frame|media_type=audio|stream_index=0|key_frame=1|pts=360448|pts_time=8.173424|pkt_dts=N/A|pkt_dts_time=N/A|best_effort_timestamp=360448|best_effort_timestamp_time=8.173424|pkt_duration=44|pkt_duration_time=0.000998|duration=44|duration_time=0.000998|pkt_pos=65528|pkt_size=8|sample_fmt=fltp|nb_samples=2048|channels=2|channel_layout=unknown