PK
Guest
|
Posted:
Tue Dec 20, 2005 9:30 am Post subject:
Handle count is increasing. Am I missing any call to Release |
|
|
Hi All,
Not sure if this is the correct place to post. But any help on the issue
would be appreciated.
I wanted to get the audio stream from the given mp3, wma or a wav file. So I
followed the code sample as follows. I have a multithreaded application. I
found that there was handle count increase whenever I called
AddMediaStream() / OpenFile() of the interface IAMMultiMediaStream. The
handle count was increasing in a very drastic manner and not by just 1.
Some of the links I refered was
http://dpi.ufv.br/downloads/C++IntroductoryEdition/VCB600ENU1/MSDN_VCB/SAMPLES/VC98/SDK/GRAPHICS/DIRECTANIMATION/HELP/DS/DSSD0375.HTM
The code snippet for the calling function is as follows
hr = RenderFileToMMStream(ptszFileName, &pMMStream);
if(SUCCEEDED(hr)&& pMMStream)
{
hr = RenderStreamForFileInfo(pMMStream);
pMMStream->Release();
}
HRESULT RenderStreamForFileInfo(IMultiMediaStream *pMMStream)
{
HRESULT hr = S_OK;
WAVEFORMATEX wfx;
#define DATA_SIZE 4096
PBYTE pBuffer = (PBYTE)LocalAlloc(LMEM_FIXED, DATA_SIZE);
IMediaStream *pStream = NULL;
IAudioStreamSample *pSample = NULL;
IAudioMediaStream *pAudioStream = NULL;
IAudioData *pAudioData = NULL;
pMMStream->GetMediaStream(MSPID_PrimaryAudio, &pStream);
pStream->QueryInterface(IID_IAudioMediaStream, (void **)&pAudioStream);
assert(pAudioStream != NULL);
pAudioStream->GetFormat(&wfx);
AudioFormat audio_format;
audio_format.bits_per_sample = wfx.wBitsPerSample;
audio_format.channels = wfx.nChannels;
audio_format.sample_rate = wfx.nSamplesPerSec;
if ((audio_format.sample_rate < 0) || (audio_format.sample_rate == 0))
{
hr = E_FAIL;
goto DONE;
}
hr = CoCreateInstance(CLSID_AMAudioData, NULL, CLSCTX_INPROC_SERVER,
IID_IAudioData, (void **)&pAudioData);
assert(pAudioData != NULL);
hr = pAudioData->SetBuffer(DATA_SIZE, pBuffer, 0);
hr = pAudioData->SetFormat(&wfx);
hr = pAudioStream->CreateSample(pAudioData, 0, &pSample);
DWORD dwLength;
pAudioData->GetInfo(NULL, NULL, &dwLength);
DONE:
SAFE_RELEASE( pAudioData );
SAFE_RELEASE( pSample );
SAFE_RELEASE( pStream );
SAFE_RELEASE( pAudioStream );
LocalFree((HLOCAL)pBuffer);
return hr;
}
HRESULT RenderFileToMMStream(const TCHAR* ptszFileName, IMultiMediaStream
**ppMMStream)
{
IAMMultiMediaStream *pAMStream = NULL;
HRESULT hr = S_OK;
CP2P_LICMGR objLicMgr;
//CComPtr<IMediaStream> poMediaStream;
hr = CoCreateInstance(CLSID_AMMultiMediaStream, NULL, CLSCTX_INPROC_SERVER,
IID_IAMMultiMediaStream, (void **)&pAMStream);
if(SUCCEEDED(hr)&& pAMStream)
{
pAMStream->Initialize(STREAMTYPE_READ, AMMSF_NOGRAPHTHREAD, NULL);
pAMStream->AddMediaStream(NULL, &MSPID_PrimaryAudio, 0,
NULL );//&poMediaStream);
#ifndef UNICODE
WCHAR* pwszFileName = NULL;
hr = objLicMgr.ConvertStrToUnicode( ptszFileName, &pwszFileName );
pAMStream->OpenFile(pwszFileName, AMMSF_RUN);
SAFE_ARRAYDELETE( pwszFileName );
#else
pAMStream->OpenFile(ptszFileName, AMMSF_RUN);
#endif
*ppMMStream = pAMStream;
//pAMStream->AddRef();
//poMediaStream->Release();
}
return hr;
}
Note: In RenderFileToMMStream() function I had come accross one article
which said when we make a call to AddMediaStream() the last parameter will
contain the IMediaStream pointer. We should call the Release on this
pointer. But Release() is a private member of this interface.
Also note that this functions are called several times on a multithreaded
environment.
Let me know if there any issue in the code. Am I missing any Release() on
any interface or something like that. Any inputs regarding the same would be
greatly appreciated :-)
Regds,
PK
|
|