5544
- 收藏
- 点赞
- 分享
- 举报
Hi3516a osd 刷新Out of memory问题
我最近在做海思3516a的osd菜单,就像电视机上的频道选择,音量控制那样。
采用的方案是SDL+freetype+SDL_ttf。
osd的刷新放在一个线程中,osd的菜单层次改变,字符串改变,颜色改变放在其他线程中。
下面这段代码是osd刷新的线程。
void *monitor_thread(void *arg)
{
HI_S32 s32Ret;
RGN_ATTR_S stRgnAttrSet[RGN_MAX];
RGN_CHN_ATTR_S stChnAttr[RGN_MAX];
stChn.enModId = HI_ID_VPSS;
stChn.s32DevId = 0;
stChn.s32ChnId = 0;
BITMAP_S stBitmap[RGN_MAX];
TTF_Font *font;
SDL_PixelFormat *fmt;
SDL_Surface *text;
SDL_Surface *temp;
if (TTF_Init() < 0)
{
fprintf(stderr, "Couldn't initialize TTF:%s\n", SDL_GetError());
SDL_Quit();
return (void*)-1;
}
font = TTF_OpenFont("./simhei.ttf", 16);
if (NULL == font)
{
fprintf(stderr, "Couldn't load %d pt font from %s:%s\n", 18, "ptsize", SDL_GetError());
return (void*)-2;
}
fmt = (SDL_PixelFormat*)malloc(sizeof(SDL_PixelFormat));
memset(fmt, 0, sizeof(SDL_PixelFormat));
fmt->BitsPerPixel = 16;
fmt->BytesPerPixel = 2;
fmt->colorkey = 0xffffffff;
fmt->alpha = 0xff;
//创建八个region并Attach到VPSS通道上
for (item_count = 0; item_count < RGN_MAX; item_count++)
{
stRgnAttrSet[item_count].enType = OVERLAYEX_RGN;
stRgnAttrSet[item_count].unAttr.stOverlayEx.enPixelFmt = PIXEL_FORMAT_RGB_1555;
stRgnAttrSet[item_count].unAttr.stOverlayEx.stSize.u32Width = 136;
stRgnAttrSet[item_count].unAttr.stOverlayEx.stSize.u32Height = 18;
stRgnAttrSet[item_count].unAttr.stOverlayEx.u32BgColor = 0x00000000;//0x000003e0;
s32Ret = HI_MPI_RGN_Create(item_count, &(stRgnAttrSet[item_count]));
if (s32Ret != HI_SUCCESS)
{
printf("HI_MPI_RGN_Create failed! s32Ret: 0x%x.\n", s32Ret);
return (void*)s32Ret;
}
stChnAttr[item_count].bShow = HI_TRUE;
stChnAttr[item_count].enType = OVERLAYEX_RGN;
stChnAttr[item_count].unChnAttr.stOverlayExChn.stPoint.s32X = 46;
stChnAttr[item_count].unChnAttr.stOverlayExChn.stPoint.s32Y = 34 + item_count * 18;//position of region
stChnAttr[item_count].unChnAttr.stOverlayExChn.u32BgAlpha = 0;
stChnAttr[item_count].unChnAttr.stOverlayExChn.u32FgAlpha = 128;
stChnAttr[item_count].unChnAttr.stOverlayExChn.u32Layer = 0;
s32Ret = HI_MPI_RGN_AttachToChn(item_count, &stChn, &(stChnAttr[item_count]));
if (s32Ret != HI_SUCCESS)
{
printf("HI_MPI_RGN_AttachToChn failed! s32Ret: 0x%x.\n", s32Ret);
return (void*)s32Ret;
}
}
while (1) //每隔50us调用HI_MPI_RGN_SetBitMap刷新八个region
{
usleep(50);
pthread_mutex_lock(&thread_mutex);
for (item_count = 0; item_count < RGN_MAX; item_count++)
{
if (ZERO_LEVEL == Menu_Level)
text = TTF_RenderUTF8_Solid(font, strings0[item_count], forecol0[item_count]);
else if (FIRST_LEVEL == Menu_Level)
text = TTF_RenderUTF8_Solid(font, strings1[item_count], forecol1[item_count]);
else if (SECOND_LEVEL_GAIN == Menu_Level)
text = TTF_RenderUTF8_Solid(font, strings2_gain[item_count], forecol2_gain[item_count]);
else if (SECOND_LEVEL_SHUTTER == Menu_Level)
text = TTF_RenderUTF8_Solid(font, strings2_shutter[item_count], forecol2_shutter[item_count]);
else if (SECOND_LEVEL_BRIGHT == Menu_Level)
text = TTF_RenderUTF8_Solid(font, strings2_bright[item_count], forecol2_bright[item_count]);
else if (SECOND_LEVEL_WBMODE == Menu_Level)
text = TTF_RenderUTF8_Solid(font, strings2_wbmode[item_count], forecol2_wbmode[item_count]);
else if (SECOND_LEVEL_SHARP == Menu_Level)
text = TTF_RenderUTF8_Solid(font, strings2_sharp[item_count], forecol2_sharp[item_count]);
else if (SECOND_LEVEL_GAMMA == Menu_Level)
text = TTF_RenderUTF8_Solid(font, strings2_gamma[item_count], forecol2_gamma[item_count]);
else
{}
temp = SDL_ConvertSurface(text, fmt, 0x00);
stBitmap[item_count].u32Width = temp->w;
stBitmap[item_count].u32Height = temp->h;
stBitmap[item_count].pData = temp->pixels;
stBitmap[item_count].enPixelFormat = PIXEL_FORMAT_RGB_1555;
s32Ret = HI_MPI_RGN_SetBitMap(item_count, &(stBitmap[item_count])); //刷新region
if (s32Ret != HI_SUCCESS)
{
printf("HI_MPI_RGN_SetBitMap failed with %#x!\n", s32Ret);
return (void*)s32Ret;
}
free(stBitmap[item_count].pData);
stBitmap[item_count].pData = NULL;
}
if ('q' == g_ch)
break;
pthread_mutex_unlock(&thread_mutex);
}
free(fmt);
fmt = NULL;
SDL_FreeSurface(text);
SDL_FreeSurface(temp);
TTF_CloseFont(font);
TTF_Quit();
return (void*)0; //退出线程前释放资源
}
在运行这个demo的时候过段时间会自动退出并报out of memory信息,如果加大usleep(5000),也就是增大刷新间隔,这个demo会坚持更长的时间才自动退出。所以基本可以确定问题是出在刷新Region的地方。大家在做海思osd的时候有没有遇到类似的问题?
采用的方案是SDL+freetype+SDL_ttf。
osd的刷新放在一个线程中,osd的菜单层次改变,字符串改变,颜色改变放在其他线程中。
下面这段代码是osd刷新的线程。
void *monitor_thread(void *arg)
{
HI_S32 s32Ret;
RGN_ATTR_S stRgnAttrSet[RGN_MAX];
RGN_CHN_ATTR_S stChnAttr[RGN_MAX];
stChn.enModId = HI_ID_VPSS;
stChn.s32DevId = 0;
stChn.s32ChnId = 0;
BITMAP_S stBitmap[RGN_MAX];
TTF_Font *font;
SDL_PixelFormat *fmt;
SDL_Surface *text;
SDL_Surface *temp;
if (TTF_Init() < 0)
{
fprintf(stderr, "Couldn't initialize TTF:%s\n", SDL_GetError());
SDL_Quit();
return (void*)-1;
}
font = TTF_OpenFont("./simhei.ttf", 16);
if (NULL == font)
{
fprintf(stderr, "Couldn't load %d pt font from %s:%s\n", 18, "ptsize", SDL_GetError());
return (void*)-2;
}
fmt = (SDL_PixelFormat*)malloc(sizeof(SDL_PixelFormat));
memset(fmt, 0, sizeof(SDL_PixelFormat));
fmt->BitsPerPixel = 16;
fmt->BytesPerPixel = 2;
fmt->colorkey = 0xffffffff;
fmt->alpha = 0xff;
//创建八个region并Attach到VPSS通道上
for (item_count = 0; item_count < RGN_MAX; item_count++)
{
stRgnAttrSet[item_count].enType = OVERLAYEX_RGN;
stRgnAttrSet[item_count].unAttr.stOverlayEx.enPixelFmt = PIXEL_FORMAT_RGB_1555;
stRgnAttrSet[item_count].unAttr.stOverlayEx.stSize.u32Width = 136;
stRgnAttrSet[item_count].unAttr.stOverlayEx.stSize.u32Height = 18;
stRgnAttrSet[item_count].unAttr.stOverlayEx.u32BgColor = 0x00000000;//0x000003e0;
s32Ret = HI_MPI_RGN_Create(item_count, &(stRgnAttrSet[item_count]));
if (s32Ret != HI_SUCCESS)
{
printf("HI_MPI_RGN_Create failed! s32Ret: 0x%x.\n", s32Ret);
return (void*)s32Ret;
}
stChnAttr[item_count].bShow = HI_TRUE;
stChnAttr[item_count].enType = OVERLAYEX_RGN;
stChnAttr[item_count].unChnAttr.stOverlayExChn.stPoint.s32X = 46;
stChnAttr[item_count].unChnAttr.stOverlayExChn.stPoint.s32Y = 34 + item_count * 18;//position of region
stChnAttr[item_count].unChnAttr.stOverlayExChn.u32BgAlpha = 0;
stChnAttr[item_count].unChnAttr.stOverlayExChn.u32FgAlpha = 128;
stChnAttr[item_count].unChnAttr.stOverlayExChn.u32Layer = 0;
s32Ret = HI_MPI_RGN_AttachToChn(item_count, &stChn, &(stChnAttr[item_count]));
if (s32Ret != HI_SUCCESS)
{
printf("HI_MPI_RGN_AttachToChn failed! s32Ret: 0x%x.\n", s32Ret);
return (void*)s32Ret;
}
}
while (1) //每隔50us调用HI_MPI_RGN_SetBitMap刷新八个region
{
usleep(50);
pthread_mutex_lock(&thread_mutex);
for (item_count = 0; item_count < RGN_MAX; item_count++)
{
if (ZERO_LEVEL == Menu_Level)
text = TTF_RenderUTF8_Solid(font, strings0[item_count], forecol0[item_count]);
else if (FIRST_LEVEL == Menu_Level)
text = TTF_RenderUTF8_Solid(font, strings1[item_count], forecol1[item_count]);
else if (SECOND_LEVEL_GAIN == Menu_Level)
text = TTF_RenderUTF8_Solid(font, strings2_gain[item_count], forecol2_gain[item_count]);
else if (SECOND_LEVEL_SHUTTER == Menu_Level)
text = TTF_RenderUTF8_Solid(font, strings2_shutter[item_count], forecol2_shutter[item_count]);
else if (SECOND_LEVEL_BRIGHT == Menu_Level)
text = TTF_RenderUTF8_Solid(font, strings2_bright[item_count], forecol2_bright[item_count]);
else if (SECOND_LEVEL_WBMODE == Menu_Level)
text = TTF_RenderUTF8_Solid(font, strings2_wbmode[item_count], forecol2_wbmode[item_count]);
else if (SECOND_LEVEL_SHARP == Menu_Level)
text = TTF_RenderUTF8_Solid(font, strings2_sharp[item_count], forecol2_sharp[item_count]);
else if (SECOND_LEVEL_GAMMA == Menu_Level)
text = TTF_RenderUTF8_Solid(font, strings2_gamma[item_count], forecol2_gamma[item_count]);
else
{}
temp = SDL_ConvertSurface(text, fmt, 0x00);
stBitmap[item_count].u32Width = temp->w;
stBitmap[item_count].u32Height = temp->h;
stBitmap[item_count].pData = temp->pixels;
stBitmap[item_count].enPixelFormat = PIXEL_FORMAT_RGB_1555;
s32Ret = HI_MPI_RGN_SetBitMap(item_count, &(stBitmap[item_count])); //刷新region
if (s32Ret != HI_SUCCESS)
{
printf("HI_MPI_RGN_SetBitMap failed with %#x!\n", s32Ret);
return (void*)s32Ret;
}
free(stBitmap[item_count].pData);
stBitmap[item_count].pData = NULL;
}
if ('q' == g_ch)
break;
pthread_mutex_unlock(&thread_mutex);
}
free(fmt);
fmt = NULL;
SDL_FreeSurface(text);
SDL_FreeSurface(temp);
TTF_CloseFont(font);
TTF_Quit();
return (void*)0; //退出线程前释放资源
}
在运行这个demo的时候过段时间会自动退出并报out of memory信息,如果加大usleep(5000),也就是增大刷新间隔,这个demo会坚持更长的时间才自动退出。所以基本可以确定问题是出在刷新Region的地方。大家在做海思osd的时候有没有遇到类似的问题?
我来回答
回答5个
时间排序
认可量排序
认可0
认可0
认可0
认可0
认可0
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币
Markdown 语法
- 加粗**内容**
- 斜体*内容*
- 删除线~~内容~~
- 引用> 引用内容
- 代码`代码`
- 代码块```编程语言↵代码```
- 链接[链接标题](url)
- 无序列表- 内容
- 有序列表1. 内容
- 缩进内容
- 图片![alt](url)
相关问答
-
2016-12-16 17:55:12
-
2016-03-14 17:14:53
-
2017-08-24 15:55:36
-
2016-06-22 18:03:34
-
2016-04-20 11:15:17
-
2016-04-08 15:29:33
-
2017-01-11 11:11:14
-
142017-10-27 11:19:22
-
2016-05-21 16:18:04
-
2016-01-27 14:04:54
-
2018-11-12 18:05:53
-
2015-05-10 19:22:27
-
2015-10-27 14:38:46
-
2016-07-28 21:17:54
-
2016-08-04 14:49:10
-
2020-05-06 14:31:37
-
2017-12-20 11:14:54
-
2016-07-26 11:29:36
-
2016-06-04 20:55:06
无更多相似问答 去提问
点击登录
-- 积分
-- E币
提问
—
收益
—
被采纳
—
我要提问
切换马甲
上一页
下一页
悬赏问答
-
5Hi3516CV610 如何使用SD卡升级固件
-
5cat /dev/logmpp 报错 <3>[ vi] [func]:vi_send_frame_node [line]:99 [info]:vi pic queue is full!
-
50如何获取vpss chn的图像修改后发送至vo
-
5FPGA通过Bt1120传YUV422数据过来,vi接收不到数据——3516dv500
-
50SS928 运行PQtools 拼接 推到设备里有一半画面会异常
-
53536AV100的sample_vdec输出到CVBS显示
-
10海思板子mpp怎么在vi阶段改变视频数据尺寸
-
10HI3559AV100 多摄像头同步模式
-
9海思ss928单路摄像头vio中加入opencv处理并显示
-
10EB-RV1126-BC-191板子运行自己编码的程序
举报反馈
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明
提醒
你的问题还没有最佳答案,是否结题,结题后将扣除20%的悬赏金
取消
确认
提醒
你的问题还没有最佳答案,是否结题,结题后将根据回答情况扣除相应悬赏金(1回答=1E币)
取消
确认