From a1b74e1220d15eba7eab86b30691fb85d7f04e5c Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 14 May 2020 20:56:24 -0700 Subject: [PATCH] Fix vaExportSurfaceHandle() detection with i965 VAAPI driver --- .../video/ffmpeg-renderers/vaapi.cpp | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/app/streaming/video/ffmpeg-renderers/vaapi.cpp b/app/streaming/video/ffmpeg-renderers/vaapi.cpp index 1badb77a..fecb236e 100644 --- a/app/streaming/video/ffmpeg-renderers/vaapi.cpp +++ b/app/streaming/video/ffmpeg-renderers/vaapi.cpp @@ -446,6 +446,26 @@ VAAPIRenderer::canExportEGL() { VASurfaceID surfaceId; VAStatus st; VADRMPRIMESurfaceDescriptor descriptor; + VASurfaceAttrib attrs[2]; + int attributeCount = 0; + + // FFmpeg handles setting these quirk flags for us + if (!(vaDeviceContext->driver_quirks & AV_VAAPI_DRIVER_QUIRK_ATTRIB_MEMTYPE)) { + attrs[attributeCount].type = VASurfaceAttribMemoryType; + attrs[attributeCount].flags = VA_SURFACE_ATTRIB_SETTABLE; + attrs[attributeCount].value.type = VAGenericValueTypeInteger; + attrs[attributeCount].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA; + attributeCount++; + } + + // These attributes are required for i965 to create a surface that can + // be successfully exported via vaExportSurfaceHandle(). iHD doesn't + // need these, but it doesn't seem to hurt either. + attrs[attributeCount].type = VASurfaceAttribPixelFormat; + attrs[attributeCount].flags = VA_SURFACE_ATTRIB_SETTABLE; + attrs[attributeCount].value.type = VAGenericValueTypeInteger; + attrs[attributeCount].value.value.i = VA_FOURCC_NV12; + attributeCount++; st = vaCreateSurfaces(vaDeviceContext->display, VA_RT_FORMAT_YUV420, @@ -453,8 +473,8 @@ VAAPIRenderer::canExportEGL() { 720, &surfaceId, 1, - nullptr, - 0); + attrs, + attributeCount); if (st != VA_STATUS_SUCCESS) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "vaCreateSurfaces() failed: %d", st);