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 362C645498 for ; Wed, 31 May 2023 14:56:13 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 142E668C2D1; Wed, 31 May 2023 17:55:20 +0300 (EEST) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1CD3168C253 for ; Wed, 31 May 2023 17:55:13 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id EF8902406CD for ; Wed, 31 May 2023 16:55:09 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id C9uQRIoNymUa for ; Wed, 31 May 2023 16:55:09 +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 E52442406CC for ; Wed, 31 May 2023 16:55:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id C766F3A0D97 for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:52 +0200 Message-Id: <20230531145453.20994-22-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 22/23] fftools/ffmpeg_enc: use a private AVPacket instance for encoding 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: The code currently uses OutputStream.pkt, which complicates its ownership semantics. --- fftools/ffmpeg_enc.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 8dd8104cea..2bf4782a9f 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -57,6 +57,9 @@ struct Encoder { AVFrame *sq_frame; + // packet for receiving encoded output + AVPacket *pkt; + // combined size of all the packets received from the encoder uint64_t data_size; @@ -78,6 +81,8 @@ void enc_free(Encoder **penc) av_frame_free(&enc->last_frame); av_frame_free(&enc->sq_frame); + av_packet_free(&enc->pkt); + av_freep(penc); } @@ -97,6 +102,10 @@ int enc_alloc(Encoder **penc, const AVCodec *codec) goto fail; } + enc->pkt = av_packet_alloc(); + if (!enc->pkt) + goto fail; + *penc = enc; return 0; @@ -454,10 +463,11 @@ static int check_recording_time(OutputStream *ost, int64_t ts, AVRational tb) void enc_subtitle(OutputFile *of, OutputStream *ost, AVSubtitle *sub) { + Encoder *e = ost->enc; int subtitle_out_max_size = 1024 * 1024; int subtitle_out_size, nb, i, ret; AVCodecContext *enc; - AVPacket *pkt = ost->pkt; + AVPacket *pkt = e->pkt; int64_t pts; if (sub->pts == AV_NOPTS_VALUE) { @@ -669,7 +679,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) { Encoder *e = ost->enc; AVCodecContext *enc = ost->enc_ctx; - AVPacket *pkt = ost->pkt; + AVPacket *pkt = e->pkt; const char *type_desc = av_get_media_type_string(enc->codec_type); const char *action = frame ? "encode" : "flush"; int ret; -- 2.40.1 _______________________________________________ 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".