[FFmpeg-devel] [PATCH] avcodec/libdav1d: export decoder frame delay

James Almer jamrial at gmail.com
Thu May 11 19:04:45 EEST 2023


As this is a AV_CODEC_CAP_OTHER_THREADS decoder, threading is handled by the
underlying library. In this case, the frame delay is calculated by libdav1d
based on the values from avctx->thread_count and the private max_frame_delay
option.
Make said max_frame_delay option an exported one, and store the final delay
used by libdav1d here, for the caller to query if needed.

Signed-off-by: James Almer <jamrial at gmail.com>
---
 doc/decoders.texi     |  3 ++-
 libavcodec/libdav1d.c | 16 +++++++++++++++-
 libavcodec/version.h  |  2 +-
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/doc/decoders.texi b/doc/decoders.texi
index 09b8314dd2..0130b35603 100644
--- a/doc/decoders.texi
+++ b/doc/decoders.texi
@@ -86,7 +86,8 @@ global option @code{threads} instead.
 
 @item max_frame_delay
 Set max amount of frames the decoder may buffer internally. The default value is 0
-(autodetect).
+(autodetect). The decoder will afterwards export the final calculated frame delay here
+when using libdav1d >= 1.1.0.
 
 @item filmgrain
 Apply film grain to the decoded video if present in the bitstream. Defaults to the
diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
index af072da681..de06a2c09e 100644
--- a/libavcodec/libdav1d.c
+++ b/libavcodec/libdav1d.c
@@ -278,6 +278,14 @@ static av_cold int libdav1d_init(AVCodecContext *c)
     if (res < 0)
         return AVERROR(ENOMEM);
 
+#if FF_DAV1D_VERSION_AT_LEAST(6,7)
+    res = dav1d_get_frame_delay(&s);
+    if (res < 0) // Should not happen
+        return AVERROR_EXTERNAL;
+
+    dav1d->max_frame_delay = res;
+#endif
+
     return 0;
 }
 
@@ -648,10 +656,16 @@ static av_cold int libdav1d_close(AVCodecContext *c)
 
 #define OFFSET(x) offsetof(Libdav1dContext, x)
 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
+#if FF_DAV1D_VERSION_AT_LEAST(6,7)
+#define X AV_OPT_FLAG_EXPORT
+#else
+#define X 0
+#endif
+
 static const AVOption libdav1d_options[] = {
     { "tilethreads", "Tile threads", OFFSET(tile_threads), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, DAV1D_MAX_TILE_THREADS, VD | AV_OPT_FLAG_DEPRECATED },
     { "framethreads", "Frame threads", OFFSET(frame_threads), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, DAV1D_MAX_FRAME_THREADS, VD | AV_OPT_FLAG_DEPRECATED },
-    { "max_frame_delay", "Max frame delay", OFFSET(max_frame_delay), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, DAV1D_MAX_FRAME_DELAY, VD },
+    { "max_frame_delay", "Max frame delay", OFFSET(max_frame_delay), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, DAV1D_MAX_FRAME_DELAY, VD|X },
     { "filmgrain", "Apply Film Grain", OFFSET(apply_grain), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VD | AV_OPT_FLAG_DEPRECATED },
     { "oppoint",  "Select an operating point of the scalable bitstream", OFFSET(operating_point), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 31, VD },
     { "alllayers", "Output all spatial layers", OFFSET(all_layers), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 8b53586be1..6d4d7ca018 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -30,7 +30,7 @@
 #include "version_major.h"
 
 #define LIBAVCODEC_VERSION_MINOR  11
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \
-- 
2.40.1



More information about the ffmpeg-devel mailing list