From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id EB9EB42B11 for ; Tue, 11 Jan 2022 20:51:38 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4747368AFED; Tue, 11 Jan 2022 22:47:57 +0200 (EET) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E493B68AE7A for ; Tue, 11 Jan 2022 22:47:32 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 79C6F240590 for ; Tue, 11 Jan 2022 21:47:31 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id kQIIEzaP6-XM for ; Tue, 11 Jan 2022 21:47:29 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 93C03240555 for ; Tue, 11 Jan 2022 21:47:25 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 1A60A3A0A2B; Tue, 11 Jan 2022 21:47:25 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 21:45:47 +0100 Message-Id: <20220111204610.14262-12-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220111204610.14262-1-anton@khirnov.net> References: <20220111204610.14262-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/35] lavc/avcodec: switch to new FIFO API 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --- libavcodec/avcodec.c | 15 ++++++--------- libavcodec/decode.c | 22 ++++++++-------------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index c00a9b2af8..a75bbe721f 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -183,7 +183,8 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code avci->es.in_frame = av_frame_alloc(); avci->in_pkt = av_packet_alloc(); avci->last_pkt_props = av_packet_alloc(); - avci->pkt_props = av_fifo_alloc(sizeof(*avci->last_pkt_props)); + avci->pkt_props = av_fifo_alloc2(1, sizeof(*avci->last_pkt_props), + AV_FIFO_FLAG_AUTO_GROW); if (!avci->buffer_frame || !avci->buffer_pkt || !avci->es.in_frame || !avci->in_pkt || !avci->last_pkt_props || !avci->pkt_props) { @@ -399,13 +400,10 @@ void avcodec_flush_buffers(AVCodecContext *avctx) av_packet_unref(avci->buffer_pkt); av_packet_unref(avci->last_pkt_props); - while (av_fifo_size(avci->pkt_props) >= sizeof(*avci->last_pkt_props)) { - av_fifo_generic_read(avci->pkt_props, - avci->last_pkt_props, sizeof(*avci->last_pkt_props), - NULL); + while (av_fifo_can_read(avci->pkt_props)) { + av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1); av_packet_unref(avci->last_pkt_props); } - av_fifo_reset(avci->pkt_props); av_frame_unref(avci->es.in_frame); av_packet_unref(avci->in_pkt); @@ -464,10 +462,9 @@ av_cold int avcodec_close(AVCodecContext *avctx) av_frame_free(&avci->buffer_frame); av_packet_free(&avci->buffer_pkt); if (avci->pkt_props) { - while (av_fifo_size(avci->pkt_props) >= sizeof(*avci->last_pkt_props)) { + while (av_fifo_can_read(avci->pkt_props)) { av_packet_unref(avci->last_pkt_props); - av_fifo_generic_read(avci->pkt_props, avci->last_pkt_props, - sizeof(*avci->last_pkt_props), NULL); + av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1); } av_fifo_freep(&avci->pkt_props); } diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 0912f86a14..9f6f2e7fa6 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -165,26 +165,21 @@ static int extract_packet_props(AVCodecInternal *avci, const AVPacket *pkt) int ret = 0; if (IS_EMPTY(avci->last_pkt_props)) { - if (av_fifo_size(avci->pkt_props) >= sizeof(*pkt)) { - av_fifo_generic_read(avci->pkt_props, avci->last_pkt_props, - sizeof(*avci->last_pkt_props), NULL); + if (av_fifo_can_read(avci->pkt_props)) { + av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1); } else return copy_packet_props(avci->last_pkt_props, pkt); } - if (av_fifo_space(avci->pkt_props) < sizeof(*pkt)) { - ret = av_fifo_grow(avci->pkt_props, sizeof(*pkt)); - if (ret < 0) - return ret; - } - ret = copy_packet_props(&tmp, pkt); if (ret < 0) return ret; - av_fifo_generic_write(avci->pkt_props, &tmp, sizeof(tmp), NULL); + ret = av_fifo_write(avci->pkt_props, &tmp, 1); + if (ret < 0) + av_packet_unref(&tmp); - return 0; + return ret; } static int decode_bsfs_init(AVCodecContext *avctx) @@ -543,9 +538,8 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) avci->draining_done = 1; if (!(avctx->codec->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS) && - IS_EMPTY(avci->last_pkt_props) && av_fifo_size(avci->pkt_props) >= sizeof(*avci->last_pkt_props)) - av_fifo_generic_read(avci->pkt_props, - avci->last_pkt_props, sizeof(*avci->last_pkt_props), NULL); + IS_EMPTY(avci->last_pkt_props) && av_fifo_can_read(avci->pkt_props)) + av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1); if (!ret) { frame->best_effort_timestamp = guess_correct_pts(avctx, -- 2.33.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".