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
path: root/src/lib.c
diff options
context:
space:
mode:
authorHenrik Gramner <gramner@twoorioles.com>2020-11-20 03:37:54 +0300
committerHenrik Gramner <henrik@gramner.com>2020-11-22 16:51:03 +0300
commit236e1122da50c23d95766682590d546f787684ea (patch)
treebaf702b6c70baefc15a07ebb051c9deeaf843f17 /src/lib.c
parentdc98fff8757e018a4a74217aade64a10b7afd46d (diff)
Add more buffer pools
Add buffer pools for miscellaneous smaller buffers that are repeatedly being freed and reallocated. Also improve dav1d_ref_create() by consolidating two separate memory allocations into a single one.
Diffstat (limited to 'src/lib.c')
-rw-r--r--src/lib.c49
1 files changed, 38 insertions, 11 deletions
diff --git a/src/lib.c b/src/lib.c
index 5e2ab2f..76f805a 100644
--- a/src/lib.c
+++ b/src/lib.c
@@ -38,7 +38,6 @@
#include "dav1d/dav1d.h"
#include "dav1d/data.h"
-#include "common/mem.h"
#include "common/validate.h"
#include "src/cpu.h"
@@ -77,6 +76,35 @@ COLD void dav1d_default_settings(Dav1dSettings *const s) {
s->frame_size_limit = 0;
}
+static COLD int init_mem_pools(Dav1dContext *const c) {
+ if (!pthread_mutex_init(&c->seq_hdr_pool.lock, NULL)) {
+ if (!pthread_mutex_init(&c->frame_hdr_pool.lock, NULL)) {
+ if (!pthread_mutex_init(&c->segmap_pool.lock, NULL)) {
+ if (!pthread_mutex_init(&c->refmvs_pool.lock, NULL)) {
+ if (!pthread_mutex_init(&c->cdf_pool.lock, NULL)) {
+ if (c->allocator.alloc_picture_callback == dav1d_default_picture_alloc) {
+ if (!pthread_mutex_init(&c->picture_pool.lock, NULL)) {
+ c->allocator.cookie = &c->picture_pool;
+ c->mem_pools_inited = 2;
+ return 0;
+ }
+ } else {
+ c->mem_pools_inited = 1;
+ return 0;
+ }
+ pthread_mutex_destroy(&c->cdf_pool.lock);
+ }
+ pthread_mutex_destroy(&c->refmvs_pool.lock);
+ }
+ pthread_mutex_destroy(&c->segmap_pool.lock);
+ }
+ pthread_mutex_destroy(&c->frame_hdr_pool.lock);
+ }
+ pthread_mutex_destroy(&c->seq_hdr_pool.lock);
+ }
+ return -1;
+}
+
static void close_internal(Dav1dContext **const c_out, int flush);
NO_SANITIZE("cfi-icall") // CFI is broken with dlsym()
@@ -129,10 +157,7 @@ COLD int dav1d_open(Dav1dContext **const c_out, const Dav1dSettings *const s) {
c->all_layers = s->all_layers;
c->frame_size_limit = s->frame_size_limit;
- if (c->allocator.alloc_picture_callback == dav1d_default_picture_alloc) {
- if (pthread_mutex_init(&c->picture_buffer_pool.lock, NULL)) goto error;
- c->allocator.cookie = c;
- }
+ if (init_mem_pools(c)) goto error;
/* On 32-bit systems extremely large frame sizes can cause overflows in
* dav1d_decode_frame() malloc size calculations. Prevent that from occuring
@@ -577,12 +602,14 @@ static COLD void close_internal(Dav1dContext **const c_out, int flush) {
dav1d_ref_dec(&c->content_light_ref);
dav1d_ref_dec(&c->itut_t35_ref);
- pthread_mutex_destroy(&c->picture_buffer_pool.lock);
- Dav1dPictureBuffer *buf = c->picture_buffer_pool.buf;
- while (buf) {
- Dav1dPictureBuffer *const next = buf->next;
- dav1d_free_aligned(buf->data);
- buf = next;
+ if (c->mem_pools_inited) {
+ dav1d_mem_pool_destroy(&c->seq_hdr_pool);
+ dav1d_mem_pool_destroy(&c->frame_hdr_pool);
+ dav1d_mem_pool_destroy(&c->segmap_pool);
+ dav1d_mem_pool_destroy(&c->refmvs_pool);
+ dav1d_mem_pool_destroy(&c->cdf_pool);
+ if (c->mem_pools_inited == 2)
+ dav1d_mem_pool_destroy(&c->picture_pool);
}
dav1d_freep_aligned(c_out);