diff mbox series

[FFmpeg-devel,04/18] fftools/ffmpeg_dec: move scheduler registration from dec_open() to dec_alloc()

Message ID 20240306110319.17339-4-anton@khirnov.net
State Accepted
Commit 48c39a9c71f8ede1b503176375a7ca6a930d3dd5
Headers show
Series [FFmpeg-devel,01/18] fftools/cmdutils: fix printing group name in split_commandline() | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov March 6, 2024, 11:03 a.m. UTC
Will be useful in following commits where we will want to create a
decoder before having enough information to open it.
---
 fftools/ffmpeg_dec.c | 51 +++++++++++++++++++++++---------------------
 1 file changed, 27 insertions(+), 24 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index 8c92b27cc1..98c4a0c83c 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -110,9 +110,26 @@  void dec_free(Decoder **pdec)
     av_freep(pdec);
 }
 
-static int dec_alloc(DecoderPriv **pdec)
+static const char *dec_item_name(void *obj)
+{
+    const DecoderPriv *dp = obj;
+
+    return dp->log_name;
+}
+
+static const AVClass dec_class = {
+    .class_name                = "Decoder",
+    .version                   = LIBAVUTIL_VERSION_INT,
+    .parent_log_context_offset = offsetof(DecoderPriv, log_parent),
+    .item_name                 = dec_item_name,
+};
+
+static void *decoder_thread(void *arg);
+
+static int dec_alloc(DecoderPriv **pdec, Scheduler *sch, int send_end_ts)
 {
     DecoderPriv *dp;
+    int ret = 0;
 
     *pdec = NULL;
 
@@ -128,17 +145,24 @@  static int dec_alloc(DecoderPriv **pdec)
     if (!dp->pkt)
         goto fail;
 
+    dp->dec.class                    = &dec_class;
     dp->last_filter_in_rescale_delta = AV_NOPTS_VALUE;
     dp->last_frame_pts               = AV_NOPTS_VALUE;
     dp->last_frame_tb                = (AVRational){ 1, 1 };
     dp->hwaccel_pix_fmt              = AV_PIX_FMT_NONE;
 
+    ret = sch_add_dec(sch, decoder_thread, dp, send_end_ts);
+    if (ret < 0)
+        goto fail;
+    dp->sch     = sch;
+    dp->sch_idx = ret;
+
     *pdec = dp;
 
     return 0;
 fail:
     dec_free((Decoder**)&dp);
-    return AVERROR(ENOMEM);
+    return ret >= 0 ? AVERROR(ENOMEM) : ret;
 }
 
 static AVRational audio_samplerate_update(DecoderPriv *dp,
@@ -1042,20 +1066,6 @@  static int hw_device_setup_for_decode(DecoderPriv *dp,
     return 0;
 }
 
-static const char *dec_item_name(void *obj)
-{
-    const DecoderPriv *dp = obj;
-
-    return dp->log_name;
-}
-
-static const AVClass dec_class = {
-    .class_name                = "Decoder",
-    .version                   = LIBAVUTIL_VERSION_INT,
-    .parent_log_context_offset = offsetof(DecoderPriv, log_parent),
-    .item_name                 = dec_item_name,
-};
-
 int dec_open(Decoder **pdec, Scheduler *sch,
              AVDictionary **dec_opts, const DecoderOpts *o)
 {
@@ -1065,18 +1075,11 @@  int dec_open(Decoder **pdec, Scheduler *sch,
 
     *pdec = NULL;
 
-    ret = dec_alloc(&dp);
+    ret = dec_alloc(&dp, sch, !!(o->flags & DECODER_FLAG_SEND_END_TS));
     if (ret < 0)
         return ret;
 
-    ret = sch_add_dec(sch, decoder_thread, dp, o->flags & DECODER_FLAG_SEND_END_TS);
-    if (ret < 0)
-        return ret;
-    dp->sch     = sch;
-    dp->sch_idx = ret;
-
     dp->flags      = o->flags;
-    dp->dec.class  = &dec_class;
     dp->log_parent = o->log_parent;
 
     dp->framerate_in            = o->framerate;