void CPPageExternalFilters::OnDoubleClickFilter() { if (FilterOverride* f = GetCurFilter()) { CComPtr<IBaseFilter> pBF; CString name; if (f->type == FilterOverride::REGISTERED) { CStringW namew; if (CreateFilter(f->dispname, &pBF, namew)) { name = namew; } } else if (f->type == FilterOverride::EXTERNAL) { if (SUCCEEDED(LoadExternalFilter(f->path, f->clsid, &pBF))) { name = f->name; } } if (CComQIPtr<ISpecifyPropertyPages> pSPP = pBF) { CComPropertySheet ps(name, this); if (ps.AddPages(pSPP) > 0) { CComPtr<IFilterGraph> pFG; if (SUCCEEDED(pFG.CoCreateInstance(CLSID_FilterGraph))) { pFG->AddFilter(pBF, L""); } ps.DoModal(); } } } }
HRESULT CGraphManager::CreateCaptureGraphInternal() { HRESULT hr = S_OK; CComVariant varCamName; CPropertyBag PropBag; OAEVENT oaEvent; WCHAR wzDeviceName[ MAX_PATH + 1 ]; CComPtr<IMediaEvent> pMediaEvent; CComPtr<IGraphBuilder> pFilterGraph; CComPtr<IPersistPropertyBag> pPropertyBag; CComPtr<IDMOWrapperFilter> pWrapperFilter; CComPtr<IBaseFilter> pImageSinkFilter; // // Create the capture graph builder and register the filtergraph manager. // CHK( m_pCaptureGraphBuilder.CoCreateInstance( CLSID_CaptureGraphBuilder )); CHK( pFilterGraph.CoCreateInstance( CLSID_FilterGraph )); CHK( m_pCaptureGraphBuilder->SetFiltergraph( pFilterGraph )); // // Create and initialize the video capture filter // CHK( m_pVideoCaptureFilter.CoCreateInstance( CLSID_VideoCapture )); CHK( m_pVideoCaptureFilter.QueryInterface( &pPropertyBag )); // We are loading the driver CAM1 in the video capture filter. CHK( GetFirstCameraDriver( wzDeviceName )); varCamName = wzDeviceName; if( varCamName.vt != VT_BSTR ) { ERR( E_OUTOFMEMORY ); } CHK( PropBag.Write( L"VCapName", &varCamName )); CHK( pPropertyBag->Load( &PropBag, NULL )); // Everything succeeded, the video capture filter is added to the filtergraph CHK( pFilterGraph->AddFilter( m_pVideoCaptureFilter, L"Video Capture Filter Source" )); // // Create the still image filter, and connect it to the video capture filter // CHK( pImageSinkFilter.CoCreateInstance( CLSID_IMGSinkFilter )); CHK( pFilterGraph->AddFilter( pImageSinkFilter, L"Still image filter" )); CHK( m_pCaptureGraphBuilder->RenderStream( &PIN_CATEGORY_STILL, &MEDIATYPE_Video, m_pVideoCaptureFilter, NULL, pImageSinkFilter )); CHK( pImageSinkFilter.QueryInterface( &m_pImageSinkFilter )); // // Prevent the data from flowing into the capture stream // // CHK( m_pCaptureGraphBuilder->ControlStream( &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, m_pVideoCaptureFilter, 0, 0 ,0,0 )); // // Let's get the handle for DShow events. The main loop will listen to both notifications from // the UI thread and for DShow notifications // CHK( pFilterGraph->QueryInterface( IID_IMediaEvent, (void**) &pMediaEvent )); CHK( pMediaEvent->GetEventHandle( &oaEvent )); m_handle[1] = (HANDLE) oaEvent; m_fGraphBuilt = TRUE; NotifyMessage( MESSAGE_INFO, L"Builing the graph completed" ); Cleanup: if( FAILED( hr )) { NotifyMessage( MESSAGE_ERROR, L"Builing the graph failed" ); } return hr; }
bool DShowAudioSource::load(const RString& path) { mPath = path; HRESULT hr = S_OK; // Create the graph builder CComPtr<IGraphBuilder> pGraphBuilder; hr = pGraphBuilder.CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER); if(FAILED(hr)) return false; // Create the sample grabber filter CComPtr<IBaseFilter> pSampleGrabberBaseFilter; hr = pSampleGrabberBaseFilter.CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER); if(FAILED(hr)) return false; // Add the sample grabber filter to the graph hr = pGraphBuilder->AddFilter(pSampleGrabberBaseFilter, L"Sample Grabber"); if(FAILED(hr)) return false; // Get the Sample Grabber interface CComQIPtr<ISampleGrabber> pSampleGrabberFilter(pSampleGrabberBaseFilter); if(pSampleGrabberFilter == 0) return false; // Set the sample grabber's media type AM_MEDIA_TYPE mt; ZeroMemory(&mt, sizeof(AM_MEDIA_TYPE)); mt.majortype = MEDIATYPE_Audio; mt.subtype = MEDIASUBTYPE_PCM; mt.formattype = FORMAT_WaveFormatEx; hr = pSampleGrabberFilter->SetMediaType(&mt); if(FAILED(hr)) return false; // Create the sample grabber callback mpSampleGrabberCallback.Attach(new SampleGrabberCallback(this)); hr = pSampleGrabberFilter->SetCallback(mpSampleGrabberCallback, 1); if(FAILED(hr)) return false; // Add the source filter to the graph WCHAR filename[MAX_PATH]; MultiByteToWideChar(CP_ACP, 0,mPath.c_str(), -1, filename, MAX_PATH); CComPtr<IBaseFilter> pSourceFilter; hr = pGraphBuilder->AddSourceFilter(filename, L"Audio Source", &pSourceFilter); if(FAILED(hr)) return false; // Create the NULL renderer. We are only decoding CComPtr<IBaseFilter> pNullRenderer; hr = pNullRenderer.CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER); hr = pGraphBuilder->AddFilter(pNullRenderer, L"NULL Renderer"); // Connect input to sample grabber hr = ConnectFilters(pGraphBuilder, pSourceFilter, pSampleGrabberBaseFilter); if(FAILED(hr)) return false; // Connect sample grabber to NULL renderer hr = ConnectFilters(pGraphBuilder, pSampleGrabberBaseFilter, pNullRenderer); if(FAILED(hr)) return false; // Get some useful interfaces mpMediaControl = pGraphBuilder; if(mpMediaControl == 0) return false; mpMediaEvent = pGraphBuilder; if(mpMediaEvent == 0) return false; mpMediaSeeking = pGraphBuilder; if(mpMediaSeeking == 0) return false; // Get the waveformatex structure pSampleGrabberFilter->GetConnectedMediaType(&mt); mpWaveFormatEx = reinterpret_cast<WAVEFORMATEX*>(mt.pbFormat); hr = mpMediaSeeking->SetTimeFormat(&TIME_FORMAT_MEDIA_TIME); if(FAILED(hr)) return false; CComQIPtr<IMediaFilter> pMediaFilter(pGraphBuilder); pMediaFilter->SetSyncSource(0); mCurrentPosition = 0; mEOF = false; printf("# channels = %d\n", mpWaveFormatEx->nChannels); printf("Sample rate = %d\n", mpWaveFormatEx->nSamplesPerSec); return true; }