aboutsummaryrefslogtreecommitdiffhomepage
path: root/video
diff options
context:
space:
mode:
authorGravatar wm4 <wm4@nowhere>2018-01-12 01:40:01 +0100
committerGravatar Kevin Mitchell <kevmitch@gmail.com>2018-01-13 03:26:45 -0800
commit83ab873497e8b295d32ee364ef64c4533db5a048 (patch)
tree1185a249ac7c49d8b5859830c98b25abae6a63ae /video
parentd53c0604ca796020e5ac26f08c0d6fd0c8201718 (diff)
video: change some mp_image_pool semantics
Remove the max_count creation parameter, because it's pointless and rarely ever did anything. Add a talloc parent parameter instead (which is something completely different, but convenient, and all callers needs to be changed anyway). Instead of clearing the pool when the now removed maximum is reached, clear it on image parameter changes instead.
Diffstat (limited to 'video')
-rw-r--r--video/decode/vd_lavc.c4
-rw-r--r--video/filter/vf.c2
-rw-r--r--video/filter/vf_d3d11vpp.c2
-rw-r--r--video/mp_image_pool.c18
-rw-r--r--video/mp_image_pool.h2
-rw-r--r--video/out/vo_vaapi.c2
6 files changed, 16 insertions, 14 deletions
diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c
index 79adc311a9..eab1427bb7 100644
--- a/video/decode/vd_lavc.c
+++ b/video/decode/vd_lavc.c
@@ -546,8 +546,8 @@ static int init(struct dec_video *vd, const char *decoder)
ctx->opts = vd->opts;
ctx->decoder = talloc_strdup(ctx, decoder);
ctx->hwdec_devs = vd->hwdec_devs;
- ctx->hwdec_swpool = talloc_steal(ctx, mp_image_pool_new(17));
- ctx->dr_pool = talloc_steal(ctx, mp_image_pool_new(INT_MAX));
+ ctx->hwdec_swpool = mp_image_pool_new(ctx);
+ ctx->dr_pool = mp_image_pool_new(ctx);
pthread_mutex_init(&ctx->dr_lock, NULL);
diff --git a/video/filter/vf.c b/video/filter/vf.c
index 48a6e9a3a6..d5df466ba8 100644
--- a/video/filter/vf.c
+++ b/video/filter/vf.c
@@ -233,7 +233,7 @@ static struct vf_instance *vf_open(struct vf_chain *c, const char *name,
.log = mp_log_new(vf, c->log, name),
.hwdec_devs = c->hwdec_devs,
.query_format = vf_default_query_format,
- .out_pool = talloc_steal(vf, mp_image_pool_new(16)),
+ .out_pool = mp_image_pool_new(vf),
.chain = c,
};
struct m_config *config =
diff --git a/video/filter/vf_d3d11vpp.c b/video/filter/vf_d3d11vpp.c
index f49af06424..3be49ede80 100644
--- a/video/filter/vf_d3d11vpp.c
+++ b/video/filter/vf_d3d11vpp.c
@@ -412,7 +412,7 @@ static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
p->params = *in;
p->out_params = *out;
- p->pool = mp_image_pool_new(20);
+ p->pool = mp_image_pool_new(vf);
mp_image_pool_set_allocator(p->pool, alloc_pool, vf);
mp_image_pool_set_lru(p->pool);
diff --git a/video/mp_image_pool.c b/video/mp_image_pool.c
index 809b4f3352..c526772981 100644
--- a/video/mp_image_pool.c
+++ b/video/mp_image_pool.c
@@ -43,11 +43,11 @@ static pthread_mutex_t pool_mutex = PTHREAD_MUTEX_INITIALIZER;
// destructors are thread-safe.)
struct mp_image_pool {
- int max_count;
-
struct mp_image **images;
int num_images;
+ int fmt, w, h;
+
mp_image_allocator allocator;
void *allocator_ctx;
@@ -70,13 +70,12 @@ static void image_pool_destructor(void *ptr)
mp_image_pool_clear(pool);
}
-struct mp_image_pool *mp_image_pool_new(int max_count)
+// If tparent!=NULL, set it as talloc parent for the pool.
+struct mp_image_pool *mp_image_pool_new(void *tparent)
{
- struct mp_image_pool *pool = talloc_ptrtype(NULL, pool);
+ struct mp_image_pool *pool = talloc_ptrtype(tparent, pool);
talloc_set_destructor(pool, image_pool_destructor);
- *pool = (struct mp_image_pool) {
- .max_count = max_count,
- };
+ *pool = (struct mp_image_pool) {0};
return pool;
}
@@ -188,8 +187,11 @@ struct mp_image *mp_image_pool_get(struct mp_image_pool *pool, int fmt,
return mp_image_alloc(fmt, w, h);
struct mp_image *new = mp_image_pool_get_no_alloc(pool, fmt, w, h);
if (!new) {
- if (pool->num_images >= pool->max_count)
+ if (fmt != pool->fmt || w != pool->w || h != pool->h)
mp_image_pool_clear(pool);
+ pool->fmt = fmt;
+ pool->w = w;
+ pool->h = h;
if (pool->allocator) {
new = pool->allocator(pool->allocator_ctx, fmt, w, h);
} else {
diff --git a/video/mp_image_pool.h b/video/mp_image_pool.h
index 5f570bc6f6..a49771ffbb 100644
--- a/video/mp_image_pool.h
+++ b/video/mp_image_pool.h
@@ -5,7 +5,7 @@
struct mp_image_pool;
-struct mp_image_pool *mp_image_pool_new(int max_count);
+struct mp_image_pool *mp_image_pool_new(void *tparent);
struct mp_image *mp_image_pool_get(struct mp_image_pool *pool, int fmt,
int w, int h);
// the reference to "new" is transferred to the pool
diff --git a/video/out/vo_vaapi.c b/video/out/vo_vaapi.c
index a3f701519d..c8ffffcb1e 100644
--- a/video/out/vo_vaapi.c
+++ b/video/out/vo_vaapi.c
@@ -816,7 +816,7 @@ static int preinit(struct vo *vo)
if (!p->image_formats)
goto fail;
- p->pool = mp_image_pool_new(MAX_OUTPUT_SURFACES + 3);
+ p->pool = mp_image_pool_new(p);
va_pool_set_allocator(p->pool, p->mpvaapi, VA_RT_FORMAT_YUV420);
int max_subpic_formats = vaMaxNumSubpictureFormats(p->display);