22 # include <va/va_x11.h>
25 # include <va/va_drm.h>
29 # include <va/va_drmcommon.h>
31 # include <drm_fourcc.h>
32 # ifndef DRM_FORMAT_MOD_INVALID
33 # define DRM_FORMAT_MOD_INVALID ((1ULL << 56) - 1)
99 } VAAPIFormatDescriptor;
101 #define MAP(va, rt, av, swap_uv) { \
103 VA_RT_FORMAT_ ## rt, \
110 MAP(NV12, YUV420, NV12, 0),
111 #ifdef VA_FOURCC_I420
112 MAP(I420, YUV420, YUV420P, 0),
114 MAP(YV12, YUV420, YUV420P, 1),
115 MAP(IYUV, YUV420, YUV420P, 0),
116 MAP(422
H, YUV422, YUV422P, 0),
117 #ifdef VA_FOURCC_YV16
118 MAP(YV16, YUV422, YUV422P, 1),
120 MAP(UYVY, YUV422, UYVY422, 0),
121 MAP(YUY2, YUV422, YUYV422, 0),
122 #ifdef VA_FOURCC_Y210
123 MAP(Y210, YUV422_10, Y210, 0),
125 MAP(411
P, YUV411, YUV411P, 0),
126 MAP(422
V, YUV422, YUV440P, 0),
127 MAP(444
P, YUV444, YUV444P, 0),
128 MAP(Y800, YUV400, GRAY8, 0),
129 #ifdef VA_FOURCC_P010
130 MAP(P010, YUV420_10BPP, P010, 0),
132 MAP(BGRA, RGB32, BGRA, 0),
133 MAP(BGRX, RGB32, BGR0, 0),
135 MAP(RGBX, RGB32, RGB0, 0),
136 #ifdef VA_FOURCC_ABGR
137 MAP(ABGR, RGB32, ABGR, 0),
138 MAP(XBGR, RGB32, 0BGR, 0),
140 MAP(ARGB, RGB32, ARGB, 0),
141 MAP(XRGB, RGB32, 0RGB, 0),
142 #ifdef VA_FOURCC_X2R10G10B10
143 MAP(X2R10G10B10, RGB32_10, X2RGB10, 0),
148 static const VAAPIFormatDescriptor *
158 static const VAAPIFormatDescriptor *
170 const VAAPIFormatDescriptor *
desc;
173 return desc->pix_fmt;
180 VAImageFormat **image_format)
185 for (
i = 0;
i <
ctx->nb_formats;
i++) {
188 *image_format = &
ctx->formats[
i].image_format;
196 const void *hwconfig,
202 VASurfaceAttrib *attr_list =
NULL;
206 int err,
i, j, attr_count, pix_fmt_count;
211 vas = vaQuerySurfaceAttributes(hwctx->
display,
config->config_id,
213 if (vas != VA_STATUS_SUCCESS) {
215 "%d (%s).\n", vas, vaErrorStr(vas));
220 attr_list =
av_malloc(attr_count *
sizeof(*attr_list));
226 vas = vaQuerySurfaceAttributes(hwctx->
display,
config->config_id,
227 attr_list, &attr_count);
228 if (vas != VA_STATUS_SUCCESS) {
230 "%d (%s).\n", vas, vaErrorStr(vas));
236 for (
i = 0;
i < attr_count;
i++) {
237 switch (attr_list[
i].
type) {
238 case VASurfaceAttribPixelFormat:
239 fourcc = attr_list[
i].value.value.i;
247 case VASurfaceAttribMinWidth:
248 constraints->
min_width = attr_list[
i].value.value.i;
250 case VASurfaceAttribMinHeight:
251 constraints->
min_height = attr_list[
i].value.value.i;
253 case VASurfaceAttribMaxWidth:
254 constraints->
max_width = attr_list[
i].value.value.i;
256 case VASurfaceAttribMaxHeight:
257 constraints->
max_height = attr_list[
i].value.value.i;
261 if (pix_fmt_count == 0) {
273 for (
i = j = 0;
i < attr_count;
i++) {
276 if (attr_list[
i].
type != VASurfaceAttribPixelFormat)
278 fourcc = attr_list[
i].value.value.i;
284 for (k = 0; k < j; k++) {
303 for (
i = j = 0;
i <
ctx->nb_formats;
i++) {
306 for (k = 0; k < j; k++) {
332 static const struct {
337 #if !VA_CHECK_VERSION(1, 0, 0)
340 "Intel i965 (Quick Sync)",
352 "Splitted-Desktop Systems VDPAU backend for VA-API",
361 VAImageFormat *image_list =
NULL;
363 const char *vendor_string;
364 int err,
i, image_count;
368 image_count = vaMaxNumImageFormats(hwctx->
display);
369 if (image_count <= 0) {
373 image_list =
av_malloc(image_count *
sizeof(*image_list));
378 vas = vaQueryImageFormats(hwctx->
display, image_list, &image_count);
379 if (vas != VA_STATUS_SUCCESS) {
390 for (
i = 0;
i < image_count;
i++) {
400 ctx->formats[
ctx->nb_formats].image_format = image_list[
i];
405 vendor_string = vaQueryVendorString(hwctx->
display);
417 if (strstr(vendor_string,
420 "as known nonstandard driver \"%s\", setting "
431 "nonstandard list, using standard behaviour.\n");
435 "assuming standard behaviour.\n");
458 VASurfaceID surface_id;
461 surface_id = (VASurfaceID)(uintptr_t)
data;
463 vas = vaDestroySurfaces(hwctx->
display, &surface_id, 1);
464 if (vas != VA_STATUS_SUCCESS) {
466 "%d (%s).\n", surface_id, vas, vaErrorStr(vas));
476 VASurfaceID surface_id;
484 vas = vaCreateSurfaces(hwctx->
display,
ctx->rt_format,
487 ctx->attributes,
ctx->nb_attributes);
488 if (vas != VA_STATUS_SUCCESS) {
490 "%d (%s).\n", vas, vaErrorStr(vas));
499 vaDestroySurfaces(hwctx->
display, &surface_id, 1);
519 const VAAPIFormatDescriptor *
desc;
520 VAImageFormat *expected_format;
522 VASurfaceID test_surface_id;
537 int need_pixel_format = 1;
539 if (avfc->
attributes[
i].type == VASurfaceAttribMemoryType)
540 need_memory_type = 0;
541 if (avfc->
attributes[
i].type == VASurfaceAttribPixelFormat)
542 need_pixel_format = 0;
548 sizeof(*
ctx->attributes));
549 if (!
ctx->attributes) {
556 if (need_memory_type) {
557 ctx->attributes[
i++] = (VASurfaceAttrib) {
558 .type = VASurfaceAttribMemoryType,
559 .
flags = VA_SURFACE_ATTRIB_SETTABLE,
560 .value.type = VAGenericValueTypeInteger,
561 .value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA,
564 if (need_pixel_format) {
565 ctx->attributes[
i++] = (VASurfaceAttrib) {
566 .type = VASurfaceAttribPixelFormat,
567 .
flags = VA_SURFACE_ATTRIB_SETTABLE,
568 .value.type = VAGenericValueTypeInteger,
569 .value.value.i =
desc->fourcc,
575 ctx->nb_attributes = 0;
578 ctx->rt_format =
desc->rt_format;
614 "user-configured buffer pool.\n");
622 "internal buffer pool.\n");
627 test_surface_id = (VASurfaceID)(uintptr_t)test_surface->
data;
629 ctx->derive_works = 0;
634 vas = vaDeriveImage(hwctx->
display, test_surface_id, &test_image);
635 if (vas == VA_STATUS_SUCCESS) {
636 if (expected_format->fourcc == test_image.format.fourcc) {
638 ctx->derive_works = 1;
641 "derived image format %08x does not match "
642 "expected format %08x.\n",
643 expected_format->fourcc, test_image.format.fourcc);
645 vaDestroyImage(hwctx->
display, test_image.image_id);
648 "deriving image does not work: "
649 "%d (%s).\n", vas, vaErrorStr(vas));
653 "image format is not supported.\n");
695 int i, k, sw_format_available;
697 sw_format_available = 0;
698 for (
i = 0;
i <
ctx->nb_formats;
i++) {
700 sw_format_available = 1;
707 if (sw_format_available) {
713 for (
i = 0;
i <
ctx->nb_formats;
i++) {
730 VASurfaceID surface_id;
733 surface_id = (VASurfaceID)(uintptr_t)hwmap->
source->
data[3];
736 vas = vaUnmapBuffer(hwctx->
display,
map->image.buf);
737 if (vas != VA_STATUS_SUCCESS) {
739 "%#x: %d (%s).\n", surface_id, vas, vaErrorStr(vas));
744 vas = vaPutImage(hwctx->
display, surface_id,
map->image.image_id,
747 if (vas != VA_STATUS_SUCCESS) {
749 "%#x: %d (%s).\n", surface_id, vas, vaErrorStr(vas));
753 vas = vaDestroyImage(hwctx->
display,
map->image.image_id);
754 if (vas != VA_STATUS_SUCCESS) {
756 "%#x: %d (%s).\n", surface_id, vas, vaErrorStr(vas));
767 VASurfaceID surface_id;
768 const VAAPIFormatDescriptor *
desc;
769 VAImageFormat *image_format;
772 void *address =
NULL;
775 surface_id = (VASurfaceID)(uintptr_t)
src->data[3];
799 map->image.image_id = VA_INVALID_ID;
801 vas = vaSyncSurface(hwctx->
display, surface_id);
802 if (vas != VA_STATUS_SUCCESS) {
804 "%#x: %d (%s).\n", surface_id, vas, vaErrorStr(vas));
818 vas = vaDeriveImage(hwctx->
display, surface_id, &
map->image);
819 if (vas != VA_STATUS_SUCCESS) {
821 "surface %#x: %d (%s).\n",
822 surface_id, vas, vaErrorStr(vas));
826 if (
map->image.format.fourcc != image_format->fourcc) {
828 "is in wrong format: expected %#08x, got %#08x.\n",
829 surface_id, image_format->fourcc,
map->image.format.fourcc);
835 vas = vaCreateImage(hwctx->
display, image_format,
837 if (vas != VA_STATUS_SUCCESS) {
839 "surface %#x: %d (%s).\n",
840 surface_id, vas, vaErrorStr(vas));
845 vas = vaGetImage(hwctx->
display, surface_id, 0, 0,
847 if (vas != VA_STATUS_SUCCESS) {
849 "surface %#x: %d (%s).\n",
850 surface_id, vas, vaErrorStr(vas));
857 vas = vaMapBuffer(hwctx->
display,
map->image.buf, &address);
858 if (vas != VA_STATUS_SUCCESS) {
860 "%#x: %d (%s).\n", surface_id, vas, vaErrorStr(vas));
873 for (
i = 0;
i <
map->image.num_planes;
i++) {
874 dst->
data[
i] = (uint8_t*)address +
map->image.offsets[
i];
879 if (
desc &&
desc->chroma_planes_swapped) {
889 vaUnmapBuffer(hwctx->
display,
map->image.buf);
890 if (
map->image.image_id != VA_INVALID_ID)
891 vaDestroyImage(hwctx->
display,
map->image.image_id);
940 map->format =
src->format;
947 map->height =
src->height;
983 #define DRM_MAP(va, layers, ...) { \
988 static const struct {
990 int nb_layer_formats;
992 } vaapi_drm_format_map[] = {
994 DRM_MAP(NV12, 2, DRM_FORMAT_R8, DRM_FORMAT_RG88),
995 DRM_MAP(NV12, 2, DRM_FORMAT_R8, DRM_FORMAT_GR88),
997 DRM_MAP(NV12, 1, DRM_FORMAT_NV12),
998 #if defined(VA_FOURCC_P010) && defined(DRM_FORMAT_R16)
999 DRM_MAP(P010, 2, DRM_FORMAT_R16, DRM_FORMAT_RG1616),
1001 DRM_MAP(BGRA, 1, DRM_FORMAT_ARGB8888),
1002 DRM_MAP(BGRX, 1, DRM_FORMAT_XRGB8888),
1003 DRM_MAP(
RGBA, 1, DRM_FORMAT_ABGR8888),
1004 DRM_MAP(RGBX, 1, DRM_FORMAT_XBGR8888),
1005 #ifdef VA_FOURCC_ABGR
1006 DRM_MAP(ABGR, 1, DRM_FORMAT_RGBA8888),
1007 DRM_MAP(XBGR, 1, DRM_FORMAT_RGBX8888),
1009 DRM_MAP(ARGB, 1, DRM_FORMAT_BGRA8888),
1010 DRM_MAP(XRGB, 1, DRM_FORMAT_BGRX8888),
1019 VASurfaceID surface_id = (VASurfaceID)(uintptr_t)hwmap->
priv;
1023 vaDestroySurfaces(dst_dev->
display, &surface_id, 1);
1034 const VAAPIFormatDescriptor *format_desc;
1035 VASurfaceID surface_id;
1036 VAStatus vas = VA_STATUS_SUCCESS;
1043 if (
desc->nb_objects != 1) {
1045 "made from a single DRM object.\n");
1051 if (
desc->nb_layers != vaapi_drm_format_map[
i].nb_layer_formats)
1053 for (j = 0; j <
desc->nb_layers; j++) {
1054 if (
desc->layers[j].format !=
1055 vaapi_drm_format_map[
i].layer_formats[j])
1058 if (j !=
desc->nb_layers)
1060 va_fourcc = vaapi_drm_format_map[
i].va_fourcc;
1070 "%08x.\n",
desc->objects[0].fd, va_fourcc);
1078 VADRMPRIMESurfaceDescriptor prime_desc;
1079 VASurfaceAttrib prime_attrs[2] = {
1081 .type = VASurfaceAttribMemoryType,
1082 .flags = VA_SURFACE_ATTRIB_SETTABLE,
1083 .value.type = VAGenericValueTypeInteger,
1084 .value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2,
1087 .type = VASurfaceAttribExternalBufferDescriptor,
1088 .flags = VA_SURFACE_ATTRIB_SETTABLE,
1089 .value.type = VAGenericValueTypePointer,
1090 .value.value.p = &prime_desc,
1093 prime_desc.fourcc = va_fourcc;
1094 prime_desc.width = src_fc->
width;
1095 prime_desc.height = src_fc->
height;
1096 prime_desc.num_objects =
desc->nb_objects;
1097 for (
i = 0;
i <
desc->nb_objects; ++
i) {
1098 prime_desc.objects[
i].fd =
desc->objects[
i].fd;
1099 prime_desc.objects[
i].size =
desc->objects[
i].size;
1100 prime_desc.objects[
i].drm_format_modifier =
1101 desc->objects[
i].format_modifier;
1104 prime_desc.num_layers =
desc->nb_layers;
1105 for (
i = 0;
i <
desc->nb_layers; ++
i) {
1106 prime_desc.layers[
i].drm_format =
desc->layers[
i].format;
1107 prime_desc.layers[
i].num_planes =
desc->layers[
i].nb_planes;
1108 for (j = 0; j <
desc->layers[
i].nb_planes; ++j) {
1109 prime_desc.layers[
i].object_index[j] =
1110 desc->layers[
i].planes[j].object_index;
1111 prime_desc.layers[
i].offset[j] =
desc->layers[
i].planes[j].offset;
1112 prime_desc.layers[
i].pitch[j] =
desc->layers[
i].planes[j].pitch;
1115 if (format_desc->chroma_planes_swapped &&
1116 desc->layers[
i].nb_planes == 3) {
1117 FFSWAP(uint32_t, prime_desc.layers[
i].pitch[1],
1118 prime_desc.layers[
i].pitch[2]);
1119 FFSWAP(uint32_t, prime_desc.layers[
i].offset[1],
1120 prime_desc.layers[
i].offset[2]);
1130 vas = vaCreateSurfaces(dst_dev->
display, format_desc->rt_format,
1131 src->width,
src->height, &surface_id, 1,
1133 if (vas != VA_STATUS_SUCCESS)
1137 if (!use_prime2 || vas != VA_STATUS_SUCCESS) {
1139 unsigned long buffer_handle;
1140 VASurfaceAttribExternalBuffers buffer_desc;
1141 VASurfaceAttrib buffer_attrs[2] = {
1143 .type = VASurfaceAttribMemoryType,
1144 .flags = VA_SURFACE_ATTRIB_SETTABLE,
1145 .value.type = VAGenericValueTypeInteger,
1146 .value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME,
1149 .type = VASurfaceAttribExternalBufferDescriptor,
1150 .flags = VA_SURFACE_ATTRIB_SETTABLE,
1151 .value.type = VAGenericValueTypePointer,
1152 .value.value.p = &buffer_desc,
1156 buffer_handle =
desc->objects[0].fd;
1157 buffer_desc.pixel_format = va_fourcc;
1158 buffer_desc.width = src_fc->
width;
1159 buffer_desc.height = src_fc->
height;
1160 buffer_desc.data_size =
desc->objects[0].size;
1161 buffer_desc.buffers = &buffer_handle;
1162 buffer_desc.num_buffers = 1;
1163 buffer_desc.flags = 0;
1166 for (
i = 0;
i <
desc->nb_layers;
i++) {
1167 for (j = 0; j <
desc->layers[
i].nb_planes; j++) {
1168 buffer_desc.pitches[k] =
desc->layers[
i].planes[j].pitch;
1169 buffer_desc.offsets[k] =
desc->layers[
i].planes[j].offset;
1173 buffer_desc.num_planes = k;
1175 if (format_desc->chroma_planes_swapped &&
1176 buffer_desc.num_planes == 3) {
1177 FFSWAP(uint32_t, buffer_desc.pitches[1], buffer_desc.pitches[2]);
1178 FFSWAP(uint32_t, buffer_desc.offsets[1], buffer_desc.offsets[2]);
1181 vas = vaCreateSurfaces(dst_dev->
display, format_desc->rt_format,
1186 if (vas != VA_STATUS_SUCCESS) {
1188 "object: %d (%s).\n", vas, vaErrorStr(vas));
1194 &vaapi_unmap_from_drm,
1195 (
void*)(uintptr_t)surface_id);
1201 dst->
data[3] = (uint8_t*)(uintptr_t)surface_id;
1204 "surface %#x.\n",
desc->objects[0].fd, surface_id);
1209 #if VA_CHECK_VERSION(1, 1, 0)
1226 VASurfaceID surface_id;
1228 VADRMPRIMESurfaceDescriptor va_desc;
1230 uint32_t export_flags;
1233 surface_id = (VASurfaceID)(uintptr_t)
src->data[3];
1235 export_flags = VA_EXPORT_SURFACE_SEPARATE_LAYERS;
1237 export_flags |= VA_EXPORT_SURFACE_READ_ONLY;
1239 export_flags |= VA_EXPORT_SURFACE_WRITE_ONLY;
1241 vas = vaExportSurfaceHandle(hwctx->
display, surface_id,
1242 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2,
1243 export_flags, &va_desc);
1244 if (vas != VA_STATUS_SUCCESS) {
1245 if (vas == VA_STATUS_ERROR_UNIMPLEMENTED)
1248 "%d (%s).\n", surface_id, vas, vaErrorStr(vas));
1260 for (
i = 0;
i < va_desc.num_objects;
i++) {
1264 va_desc.objects[
i].drm_format_modifier;
1266 drm_desc->
nb_layers = va_desc.num_layers;
1267 for (
i = 0;
i < va_desc.num_layers;
i++) {
1270 for (j = 0; j < va_desc.layers[
i].num_planes; j++) {
1272 va_desc.layers[
i].object_index[j];
1274 va_desc.layers[
i].offset[j];
1276 va_desc.layers[
i].pitch[j];
1281 &vaapi_unmap_to_drm_esh, drm_desc);
1287 dst->
data[0] = (uint8_t*)drm_desc;
1292 for (
i = 0;
i < va_desc.num_objects;
i++)
1293 close(va_desc.objects[
i].fd);
1299 #if VA_CHECK_VERSION(0, 36, 0)
1300 typedef struct VAAPIDRMImageBufferMapping {
1302 VABufferInfo buffer_info;
1305 } VAAPIDRMImageBufferMapping;
1311 VAAPIDRMImageBufferMapping *mapping = hwmap->
priv;
1312 VASurfaceID surface_id;
1315 surface_id = (VASurfaceID)(uintptr_t)hwmap->
source->
data[3];
1322 vas = vaReleaseBufferHandle(hwctx->
display, mapping->image.buf);
1323 if (vas != VA_STATUS_SUCCESS) {
1325 "handle of image %#x (derived from surface %#x): "
1326 "%d (%s).\n", mapping->image.buf, surface_id,
1327 vas, vaErrorStr(vas));
1330 vas = vaDestroyImage(hwctx->
display, mapping->image.image_id);
1331 if (vas != VA_STATUS_SUCCESS) {
1333 "derived from surface %#x: %d (%s).\n",
1334 surface_id, vas, vaErrorStr(vas));
1344 VAAPIDRMImageBufferMapping *mapping =
NULL;
1345 VASurfaceID surface_id;
1349 surface_id = (VASurfaceID)(uintptr_t)
src->data[3];
1357 vas = vaDeriveImage(hwctx->
display, surface_id,
1359 if (vas != VA_STATUS_SUCCESS) {
1361 "surface %#x: %d (%s).\n",
1362 surface_id, vas, vaErrorStr(vas));
1368 if (vaapi_drm_format_map[
i].va_fourcc ==
1369 mapping->image.format.fourcc)
1374 "VAAPI format %#x.\n", mapping->image.format.fourcc);
1379 mapping->buffer_info.mem_type =
1380 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
1382 mapping->drm_desc.nb_layers =
1383 vaapi_drm_format_map[
i].nb_layer_formats;
1384 if (mapping->drm_desc.nb_layers > 1) {
1385 if (mapping->drm_desc.nb_layers != mapping->image.num_planes) {
1387 "expected format: got %d planes, but expected %d.\n",
1388 mapping->image.num_planes, mapping->drm_desc.nb_layers);
1393 for(p = 0; p < mapping->drm_desc.nb_layers; p++) {
1395 .format = vaapi_drm_format_map[
i].layer_formats[p],
1399 .offset = mapping->image.offsets[p],
1400 .pitch = mapping->image.pitches[p],
1405 mapping->drm_desc.layers[0].format =
1406 vaapi_drm_format_map[
i].layer_formats[0];
1407 mapping->drm_desc.layers[0].nb_planes = mapping->image.num_planes;
1408 for (p = 0; p < mapping->image.num_planes; p++) {
1411 .offset = mapping->image.offsets[p],
1412 .pitch = mapping->image.pitches[p],
1417 vas = vaAcquireBufferHandle(hwctx->
display, mapping->image.buf,
1418 &mapping->buffer_info);
1419 if (vas != VA_STATUS_SUCCESS) {
1421 "handle from image %#x (derived from surface %#x): "
1422 "%d (%s).\n", mapping->image.buf, surface_id,
1423 vas, vaErrorStr(vas));
1429 mapping->buffer_info.handle);
1431 mapping->drm_desc.nb_objects = 1;
1433 .fd = mapping->buffer_info.handle,
1434 .size = mapping->image.data_size,
1440 dst,
src, &vaapi_unmap_to_drm_abh,
1445 dst->
data[0] = (uint8_t*)&mapping->drm_desc;
1452 vaReleaseBufferHandle(hwctx->
display, mapping->image.buf);
1454 vaDestroyImage(hwctx->
display, mapping->image.image_id);
1464 #if VA_CHECK_VERSION(1, 1, 0)
1466 err = vaapi_map_to_drm_esh(hwfc, dst,
src,
flags);
1470 #if VA_CHECK_VERSION(0, 36, 0)
1471 return vaapi_map_to_drm_abh(hwfc, dst,
src,
flags);
1481 switch (
src->format) {
1484 return vaapi_map_from_drm(hwfc, dst,
src,
flags);
1497 return vaapi_map_to_drm(hwfc, dst,
src,
flags);
1513 if (priv->x11_display)
1514 XCloseDisplay(priv->x11_display);
1524 static void vaapi_device_log_error(
void *
context,
const char *
message)
1531 static void vaapi_device_log_info(
void *
context,
const char *
message)
1547 vaSetErrorCallback(display, &vaapi_device_log_error,
ctx);
1548 vaSetInfoCallback (display, &vaapi_device_log_info,
ctx);
1554 if (vas != VA_STATUS_SUCCESS) {
1556 "connection: %d (%s).\n", vas, vaErrorStr(vas));
1569 VADisplay display =
NULL;
1571 int try_drm, try_x11, try_all;
1579 ctx->user_opaque = priv;
1584 try_all = try_drm = try_x11 = 0;
1585 if (!strcmp(ent->
value,
"drm")) {
1587 }
else if (!strcmp(ent->
value,
"x11")) {
1596 try_drm = HAVE_VAAPI_DRM;
1597 try_x11 = HAVE_VAAPI_X11;
1601 while (!display && try_drm) {
1607 priv->
drm_fd = open(device, O_RDWR);
1609 av_log(
ctx, loglevel,
"Failed to open %s as "
1610 "DRM device node.\n", device);
1615 int n, max_devices = 8;
1620 for (n = 0; n < max_devices; n++) {
1622 "/dev/dri/renderD%d", 128 + n);
1623 priv->
drm_fd = open(path, O_RDWR);
1626 "DRM render node for device %d.\n", n);
1630 if (kernel_driver) {
1633 if (strcmp(kernel_driver->
value,
info->name)) {
1635 "with non-matching kernel driver (%s).\n",
1637 drmFreeVersion(
info);
1643 "DRM render node for device %d, "
1644 "with matching kernel driver (%s).\n",
1646 drmFreeVersion(
info);
1651 "DRM render node for device %d.\n", n);
1655 if (n >= max_devices)
1659 display = vaGetDisplayDRM(priv->
drm_fd);
1662 "from DRM device %s.\n", device);
1670 if (!display && try_x11) {
1672 priv->x11_display = XOpenDisplay(device);
1673 if (!priv->x11_display) {
1675 "%s.\n", XDisplayName(device));
1677 display = vaGetDisplay(priv->x11_display);
1680 "from X11 display %s.\n", XDisplayName(device));
1685 "X11 display %s.\n", XDisplayName(device));
1693 "device %s.\n", device);
1696 "any default device.\n");
1702 #if VA_CHECK_VERSION(0, 38, 0)
1704 vas = vaSetDriverName(display, ent->
value);
1705 if (vas != VA_STATUS_SUCCESS) {
1707 "%s: %d (%s).\n", ent->
value, vas, vaErrorStr(vas));
1708 vaTerminate(display);
1713 "supported with this VAAPI version.\n");
1731 if (src_hwctx->
fd < 0) {
1733 "device to derive a VA display from.\n");
1739 int node_type = drmGetNodeTypeFromFd(src_hwctx->
fd);
1741 if (node_type < 0) {
1743 "to refer to a DRM device.\n");
1746 if (node_type == DRM_NODE_RENDER) {
1749 render_node = drmGetRenderDeviceNameFromFd(src_hwctx->
fd);
1752 "because the device does not have an "
1753 "associated render node.\n");
1756 fd = open(render_node, O_RDWR);
1759 "because the associated render node "
1760 "could not be opened.\n");
1764 "in place of non-render DRM device.\n",
1777 if (fd != src_hwctx->
fd) {
1784 if (fd == src_hwctx->
fd) {
1792 ctx->user_opaque = priv;
1795 display = vaGetDisplayDRM(fd);