首页/新闻资讯/正文详情

libdrm的与VAAPI的surface转换的若干问题

发布时间:2026/11/4 13:23:40 来源:云帆数科 栏目:资讯中心
libdrm的与VAAPI的surface转换的若干问题
主要内容本章主要讲解libdrm相关使用内容主要是libdrm的与VAAPI的交互使用方法libva流程主要是使用libva的API将surface转换为drm可以接受的drm的framebuffer ID。分为旧版本和新版本。libva旧版本123surface的导出vaDeriveImage将surface转化为VAImagevaAcquireBufferHandle将surface导出为handle,并lockvaReleaseBufferHandle释放handle对象,并unlockvaDeriveImage使用vaDeriveImage 将surface导入成image.获取image的所有信息,主要是VABufferID对象为vaAcquireBufferHandle提供参数。VAStatus vaDeriveImage ( VADisplay dpy, VASurfaceID surface, VAImage *image /* out */VAImage结构体如下typedef struct _VAImage { VAImageID image_id; /* uniquely identify this image */ VAImageFormat format; VABufferID buf; /* image data buffer */ /* * Image data will be stored in a buffer of type VAImageBufferType to facilitate * data store on the server side for optimal performance. The buffer will be * created by the CreateImage function, and proper storage allocated based on the image * size and format. This buffer is managed by the library implementation, and * accessed by the client through the buffer Map/Unmap functions. */ uint16_t width; uint16_t height; uint32_t data_size; uint32_t num_planes; /* can not be greater than 3 */ /* * An array indicating the scanline pitch in bytes for each plane. * Each plane may have a different pitch. Maximum 3 planes for planar formats */ uint32_t pitches[3]; /* * An array indicating the byte offset from the beginning of the image data * to the start of each plane. */ uint32_t offsets[3]; /* The following fields are only needed for paletted formats */ int32_t num_palette_entries; /* set to zero for non-palette images */ /* * Each component is one byte and entry_bytes indicates the number of components in * each entry (eg. 3 for YUV palette entries). set to zero for non-palette images */ int32_t entry_bytes; /* * An array of ascii characters describing the order of the components within the bytes. * Only entry_bytes characters of the string are used. */ int8_t component_order[4]; /** \brief Reserved bytes for future use, must be zero */ uint32_t va_reserved[VA_PADDING_LOW]; } VAImage;vaAcquireBufferHandlevaAcquireBufferHandle可以获取对应buffer ID的相关信息。可以共给EGL OpenCL (OCL)DRM等使用信息主要是handle句柄以及mem_typemem_size信息。VAStatus vaAcquireBufferHandle(VADisplay dpy, VABufferID buf_id, VABufferInfo *buf_info);VABufferInfo 结构体作为输入和输出在DRM情况下type为VAImageBufferTypemem_type为VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM。输出为handle和mem_size。VABufferInfo 结构体如下typedef struct { /** \brief Buffer handle */ uintptr_t handle; /** \brief Buffer type (See \ref VABufferType). */ uint32_t type; /** * \brief Buffer memory type (See \ref VASurfaceAttribMemoryType). * * On input to vaAcquireBufferHandle(), this field can serve as a hint * to specify the set of memory types the caller is interested in. * On successful return from vaAcquireBufferHandle(), the field is * updated with the best matching memory type. */ uint32_t mem_type; /** \brief Size of the underlying buffer. */ size_t mem_size; /** \brief Reserved bytes for future use, must be zero */ uint32_t va_reserved[VA_PADDING_LOW]; } VABufferInfo;libva新版本新版本libva-2.1,版本号为1.1.0的导出方法主要依赖vaExportSurfaceHandle函数和VADRMPRIMESurfaceDescriptor结构体1surface的导出vaExportSurfaceHandle将surface进行export成VADRMPRIMESurfaceDescriptor结构体对象VAStatus vaExportSurfaceHandle(VADisplay dpy, VASurfaceID surface_id, uint32_t mem_type, uint32_t flags, void *descriptor)VADRMPRIMESurfaceDescriptor结构体如下typedef struct _VADRMPRIMESurfaceDescriptor { /** Pixel format fourcc of the whole surface (VA_FOURCC_*). */ uint32_t fourcc; /** Width of the surface in pixels. */ uint32_t width; /** Height of the surface in pixels. */ uint32_t height; /** Number of distinct DRM objects making up the surface. */ uint32_t num_objects; /** Description of each object. */ struct { /** DRM PRIME file descriptor for this object. */ int fd; /** Total size of this object (may include regions which are * not part of the surface). */ uint32_t size; /** Format modifier applied to this object. */ uint64_t drm_format_modifier; } objects[4]; /** Number of layers making up the surface. */ uint32_t num_layers; /** Description of each layer in the surface. */ struct { /** DRM format fourcc of this layer (DRM_FOURCC_*). */ uint32_t drm_format; /** Number of planes in this layer. */ uint32_t num_planes; /** Index in the objects array of the object containing each * plane. */ uint32_t object_index[4]; /** Offset within the object of each plane. */ uint32_t offset[4]; /** Pitch of each plane. */ uint32_t pitch[4]; } layers[4]; } VADRMPRIMESurfaceDescriptor;在调用vaExportSurfaceHandle后驱动会填充VADRMPRIMESurfaceDescriptor结构体相关的handleformat信息都会存在。drm流程在drm的API中surface ID对应的就是handledrm的API会使用handle进行操作。主要函数是drmModeAddFB2drmModeAddFB和drmModeAddFB2WithModifiers。将外部的buffer描述作为创建新的frame buffer的参数然后创建一个新的FBbuf_id 作为新的FB的对象作为新版本存在由于旧版本的局限性所以产生可新版本API可以最多支持四个图像平面buffer的参数输入。 drm_public int drmModeAddFB2(int fd, uint32_t width, uint32_t height, uint32_t pixel_format, const uint32_t bo_handles[4], const uint32_t pitches[4], const uint32_t offsets[4], uint32_t *buf_id, uint32_t flags) drmModeAddFB2WithModifiers是drmModeAddFB2调用的函数但是modifier为NULL。 drm_public int drmModeAddFB2WithModifiers(int fd, uint32_t width, uint32_t height, uint32_t pixel_format, const uint32_t bo_handles[4], const uint32_t pitches[4], const uint32_t offsets[4], const uint64_t modifier[4], uint32_t *buf_id, uint32_t flags) drmModeAddFB将外部的buffer描述作为创建新的frame buffer的参数然后创建一个新的FBbuf_id 作为新的FB的对象作为旧版本存在,但是只能描述一个平面图像的情况无法描述多个平面情况但是现代显示硬件通常存在多个硬件平面作为混合使用。所以具有局限性。 drm_public int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth, uint8_t bpp, uint32_t pitch, uint32_t bo_handle, uint32_t *buf_id)经常使用的就是drmModeAddFB2将va中的信息导出并创建一个framebuffer ID对应于va的surface实例导出NV12格式surface前提在intel上当创建一个NV12格式的surface时使用va新版本vaExportSurfaceHandle导出时参数dpyva的VADisplay对象surface_id:需要导出的suface的ID值mem_type内存类型为VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2intel上只支持这种。flags:导出为分量为单平面(理论上支持NV12,RGBX系列等可以具有多平面分量的图像格式实际上需要驱动支持)VA_EXPORT_SURFACE_READ_WRITE|VA_EXPORT_SURFACE_SEPARATE_LAYERS或者导出为合成平面(理论上支持YUY2,YVYU,UYVY,RGBX系列,等可以具有合成平面分量的图像格式实际上需要驱动支持)VA_EXPORT_SURFACE_READ_WRITE|VA_EXPORT_SURFACE_COMPOSED_LAYERS导出的结构体参数可能如下合成平面导出时如下:desc{ fourcc0x3231564E,width1920,height1080,num_objects1, num_objects[4]{ {fd0x5,size5570560,drm_format_modifier(156|2)} {0} {0} {0} } num_layers1, layers[4]{ {drm_format0x3231564E,num_planes1,object_index[4]{0},offset[4]{0},pitch[4]{1920,0,0,0}} {0} {0} {0} } }多平面导出时如下:desc{ fourcc0x3231564E,width1920,height1080,num_objects1, num_objects[4]{ {fd0x5,size5570560,drm_format_modifier(156|2)} {0} {0} {0} } num_layers2, layers[4]{ {drm_format0x3231564E,num_planes1,object_index[4]{0},offset[4]{0},pitch[4]{1920,0,0,0}} {drm_format0x3231564E,num_planes1,object_index[4]{0},offset[4]{2073600,0,0,0},pitch[4]{1920,0,0,0}} {0} {0} } }导出YUY2格式surface前提在intel上当创建一个YUY2格式的surface时使用va新版本vaExportSurfaceHandle导出时,对于YUY2格式的图像只能使用合成平面导出参数dpyva的VADisplay对象surface_id:需要导出的suface的ID值mem_type内存类型为VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2intel上只支持这种。flags:导出为合成平面(理论上支持YUY2,YVYU,UYVY,RGBX系列,等可以具有合成平面分量的图像格式实际上需要驱动支持)VA_EXPORT_SURFACE_READ_WRITE|VA_EXPORT_SURFACE_COMPOSED_LAYERS导出的结构体参数可能如下合成平面导出时结构体如下:desc{ fourcc0x32595559,width1920,height1080,num_objects1, num_objects[4]{ {fd0x5,size4177920,drm_format_modifier(156|2)} {0} {0} {0} } num_layers1, layers[4]{ {drm_format0x56595559,num_planes1,object_index[4]{0},offset[4]{0},pitch[4]{3840,0,0,0}} {0} {0} {0} } }

