Windows Media Format SDK IWMSyncReader Problem
-
I've followed the MSDN sample codes to read samples from a wmv file. But what's different is that I need to call SetRange() each time when I enter a while loop to grab only sample in a specific range (Ex: every 1 second). But even if I called INSSBuffer::Release() to release the buffer interface after calling IWMSyncReader::GetNextSample(), the memory seemd not release at once. I used the taskmgr.exe to peek my memory usage. Codes are as follows: QWORD qwRange = 0; int nIndex = 0; while( qwRange < m_qwFileDuration ) { QWORD cnsSampleTime = 0; QWORD cnsDuration = 0; DWORD dwFlags = 0; DWORD dwOutputNum = 0; DWORD dwLength = 0; LPBYTE pBuf = NULL; INSSBuffer* pMyBuffer = NULL; HRESULT hr = S_OK; UINT nIndex = 0; hr |= m_pSyncReader->SetRange( qwRange,0 ); if( FAILED(hr)) return; hr |= m_pSyncReader->GetNextSample( m_wStreamNumber, &pMyBuffer, &cnsSampleTime, &cnsDuration, &dwFlags, &dwOutputNum, NULL ); if( FAILED(hr)) return; hr |= pMyBuffer->GetBufferAndLength( &pBuf, &dwLength ); if( FAILED(hr)) return; memcpy( m_ppBuf[nIndex], pBuf, dwLength ); pMyBuffer->Release(); pMyBuffer = NULL; qwRange += 10000000; nIndex++; } First loop: SetRange() would increase the memory usage, GetNextSample() would further increase the memory usage. After First loop: SetRange() would decrease the memory usage, but more than that of the previous loop, and GetNextSample() would increase the memory usage again. After using taskmgr.exe and run my code in debug mode to examine the memory usage, I found the memory usage only changed after these 2 lines. If I tried to delete the local buffer pBuf after Realese() would result in a memory exception... Why and how to prevent memory leak? Can somebody help me? Thanks!
-
I've followed the MSDN sample codes to read samples from a wmv file. But what's different is that I need to call SetRange() each time when I enter a while loop to grab only sample in a specific range (Ex: every 1 second). But even if I called INSSBuffer::Release() to release the buffer interface after calling IWMSyncReader::GetNextSample(), the memory seemd not release at once. I used the taskmgr.exe to peek my memory usage. Codes are as follows: QWORD qwRange = 0; int nIndex = 0; while( qwRange < m_qwFileDuration ) { QWORD cnsSampleTime = 0; QWORD cnsDuration = 0; DWORD dwFlags = 0; DWORD dwOutputNum = 0; DWORD dwLength = 0; LPBYTE pBuf = NULL; INSSBuffer* pMyBuffer = NULL; HRESULT hr = S_OK; UINT nIndex = 0; hr |= m_pSyncReader->SetRange( qwRange,0 ); if( FAILED(hr)) return; hr |= m_pSyncReader->GetNextSample( m_wStreamNumber, &pMyBuffer, &cnsSampleTime, &cnsDuration, &dwFlags, &dwOutputNum, NULL ); if( FAILED(hr)) return; hr |= pMyBuffer->GetBufferAndLength( &pBuf, &dwLength ); if( FAILED(hr)) return; memcpy( m_ppBuf[nIndex], pBuf, dwLength ); pMyBuffer->Release(); pMyBuffer = NULL; qwRange += 10000000; nIndex++; } First loop: SetRange() would increase the memory usage, GetNextSample() would further increase the memory usage. After First loop: SetRange() would decrease the memory usage, but more than that of the previous loop, and GetNextSample() would increase the memory usage again. After using taskmgr.exe and run my code in debug mode to examine the memory usage, I found the memory usage only changed after these 2 lines. If I tried to delete the local buffer pBuf after Realese() would result in a memory exception... Why and how to prevent memory leak? Can somebody help me? Thanks!