Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to change the nSamplesPerSec with WMFSDK

9 views
Skip to first unread message

Xu

unread,
May 18, 2011, 4:17:45 AM5/18/11
to
Hi:

When I use the Windows Media Format 9 SDK to change the
nChannels,wBitsPerSample, and nSamplesPerSec in the WAVEFORMATEX structure, I got memery leak.

in the following codes,I use
m_pReader->GetOutputProps(0,&pProps); to get IWMOutputMediaProps object,
and change the properties and the call
m_pReader->SetOutputProps(0,pProps); to save the changes.

but i get a memery leak.

The following codes is the part of codes I implentment the function.

{
DWORD cOutputs = 0;
HRESULT hr = S_OK;
IWMOutputMediaProps* pProps = NULL;
WM_MEDIA_TYPE* pMediaType = NULL;
ULONG cbType = 0;
m_pReader->GetOutputCount(&cOutputs );

m_pReader->GetOutputProps(0,&pProps);

pProps->GetMediaType(NULL,&cbType);

pMediaType = (WM_MEDIA_TYPE*) new BYTE[cbType];

//pMediaType = ( WM_MEDIA_TYPE* ) malloc(cbType);

hr = pProps->GetMediaType(pMediaType, &cbType );

if (WMFORMAT_WaveFormatEx == pMediaType->formattype)
{
memcpy(&m_Wfx, pMediaType->pbFormat, pMediaType->cbFormat );

m_Wfx.wFormatTag = WAVE_FORMAT_PCM;
m_Wfx.nChannels = GetRealChannels(m_Wfx.nChannels);
m_Wfx.nSamplesPerSec = GetRealRate(m_Wfx.nSamplesPerSec);
m_Wfx.wBitsPerSample = GetRealBits(m_Wfx.wBitsPerSample);
m_Wfx.nBlockAlign = (m_Wfx.nChannels * m_Wfx.wBitsPerSample) >> 3;
m_Wfx.nAvgBytesPerSec = m_Wfx.nSamplesPerSec * m_Wfx.nBlockAlign;

memcpy(pMediaType->pbFormat,&m_Wfx, pMediaType->cbFormat );


hr = pProps->SetMediaType(pMediaType);

m_pReader->SetOutputProps(0,pProps);

bRet = TRUE;
}
else
{
bRet = FALSE;
}

SAFE_ARRAYDELETE(pMediaType);
//free(pMediaType);

SAFE_RELEASE(pProps);
}


Maybe someone else also met this issue,who can share the experience,thanks.

that all.

0 new messages