相关推荐

JDK11 官网下载(内含资源路径)
JDK11 官网下载(内含资源路径)

目录前言一、Oracle(甲骨文)二、JDK11下载1.JDK11下载入口2.JDK版本说明3.JDK11下载前说明4.JDK11下载总结(资源路径)前言 我们要学习 Java 语言去开发 Java 程序,就需要先下载 JDK,JDK 是 Java 开发工具包… · 2026/11/4 13:20:36

STM32L152与DRV8818双极步进电机驱动方案实战详解
STM32L152与DRV8818双极步进电机驱动方案实战详解

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views … · 2026/11/4 13:21:29

PIC18F4553 + DRV8818 步进电机控制方案详解
PIC18F4553 + DRV8818 步进电机控制方案详解

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views … · 2026/11/4 6:55:31

卒中救治管理系统架构设计与医疗信息化实践
卒中救治管理系统架构设计与医疗信息化实践

1. 卒中救治管理系统架构解析1.1 技术选型背后的医疗场景考量在急诊卒中救治场景中,时间就是生命。我们选择ASP.NET Core MVC作为后端框架,主要基于三个医疗信息化领域的特殊需求:首先,其高性能特性能够支撑急诊科室的高并发访问&… · 2026/11/4 13:23:06

五级行政区划数据实战:树形建模、清洗导入与地址选择器
五级行政区划数据实战:树形建模、清洗导入与地址选择器

