|
本帖最后由 hpdell 于 2018-9-5 11:00 编辑
请教下播放视频推出后每次都会占用2.5MB左右的空间,几次下来内存都所剩无几了 ?
在 每次进入播放时,会申请内存,播放完成后会释放内存,播放下一首曲目时也会 申请内存,播放玩后再释放内存,
当在正常播放时,按下退出键,也会释放内存,但是等退出到主界面时,获取到的剩余内存就会少 2.5MB 左右,每次减少的内存
大小都是一致的,请问这是什么原因啊 ?
内存申请函数:
//申请内存
void *GUI_MYmalloc(unsigned int num_bytes)
{
GUI_HMEM h = GUI_ALLOC_AllocZero((unsigned int) num_bytes); /* 申请一块内存空间 并且将其清零 */
void *p = GUI_ALLOC_h2p(h); /* 将申请到内存的句柄转换成指针类型 */
return p;
}
内存释放函数:
//释放内存
void GUI_MYfree(void *ptr)
{
GUI_HMEM h = GUI_ALLOC_p2h((void *)ptr);
GUI_ALLOC_Free(h);
}
/*
内存申请、释放
fm=0申请
=1释放
*/
uint8_t AVI_Memory(int8_t FM)
{
if(!FM) //申请内存
{
_VideoPlayCtrl._avi_file = (FIL *)mymalloc(SRAMIN, sizeof(FIL));
AVI_Handel.pAudioBufferA = (uint8_t *)mymalloc(SRAMIN, AVI_AUDIO_BUF_IN_SIZE);
AVI_Handel.pAudioBufferB = (uint8_t *)mymalloc(SRAMIN, AVI_AUDIO_BUF_IN_SIZE);
AVI_Handel.pVideoBufferOut = (uint8_t *)GUI_MYmalloc( 1024*1024*2);
AVI_Handel.pAudioBufferOutA = (uint8_t *)GUI_MYmalloc( (1024*128));
AVI_Handel.pAudioBufferOutA = (uint8_t *)GUI_MYmalloc( (1024*128));
AVI_Handel.pVideoBufferTemp = (uint8_t *)GUI_MYmalloc( AVI_MAX_SIZE); // 申请视频buf 120KByte or 1MB
AVI_mp3FrameInfo= (MP3FrameInfo *)mymalloc(SRAMIN, (sizeof(MP3FrameInfo))); //内存分配.
AVI_hMP3Decoder = (HMP3Decoder *)MP3InitDecoder();//申请内存
if(!_VideoPlayCtrl._avi_file || !AVI_Handel.pVideoBufferOut || !AVI_Handel.pVideoBufferTemp
|| !AVI_Handel.pAudioBufferA || !AVI_Handel.pAudioBufferB
|| !AVI_mp3FrameInfo || !AVI_hMP3Decoder
|| !AVI_Handel.pAudioBufferOutA || !AVI_Handel.pAudioBufferOutB)
return 4;
memset(AVI_Handel.pAudioBufferA, 0, AVI_AUDIO_BUF_IN_SIZE);
memset(AVI_Handel.pAudioBufferB, 0, AVI_AUDIO_BUF_IN_SIZE);
JPEG_MallocBuff(); // 申请内存 ,使用完后,必须释放内存
}
else // 释放内存
{
if(_VideoPlayCtrl._avi_file )
{
myfree(SRAMIN, _VideoPlayCtrl._avi_file);
_VideoPlayCtrl._avi_file =0;
}
if(AVI_Handel.pVideoBufferOut )
{
GUI_MYfree((void *) AVI_Handel.pVideoBufferOut);
AVI_Handel.pVideoBufferOut = 0;
}
if(AVI_Handel.pVideoBufferTemp )
{
GUI_MYfree((void *) AVI_Handel.pVideoBufferTemp);
AVI_Handel.pVideoBufferTemp = 0;
}
if(AVI_Handel.pAudioBufferA )
{
myfree(SRAMIN, AVI_Handel.pAudioBufferA);
AVI_Handel.pAudioBufferA = 0;
}
if(AVI_Handel.pAudioBufferB)
{
myfree(SRAMIN, AVI_Handel.pAudioBufferB);
AVI_Handel.pAudioBufferB =0;
}
if(AVI_hMP3Decoder)
{
MP3FreeDecoder(AVI_hMP3Decoder);
AVI_hMP3Decoder =0;
}
if(AVI_mp3FrameInfo)
{
myfree(SRAMIN, AVI_mp3FrameInfo);
AVI_mp3FrameInfo =0;
}
if(AVI_Handel.pAudioBufferOutA)
{
GUI_MYfree((void *) AVI_Handel.pAudioBufferOutA);
AVI_Handel.pAudioBufferOutA =0;
}
if(AVI_Handel.pAudioBufferOutB)
{
GUI_MYfree((void *) AVI_Handel.pAudioBufferOutB);
AVI_Handel.pAudioBufferOutB =0;
}
JPEG_FreeBuff(); //释放 jpeg 内存
}
return 0; //成功
}
按下退出播放按钮后进行如下操作:
case ID_BUTTON_RETURN_APP: //程序退出返回到主界面
{
switch(NCode)
{
case WM_NOTIFICATION_CLICKED:
break;
case WM_NOTIFICATION_RELEASED:
{
WM_MakeModal(0); //取消模态
// 关闭当前对话框, 创建对话框1
GUI_EndDialog(pMsg->hWin, 0);
hWinVideo = NULL;
hWinVideoList = NULL;
s_ucPlayStatus = 0;
g_tWav.ucDispUpdate = 0;
xEventGroupSetBits(xCreatedEventGroup, MusicTaskAudioStop_11); //这个发送的信息程序能够正常执行
MainTaskWindowShow(); //直接显示主界面,速度比重新绘制要快
} break;
}
} break;
// 视频播放任务里面对退出的处理
case MusicTaskAudioReturn_6: //播放下一曲目时,先停止当前播放
case MusicTaskAudioStop_11: // 停止播放 , 程序退出播放界面返回到主界面
_VideoPlayCtrl.AVI_AudioState = VIDEO_STATE_STOP;
AVI_FRAM_Stop();
VIDEO_PLAY_Stop();
if(res == FR_OK)
{
f_close (_VideoPlayCtrl._avi_file);
}
AVI_Memory(1); //释放内存
WM8978_PowerDown();
return;
|
|