diff mbox series

[FFmpeg-devel,04/12] fftools/ffmpeg_dec: apply decoder options manually

Message ID 20240322202841.31730-4-anton@khirnov.net
State Accepted
Commit 372c78dd42f2b1ca743473b9c32fad71c65919e0
Headers show
Series [FFmpeg-devel,01/12] tests/fate/ffmpeg: evaluate thread count in fate-run.sh rather than make | 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 22, 2024, 8:28 p.m. UTC
Do not pass an options dictionary to avcodec_open2().

This should be equivalent to current behaviour, but will allow
overriding caller-supplied options in a cleaner and more robust manner.

We can now set the COPY_OPAQUE flag directly rather going through
dec_opts.
---
 fftools/ffmpeg_dec.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index ed411b6bf8..ad02a64b60 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -21,6 +21,7 @@ 
 #include "libavutil/dict.h"
 #include "libavutil/error.h"
 #include "libavutil/log.h"
+#include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/pixfmt.h"
 #include "libavutil/time.h"
@@ -1191,8 +1192,6 @@  static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts,
     if (!av_dict_get(*dec_opts, "threads", NULL, 0))
         av_dict_set(dec_opts, "threads", "auto", 0);
 
-    av_dict_set(dec_opts, "flags", "+copy_opaque", AV_DICT_MULTIKEY);
-
     ret = hw_device_setup_for_decode(dp, codec, o->hwaccel_device);
     if (ret < 0) {
         av_log(dp, AV_LOG_ERROR,
@@ -1201,7 +1200,19 @@  static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts,
         return ret;
     }
 
-    if ((ret = avcodec_open2(dp->dec_ctx, codec, dec_opts)) < 0) {
+    ret = av_opt_set_dict2(dp->dec_ctx, dec_opts, AV_OPT_SEARCH_CHILDREN);
+    if (ret < 0) {
+        av_log(dp, AV_LOG_ERROR, "Error applying decoder options: %s\n",
+               av_err2str(ret));
+        return ret;
+    }
+    ret = check_avoptions(*dec_opts);
+    if (ret < 0)
+        return ret;
+
+    dp->dec_ctx->flags |= AV_CODEC_FLAG_COPY_OPAQUE;
+
+    if ((ret = avcodec_open2(dp->dec_ctx, codec, NULL)) < 0) {
         av_log(dp, AV_LOG_ERROR, "Error while opening decoder: %s\n",
                av_err2str(ret));
         return ret;
@@ -1220,10 +1231,6 @@  static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts,
             dp->dec_ctx->extra_hw_frames = extra_frames;
     }
 
-    ret = check_avoptions(*dec_opts);
-    if (ret < 0)
-        return ret;
-
     dp->dec.subtitle_header      = dp->dec_ctx->subtitle_header;
     dp->dec.subtitle_header_size = dp->dec_ctx->subtitle_header_size;