diff mbox series

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

Message ID 20230511160445.2214-1-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel] avcodec/libdav1d: export decoder frame delay | 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

James Almer May 11, 2023, 4:04 p.m. UTC
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@gmail.com>
---
 doc/decoders.texi     |  3 ++-
 libavcodec/libdav1d.c | 16 +++++++++++++++-
 libavcodec/version.h  |  2 +-
 3 files changed, 18 insertions(+), 3 deletions(-)

Comments

Derek Buitenhuis May 11, 2023, 7:22 p.m. UTC | #1
On 5/11/2023 5:04 PM, James Almer wrote:
> 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@gmail.com>
> ---

I can confirm this works as expected.

- Derek
Ronald S. Bultje May 12, 2023, 11:36 a.m. UTC | #2
Hi,


On Thu, May 11, 2023 at 12:04 PM James Almer <jamrial@gmail.com> wrote:

> 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@gmail.com>
> ---
>  doc/decoders.texi     |  3 ++-
>  libavcodec/libdav1d.c | 16 +++++++++++++++-
>  libavcodec/version.h  |  2 +-
>  3 files changed, 18 insertions(+), 3 deletions(-)
>

LGTM.

Ronald
diff mbox series

Patch

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, \