From patchwork Mon Dec 13 15:20:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 32430 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5574426iog; Mon, 13 Dec 2021 07:24:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJyWI+RREPVhm3oPUk7Fax4tJ2Yd6B8Y3Snr7YeCxrWqibBGtlVyTYH7bOB0F/pVDKy42g/p X-Received: by 2002:a17:906:b51:: with SMTP id v17mr45857685ejg.262.1639409045602; Mon, 13 Dec 2021 07:24:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639409045; cv=none; d=google.com; s=arc-20160816; b=syTLhwzqRhkyPxW9CPNxHw3KHkpFUs++SVBHjJ6qHvpe1/+S6SbMAEao24dqHKsX/s RBvKEKsJ/clkCmPddqjj4fxxYh1qA7cRnirnsG1H8JQDC3u4rVNYYW0zDFofaRXsd6kA URpPAVhLA+J+eQqm66yergNWG9MEBtCFn02BPsSRxLFI1U0ujo2zgoSjMyWceJeYFHvw FAKcT4+pX1Pa2LL/20m2LdXwc6PEoeUE/Ov+XzulTqiBEvT8uQbKzsbxis+47SuXhtXf 4FaOfnrKQO3Q1tlBzHbXVMVoXRiAnqPK6OnSz9ZZte9amZjVjcFVVDoHYt0FiLsah8yw 5YFQ== 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=PoarOX/+2TH4b4Y6RAhiUzcHpc9MEEbAIIdAcVuYqHo=; b=aVVvIRD55nfYSr68WQqqrlMIVJMSTEA+mT//TglEWZ6G7zYaBFGQRVBxVpiadV4TTb cGtdV7CbfLKajT+sXF0q/iGTbL3E6vr8oA5ad5t4O6BHe83pAbUH9a4ER1KDjm7Jgber 8OeDLi2S2/GhNSZBJFlrZzar4G/Y7T47Ga2IKHM0bEHfPIaJ/su7BP4daG6AwW8yXghi tkvTQunn1ERvJA7pguxnoKeq/lVq2Tm60nCJbNTBzzG0IZr3oke0PqPaeTnmM8kTO7hN 8nu3ykIWGEPpsw1+hYq1ZCNzHknC1iTTgglHteRuaR0LUF8D97U6maXdwMceG4FU19hN Umog== 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 e15si22656449edz.579.2021.12.13.07.24.05; Mon, 13 Dec 2021 07:24:05 -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 183FF68AF8F; Mon, 13 Dec 2021 17:22:25 +0200 (EET) 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 6D19368AFAD for ; Mon, 13 Dec 2021 17:22:14 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 36047240511 for ; Mon, 13 Dec 2021 16:22:11 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id cAOn4QRjPgjw for ; Mon, 13 Dec 2021 16:22:10 +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 mail0.khirnov.net (Postfix) with ESMTPS id A63AA24055A for ; Mon, 13 Dec 2021 16:22:07 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 2CC763A09CE; Mon, 13 Dec 2021 16:22:07 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 13 Dec 2021 16:20:27 +0100 Message-Id: <20211213152042.5900-9-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211213152042.5900-1-anton@khirnov.net> References: <20211213152042.5900-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/24] ffmpeg_mux: add private muxer context 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: 10GRdq2qufWP Move header_written into it, which is not (and should not be) used by any code outside of ffmpeg_mux. In the future this context will contain more muxer-private state that should not be visible to other code. --- fftools/ffmpeg.h | 6 ++++-- fftools/ffmpeg_mux.c | 26 ++++++++++++++++++++++---- fftools/ffmpeg_opt.c | 6 ++++++ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index c28acad4f1..279a99cc48 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -573,9 +573,12 @@ typedef struct OutputStream { int64_t error[4]; } OutputStream; +typedef struct Muxer Muxer; + typedef struct OutputFile { int index; + Muxer *mux; const AVOutputFormat *format; AVFormatContext *ctx; @@ -586,8 +589,6 @@ typedef struct OutputFile { uint64_t limit_filesize; /* filesize limit expressed in bytes */ int shortest; - - int header_written; } OutputFile; extern InputStream **input_streams; @@ -686,6 +687,7 @@ int hw_device_setup_for_filter(FilterGraph *fg); int hwaccel_decode_init(AVCodecContext *avctx); +int of_muxer_init(OutputFile *of); /* open the muxer when all the streams are initialized */ int of_check_init(OutputFile *of); int of_write_trailer(OutputFile *of); diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 9787fe7f78..cf85db674e 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -32,6 +32,10 @@ #include "ffmpeg.h" +struct Muxer { + int header_written; +}; + static void close_all_output_streams(OutputStream *ost, OSTFinished this_stream, OSTFinished others) { int i; @@ -64,7 +68,7 @@ void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, ost->frame_number++; } - if (!of->header_written) { + if (!of->mux->header_written) { AVPacket *tmp_pkt; /* the muxer is not initialized yet, buffer the packet */ if (!av_fifo_space(ost->muxing_queue)) { @@ -195,7 +199,7 @@ static int print_sdp(void) AVFormatContext **avc; for (i = 0; i < nb_output_files; i++) { - if (!output_files[i]->header_written) + if (!output_files[i]->mux->header_written) return 0; } @@ -259,7 +263,7 @@ int of_check_init(OutputFile *of) return ret; } //assert_avoptions(of->opts); - of->header_written = 1; + of->mux->header_written = 1; av_dump_format(of->ctx, of->index, of->ctx->url, 1); nb_output_dumped++; @@ -296,7 +300,7 @@ int of_write_trailer(OutputFile *of) { int ret; - if (!of->header_written) { + if (!of->mux->header_written) { av_log(NULL, AV_LOG_ERROR, "Nothing was written into output file %d (%s), because " "at least one of its streams received no packets.\n", @@ -327,5 +331,19 @@ void of_close(OutputFile **pof) avformat_free_context(s); av_dict_free(&of->opts); + av_freep(&of->mux); + av_freep(pof); } + +int of_muxer_init(OutputFile *of) +{ + Muxer *mux = av_mallocz(sizeof(*mux)); + + if (!mux) + return AVERROR(ENOMEM); + + of->mux = mux; + + return 0; +} diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 433102bb49..5b42b450f3 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2886,6 +2886,12 @@ loop_end: exit_program(1); } + err = of_muxer_init(of); + if (err < 0) { + av_log(NULL, AV_LOG_FATAL, "Error initializing the muxer\n"); + exit_program(1); + } + return 0; }