简介:面向地域分析、地图服务与本地化业务开发者的全国五级行政区划数据集合,覆盖省、市、区县、乡镇及村委会层级,可解决应用中的标准行政区划编码与层级关联需求。压缩包为rar格式,共1个文件,主体是可在MySQL中创建并… · 2026/11/4 13:23:06

AutoCAD SHX字体治理:从乱码到稳定交付的工程化方案
AutoCAD SHX字体治理:从乱码到稳定交付的工程化方案

1. 为什么AutoCAD工程师还在手动复制SHX字体?——一个被低估的效率黑洞你有没有过这样的经历:打开同事发来的DWG文件,图层、线型、标注样式都对得上,可一到文字区域,满屏问号和乱码?或者在出图前最后一刻发… · 2026/11/4 13:23:06

宇树科技四足机器人高校市场策略与技术解析
宇树科技四足机器人高校市场策略与技术解析

1. 宇树科技商业现象解析2023年机器人行业最引人注目的现象之一,当属宇树科技(Unitree)以不到1亿元研发投入实现6亿元年营收的商业表现。这家专注于四足机器人研发的企业,其70%的Go1系列人形机器人产品流向高校实验室,… · 2026/11/4 13:23:06

Harness套Harness:双层架构实现Coding Agent连续70轮不崩
Harness套Harness:双层架构实现Coding Agent连续70轮不崩

