From patchwork Thu Oct 13 13:49:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38720 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp348933pzb; Thu, 13 Oct 2022 06:50:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5a4Qx3rawfW9MLdtLxP11fw8VSUfjlLS6tYy0MAjs0V7cqBYg5/QZvhLmujCZrhb0SQjbC X-Received: by 2002:a17:906:846b:b0:78d:f3b9:aadf with SMTP id hx11-20020a170906846b00b0078df3b9aadfmr6585247ejc.731.1665669006375; Thu, 13 Oct 2022 06:50:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665669006; cv=none; d=google.com; s=arc-20160816; b=kxmJDRrwyYgXBoxf847Fk61AvH4iPZSCh3K8jQZyo/i5OGttYAPo5ZissKbpzLpvyd 70SqSv1CysemBj9pX24KoV6rkWT6cemLQyZFsD2UoXIztTAhXqsAq7v8uz8p1+MIWZsZ AuHhju0fspoF1GAwxBoxu8LSLq8hzdIu37DHn0DE6x/LFfloYgEhZ+mEgo1JZd7Hnott CgE3Z7sxfMovPkC5dJV3PLsijObUDIlgSJR74v32lNXWt5NZi57UZc4Z5mXvi4A+nCcY koryM9lRdFlML5LObG0dgu8ncy3whLfgs55iUAm0LPg91KIEpSrjuYXy4/ucl3CmSvh9 bcMg== 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=U5TeYNcqMQG0lna4xWDLiqs7eK+lS8pN3mKTcvYfiTo=; b=lq8M97mZsfPKd/Z+EzTtVqOon2jQcPZTBLvVcCZT2SQRY9f3QIhn+pp6S265IH+x/x X22loiF8lVSmQn2aQA64X6bJY/ut2IRzGXQWgmG3YlWkjWNj53bbmom+p2JwJ40Th9Xt FHeT5EkNru0CvF5yDRevwE5fxGRVf1fQ5kBYKh82xAPVhysDEzDwAvq6xN823y7pGGoT 2PuG+4BF1mFL+fGLuXWn/Hzx65jpjEnyQ89i/zu34hBwQxEJ0ptd/gqslcxA96aOE1ZZ AtN8fj/f2/MwVfkS9obtUkO6N+k0bX0YngjXLZ7bXCaiVZOubDwZgBPQ7Y1hCUvvEw8a hAQA== 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 m15-20020aa7c2cf000000b00456c221ffd5si15976127edp.478.2022.10.13.06.50.05; Thu, 13 Oct 2022 06:50:06 -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 ECC7F68BD6C; Thu, 13 Oct 2022 16:49:25 +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 CA58268BD3B for ; Thu, 13 Oct 2022 16:49:15 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 66A112404F7 for ; Thu, 13 Oct 2022 15:49:15 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id o2FlC2yrvagk for ; Thu, 13 Oct 2022 15:49:14 +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 48EFC240591 for ; Thu, 13 Oct 2022 15:49:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 2F7643A18BC for ; Thu, 13 Oct 2022 15:49:08 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Oct 2022 15:49:01 +0200 Message-Id: <20221013134904.10104-10-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 10/13] fftools/ffmpeg_mux: inline of_muxer_init() into of_open() 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: vQ3++cFKy8W2 A separate muxer init is no longer necessary, now that of_open() has access to Muxer. --- fftools/ffmpeg.h | 4 --- fftools/ffmpeg_mux.c | 56 ++++----------------------------------- fftools/ffmpeg_mux.h | 5 ++++ fftools/ffmpeg_mux_init.c | 39 ++++++++++++++++++++------- 4 files changed, 40 insertions(+), 64 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index fb409c22ad..9ccd158e4b 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -727,10 +727,6 @@ int hw_device_setup_for_filter(FilterGraph *fg); int hwaccel_decode_init(AVCodecContext *avctx); -int of_muxer_init(OutputFile *of, AVFormatContext *fc, - AVDictionary *opts, int64_t limit_filesize, - int thread_queue_size); - /* * Initialize muxing state for the given stream, should be called * after the codec/streamcopy setup has been done. diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 4c56f4ba96..2f71e03144 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -38,7 +38,7 @@ #include "libavformat/avformat.h" #include "libavformat/avio.h" -static int want_sdp = 1; +int want_sdp = 1; static Muxer *mux_from_of(OutputFile *of) { @@ -487,9 +487,9 @@ fail: return ret; } -static int mux_check_init(OutputFile *of) +int mux_check_init(Muxer *mux) { - Muxer *mux = mux_from_of(of); + OutputFile *of = &mux->of; AVFormatContext *fc = mux->fc; int ret, i; @@ -538,12 +538,13 @@ static int mux_check_init(OutputFile *of) int of_stream_init(OutputFile *of, OutputStream *ost) { + Muxer *mux = mux_from_of(of); 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); + return mux_check_init(mux); } int of_write_trailer(OutputFile *of) @@ -638,53 +639,6 @@ void of_close(OutputFile **pof) av_freep(pof); } -int of_muxer_init(OutputFile *of, AVFormatContext *fc, - AVDictionary *opts, int64_t limit_filesize, - int thread_queue_size) -{ - Muxer *mux = mux_from_of(of); - int ret = 0; - - mux->streams = av_calloc(fc->nb_streams, sizeof(*mux->streams)); - if (!mux->streams) { - fc_close(&fc); - return AVERROR(ENOMEM); - } - of->nb_streams = fc->nb_streams; - - mux->fc = fc; - - for (int i = 0; i < fc->nb_streams; i++) { - MuxStream *ms = &mux->streams[i]; - ms->muxing_queue = av_fifo_alloc2(8, sizeof(AVPacket*), 0); - if (!ms->muxing_queue) { - ret = AVERROR(ENOMEM); - goto fail; - } - ms->last_mux_dts = AV_NOPTS_VALUE; - } - - mux->thread_queue_size = thread_queue_size > 0 ? thread_queue_size : 8; - mux->limit_filesize = limit_filesize; - mux->opts = opts; - - if (strcmp(of->format->name, "rtp")) - want_sdp = 0; - - /* write the header for files with no streams */ - if (of->format->flags & AVFMT_NOSTREAMS && fc->nb_streams == 0) { - ret = mux_check_init(of); - if (ret < 0) - goto fail; - } - -fail: - if (ret < 0) - mux_free(mux); - - return ret; -} - int64_t of_filesize(OutputFile *of) { Muxer *mux = mux_from_of(of); diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h index 90ff979ec1..d9c4dce750 100644 --- a/fftools/ffmpeg_mux.h +++ b/fftools/ffmpeg_mux.h @@ -71,4 +71,9 @@ typedef struct Muxer { AVPacket *sq_pkt; } Muxer; +/* whether we want to print an SDP, set in of_open() */ +extern int want_sdp; + +int mux_check_init(Muxer *mux); + #endif /* FFTOOLS_FFMPEG_MUX_H */ diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 6c4d9bad1e..be7286c26d 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1582,7 +1582,7 @@ int of_open(OptionsContext *o, const char *filename) AVFormatContext *oc; int i, j, err; OutputFile *of; - AVDictionary *unused_opts = NULL, *format_opts = NULL; + AVDictionary *unused_opts = NULL; const AVDictionaryEntry *e = NULL; if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) { @@ -1608,7 +1608,10 @@ int of_open(OptionsContext *o, const char *filename) of->recording_time = o->recording_time; of->start_time = o->start_time; of->shortest = o->shortest; - av_dict_copy(&format_opts, o->g->format_opts, 0); + + mux->thread_queue_size = o->thread_queue_size > 0 ? o->thread_queue_size : 8; + mux->limit_filesize = o->limit_filesize; + av_dict_copy(&mux->opts, o->g->format_opts, 0); if (!strcmp(filename, "-")) filename = "pipe:"; @@ -1618,6 +1621,10 @@ int of_open(OptionsContext *o, const char *filename) print_error(filename, err); exit_program(1); } + mux->fc = oc; + + if (strcmp(oc->oformat->name, "rtp")) + want_sdp = 0; of->format = oc->oformat; if (o->recording_time != INT64_MAX) @@ -1629,7 +1636,7 @@ int of_open(OptionsContext *o, const char *filename) oc->flags |= AVFMT_FLAG_BITEXACT; of->bitexact = 1; } else { - of->bitexact = check_opt_bitexact(oc, format_opts, "fflags", + of->bitexact = check_opt_bitexact(oc, mux->opts, "fflags", AVFMT_FLAG_BITEXACT); } @@ -1798,7 +1805,7 @@ int of_open(OptionsContext *o, const char *filename) /* open the file */ if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE, &oc->interrupt_callback, - &format_opts)) < 0) { + &mux->opts)) < 0) { print_error(filename, err); exit_program(1); } @@ -1806,7 +1813,7 @@ int of_open(OptionsContext *o, const char *filename) assert_file_overwrite(filename); if (o->mux_preload) { - av_dict_set_int(&format_opts, "preload", o->mux_preload*AV_TIME_BASE, 0); + av_dict_set_int(&mux->opts, "preload", o->mux_preload*AV_TIME_BASE, 0); } oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE); @@ -1884,10 +1891,24 @@ int of_open(OptionsContext *o, const char *filename) of->url = filename; - err = of_muxer_init(of, oc, format_opts, o->limit_filesize, o->thread_queue_size); - if (err < 0) { - av_log(NULL, AV_LOG_FATAL, "Error initializing internal muxing state\n"); - exit_program(1); + mux->streams = av_calloc(oc->nb_streams, sizeof(*mux->streams)); + if (!mux->streams) + return AVERROR(ENOMEM); + of->nb_streams = oc->nb_streams; + + for (int i = 0; i < oc->nb_streams; i++) { + MuxStream *ms = &mux->streams[i]; + ms->muxing_queue = av_fifo_alloc2(8, sizeof(AVPacket*), 0); + if (!ms->muxing_queue) + return AVERROR(ENOMEM); + ms->last_mux_dts = AV_NOPTS_VALUE; + } + + /* write the header for files with no streams */ + if (of->format->flags & AVFMT_NOSTREAMS && oc->nb_streams == 0) { + int ret = mux_check_init(mux); + if (ret < 0) + return ret; } return 0;