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);
1029 #if VA_CHECK_VERSION(1, 1, 0)
1039 const VAAPIFormatDescriptor *format_desc;
1040 VASurfaceID surface_id;
1041 VAStatus vas = VA_STATUS_SUCCESS;
1045 #
if !VA_CHECK_VERSION(1, 1, 0)
1046 unsigned long buffer_handle;
1047 VASurfaceAttribExternalBuffers buffer_desc;
1048 VASurfaceAttrib attrs[2] = {
1050 .type = VASurfaceAttribMemoryType,
1051 .flags = VA_SURFACE_ATTRIB_SETTABLE,
1052 .value.type = VAGenericValueTypeInteger,
1053 .value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME,
1056 .type = VASurfaceAttribExternalBufferDescriptor,
1057 .flags = VA_SURFACE_ATTRIB_SETTABLE,
1058 .value.type = VAGenericValueTypePointer,
1059 .value.value.p = &buffer_desc,
1066 if (
desc->nb_objects != 1) {
1068 "made from a single DRM object.\n");
1074 if (
desc->nb_layers != vaapi_drm_format_map[
i].nb_layer_formats)
1076 for (j = 0; j <
desc->nb_layers; j++) {
1077 if (
desc->layers[j].format !=
1078 vaapi_drm_format_map[
i].layer_formats[j])
1081 if (j !=
desc->nb_layers)
1083 va_fourcc = vaapi_drm_format_map[
i].va_fourcc;
1093 "%08x.\n",
desc->objects[0].fd, va_fourcc);
1098 #if VA_CHECK_VERSION(1, 1, 0)
1102 VADRMPRIMESurfaceDescriptor prime_desc;
1103 VASurfaceAttrib prime_attrs[2] = {
1105 .type = VASurfaceAttribMemoryType,
1106 .flags = VA_SURFACE_ATTRIB_SETTABLE,
1107 .value.type = VAGenericValueTypeInteger,
1108 .value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2,
1111 .type = VASurfaceAttribExternalBufferDescriptor,
1112 .flags = VA_SURFACE_ATTRIB_SETTABLE,
1113 .value.type = VAGenericValueTypePointer,
1114 .value.value.p = &prime_desc,
1117 prime_desc.fourcc = va_fourcc;
1118 prime_desc.width = src_fc->
width;
1119 prime_desc.height = src_fc->
height;
1120 prime_desc.num_objects =
desc->nb_objects;
1121 for (
i = 0;
i <
desc->nb_objects; ++
i) {
1122 prime_desc.objects[
i].fd =
desc->objects[
i].fd;
1123 prime_desc.objects[
i].size =
desc->objects[
i].size;
1124 prime_desc.objects[
i].drm_format_modifier =
1125 desc->objects[
i].format_modifier;
1128 prime_desc.num_layers =
desc->nb_layers;
1129 for (
i = 0;
i <
desc->nb_layers; ++
i) {
1130 prime_desc.layers[
i].drm_format =
desc->layers[
i].format;
1131 prime_desc.layers[
i].num_planes =
desc->layers[
i].nb_planes;
1132 for (j = 0; j <
desc->layers[
i].nb_planes; ++j) {
1133 prime_desc.layers[
i].object_index[j] =
1134 desc->layers[
i].planes[j].object_index;
1135 prime_desc.layers[
i].offset[j] =
desc->layers[
i].planes[j].offset;
1136 prime_desc.layers[
i].pitch[j] =
desc->layers[
i].planes[j].pitch;
1139 if (format_desc->chroma_planes_swapped &&
1140 desc->layers[
i].nb_planes == 3) {
1141 FFSWAP(uint32_t, prime_desc.layers[
i].pitch[1],
1142 prime_desc.layers[
i].pitch[2]);
1143 FFSWAP(uint32_t, prime_desc.layers[
i].offset[1],
1144 prime_desc.layers[
i].offset[2]);
1154 vas = vaCreateSurfaces(dst_dev->
display, format_desc->rt_format,
1155 src->width,
src->height, &surface_id, 1,
1157 if (vas != VA_STATUS_SUCCESS)
1161 if (!use_prime2 || vas != VA_STATUS_SUCCESS) {
1163 unsigned long buffer_handle;
1164 VASurfaceAttribExternalBuffers buffer_desc;
1165 VASurfaceAttrib buffer_attrs[2] = {
1167 .type = VASurfaceAttribMemoryType,
1168 .flags = VA_SURFACE_ATTRIB_SETTABLE,
1169 .value.type = VAGenericValueTypeInteger,
1170 .value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME,
1173 .type = VASurfaceAttribExternalBufferDescriptor,
1174 .flags = VA_SURFACE_ATTRIB_SETTABLE,
1175 .value.type = VAGenericValueTypePointer,
1176 .value.value.p = &buffer_desc,
1180 buffer_handle =
desc->objects[0].fd;
1181 buffer_desc.pixel_format = va_fourcc;
1182 buffer_desc.width = src_fc->
width;
1183 buffer_desc.height = src_fc->
height;
1184 buffer_desc.data_size =
desc->objects[0].size;
1185 buffer_desc.buffers = &buffer_handle;
1186 buffer_desc.num_buffers = 1;
1187 buffer_desc.flags = 0;
1190 for (
i = 0;
i <
desc->nb_layers;
i++) {
1191 for (j = 0; j <
desc->layers[
i].nb_planes; j++) {
1192 buffer_desc.pitches[k] =
desc->layers[
i].planes[j].pitch;
1193 buffer_desc.offsets[k] =
desc->layers[
i].planes[j].offset;
1197 buffer_desc.num_planes = k;
1199 if (format_desc->chroma_planes_swapped &&
1200 buffer_desc.num_planes == 3) {
1201 FFSWAP(uint32_t, buffer_desc.pitches[1], buffer_desc.pitches[2]);
1202 FFSWAP(uint32_t, buffer_desc.offsets[1], buffer_desc.offsets[2]);
1205 vas = vaCreateSurfaces(dst_dev->
display, format_desc->rt_format,
1211 buffer_handle =
desc->objects[0].fd;
1212 buffer_desc.pixel_format = va_fourcc;
1213 buffer_desc.width = src_fc->
width;
1214 buffer_desc.height = src_fc->
height;
1215 buffer_desc.data_size =
desc->objects[0].size;
1216 buffer_desc.buffers = &buffer_handle;
1217 buffer_desc.num_buffers = 1;
1218 buffer_desc.flags = 0;
1221 for (
i = 0;
i <
desc->nb_layers;
i++) {
1222 for (j = 0; j <
desc->layers[
i].nb_planes; j++) {
1223 buffer_desc.pitches[k] =
desc->layers[
i].planes[j].pitch;
1224 buffer_desc.offsets[k] =
desc->layers[
i].planes[j].offset;
1228 buffer_desc.num_planes = k;
1230 if (format_desc->chroma_planes_swapped &&
1231 buffer_desc.num_planes == 3) {
1232 FFSWAP(uint32_t, buffer_desc.pitches[1], buffer_desc.pitches[2]);
1233 FFSWAP(uint32_t, buffer_desc.offsets[1], buffer_desc.offsets[2]);
1236 vas = vaCreateSurfaces(dst_dev->
display, format_desc->rt_format,
1241 if (vas != VA_STATUS_SUCCESS) {
1243 "object: %d (%s).\n", vas, vaErrorStr(vas));
1249 &vaapi_unmap_from_drm,
1250 (
void*)(uintptr_t)surface_id);
1256 dst->
data[3] = (uint8_t*)(uintptr_t)surface_id;
1259 "surface %#x.\n",
desc->objects[0].fd, surface_id);
1264 #if VA_CHECK_VERSION(1, 1, 0)
1281 VASurfaceID surface_id;
1283 VADRMPRIMESurfaceDescriptor va_desc;
1285 uint32_t export_flags;
1288 surface_id = (VASurfaceID)(uintptr_t)
src->data[3];
1290 export_flags = VA_EXPORT_SURFACE_SEPARATE_LAYERS;
1292 export_flags |= VA_EXPORT_SURFACE_READ_ONLY;
1294 export_flags |= VA_EXPORT_SURFACE_WRITE_ONLY;
1296 vas = vaExportSurfaceHandle(hwctx->
display, surface_id,
1297 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2,
1298 export_flags, &va_desc);
1299 if (vas != VA_STATUS_SUCCESS) {
1300 if (vas == VA_STATUS_ERROR_UNIMPLEMENTED)
1303 "%d (%s).\n", surface_id, vas, vaErrorStr(vas));
1315 for (
i = 0;
i < va_desc.num_objects;
i++) {
1319 va_desc.objects[
i].drm_format_modifier;
1321 drm_desc->
nb_layers = va_desc.num_layers;
1322 for (
i = 0;
i < va_desc.num_layers;
i++) {
1325 for (j = 0; j < va_desc.layers[
i].num_planes; j++) {
1327 va_desc.layers[
i].object_index[j];
1329 va_desc.layers[
i].offset[j];
1331 va_desc.layers[
i].pitch[j];
1336 &vaapi_unmap_to_drm_esh, drm_desc);
1342 dst->
data[0] = (uint8_t*)drm_desc;
1347 for (
i = 0;
i < va_desc.num_objects;
i++)
1348 close(va_desc.objects[
i].fd);
1354 #if VA_CHECK_VERSION(0, 36, 0)
1355 typedef struct VAAPIDRMImageBufferMapping {
1357 VABufferInfo buffer_info;
1360 } VAAPIDRMImageBufferMapping;
1366 VAAPIDRMImageBufferMapping *mapping = hwmap->
priv;
1367 VASurfaceID surface_id;
1370 surface_id = (VASurfaceID)(uintptr_t)hwmap->
source->
data[3];
1377 vas = vaReleaseBufferHandle(hwctx->
display, mapping->image.buf);
1378 if (vas != VA_STATUS_SUCCESS) {
1380 "handle of image %#x (derived from surface %#x): "
1381 "%d (%s).\n", mapping->image.buf, surface_id,
1382 vas, vaErrorStr(vas));
1385 vas = vaDestroyImage(hwctx->
display, mapping->image.image_id);
1386 if (vas != VA_STATUS_SUCCESS) {
1388 "derived from surface %#x: %d (%s).\n",
1389 surface_id, vas, vaErrorStr(vas));
1399 VAAPIDRMImageBufferMapping *mapping =
NULL;
1400 VASurfaceID surface_id;
1404 surface_id = (VASurfaceID)(uintptr_t)
src->data[3];
1412 vas = vaDeriveImage(hwctx->
display, surface_id,
1414 if (vas != VA_STATUS_SUCCESS) {
1416 "surface %#x: %d (%s).\n",
1417 surface_id, vas, vaErrorStr(vas));
1423 if (vaapi_drm_format_map[
i].va_fourcc ==
1424 mapping->image.format.fourcc)
1429 "VAAPI format %#x.\n", mapping->image.format.fourcc);
1434 mapping->buffer_info.mem_type =
1435 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
1437 mapping->drm_desc.nb_layers =
1438 vaapi_drm_format_map[
i].nb_layer_formats;
1439 if (mapping->drm_desc.nb_layers > 1) {
1440 if (mapping->drm_desc.nb_layers != mapping->image.num_planes) {
1442 "expected format: got %d planes, but expected %d.\n",
1443 mapping->image.num_planes, mapping->drm_desc.nb_layers);
1448 for(p = 0; p < mapping->drm_desc.nb_layers; p++) {
1450 .format = vaapi_drm_format_map[
i].layer_formats[p],
1454 .offset = mapping->image.offsets[p],
1455 .pitch = mapping->image.pitches[p],
1460 mapping->drm_desc.layers[0].format =
1461 vaapi_drm_format_map[
i].layer_formats[0];
1462 mapping->drm_desc.layers[0].nb_planes = mapping->image.num_planes;
1463 for (p = 0; p < mapping->image.num_planes; p++) {
1466 .offset = mapping->image.offsets[p],
1467 .pitch = mapping->image.pitches[p],
1472 vas = vaAcquireBufferHandle(hwctx->
display, mapping->image.buf,
1473 &mapping->buffer_info);
1474 if (vas != VA_STATUS_SUCCESS) {
1476 "handle from image %#x (derived from surface %#x): "
1477 "%d (%s).\n", mapping->image.buf, surface_id,
1478 vas, vaErrorStr(vas));
1484 mapping->buffer_info.handle);
1486 mapping->drm_desc.nb_objects = 1;
1488 .fd = mapping->buffer_info.handle,
1489 .size = mapping->image.data_size,
1495 dst,
src, &vaapi_unmap_to_drm_abh,
1500 dst->
data[0] = (uint8_t*)&mapping->drm_desc;
1507 vaReleaseBufferHandle(hwctx->
display, mapping->image.buf);
1509 vaDestroyImage(hwctx->
display, mapping->image.image_id);
1519 #if VA_CHECK_VERSION(1, 1, 0)
1521 err = vaapi_map_to_drm_esh(hwfc, dst,
src,
flags);
1525 #if VA_CHECK_VERSION(0, 36, 0)
1526 return vaapi_map_to_drm_abh(hwfc, dst,
src,
flags);
1536 switch (
src->format) {
1539 return vaapi_map_from_drm(hwfc, dst,
src,
flags);
1552 return vaapi_map_to_drm(hwfc, dst,
src,
flags);
1568 if (priv->x11_display)
1569 XCloseDisplay(priv->x11_display);
1579 static void vaapi_device_log_error(
void *
context,
const char *
message)
1586 static void vaapi_device_log_info(
void *
context,
const char *
message)
1602 vaSetErrorCallback(display, &vaapi_device_log_error,
ctx);
1603 vaSetInfoCallback (display, &vaapi_device_log_info,
ctx);
1609 if (vas != VA_STATUS_SUCCESS) {
1611 "connection: %d (%s).\n", vas, vaErrorStr(vas));
1624 VADisplay display =
NULL;
1626 int try_drm, try_x11, try_all;
1634 ctx->user_opaque = priv;
1639 try_all = try_drm = try_x11 = 0;
1640 if (!strcmp(ent->
value,
"drm")) {
1642 }
else if (!strcmp(ent->
value,
"x11")) {
1651 try_drm = HAVE_VAAPI_DRM;
1652 try_x11 = HAVE_VAAPI_X11;
1656 while (!display && try_drm) {
1662 priv->
drm_fd = open(device, O_RDWR);
1664 av_log(
ctx, loglevel,
"Failed to open %s as "
1665 "DRM device node.\n", device);
1670 int n, max_devices = 8;
1675 for (n = 0; n < max_devices; n++) {
1677 "/dev/dri/renderD%d", 128 + n);
1678 priv->
drm_fd = open(path, O_RDWR);
1681 "DRM render node for device %d.\n", n);
1685 if (kernel_driver) {
1688 if (strcmp(kernel_driver->
value,
info->name)) {
1690 "with non-matching kernel driver (%s).\n",
1692 drmFreeVersion(
info);
1698 "DRM render node for device %d, "
1699 "with matching kernel driver (%s).\n",
1701 drmFreeVersion(
info);
1706 "DRM render node for device %d.\n", n);
1710 if (n >= max_devices)
1714 display = vaGetDisplayDRM(priv->
drm_fd);
1717 "from DRM device %s.\n", device);
1725 if (!display && try_x11) {
1727 priv->x11_display = XOpenDisplay(device);
1728 if (!priv->x11_display) {
1730 "%s.\n", XDisplayName(device));
1732 display = vaGetDisplay(priv->x11_display);
1735 "from X11 display %s.\n", XDisplayName(device));
1740 "X11 display %s.\n", XDisplayName(device));
1748 "device %s.\n", device);
1751 "any default device.\n");
1757 #if VA_CHECK_VERSION(0, 38, 0)
1759 vas = vaSetDriverName(display, ent->
value);
1760 if (vas != VA_STATUS_SUCCESS) {
1762 "%s: %d (%s).\n", ent->
value, vas, vaErrorStr(vas));
1763 vaTerminate(display);
1768 "supported with this VAAPI version.\n");
1786 if (src_hwctx->
fd < 0) {
1788 "device to derive a VA display from.\n");
1794 int node_type = drmGetNodeTypeFromFd(src_hwctx->
fd);
1796 if (node_type < 0) {
1798 "to refer to a DRM device.\n");
1801 if (node_type == DRM_NODE_RENDER) {
1804 render_node = drmGetRenderDeviceNameFromFd(src_hwctx->
fd);
1807 "because the device does not have an "
1808 "associated render node.\n");
1811 fd = open(render_node, O_RDWR);
1814 "because the associated render node "
1815 "could not be opened.\n");
1819 "in place of non-render DRM device.\n",
1832 if (fd != src_hwctx->
fd) {
1839 if (fd == src_hwctx->
fd) {
1847 ctx->user_opaque = priv;
1850 display = vaGetDisplayDRM(fd);