0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00

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.
This commit is contained in:
wm4 2018-01-12 01:40:01 +01:00 committed by Kevin Mitchell
parent d53c0604ca
commit 83ab873497
6 changed files with 16 additions and 14 deletions

View File

@ -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);

View File

@ -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 =

View File

@ -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);

View File

@ -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 {

View File

@ -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

View File

@ -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);