From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id A87F345BFA for ; Sat, 25 Mar 2023 19:17:49 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2361F68C9FE; Sat, 25 Mar 2023 21:16:20 +0200 (EET) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A385268C97F for ; Sat, 25 Mar 2023 21:16:11 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 5C00A2404EE for ; Sat, 25 Mar 2023 20:16:11 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id BkTuPfZfEToo for ; Sat, 25 Mar 2023 20:16: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 4364D240D03 for ; Sat, 25 Mar 2023 20:16:01 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 0630D3A06E4 for ; Sat, 25 Mar 2023 20:15:55 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 25 Mar 2023 20:15:21 +0100 Message-Id: <20230325191529.10578-15-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230325191529.10578-1-anton@khirnov.net> References: <20230325191529.10578-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/23] fftools/ffmpeg: simplify output stream initialization call graph 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Several places in the code currently call init_output_stream_wrapper(), which in turn calls init_output_stream(), which then calls either enc_init() or init_output_stream_streamcopy(), followed by of_stream_init(), which tells the muxer the stream is ready for muxing. All except one of these callers are in the encoding code, which will be moved to ffmpeg_enc.c. Keeping this structure would then necessitate ffmpeg_enc.c calling back into the common code in ffmpeg.c, which would then just call ffmpeg_mux, thus making the already convoluted call chain even more so. Simplify the situation by using separate paths for filter-fed output streams (audio and video encoders) and others (subtitles, streamcopy, data, attachments). --- fftools/ffmpeg.c | 51 +++++++++++++++++--------------------------- fftools/ffmpeg_enc.c | 7 ++++++ 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 03e5391970..1969ce9295 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -724,25 +724,6 @@ early_exit: return float_pts; } -static int init_output_stream(OutputStream *ost, AVFrame *frame); - -static int init_output_stream_wrapper(OutputStream *ost, AVFrame *frame, - unsigned int fatal) -{ - int ret = AVERROR_BUG; - - if (ost->initialized) - return 0; - - ret = init_output_stream(ost, frame); - if (ret < 0) { - if (fatal) - exit_program(1); - } - - return ret; -} - static double psnr(double d) { return -10.0 * log10(d); @@ -1023,7 +1004,9 @@ static void do_audio_out(OutputFile *of, OutputStream *ost, AVCodecContext *enc = ost->enc_ctx; int ret; - init_output_stream_wrapper(ost, frame, 1); + ret = enc_open(ost, frame); + if (ret < 0) + exit_program(1); if (frame->pts == AV_NOPTS_VALUE) frame->pts = ost->next_pts; @@ -1264,7 +1247,9 @@ static void do_video_out(OutputFile *of, InputStream *ist = ost->ist; AVFilterContext *filter = ost->filter->filter; - init_output_stream_wrapper(ost, next_picture, 1); + ret = enc_open(ost, next_picture); + if (ret < 0) + exit_program(1); frame_rate = av_buffersink_get_frame_rate(filter); if (frame_rate.num > 0 && frame_rate.den > 0) @@ -1820,7 +1805,9 @@ static void flush_encoders(void) of_output_packet(of, ost->pkt, ost, 1); } - init_output_stream_wrapper(ost, NULL, 1); + ret = enc_open(ost, NULL); + if (ret < 0) + exit_program(1); } if (enc->codec_type != AVMEDIA_TYPE_VIDEO && enc->codec_type != AVMEDIA_TYPE_AUDIO) @@ -2967,24 +2954,26 @@ static int init_output_stream_streamcopy(OutputStream *ost) return 0; } -static int init_output_stream(OutputStream *ost, AVFrame *frame) +static int init_output_stream_nofilter(OutputStream *ost) { int ret = 0; if (ost->enc_ctx) { - ret = enc_open(ost, frame); + ret = enc_open(ost, NULL); if (ret < 0) return ret; - } else if (ost->ist) { - ret = init_output_stream_streamcopy(ost); + } else { + if (ost->ist) { + ret = init_output_stream_streamcopy(ost); + if (ret < 0) + return ret; + } + + ret = of_stream_init(output_files[ost->file_index], ost); if (ret < 0) return ret; } - ret = of_stream_init(output_files[ost->file_index], ost); - if (ret < 0) - return ret; - return ret; } @@ -3017,7 +3006,7 @@ static int transcode_init(void) ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)) continue; - ret = init_output_stream_wrapper(ost, NULL, 0); + ret = init_output_stream_nofilter(ost); if (ret < 0) goto dump_format; } diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 9db2ff5ef3..a4660051a2 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -93,6 +93,9 @@ int enc_open(OutputStream *ost, AVFrame *frame) OutputFile *of = output_files[ost->file_index]; int ret; + if (ost->initialized) + return 0; + set_encoder_id(output_files[ost->file_index], ost); if (ist) { @@ -338,5 +341,9 @@ int enc_open(OutputStream *ost, AVFrame *frame) ost->mux_timebase = enc_ctx->time_base; + ret = of_stream_init(of, ost); + if (ret < 0) + return ret; + return 0; } -- 2.39.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".