From patchwork Mon Jul 3 19:32:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42418 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1e:b0:12b:9ae3:586d with SMTP id c30csp4589711pzh; Mon, 3 Jul 2023 12:34:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlG9RaMlGV4K8rP9qL3I9XXss8NLgmrP9nBY8biN5+GhbxoxxtSWdkNOabRUHDsrwk/MO0Zs X-Received: by 2002:a2e:7016:0:b0:2b6:a6e7:5afa with SMTP id l22-20020a2e7016000000b002b6a6e75afamr6873402ljc.12.1688412867662; Mon, 03 Jul 2023 12:34:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688412867; cv=none; d=google.com; s=arc-20160816; b=elkvOU2nhWhl0IECdcshpAMiJYLfaoyIv7kWtYI0Org0K9tnfNotdTFReFqAHVMtno 9Oi4hpcD4yWktS9e0kvNT0zrS4SBJBPR0/m8ay+6Knb3VURe5YYrzQYosfE/LRKdNZWV oJiSkZdsch5zuibQgc2OwxB6nL+vbPLtxSSt17SuroFB6DK6pZ0uAnupTzQ9m+SGNnb+ Axl1oC3iV1ay6PhvEco6y5ptTeyIvXLyhaR4gtm+VBzcXACLzVZonQPXw04VwQpI1HX0 7vREDyjXLTBqfzBiDvFyD2mqXD2EnAPqbdLaSuXCwNG/wvIzIEcW3KSl/fzMfrqIIzt8 v86g== 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=x3V5hFK2UTfcB+Sf/fiLCW67WoQ/D4APLE1l8m+1pNE=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=XlFIDGV3PcRk/Cs0pAlASDH/vCRfr+gMUqDy1QYrQhzO5GLFeo6/YkAYxN7/OLWl46 v40nArU+i47eULYy2x4yKG45uZmQuDDPKOvss5l48fdHgnna+bwr98259nlknLZm+an1 zWLmCWEr/o6uvPmDLR8d/xPb3+UmEdzP2YLqF6/OAN8vFCu5Gwb9JDu8nE0QYmVI5efq +JR85uap6rF6b05qtzaUZU9+4DFrbNp3OpkAMRxAsNhPajKw0SrAT2hmlUC1m2Dapn3j pkc0AgarZK1uuDgY1iJe302AZ5X/r3p7fQPfOWg1gSk6znKvet94XcCDmGn+IuFtQuOs 0h8w== 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 f2-20020a50ee82000000b0051e161794a2si1243602edr.2.2023.07.03.12.34.27; Mon, 03 Jul 2023 12:34:27 -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; 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 38CC768C5D7; Mon, 3 Jul 2023 22:33:09 +0300 (EEST) 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 7FC9668C5BA for ; Mon, 3 Jul 2023 22:32:58 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 5A17E2405F9 for ; Mon, 3 Jul 2023 21:32:56 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id e78-gVdTrfTd for ; Mon, 3 Jul 2023 21:32:55 +0200 (CEST) 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 EE9162405EC for ; Mon, 3 Jul 2023 21:32:51 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id D17CA3A19DC for ; Mon, 3 Jul 2023 21:32:45 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 3 Jul 2023 21:32:28 +0200 Message-Id: <20230703193229.8593-10-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230703193229.8593-1-anton@khirnov.net> References: <20230703193229.8593-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 09/10] lavc/decode: move submitting input packets to bitstream filters 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: Swl2OLGqxr6y Do it from ff_decode_get_packet() rather than from avcodec_send_packet(). This way all nontrivial stages of the decoding pipeline (i.e. other than just placing a packet at its entrance) are pull-based rather than a mix of push an pull. --- libavcodec/decode.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 47714a9393..89c3c2a48d 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -48,6 +48,7 @@ #include "decode.h" #include "hwconfig.h" #include "internal.h" +#include "packet_internal.h" #include "thread.h" typedef struct DecodeContext { @@ -200,14 +201,11 @@ fail: return ret; } -int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt) +static int decode_get_packet(AVCodecContext *avctx, AVPacket *pkt) { AVCodecInternal *avci = avctx->internal; int ret; - if (avci->draining) - return AVERROR_EOF; - ret = av_bsf_receive_packet(avci->bsf, pkt); if (ret == AVERROR_EOF) avci->draining = 1; @@ -230,6 +228,31 @@ finish: return ret; } +int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt) +{ + AVCodecInternal *avci = avctx->internal; + DecodeContext *dc = decode_ctx(avci); + + if (avci->draining) + return AVERROR_EOF; + + while (1) { + int ret = decode_get_packet(avctx, pkt); + if (ret == AVERROR(EAGAIN) && + (!AVPACKET_IS_EMPTY(avci->buffer_pkt) || dc->draining_started)) { + ret = av_bsf_send_packet(avci->bsf, avci->buffer_pkt); + if (ret < 0) { + av_packet_unref(avci->buffer_pkt); + return ret; + } + + continue; + } + + return ret; + } +} + /** * Attempt to guess proper monotonic timestamps for decoded video frames * which might have incorrect times. Input timestamps may wrap around, in @@ -651,12 +674,6 @@ int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacke } else dc->draining_started = 1; - ret = av_bsf_send_packet(avci->bsf, avci->buffer_pkt); - if (ret < 0) { - av_packet_unref(avci->buffer_pkt); - return ret; - } - if (!avci->buffer_frame->buf[0]) { ret = decode_receive_frame_internal(avctx, avci->buffer_frame); if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)