From patchwork Thu Jun 16 19:55:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 36279 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp1129099pzb; Thu, 16 Jun 2022 13:07:11 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vjtChSX8is1zP7IfPr5CW8qPPuJKHQQGGlnwTuASMoG5NOtnai+v+cFagSBA49t3NYg+O4 X-Received: by 2002:a17:906:b208:b0:70e:c7f1:f8bf with SMTP id p8-20020a170906b20800b0070ec7f1f8bfmr6066129ejz.143.1655410031125; Thu, 16 Jun 2022 13:07:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655410031; cv=none; d=google.com; s=arc-20160816; b=FwGyLQPp/Wm86g65+hl9mOlkn5rEepJN4+MlHVRnF9envqxHhuxPv3FyHFj3GUuCfr 4sf2Ht3m709DkQjCSPSR3YNWgJ8RXWafElr/D8dckCc4ocxl84z9GQd9p60zqbPlbbN0 J3Qow1dP9MtlBQcL2BhpcPqmmRGDEoAQljKD1ICbxIUkYWuFUrXBCsKBJ/gHWKPvEF4w iviJPmb5LNKvYfYaJz3NCWsaD++InTVkuUB8nZFZa/5aOuOE+lJNiKXDUeIo7dlvdbp6 j8JqjXnDax8d77n18PeFoiIJTud/hXWk/MLqjfoNsWGpnUu2Oz8Ss3KUlI13NiK4FPoO MnJg== 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:message-id:date:to:from :delivered-to; bh=Co/MbI6RlNTAKVeKQM+V1SuItBpZN6cTD4OuUYNAozk=; b=LwBVFX/or/s9/6b6rU9fukJfbhplDFTFCZg02nAigVukjlcszHAs2nz09en9LbFoui xxWnYdHUJAjsnmSU/wVTLD1H2vv6ZkmlCMkP4NNbrZYHf5CwMpM+NqcMOkE4nYlGWT9o fLo1uFPHNmyNkkbP77PR9LWNUZRawDTX6euc/PIqN8AGxDb6di7E9I28JduN86HjhI94 XQTTi+4zhYkeyqtwW1QQPF9JoAIsKOZoerR+wUs/V0f6pRRhNnUK+g/W4a3tCHiUumNd drBGKGAKve+Om+cG97Mm50i2Gyq/Ipc3lkQvfEPJVKN8n/EZaXjPXG7o40yodi0klm0t WDug== 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 k18-20020a05640212d200b0042dffafcf4dsi768005edx.35.2022.06.16.13.07.10; Thu, 16 Jun 2022 13:07: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 5E04F68B8C7; Thu, 16 Jun 2022 23:04: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 90E7568B850 for ; Thu, 16 Jun 2022 23:03:41 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 86D27240512 for ; Thu, 16 Jun 2022 22:03:39 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id D_3KlKcVwZE9 for ; Thu, 16 Jun 2022 22:03:39 +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 0537F24055A for ; Thu, 16 Jun 2022 22:03:34 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 794913A0A3A; Thu, 16 Jun 2022 22:03:30 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 16 Jun 2022 21:55:00 +0200 Message-Id: <20220616195534.5278-1-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/35] fftools/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: F5vOJuyi+5Zn 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 69a368b8d1..c6ffe9fdf6 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -581,9 +581,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; @@ -594,8 +597,6 @@ typedef struct OutputFile { uint64_t limit_filesize; /* filesize limit expressed in bytes */ int shortest; - - int header_written; } OutputFile; extern InputStream **input_streams; @@ -694,6 +695,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 a55fd18f8f..e47a55c4e9 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -32,6 +32,10 @@ #include "libavformat/avformat.h" #include "libavformat/avio.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_can_write(ost->muxing_queue)) { @@ -182,7 +186,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; } @@ -246,7 +250,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++; @@ -282,7 +286,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", @@ -313,5 +317,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 398067da96..ab8d307c3c 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2947,6 +2947,12 @@ loop_end: exit_program(1); } + err = of_muxer_init(of); + if (err < 0) { + av_log(NULL, AV_LOG_FATAL, "Error initializing internal muxing state\n"); + exit_program(1); + } + return 0; }