summaryrefslogtreecommitdiffstats
path: root/video/hwdec.c
diff options
context:
space:
mode:
Diffstat (limited to 'video/hwdec.c')
-rw-r--r--video/hwdec.c63
1 files changed, 28 insertions, 35 deletions
diff --git a/video/hwdec.c b/video/hwdec.c
index 97b984db18..f397f3bafb 100644
--- a/video/hwdec.c
+++ b/video/hwdec.c
@@ -1,26 +1,26 @@
-#include <pthread.h>
#include <assert.h>
#include <libavutil/hwcontext.h>
#include "config.h"
-
#include "hwdec.h"
+#include "osdep/threads.h"
struct mp_hwdec_devices {
- pthread_mutex_t lock;
+ mp_mutex lock;
struct mp_hwdec_ctx **hwctxs;
int num_hwctxs;
- void (*load_api)(void *ctx);
+ void (*load_api)(void *ctx,
+ struct hwdec_imgfmt_request *params);
void *load_api_ctx;
};
struct mp_hwdec_devices *hwdec_devices_create(void)
{
struct mp_hwdec_devices *devs = talloc_zero(NULL, struct mp_hwdec_devices);
- pthread_mutex_init(&devs->lock, NULL);
+ mp_mutex_init(&devs->lock);
return devs;
}
@@ -30,38 +30,26 @@ void hwdec_devices_destroy(struct mp_hwdec_devices *devs)
return;
assert(!devs->num_hwctxs); // must have been hwdec_devices_remove()ed
assert(!devs->load_api); // must have been unset
- pthread_mutex_destroy(&devs->lock);
+ mp_mutex_destroy(&devs->lock);
talloc_free(devs);
}
-struct mp_hwdec_ctx *hwdec_devices_get_by_lavc(struct mp_hwdec_devices *devs,
- int av_hwdevice_type)
+struct mp_hwdec_ctx *hwdec_devices_get_by_imgfmt(struct mp_hwdec_devices *devs,
+ int hw_imgfmt)
{
struct mp_hwdec_ctx *res = NULL;
- pthread_mutex_lock(&devs->lock);
+ mp_mutex_lock(&devs->lock);
for (int n = 0; n < devs->num_hwctxs; n++) {
struct mp_hwdec_ctx *dev = devs->hwctxs[n];
- if (dev->av_device_ref) {
- AVHWDeviceContext *hwctx = (void *)dev->av_device_ref->data;
- if (hwctx->type == av_hwdevice_type) {
- res = dev;
- break;
- }
+ if (dev->hw_imgfmt == hw_imgfmt) {
+ res = dev;
+ break;
}
}
- pthread_mutex_unlock(&devs->lock);
+ mp_mutex_unlock(&devs->lock);
return res;
}
-struct AVBufferRef *hwdec_devices_get_lavc(struct mp_hwdec_devices *devs,
- int av_hwdevice_type)
-{
- struct mp_hwdec_ctx *ctx = hwdec_devices_get_by_lavc(devs, av_hwdevice_type);
- if (!ctx)
- return NULL;
- return av_buffer_ref(ctx->av_device_ref);
-}
-
struct mp_hwdec_ctx *hwdec_devices_get_first(struct mp_hwdec_devices *devs)
{
return hwdec_devices_get_n(devs, 0);
@@ -69,42 +57,44 @@ struct mp_hwdec_ctx *hwdec_devices_get_first(struct mp_hwdec_devices *devs)
struct mp_hwdec_ctx *hwdec_devices_get_n(struct mp_hwdec_devices *devs, int n)
{
- pthread_mutex_lock(&devs->lock);
+ mp_mutex_lock(&devs->lock);
struct mp_hwdec_ctx *res = n < devs->num_hwctxs ? devs->hwctxs[n] : NULL;
- pthread_mutex_unlock(&devs->lock);
+ mp_mutex_unlock(&devs->lock);
return res;
}
void hwdec_devices_add(struct mp_hwdec_devices *devs, struct mp_hwdec_ctx *ctx)
{
- pthread_mutex_lock(&devs->lock);
+ mp_mutex_lock(&devs->lock);
MP_TARRAY_APPEND(devs, devs->hwctxs, devs->num_hwctxs, ctx);
- pthread_mutex_unlock(&devs->lock);
+ mp_mutex_unlock(&devs->lock);
}
void hwdec_devices_remove(struct mp_hwdec_devices *devs, struct mp_hwdec_ctx *ctx)
{
- pthread_mutex_lock(&devs->lock);
+ mp_mutex_lock(&devs->lock);
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);
+ mp_mutex_unlock(&devs->lock);
}
void hwdec_devices_set_loader(struct mp_hwdec_devices *devs,
- void (*load_api)(void *ctx), void *load_api_ctx)
+ void (*load_api)(void *ctx, struct hwdec_imgfmt_request *params),
+ void *load_api_ctx)
{
devs->load_api = load_api;
devs->load_api_ctx = load_api_ctx;
}
-void hwdec_devices_request_all(struct mp_hwdec_devices *devs)
+void hwdec_devices_request_for_img_fmt(struct mp_hwdec_devices *devs,
+ struct hwdec_imgfmt_request *params)
{
- if (devs->load_api && !hwdec_devices_get_first(devs))
- devs->load_api(devs->load_api_ctx);
+ if (devs->load_api)
+ devs->load_api(devs->load_api_ctx, params);
}
char *hwdec_devices_get_names(struct mp_hwdec_devices *devs)
@@ -128,6 +118,9 @@ static const struct hwcontext_fns *const hwcontext_fns[] = {
#if HAVE_D3D9_HWACCEL
&hwcontext_fns_dxva2,
#endif
+#if HAVE_DRM
+ &hwcontext_fns_drmprime,
+#endif
#if HAVE_VAAPI
&hwcontext_fns_vaapi,
#endif