From patchwork Mon Jul 3 19:32:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42410 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1e:b0:12b:9ae3:586d with SMTP id c30csp4589088pzh; Mon, 3 Jul 2023 12:33:20 -0700 (PDT) X-Google-Smtp-Source: APBJJlGvs9Bd5/2uhlpUmLcEN8FKM/u6p4sN8s5fBwIHL/scq5YMmXXEUtWBY8PjjMS/kdzYd+BU X-Received: by 2002:a17:906:dfeb:b0:988:6491:98e3 with SMTP id lc11-20020a170906dfeb00b00988649198e3mr8969687ejc.68.1688412800283; Mon, 03 Jul 2023 12:33:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688412800; cv=none; d=google.com; s=arc-20160816; b=lGWB0SHgXxL+w/LFeoeTjQanG4upVUZnobut5IbbDmsyciL7z44Qbg3aCrZBdM4D+t bkcr2+orWw0A2492xzuC8MKVPtmSq1d0YiCSCc0grJbT3ZMcKfONepxFyrK8A4QvQ1z5 TdkPVDm9iXKUPjC0JvZGmYm0gGB5c3b28NANty7S6H8BRBTbxA3UASgpPtHvUPZ5ekAr +qGAwPKGrRgd/pTwn2jA1ti4aCaEgfgLwEDQVgNpSUFG7nV4gfuK89Dv7iAWVAhtnpIX vD2AeM+JFeNQXePObeqPnesiT70XBD8XJ0JeeraqbBgaWa5v0bqqY2/iX15g26iEqRvV FyvA== 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=nrR1icW/4jyMg0TWB2hrDkJzB0cV4bAzeycdRhhuUIQ=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=VfO+Kek4KbKjJlkzitvkkmuD45XitOxHwZmlmqqnShWMFARDvKbgKZGJk7dSokMm3C IbQmRYWccote1MzwzKagfZu0QaYulSAhnA/QHIhXUOOL8SRwYGyxTno4kBZHxq1IA2IL pEqF/p/vteFLzAyPyzozFTxOjTEsCsgLzUVvXlIhMHgKUl48M7vkKABhPbk5jDd8/0ro KYs+Z+SlzODHHOh9lwue+klvWWBiDpFPI2Ng+gFYldrYndNbY6UF/aE8VoQMwm+KrWmU 28QYd/LxfiO75bG3RgEN/34U9AuWlOJptwr0j+uTcHeHHGnJAtK/0iKb7TvL4lVNgE26 dFlQ== 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 gf18-20020a170906e21200b009828e8bec17si12494871ejb.531.2023.07.03.12.33.19; Mon, 03 Jul 2023 12:33:20 -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 8F18668C5A6; Mon, 3 Jul 2023 22:33:00 +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 394B268C1E3 for ; Mon, 3 Jul 2023 22:32:53 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id EF3C32404EC for ; Mon, 3 Jul 2023 21:32:52 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 2Y6E-S80xsQE for ; Mon, 3 Jul 2023 21:32:52 +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 D7CD52404EE 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 737DC3A0362 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:20 +0200 Message-Id: <20230703193229.8593-2-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 01/10] lavc: add a header for internal generic-layer APIs 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: vLyqf+TLdCWb The goal is to distinguish between APIs provided by the generic layer to individual codecs and APIs internal to the generic layer. Start by moving ff_{decode,encode}_receive_frame() and ff_{decode,encode}_preinit() into this new header, as those functions are called from generic code and should not be visible to individual codecs. --- libavcodec/avcodec.c | 1 + libavcodec/avcodec_internal.h | 53 +++++++++++++++++++++++++++++++++++ libavcodec/decode.c | 1 + libavcodec/decode.h | 11 -------- libavcodec/encode.c | 1 + libavcodec/encode.h | 11 -------- 6 files changed, 56 insertions(+), 22 deletions(-) create mode 100644 libavcodec/avcodec_internal.h diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index db8226f9b3..638cb55146 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -34,6 +34,7 @@ #include "libavutil/opt.h" #include "libavutil/thread.h" #include "avcodec.h" +#include "avcodec_internal.h" #include "bsf.h" #include "codec_internal.h" #include "decode.h" diff --git a/libavcodec/avcodec_internal.h b/libavcodec/avcodec_internal.h new file mode 100644 index 0000000000..be60a36644 --- /dev/null +++ b/libavcodec/avcodec_internal.h @@ -0,0 +1,53 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* + * APIs internal to the generic codec layer. + * + * MUST NOT be included by individual encoders or decoders. + */ + +#ifndef AVCODEC_AVCODEC_INTERNAL_H +#define AVCODEC_AVCODEC_INTERNAL_H + +struct AVCodecContext; +struct AVFrame; + +/** + * avcodec_receive_frame() implementation for decoders. + */ +int ff_decode_receive_frame(struct AVCodecContext *avctx, struct AVFrame *frame); + +/** + * avcodec_receive_frame() implementation for encoders. + */ +int ff_encode_receive_frame(struct AVCodecContext *avctx, struct AVFrame *frame); + +/* + * Perform encoder initialization and validation. + * Called when opening the encoder, before the FFCodec.init() call. + */ +int ff_encode_preinit(struct AVCodecContext *avctx); + +/** + * Perform decoder initialization and validation. + * Called when opening the decoder, before the FFCodec.init() call. + */ +int ff_decode_preinit(struct AVCodecContext *avctx); + +#endif // AVCODEC_AVCODEC_INTERNAL_H diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 6ee2c85a75..336635f772 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -41,6 +41,7 @@ #include "libavutil/opt.h" #include "avcodec.h" +#include "avcodec_internal.h" #include "bytestream.h" #include "bsf.h" #include "codec_internal.h" diff --git a/libavcodec/decode.h b/libavcodec/decode.h index aaa29bc7f5..2b9fe59907 100644 --- a/libavcodec/decode.h +++ b/libavcodec/decode.h @@ -53,11 +53,6 @@ typedef struct FrameDecodeData { void (*hwaccel_priv_free)(void *priv); } FrameDecodeData; -/** - * avcodec_receive_frame() implementation for decoders. - */ -int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame *frame); - /** * Called by decoders to get the next packet for decoding. * @@ -99,12 +94,6 @@ int ff_attach_decode_data(AVFrame *frame); */ int ff_copy_palette(void *dst, const AVPacket *src, void *logctx); -/** - * Perform decoder initialization and validation. - * Called when opening the decoder, before the FFCodec.init() call. - */ -int ff_decode_preinit(AVCodecContext *avctx); - /** * Check that the provided frame dimensions are valid and set them on the codec * context. diff --git a/libavcodec/encode.c b/libavcodec/encode.c index ab5f889615..3a016b14c1 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -27,6 +27,7 @@ #include "libavutil/samplefmt.h" #include "avcodec.h" +#include "avcodec_internal.h" #include "codec_internal.h" #include "encode.h" #include "frame_thread_encoder.h" diff --git a/libavcodec/encode.h b/libavcodec/encode.h index 26a3304045..dfaab7c976 100644 --- a/libavcodec/encode.h +++ b/libavcodec/encode.h @@ -26,11 +26,6 @@ #include "avcodec.h" #include "packet.h" -/** - * avcodec_receive_frame() implementation for encoders. - */ -int ff_encode_receive_frame(AVCodecContext *avctx, AVFrame *frame); - /** * Called by encoders to get the next frame for encoding. * @@ -75,12 +70,6 @@ int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size); int ff_encode_reordered_opaque(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame); -/* - * Perform encoder initialization and validation. - * Called when opening the encoder, before the FFCodec.init() call. - */ -int ff_encode_preinit(AVCodecContext *avctx); - int ff_encode_encode_cb(AVCodecContext *avctx, AVPacket *avpkt, AVFrame *frame, int *got_packet); From patchwork Mon Jul 3 19:32:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42409 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1e:b0:12b:9ae3:586d with SMTP id c30csp4589012pzh; Mon, 3 Jul 2023 12:33:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlF10r6T+VCMasUUVBRz05A3rr7rCkp7OUBC1Hlrs4bkHzFQ3mQMOr3ikboqn80Rri24O87I X-Received: by 2002:aa7:c60c:0:b0:51d:d5f2:1222 with SMTP id h12-20020aa7c60c000000b0051dd5f21222mr8674570edq.5.1688412791576; Mon, 03 Jul 2023 12:33:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688412791; cv=none; d=google.com; s=arc-20160816; b=aKjMm7R+xmkpEFniS0zhdPzGjeLjhp5MePLpHSEJUHfBmmv0yYQ7PGPDQlXZCjcQZL vmRB1z8nesEvwJvdtfbEw/ix4UBNhMMFuZForvdqSxaZCa0ksPP64S6+Pqo6k7zwdOwx Of58j+afmulFwZ0NnQf7ZKICwaODQPItKra0ENOQyOUa/r7roeY082i1wPXHmpnuoZ/k NePhtbBlSq1PIUYr4jZhI4u3512KqdcAoqsQAm1tWa/9A9V+4bQdaJjsvMqUPs1nRyWi /2x9D7AbQaGQYN6NLV6yVN+oq1vYrxxoaTft4nupbSEJvzgOyGvBW/9Q0ODSRpyqjgCx MwTg== 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=HCHqPQ/clcpJeS8s48pniF3hAEkwBvAzelbvooBSGjM=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=LNMx3RseSy0HSHno8fd1P0X7pXSObhzsBxFXd7fC7KPHHyNpmwPpJbTfcsU4ODlk/d LMObaSeZJEbYMvKM8dxIItGuggR8V8DozwjO2vvAsacfLTJHoAH0+GzeTJZK4x7eQwNl KZ3myGueY8ZojHm3NDl+jy2CnvwG76N0df37v8STq9OpmQXIpMZ5l23aI9RpTkrAcT5m kMof8oPBBlQZe5XeiFwUKcGv3jEUl2HbxxAY2HbNQW1nc+e7qDFh8Msz0l80kJ0IMmre YdE5Soy2hVbBtls4CiPz3y15zMSbwrWrPvCBHlK96RmNXiVJrjsEX8wHebPzSSFJF0oU 9Dng== 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 d16-20020a50fb10000000b0051de30de0c4si5798590edq.595.2023.07.03.12.33.11; Mon, 03 Jul 2023 12:33:11 -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 9A1CC68C59F; Mon, 3 Jul 2023 22:32:59 +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 AADBF68C563 for ; Mon, 3 Jul 2023 22:32:52 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 70F7D2404EA for ; Mon, 3 Jul 2023 21:32:52 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id I8Vky7T1xuAt for ; Mon, 3 Jul 2023 21:32:51 +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 D729A2404EC 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 7F1543A0E3B 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:21 +0200 Message-Id: <20230703193229.8593-3-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 02/10] lavc/avcodec: split flushing into decode- and encode-specific functions 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: zZfC/+w7aELk Will allow making some state private to encoding/decoding in the future. --- libavcodec/avcodec.c | 17 +++-------------- libavcodec/avcodec_internal.h | 3 +++ libavcodec/decode.c | 15 +++++++++++++++ libavcodec/encode.c | 10 ++++++++++ 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index 638cb55146..c01dac2049 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -383,23 +383,12 @@ void avcodec_flush_buffers(AVCodecContext *avctx) "that doesn't support it\n"); return; } - if (avci->in_frame) - av_frame_unref(avci->in_frame); - if (avci->recon_frame) - av_frame_unref(avci->recon_frame); - } else { - av_packet_unref(avci->last_pkt_props); - av_packet_unref(avci->in_pkt); - - avctx->pts_correction_last_pts = - avctx->pts_correction_last_dts = INT64_MIN; - - av_bsf_flush(avci->bsf); - } + ff_encode_flush_buffers(avctx); + } else + ff_decode_flush_buffers(avctx); avci->draining = 0; avci->draining_done = 0; - avci->nb_draining_errors = 0; av_frame_unref(avci->buffer_frame); av_packet_unref(avci->buffer_pkt); diff --git a/libavcodec/avcodec_internal.h b/libavcodec/avcodec_internal.h index be60a36644..6ffe575c3e 100644 --- a/libavcodec/avcodec_internal.h +++ b/libavcodec/avcodec_internal.h @@ -50,4 +50,7 @@ int ff_encode_preinit(struct AVCodecContext *avctx); */ int ff_decode_preinit(struct AVCodecContext *avctx); +void ff_decode_flush_buffers(struct AVCodecContext *avctx); +void ff_encode_flush_buffers(struct AVCodecContext *avctx); + #endif // AVCODEC_AVCODEC_INTERNAL_H diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 336635f772..01ac35bf34 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1740,3 +1740,18 @@ AVBufferRef *ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, return ref; } + +void ff_decode_flush_buffers(AVCodecContext *avctx) +{ + AVCodecInternal *avci = avctx->internal; + + av_packet_unref(avci->last_pkt_props); + av_packet_unref(avci->in_pkt); + + avctx->pts_correction_last_pts = + avctx->pts_correction_last_dts = INT64_MIN; + + av_bsf_flush(avci->bsf); + + avci->nb_draining_errors = 0; +} diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 3a016b14c1..0b1947c781 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -785,3 +785,13 @@ int ff_encode_receive_frame(AVCodecContext *avctx, AVFrame *frame) av_frame_move_ref(frame, avci->recon_frame); return 0; } + +void ff_encode_flush_buffers(AVCodecContext *avctx) +{ + AVCodecInternal *avci = avctx->internal; + + if (avci->in_frame) + av_frame_unref(avci->in_frame); + if (avci->recon_frame) + av_frame_unref(avci->recon_frame); +} From patchwork Mon Jul 3 19:32:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42411 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1e:b0:12b:9ae3:586d with SMTP id c30csp4589185pzh; Mon, 3 Jul 2023 12:33:28 -0700 (PDT) X-Google-Smtp-Source: APBJJlFgtlzl+l3SarqJTSpt1Fi+R31GGwLZdVhzMFN0xtmQz3MQh2teGGlxVaJgMAIv5qzwv+jc X-Received: by 2002:a17:906:3bd3:b0:982:870f:9e8f with SMTP id v19-20020a1709063bd300b00982870f9e8fmr7458349ejf.62.1688412808453; Mon, 03 Jul 2023 12:33:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688412808; cv=none; d=google.com; s=arc-20160816; b=cpkHK6CMBDTtDS2EtejQRRdH21lL1Rj9dqQFuvohTk2qbCcMnDXPGCN3jOTUK7fwco 6nfPwK/QjlqgpJ9JgN2O2ulX5KMNM93f00prWf1BognBl7+Nj0HHQPXjv71CAdabcUPa S1DByP3/QH1TQQEE9isV7cuUQrmxhW73VqiFxO94IZwASdhYQKYzRM1dtxLgLTlAcMd6 SDjJYRsLozmKiFnEqr7HKcon7VgVsKwCpJFwZU+nkVL5T7SrOBs1pw59VIQvRE+ZwACQ H2Vfrw4JA0D6XkILYNG1V2mlFe3z2hvNifgsaQ1F19rGwVGp3laK8eYGC+FT81UYRpm1 v/+g== 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=21fF0VguCa3CQDrWXIu6X6BN1rv1VZbPzDysQ/IovpY=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=JnEu6A78ZG69+foQOmVTtpiNxkDwe0Xx07+2Qk5rnJvo5mPB72E02bqy3fpaKZM9U4 jIkcuqTqPB09QClh38yyRIyqPN3jmLGPvqKUrrJMZc/YdQsDXABzxFfJcXyYoxt74gyM mj60TKHTvu9auT2yMvHpPShyTjQf+r9brrs5SCi5wp6U3cJt0nwxdngz27pAVc36WiR1 BiBmVzeudrroi3qVBkqby/3pxnQWr/Oo2y/WgPyvdvjlysQchi+3D6OPYeH/deqVAtbp X+/z+m9ZzYKo8ASbGm/L6XN6qG2duW85PDQimAWd1RF93MCgJR7MkU0p48op55met19A ACTA== 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 o9-20020a170906774900b00988839e5435si10979678ejn.522.2023.07.03.12.33.28; Mon, 03 Jul 2023 12:33:28 -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 9E3DF68C5AA; Mon, 3 Jul 2023 22:33:01 +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 AE46868C596 for ; Mon, 3 Jul 2023 22:32:53 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 780FA2404EE for ; Mon, 3 Jul 2023 21:32:53 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 7TOEuY_TPOaP for ; Mon, 3 Jul 2023 21:32:53 +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 DA8FF2404F5 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 8AB7B3A10A9 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:22 +0200 Message-Id: <20230703193229.8593-4-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 03/10] lavc: reindent after previous commit 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: IEe+TU/tXXSe --- libavcodec/decode.c | 10 +++++----- libavcodec/encode.c | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 01ac35bf34..3115282923 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1745,13 +1745,13 @@ void ff_decode_flush_buffers(AVCodecContext *avctx) { AVCodecInternal *avci = avctx->internal; - av_packet_unref(avci->last_pkt_props); - av_packet_unref(avci->in_pkt); + av_packet_unref(avci->last_pkt_props); + av_packet_unref(avci->in_pkt); - avctx->pts_correction_last_pts = - avctx->pts_correction_last_dts = INT64_MIN; + avctx->pts_correction_last_pts = + avctx->pts_correction_last_dts = INT64_MIN; - av_bsf_flush(avci->bsf); + av_bsf_flush(avci->bsf); avci->nb_draining_errors = 0; } diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 0b1947c781..2620810476 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -790,8 +790,8 @@ void ff_encode_flush_buffers(AVCodecContext *avctx) { AVCodecInternal *avci = avctx->internal; - if (avci->in_frame) - av_frame_unref(avci->in_frame); - if (avci->recon_frame) - av_frame_unref(avci->recon_frame); + if (avci->in_frame) + av_frame_unref(avci->in_frame); + if (avci->recon_frame) + av_frame_unref(avci->recon_frame); } From patchwork Mon Jul 3 19:32:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42414 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1e:b0:12b:9ae3:586d with SMTP id c30csp4589398pzh; Mon, 3 Jul 2023 12:33:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5+IujoHfSLph77zkjNTfsWB2J/Xw1bpcLVy+rpmhSJCK++NsLDJm/fu1i8h59HFza3km/K X-Received: by 2002:aa7:d51a:0:b0:51a:4451:564d with SMTP id y26-20020aa7d51a000000b0051a4451564dmr15886047edq.18.1688412834168; Mon, 03 Jul 2023 12:33:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688412834; cv=none; d=google.com; s=arc-20160816; b=pItyyjv2i+JYUgeNfSVBRcl1j6yubyiDA9eRcSxC3VOb0BSaKMY4g/mFcqlpwfcUFU dwGVR5xU6ivicgC4/kb3QYghnAPoSb1/FwCPJMquXJ+u24j8MdseR8UpRdXd+ndTMWlK AkhAiMj6jfGAWpRRQmzlQeYykDLgK+DNhGqJQsZJ5Rz5qlO/VTj0e0KKkPg52WhvgDHq UpVUzUO+oZF/YDke3Z5rF9GQqV1faDLeEktys/p6yFWJQZJknzpmhB3vLX+gnGE3J7Sp uj2o2j2o9UjZAT/Ex4ffL5+/N8Kw8A0agtWsTtvzYewqHfbYnOJl/kZdP3rqGu/Xl63X +W2Q== 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=1V1InUrfMMCrS4SJRJ64GGPPnJEt3ZqFAK4Jm23yXA0=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=VdN9RBtrcEZkNdR2noIPI0UfCGHY0F0/S+3lUUiAzpFt8IX8L72H5WUYKb2/tQqTDk 53zSVGndfLadxq4FCtf7BkLcoIS5zRAbwUZTNSzyBTlbkRYfJKJrZFvkU6QNUoyieC/D MsIfP5HlfJdovwvXHFwKYSh0B06XIDteBJ30or0KV0j2RctQNXbN3hpuaKSxO1tVXS/I wmP2zXujcEDnxgKNbiZ4b8joB5JGriTP+3Mk7wXI7ph57kkmz6Cvy4zA8gH7wstAKziz z2aRsovm2su2a7dpc8sQv3kZtSkb0Mdm8DS2JIKPRf/MCMDtLM+uRn3FeXTwRD0rN1tN xssQ== 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 f6-20020a056402160600b0051e04eb3321si3034351edv.519.2023.07.03.12.33.53; Mon, 03 Jul 2023 12:33:54 -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 428D368C5C4; Mon, 3 Jul 2023 22:33:05 +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 CDC0868C5B1 for ; Mon, 3 Jul 2023 22:32:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id A7F372405B5 for ; Mon, 3 Jul 2023 21:32:54 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id k-Hn3zxkNHO7 for ; Mon, 3 Jul 2023 21:32:54 +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 DB6C12404F8 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 9586C3A1267 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:23 +0200 Message-Id: <20230703193229.8593-5-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 04/10] lavc: add generic-decode-layer private data 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: 30sfJGE+v7FJ Move AVCodecInternal.nb_draining_errors to it, should should not be visible outside of decode.c. --- libavcodec/avcodec.c | 4 +++- libavcodec/avcodec_internal.h | 2 ++ libavcodec/decode.c | 21 +++++++++++++++++++-- libavcodec/internal.h | 3 --- libavcodec/pthread_frame.c | 3 ++- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index c01dac2049..aef2edce32 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -150,7 +150,9 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE) return AVERROR(EINVAL); - avci = av_mallocz(sizeof(*avci)); + avci = av_codec_is_decoder(codec) ? + ff_decode_internal_alloc() : + av_mallocz(sizeof(AVCodecInternal)); if (!avci) { ret = AVERROR(ENOMEM); goto end; diff --git a/libavcodec/avcodec_internal.h b/libavcodec/avcodec_internal.h index 6ffe575c3e..f52f91e07c 100644 --- a/libavcodec/avcodec_internal.h +++ b/libavcodec/avcodec_internal.h @@ -53,4 +53,6 @@ int ff_decode_preinit(struct AVCodecContext *avctx); void ff_decode_flush_buffers(struct AVCodecContext *avctx); void ff_encode_flush_buffers(struct AVCodecContext *avctx); +struct AVCodecInternal *ff_decode_internal_alloc(void); + #endif // AVCODEC_AVCODEC_INTERNAL_H diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 3115282923..acec9860a5 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -50,6 +50,18 @@ #include "internal.h" #include "thread.h" +typedef struct DecodeContext { + AVCodecInternal avci; + + /* to prevent infinite loop on errors when draining */ + int nb_draining_errors; +} DecodeContext; + +static DecodeContext *decode_ctx(AVCodecInternal *avci) +{ + return (DecodeContext *)avci; +} + static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt) { int ret; @@ -439,7 +451,7 @@ FF_ENABLE_DEPRECATION_WARNINGS int nb_errors_max = 20 + (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME ? avctx->thread_count : 1); - if (avci->nb_draining_errors++ >= nb_errors_max) { + if (decode_ctx(avci)->nb_draining_errors++ >= nb_errors_max) { av_log(avctx, AV_LOG_ERROR, "Too many errors when draining, this is a bug. " "Stop draining and force EOF.\n"); avci->draining_done = 1; @@ -1753,5 +1765,10 @@ void ff_decode_flush_buffers(AVCodecContext *avctx) av_bsf_flush(avci->bsf); - avci->nb_draining_errors = 0; + decode_ctx(avci)->nb_draining_errors = 0; +} + +AVCodecInternal *ff_decode_internal_alloc(void) +{ + return av_mallocz(sizeof(DecodeContext)); } diff --git a/libavcodec/internal.h b/libavcodec/internal.h index dceae182c0..0c1f0b82ea 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -148,9 +148,6 @@ typedef struct AVCodecInternal { AVFrame *buffer_frame; int draining_done; - /* to prevent infinite loop on errors when draining */ - int nb_draining_errors; - /* used when avctx flag AV_CODEC_FLAG_DROPCHANGED is set */ int changed_frames_dropped; int initial_format; diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index 008f3da43b..bc305f561f 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -28,6 +28,7 @@ #include #include "avcodec.h" +#include "avcodec_internal.h" #include "codec_internal.h" #include "decode.h" #include "hwconfig.h" @@ -815,7 +816,7 @@ static av_cold int init_thread(PerThreadContext *p, int *threads_to_free, p->parent = fctx; p->avctx = copy; - copy->internal = av_mallocz(sizeof(*copy->internal)); + copy->internal = ff_decode_internal_alloc(); if (!copy->internal) return AVERROR(ENOMEM); copy->internal->thread_ctx = p; From patchwork Mon Jul 3 19:32:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42413 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1e:b0:12b:9ae3:586d with SMTP id c30csp4589308pzh; Mon, 3 Jul 2023 12:33:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlH55zUtLzP4tak4n5wAllLotQARUgnRML+QwazEEGSYpMqLleShP4nNHzkgs9sHq30IdF8E X-Received: by 2002:a50:ec8b:0:b0:51d:d1af:df15 with SMTP id e11-20020a50ec8b000000b0051dd1afdf15mr7791954edr.23.1688412825702; Mon, 03 Jul 2023 12:33:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688412825; cv=none; d=google.com; s=arc-20160816; b=WeOI7vtN7YR3VvJfE1i7HNK7hH5UaMv+/0F03zpSBhUha2Wa77NIjs2daMEJ+r/oTQ bcPOqaT6rYfr2ADGzwo9y7YaJnvy/iEqAxzOCnV6JlIHI+m7I1elAdua8vyqvZG/upE7 W87hhREIE43VcqwBNBMNG9X/P9m94DlBCGleUgra9CCN1mijeC8+iaXnAWSGlbui78hb 00Tzj8i7INqhSZZ+bPWuy1oX6ZxVePLcEVoAA1yuuMS5AAbhZ/b9k32ptOA3NbBAypxS 1mIXSnK6wNRz9HUckH9AOe2KAioBQI1qVJ1ZqqHVgwWKoO7YBF6mD8BzLnNbdnveyaBD ltSg== 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=6INE6icxmY34gAR9hqyQ7VxqrPGe6hL9MO0HWyl88Fc=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=0t7E0XwcAY8KITJUl9SF6OS9M1M/kbd2yEswC59MwKCUJeaOy/VrW3NoXZ0xZltMqb A3w2eCt9XJ4xVLqLz5DNL1CYAfCW/45jVYsr6ZyK28c4Hjx6w0S2J77Wv7yyFs4TmTGM te65/VQ6kkAR1R5iieyHb4tYZSC7eXz2gW19NrOUAE6zzRHBjkYUCZCzyh3kU7rs4frG dGZlYGP+sUVlb1wOVE1hzpNGlmkaPuPktTUwLOWqzDeiL9pUb+IQ5XE5WBkyFXKz+dtB PeygRCrGsNaSxRN0aLe3fhxPIYgb2m1jg+C8J1qer+QSZicTZmQeZh1mlge2hcwimK3S UVsw== 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 j13-20020aa7c0cd000000b0051e0d8c614fsi2048395edp.567.2023.07.03.12.33.45; Mon, 03 Jul 2023 12:33:45 -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 1660F68C5B2; Mon, 3 Jul 2023 22:33:04 +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 C7B3C68C5B0 for ; Mon, 3 Jul 2023 22:32:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 276AD240591 for ; Mon, 3 Jul 2023 21:32:54 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id mBW2dsbFBh32 for ; Mon, 3 Jul 2023 21:32:53 +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 E22012405B5 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 A26703A12EC 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:24 +0200 Message-Id: <20230703193229.8593-6-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 05/10] lavc: add generic-encode-layer private data 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: 8Gfvzxb/+ofx Move AVCodecInternal.intra_only_flag to it, should should not be visible outside of encode.c. --- libavcodec/avcodec.c | 2 +- libavcodec/avcodec_internal.h | 1 + libavcodec/encode.c | 26 ++++++++++++++++++++++++-- libavcodec/internal.h | 7 ------- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index aef2edce32..8ccc610227 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -152,7 +152,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code avci = av_codec_is_decoder(codec) ? ff_decode_internal_alloc() : - av_mallocz(sizeof(AVCodecInternal)); + ff_encode_internal_alloc(); if (!avci) { ret = AVERROR(ENOMEM); goto end; diff --git a/libavcodec/avcodec_internal.h b/libavcodec/avcodec_internal.h index f52f91e07c..9b93ff3d81 100644 --- a/libavcodec/avcodec_internal.h +++ b/libavcodec/avcodec_internal.h @@ -54,5 +54,6 @@ void ff_decode_flush_buffers(struct AVCodecContext *avctx); void ff_encode_flush_buffers(struct AVCodecContext *avctx); struct AVCodecInternal *ff_decode_internal_alloc(void); +struct AVCodecInternal *ff_encode_internal_alloc(void); #endif // AVCODEC_AVCODEC_INTERNAL_H diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 2620810476..6da5d86ea0 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -33,6 +33,22 @@ #include "frame_thread_encoder.h" #include "internal.h" +typedef struct EncodeContext { + AVCodecInternal avci; + + /** + * This is set to AV_PKT_FLAG_KEY for encoders that encode intra-only + * formats (i.e. whose codec descriptor has AV_CODEC_PROP_INTRA_ONLY set). + * This is used to set said flag generically for said encoders. + */ + int intra_only_flag; +} EncodeContext; + +static EncodeContext *encode_ctx(AVCodecInternal *avci) +{ + return (EncodeContext*)avci; +} + int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size) { if (size < 0 || size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) { @@ -372,7 +388,7 @@ static int encode_receive_packet_internal(AVCodecContext *avctx, AVPacket *avpkt } else ret = encode_simple_receive_packet(avctx, avpkt); if (ret >= 0) - avpkt->flags |= avci->intra_only_flag; + avpkt->flags |= encode_ctx(avci)->intra_only_flag; if (ret == AVERROR_EOF) avci->draining_done = 1; @@ -680,6 +696,7 @@ static int encode_preinit_audio(AVCodecContext *avctx) int ff_encode_preinit(AVCodecContext *avctx) { AVCodecInternal *avci = avctx->internal; + EncodeContext *ec = encode_ctx(avci); int ret = 0; if (avctx->time_base.num <= 0 || avctx->time_base.den <= 0) { @@ -710,7 +727,7 @@ int ff_encode_preinit(AVCodecContext *avctx) avctx->rc_initial_buffer_occupancy = avctx->rc_buffer_size * 3LL / 4; if (avctx->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY) - avctx->internal->intra_only_flag = AV_PKT_FLAG_KEY; + ec->intra_only_flag = AV_PKT_FLAG_KEY; if (ffcodec(avctx->codec)->cb_type == FF_CODEC_CB_TYPE_ENCODE) { avci->in_frame = av_frame_alloc(); @@ -795,3 +812,8 @@ void ff_encode_flush_buffers(AVCodecContext *avctx) if (avci->recon_frame) av_frame_unref(avci->recon_frame); } + +AVCodecInternal *ff_encode_internal_alloc(void) +{ + return av_mallocz(sizeof(EncodeContext)); +} diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 0c1f0b82ea..497cd77f23 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -95,13 +95,6 @@ typedef struct AVCodecInternal { uint8_t *byte_buffer; unsigned int byte_buffer_size; - /** - * This is set to AV_PKT_FLAG_KEY for encoders that encode intra-only - * formats (i.e. whose codec descriptor has AV_CODEC_PROP_INTRA_ONLY set). - * This is used to set said flag generically for said encoders. - */ - int intra_only_flag; - void *frame_thread_encoder; /** From patchwork Mon Jul 3 19:32:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42417 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1e:b0:12b:9ae3:586d with SMTP id c30csp4589636pzh; Mon, 3 Jul 2023 12:34:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlHqE5U4Xa88Q3+8in7bDpOYs7PbU3pfEYiiiKKQBZO/XmLYyCG6OnnXP93by1LxMAVY4H4E X-Received: by 2002:a17:907:20a9:b0:988:699d:64d0 with SMTP id pw9-20020a17090720a900b00988699d64d0mr7785814ejb.32.1688412858745; Mon, 03 Jul 2023 12:34:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688412858; cv=none; d=google.com; s=arc-20160816; b=fJ3/WANRQ6Eml4s0A+ay8KS6OSNYvHNZG7Ioeh6eZAIaEdcWS3AB5rJSXSEFctjrCu egMMGQERTjM/jnn0gpc0+PP4tMHvxoOSt6hYVl21BqYm7F9N0cLlQWduqY68kvsbLf1q DYpPpJgj8hmgLD1JjaitAsaKx01noKqdK6flj9P5KgcYE4KR2UM5A8AwbCk0pEYAuHdB l6sv+kXL6wINecWGClqmzclpYqEJQKiMXHqzm4k2yxdyQX+yMyxrTke4gYJ1nq+2OriF 7OE8fdNuVR3kYtl93ivW7WyT5OAbOcoCH711siKIFm0iyUnw5WkvHEBzBKTyJnHNcezQ dwcA== 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=u04grFjjZmEryMdN9y9gCGXLNG2aIsUjFbXZvVVV1ug=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=TlaTts3rhmlC+2+1DtmlAuGZfdZcQWfxbD7EU3zjhVnFMy3GzQuIOniEOEGCURdl9K SSzzyO+IdcNN8aTW1aAHuYsO0cHH2Zp8UKdBvyQX0IKZVq54bAPSxc2TLVOKP11QFij8 CkpDEYeuRFCtYIpiheIr+u3pEP7VxQ8jGQjkuG+BsKVmviVOl6bfa/pHnaSBY9RNjXvK 8JauJ44ZYuarO0wG95KY2pZDm1A5GdsLnPoQBPys1BAY5j1y77V7pZOjECyPUf7KUxkE ybQ9IDI3bj85VzqQH6b8wSfW8fpITp0Hspbp5MK8zd8SS0qBGUHvJjap6UekOBeOR/kS oD0Q== 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 lr27-20020a170906fb9b00b00992437c5881si8052739ejb.198.2023.07.03.12.34.18; Mon, 03 Jul 2023 12:34:18 -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 34FD368C5D0; Mon, 3 Jul 2023 22:33:08 +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 7631568C5B0 for ; Mon, 3 Jul 2023 22:32:58 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id E14642406CB for ; Mon, 3 Jul 2023 21:32:55 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id eAYGPR_sORhm for ; Mon, 3 Jul 2023 21:32:54 +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 1258A2405F9 for ; Mon, 3 Jul 2023 21:32:52 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id AE3513A168E 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:25 +0200 Message-Id: <20230703193229.8593-7-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 06/10] lavc: move AVCodecInternal.last_audio_frame to EncodeContext 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: zvdobik69Qf7 It does not need to be visible outside of encode.c. --- libavcodec/encode.c | 13 ++++++++++--- libavcodec/internal.h | 6 ------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 6da5d86ea0..58eab5b001 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -42,6 +42,12 @@ typedef struct EncodeContext { * This is used to set said flag generically for said encoders. */ int intra_only_flag; + + /** + * An audio frame with less than required samples has been submitted (and + * potentially padded with silence). Reject all subsequent frames. + */ + int last_audio_frame; } EncodeContext; static EncodeContext *encode_ctx(AVCodecInternal *avci) @@ -174,7 +180,7 @@ static int pad_last_frame(AVCodecContext *s, AVFrame *frame, const AVFrame *src, fail: av_frame_unref(frame); - s->internal->last_audio_frame = 0; + encode_ctx(s->internal)->last_audio_frame = 0; return ret; } @@ -446,6 +452,7 @@ static int encode_generate_icc_profile(av_unused AVCodecContext *c, av_unused AV static int encode_send_frame_internal(AVCodecContext *avctx, const AVFrame *src) { AVCodecInternal *avci = avctx->internal; + EncodeContext *ec = encode_ctx(avci); AVFrame *dst = avci->buffer_frame; int ret; @@ -458,7 +465,7 @@ static int encode_send_frame_internal(AVCodecContext *avctx, const AVFrame *src) /* check for valid frame size */ if (!(avctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)) { /* if we already got an undersized frame, that must have been the last */ - if (avctx->internal->last_audio_frame) { + if (ec->last_audio_frame) { av_log(avctx, AV_LOG_ERROR, "frame_size (%d) was not respected for a non-last frame\n", avctx->frame_size); return AVERROR(EINVAL); } @@ -467,7 +474,7 @@ static int encode_send_frame_internal(AVCodecContext *avctx, const AVFrame *src) return AVERROR(EINVAL); } if (src->nb_samples < avctx->frame_size) { - avctx->internal->last_audio_frame = 1; + ec->last_audio_frame = 1; if (!(avctx->codec->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME)) { int pad_samples = avci->pad_samples ? avci->pad_samples : avctx->frame_size; int out_samples = (src->nb_samples + pad_samples - 1) / pad_samples * pad_samples; diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 497cd77f23..868dd46b48 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -56,12 +56,6 @@ typedef struct AVCodecInternal { */ int is_copy; - /** - * An audio frame with less than required samples has been submitted (and - * potentially padded with silence). Reject all subsequent frames. - */ - int last_audio_frame; - /** * Audio encoders can set this flag during init to indicate that they * want the small last frame to be padded to a multiple of pad_samples. From patchwork Mon Jul 3 19:32:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42412 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1e:b0:12b:9ae3:586d with SMTP id c30csp4589255pzh; Mon, 3 Jul 2023 12:33:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlF6E0M5bQNLXzdS+MDYXIIhCIhIbGp4dY0NkMrycKDyXSVdRigbrfVxm7PFgdWxRJLEFj/M X-Received: by 2002:ac2:5f63:0:b0:4fa:21d5:c0a3 with SMTP id c3-20020ac25f63000000b004fa21d5c0a3mr7035754lfc.36.1688412816813; Mon, 03 Jul 2023 12:33:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688412816; cv=none; d=google.com; s=arc-20160816; b=dbcYRpvxnSzyIn8elkR5of/XXqszFQP2jTUUP8Jhaz2A3KZNwvnKkaJ48knZKCmFAM z33GoqpmmBQhmvK/15xHF6R83lsFPpCbdBmFtfoabczDtLaniPuz/Bg31Bwf8MLhIm/i I6hly+r0xhJyza1D646YAF8oBlhNWd+ow+aiNuxn+Pse8cOWGjHH5oeVU9bsoSrNMiii cV+Um2kGAq43ZHoOU8tQ3ZpmxhnSPJZiJ2YIT0QA9l5DOz3EJB2CIRz4H7cLya3Hx7vz oJwX74FhXeppwFMVoGXsgC3KnucLZlxhhLQvBkA0M7KzWA+CHXN400Q4Cjzktx0FBUg7 oE8Q== 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=oo1dK8NUoa1Yyuk3P9BeHlLm0zRJtGl3N3tr2I8lkeY=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=qtPnhqefEjoDPZtJ4b+7EJSZRc6cR9eZfW+M0iv1otlzq0ubLCGpsMQAEUrhA3naE9 J1XmHfbaXabmsl/VKy/naZ9ffc2Yrrp/qEygIXZwUe2nTKIHKixMocq8vDR+EXzCnpWO hTgo6yQVF6/kVLQm35SjiS2qPC8ZRzPKWBtRvbrm3wIvU5Cxu/6VTHnSp/ovBDDFO6Sm CCpzmbfMqUftaXvTR8P7r4bczAynmmi0j865G8FEbCED9E7KAmyTdXP/X5PdOpK9gb6p SUpDQWrBGWARJeggnfSnBmlzUp4lkheSzlmIag7T5k16w16P9t6iDM2dOslxVn3JpxbG BcXQ== 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 f19-20020a056402151300b0051dd50ceaa1si5637083edw.140.2023.07.03.12.33.36; Mon, 03 Jul 2023 12:33:36 -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 ACB0C68C5AF; Mon, 3 Jul 2023 22:33:02 +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 60B1868C59F for ; Mon, 3 Jul 2023 22:32:54 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id F37D52404F5 for ; Mon, 3 Jul 2023 21:32:53 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id mOmmVLjZlZZw for ; Mon, 3 Jul 2023 21:32:52 +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 E0A20240591 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 BA24A3A16DB 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:26 +0200 Message-Id: <20230703193229.8593-8-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 07/10] lavc/decode: track whether the caller started draining with a separate flag 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: zRZPd2QqXDsy Decoding pipeline has multiple stages, some of which may have their own delay (e.g. bitstream filters). The code currently uses AVCodecInternal.draining to track all of them, but they do not have to all be in sync. --- libavcodec/decode.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index acec9860a5..47714a9393 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -55,6 +55,11 @@ typedef struct DecodeContext { /* to prevent infinite loop on errors when draining */ int nb_draining_errors; + + /** + * The caller has submitted a NULL packet on input. + */ + int draining_started; } DecodeContext; static DecodeContext *decode_ctx(AVCodecInternal *avci) @@ -626,12 +631,13 @@ FF_ENABLE_DEPRECATION_WARNINGS int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt) { AVCodecInternal *avci = avctx->internal; + DecodeContext *dc = decode_ctx(avci); int ret; if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec)) return AVERROR(EINVAL); - if (avctx->internal->draining) + if (dc->draining_started) return AVERROR_EOF; if (avpkt && !avpkt->size && avpkt->data) @@ -642,7 +648,8 @@ int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacke ret = av_packet_ref(avci->buffer_pkt, avpkt); if (ret < 0) return ret; - } + } else + dc->draining_started = 1; ret = av_bsf_send_packet(avci->bsf, avci->buffer_pkt); if (ret < 0) { @@ -1756,6 +1763,7 @@ AVBufferRef *ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void ff_decode_flush_buffers(AVCodecContext *avctx) { AVCodecInternal *avci = avctx->internal; + DecodeContext *dc = decode_ctx(avci); av_packet_unref(avci->last_pkt_props); av_packet_unref(avci->in_pkt); @@ -1765,7 +1773,8 @@ void ff_decode_flush_buffers(AVCodecContext *avctx) av_bsf_flush(avci->bsf); - decode_ctx(avci)->nb_draining_errors = 0; + dc->nb_draining_errors = 0; + dc->draining_started = 0; } AVCodecInternal *ff_decode_internal_alloc(void) From patchwork Mon Jul 3 19:32:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42415 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1e:b0:12b:9ae3:586d with SMTP id c30csp4589495pzh; Mon, 3 Jul 2023 12:34:02 -0700 (PDT) X-Google-Smtp-Source: APBJJlFsNayQFNSi1pVP1IMO2DKOSd0vA5H/eN69KT3QmBMr3DG25Ieah+Clx3mzuRPMJ9AA7J4r X-Received: by 2002:a05:6512:1196:b0:4fb:8cd1:1679 with SMTP id g22-20020a056512119600b004fb8cd11679mr9531669lfr.44.1688412842261; Mon, 03 Jul 2023 12:34:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688412842; cv=none; d=google.com; s=arc-20160816; b=qnyLX4GZDKalHJMODMrvx4XLjkvk1VXH+OD0Cou/fmSEsHmKGmsPQEFyd5bNevWYBa HY5eqYEVRvu1cL7QGzhNb7za692TEa/idvqg4Q6LMcQiibzfTyeCkEE37QxWgNEZLnVB IVr7AGhMIocA6Rr2tc5aoAW/qSEk32DIfpO2TgXAgaC5c6F5UBfm2nAu09/2viqgzfdO cbs78Bz3+vG3Srh3eYM3T63p7Re95KH51OGCTgSqIHpcj87mbvEcr1a3ha2ydyQiweOV FK9S5vLefFjWc0deO/ykiAxCkV4kptALzsSOnqXen70OXNsa9HOyYBNEXPM7BLG9ZjX0 FRxg== 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=4u2HR6N+/zCH4DM543jFq+nD09Gp5Dpd9Fl3I3mYFwo=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=mZVwxtXiCM1lFKFl89szN25bDpn186mDPSk02Vkjltye/Tl+8OEMsfnjSb7e68NMLz HM6sKsDrJCTg/QNF91aR+aJKrPxFSM2y6EIL6otcerFCyl+uoFFOVamQ2yMNv+OhwyYg G4QDpCgcwQvzTQnKOTRawTEaMS5D1XPLE3+Sxt080oClBCAv75sYPx4xjCsjMT2G4xR2 Phad9rUXxsj/iRMbhyESBvniEVVvmOAGB3Xq0lHqRnyw9D1bjJZkPra70VAvpP1hRDsa kmNpWSBn/JA2Rn65F6ubCkc2nm1TgMDpWZmDkoqrT3sKihZPrNwwREave3MybBwgmr6g JXcg== 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 k3-20020a05640212c300b0051be9f09bf8si12225327edx.9.2023.07.03.12.34.01; Mon, 03 Jul 2023 12:34:02 -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 51E8F68C5C6; Mon, 3 Jul 2023 22:33:06 +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 E650868C5B3 for ; Mon, 3 Jul 2023 22:32:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 3DDE92404F8 for ; Mon, 3 Jul 2023 21:32:55 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 5KQWfyz5q_zx for ; Mon, 3 Jul 2023 21:32:54 +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 12FEB2406CA for ; Mon, 3 Jul 2023 21:32:52 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id C572F3A1786 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:27 +0200 Message-Id: <20230703193229.8593-9-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 08/10] lavc/bsf: move IS_EMPTY() to packet_internal() 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: ga0toyyYJ5cQ It will be useful in other places. --- libavcodec/bsf.c | 11 +++++------ libavcodec/packet_internal.h | 2 ++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/libavcodec/bsf.c b/libavcodec/bsf.c index 42cc1b5ab0..1e710f7d4a 100644 --- a/libavcodec/bsf.c +++ b/libavcodec/bsf.c @@ -31,8 +31,7 @@ #include "bsf_internal.h" #include "codec_desc.h" #include "codec_par.h" - -#define IS_EMPTY(pkt) (!(pkt)->data && !(pkt)->side_data_elems) +#include "packet_internal.h" static av_always_inline const FFBitStreamFilter *ff_bsf(const AVBitStreamFilter *bsf) { @@ -205,7 +204,7 @@ int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt) FFBSFContext *const bsfi = ffbsfcontext(ctx); int ret; - if (!pkt || IS_EMPTY(pkt)) { + if (!pkt || AVPACKET_IS_EMPTY(pkt)) { if (pkt) av_packet_unref(pkt); bsfi->eof = 1; @@ -217,7 +216,7 @@ int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt) return AVERROR(EINVAL); } - if (!IS_EMPTY(bsfi->buffer_pkt)) + if (!AVPACKET_IS_EMPTY(bsfi->buffer_pkt)) return AVERROR(EAGAIN); ret = av_packet_make_refcounted(pkt); @@ -241,7 +240,7 @@ int ff_bsf_get_packet(AVBSFContext *ctx, AVPacket **pkt) if (bsfi->eof) return AVERROR_EOF; - if (IS_EMPTY(bsfi->buffer_pkt)) + if (AVPACKET_IS_EMPTY(bsfi->buffer_pkt)) return AVERROR(EAGAIN); tmp_pkt = av_packet_alloc(); @@ -261,7 +260,7 @@ int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt) if (bsfi->eof) return AVERROR_EOF; - if (IS_EMPTY(bsfi->buffer_pkt)) + if (AVPACKET_IS_EMPTY(bsfi->buffer_pkt)) return AVERROR(EAGAIN); av_packet_move_ref(pkt, bsfi->buffer_pkt); diff --git a/libavcodec/packet_internal.h b/libavcodec/packet_internal.h index 92a0d4e6d5..52fa6d9be9 100644 --- a/libavcodec/packet_internal.h +++ b/libavcodec/packet_internal.h @@ -23,6 +23,8 @@ #include "packet.h" +#define AVPACKET_IS_EMPTY(pkt) (!(pkt)->data && !(pkt)->side_data_elems) + typedef struct PacketListEntry { struct PacketListEntry *next; AVPacket pkt; 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) From patchwork Mon Jul 3 19:32:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42416 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1e:b0:12b:9ae3:586d with SMTP id c30csp4589590pzh; Mon, 3 Jul 2023 12:34:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ42YjiP2APDKbEVMs7fUM5gSVVDIdPxugHk1m0pkWnVUve5QQ7BMZFkXdGsqu8+xHvA2pTD X-Received: by 2002:a17:907:9867:b0:97e:56d5:b885 with SMTP id ko7-20020a170907986700b0097e56d5b885mr6622202ejc.60.1688412852393; Mon, 03 Jul 2023 12:34:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688412852; cv=none; d=google.com; s=arc-20160816; b=UMJ4NNPLNs3GHhzzqLAQZs+2OJI2XvF4Vfy0qGd1ecGVBrHD199EZs81Pud4ivG9Jf OES/L2ir5WUPWS/eEpAIh1mdJ6t2gO3UiJwgCZM1PFW2schbHbqU7DR48jzMXoeGpv6g iSkQIzcsh+UUgCYHNG90WT4arKU7cn4+lL1xqNVQpd1SWpm8liRdTKSo3SuvTKA3HSET V6+WOrpwTjt4kinoeUPFRe8EJzJpGg+ar0Tvq5Mq8qYppstdiLDIERE9IlKu3T3vo41r +ntakiQNPTtLogSsOssjy8b8/EarbZWDUta8RdvMwjLYC8PalJoyl4xV58owlSP74y5e nJQw== 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=x6iayVBFthy93t1ltTyflhiTnfPG2D69x1Z8MnIL9TA=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=SWsyLOAlgQCeDwK1df4DuDQusgKkOXKWy9OTlJs/91/eE8vttE8hzDpZvaPOrG0BiC Ap7oyp+zoJFD+E0IGtC0fKQ+kZz3PWswtoqbySWzXSNgI6dgoroCYPoF9w5/h4zBMUic CBF3yGW/InLzjVh3Vb/7/wm7v/Gu0QEF7wnFirnGoqgY97Em4nMkZcvBsnVyYU7DJ9ug 7q0mazX20oCmRoexLw3NkQxLF/a5hoUjEFwL1G8zC5PUMem2Wf+3aLkjFBXbbLEmsZl3 7vo1m9scp+NVV3WKLeviwzDWYuNO11LAfjI1Dex11gpjjsxqSDyZkT3Taww8lXZbgJNg C0+w== 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 r20-20020a170906281400b00987d66e6d26si12593898ejc.250.2023.07.03.12.34.10; Mon, 03 Jul 2023 12:34: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; 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 3BCA568C5CB; Mon, 3 Jul 2023 22:33:07 +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 EACD268C5B0 for ; Mon, 3 Jul 2023 22:32:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id BE0ED2406CA for ; Mon, 3 Jul 2023 21:32:55 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id H1t79bWdwjkY 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 188D72406CB for ; Mon, 3 Jul 2023 21:32:52 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id DCF963A1A05 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:29 +0200 Message-Id: <20230703193229.8593-11-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 10/10] lavc/decode: do not perform decoding when sending draining packets 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: ZhQJPhSfZwjG This way decoding errors will not be returned when the user starts draining the decoder, avoiding confusion over whether draining did or did not start. Fixes failures of fate-h264-attachment-631 for certain numbers of frame threads (e.g. 5). --- libavcodec/decode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 89c3c2a48d..269633ce10 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -674,7 +674,7 @@ int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacke } else dc->draining_started = 1; - if (!avci->buffer_frame->buf[0]) { + if (!avci->buffer_frame->buf[0] && !dc->draining_started) { ret = decode_receive_frame_internal(avctx, avci->buffer_frame); if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) return ret;