IMEDIA and My Memory Leak - Any Helpers??? | developer.brewmp.com IMEDIA and My Memory Leak - Any Helpers??? | developer.brewmp.com

Developer

IMEDIA and My Memory Leak - Any Helpers???

Forums:

Hey all - I am almost ready to submit an application, but I've have one last bug to overcome and can't seem to whip it. My application uses IMEDIA interface to play large audio files to callers, but each time I hit menu option to initiate playback of the file - I loose 74+K. Does IMEDIA_SetMediaData allocate memory - If so, how do you free it - I've tried and all heck breaks loose....What am I doing wrong here. I have attached all the relevant code. Brew 2.1 API is being used for this app. Other than the memory leak this app works great - any comments are appreciated!

typedef struct _MyApp MyApp;
struct _MyApp
{
ISocket * m_pISocket;
INetMgr * m_pINetMgr;
IMedia * m_pMedia;
IMedia * m_pMedia2;
AECHAR * m_Audio1;
AECHAR * m_Audio2;
.....other vars
;

....Start up application DrawMySplashScreen is called where I MALLOC some memory to hold my audio

static void DrawMySplashScreen( MyApp * pMe )
{
NOTE: This is only called once!
if((pMe->m_Audio1 = MALLOC(32000)) == NULL)
return;

if((pMe->m_Audio2 = MALLOC(32000)) == NULL)
return;

Display and Handle Player Menu Options

PlayerMenu Function....
{
....
// PLAY SELECTED
Users Selected option to play audio file so I.... 1) creat the Media Player interface and
2) memset the audio buffers then 3) call socket routine

if((ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_MEDIAQCP, (void **)&pMe->m_pMedia)) != SUCCESS)
{
return FALSE;
}
if((ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_MEDIAQCP, (void **)&pMe->m_pMedia2)) != SUCCESS)
{
return FALSE;
}
MEMSET(pMe->m_Audio1, '\0', 32000);
MEMSET(pMe->m_Audio2, '\0', 32000);
Socket_Connect(pMe);

//STOP SELECTED
If the user presses Stop command, then I free up and display the menu again
IMEDIA_Stop(pMe->m_pMedia);
IMEDIA_Stop(pMe->m_pMedia2);
IMEDIA_Release(pMe->m_pMedia);
IMEDIA_Release(pMe->m_pMedia2);

}

// After I connect to the socket and request the audio file, my CB routine is called
This is where I initiate the audio playback.
static void Socket_ReadDataCB(void *cxt)
{
....Read until all audio is obtained and store it in AudioBuf(n)
if reading buf1
MEMCPY((char *)pMe->m_Audio1+(pMe->m_totalbytes - ByteCount), buf, ByteCount);
else
MEMCPY((char *)pMe->m_Audio2+(pMe->m_totalbytes - ByteCount), buf, ByteCount);

if(First audio chunk to play)
....Now that I have all the audio - Play it
md.clsData = MMD_BUFFER;
md.pData = (void *)pMe->m_Audio1;
md.dwSize = pMe->m_Buf1_Bytes;

IMEDIA_SetMediaData(pMe->m_pMedia, &md);
IMEDIA_RegisterNotify(pMe->m_pMedia, (PFNMEDIANOTIFY) *MediaPlayCB, pMe);
IMEDIA_Play(pMe->m_pMedia);
else
return

// Media call back
static void MediaPlayCB(void *cxt, AEEMediaCmdNotify * pCmdNotify)
{
MyApp *pMe = (MyApp *)cxt;

switch(pCmdNotify->nStatus)
{
case MM_STATUS_DONE:
if(played buffer 1)

md2.clsData = MMD_BUFFER;
md2.pData = (void *)pMe->m_Audio2;
md2.dwSize = pMe->m_Buf2_Bytes;
retval = IMEDIA_SetMediaData(pMe->m_pMedia2, &md2);
retval = IMEDIA_RegisterNotify(pMe->m_pMedia2, (PFNMEDIANOTIFY) *MediaPlayCB, pMe);
retval = IMEDIA_Play(pMe->m_pMedia2);
else
md2.clsData = MMD_BUFFER;
md2.pData = (void *)pMe->m_Audio1;
md2.dwSize = pMe->m_Buf1_Bytes;
retval = IMEDIA_SetMediaData(pMe->m_pMedia1, &md2);
retval = IMEDIA_RegisterNotify(pMe->m_pMedia1, (PFNMEDIANOTIFY) *MediaPlayCB, pMe);
retval = IMEDIA_Play(pMe->m_pMedia1);

case MM_TICK_UPDATE
call socket routine to get more audio
:cool: :cool: :cool:

Did you free pMe->m_Audio1/m_Audio2 ? IIRC, IMEDIA does not take ownership of these buffers, so it's up to your app to free it..

Did you free pMe->m_Audio1/m_Audio2 ? IIRC, IMEDIA does not take ownership of these buffers, so it's up to your app to free it..

Yes, Audio1 and Audio2 are freed when I exit the application. I MEMSET them when the user presses the play button.
I have traced this memory leak up to the point that IMEDIA initiates the _Play. At this point is where the memory is used. If I stop IMEDIA playback and then restart it another 74+K is lost.
Very frustrating what is IMEDIA doing to my memory? :confused:

Yes, Audio1 and Audio2 are freed when I exit the application. I MEMSET them when the user presses the play button.
I have traced this memory leak up to the point that IMEDIA initiates the _Play. At this point is where the memory is used. If I stop IMEDIA playback and then restart it another 74+K is lost.
Very frustrating what is IMEDIA doing to my memory? :confused: