hwdec_vaegl: Fix VAAPI EGL interop used with gpu-context=drm

Add another parameter to mpv_opengl_drm_params to hold the FD to the
render node, so that the fd can be passed to hwdec_vaegl.

The render node is opened in context_drm_egl and inferred from the
primary device fd using drmGetRenderDeviceNameFromFd.
This commit is contained in:
Anton Kindestam 2018-06-28 15:06:41 +02:00 committed by Jan Ekström
parent 7beee68f8d
commit 351c083487
3 changed files with 29 additions and 6 deletions

View File

@ -149,7 +149,7 @@ typedef struct mpv_opengl_fbo {
typedef struct mpv_opengl_drm_params {
/**
* DRM fd (int). set this to -1 if invalid.
* DRM fd (int). Set to a negative number if invalid.
*/
int fd;
@ -169,6 +169,12 @@ typedef struct mpv_opengl_drm_params {
* The atomic request pointer is usually changed at every renderloop.
*/
struct _drmModeAtomicReq **atomic_request_ptr;
/**
* DRM render node. Used for VAAPI interop.
* Set to a negative number if invalid.
*/
int render_fd;
} mpv_opengl_drm_params;
typedef struct mpv_opengl_drm_osd_size {

View File

@ -513,6 +513,8 @@ static void drm_egl_uninit(struct ra_ctx *ctx)
p->egl.context = EGL_NO_CONTEXT;
eglDestroyContext(p->egl.display, p->egl.context);
close(p->drm_params.render_fd);
if (p->kms) {
kms_destroy(p->kms);
p->kms = 0;
@ -664,6 +666,20 @@ static bool drm_egl_init(struct ra_ctx *ctx)
p->drm_params.connector_id = p->kms->connector->connector_id;
if (p->kms->atomic_context)
p->drm_params.atomic_request_ptr = &p->kms->atomic_context->request;
char *rendernode_path = drmGetRenderDeviceNameFromFd(p->kms->fd);
if (rendernode_path) {
MP_VERBOSE(ctx, "Opening render node \"%s\"\n", rendernode_path);
p->drm_params.render_fd = open(rendernode_path, O_RDWR | O_CLOEXEC);
if (p->drm_params.render_fd < 0) {
MP_WARN(ctx, "Cannot open render node \"%s\": %s. VAAPI hwdec will be disabled\n",
rendernode_path, mp_strerror(errno));
}
free(rendernode_path);
} else {
p->drm_params.render_fd = -1;
MP_VERBOSE(ctx, "Could not find path to render node. VAAPI hwdec will be disabled\n");
}
struct ra_gl_ctx_params params = {
.swap_buffers = drm_egl_swap_buffers,
.external_swapchain = p->kms->atomic_context ? &drm_atomic_swapchain :

View File

@ -36,6 +36,7 @@
#include "video/vaapi.h"
#include "common.h"
#include "ra_gl.h"
#include "libmpv/render_gl.h"
#ifndef GL_OES_EGL_image
typedef void* GLeglImageOES;
@ -77,11 +78,11 @@ static VADisplay *create_wayland_va_display(struct ra *ra)
static VADisplay *create_drm_va_display(struct ra *ra)
{
int drm_fd = (intptr_t)ra_get_native_resource(ra, "drm");
// Note: yes, drm_fd==0 could be valid - but it's rare and doesn't fit with
// our slightly crappy way of passing it through, so consider 0 not
// valid.
return drm_fd ? vaGetDisplayDRM(drm_fd) : NULL;
mpv_opengl_drm_params *params = ra_get_native_resource(ra, "drm_params");
if (!params || params->render_fd < 0)
return NULL;
return vaGetDisplayDRM(params->render_fd);
}
#endif