From patchwork Sat Nov 4 07:56: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: 44525 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3aa6:b0:181:818d:5e7f with SMTP id d38csp337081pzh; Sat, 4 Nov 2023 02:25:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH0nxCs/i5AyPvBBdkHVDoFCneKGwnEqaWDjSp4TTKLvqcZHP9dKtiZ8zHGR39U9tToh9Ey X-Received: by 2002:aa7:d8cc:0:b0:53f:8493:5b0b with SMTP id k12-20020aa7d8cc000000b0053f84935b0bmr18050372eds.35.1699089931265; Sat, 04 Nov 2023 02:25:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699089931; cv=none; d=google.com; s=arc-20160816; b=D4JTumbde7dAf3zeE3Zz9h1fKG4rcjG5IbOJlu5hCXMDKi0yu+8TXQZzqpmXdd14yV QMWt7bZfPlmpv3yBFpnd78sIM5Jn4R9TBfxSq6R7h+tV1yv5wGHF/6OLA7dnxelcMpuG t14dbuFEIdGm8qFtdmpbweSAyKk8LPWEk10+rdYNQy3PdybcAcAarljVvbHe5AFHWK0x ZT87alm6zrWwcjSS9OB2e0NlR2aONIOLPoQDD8hTcaisPugj+V3RbHWgz3uEB7UfYxw2 tmCx9lgoXFR032hRxSmZtyHFCMtdhQWCvPisVQ1k8PoxjoXUaiHeKsJu5b5eSz2SHKPM 5RAw== 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=WRYHU8srqVUBIodQwtoCyxxmwbdXL/EHY9ZVuHRdpMM=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=ci94fi3QvD3ttjzhhc1bsehvzQDVcNH3ixTFQu0fBw6hzb3yEwEs6FGJKCiKwnmPpL 75Uob80kbCQkbIRNaPqvT7ckYDhR1notXYKM2Ngv3N4LF08+9l9ExicoJKoLYIbchJgL i/ZUWdaEIZ9FYU7mFC1g72bLhhopSvA2qvGtCSsdf+/MOlGcexjBNUEnMaOSwpDiJCTG OgSCQ4v9CUK+7MZOYs7CXOIpPYFbyDDLx1brXvoHpMp3EYv/yHv+y6Lt190IScLOm3xM LpnH6Jk1OTjskkrhy2X4kYAL1m5b6nLtVrSaFMiQLuEWYNe9ZjNMPYZ4muDsCTPjKHca z8Gw== 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 r15-20020a05640251cf00b00543565fe380si1900700edd.102.2023.11.04.02.25.30; Sat, 04 Nov 2023 02:25:31 -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 76B4D68CEDE; Sat, 4 Nov 2023 11:22:19 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8D98868CE5C for ; Sat, 4 Nov 2023 11:21:55 +0200 (EET) Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id BD0DD14AB for ; Sat, 4 Nov 2023 10:21:54 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id UJiov6USPWF0 for ; Sat, 4 Nov 2023 10:21:54 +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 mail1.khirnov.net (Postfix) with ESMTPS id 0EF0714E7 for ; Sat, 4 Nov 2023 10:21:47 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A6B1B3A11D6 for ; Sat, 4 Nov 2023 10:21:40 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 4 Nov 2023 08:56:22 +0100 Message-ID: <20231104092125.10213-14-anton@khirnov.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231104092125.10213-1-anton@khirnov.net> References: <20231104092125.10213-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/24] fftools/ffmpeg_mux: add muxing thread 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: tLP5GesK9C5B To be used for data that never needs to be visible outside of the muxer thread. Start by moving the muxed AVPacket in there. --- fftools/ffmpeg_mux.c | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 30c033036d..82352b7981 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -39,6 +39,10 @@ #include "libavformat/avformat.h" #include "libavformat/avio.h" +typedef struct MuxThreadContext { + AVPacket *pkt; +} MuxThreadContext; + int want_sdp = 1; static Muxer *mux_from_of(OutputFile *of) @@ -210,18 +214,40 @@ static void thread_set_name(OutputFile *of) ff_thread_setname(name); } +static void mux_thread_uninit(MuxThreadContext *mt) +{ + av_packet_free(&mt->pkt); + + memset(mt, 0, sizeof(*mt)); +} + +static int mux_thread_init(MuxThreadContext *mt) +{ + memset(mt, 0, sizeof(*mt)); + + mt->pkt = av_packet_alloc(); + if (!mt->pkt) + goto fail; + + return 0; + +fail: + mux_thread_uninit(mt); + return AVERROR(ENOMEM); +} + static void *muxer_thread(void *arg) { Muxer *mux = arg; OutputFile *of = &mux->of; - AVPacket *pkt = NULL; + + MuxThreadContext mt; + int ret = 0; - pkt = av_packet_alloc(); - if (!pkt) { - ret = AVERROR(ENOMEM); + ret = mux_thread_init(&mt); + if (ret < 0) goto finish; - } thread_set_name(of); @@ -229,7 +255,7 @@ static void *muxer_thread(void *arg) OutputStream *ost; int stream_idx, stream_eof = 0; - ret = tq_receive(mux->tq, &stream_idx, pkt); + ret = tq_receive(mux->tq, &stream_idx, mt.pkt); if (stream_idx < 0) { av_log(mux, AV_LOG_VERBOSE, "All streams finished\n"); ret = 0; @@ -237,8 +263,8 @@ static void *muxer_thread(void *arg) } ost = of->streams[stream_idx]; - ret = sync_queue_process(mux, ost, ret < 0 ? NULL : pkt, &stream_eof); - av_packet_unref(pkt); + ret = sync_queue_process(mux, ost, ret < 0 ? NULL : mt.pkt, &stream_eof); + av_packet_unref(mt.pkt); if (ret == AVERROR_EOF) { if (stream_eof) { tq_receive_finish(mux->tq, stream_idx); @@ -254,7 +280,7 @@ static void *muxer_thread(void *arg) } finish: - av_packet_free(&pkt); + mux_thread_uninit(&mt); for (unsigned int i = 0; i < mux->fc->nb_streams; i++) tq_receive_finish(mux->tq, i);