|
8#
楼主 |
发表于 2022-12-19 11:11:52
|
只看该作者
分配dma buf 的方式:
struct drm_mode_create_dumb create = {};
struct drm_mode_map_dumb map = {};
struct drm_mode_destroy_dumb destroy = {};
memset(&create, 0, sizeof(drm_mode_create_dumb));
create.width = (size + align - 1) & (~(align - 1));
create.height = 1;
create.bpp = 8;
// create.flags = flags;
int ret = drmIoctl(device_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create);
if (ret < 0)
{
fprintf(stderr, "can not create dumb buffer (%d): %m \n", errno);
return -errno;
}
struct drm_prime_handle prime_handle;
memset(&prime_handle, 0, sizeof(struct drm_prime_handle));
prime_handle.handle = create.handle;
prime_handle.fd = -1;
prime_handle.flags = DRM_CLOEXEC | DRM_RDWR;
ret = drmIoctl(device_fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &prime_handle);
if (ret != 0)
{
fprintf(stderr, "can not create frame buffer (%d) : %m \n", errno);
ret = -errno;
memset(&destroy, 0, sizeof(drm_mode_destroy_dumb));
destroy.handle = create.handle;
drmIoctl(device_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy);
return ret;
}
其中设备打开的是:
device_fd = open("/dev/video0", O_RDWR | O_CLOEXEC); |
|