From 6777dd0a61ab78cc9fab92af53558ea44c135056 Mon Sep 17 00:00:00 2001 From: James Almer Date: Thu, 31 Mar 2022 09:42:56 -0300 Subject: lib: add a function to query the decoder frame delay --- include/dav1d/dav1d.h | 15 +++++++++++++++ meson.build | 2 +- src/cpu.c | 3 ++- src/lib.c | 12 ++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/include/dav1d/dav1d.h b/include/dav1d/dav1d.h index fd3b622..bd70303 100644 --- a/include/dav1d/dav1d.h +++ b/include/dav1d/dav1d.h @@ -287,6 +287,21 @@ DAV1D_API int dav1d_get_event_flags(Dav1dContext *c, enum Dav1dEventFlags *flags */ DAV1D_API int dav1d_get_decode_error_data_props(Dav1dContext *c, Dav1dDataProps *out); +/** + * Get the decoder delay, which is the number of internally buffered frames, not + * including reference frames. + * This value is guaranteed to be >= 1 and <= max_frame_delay. + * + * @param c Input settings context. + * + * @return Decoder frame delay on success, or < 0 (a negative DAV1D_ERR code) on + * error. + * + * @note The returned delay is valid only for a Dav1dContext initialized with the + * provided Dav1dSettings. + */ +DAV1D_API int dav1d_get_frame_delay(const Dav1dSettings *s); + # ifdef __cplusplus } # endif diff --git a/meson.build b/meson.build index a312ae0..372a55d 100644 --- a/meson.build +++ b/meson.build @@ -30,7 +30,7 @@ project('dav1d', ['c'], 'b_ndebug=if-release'], meson_version: '>= 0.49.0') -dav1d_soname_version = '6.6.0' +dav1d_soname_version = '6.7.0' dav1d_api_version_array = dav1d_soname_version.split('.') dav1d_api_version_major = dav1d_api_version_array[0] dav1d_api_version_minor = dav1d_api_version_array[1] diff --git a/src/cpu.c b/src/cpu.c index 2e5e8d9..3d129c8 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -99,6 +99,7 @@ COLD int dav1d_num_logical_processors(Dav1dContext *const c) { #elif defined(_SC_NPROCESSORS_ONLN) return (int)sysconf(_SC_NPROCESSORS_ONLN); #endif - dav1d_log(c, "Unable to detect thread count, defaulting to single-threaded mode\n"); + if (c) + dav1d_log(c, "Unable to detect thread count, defaulting to single-threaded mode\n"); return 1; } diff --git a/src/lib.c b/src/lib.c index 210b4f3..528198e 100644 --- a/src/lib.c +++ b/src/lib.c @@ -116,6 +116,18 @@ static COLD void get_num_threads(Dav1dContext *const c, const Dav1dSettings *con *n_tc < 50 ? fc_lut[*n_tc - 1] : 8; // min(8, ceil(sqrt(n))) } +COLD int dav1d_get_frame_delay(const Dav1dSettings *const s) { + unsigned n_tc, n_fc; + validate_input_or_ret(s != NULL, DAV1D_ERR(EINVAL)); + validate_input_or_ret(s->n_threads >= 0 && + s->n_threads <= DAV1D_MAX_THREADS, DAV1D_ERR(EINVAL)); + validate_input_or_ret(s->max_frame_delay >= 0 && + s->max_frame_delay <= DAV1D_MAX_FRAME_DELAY, DAV1D_ERR(EINVAL)); + + get_num_threads(NULL, s, &n_tc, &n_fc); + return n_fc; +} + COLD int dav1d_open(Dav1dContext **const c_out, const Dav1dSettings *const s) { static pthread_once_t initted = PTHREAD_ONCE_INIT; pthread_once(&initted, init_internal); -- cgit v1.2.3