-
Notifications
You must be signed in to change notification settings - Fork 1
MPP_FormatTool
SweerItTer edited this page Feb 1, 2026
·
3 revisions
FormatTool 是 utilsCore MPP 模块的工具函数集合,提供 DRM 和 MPP 格式之间的转换功能。
- DRM 格式转 MPP 格式
- MPP 格式转 DRM 格式
- 格式配置
- 跨模块格式转换
- 显示和编码格式匹配
- 依赖: Rockchip MPP 库
- 依赖: DRM 格式定义
- 被依赖: EncoderContext、JpegEncoder 等模块
inline MppFrameFormat convertDrmToMppFormat(uint32_t drm_fmt);参数说明:
-
drm_fmt(输入): DRM 格式(如 DRM_FORMAT_NV12)
返回值: MPP 格式
所有权归属:
- 无所有权转移
注意事项:
- 使用 unordered_map 作为查找表
- 不支持的格式默认返回 MPP_FMT_YUV420SP
- 线程安全
使用例程:
// DRM NV12 转 MPP 格式
MppFrameFormat mpp_fmt = convertDrmToMppFormat(DRM_FORMAT_NV12);
printf("MPP format: 0x%x\n", mpp_fmt); // 输出: MPP_FMT_YUV420SP
// DRM RGB888 转 MPP 格式
mpp_fmt = convertDrmToMppFormat(DRM_FORMAT_RGB888);
printf("MPP format: 0x%x\n", mpp_fmt); // 输出: MPP_FMT_RGB888inline uint32_t convertMppToDrmFormat(MppFrameFormat mpp_fmt);参数说明:
-
mpp_fmt(输入): MPP 格式(如 MPP_FMT_YUV420SP)
返回值: DRM 格式
所有权归属:
- 无所有权转移
注意事项:
- 使用 unordered_map 作为查找表
- 不支持的格式默认返回 DRM_FORMAT_NV12
- 线程安全
使用例程:
// MPP YUV420SP 转 DRM 格式
uint32_t drm_fmt = convertMppToDrmFormat(MPP_FMT_YUV420SP);
printf("DRM format: 0x%x\n", drm_fmt); // 输出: DRM_FORMAT_NV12
// MPP RGB888 转 DRM 格式
drm_fmt = convertMppToDrmFormat(MPP_FMT_RGB888);
printf("DRM format: 0x%x\n", drm_fmt); // 输出: DRM_FORMAT_RGB888| DRM 格式 | MPP 格式 |
|---|---|
| DRM_FORMAT_NV12 | MPP_FMT_YUV420SP |
| DRM_FORMAT_NV21 | MPP_FMT_YUV420SP |
| DRM_FORMAT_YUV420 | MPP_FMT_YUV420P |
| DRM_FORMAT_YVU420 | MPP_FMT_YUV420P |
| DRM_FORMAT_NV16 | MPP_FMT_YUV422SP |
| DRM_FORMAT_NV61 | MPP_FMT_YUV422SP |
| DRM_FORMAT_YUYV | MPP_FMT_YUV422_YUYV |
| DRM_FORMAT_UYVY | MPP_FMT_YUV422_UYVY |
| DRM_FORMAT_RGB565 | MPP_FMT_RGB565 |
| DRM_FORMAT_BGR565 | MPP_FMT_BGR565 |
| DRM_FORMAT_RGB888 | MPP_FMT_RGB888 |
| DRM_FORMAT_BGR888 | MPP_FMT_BGR888 |
| DRM_FORMAT_ARGB8888 | MPP_FMT_ARGB8888 |
| DRM_FORMAT_ABGR8888 | MPP_FMT_ABGR8888 |
| MPP 格式 | DRM 格式 |
|---|---|
| MPP_FMT_YUV420SP | DRM_FORMAT_NV12 |
| MPP_FMT_YUV420P | DRM_FORMAT_YUV420 |
| MPP_FMT_YUV422SP | DRM_FORMAT_NV16 |
| MPP_FMT_YUV422_YUYV | DRM_FORMAT_YUYV |
| MPP_FMT_YUV422_UYVY | DRM_FORMAT_UYVY |
| MPP_FMT_RGB565 | DRM_FORMAT_RGB565 |
| MPP_FMT_BGR565 | DRM_FORMAT_BGR565 |
| MPP_FMT_RGB888 | DRM_FORMAT_RGB888 |
| MPP_FMT_BGR888 | DRM_FORMAT_BGR888 |
| MPP_FMT_ARGB8888 | DRM_FORMAT_ARGB8888 |
| MPP_FMT_ABGR8888 | DRM_FORMAT_ABGR8888 |
// 获取显示格式(DRM)
uint32_t drm_fmt = get_drm_format_from_display();
// 转换为 MPP 格式用于编码
MppFrameFormat mpp_fmt = convertDrmToMppFormat(drm_fmt);
// 配置编码器
encoder_config.format = mpp_fmt;// 获取编码格式(MPP)
MppFrameFormat mpp_fmt = encoder_config.format;
// 转换为 DRM 格式用于显示
uint32_t drm_fmt = convertMppToDrmFormat(mpp_fmt);
// 配置显示层
drm_layer->format = drm_fmt;// 验证 DRM 格式是否支持
uint32_t drm_fmt = DRM_FORMAT_NV12;
MppFrameFormat mpp_fmt = convertDrmToMppFormat(drm_fmt);
if (mpp_fmt == MPP_FMT_YUV420SP) {
printf("Format supported\n");
}std::vector<uint32_t> drm_formats = {
DRM_FORMAT_NV12,
DRM_FORMAT_YUV420,
DRM_FORMAT_RGB888,
DRM_FORMAT_ARGB8888
};
for (auto drm_fmt : drm_formats) {
MppFrameFormat mpp_fmt = convertDrmToMppFormat(drm_fmt);
printf("DRM 0x%x -> MPP 0x%x\n", drm_fmt, mpp_fmt);
}// 尝试获取 DRM 格式
uint32_t drm_fmt = get_preferred_drm_format();
// 转换为 MPP 格式
MppFrameFormat mpp_fmt = convertDrmToMppFormat(drm_fmt);
// 如果转换失败,使用默认格式
if (mpp_fmt == MPP_FMT_YUV420SP && drm_fmt != DRM_FORMAT_NV12) {
printf("Using default format\n");
}- 默认格式: 不支持的格式默认返回 MPP_FMT_YUV420SP / DRM_FORMAT_NV12
- 查找表: 使用 static unordered_map 作为查找表,首次调用时初始化
- 线程安全: 函数是线程安全的
- 格式映射: 某些 DRM 格式映射到相同的 MPP 格式(如 NV12 和 NV21)
- 性能: 使用 unordered_map 查找,性能较好
- 格式支持: 只支持常用格式,不支持所有格式
- EncoderContext - 编码器上下文
- JpegEncoder - JPEG 编码器
- StreamWriter - 流写入器
- MPP 模块总览
主页
API 文档
DMA 模块
DRM 模块
- DRM 模块总览
- DeviceController - DRM 设备控制器
- DrmLayer - DRM 图层管理
- PlanesCompositor - DRM 平面合成器
- DrmBpp - DRM 格式定义
NET 模块
- NET 模块总览
- TcpServer - TCP 服务器
- SocketConnection - Socket 连接管理
- CommandHandler - 命令处理器
- DataPacket - 数据包
V4L2 模块
- V4L2 模块总览
- CameraController - V4L2 摄像头控制器
- Frame - V4L2 帧数据结构
- FormatTool - V4L2 格式工具
- Exception - V4L2 异常类
V4L2Param 模块
- V4L2Param 模块总览
- ParamControl - 参数控制
- ParamLogger - 参数日志
- ParamProcessor - 参数处理器
RGA 模块
- RGA 模块总览
- RgaConverter - RGA 转换器
- RgaProcessor - RGA 处理器
- FormatTool - RGA 格式工具
MPP 模块
- MPP 模块总览
- EncoderContext - 编码器上下文
- EncoderCore - 编码器核心
- JpegEncoder - JPEG 编码器
- StreamWriter - 流写入器
- MppResourceGuard - MPP 资源守护
- FileTools - 文件工具
- FormatTool - 格式工具
Sys 模块
- Sys 模块总览
- CpuMonitor - CPU 监控器
- MemoryMonitor - 内存监控器
- Base - 基础类
Mouse 模块
- Mouse 模块总览
- Watcher - 鼠标监视器
Utils 模块
- Utils 模块总览
- AsyncThreadPool - 异步线程池
- ConcurrentQueue - 并发队列
- FdWrapper - 文件描述符包装器
- FenceWatcher - 围栏监视器
- FixedSizePool - 固定大小对象池
- Logger - 日志记录器
- ObjectsPool - 对象池
- OrderedQueue - 有序队列
- ProgressBar - 进度条
- SafeQueue - 安全队列
- SharedBufferState - 共享缓冲区状态
- SimpleVariant - 简单变体类型
- ThreadPauser - 线程暂停器
- ThreadUtils - 线程工具
- Types - 类型定义
- UdevMonitor - Udev 监视器