Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 05/18] fftools/ffmpeg_dec: factor opening the decoder out of dec_open()
Date: Wed,  6 Mar 2024 12:03:06 +0100
Message-ID: <20240306110319.17339-5-anton@khirnov.net> (raw)
In-Reply-To: <20240306110319.17339-1-anton@khirnov.net>

Rename dec_open to dec_init(), as it is more descriptive of its new
purpose.

Will be useful in following commits, which will add a new path for
opening decoders.
---
 fftools/ffmpeg.h       |  2 +-
 fftools/ffmpeg_dec.c   | 61 ++++++++++++++++++++++--------------------
 fftools/ffmpeg_demux.c |  2 +-
 3 files changed, 34 insertions(+), 31 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 1c5ebcb43f..6b049e329b 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -740,7 +740,7 @@ AVBufferRef *hw_device_for_filter(void);
  * @retval ">=0" non-negative scheduler index on success
  * @retval "<0"  an error code on failure
  */
-int dec_open(Decoder **pdec, Scheduler *sch,
+int dec_init(Decoder **pdec, Scheduler *sch,
              AVDictionary **dec_opts, const DecoderOpts *o);
 void dec_free(Decoder **pdec);
 
diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index 98c4a0c83c..af57b2bb9d 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -1066,19 +1066,11 @@ static int hw_device_setup_for_decode(DecoderPriv *dp,
     return 0;
 }
 
-int dec_open(Decoder **pdec, Scheduler *sch,
-             AVDictionary **dec_opts, const DecoderOpts *o)
+static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts, const DecoderOpts *o)
 {
-    DecoderPriv *dp;
     const AVCodec *codec = o->codec;
     int ret;
 
-    *pdec = NULL;
-
-    ret = dec_alloc(&dp, sch, !!(o->flags & DECODER_FLAG_SEND_END_TS));
-    if (ret < 0)
-        return ret;
-
     dp->flags      = o->flags;
     dp->log_parent = o->log_parent;
 
@@ -1091,39 +1083,31 @@ int dec_open(Decoder **pdec, Scheduler *sch,
     snprintf(dp->log_name, sizeof(dp->log_name), "dec:%s", codec->name);
 
     dp->parent_name = av_strdup(o->name ? o->name : "");
-    if (!dp->parent_name) {
-        ret = AVERROR(ENOMEM);
-        goto fail;
-    }
+    if (!dp->parent_name)
+        return AVERROR(ENOMEM);
 
     if (codec->type == AVMEDIA_TYPE_SUBTITLE &&
         (dp->flags & DECODER_FLAG_FIX_SUB_DURATION)) {
         for (int i = 0; i < FF_ARRAY_ELEMS(dp->sub_prev); i++) {
             dp->sub_prev[i] = av_frame_alloc();
-            if (!dp->sub_prev[i]) {
-                ret = AVERROR(ENOMEM);
-                goto fail;
-            }
+            if (!dp->sub_prev[i])
+                return AVERROR(ENOMEM);
         }
         dp->sub_heartbeat = av_frame_alloc();
-        if (!dp->sub_heartbeat) {
-            ret = AVERROR(ENOMEM);
-            goto fail;
-        }
+        if (!dp->sub_heartbeat)
+            return AVERROR(ENOMEM);
     }
 
     dp->sar_override = o->par->sample_aspect_ratio;
 
     dp->dec_ctx = avcodec_alloc_context3(codec);
-    if (!dp->dec_ctx) {
-        ret = AVERROR(ENOMEM);
-        goto fail;
-    }
+    if (!dp->dec_ctx)
+        return AVERROR(ENOMEM);
 
     ret = avcodec_parameters_to_context(dp->dec_ctx, o->par);
     if (ret < 0) {
         av_log(dp, AV_LOG_ERROR, "Error initializing the decoder context.\n");
-        goto fail;
+        return ret;
     }
 
     dp->dec_ctx->opaque                = dp;
@@ -1140,22 +1124,41 @@ int dec_open(Decoder **pdec, Scheduler *sch,
         av_log(dp, AV_LOG_ERROR,
                "Hardware device setup failed for decoder: %s\n",
                av_err2str(ret));
-        goto fail;
+        return ret;
     }
 
     if ((ret = avcodec_open2(dp->dec_ctx, codec, dec_opts)) < 0) {
         av_log(dp, AV_LOG_ERROR, "Error while opening decoder: %s\n",
                av_err2str(ret));
-        goto fail;
+        return ret;
     }
 
     ret = check_avoptions(*dec_opts);
     if (ret < 0)
-        goto fail;
+        return ret;
 
     dp->dec.subtitle_header      = dp->dec_ctx->subtitle_header;
     dp->dec.subtitle_header_size = dp->dec_ctx->subtitle_header_size;
 
+    return 0;
+}
+
+int dec_init(Decoder **pdec, Scheduler *sch,
+             AVDictionary **dec_opts, const DecoderOpts *o)
+{
+    DecoderPriv *dp;
+    int ret;
+
+    *pdec = NULL;
+
+    ret = dec_alloc(&dp, sch, !!(o->flags & DECODER_FLAG_SEND_END_TS));
+    if (ret < 0)
+        return ret;
+
+    ret = dec_open(dp, dec_opts, o);
+    if (ret < 0)
+        goto fail;
+
     *pdec = &dp->dec;
 
     return dp->sch_idx;
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 29f4a26224..ae0f635d8c 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -935,7 +935,7 @@ static int ist_use(InputStream *ist, int decoding_needed)
 
         ds->dec_opts.log_parent = ist;
 
-        ret = dec_open(&ist->decoder, d->sch,
+        ret = dec_init(&ist->decoder, d->sch,
                        &ds->decoder_opts, &ds->dec_opts);
         if (ret < 0)
             return ret;
-- 
2.43.0

_______________________________________________
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".

  parent reply	other threads:[~2024-03-06 11:08 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-06 11:03 [FFmpeg-devel] [PATCH 01/18] fftools/cmdutils: fix printing group name in split_commandline() Anton Khirnov
2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 02/18] fftools/ffmpeg_filter: refactor setting input timebase Anton Khirnov
2024-03-07 20:37   ` Michael Niedermayer
2024-03-08  5:34     ` Anton Khirnov
2024-03-10  3:36       ` Michael Niedermayer
2024-03-10  6:13         ` Anton Khirnov
2024-03-10 19:21           ` Michael Niedermayer
2024-03-10 22:24             ` Anton Khirnov
2024-03-10 22:29               ` James Almer
2024-03-10 22:49                 ` Anton Khirnov
2024-03-10 23:37                   ` Michael Niedermayer
2024-03-11  6:03                     ` Anton Khirnov
2024-03-11 10:12                   ` Tobias Rapp
2024-03-11 12:23                     ` Anton Khirnov
2024-03-11 12:29                       ` Martin Storsjö
2024-03-11 13:28                         ` Anton Khirnov
2024-03-11 14:03                           ` Martin Storsjö via ffmpeg-devel
2024-03-11 14:32                             ` Anton Khirnov
2024-03-11 14:37                               ` Martin Storsjö
2024-03-11 14:31                           ` Tobias Rapp
2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 03/18] fftools/ffmpeg_filter: drop unused InputFilterPriv.ist Anton Khirnov
2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 04/18] fftools/ffmpeg_dec: move scheduler registration from dec_open() to dec_alloc() Anton Khirnov
2024-03-06 11:03 ` Anton Khirnov [this message]
2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 06/18] fftools/ffmpeg_opt: merge init_complex_filters() and check_filter_outputs() Anton Khirnov
2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 07/18] fftools/ffmpeg_filter: move filtergraph input type check to a better place Anton Khirnov
2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 08/18] fftools/ffmpeg_filter: add logging for binding inputs to demuxer streams Anton Khirnov
2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 09/18] fftools/ffmpeg: simplify propagating fallback parameters from decoders to filters Anton Khirnov
2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 10/18] fftools/ffmpeg: remove unncessary casts for *_thread() return values Anton Khirnov
2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 11/18] fftools/ffmpeg_enc: drop unnecessary parameter from forced_kf_apply() Anton Khirnov
2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 12/18] fftools/ffmpeg_enc: merge do_{audio, video}_out into frame_encode() Anton Khirnov
2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 13/18] fftools/ffmpeg_sched: allow encoders to send to multiple destinations Anton Khirnov
2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 14/18] fftools/ffmpeg_sched: factor initializing nodes into separate function Anton Khirnov
2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 15/18] fftools/ffmpeg_sched: allow connecting encoder output to decoders Anton Khirnov
2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 16/18] fftools/ffmpeg: prepare FrameData for having allocated fields Anton Khirnov
2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 17/18] fftools/ffmpeg: add loopback decoding Anton Khirnov
2024-03-07 14:42   ` [FFmpeg-devel] [PATCH v2 " Anton Khirnov
2024-03-06 11:03 ` [FFmpeg-devel] [PATCH 18/18] fftools/ffmpeg_enc: set AV_PKT_FLAG_TRUSTED on encoded packets Anton Khirnov
2024-03-09 19:08 ` [FFmpeg-devel] [PATCH 01/18] fftools/cmdutils: fix printing group name in split_commandline() Anton Khirnov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240306110319.17339-5-anton@khirnov.net \
    --to=anton@khirnov.net \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git