5.9. 区域处理 - OSD
5.9.1. 模块描述
OSD( On-Screen Display )模块
视频
图像增强:对 实时 视频 或 静态 图像 叠加 特定 区域 的 标注、信息 展示。 隐私
保护:通过 叠加 马赛克 或 遮挡 区域,对 特定 区域 进行 模糊 处理 或 遮盖,保护 敏感 信息。
因为 OSD 属于 VSE 的
5.9.1.1. 基础规格
OSD 支持
填色、绘制 点 线 和 文字、马赛克 等 功能 绘制
文字 支持 点阵 16x16 的 HZK16 中 文字 库 和 点阵 16x8 的 ASC16 英文 字库 OSD 中
叠加 Region 的 宽度 为 32 的 倍数 , 高度 为 偶数 , 最小 size 为 32x2 支持
叠加 区域 数据格式 VGA_8 , colormap 支持 16 种 每个 OSD 支持 8 个
面积 大小 2x2 到 256x256 直方图 统计 区域 VSE 硬件
支持 OSD 功能 , 除 通道 4 外 , 其他 通道 均 支持 OSD, 最大 支持 4 个 区域 , 软件 OSD 最 多 支持 255 个 区域 OSD 使用
时 需要 与 VSE 输出 通道 绑定,每路 VSE 输出 通道 对应 OSD 功能 支持 情况 如下:
| vse 输出 |
硬件 OSD 叠加 |
软件 OSD 叠加 |
|---|---|---|
| 0 | 支持 | 支持 |
| 1 | 支持 | 支持 |
| 2 | 支持 | 支持 |
| 3 | 支持 | 支持 |
| 4 | 不 |
支持 |
| 5 | 支持 | 支持 |
备注:
VSE 通道 4 默认

VSE 的
输入 通道( Ichn0 )的 数据源 来自 两种 方式,一种 VFLOW 的 方式,另 一种 是 回灌 的 方式。 region buf 通过
hbn_rgn_create创建,使用hbn_rgn_attach_to_chn将创建 好 的 region buf 绑定 到 VSE 的 指定 通道 上。 OSD 绑定
到 VSE 的 指定 的 输出 通道( Ochnx)以后, OSD 硬件 会 自动 把 region buf 的 数据 叠加 到 经过 VSE 的 视频 帧 上。 VSE 的
输出 通道 4 ( Ochn4 ) 不 支持 OSD,默认 使用 NEON 实现 OSD 叠加 功能。 VSE 的
输出 通道 超过 4 个 Region 时,超出 4 个 Region 的 部分 使用 软件 NEON 指令集 操作 图像 数据 完成。
5.9.1.2. 注意事项
区域
左图

