diff options
author | James Almer <jamrial@gmail.com> | 2019-05-12 23:29:36 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2019-05-20 16:20:04 -0300 |
commit | fbc5a27694c2b3f7511cb59b191d7ba634bfaf21 (patch) | |
tree | deb1ba25408818b29e03917c8c92c2c7e4e8869d | |
parent | b401a4ab8aa85c536bd9eee0da8f51551b66c70e (diff) | |
download | ffmpeg-fbc5a27694c2b3f7511cb59b191d7ba634bfaf21.tar.gz |
avcodec/libdav1d: fine tune thread distribution
As suggested by Ronald, don't map auto threads to frame threads only, and
instead distribute them between frame and tile more efficiently.
Add a new framethreads override option, similar to the tilethreads one.
Signed-off-by: James Almer <jamrial@gmail.com>
-rw-r--r-- | libavcodec/libdav1d.c | 16 | ||||
-rw-r--r-- | libavcodec/version.h | 2 |
2 files changed, 14 insertions, 4 deletions
diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c index 30c6eccfef..4fa3b0ae44 100644 --- a/libavcodec/libdav1d.c +++ b/libavcodec/libdav1d.c @@ -38,6 +38,7 @@ typedef struct Libdav1dContext { Dav1dData data; int tile_threads; + int frame_threads; int apply_grain; } Libdav1dContext; @@ -114,6 +115,7 @@ static av_cold int libdav1d_init(AVCodecContext *c) { Libdav1dContext *dav1d = c->priv_data; Dav1dSettings s; + int threads = (c->thread_count ? c->thread_count : av_cpu_count()) * 3 / 2; int res; av_log(c, AV_LOG_INFO, "libdav1d %s\n", dav1d_version()); @@ -124,9 +126,16 @@ static av_cold int libdav1d_init(AVCodecContext *c) s.allocator.cookie = dav1d; s.allocator.alloc_picture_callback = libdav1d_picture_allocator; s.allocator.release_picture_callback = libdav1d_picture_release; - s.n_tile_threads = dav1d->tile_threads; s.apply_grain = dav1d->apply_grain; - s.n_frame_threads = FFMIN(c->thread_count ? c->thread_count : av_cpu_count(), DAV1D_MAX_FRAME_THREADS); + + s.n_tile_threads = dav1d->tile_threads + ? dav1d->tile_threads + : FFMIN(floor(sqrt(threads)), DAV1D_MAX_TILE_THREADS); + s.n_frame_threads = dav1d->frame_threads + ? dav1d->frame_threads + : FFMIN(ceil(threads / s.n_tile_threads), DAV1D_MAX_FRAME_THREADS); + av_log(c, AV_LOG_DEBUG, "Using %d frame threads, %d tile threads\n", + s.n_frame_threads, s.n_tile_threads); res = dav1d_open(&dav1d->c, &s); if (res < 0) @@ -317,7 +326,8 @@ 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 static const AVOption libdav1d_options[] = { - { "tilethreads", "Tile threads", OFFSET(tile_threads), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, DAV1D_MAX_TILE_THREADS, VD }, + { "tilethreads", "Tile threads", OFFSET(tile_threads), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, DAV1D_MAX_TILE_THREADS, VD }, + { "framethreads", "Frame threads", OFFSET(frame_threads), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, DAV1D_MAX_FRAME_THREADS, VD }, { "filmgrain", "Apply Film Grain", OFFSET(apply_grain), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, VD }, { NULL } }; diff --git a/libavcodec/version.h b/libavcodec/version.h index d11beb7885..7ed60717f0 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,7 +29,7 @@ #define LIBAVCODEC_VERSION_MAJOR 58 #define LIBAVCODEC_VERSION_MINOR 52 -#define LIBAVCODEC_VERSION_MICRO 101 +#define LIBAVCODEC_VERSION_MICRO 102 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ |