void AsioSessionState::setTransportFilters( const std::vector<FilterPtr> &filters) { mTransportFilters.assign(filters.begin(), filters.end()); connectFilters(mTransportFilters); if (!mTransportFilters.empty()) { mTransportFilters.front()->setPreFilter( *mFilterAdapterPtr ); mTransportFilters.back()->setPostFilter( *mFilterAdapterPtr ); } }
DShowCameraDeviceInteral (CameraDevice* const owner_, const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_, const ComSmartPtr <IBaseFilter>& filter_, int minWidth, int minHeight, int maxWidth, int maxHeight) : owner (owner_), captureGraphBuilder (captureGraphBuilder_), filter (filter_), ok (false), imageNeedsFlipping (false), width (0), height (0), activeUsers (0), recordNextFrameTime (false), previewMaxFPS (60) { HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph); if (FAILED (hr)) return; hr = captureGraphBuilder->SetFiltergraph (graphBuilder); if (FAILED (hr)) return; hr = graphBuilder.QueryInterface (mediaControl); if (FAILED (hr)) return; { ComSmartPtr <IAMStreamConfig> streamConfig; hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE, 0, filter, IID_IAMStreamConfig, (void**) streamConfig.resetAndGetPointerAddress()); if (streamConfig != nullptr) { getVideoSizes (streamConfig); if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight)) return; } } hr = graphBuilder->AddFilter (filter, _T("Video Capture")); if (FAILED (hr)) return; hr = smartTee.CoCreateInstance (CLSID_SmartTee); if (FAILED (hr)) return; hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee")); if (FAILED (hr)) return; if (! connectFilters (filter, smartTee)) return; ComSmartPtr <IBaseFilter> sampleGrabberBase; hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber); if (FAILED (hr)) return; hr = sampleGrabberBase.QueryInterface (IID_ISampleGrabber, sampleGrabber); if (FAILED (hr)) return; { AM_MEDIA_TYPE mt = { 0 }; mt.majortype = MEDIATYPE_Video; mt.subtype = MEDIASUBTYPE_RGB24; mt.formattype = FORMAT_VideoInfo; sampleGrabber->SetMediaType (&mt); } callback = new GrabberCallback (*this); hr = sampleGrabber->SetCallback (callback, 1); hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber")); if (FAILED (hr)) return; ComSmartPtr <IPin> grabberInputPin; if (! (getPin (smartTee, PINDIR_OUTPUT, smartTeeCaptureOutputPin, "capture") && getPin (smartTee, PINDIR_OUTPUT, smartTeePreviewOutputPin, "preview") && getPin (sampleGrabberBase, PINDIR_INPUT, grabberInputPin))) return; hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin); if (FAILED (hr)) return; AM_MEDIA_TYPE mt = { 0 }; hr = sampleGrabber->GetConnectedMediaType (&mt); VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat); width = pVih->bmiHeader.biWidth; height = pVih->bmiHeader.biHeight; ComSmartPtr <IBaseFilter> nullFilter; hr = nullFilter.CoCreateInstance (CLSID_NullRenderer); hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer")); if (connectFilters (sampleGrabberBase, nullFilter) && addGraphToRot()) { activeImage = Image (Image::RGB, width, height, true); loadingImage = Image (Image::RGB, width, height, true); ok = true; } }
bool DShowMoviePlayer::loadMovie (void) { if (!_oleInitialized) { ::CoInitialize (0); } char physicFileName[512]; wchar_t physicFileNameW[512]; ATOM_GetNativePathName (_fileName.c_str(), physicFileName); if (!convertCStringToWString (physicFileName, physicFileNameW, 512)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "Error converting C string filename to UNICODE"); return false; } #if 1 HRESULT hr = ::CoCreateInstance (CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&_graphBuilder); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error creating graph"); return false; } hr = ::CoCreateInstance (CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&_grabberFilter); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error creating sample grabber"); return false; } hr = _grabberFilter->QueryInterface (IID_ISampleGrabber, (void**)&_grabber); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error querying sample grabber"); return false; } AM_MEDIA_TYPE mt; memset (&mt, 0, sizeof(AM_MEDIA_TYPE)); mt.majortype = MEDIATYPE_Video; mt.subtype = MEDIASUBTYPE_RGB32; mt.formattype = FORMAT_VideoInfo; hr = _grabber->SetMediaType (&mt); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error setting smaple grabber media type"); return false; } hr = _graphBuilder->AddFilter (_grabberFilter, L"Sample Grabber"); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error adding filter"); return false; } hr = _graphBuilder->QueryInterface (IID_IMediaControl, (void**)&_control); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error querying media control"); return false; } IBaseFilter *render = 0; hr = ::CoCreateInstance (CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&render); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error creating render filter"); return false; } hr = _graphBuilder->AddFilter (render, L"Null renderer"); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error adding null-renderer filter"); return false; } hr = _control->RenderFile (physicFileNameW); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error rendering file"); return false; } #if 0 IPin *grabberOut = 0; FindPin (_grabberFilter, PINDIR_OUTPUT, 0, &grabberOut); if (grabberOut) { grabberOut->Disconnect (); grabberOut->Release (); } #endif SaveGraphFile (_graphBuilder, L"C:\\test.grf"); hr = _graphBuilder->QueryInterface (IID_IVideoWindow, (void**)&_window); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error querying video window"); return false; } _window->put_AutoShow (OAFALSE); #if 0 if (!ConnectPins (_graphBuilder, _grabberFilter, 0, render, 0)) { return false; } _control->RenderFile (physicFileNameW); #endif memset(&mt, 0, sizeof(mt)); mt.majortype = MEDIATYPE_Video; mt.subtype = MEDIASUBTYPE_RGB32; mt.formattype = FORMAT_VideoInfo; hr = _grabber->GetConnectedMediaType (&mt); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error getting connected media type"); return false; } VIDEOINFOHEADER *vih = (VIDEOINFOHEADER*)mt.pbFormat; _videoWidth = vih->bmiHeader.biWidth; _videoHeight = vih->bmiHeader.biHeight; _bufferSize = mt.lSampleSize; if (mt.cbFormat != 0) { ::CoTaskMemFree ((PVOID)mt.pbFormat); mt.cbFormat = 0; mt.pbFormat = 0; } if (mt.pUnk != NULL) { mt.pUnk->Release (); mt.pUnk = NULL; } _grabber->SetOneShot (FALSE); _grabber->SetBufferSamples (TRUE); hr = _graphBuilder->QueryInterface (IID_IMediaEvent, (void**)&_event); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error querying media event"); return false; } hr = _graphBuilder->QueryInterface (IID_IMediaSeeking, (void**)&_seeking); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error querying media seeking"); return false; } #else HRESULT hr = ::CoCreateInstance (CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&_graphBuilder); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error creating graph"); return false; } hr = _graphBuilder->QueryInterface (IID_IMediaControl, (void**)&_control); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error querying media control"); return false; } hr = _graphBuilder->QueryInterface (IID_IMediaEvent, (void**)&_event); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error querying media event"); return false; } hr = _graphBuilder->QueryInterface (IID_IMediaSeeking, (void**)&_seeking); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error querying media seeking"); return false; } hr = ::CoCreateInstance (CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&_grabberFilter); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error creating sample grabber"); return false; } hr = _graphBuilder->AddFilter (_grabberFilter, L"Sample Grabber"); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error adding filter"); return false; } hr = _grabberFilter->QueryInterface (IID_ISampleGrabber, (void**)&_grabber); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error querying sample grabber"); return false; } AM_MEDIA_TYPE mt; memset (&mt, 0, sizeof(AM_MEDIA_TYPE)); mt.majortype = MEDIATYPE_Video; mt.subtype = MEDIASUBTYPE_RGB24; mt.formattype = FORMAT_VideoInfo; hr = _grabber->SetMediaType (&mt); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error setting smaple grabber media type"); return false; } IBaseFilter *srcFilter = 0; hr = _graphBuilder->AddSourceFilter (physicFileNameW, L"Source", &srcFilter); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error adding source filter"); return false; } hr = connectFilters (_graphBuilder, srcFilter, _grabberFilter); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error connecting filters"); return false; } IBaseFilter *render = 0; hr = ::CoCreateInstance (CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&render); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error creating render filter"); return false; } _graphBuilder->AddFilter (render, L"Render"); hr = connectFilters (_graphBuilder, _grabberFilter, render); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error connect filters"); return false; } hr = _graphBuilder->RenderFile (physicFileNameW, NULL); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error rendering file"); return false; } hr = _graphBuilder->QueryInterface (IID_IVideoWindow, (void**)&_window); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error querying video window"); return false; } _window->put_AutoShow (OAFALSE); AM_MEDIA_TYPE mtt; hr = _grabber->GetConnectedMediaType (&mtt); if (FAILED(hr)) { ATOM_LOGGER::error ("%s() %s\n", __FUNCTION__, "[DSHOW] Error getting connected media type info"); return false; } VIDEOINFOHEADER *vih = (VIDEOINFOHEADER*)mtt.pbFormat; _videoWidth = vih->bmiHeader.biWidth; _videoHeight = vih->bmiHeader.biHeight; if (mtt.cbFormat != 0) { ::CoTaskMemFree ((PVOID)mtt.pbFormat); mtt.cbFormat = 0; mtt.pbFormat = 0; } if (mtt.pUnk != NULL) { mtt.pUnk->Release (); mtt.pUnk = NULL; } _grabber->SetOneShot (FALSE); _grabber->SetBufferSamples (TRUE); #endif return true; }