1. 从"套娃"说起:Harness 套 Harness 到底在解决什么问题 第一次看到"Harness 套 Harness"这个说法,我脑子里蹦出来的画面是俄罗斯套娃——一层包一层,每层都在干自己的活。但真正跑过几轮之后才明白,这个比喻… · 2026/11/4 13:22:02

Windows Sandbox中CreateProcessAsUserW失败原因与修复方案
Windows Sandbox中CreateProcessAsUserW失败原因与修复方案

1. 这个错误不是权限问题,而是沙盒环境的“身份错位” 第一次在某跨平台系统开发中遇到 CreateProcessAsUserW failed: 2 报错时,我下意识去查 Windows 权限策略、UAC 设置、管理员组成员关系——整整花了三小时翻文档、改组策略、重装沙盒功能&#x… · 2026/11/4 13:22:02

双极步进电机控制实战:DRV8818PWPR与PIC18F86K22驱动调试
双极步进电机控制实战:DRV8818PWPR与PIC18F86K22驱动调试

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views … · 2026/11/4 3:16:49

STM32F207ZG + DRV8818PWPR 步进电机驱动实战解析
STM32F207ZG + DRV8818PWPR 步进电机驱动实战解析

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views … · 2026/11/4 6:59:29

DRV8818PWPR+dsPIC30F4013工业级双极步进电机控制方案
DRV8818PWPR+dsPIC30F4013工业级双极步进电机控制方案

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views … · 2026/11/4 7:02:38

AI辅助技术栈评估:提升研发决策效率60%
AI辅助技术栈评估:提升研发决策效率60%

1. 项目背景与核心价值技术决策一直是研发团队面临的重大挑战。随着技术生态的快速演进,技术栈的选择、维护和迭代变得愈发复杂。我们团队在过去两年里,先后经历了三次重大技术栈迁移,每次都需要投入大量人力进行技术评估和风险分析。直到去年… · 2026/11/4 0:00:17

从生成Token到直接决策:Jev如何重塑AI Agent工程实践
从生成Token到直接决策:Jev如何重塑AI Agent工程实践

1. 从"生成文字"到"拍板决策":Jev 到底在解决什么问题大多数人第一次接触大模型,脑子里建立的模型是"输入问题、输出文字"。你问它今天天气怎么样,它给你一段描述;你让它写个周报,它给你… · 2026/11/4 0:00:17

32G统一内存跑大模型:内存账、TPS实测与端云分流
32G统一内存跑大模型:内存账、TPS实测与端云分流

想在一台 32G 统一内存的小主机上把大模型跑成"日常可用",这件事我前后折腾了小半年。标题里说的这台 Mac mini M6,是我们这次讨论的目标平台,具体到手规格以实物为准;但下面这套推算方法和实测思路,对任何统… · 2026/11/4 0:00:17

双极步进电机控制实战:DRV8818PWPR与PIC18F86K22驱动调试
双极步进电机控制实战:DRV8818PWPR与PIC18F86K22驱动调试

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views … · 2026/11/4 3:16:49

STM32F207ZG + DRV8818PWPR 步进电机驱动实战解析
STM32F207ZG + DRV8818PWPR 步进电机驱动实战解析

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views … · 2026/11/4 6:59:29

DRV8818PWPR+dsPIC30F4013工业级双极步进电机控制方案
DRV8818PWPR+dsPIC30F4013工业级双极步进电机控制方案

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views … · 2026/11/4 7:02:38

了解更多?预约专属演示

我们的顾问将为您一对一讲解产品与方案

企业微信二维码