From patchwork Thu Oct 13 13:48:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38721 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp348993pzb; Thu, 13 Oct 2022 06:50:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6ZWK2mJ37DibdJefwZmy1qGbZcAq3/ju/BhaDLgRJhQr9N7SE+6ZNiVUlxYDS/PUcrlvX1 X-Received: by 2002:a05:6402:e9b:b0:454:351c:c222 with SMTP id h27-20020a0564020e9b00b00454351cc222mr32726472eda.216.1665669014651; Thu, 13 Oct 2022 06:50:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665669014; cv=none; d=google.com; s=arc-20160816; b=BYXn59CyQzodcHUg5rnApku4IHTApTd6YsMc2FD5omWPULm8ZdwfQ+611YTIoDiynt UM2c8MkUyv6gpC5D1MwQYTkMhITJFHRDmSS/1Nqo2yXVWU6M+KMQAv85l6kn84HX8TkE eREmY+LCsiWDQ2YfHXLTSX9dF242rkSKFs7cUkEyiGAvg9CkbFgBZjx2kcy1wSQgW3mj VM11/w950HijDmfLPPZ8fUGHZDWHXyaeZXrYnW9EAfBAerKQZRh2cYuaH7y+bY5wYUxB yxFvB82Ls6rlmwlbxw4CM1qsbdTvo8IYFJnUFfM5QXPaTfxPqb+wan544lcT+4oAucrE AWXw== 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=Ut3cpa1JhqozQ2fCgwwZAbB8a2wrq7tER8W1VI7Jao4=; b=GvrdMHe6+VBVNwBfz2kZWQHfKuArfinhbQar/bqz0uvjP4gJz7gqKkeeq2FV3z4IY8 moMn5Mt/RDn6y7LCvgNxwEkMNYDoLZYwUxbBLIg2oQJDjB+/F3Qd9WW7cQzo4bQOnee7 o5FVtnr+usMjitLA5wP6zBHbccPDF8Hl5N6SPsdrhD6Z9sNuFByG4MBzOueMKfNQbLr7 +WeoLAQXeNKw41D+l653UBnObb0yGl7UGpDPw28+t2gFE7CFR/S4J0sGdi7dHd+0rSEB cf7yJhjI38vNvPbukdz2bOHNOxswdKv/NRszUnnptFk15rGkTaRUuaHPlVb5pIGdGdA8 SRbg== 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 l6-20020a170906644600b0077b287e3adesi17371980ejn.190.2022.10.13.06.50.14; Thu, 13 Oct 2022 06:50:14 -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 058CA68BD7F; Thu, 13 Oct 2022 16:49:27 +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 1A9AB68BD3B for ; Thu, 13 Oct 2022 16:49:21 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 9C47E2406CB for ; Thu, 13 Oct 2022 15:49:18 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id uSPhk4njvaqe for ; Thu, 13 Oct 2022 15:49:18 +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 7EC402406CD for ; Thu, 13 Oct 2022 15:49:14 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 099373A168C for ; Thu, 13 Oct 2022 15:49:08 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Oct 2022 15:48:56 +0200 Message-Id: <20221013134904.10104-5-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221013134904.10104-1-anton@khirnov.net> References: <20221013134904.10104-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/13] fftools/ffmpeg: move some stream initialization code to ffmpeg_mux 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: pmypJknUUF5r The code in question is muxing-specific and so belongs there. This will allow make some objects private to the muxer in future commits. --- fftools/ffmpeg.c | 8 +------- fftools/ffmpeg.h | 10 ++++++++-- fftools/ffmpeg_mux.c | 15 ++++++++++++--- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 015ff762c9..9bb877fb34 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3115,7 +3115,6 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame) static int init_output_stream(OutputStream *ost, AVFrame *frame, char *error, int error_len) { - OutputFile *of = output_files[ost->file_index]; int ret = 0; if (ost->enc_ctx) { @@ -3220,12 +3219,7 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame, if (ret < 0) return ret; - if (ost->sq_idx_mux >= 0) - sq_set_tb(of->sq_mux, ost->sq_idx_mux, ost->mux_timebase); - - ost->initialized = 1; - - ret = of_check_init(output_files[ost->file_index]); + ret = of_stream_init(output_files[ost->file_index], ost); if (ret < 0) return ret; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 632b7c0e86..5030f72fe5 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -720,8 +720,14 @@ int hwaccel_decode_init(AVCodecContext *avctx); int of_muxer_init(OutputFile *of, AVFormatContext *fc, AVDictionary *opts, int64_t limit_filesize, int thread_queue_size); -/* open the muxer when all the streams are initialized */ -int of_check_init(OutputFile *of); + +/* + * Initialize muxing state for the given stream, should be called + * after the codec/streamcopy setup has been done. + * + * Open the muxer once all the streams have been initialized. + */ +int of_stream_init(OutputFile *of, OutputStream *ost); int of_write_trailer(OutputFile *of); void of_close(OutputFile **pof); diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 63f63c0852..7bc25c6175 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -516,8 +516,7 @@ fail: return ret; } -/* open the muxer when all the streams are initialized */ -int of_check_init(OutputFile *of) +static int mux_check_init(OutputFile *of) { AVFormatContext *fc = of->mux->fc; int ret, i; @@ -565,6 +564,16 @@ int of_check_init(OutputFile *of) return 0; } +int of_stream_init(OutputFile *of, OutputStream *ost) +{ + if (ost->sq_idx_mux >= 0) + sq_set_tb(of->sq_mux, ost->sq_idx_mux, ost->mux_timebase); + + ost->initialized = 1; + + return mux_check_init(of); +} + int of_write_trailer(OutputFile *of) { AVFormatContext *fc = of->mux->fc; @@ -710,7 +719,7 @@ int of_muxer_init(OutputFile *of, AVFormatContext *fc, /* write the header for files with no streams */ if (of->format->flags & AVFMT_NOSTREAMS && fc->nb_streams == 0) { - ret = of_check_init(of); + ret = mux_check_init(of); if (ret < 0) goto fail; }