diff options
Diffstat (limited to 'video/hwdec.c')
-rw-r--r-- | video/hwdec.c | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/video/hwdec.c b/video/hwdec.c index df0cf88839..31df1522ce 100644 --- a/video/hwdec.c +++ b/video/hwdec.c @@ -8,9 +8,10 @@ struct mp_hwdec_devices { pthread_mutex_t lock; - struct mp_hwdec_ctx *hwctx; + struct mp_hwdec_ctx **hwctxs; + int num_hwctxs; - void (*load_api)(void *ctx, enum hwdec_type type); + void (*load_api)(void *ctx); void *load_api_ctx; }; @@ -25,7 +26,7 @@ void hwdec_devices_destroy(struct mp_hwdec_devices *devs) { if (!devs) return; - assert(!devs->hwctx); // must have been hwdec_devices_remove()ed + assert(!devs->num_hwctxs); // must have been hwdec_devices_remove()ed assert(!devs->load_api); // must have been unset pthread_mutex_destroy(&devs->lock); talloc_free(devs); @@ -36,8 +37,12 @@ struct mp_hwdec_ctx *hwdec_devices_get(struct mp_hwdec_devices *devs, { struct mp_hwdec_ctx *res = NULL; pthread_mutex_lock(&devs->lock); - if (devs->hwctx && devs->hwctx->type == type) - res = devs->hwctx; + for (int n = 0; n < devs->num_hwctxs; n++) { + if (devs->hwctxs[n]->type == type) { + res = devs->hwctxs[n]; + break; + } + } pthread_mutex_unlock(&devs->lock); return res; } @@ -45,7 +50,7 @@ struct mp_hwdec_ctx *hwdec_devices_get(struct mp_hwdec_devices *devs, struct mp_hwdec_ctx *hwdec_devices_get_first(struct mp_hwdec_devices *devs) { pthread_mutex_lock(&devs->lock); - struct mp_hwdec_ctx *res = devs->hwctx; + struct mp_hwdec_ctx *res = devs->num_hwctxs ? devs->hwctxs[0] : NULL; pthread_mutex_unlock(&devs->lock); return res; } @@ -53,42 +58,55 @@ struct mp_hwdec_ctx *hwdec_devices_get_first(struct mp_hwdec_devices *devs) void hwdec_devices_add(struct mp_hwdec_devices *devs, struct mp_hwdec_ctx *ctx) { pthread_mutex_lock(&devs->lock); - // We support only 1 device; ignore the rest. - if (!devs->hwctx) - devs->hwctx = ctx; + MP_TARRAY_APPEND(devs, devs->hwctxs, devs->num_hwctxs, ctx); pthread_mutex_unlock(&devs->lock); } void hwdec_devices_remove(struct mp_hwdec_devices *devs, struct mp_hwdec_ctx *ctx) { pthread_mutex_lock(&devs->lock); - if (devs->hwctx == ctx) - devs->hwctx = NULL; + for (int n = 0; n < devs->num_hwctxs; n++) { + if (devs->hwctxs[n] == ctx) { + MP_TARRAY_REMOVE_AT(devs->hwctxs, devs->num_hwctxs, n); + break; + } + } pthread_mutex_unlock(&devs->lock); } void hwdec_devices_set_loader(struct mp_hwdec_devices *devs, - void (*load_api)(void *ctx, enum hwdec_type type), void *load_api_ctx) + void (*load_api)(void *ctx), void *load_api_ctx) { devs->load_api = load_api; devs->load_api_ctx = load_api_ctx; } -void hwdec_devices_request(struct mp_hwdec_devices *devs, enum hwdec_type type) +void hwdec_devices_request_all(struct mp_hwdec_devices *devs) { if (devs->load_api && !hwdec_devices_get_first(devs)) - devs->load_api(devs->load_api_ctx, type); + devs->load_api(devs->load_api_ctx); } void *hwdec_devices_load(struct mp_hwdec_devices *devs, enum hwdec_type type) { if (!devs) return NULL; - hwdec_devices_request(devs, type); + hwdec_devices_request_all(devs); struct mp_hwdec_ctx *hwctx = hwdec_devices_get(devs, type); return hwctx ? hwctx->ctx : NULL; } +char *hwdec_devices_get_names(struct mp_hwdec_devices *devs) +{ + char *res = NULL; + for (int n = 0; n < devs->num_hwctxs; n++) { + if (res) + ta_xstrdup_append(&res, ","); + ta_xstrdup_append(&res, devs->hwctxs[n]->driver_name); + } + return res; +} + #if HAVE_D3D_HWACCEL extern const struct hwcontext_fns hwcontext_fns_d3d11; #endif |