Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/videolan/dav1d.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2022-03-31 15:31:32 +0300
committerJames Almer <jamrial@gmail.com>2022-03-31 15:31:32 +0300
commitac07a6653a5a0c0fee65dc4c229b8188bb726acb (patch)
treedb9534a1e86a3d13a48327b3bcfb099541a251c1
parent87f9a81cd770e49394a45deca7a3df41243de00b (diff)
lib: split calculating thread count to its own function
-rw-r--r--src/lib.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/lib.c b/src/lib.c
index b21a735..210b4f3 100644
--- a/src/lib.c
+++ b/src/lib.c
@@ -97,6 +97,25 @@ static COLD size_t get_stack_size_internal(const pthread_attr_t *const thread_at
return 0;
}
+static COLD void get_num_threads(Dav1dContext *const c, const Dav1dSettings *const s,
+ unsigned *n_tc, unsigned *n_fc)
+{
+ /* ceil(sqrt(n)) */
+ static const uint8_t fc_lut[49] = {
+ 1, /* 1 */
+ 2, 2, 2, /* 2- 4 */
+ 3, 3, 3, 3, 3, /* 5- 9 */
+ 4, 4, 4, 4, 4, 4, 4, /* 10-16 */
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, /* 17-25 */
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, /* 26-36 */
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, /* 37-49 */
+ };
+ *n_tc = s->n_threads ? s->n_threads :
+ iclip(dav1d_num_logical_processors(c), 1, DAV1D_MAX_THREADS);
+ *n_fc = s->max_frame_delay ? umin(s->max_frame_delay, *n_tc) :
+ *n_tc < 50 ? fc_lut[*n_tc - 1] : 8; // min(8, ceil(sqrt(n)))
+}
+
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);
@@ -171,20 +190,7 @@ COLD int dav1d_open(Dav1dContext **const c_out, const Dav1dSettings *const s) {
c->flush = &c->flush_mem;
atomic_init(c->flush, 0);
- c->n_tc = s->n_threads ? s->n_threads :
- iclip(dav1d_num_logical_processors(c), 1, DAV1D_MAX_THREADS);
- /* ceil(sqrt(n)) */
- static const uint8_t fc_lut[49] = {
- 1, /* 1 */
- 2, 2, 2, /* 2- 4 */
- 3, 3, 3, 3, 3, /* 5- 9 */
- 4, 4, 4, 4, 4, 4, 4, /* 10-16 */
- 5, 5, 5, 5, 5, 5, 5, 5, 5, /* 17-25 */
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, /* 26-36 */
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, /* 37-49 */
- };
- c->n_fc = s->max_frame_delay ? umin(s->max_frame_delay, c->n_tc) :
- c->n_tc < 50 ? fc_lut[c->n_tc - 1] : 8; // min(8, ceil(sqrt(n)))
+ get_num_threads(c, s, &c->n_tc, &c->n_fc);
c->fc = dav1d_alloc_aligned(sizeof(*c->fc) * c->n_fc, 32);
if (!c->fc) goto error;