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) 91 typedef struct VAAPIFormat {
98 #define MAP(va, rt, av, swap_uv) { \ 100 VA_RT_FORMAT_ ## rt, \ 107 MAP(NV12, YUV420, NV12, 0),
108 #ifdef VA_FOURCC_I420 109 MAP(I420, YUV420, YUV420P, 0),
111 MAP(YV12, YUV420, YUV420P, 1),
112 MAP(IYUV, YUV420, YUV420P, 0),
113 MAP(422
H, YUV422, YUV422P, 0),
114 #ifdef VA_FOURCC_YV16 115 MAP(YV16, YUV422, YUV422P, 1),
117 MAP(UYVY, YUV422, UYVY422, 0),
118 MAP(YUY2, YUV422, YUYV422, 0),
119 #ifdef VA_FOURCC_Y210 120 MAP(Y210, YUV422_10, Y210, 0),
122 MAP(411
P, YUV411, YUV411P, 0),
123 MAP(422
V, YUV422, YUV440P, 0),
124 MAP(444
P, YUV444, YUV444P, 0),
125 MAP(Y800, YUV400, GRAY8, 0),
126 #ifdef VA_FOURCC_P010 127 MAP(P010, YUV420_10BPP, P010, 0),
129 MAP(BGRA, RGB32, BGRA, 0),
130 MAP(BGRX, RGB32, BGR0, 0),
132 MAP(RGBX, RGB32, RGB0, 0),
133 #ifdef VA_FOURCC_ABGR 134 MAP(ABGR, RGB32, ABGR, 0),
135 MAP(XBGR, RGB32, 0BGR, 0),
137 MAP(ARGB, RGB32, ARGB, 0),
138 MAP(XRGB, RGB32, 0RGB, 0),
139 #ifdef VA_FOURCC_X2R10G10B10 140 MAP(X2R10G10B10, RGB32_10, X2RGB10, 0),
150 if (vaapi_format_map[i].fourcc == fourcc)
151 return &vaapi_format_map[
i];
160 if (vaapi_format_map[i].pix_fmt == pix_fmt)
161 return &vaapi_format_map[
i];
177 VAImageFormat **image_format)
193 const void *hwconfig,
199 VASurfaceAttrib *attr_list =
NULL;
203 int err,
i, j, attr_count, pix_fmt_count;
210 if (vas != VA_STATUS_SUCCESS) {
212 "%d (%s).\n", vas, vaErrorStr(vas));
217 attr_list =
av_malloc(attr_count *
sizeof(*attr_list));
224 attr_list, &attr_count);
225 if (vas != VA_STATUS_SUCCESS) {
227 "%d (%s).\n", vas, vaErrorStr(vas));
233 for (i = 0; i < attr_count; i++) {
234 switch (attr_list[i].
type) {
235 case VASurfaceAttribPixelFormat:
236 fourcc = attr_list[
i].value.value.i;
244 case VASurfaceAttribMinWidth:
245 constraints->
min_width = attr_list[
i].value.value.i;
247 case VASurfaceAttribMinHeight:
248 constraints->
min_height = attr_list[
i].value.value.i;
250 case VASurfaceAttribMaxWidth:
251 constraints->
max_width = attr_list[
i].value.value.i;
253 case VASurfaceAttribMaxHeight:
254 constraints->
max_height = attr_list[
i].value.value.i;
258 if (pix_fmt_count == 0) {
270 for (i = j = 0; i < attr_count; i++) {
273 if (attr_list[i].
type != VASurfaceAttribPixelFormat)
275 fourcc = attr_list[
i].value.value.i;
281 for (k = 0; k < j; k++) {
303 for (k = 0; k < j; k++) {
329 static const struct {
334 #if !VA_CHECK_VERSION(1, 0, 0) 337 "Intel i965 (Quick Sync)",
349 "Splitted-Desktop Systems VDPAU backend for VA-API",
358 VAImageFormat *image_list =
NULL;
360 const char *vendor_string;
361 int err,
i, image_count;
365 image_count = vaMaxNumImageFormats(hwctx->
display);
366 if (image_count <= 0) {
370 image_list =
av_malloc(image_count *
sizeof(*image_list));
375 vas = vaQueryImageFormats(hwctx->
display, image_list, &image_count);
376 if (vas != VA_STATUS_SUCCESS) {
387 for (i = 0; i < image_count; i++) {
388 fourcc = image_list[
i].fourcc;
402 vendor_string = vaQueryVendorString(hwctx->
display);
414 if (strstr(vendor_string,
417 "as known nonstandard driver \"%s\", setting " 428 "nonstandard list, using standard behaviour.\n");
432 "assuming standard behaviour.\n");
455 VASurfaceID surface_id;
458 surface_id = (VASurfaceID)(uintptr_t)
data;
460 vas = vaDestroySurfaces(hwctx->
display, &surface_id, 1);
461 if (vas != VA_STATUS_SUCCESS) {
463 "%d (%s).\n", surface_id, vas, vaErrorStr(vas));
473 VASurfaceID surface_id;
485 if (vas != VA_STATUS_SUCCESS) {
487 "%d (%s).\n", vas, vaErrorStr(vas));
496 vaDestroySurfaces(hwctx->
display, &surface_id, 1);
517 VAImageFormat *expected_format;
519 VASurfaceID test_surface_id;
534 int need_pixel_format = 1;
536 if (avfc->
attributes[i].type == VASurfaceAttribMemoryType)
537 need_memory_type = 0;
538 if (avfc->
attributes[i].type == VASurfaceAttribPixelFormat)
539 need_pixel_format = 0;
553 if (need_memory_type) {
555 .type = VASurfaceAttribMemoryType,
556 .flags = VA_SURFACE_ATTRIB_SETTABLE,
557 .value.type = VAGenericValueTypeInteger,
558 .value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA,
561 if (need_pixel_format) {
563 .type = VASurfaceAttribPixelFormat,
564 .flags = VA_SURFACE_ATTRIB_SETTABLE,
565 .value.type = VAGenericValueTypeInteger,
566 .value.value.i = desc->
fourcc,
611 "user-configured buffer pool.\n");
619 "internal buffer pool.\n");
624 test_surface_id = (VASurfaceID)(uintptr_t)test_surface->
data;
631 vas = vaDeriveImage(hwctx->
display, test_surface_id, &test_image);
632 if (vas == VA_STATUS_SUCCESS) {
633 if (expected_format->fourcc == test_image.format.fourcc) {
638 "derived image format %08x does not match " 639 "expected format %08x.\n",
640 expected_format->fourcc, test_image.format.fourcc);
642 vaDestroyImage(hwctx->
display, test_image.image_id);
645 "deriving image does not work: " 646 "%d (%s).\n", vas, vaErrorStr(vas));
650 "image format is not supported.\n");
692 int i, k, sw_format_available;
694 sw_format_available = 0;
697 sw_format_available = 1;
704 if (sw_format_available) {
727 VASurfaceID surface_id;
730 surface_id = (VASurfaceID)(uintptr_t)hwmap->
source->
data[3];
734 if (vas != VA_STATUS_SUCCESS) {
736 "%#x: %d (%s).\n", surface_id, vas, vaErrorStr(vas));
741 vas = vaPutImage(hwctx->
display, surface_id, map->
image.image_id,
744 if (vas != VA_STATUS_SUCCESS) {
746 "%#x: %d (%s).\n", surface_id, vas, vaErrorStr(vas));
750 vas = vaDestroyImage(hwctx->
display, map->
image.image_id);
751 if (vas != VA_STATUS_SUCCESS) {
753 "%#x: %d (%s).\n", surface_id, vas, vaErrorStr(vas));
764 VASurfaceID surface_id;
766 VAImageFormat *image_format;
769 void *address =
NULL;
772 surface_id = (VASurfaceID)(uintptr_t)src->
data[3];
781 if (dst->
format != hwfc->
sw_format && (flags & AV_HWFRAME_MAP_DIRECT)) {
796 map->
image.image_id = VA_INVALID_ID;
798 vas = vaSyncSurface(hwctx->
display, surface_id);
799 if (vas != VA_STATUS_SUCCESS) {
801 "%#x: %d (%s).\n", surface_id, vas, vaErrorStr(vas));
815 vas = vaDeriveImage(hwctx->
display, surface_id, &map->
image);
816 if (vas != VA_STATUS_SUCCESS) {
818 "surface %#x: %d (%s).\n",
819 surface_id, vas, vaErrorStr(vas));
823 if (map->
image.format.fourcc != image_format->fourcc) {
825 "is in wrong format: expected %#08x, got %#08x.\n",
826 surface_id, image_format->fourcc, map->
image.format.fourcc);
832 vas = vaCreateImage(hwctx->
display, image_format,
834 if (vas != VA_STATUS_SUCCESS) {
836 "surface %#x: %d (%s).\n",
837 surface_id, vas, vaErrorStr(vas));
842 vas = vaGetImage(hwctx->
display, surface_id, 0, 0,
844 if (vas != VA_STATUS_SUCCESS) {
846 "surface %#x: %d (%s).\n",
847 surface_id, vas, vaErrorStr(vas));
854 vas = vaMapBuffer(hwctx->
display, map->
image.buf, &address);
855 if (vas != VA_STATUS_SUCCESS) {
857 "%#x: %d (%s).\n", surface_id, vas, vaErrorStr(vas));
870 for (i = 0; i < map->
image.num_planes; i++) {
887 if (map->
image.image_id != VA_INVALID_ID)
980 #define DRM_MAP(va, layers, ...) { \ 985 static const struct {
987 int nb_layer_formats;
989 } vaapi_drm_format_map[] = {
991 DRM_MAP(NV12, 2, DRM_FORMAT_R8, DRM_FORMAT_RG88),
993 DRM_MAP(NV12, 1, DRM_FORMAT_NV12),
994 #if defined(VA_FOURCC_P010) && defined(DRM_FORMAT_R16) 995 DRM_MAP(P010, 2, DRM_FORMAT_R16, DRM_FORMAT_RG1616),
997 DRM_MAP(BGRA, 1, DRM_FORMAT_ARGB8888),
998 DRM_MAP(BGRX, 1, DRM_FORMAT_XRGB8888),
999 DRM_MAP(
RGBA, 1, DRM_FORMAT_ABGR8888),
1000 DRM_MAP(RGBX, 1, DRM_FORMAT_XBGR8888),
1001 #ifdef VA_FOURCC_ABGR 1002 DRM_MAP(ABGR, 1, DRM_FORMAT_RGBA8888),
1003 DRM_MAP(XBGR, 1, DRM_FORMAT_RGBX8888),
1005 DRM_MAP(ARGB, 1, DRM_FORMAT_BGRA8888),
1006 DRM_MAP(XRGB, 1, DRM_FORMAT_BGRX8888),
1015 VASurfaceID surface_id = (VASurfaceID)(uintptr_t)hwmap->
priv;
1019 vaDestroySurfaces(dst_dev->
display, &surface_id, 1);
1030 VASurfaceID surface_id;
1035 unsigned long buffer_handle;
1036 VASurfaceAttribExternalBuffers buffer_desc;
1037 VASurfaceAttrib attrs[2] = {
1039 .type = VASurfaceAttribMemoryType,
1040 .flags = VA_SURFACE_ATTRIB_SETTABLE,
1041 .value.type = VAGenericValueTypeInteger,
1042 .value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME,
1045 .type = VASurfaceAttribExternalBufferDescriptor,
1046 .flags = VA_SURFACE_ATTRIB_SETTABLE,
1047 .value.type = VAGenericValueTypePointer,
1048 .value.value.p = &buffer_desc,
1054 if (
desc->nb_objects != 1) {
1056 "made from a single DRM object.\n");
1062 if (
desc->nb_layers != vaapi_drm_format_map[
i].nb_layer_formats)
1064 for (j = 0; j <
desc->nb_layers; j++) {
1065 if (
desc->layers[j].format !=
1066 vaapi_drm_format_map[i].layer_formats[j])
1069 if (j !=
desc->nb_layers)
1071 va_fourcc = vaapi_drm_format_map[
i].va_fourcc;
1081 "%08x.\n",
desc->objects[0].fd, va_fourcc);
1086 buffer_handle =
desc->objects[0].fd;
1087 buffer_desc.pixel_format = va_fourcc;
1088 buffer_desc.width = src_fc->
width;
1089 buffer_desc.height = src_fc->
height;
1090 buffer_desc.data_size =
desc->objects[0].size;
1091 buffer_desc.buffers = &buffer_handle;
1092 buffer_desc.num_buffers = 1;
1093 buffer_desc.flags = 0;
1096 for (
i = 0;
i <
desc->nb_layers;
i++) {
1097 for (j = 0; j <
desc->layers[
i].nb_planes; j++) {
1098 buffer_desc.pitches[k] =
desc->layers[
i].planes[j].pitch;
1099 buffer_desc.offsets[k] =
desc->layers[
i].planes[j].offset;
1103 buffer_desc.num_planes = k;
1105 if (format_desc->chroma_planes_swapped &&
1106 buffer_desc.num_planes == 3) {
1107 FFSWAP(uint32_t, buffer_desc.pitches[1], buffer_desc.pitches[2]);
1108 FFSWAP(uint32_t, buffer_desc.offsets[1], buffer_desc.offsets[2]);
1111 vas = vaCreateSurfaces(dst_dev->display, format_desc->rt_format,
1115 if (vas != VA_STATUS_SUCCESS) {
1117 "object: %d (%s).\n", vas, vaErrorStr(vas));
1123 &vaapi_unmap_from_drm,
1124 (
void*)(uintptr_t)surface_id);
1133 "surface %#x.\n",
desc->objects[0].fd, surface_id);
1138 #if VA_CHECK_VERSION(1, 1, 0) 1155 VASurfaceID surface_id;
1157 VADRMPRIMESurfaceDescriptor va_desc;
1159 uint32_t export_flags;
1162 surface_id = (VASurfaceID)(uintptr_t)src->
data[3];
1164 export_flags = VA_EXPORT_SURFACE_SEPARATE_LAYERS;
1166 export_flags |= VA_EXPORT_SURFACE_READ_ONLY;
1168 export_flags |= VA_EXPORT_SURFACE_WRITE_ONLY;
1170 vas = vaExportSurfaceHandle(hwctx->
display, surface_id,
1171 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2,
1172 export_flags, &va_desc);
1173 if (vas != VA_STATUS_SUCCESS) {
1174 if (vas == VA_STATUS_ERROR_UNIMPLEMENTED)
1177 "%d (%s).\n", surface_id, vas, vaErrorStr(vas));
1189 for (i = 0; i < va_desc.num_objects; i++) {
1193 va_desc.objects[
i].drm_format_modifier;
1195 drm_desc->
nb_layers = va_desc.num_layers;
1196 for (i = 0; i < va_desc.num_layers; i++) {
1199 for (j = 0; j < va_desc.layers[
i].num_planes; j++) {
1201 va_desc.layers[
i].object_index[j];
1203 va_desc.layers[
i].offset[j];
1205 va_desc.layers[
i].pitch[j];
1210 &vaapi_unmap_to_drm_esh, drm_desc);
1221 for (i = 0; i < va_desc.num_objects; i++)
1222 close(va_desc.objects[i].fd);
1228 #if VA_CHECK_VERSION(0, 36, 0) 1229 typedef struct VAAPIDRMImageBufferMapping {
1231 VABufferInfo buffer_info;
1234 } VAAPIDRMImageBufferMapping;
1240 VAAPIDRMImageBufferMapping *mapping = hwmap->
priv;
1241 VASurfaceID surface_id;
1244 surface_id = (VASurfaceID)(uintptr_t)hwmap->
source->
data[3];
1251 vas = vaReleaseBufferHandle(hwctx->
display, mapping->image.buf);
1252 if (vas != VA_STATUS_SUCCESS) {
1254 "handle of image %#x (derived from surface %#x): " 1255 "%d (%s).\n", mapping->image.buf, surface_id,
1256 vas, vaErrorStr(vas));
1259 vas = vaDestroyImage(hwctx->
display, mapping->image.image_id);
1260 if (vas != VA_STATUS_SUCCESS) {
1262 "derived from surface %#x: %d (%s).\n",
1263 surface_id, vas, vaErrorStr(vas));
1273 VAAPIDRMImageBufferMapping *mapping =
NULL;
1274 VASurfaceID surface_id;
1278 surface_id = (VASurfaceID)(uintptr_t)src->
data[3];
1286 vas = vaDeriveImage(hwctx->
display, surface_id,
1288 if (vas != VA_STATUS_SUCCESS) {
1290 "surface %#x: %d (%s).\n",
1291 surface_id, vas, vaErrorStr(vas));
1297 if (vaapi_drm_format_map[i].va_fourcc ==
1298 mapping->image.format.fourcc)
1303 "VAAPI format %#x.\n", mapping->image.format.fourcc);
1308 mapping->buffer_info.mem_type =
1309 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
1311 mapping->drm_desc.nb_layers =
1312 vaapi_drm_format_map[
i].nb_layer_formats;
1313 if (mapping->drm_desc.nb_layers > 1) {
1314 if (mapping->drm_desc.nb_layers != mapping->image.num_planes) {
1316 "expected format: got %d planes, but expected %d.\n",
1317 mapping->image.num_planes, mapping->drm_desc.nb_layers);
1322 for(p = 0; p < mapping->drm_desc.nb_layers; p++) {
1324 .format = vaapi_drm_format_map[
i].layer_formats[p],
1328 .offset = mapping->image.offsets[p],
1329 .pitch = mapping->image.pitches[p],
1334 mapping->drm_desc.layers[0].format =
1335 vaapi_drm_format_map[
i].layer_formats[0];
1336 mapping->drm_desc.layers[0].nb_planes = mapping->image.num_planes;
1337 for (p = 0; p < mapping->image.num_planes; p++) {
1340 .offset = mapping->image.offsets[p],
1341 .pitch = mapping->image.pitches[p],
1346 vas = vaAcquireBufferHandle(hwctx->
display, mapping->image.buf,
1347 &mapping->buffer_info);
1348 if (vas != VA_STATUS_SUCCESS) {
1350 "handle from image %#x (derived from surface %#x): " 1351 "%d (%s).\n", mapping->image.buf, surface_id,
1352 vas, vaErrorStr(vas));
1358 mapping->buffer_info.handle);
1360 mapping->drm_desc.nb_objects = 1;
1362 .fd = mapping->buffer_info.handle,
1363 .size = mapping->image.data_size,
1369 dst, src, &vaapi_unmap_to_drm_abh,
1381 vaReleaseBufferHandle(hwctx->
display, mapping->image.buf);
1383 vaDestroyImage(hwctx->
display, mapping->image.image_id);
1393 #if VA_CHECK_VERSION(1, 1, 0) 1395 err = vaapi_map_to_drm_esh(hwfc, dst, src, flags);
1399 #if VA_CHECK_VERSION(0, 36, 0) 1400 return vaapi_map_to_drm_abh(hwfc, dst, src, flags);
1413 return vaapi_map_from_drm(hwfc, dst, src, flags);
1426 return vaapi_map_to_drm(hwfc, dst, src, flags);
1442 if (priv->x11_display)
1443 XCloseDisplay(priv->x11_display);
1453 static void vaapi_device_log_error(
void *
context,
const char *
message)
1460 static void vaapi_device_log_info(
void *
context,
const char *
message)
1476 vaSetErrorCallback(display, &vaapi_device_log_error, ctx);
1477 vaSetInfoCallback (display, &vaapi_device_log_info, ctx);
1482 vas = vaInitialize(display, &major, &minor);
1483 if (vas != VA_STATUS_SUCCESS) {
1485 "connection: %d (%s).\n", vas, vaErrorStr(vas));
1489 "version %d.%d\n", major, minor);
1498 VADisplay display =
NULL;
1500 int try_drm, try_x11, try_all;
1513 try_all = try_drm = try_x11 = 0;
1514 if (!strcmp(ent->
value,
"drm")) {
1516 }
else if (!strcmp(ent->
value,
"x11")) {
1525 try_drm = HAVE_VAAPI_DRM;
1526 try_x11 = HAVE_VAAPI_X11;
1530 while (!display && try_drm) {
1536 priv->
drm_fd = open(device, O_RDWR);
1538 av_log(ctx, loglevel,
"Failed to open %s as " 1539 "DRM device node.\n", device);
1544 int n, max_devices = 8;
1549 for (n = 0; n < max_devices; n++) {
1551 "/dev/dri/renderD%d", 128 + n);
1552 priv->
drm_fd = open(path, O_RDWR);
1555 "DRM render node for device %d.\n", n);
1559 if (kernel_driver) {
1561 info = drmGetVersion(priv->
drm_fd);
1562 if (strcmp(kernel_driver->
value, info->name)) {
1564 "with non-matching kernel driver (%s).\n",
1566 drmFreeVersion(info);
1572 "DRM render node for device %d, " 1573 "with matching kernel driver (%s).\n",
1575 drmFreeVersion(info);
1580 "DRM render node for device %d.\n", n);
1584 if (n >= max_devices)
1588 display = vaGetDisplayDRM(priv->
drm_fd);
1591 "from DRM device %s.\n", device);
1599 if (!display && try_x11) {
1601 priv->x11_display = XOpenDisplay(device);
1602 if (!priv->x11_display) {
1604 "%s.\n", XDisplayName(device));
1606 display = vaGetDisplay(priv->x11_display);
1609 "from X11 display %s.\n", XDisplayName(device));
1614 "X11 display %s.\n", XDisplayName(device));
1622 "device %s.\n", device);
1625 "any default device.\n");
1631 #if VA_CHECK_VERSION(0, 38, 0) 1633 vas = vaSetDriverName(display, ent->
value);
1634 if (vas != VA_STATUS_SUCCESS) {
1636 "%s: %d (%s).\n", ent->
value, vas, vaErrorStr(vas));
1637 vaTerminate(display);
1642 "supported with this VAAPI version.\n");
1660 if (src_hwctx->
fd < 0) {
1662 "device to derive a VA display from.\n");
1668 int node_type = drmGetNodeTypeFromFd(src_hwctx->
fd);
1670 if (node_type < 0) {
1672 "to refer to a DRM device.\n");
1675 if (node_type == DRM_NODE_RENDER) {
1678 render_node = drmGetRenderDeviceNameFromFd(src_hwctx->
fd);
1681 "because the device does not have an " 1682 "associated render node.\n");
1685 fd = open(render_node, O_RDWR);
1688 "because the associated render node " 1689 "could not be opened.\n");
1693 "in place of non-render DRM device.\n",
1706 if (fd != src_hwctx->
fd) {
1713 if (fd == src_hwctx->
fd) {
1724 display = vaGetDisplayDRM(fd);
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
The mapped frame will be overwritten completely in subsequent operations, so the current frame data n...
static enum AVPixelFormat pix_fmt
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
VAAPI-specific data associated with a frame pool.
static enum AVPixelFormat vaapi_pix_fmt_from_fourcc(unsigned int fourcc)
This structure describes decoded (raw) audio or video data.
The driver does not support the VASurfaceAttribMemoryType attribute, so the surface allocation code w...
ptrdiff_t const GLvoid * data
static void vaapi_device_free(AVHWDeviceContext *ctx)
static int device_init(AVFormatContext *ctx, int *width, int *height, uint32_t pixelformat)
#define AV_LOG_WARNING
Something somehow does not look correct.
Memory handling functions.
VASurfaceAttrib * attributes
Set by the user to apply surface attributes to all surfaces in the frame pool.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
int width
The allocated dimensions of the frames in this pool.
static int vaapi_get_buffer(AVHWFramesContext *hwfc, AVFrame *frame)
#define FF_ARRAY_ELEMS(a)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static const VAAPIFormatDescriptor * vaapi_format_from_pix_fmt(enum AVPixelFormat pix_fmt)
static int vaapi_device_derive(AVHWDeviceContext *ctx, AVHWDeviceContext *src_ctx, AVDictionary *opts, int flags)
int max_width
The maximum size of frames in this hw_frames_ctx.
int nb_objects
Number of DRM objects making up this frame.
static const VAAPIFormatDescriptor * vaapi_format_from_fourcc(unsigned int fourcc)
API-specific header for AV_HWDEVICE_TYPE_VAAPI.
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame...
static int vaapi_transfer_data_from(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
static int vaapi_device_init(AVHWDeviceContext *hwdev)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
AVBufferPool * pool_internal
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static const VAAPIFormatDescriptor vaapi_format_map[]
static void vaapi_buffer_free(void *opaque, uint8_t *data)
static int vaapi_device_connect(AVHWDeviceContext *ctx, VADisplay display)
The mapping must be direct.
size_t size
Total size of the object.
The maximum number of layers/planes in a DRM frame.
static void vaapi_frames_uninit(AVHWFramesContext *hwfc)
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
AVDRMLayerDescriptor layers[AV_DRM_MAX_PLANES]
Array of layers in the frame.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
static int vaapi_map_frame(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
int fd
DRM PRIME fd for the object.
int nb_layers
Number of layers in the frame.
int object_index
Index of the object containing this plane in the objects array of the enclosing frame descriptor...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
VAAPI hardware pipeline configuration details.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
ptrdiff_t pitch
Pitch (linesize) of this plane.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
The mapping must be writeable.
simple assert() macros that are a bit more flexible than ISO C assert().
int nb_planes
Number of planes in the layer.
AVBufferRef * av_buffer_create(uint8_t *data, buffer_size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
VASurfaceAttrib * attributes
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
const char * match_string
int initial_pool_size
Initial size of the frame pool.
static int vaapi_map_to_memory(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
static AVBufferRef * vaapi_pool_alloc(void *opaque, buffer_size_t size)
AVFrame * source
A reference to the original source of the mapping.
AVDRMPlaneDescriptor planes[AV_DRM_MAX_PLANES]
Array of planes in this layer.
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
#define DRM_FORMAT_MOD_INVALID
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
#define MAP(va, rt, av, swap_uv)
The driver does not support surface attributes at all.
The mapping must be readable.
static int vaapi_transfer_get_formats(AVHWFramesContext *hwfc, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
AVDRMObjectDescriptor objects[AV_DRM_MAX_PLANES]
Array of objects making up the frame.
static int vaapi_map_to(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
uint64_t format_modifier
Format modifier applied to the object (DRM_FORMAT_MOD_*).
AVBufferPool * av_buffer_pool_init2(buffer_size_t size, void *opaque, AVBufferRef *(*alloc)(void *opaque, buffer_size_t size), void(*pool_free)(void *opaque))
Allocate and initialize a buffer pool with a more complex allocator.
static int vaapi_transfer_data_to(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
static void vaapi_unmap_frame(AVHWFramesContext *hwfc, HWMapDescriptor *hwmap)
VADisplay display
The VADisplay handle, to be filled by the user.
VAAPISurfaceFormat * formats
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
int min_width
The minimum size of frames in this hw_frames_ctx.
void * priv
Hardware-specific private data associated with the mapping.
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
const char * friendly_name
uint8_t * data
The data buffer.
static int vaapi_map_from(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
static int vaapi_frames_init(AVHWFramesContext *hwfc)
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
The quirks field has been set by the user and should not be detected automatically by av_hwdevice_ctx...
unsigned int driver_quirks
Driver quirks to apply - this is filled by av_hwdevice_ctx_init(), with reference to a table of known...
int ff_hwframe_map_create(AVBufferRef *hwframe_ref, AVFrame *dst, const AVFrame *src, void(*unmap)(AVHWFramesContext *ctx, HWMapDescriptor *hwmap), void *priv)
DRM-managed buffers exposed through PRIME buffer sharing.
This struct describes a set or pool of "hardware" frames (i.e.
refcounted data buffer API
enum AVPixelFormat * valid_hw_formats
A list of possible values for format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
The driver does not destroy parameter buffers when they are used by vaRenderPicture().
const VDPAUPixFmtMap * map
static int vaapi_get_image_format(AVHWDeviceContext *hwdev, enum AVPixelFormat pix_fmt, VAImageFormat **image_format)
API-specific header for AV_HWDEVICE_TYPE_DRM.
AVHWFramesInternal * internal
Private data used internally by libavutil.
static enum AVPixelFormat pix_fmts[]
static void vaapi_device_uninit(AVHWDeviceContext *hwdev)
#define flags(name, subs,...)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void * user_opaque
Arbitrary user data, to be used e.g.
static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
A reference to a data buffer.
common internal and external API header
static int ref[MAX_W *MAX_W]
int fd
File descriptor of DRM device.
static int vaapi_frames_get_constraints(AVHWDeviceContext *hwdev, const void *hwconfig, AVHWFramesConstraints *constraints)
uint32_t format
Format of the layer (DRM_FORMAT_*).
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
AVHWFrameTransferDirection
AVBufferPool * pool
A pool from which the frames are allocated by av_hwframe_get_buffer().
enum AVPixelFormat * valid_sw_formats
A list of possible values for sw_format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
ptrdiff_t offset
Offset within that object of this plane.
VAAPI connection details.
VAConfigID config_id
ID of a VAAPI pipeline configuration.
void(* free)(struct AVHWDeviceContext *ctx)
This field may be set by the caller before calling av_hwdevice_ctx_init().
const HWContextType ff_hwcontext_type_vaapi
VASurfaceID * surface_ids
The surfaces IDs of all surfaces in the pool after creation.
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
#define av_malloc_array(a, b)
#define FFSWAP(type, a, b)
AVHWDeviceInternal * internal
Private data used internally by libavutil.
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option keep it simple and lowercase description are in without and describe what they for example set the foo of the bar offset is the offset of the field in your local context
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
#define AVERROR_EXTERNAL
Generic error in an external library.
AVPixelFormat
Pixel format.
static const struct @306 vaapi_driver_quirks_table[]
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.