summaryrefslogtreecommitdiffstats
path: root/libavcodec/libdav1d.c
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2019-05-12 23:29:36 -0300
committerJames Almer <jamrial@gmail.com>2019-05-20 16:20:04 -0300
commitfbc5a27694c2b3f7511cb59b191d7ba634bfaf21 (patch)
treedeb1ba25408818b29e03917c8c92c2c7e4e8869d /libavcodec/libdav1d.c
parentb401a4ab8aa85c536bd9eee0da8f51551b66c70e (diff)
downloadffmpeg-streaming-fbc5a27694c2b3f7511cb59b191d7ba634bfaf21.zip
ffmpeg-streaming-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>
Diffstat (limited to 'libavcodec/libdav1d.c')
-rw-r--r--libavcodec/libdav1d.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
index 30c6ecc..4fa3b0a 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 }
};
OpenPOWER on IntegriCloud