mirror of
https://github.com/mpv-player/mpv
synced 2025-04-20 22:26:30 +00:00
vaapi: add option to select a non-default device path
On machines with multiple GPUs, /dev/dri/renderD128 isn't guaranteed to point to a valid vaapi device. This just adds the option to specify what path to use. The old fallback /dev/dri/card0 is gone but that's not a loss as its a legacy interface no longer accepted as valid by libva. Fixes #4320
This commit is contained in:
parent
af9c6c1133
commit
e3e2c794ef
@ -89,6 +89,7 @@ extern const struct m_sub_options angle_conf;
|
|||||||
extern const struct m_sub_options cocoa_conf;
|
extern const struct m_sub_options cocoa_conf;
|
||||||
extern const struct m_sub_options macos_conf;
|
extern const struct m_sub_options macos_conf;
|
||||||
extern const struct m_sub_options android_conf;
|
extern const struct m_sub_options android_conf;
|
||||||
|
extern const struct m_sub_options vaapi_conf;
|
||||||
|
|
||||||
static const struct m_sub_options screenshot_conf = {
|
static const struct m_sub_options screenshot_conf = {
|
||||||
.opts = image_writer_opts,
|
.opts = image_writer_opts,
|
||||||
@ -756,6 +757,10 @@ const m_option_t mp_opts[] = {
|
|||||||
0, INT_MAX, ({"auto", -1})),
|
0, INT_MAX, ({"auto", -1})),
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if HAVE_VAAPI
|
||||||
|
OPT_SUBSTRUCT("vaapi", vaapi_opts, vaapi_conf, 0),
|
||||||
|
#endif
|
||||||
|
|
||||||
#if HAVE_ENCODING
|
#if HAVE_ENCODING
|
||||||
OPT_SUBSTRUCT("", encode_opts, encode_config, 0),
|
OPT_SUBSTRUCT("", encode_opts, encode_config, 0),
|
||||||
#endif
|
#endif
|
||||||
|
@ -347,6 +347,7 @@ typedef struct MPOpts {
|
|||||||
struct macos_opts *macos_opts;
|
struct macos_opts *macos_opts;
|
||||||
struct android_opts *android_opts;
|
struct android_opts *android_opts;
|
||||||
struct dvd_opts *dvd_opts;
|
struct dvd_opts *dvd_opts;
|
||||||
|
struct vaapi_opts *vaapi_opts;
|
||||||
|
|
||||||
int cuda_device;
|
int cuda_device;
|
||||||
} MPOpts;
|
} MPOpts;
|
||||||
|
@ -26,10 +26,27 @@
|
|||||||
#include "mp_image.h"
|
#include "mp_image.h"
|
||||||
#include "img_format.h"
|
#include "img_format.h"
|
||||||
#include "mp_image_pool.h"
|
#include "mp_image_pool.h"
|
||||||
|
#include "options/m_config.h"
|
||||||
|
|
||||||
#include <libavutil/hwcontext.h>
|
#include <libavutil/hwcontext.h>
|
||||||
#include <libavutil/hwcontext_vaapi.h>
|
#include <libavutil/hwcontext_vaapi.h>
|
||||||
|
|
||||||
|
struct vaapi_opts {
|
||||||
|
char *path;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define OPT_BASE_STRUCT struct vaapi_opts
|
||||||
|
const struct m_sub_options vaapi_conf = {
|
||||||
|
.opts = (const struct m_option[]) {
|
||||||
|
OPT_STRING("device", path, 0),
|
||||||
|
{0},
|
||||||
|
},
|
||||||
|
.defaults = &(const struct vaapi_opts) {
|
||||||
|
.path = "/dev/dri/renderD128",
|
||||||
|
},
|
||||||
|
.size = sizeof(struct vaapi_opts),
|
||||||
|
};
|
||||||
|
|
||||||
int va_get_colorspace_flag(enum mp_csp csp)
|
int va_get_colorspace_flag(enum mp_csp csp)
|
||||||
{
|
{
|
||||||
switch (csp) {
|
switch (csp) {
|
||||||
@ -216,7 +233,8 @@ bool va_guess_if_emulated(struct mp_vaapi_ctx *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct va_native_display {
|
struct va_native_display {
|
||||||
void (*create)(VADisplay **out_display, void **out_native_ctx);
|
void (*create)(VADisplay **out_display, void **out_native_ctx,
|
||||||
|
const char *path);
|
||||||
void (*destroy)(void *native_ctx);
|
void (*destroy)(void *native_ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -229,7 +247,8 @@ static void x11_destroy(void *native_ctx)
|
|||||||
XCloseDisplay(native_ctx);
|
XCloseDisplay(native_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void x11_create(VADisplay **out_display, void **out_native_ctx)
|
static void x11_create(VADisplay **out_display, void **out_native_ctx,
|
||||||
|
const char *path)
|
||||||
{
|
{
|
||||||
void *native_display = XOpenDisplay(NULL);
|
void *native_display = XOpenDisplay(NULL);
|
||||||
if (!native_display)
|
if (!native_display)
|
||||||
@ -264,18 +283,12 @@ static void drm_destroy(void *native_ctx)
|
|||||||
talloc_free(ctx);
|
talloc_free(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void drm_create(VADisplay **out_display, void **out_native_ctx)
|
static void drm_create(VADisplay **out_display, void **out_native_ctx,
|
||||||
|
const char *path)
|
||||||
{
|
{
|
||||||
static const char *drm_device_paths[] = {
|
int drm_fd = open(path, O_RDWR);
|
||||||
"/dev/dri/renderD128",
|
|
||||||
"/dev/dri/card0",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
for (int i = 0; drm_device_paths[i]; i++) {
|
|
||||||
int drm_fd = open(drm_device_paths[i], O_RDWR);
|
|
||||||
if (drm_fd < 0)
|
if (drm_fd < 0)
|
||||||
continue;
|
return;
|
||||||
|
|
||||||
struct va_native_display_drm *ctx = talloc_ptrtype(NULL, ctx);
|
struct va_native_display_drm *ctx = talloc_ptrtype(NULL, ctx);
|
||||||
ctx->drm_fd = drm_fd;
|
ctx->drm_fd = drm_fd;
|
||||||
@ -287,7 +300,6 @@ static void drm_create(VADisplay **out_display, void **out_native_ctx)
|
|||||||
|
|
||||||
close(drm_fd);
|
close(drm_fd);
|
||||||
talloc_free(ctx);
|
talloc_free(ctx);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct va_native_display disp_drm = {
|
static const struct va_native_display disp_drm = {
|
||||||
@ -309,24 +321,31 @@ static const struct va_native_display *const native_displays[] = {
|
|||||||
static struct AVBufferRef *va_create_standalone(struct mpv_global *global,
|
static struct AVBufferRef *va_create_standalone(struct mpv_global *global,
|
||||||
struct mp_log *log, struct hwcontext_create_dev_params *params)
|
struct mp_log *log, struct hwcontext_create_dev_params *params)
|
||||||
{
|
{
|
||||||
|
struct AVBufferRef *ret = NULL;
|
||||||
|
struct vaapi_opts *opts = mp_get_config_group(NULL, global, &vaapi_conf);
|
||||||
|
|
||||||
for (int n = 0; native_displays[n]; n++) {
|
for (int n = 0; native_displays[n]; n++) {
|
||||||
VADisplay *display = NULL;
|
VADisplay *display = NULL;
|
||||||
void *native_ctx = NULL;
|
void *native_ctx = NULL;
|
||||||
native_displays[n]->create(&display, &native_ctx);
|
native_displays[n]->create(&display, &native_ctx, opts->path);
|
||||||
if (display) {
|
if (display) {
|
||||||
struct mp_vaapi_ctx *ctx =
|
struct mp_vaapi_ctx *ctx =
|
||||||
va_initialize(display, log, params->probing);
|
va_initialize(display, log, params->probing);
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
vaTerminate(display);
|
vaTerminate(display);
|
||||||
native_displays[n]->destroy(native_ctx);
|
native_displays[n]->destroy(native_ctx);
|
||||||
return NULL;
|
goto end;
|
||||||
}
|
}
|
||||||
ctx->native_ctx = native_ctx;
|
ctx->native_ctx = native_ctx;
|
||||||
ctx->destroy_native_ctx = native_displays[n]->destroy;
|
ctx->destroy_native_ctx = native_displays[n]->destroy;
|
||||||
return ctx->hwctx.av_device_ref;
|
ret = ctx->hwctx.av_device_ref;
|
||||||
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
|
||||||
|
end:
|
||||||
|
talloc_free(opts);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct hwcontext_fns hwcontext_fns_vaapi = {
|
const struct hwcontext_fns hwcontext_fns_vaapi = {
|
||||||
|
Loading…
Reference in New Issue
Block a user