Toybrick

有关MPP外部commit解码内存的问题

MadDog

中级会员

积分
402
楼主
发表于 2021-10-19 18:22:10    查看: 3610|回复: 0 | [复制链接]    打印 | 只看该作者
我希望在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; 填写错误吗?


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

产品中心 购买渠道 开源社区 Wiki教程 资料下载 关于Toybrick


快速回复 返回顶部 返回列表