summaryrefslogtreecommitdiffstats
path: root/video/vaapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'video/vaapi.c')
-rw-r--r--video/vaapi.c79
1 files changed, 64 insertions, 15 deletions
diff --git a/video/vaapi.c b/video/vaapi.c
index 08248a7..666fd00 100644
--- a/video/vaapi.c
+++ b/video/vaapi.c
@@ -21,6 +21,7 @@
#include "vaapi.h"
#include "common/common.h"
+#include "common/global.h"
#include "common/msg.h"
#include "osdep/threads.h"
#include "mp_image.h"
@@ -28,9 +29,28 @@
#include "mp_image_pool.h"
#include "options/m_config.h"
+#ifdef _WIN32
+#include "osdep/windows_utils.h"
+#include "out/d3d11/context.h"
+#include "out/gpu/d3d11_helpers.h"
+#endif
+
#include <libavutil/hwcontext.h>
#include <libavutil/hwcontext_vaapi.h>
+#ifdef _WIN32
+#define DEV_PATH_DEFAULT NULL
+#define DEV_PATH_VALIDATE mp_dxgi_validate_adapter
+#else
+#define DEV_PATH_DEFAULT "/dev/dri/renderD128"
+#define DEV_PATH_VALIDATE validate_path
+
+static inline OPT_STRING_VALIDATE_FUNC(validate_path)
+{
+ return (*value && **value) ? 0 : M_OPT_INVALID;
+}
+#endif
+
struct vaapi_opts {
char *path;
};
@@ -38,21 +58,21 @@ struct vaapi_opts {
#define OPT_BASE_STRUCT struct vaapi_opts
const struct m_sub_options vaapi_conf = {
.opts = (const struct m_option[]) {
- {"device", OPT_STRING(path)},
+ {"device", OPT_STRING_VALIDATE(path, DEV_PATH_VALIDATE)},
{0},
},
.defaults = &(const struct vaapi_opts) {
- .path = "/dev/dri/renderD128",
+ .path = DEV_PATH_DEFAULT,
},
.size = sizeof(struct vaapi_opts),
};
-int va_get_colorspace_flag(enum mp_csp csp)
+int va_get_colorspace_flag(enum pl_color_system csp)
{
switch (csp) {
- case MP_CSP_BT_601: return VA_SRC_BT601;
- case MP_CSP_BT_709: return VA_SRC_BT709;
- case MP_CSP_SMPTE_240M: return VA_SRC_SMPTE_240;
+ case PL_COLOR_SYSTEM_BT_601: return VA_SRC_BT601;
+ case PL_COLOR_SYSTEM_BT_709: return VA_SRC_BT709;
+ case PL_COLOR_SYSTEM_SMPTE_240M: return VA_SRC_SMPTE_240;
}
return 0;
}
@@ -70,7 +90,7 @@ static void va_error_callback(void *context, const char *msg)
static void va_info_callback(void *context, const char *msg)
{
- va_message_callback(context, msg, MSGL_DEBUG);
+ va_message_callback(context, msg, MSGL_V);
}
static void free_device_ref(struct AVHWDeviceContext *hwctx)
@@ -166,8 +186,8 @@ bool va_guess_if_emulated(struct mp_vaapi_ctx *ctx)
}
struct va_native_display {
- void (*create)(VADisplay **out_display, void **out_native_ctx,
- const char *path);
+ void (*create)(struct mp_log *log, VADisplay **out_display,
+ void **out_native_ctx, const char *path);
void (*destroy)(void *native_ctx);
};
@@ -180,8 +200,8 @@ static void x11_destroy(void *native_ctx)
XCloseDisplay(native_ctx);
}
-static void x11_create(VADisplay **out_display, void **out_native_ctx,
- const char *path)
+static void x11_create(struct mp_log *log, VADisplay **out_display,
+ void **out_native_ctx, const char *path)
{
void *native_display = XOpenDisplay(NULL);
if (!native_display)
@@ -200,6 +220,31 @@ static const struct va_native_display disp_x11 = {
};
#endif
+#if HAVE_VAAPI_WIN32
+#include <va/va_win32.h>
+
+static void win32_create(struct mp_log *log, VADisplay **out_display,
+ void **out_native_ctx, const char *path)
+{
+ LUID *luid = NULL;
+ DXGI_ADAPTER_DESC1 desc = {0};
+ if (path && path[0]) {
+ IDXGIAdapter1 *adapter = mp_get_dxgi_adapter(log, bstr0(path), NULL);
+ if (!adapter || FAILED(IDXGIAdapter1_GetDesc1(adapter, &desc))) {
+ mp_err(log, "Failed to get adapter LUID for name: %s\n", path);
+ } else {
+ luid = &desc.AdapterLuid;
+ }
+ SAFE_RELEASE(adapter);
+ }
+ *out_display = vaGetDisplayWin32(luid);
+}
+
+static const struct va_native_display disp_win32 = {
+ .create = win32_create,
+};
+#endif
+
#if HAVE_VAAPI_DRM
#include <unistd.h>
#include <fcntl.h>
@@ -216,8 +261,8 @@ static void drm_destroy(void *native_ctx)
talloc_free(ctx);
}
-static void drm_create(VADisplay **out_display, void **out_native_ctx,
- const char *path)
+static void drm_create(struct mp_log *log, VADisplay **out_display,
+ void **out_native_ctx, const char *path)
{
int drm_fd = open(path, O_RDWR);
if (drm_fd < 0)
@@ -245,6 +290,9 @@ static const struct va_native_display *const native_displays[] = {
#if HAVE_VAAPI_DRM
&disp_drm,
#endif
+#if HAVE_VAAPI_WIN32
+ &disp_win32,
+#endif
#if HAVE_VAAPI_X11
&disp_x11,
#endif
@@ -260,13 +308,14 @@ static struct AVBufferRef *va_create_standalone(struct mpv_global *global,
for (int n = 0; native_displays[n]; n++) {
VADisplay *display = NULL;
void *native_ctx = NULL;
- native_displays[n]->create(&display, &native_ctx, opts->path);
+ native_displays[n]->create(global->log, &display, &native_ctx, opts->path);
if (display) {
struct mp_vaapi_ctx *ctx =
va_initialize(display, log, params->probing);
if (!ctx) {
vaTerminate(display);
- native_displays[n]->destroy(native_ctx);
+ if (native_displays[n]->destroy)
+ native_displays[n]->destroy(native_ctx);
goto end;
}
ctx->native_ctx = native_ctx;