Toybrick
标题:
有关MPP外部commit解码内存的问题
[打印本页]
作者:
MadDog
时间:
2021-10-19 18:22
标题:
有关MPP外部commit解码内存的问题
我希望在MPP外部分配内存,设置到MPP中使用,结果commit的时候发生错误:could not commit buffer into external buffer group error = -4
我在外部分配内存的方法是:
struct buffer_object
{
uint32_t width;
uint32_t height;
uint32_t pitch;
uint32_t handle; //
uint32_t size; // size of the buffer
uint8_t *virtaladdress; // virtual address in user space
uint32_t fb_id; // frame buffer id
};
int device_fd = open(“/dev/dri/card0”, O_RDWR | O_CLOEXEC);
int DrmBufferAllocator::alloc_buffer_object(uint32_t width, uint32_t height, uint32_t bpp, buffer_object* bo)
{
if (-1 == device_fd)
return -1;
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 = width;
create.height = height;
create.bpp = bpp;
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;
}
uint32_t fb_id = -1;
ret = drmModeAddFB(device_fd, width, height, 24, bpp, create.pitch, create.handle, &fb_id);
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;
}
map.handle = create.handle;
ret = drmIoctl(device_fd, DRM_IOCTL_MODE_MAP_DUMB, &map);
if (ret < 0)
{
fprintf(stderr, "can not map dumb 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;
}
uint8_t *virtaladdress = (uint8_t *)mmap(0, create.size, PROT_READ | PROT_WRITE, MAP_SHARED, device_fd, map.offset);
if (virtaladdress == MAP_FAILED)
{
fprintf(stderr, "can not mmap dumb buffer (%d) %m \n", errno);
ret = errno;
drmModeRmFB(device_fd, fb_id);
memset(&destroy, 0, sizeof(drm_mode_destroy_dumb));
destroy.handle = create.handle;
drmIoctl(device_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy);
return ret;
}
memset(virtaladdress, 0xff, create.size);
bo->width = width;
bo->height = height;
bo->fb_id = fb_id;
bo->pitch = create.pitch;
bo->size = create.size;
bo->handle = create.handle;
bo->virtaladdress = virtaladdress;
}
在mpp编解码时:
MppBufferGroup decoded_frame_buff_group;
ret = mpp_buffer_group_get_external(&decoded_frame_buff_group, MPP_BUFFER_TYPE_DRM);
buffer_object bo;
ret = drm_buffer_allocator->alloc_buffer_object(1920, 1088, 16, &bo);
MppBufferInfo buf_info;
buf_info.type = MPP_BUFFER_TYPE_DRM;
buf_info.size = bo.size;
buf_info.ptr = bo.virtaladdress;
// buf_info.hnd = bo.handle;
buf_info.fd = bo.fb_id;
buf_info.index = nIdx;
ret = mpp_buffer_commit(decoded_frame_buff_group, &buf_info);
这个commit操作会出错
请问是 MppBufferInfo buf_info; 填写错误吗?
欢迎光临 Toybrick (https://t.rock-chips.com/)
Powered by Discuz! X3.3