From patchwork Thu Nov 23 19:15:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 44772 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bca6:b0:181:818d:5e7f with SMTP id fx38csp802353pzb; Thu, 23 Nov 2023 11:20:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IHhbdPH6TnJuGfuThnBJALpjfN7B2BsNFKY/b/J9QCZOeWZPix2j0OkSpYDd/Sbv6P3LFms X-Received: by 2002:ac2:5f85:0:b0:503:2e6:6862 with SMTP id r5-20020ac25f85000000b0050302e66862mr125834lfe.32.1700767206773; Thu, 23 Nov 2023 11:20:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700767206; cv=none; d=google.com; s=arc-20160816; b=eZO+VA3Cxfmn66PbsNaTdIP9KQRqKYuWOc2Dfwb2iRbvD7BiV1L0hbGwyEER3srldt mLdnqLVuQNJUZidsIigMK8tPM3g4plST6ljqMvC2z0nLFQQ41456h2o8HGJ0P0HIvDDl dlZMSIGhR06HyQ323OupKf5uGkYJPzkm6930c6fNSCFlM3bPZHuE/C0Og9VUgVV+oqzZ Of8mAGLBBCMxftqoJdAFj0yPa21WlKohguUK8mqfZSOyypNhC1mWUKZLqTihIdmbrugC Vfxnvepdj7br/6ZlmykiDmj3UMZPtjSnxdo0mgjdSlHA5c6lArr7dvKYykIZyP1OrStx 546w== 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=iS7BAecR6c9fZvPi/jBru93cJ9fLHJbS/F6fCTU37/Q00xtyZtEu85otivw7bVNbjd ZBmC3393mhkoPgI4M/okomeqziw1Dbrar9Tw+uz2cHaEehswxQ/v/0RiEB6xNAnR+s1A BUryY76ZqRUkhw93pWmDg2xsg95/GQLxbnnM3ddg+SkC9ylG7ca3yqXm1L01WVf7zi8r I07ikIMk5XTrmYv3p5FSsLRtzUohqVwDBfevRnm38gVYTxKr9nrxV9bIu3vOLYInELxj mgGh0b4RimCbTd5OYhdFEgGVBo5NWk8GawHpnyzFVRTwhL5hywpz/CDw16JWEA/xZaRt 7ekA== 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 w15-20020a056402268f00b0054ab2105c99si800890edd.576.2023.11.23.11.20.06; Thu, 23 Nov 2023 11:20:06 -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 40AD268CF02; Thu, 23 Nov 2023 21:19:02 +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 2170968CEF7 for ; Thu, 23 Nov 2023 21:18:54 +0200 (EET) Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 90DFA14E4 for ; Thu, 23 Nov 2023 20:18:18 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id G56fBNQ_LiMF for ; Thu, 23 Nov 2023 20:18:18 +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 61B441531 for ; Thu, 23 Nov 2023 20:18:15 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 555E73A0582 for ; Thu, 23 Nov 2023 20:18:15 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 23 Nov 2023 20:15:03 +0100 Message-ID: <20231123191524.11296-10-anton@khirnov.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231123191524.11296-2-anton@khirnov.net> References: <20231123191524.11296-2-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/13] 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: awmDbtPHx19z 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);