5577
- 收藏
- 点赞
- 分享
- 举报
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
-
2016-06-22 18:03:34
-
2017-08-24 15:55:36
-
2016-04-20 11:15:17
-
2016-04-08 15:29:33
-
142017-10-27 11:19:22
-
2017-01-11 11:11:14
-
2016-01-27 14:04:54
-
2015-05-10 19:22:27
-
2016-05-21 16:18:04
-
2016-07-28 21:17:54
-
2018-11-12 18:05:53
-
2015-10-27 14:38:46
-
2016-08-04 14:49:10
-
2016-06-04 20:55:06
-
2015-04-20 04:38:38
-
2016-07-26 11:29:36
-
2015-07-15 18:14:15
无更多相似问答 去提问
点击登录
-- 积分
-- E币
提问
—
收益
—
被采纳
—
我要提问
切换马甲
上一页
下一页
悬赏问答
-
5SS928的emmc有32GB,bootargs设置使用16GB,但是为啥能用的只有rootfs的大小
-
33SS928怎样烧写ubuntu系统
-
10ToolPlatform下载rootfs提示网络失败
-
10谁有GK7205V500的SDK
-
5Hi3516CV610 烧录不进去
-
10Hi3559AV100 芯片硬解码h265编码格式的视频时出现视频播放错误,解码错误信息 s32PackErr:码流有错
-
5海思SS928 / SD3403的sample_venc.c摄像头编码Demo中,采集到的摄像头的YUV数据在哪个相关的函数中?
-
5海鸥派openEuler无法启动网卡,连接WIFI存在问题
-
66有没有ISP相关的巨佬帮忙看看SS928对接IMX347的图像问题
-
50求助hi3559与FPGA通过SLVS-EC接口对接问题
举报反馈
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明
提醒
你的问题还没有最佳答案,是否结题,结题后将扣除20%的悬赏金
取消
确认
提醒
你的问题还没有最佳答案,是否结题,结题后将根据回答情况扣除相应悬赏金(1回答=1E币)
取消
确认