OSD 支持
OVERLAY: 叠加
区域 , 可以 在 矩形 区域 自行 填充 内容 , 例如 写 字画 线。 COVER: 遮挡
区域 , 纯色 块 , 支持 矩形 和 多边形,不 支持 圆形。 MOSAIC: 马赛克
区域 , 矩形 区域 以 马赛克 形式 遮挡。
5.9.2. 参考示例
OSD 部分
示例 代码 可以 参考 sample_osd 章节
5.9.3. API 参考
| API 接口 | 接口 |
|---|---|
| hbn_rgn_create | 区域 |
| hbn_rgn_destroy | 区域 |
| hbn_rgn_getattr | 获取 |
| hbn_rgn_setattr | 设置 |
| hbn_rgn_setbitmap | 设置 |
| hbn_rgn_attach_to_chn | 叠加 |
| hbn_rgn_detach_from_chn | 解除 |
| hbn_rgn_set_displayattr | 设置 |
| hbn_rgn_get_displayattr | 获取 |
| hbn_rgn_draw_word | 在 buffer 中 |
| hbn_rgn_draw_line | 在 buffer 中 |
| hbn_rgn_set_colormap | 设置 osd 颜色 |
| hbn_rgn_get_sta | 获取 |
| hbn_rgn_set_sta | 设置 |
5.9.3.1. hbn_rgn_create()
【函数声明】
int32_t hbn_rgn_create(hbn_rgn_handle_t handle, const hbn_rgn_attr_t *region)
【参数描述】
[IN] hbn_rgn_handle_t handle: region handle,是 region 的
唯一 标识,最大值 不能 超过 255 。 [IN] hbn_rgn_attr_t region: region 区域
属性。
【返回值】
成功: HBN_STATUS_SUCESS 0 。
失败:异常
为 负值 错误码,参考 返回值 说明 。
【功能描述】
用于
【注意事项】
无
5.9.3.2. hbn_rgn_destroy
【函数声明】
int32_t hbn_rgn_destroy(hbn_rgn_handle_t handle)
【参数描述】
[IN] hbn_rgn_handle_t handle: region handle,是 region 的
唯一 标识,最大值 不能 超过 255 。
【返回值】
成功: HBN_STATUS_SUCESS 0 。
失败:异常
为 负值 错误码,参考 返回值 说明 。
【功能描述】
用于
【注意事项】
无
5.9.3.3. hbn_rgn_getattr
【函数声明】
int32_t hbn_rgn_getattr(hbn_rgn_handle_t handle, hbn_rgn_attr_t *region)
【参数描述】
[IN] hbn_rgn_handle_t handle: region handle,是 region 的
唯一 标识,最大值 不能 超过 255 。 [IN] hbn_rgn_attr_t *region: region 区域
属性。
【返回值】
成功: HBN_STATUS_SUCESS 0 。
失败:异常
为 负值 错误码,参考 返回值 说明 。
【功能描述】
用于
【注意事项】
无
5.9.3.4. hbn_rgn_setattr
【函数声明】
int32_t hbn_rgn_setattr(hbn_rgn_handle_t handle, const hbn_rgn_attr_t *region)
【参数描述】
[IN] hbn_rgn_handle_t handle: region handle,是 region 的
唯一 标识,最大值 不能 超过 255 。 [IN] hbn_rgn_attr_t *region:区域
属性。
【返回值】
成功: HBN_STATUS_SUCESS 0 。
失败:异常
为 负值 错误码,参考 返回值 说明 。
【功能描述】
用于
【注意事项】
无
5.9.3.5. hbn_rgn_setbitmap
【函数声明】
int32_t hbn_rgn_setbitmap(hbn_rgn_handle_t handle, const hbn_rgn_bitmap_t *bitmap_attr)
【参数描述】
[IN] hbn_rgn_handle_t handle: region handle,是 region 的
唯一 标识,最大值 不能 超过 255 。 [IN] hbn_rgn_bitmap_t *bitmap_attr:区域 buffer 属性。
【返回值】
成功: HBN_STATUS_SUCESS 0 。
失败:异常
为 负值 错误码,参考 返回值 说明 。
【功能描述】
在
【注意事项】
无
5.9.3.6. hbn_rgn_attach_to_chn
【函数声明】
int32_t hbn_rgn_attach_to_chn(hbn_rgn_handle_t handle,hbn_vnode_handle_t vnode_fd, int32_t chnid, const hbn_rgn_chn_attr_t *rgn_chn)
【参数描述】
[IN] hbn_rgn_handle_t handle: region handle,是 region 的
唯一 标识,最大值 不能 超过 255 。 [IN] hbn_vnode_handle_t vnode_fd:要
绑定 到 的 VSE handle,通过 hbn_vflow_get_vnode_handle() 获取。 [IN] int32_t chnid:要
绑定 到 的 VSE 的 channel id。 [IN] hbn_rgn_chn_attr_t *rgn_chn:区域
叠加 在 通道 上 的 显示 属性。
【返回值】
成功: HBN_STATUS_SUCESS 0 。
失败:异常
为 负值 错误码,参考 返回值 说明 。。
【功能描述】
用于
【注意事项】
VSE 的
5.9.3.7. hbn_rgn_detach_from_chn
【函数声明】
int32_t hbn_rgn_detach_from_chn(hbn_rgn_handle_t handle,hbn_vnode_handle_t vnode_fd, int32_t chnid)
【参数描述】
[IN] hbn_rgn_handle_t handle: region handle,是 region 的
唯一 标识,最大值 不能 超过 255 。 [IN] hbn_vnode_handle_t vnode_fd:要解
绑 的 VSE handle,通过 hbn_vflow_get_vnode_handle() 获取。 [IN] int32_t chnid:要解
绑 到 的 VSE 的 channel id。
【返回值】
成功: HBN_STATUS_SUCESS 0 。
失败:异常
为 负值 错误码,参考 返回值 说明 。
【功能描述】
用于
【注意事项】
无
5.9.3.8. hbn_rgn_set_displayattr
【函数声明】
int32_t hbn_rgn_set_displayattr(hbn_rgn_handle_t handle, hbn_vnode_handle_t vnode_fd, int32_t chnid, const hbn_rgn_chn_attr_t *rgn_chn)
【参数描述】
[IN] hbn_rgn_handle_t handle: region handle,是 region 的
唯一 标识,最大值 不能 超过 255 。 [IN] hbn_vnode_handle_t vnode_fd:要
操作 的 VSE handle,通过 hbn_vflow_get_vnode_handle() 获取。 [IN] int32_t chnid:要
操作 的 VSE 的 channel id。 [IN] hbn_rgn_chn_attr_t *rgn_chn:区域
叠加 在 通道 上 的 显示 属性。
【返回值】
成功: HBN_STATUS_SUCESS 0 。
失败:异常
为 负值 错误码,参考 返回值 说明 。
【功能描述】
在
【注意事项】
无
5.9.3.9. hbn_rgn_get_displayattr
【函数声明】
int32_t hbn_rgn_get_displayattr(hbn_rgn_handle_t handle, hbn_vnode_handle_t vnode_fd, int32_t chnid, const hbn_rgn_chn_attr_t *rgn_chn)
【参数描述】
[IN] hbn_rgn_handle_t handle: region handle,是 region 的
唯一 标识,最大值 不能 超过 255 。 [IN] hbn_vnode_handle_t vnode_fd:要
操作 的 VSE handle,通过 hbn_vflow_get_vnode_handle() 获取。 [IN] int32_t chnid:要
操作 的 VSE 的 channel id。 [IN] hbn_rgn_chn_attr_t *rgn_chn:区域
叠加 在 通道 上 的 显示 属性。
【返回值】
成功: HBN_STATUS_SUCESS 0 。
失败:异常
为 负值 错误码,参考 返回值 说明 。
【功能描述】
在
【注意事项】
无
5.9.3.10. hbn_rgn_draw_word
【函数声明】
int32_t hbn_rgn_draw_word(const hbn_rgn_draw_word_t *draw_word)
【参数描述】
[IN] hbn_rgn_draw_word_t *draw_word:画
字 的 属性。
【返回值】
成功: HBN_STATUS_SUCESS 0 。
失败:异常
为 负值 错误码,参考 返回值 说明 。
【功能描述】
在
【注意事项】
无
5.9.3.11. hbn_rgn_draw_line
【函数声明】
int32_t hbn_rgn_draw_line(const hbn_rgn_draw_line_t \*draw_line)
【参数描述】
[IN] hbn_rgn_draw_line_t *draw_line:画线
的 属性。
【返回值】
成功: HBN_STATUS_SUCESS 0 。
失败:异常
为 负值 错误码,参考 返回值 说明 。
【功能描述】
在
【注意事项】
无
5.9.3.12. hbn_rgn_set_colormap
【函数声明】
int32_t hbn_rgn_set_colormap(uint32_t color_map[16])
【参数描述】
[IN] uint32_t color_map[16]:要
设置 的 新 的 color_map。
【返回值】
成功: HBN_STATUS_SUCESS 0 。
失败:异常
为 负值 错误码,参考 返回值 说明 。
【功能描述】
设置
【注意事项】
新
5.9.3.13. hbn_rgn_set_sta
【函数声明】
int32_t hbn_rgn_set_sta(hbn_vnode_handle_t vnode_fd, int32_t chnid,uint8_t sta_level[3], hbn_rgn_sta_t sta_attr[8]);
【参数描述】
[IN] hbn_vnode_handle_t vnode_fd:要
操作 的 VSE handle,通过 hbn_vflow_get_vnode_handle() 获取。 [IN] int32_t chnid:要
操作 的 VSE 的 channel id。 [IN] uint8_t sta_level[3]:统计
值 阈值,需要 按照 从小到大 的 顺序 配置 3 个 参数,参数 范围 为 1 到 254 。 [IN] hbn_rgn_sta_t sta_attr[8]:统计
值 区域 的 属性,为 区域 的 位置 信息。
【返回值】
成功: HBN_STATUS_SUCESS 0 。
失败:异常
为 负值 错误码,参考 返回值 说明 。
【功能描述】
设置
【注意事项】
每次
5.9.3.14. hbn_rgn_get_sta
【函数声明】
int32_t hbn_rgn_get_sta(hbn_vnode_handle_t vnode_fd, int32_t chnid, uint16_t sta_value[8][4])
【参数描述】
[IN] hbn_vnode_handle_t vnode_fd:要
操作 的 VSE handle,通过 hbn_vflow_get_vnode_handle() 获取。 [IN] int32_t chnid:要
操作 的 VSE 的 channel id。 [OUT] uint16_t sta_value[8][4]:统计
值 数据,获取 区域 使能 位置 的 统计 值。
【返回值】
成功: HBN_STATUS_SUCESS 0 。
失败:异常
为 负值 错误码,参考 返回值 说明 。
【功能描述】
获取
【注意事项】
无。
5.9.4. 参数说明
typedef enum hbn_rgn_type_e hbn_rgn_type_t
| 名称 | 类型 | 最小值 | 最大值 | 默认值 | 含义 | 必选 |
|---|---|---|---|---|---|---|
| OVERLAY_RGN | - | - | - | - | 覆盖 |
- |
| COVER_RGN | - | - | - | - | 遮盖 |
- |
| MOSAIC_RGN | - | - | - | - | 马赛克 |
- |
| RGN_TYPE_MAX | - | - | - | - | 最大 |
- |
typedef enum hbn_rgn_font_size_e hbn_rgn_font_size_t
| 名称 | 类型 | 最小值 | 最大值 | 默认值 | 含义 | 必选 |
|---|---|---|---|---|---|---|
| FONT_SIZE_SMALL | - | - | - | - | 小字 |
- |
| FONT_SIZE_MEDIUM | - | - | - | - | 中 |
- |
| FONT_SIZE_LARGE | - | - | - | - | 大 |
- |
| FONT_SIZE_EXTRA_LARGE | - | - | - | - | 超大 |
- |
typedef enum hbn_rgn_font_color_e hbn_rgn_font_color_t
| 名称 | 类型 | 最小值 | 最大值 | 默认值 | 含义 | 必选 |
|---|---|---|---|---|---|---|
| FONT_COLOR_WHITE | - | - | - | - | 白色 | - |
| FONT_COLOR_BLACK | - | - | - | - | 黑色 | - |
| FONT_COLOR_GREY | - | - | - | - | 灰色 | - |
| FONT_COLOR_BLUE | - | - | - | - | 蓝色 | - |
| FONT_COLOR_GREEN | - | - | - | - | 绿色 | - |
| FONT_COLOR_RED | - | - | - | - | 红色 | - |
| FONT_COLOR_CYAN | - | - | - | - | 青色 | - |
| FONT_COLOR_PURPLE | - | - | - | - | 紫色 | - |
| FONT_COLOR_YELLOW | - | - | - | - | 黄色 | - |
| FONT_COLOR_ORANGE | - | - | - | - | 橙色 | - |
| FONT_COLOR_BROWN | - | - | - | - | 棕色 | - |
| FONT_COLOR_PINK | - | - | - | - | 粉色 | - |
| FONT_COLOR_DARKBLUE | - | - | - | - | 深蓝色 | - |
| FONT_COLOR_DARKGREEN | - | - | - | - | 深绿色 | - |
| FONT_COLOR_DARKRED | - | - | - | - | 深红色 | - |
| FONT_COLOR_DARKGRAY | - | - | - | - | 深灰色 | - |
| FONT_KEY_COLOR_NUM | - | - | - | - | 颜色 |
- |
typedef enum hbn_rgn_pixel_format_e hbn_rgn_pixel_format_t
| 名称 | 类型 | 最小值 | 最大值 | 默认值 | 含义 | 必选 |
|---|---|---|---|---|---|---|
| PIXEL_FORMAT_VGA_8 | - | - | - | - | 8bit 颜色 /alpha 数据格式 | - |
| PIXEL_FORMAT_YUV420SP | - | - | - | - | YUV420SP 数据格式(暂时 |
- |
typedef enum hbn_rgn_cover_type_e hbn_rgn_cover_type_t
| 名称 | 类型 | 最小值 | 最大值 | 默认值 | 含义 | 必选 |
|---|---|---|---|---|---|---|
| COVER_RECT | - | - | - | - | 矩形 | - |
| COVER_POLYGON | - | - | - | - | 多边形 | - |
typedef struct hbn_rgn_size_s hbn_rgn_size_t
| 名称 | 类型 | 最小值 | 最大值 | 默认值 | 含义 | 必选 |
|---|---|---|---|---|---|---|
| width | uint32_t | - | - | - | 宽 | - |
| height | uint32_t | - | - | - | 高 | - |
struct hbn_rgn_point_s hbn_rgn_point
| 名称 | 类型 | 最小值 | 最大值 | 默认值 | 含义 | 必选 |
|---|---|---|---|---|---|---|
| x | uint32_t | - | - | - | x 坐标 | - |
| y | uint32_t | - | - | - | y 坐标 | - |
typedef struct hbn_ren_overlay_s hbn_rgn_overlay_t
| 名称 | 类型 | 最小值 | 最大值 | 默认值 | 含义 | 必选 |
|---|---|---|---|---|---|---|
| pixel_fmt | hbn_rgn_pixel_format_t | - | - | - | 数据格式 |
是 |
| size | hbn_rgn_size_t | - | - | - | 尺寸 |
是 |
| 高度 |
struct hbn_rgn_polygon_s hbn_rgn_polygon
| 名称 | 类型 | 最小值 | 最大值 | 默认值 | 含义 | 必选 |
|---|---|---|---|---|---|---|
| side_num | hbn_rgn_pixel_format_t | 0 | POLYGON_MAX_SIDE | - | 多边形 |
是 |
| vertex[POLYGON_MAX_SIDE] | hbn_rgn_point_t | - | - | - | 多边形 |
是 |
struct hbn_rgn_cover_attr_s hbn_rgn_cover
| 名称 | 类型 | 最小值 | 最大值 | 默认值 | 含义 | 必选 |
|---|---|---|---|---|---|---|
| cover_type | hbn_rgn_cover_type_t | - | - | - | 遮盖 |
是 |
| - | union( size polygon) | - | - | - | 矩形 |
是 |
| 矩形 |
是 |
struct hbn_rgn_mosaic_attr_s hbn_rgn_mosaic
| 名称 | 类型 | 最小值 | 最大值 | 默认值 | 含义 | 必选 |
|---|---|---|---|---|---|---|
| size | hbn_rgn_size_t | - | - | - | 需要 |
是 |
| pixel_block | uint32_t | - | - | - | 暂时 |
否 |
struct hbn_rgn_attr_s hbn_rgn_attr
| 名称 | 类型 | 最小值 | 最大值 | 默认值 | 含义 | 必选 |
|---|---|---|---|---|---|---|
| type | hbn_rgn_type_t | OVERLAY_RGN | MOSAIC_RGN | - | 区域 |
是 |
| alpha | uint32_t | 0 | 15 | - | alpha 混合 |
否 |
| color | hbn_rgn_font_color_t | FONT_COLOR_WHITE | FONT_COLOR_DARKGRAY | - | 颜色 | 是 |
| overlay_attr | hbn_rgn_overlay_t | - | - | - | 叠加 |
是 |
| cover_attr | hbn_rgn_cover_t | - | - | - | 遮盖 |
是 |
| mosaic_chn | hbn_rgn_mosaic_t | - | - | - | 马赛克 |
否 |
struct hbn_rgn_chn_attr_s hbn_rgn_chn_attr
| 名称 | 类型 | 最小值 | 最大值 | 默认值 | 含义 | 必选 |
|---|---|---|---|---|---|---|
| show | bool | - | - | - | 是否 |
是 |
| invert_en | bool | - | - | - | 是否 |
否 |
| display_level | uint32_t | 0 | 3 | 0 | 显示 level,硬件 osd 时 |
是 |
| 目前 |
||||||
| point | hbn_rgn_point_t | - | - | - | 坐标 |
是 |
struct hbn_rgn_bitmap_attr_s hbn_rgn_bitmap
| 名称 | 类型 | 最小值 | 最大值 | 默认值 | 含义 | 必选 |
|---|---|---|---|---|---|---|
| pixel_fmt | hbn_rgn_pixel_format_t | - | - | - | 数据格式 |
是 |
| size | hbn_rgn_size_t | - | - | - | 尺寸 |
是 |
| *paddr | void | - | - | - | 要 |
是 |
struct hbn_rgn_draw_word_param_s hbn_rgn_draw_word
| 名称 | 类型 | 最小值 | 最大值 | 默认值 | 含义 | 必选 |
|---|---|---|---|---|---|---|
| *paddr | void | - | - | - | 画布 |
是 |
| size | hbn_rgn_size_t | - | - | - | 画布 |
是 |
| *draw_string | uint8_t | - | - | - | 画 |
是 |
| 支持 |
||||||
| font_color | hbn_rgn_font_color_t | 0 | FONT_COLOR_DARKGRAY | - | 字体 |
是 |
| bg_color | uint32_t | 0 | FONT_COLOR_DARKGRAY | - | 背景 |
是 |
| alpha | uint32_t | 0 | 15 | - | alpha 混合 index, 0 为 |
是 |
| font_size | hbn_rgn_font_size_t | - | - | - | 字体大小 | 是 |
| flush_en | bool | - | - | - | 是否 |
是 |
typedef struct hbn_rgn_draw_line_param_s hbn_rgn_draw_line_t
| 名称 | 类型 | 最小值 | 最大值 | 默认值 | 含义 | 必选 |
|---|---|---|---|---|---|---|
| *paddr | void | - | - | - | 要 |
是 |
| size | hbn_rgn_size_t | - | - | - | 画布 |
是 |
| start_point | hbn_rgn_point_t | - | - | - | 画线 |
是 |
| end_point | hbn_rgn_point_t | - | - | - | 画线 |
是 |
| thick | uint32_t | - | - | - | 线宽 | 是 |
| color | hbn_rgn_font_color_t | FONT_COLOR_WHITE | FONT_COLOR_DARKGRAY | - | 画线 |
是 |
| bg_color | uint32_t | FONT_COLOR_WHITE | FONT_COLOR_DARKGRAY | - | 背景 |
是 |
| alpha | uint32_t | 0 | 15 | - | 背景 |
是 |
| flush_en | bool | - | - | - | 是否 |
是 |
typedef struct hbn_rgn_sta_attr_s hbn_rgn_sta_t
| 名称 | 类型 | 最小值 | 最大值 | 默认值 | 含义 | 必选 |
|---|---|---|---|---|---|---|
| sta_en | uint8_t | - | - | - | 是否 |
是 |
| start_x | uint16_t | - | - | - | 起始 |
是 |
| start_y | uint16_t | - | - | - | 起始 |
是 |
| width | uint16_t | 2 | 255 | - | 统计 |
是 |
| height | uint16_t | 2 | 255 | - | 统计 |
是 |