From patchwork Tue Jan 11 20:45:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33259 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp4049998iog; Tue, 11 Jan 2022 12:51:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJzl91PpDjaXHWO0tz44v/2K048CVG3BVMya0iiXT60xpWH5/Qg/LYM3YOz00V2e+Hq0ncmS X-Received: by 2002:a17:906:4347:: with SMTP id z7mr5300066ejm.671.1641934303306; Tue, 11 Jan 2022 12:51:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641934303; cv=none; d=google.com; s=arc-20160816; b=SRz9hxWyX+Zueegzf9iNyB606YsFQq2/Qpd9ucwBcZx/aDoKlGTaMwuBw6rWUjehOv P2X5eOemmp8h0ZV9UX7ufZ11eTejBrQML6laujFZXoVL9r9N7wz0gU/F71U3KUwGqxkZ 1068SlKMeeFvAJEf/hlfFVHNbAnLq1Pm7Z2SSf4N1YFp8dfkCE8jBf/ZwE5xubeLKmJE 6ol0vAc6VwJwb3OrFhduY/7d39kV6shr+zQVzvSqegNO0SA3SDh2CY2VCt0k923afhni 5W6KnrRFadlMcZeg/LtCQ219FAgVPVIWZBBRgwaZFfX2o75wSBOJ9raXBIsx1Ka923Su lAeQ== 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:delivered-to; bh=3UrclV/tEUcPsP7yceJIIm/+aX504xX1qhX0iR+7tDw=; b=xLfaygb1034RAYbbGWwv1e7PJyAvz79BlbeM5AZzVgh9c2nPR6c5N7cJxjS7xMCHbP khq7JabMzUvLYa81XPzt4GQP0Ti13hjNL7yeNwqyW8eJ29LkES1pQATAAMs3XdEkMJ6r 9cM7q0Fr+0TkVIY2ItpgslixocW7Cl9kJ4kXw/4fXeoBWeRyGo99tIYPd23UmC94r/IM KgKAM+Fp/jDc25ZF+ZKEqOKnkndbQ93WsxhuYgepwkjF3QiAonADZLJ8rpWymDlfM/7r 2DfhsV8HWXttksXyA0nd6engnK5JeyPva7oma7cTYvr+6Y56SekxGB8NuK6ubLN6k4aF TKBg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v25si5539918edd.190.2022.01.11.12.51.42; Tue, 11 Jan 2022 12:51:43 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 791A668AFEE; Tue, 11 Jan 2022 22:47:57 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 4M6rccUudn+F --- 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,