HRESULT CCapture::StartCapture(IMFActivate *pActivate) { HRESULT hr = S_OK; IMFMediaSource *pSource = NULL; EnterCriticalSection(&m_critsec); // Create the media source for the device. hr = pActivate->ActivateObject( __uuidof(IMFMediaSource), (void**)&pSource ); // Get the symbolic link. This is needed to handle device- // loss notifications. (See CheckDeviceLost.) if (SUCCEEDED(hr)) { hr = pActivate->GetAllocatedString( MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, &m_pwszSymbolicLink, NULL ); } if (SUCCEEDED(hr)) { hr = OpenMediaSource(pSource); } if (SUCCEEDED(hr)) { // Request the first video frame. hr = m_pReader->ReadSample( (DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM, 0, NULL, NULL, NULL, NULL ); } SafeRelease(&pSource); LeaveCriticalSection(&m_critsec); return hr; }
HRESULT CCapture::StartCapture( IMFActivate *pActivate, const WCHAR *pwszFileName, const EncodingParameters& param ) { HRESULT hr = S_OK; IMFMediaSource *pSource = NULL; EnterCriticalSection(&m_critsec); // Create the media source for the device. hr = pActivate->ActivateObject( __uuidof(IMFMediaSource), (void**)&pSource ); // Get the symbolic link. This is needed to handle device- // loss notifications. (See CheckDeviceLost.) if (SUCCEEDED(hr)) { hr = pActivate->GetAllocatedString( MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, &m_pwszSymbolicLink, NULL ); } if (SUCCEEDED(hr)) { hr = OpenMediaSource(pSource); } // Create the sink writer if (SUCCEEDED(hr)) { hr = MFCreateSinkWriterFromURL( pwszFileName, NULL, NULL, &m_pWriter ); } // Set up the encoding parameters. if (SUCCEEDED(hr)) { hr = ConfigureCapture(param); } if (SUCCEEDED(hr)) { m_bFirstSample = TRUE; m_llBaseTime = 0; // Request the first video frame. hr = m_pReader->ReadSample( (DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM, 0, NULL, NULL, NULL, NULL ); } SafeRelease(&pSource); LeaveCriticalSection(&m_critsec); return hr; }