// // Removes any filters in the audio graph - called before rebuilding the audio graph. // void CMediaPlayer::RemoveAllFilters() { IEnumFilters *enumFilters; HRESULT hr = _GraphBuilder->EnumFilters(&enumFilters); if (SUCCEEDED(hr)) { IBaseFilter *filter = NULL; hr = enumFilters->Next(1, &filter, NULL); while (hr == S_OK) { // // Remove the filter from the graph. // _GraphBuilder->RemoveFilter(filter); filter->Release(); // // Reset the enumeration since we removed the filter (which invalidates the enumeration). // enumFilters->Reset(); hr = enumFilters->Next(1, &filter, NULL); } enumFilters->Release(); } }
HRESULT RemoveAllFilter(IFilterGraph* filterGraph, const std::vector<IBaseFilter*> &exceptList) { HRESULT hr; IEnumFilters *enumFilters; hr = filterGraph->EnumFilters(&enumFilters); if (FAILED(hr)) { ErrorPrint("Get enum filters error",hr); return hr; } ComReleaser enumFilterReleaser(enumFilters); IBaseFilter* filter; while (S_OK == enumFilters->Next(1, &filter, NULL)) { ComReleaser filterReleaser(filter); if(std::find(exceptList.begin(), exceptList.end() , filter) == exceptList.end()) { filterGraph->RemoveFilter(filter); enumFilters->Reset(); } } return S_OK; }
//Обновляет массив m_pFGBaseFilter[], хранящий список фильтров DirectShow в текущем Filter Graph //Функция Open() вызывает эту функцию автоматически //Однако, крайне желательно вызывать её повторно перед вызовом функций, //работающих с m_pFGBaseFilter[] массивом void CDirectShow::UpdateFGFiltersArray() { IEnumFilters *pEnumFilters = NULL; if (FAILED(m_pGraphBuilder->EnumFilters(&pEnumFilters))) return; for (m_lCounter = 0; m_lCounter < E_MAX_ARR_SIZE; m_lCounter++) { SR(m_pFGBaseFilter[m_lCounter]); m_pFGBaseFilter[m_lCounter] = NULL; } pEnumFilters->Reset(); pEnumFilters->Next(E_MAX_ARR_SIZE, &m_pFGBaseFilter[0], &m_lFGFilCount); pEnumFilters->Release(); }
recChannel_t::~recChannel_t(void) { __CONTEXT("recChannel_t::~recChannel_t"); IBaseFilter * pFilter = NULL; if (camInfo->getKind() == TEST) { looper->EndThread(); } unmap(); camList->lookUp(sourceId)->setFree(true); pControl->Stop(); looper->EndThread(); delete looper; delete pSender; remap(); int hr = 0; // Enumerate the filters in the graph. IEnumFilters *pEnum = NULL; hr = pGraph->EnumFilters(&pEnum); if (SUCCEEDED(hr)) { IBaseFilter *pFilter = NULL; while (S_OK == pEnum->Next(1, &pFilter, NULL)) { pGraph->RemoveFilter(pFilter); pFilter->Release(); pEnum->Reset(); } pEnum->Release(); } pControl->Release(); pEvent->Release(); pGraph->Release(); channelList->remove(getId()); rtpSession->deleteSender (getId(), "Channel deleted"); #ifdef _WINDOWS EndThread(); TerminateThread(hThread,0); #endif }
void PlaybackControls::EmptyGraph() { IEnumFilters *pEnum = NULL; if (mpGraph) { HRESULT hr = mpGraph->EnumFilters(&pEnum); if (SUCCEEDED(hr)) { IBaseFilter *pFilter = NULL; while (S_OK == pEnum->Next(1, &pFilter, NULL)) { mpGraph->RemoveFilter(pFilter); pEnum->Reset(); pFilter->Release(); } pEnum->Release(); } } mGraphValid = false; }
HRESULT __fastcall DemolishGraphFilters(IGraphBuilder *pFilterGraph) { HRESULT hr = S_OK; IEnumFilters* pEnum = NULL; if(!pFilterGraph) return E_POINTER; hr = pFilterGraph->EnumFilters(&pEnum); if(SUCCEEDED(hr)) { IBaseFilter *pFilter=NULL; while(S_OK == pEnum->Next(1, &pFilter, NULL)) { RemoveAndDeleteFilter(pFilterGraph, &pFilter); pEnum->Reset(); //it is need because enumerator go confused //after any "RemoveAndDeleteFilter" call } pEnum->Release(); } return hr; }
void cleanUp(IGraphBuilder** pGraphBuilder) { IMediaControl* pMediaControl; vector<IBaseFilter*> filts; IEnumFilters* filterList; IBaseFilter* filt; _RPT0(_CRT_WARN,"Releasing... \n"); if (SUCCEEDED((*pGraphBuilder)->EnumFilters(&filterList))) { filterList->Reset(); while (filterList->Next(1, &filt, NULL) == S_OK) filts.add(filt); filterList->Release(); } for (int i=0;i<filts.size();i++) { #ifdef _DEBUG FILTER_INFO info; filts.at(i)->QueryFilterInfo(&info); char str[100]; WideCharToMultiByte( CP_ACP, 0, info.achName, -1, str, 100, NULL, NULL ); _RPT1(_CRT_WARN,"Releasing: %s\n",str); #endif (*pGraphBuilder)->RemoveFilter(filts.at(i)); filts.at(i)->Release(); } (*pGraphBuilder)->Release(); (*pGraphBuilder) = NULL; for (int i=0;i<newlist.size();i++) if (newlist.at(i)) delete [] newlist.at(i); newlist.clear(); _CrtDumpMemoryLeaks(); }
//------------------------------------------------------------------------------------------------- HRESULT classMMPLAYER::Play (LPSTR argName) { WCHAR wFileName[MAX_PATH]; HRESULT hr; IPin *pPin = NULL; DWORD dwAttr = GetFileAttributes(argName); if (dwAttr == (DWORD) -1) return ERROR_FILE_NOT_FOUND; #ifndef UNICODE MultiByteToWideChar(CP_ACP, 0, argName, -1, wFileName, MAX_PATH); #else lstrcpy(wFileName, argName); #endif hr = m_pGraphBuilder->AddSourceFilter(wFileName, wFileName, &m_pSourceNext); if ( SUCCEEDED(hr) ) { hr = m_pSourceNext->FindPin(L"Output", &pPin); } if ( SUCCEEDED(hr) ) { hr = m_pMediaControl->Stop(); } if (SUCCEEDED(hr)) { IEnumFilters *pFilterEnum = NULL; IBaseFilter *pFilterTemp = NULL; if(SUCCEEDED(hr = m_pGraphBuilder->EnumFilters(&pFilterEnum))){ int iFiltCount = 0; int iPos = 0; while( S_OK == pFilterEnum->Skip(1)){ iFiltCount++; } IBaseFilter **ppFilters = reinterpret_cast<IBaseFilter **>(_alloca(sizeof(IBaseFilter *) *iFiltCount)); pFilterEnum->Reset(); while(S_OK == pFilterEnum->Next(1, &(ppFilters[iPos++]), NULL)); SAFE_RELEASE(pFilterEnum); for(iPos = 0;iPos < iFiltCount; iPos++){ m_pGraphBuilder->RemoveFilter(ppFilters[iPos]); if(ppFilters[iPos] != m_pSourceCurrent) { m_pGraphBuilder->AddFilter(ppFilters[iPos], NULL); } SAFE_RELEASE(ppFilters[iPos]); } } } if ( SUCCEEDED(hr) ) { hr = m_pGraphBuilder->Render(pPin); m_pSourceCurrent = m_pSourceNext; m_pSourceNext = NULL; } SAFE_RELEASE(pPin); if ( SUCCEEDED(hr) ) { LONGLONG IIPos = 0; hr = m_pMediaSeeking->SetPositions(&IIPos, AM_SEEKING_AbsolutePositioning, &IIPos, AM_SEEKING_NoPositioning); } if ( SUCCEEDED(hr) ) { hr = m_pMediaControl->Run(); } SAFE_RELEASE(m_pSourceCurrent); return S_OK; }
BOOL CMP3Player::OnPlayAudio( TCHAR* szName, BOOL bLooped /*= FALSE */ ) { //WCHAR wstrFileName[MAX_PATH]; HRESULT hr; IPin *pPin = NULL; // Make sure that this file exists DWORD dwAttr = GetFileAttributes(szName); if (dwAttr == (DWORD) -1) { return FALSE; } // OPTIMIZATION OPPORTUNITY // This will open the file, which is expensive. To optimize, this // should be done earlier, ideally as soon as we knew this was the // next file to ensure that the file load doesn't add to the // filter swapping time & cause a hiccup. // // Add the new source filter to the graph. (Graph can still be running) hr = m_pGraphBuilder->AddSourceFilter(szName,szName, &m_pSourceNext); // Get the first output pin of the new source filter. Audio sources // typically have only one output pin, so for most audio cases finding // any output pin is sufficient. if (SUCCEEDED(hr)) { hr = m_pSourceNext->FindPin(L"Output", &pPin); } // Stop the graph if (SUCCEEDED(hr)) { hr = m_pMediaControl->Stop(); } // Break all connections on the filters. You can do this by adding // and removing each filter in the graph if (SUCCEEDED(hr)) { IEnumFilters *pFilterEnum = NULL; if (SUCCEEDED(hr = m_pGraphBuilder->EnumFilters(&pFilterEnum))) { int iFiltCount = 0; int iPos = 0; // Need to know how many filters. If we add/remove filters during the // enumeration we'll invalidate the enumerator while (S_OK == pFilterEnum->Skip(1)) { iFiltCount++; } // Allocate space, then pull out all of the IBaseFilter **ppFilters = reinterpret_cast<IBaseFilter **> (_alloca(sizeof(IBaseFilter *) * iFiltCount)); pFilterEnum->Reset(); while (S_OK == pFilterEnum->Next(1, &(ppFilters[iPos++]), NULL)); SAFE_RELEASE(pFilterEnum); for (iPos = 0; iPos < iFiltCount; iPos++) { m_pGraphBuilder->RemoveFilter(ppFilters[iPos]); // Put the filter back, unless it is the old source if (ppFilters[iPos] != m_pSourceCurrent) { m_pGraphBuilder->AddFilter(ppFilters[iPos], NULL); } SAFE_RELEASE(ppFilters[iPos]); } } } // We have the new ouput pin. Render it if (SUCCEEDED(hr)) { hr = m_pGraphBuilder->Render(pPin); m_pSourceCurrent = m_pSourceNext; m_pSourceNext = NULL; } SAFE_RELEASE(pPin); SAFE_RELEASE(m_pSourceNext); // In case of errors // Re-seek the graph to the beginning if (SUCCEEDED(hr)) { LONGLONG llPos = 0; hr = m_pMediaSeeking->SetPositions(&llPos, AM_SEEKING_AbsolutePositioning, &llPos, AM_SEEKING_NoPositioning); } // Start the graph if (SUCCEEDED(hr)) { hr = m_pMediaControl->Run(); } // Release the old source filter. SAFE_RELEASE(m_pSourceCurrent); return TRUE; }
void recChannel_t::refresh_channel(bool all) { __CONTEXT("recChannel_t::refresh_channel"); pControl->Stop(); #ifdef _WINDOWS if (fControl) { fControl->CWnd::ShowWindow(SW_HIDE); } #endif if (pSource!=NULL) { pGraph->RemoveFilter(pSource); camInfo->setFree(true); } // Enumerate the filters in the graph. IEnumFilters *pEnum = NULL; int hr = pGraph->EnumFilters(&pEnum); if (SUCCEEDED(hr)) { IBaseFilter *pFilter = NULL; while (S_OK == pEnum->Next(1, &pFilter, NULL)) { CLSID filterId; pFilter->GetClassID(&filterId); if(filterId == CLSID_VideoRenderer || filterId == CLSID_VideoMixingRenderer) { IVideoWindow *pWindowInfo = NULL; pFilter->QueryInterface(IID_IVideoWindow, (void **)&pWindowInfo); pWindowInfo->get_Height(&windowInfo.heigth); pWindowInfo->get_Left(&windowInfo.left); pWindowInfo->get_Top(&windowInfo.top); pWindowInfo->get_Width(&windowInfo.width); pWindowInfo->put_AutoShow(OAFALSE); pWindowInfo->put_Visible(OAFALSE); if (all) { pGraph->RemoveFilter(pFilter); pFilter->Release(); pEnum->Reset(); pWindowInfo->Release(); } }else{ pGraph->RemoveFilter(pFilter); pFilter->Release(); pEnum->Reset(); } } pEnum->Release(); } if (all) { pGraph->Release(); hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph); errorCheck(hr); } hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl); errorCheck(hr); }
HRESULT recChannel_t::map(void) { __CONTEXT("recChannel_t::map"); int hr = 0; IBaseFilter * pFilter = NULL; IBaseFilter * pFilter2 = NULL; IPin * pVideoInputPin = NULL; pControl->StopWhenReady(); mapping = true; pOutput = camInfo->output; if (remaped){ //refresh Codec BW before creation pSender->sampleGrabber->BWController->refreshBW(); pSender->rebind(); hr = pGraph->Render(pOutput); { // Enumerate the filters in the graph. IEnumFilters *pEnum = NULL; int hr = pGraph->EnumFilters(&pEnum); if (SUCCEEDED(hr)) { IBaseFilter *pFilter = NULL; pEnum->Reset(); while (S_OK == pEnum->Next(1, &pFilter, NULL)) { CLSID filterId; pFilter->GetClassID(&filterId); if(filterId == CLSID_AviSplitter) { IEnumPins * pEnumpin = NULL; hr = pFilter->EnumPins(&pEnumpin); if (!hr) { IPin * pPin = NULL; pEnumpin->Reset(); while (pEnumpin->Next(1, &pPin, 0) == S_OK) { bool break_loop = false; AM_MEDIA_TYPE * mediaType; IEnumMediaTypes * enumMedia = NULL; hr = pPin->EnumMediaTypes(&enumMedia); if(!hr) { enumMedia->Reset(); while(enumMedia->Next(1,&mediaType , NULL) == S_OK) { if (mediaType->majortype == MEDIATYPE_Audio) { pPin->Disconnect(); pGraph->Render(pPin); pPin->Release(); break_loop = true; break; } } enumMedia->Release(); if (break_loop) break; } } pEnumpin->Release(); } } pFilter->Release(); } pEnum->Release(); } } pipeCreated = true; if (hr) { errorCheck(hr); NOTIFY("[recChannel_t::map]WARNING :: Can't render actual format, restoring default settings...\r\n"); capInfo.heigth = DEFAULT_CAPTURE_HEIGTH; capInfo.width = DEFAULT_CAPTURE_WIDTH; ql_t<AM_MEDIA_TYPE *> auxFormats = camInfo->getFormatList(); pSender->SetActualCodec(DEFAULT_CODEC_STR); } } if (fullScreen){ set_full_screen(true); }else{ hr = setWindowGeometry(windowInfo); errorCheck(hr); } // IVideoWindow *pWindowInfo = NULL; // hr = pGraph->QueryInterface(IID_IVideoWindow, (void **)&pWindowInfo); // if (!hr) // { // wchar_t wtext[100]; // long windowStyle,windowStyleEx; // lText(wtext,title); // pWindowInfo->get_WindowStyle(&windowStyle); // pWindowInfo->get_WindowStyleEx(&windowStyleEx); // windowStyle = windowStyle + DEFAULT_WINDOW_PROPS - DEFAULT_WINDOW_NON_PROPS; // windowStyleEx = windowStyleEx - WS_EX_APPWINDOW; // pWindowInfo->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS); // pWindowInfo->put_WindowStyleEx(WS_EX_TOOLWINDOW); // pWindowInfo->put_Caption(wtext); // //#ifdef _WINDOWS // if (camInfo->getKind() == MEDIA) // { // fControl->setGeometry(windowInfo); // // } //#endif ////Ares daemon don't show local windows on ////recChannels //#ifndef __ARES // if (camInfo->getKind() != SHARED) // { // pWindowInfo->put_Visible(OATRUE); // pWindowInfo->put_AutoShow(OATRUE); // } // else // { //#endif // pWindowInfo->put_Visible(OAFALSE); // pWindowInfo->put_AutoShow(OAFALSE); //#ifndef __ARES // } //#endif // // pWindowInfo->Release(); // setOwner(); // } IMediaSeeking * pSeek = NULL; pGraph->QueryInterface(IID_IMediaSeeking,(void **)&pSeek); if (pSeek)pSeek->SetRate(1); pControl->Run(); if (camInfo->getKind() == SHARED) { camInfo->RunSource(); } if (camInfo->getKind() == TEST) { if (pSeek) pSeek->SetRate(0.5); looper->Run(); } remaped = false; return hr; }
HRESULT FindRenderer(IGraphBuilder *pGB, const GUID *mediatype, IBaseFilter **ppFilter) { HRESULT hr; IEnumFilters *pEnum = NULL; IBaseFilter *pFilter = NULL; IPin *pPin; ULONG ulFetched, ulInPins, ulOutPins; BOOL bFound=FALSE; // Verify graph builder interface if (!pGB) return E_NOINTERFACE; // Verify that a media type was passed if (!mediatype) return E_POINTER; // Clear the filter pointer in case there is no match if (ppFilter) *ppFilter = NULL; // Get filter enumerator hr = pGB->EnumFilters(&pEnum); if (FAILED(hr)) return hr; pEnum->Reset(); // Enumerate all filters in the graph while(!bFound && (pEnum->Next(1, &pFilter, &ulFetched) == S_OK)) { #ifdef DEBUG // Read filter name for debugging purposes FILTER_INFO FilterInfo; TCHAR szName[256]; hr = pFilter->QueryFilterInfo(&FilterInfo); if (SUCCEEDED(hr)) { // Show filter name in debugger #ifdef UNICODE lstrcpy(szName, FilterInfo.achName); #else WideCharToMultiByte(CP_ACP, 0, FilterInfo.achName, -1, szName, 256, 0, 0); #endif FilterInfo.pGraph->Release(); } #endif // Find a filter with one input and no output pins hr = CountFilterPins(pFilter, &ulInPins, &ulOutPins); if (FAILED(hr)) break; if ((ulInPins == 1) && (ulOutPins == 0)) { // Get the first pin on the filter pPin=0; pPin = GetInPin(pFilter, 0); // Read this pin's major media type AM_MEDIA_TYPE type= {0}; hr = pPin->ConnectionMediaType(&type); if (FAILED(hr)) break; // Is this pin's media type the requested type? // If so, then this is the renderer for which we are searching. // Copy the interface pointer and return. if (type.majortype == *mediatype) { // Found our filter *ppFilter = pFilter; bFound = TRUE;; } // This is not the renderer, so release the interface. else pFilter->Release(); // Delete memory allocated by ConnectionMediaType() FreeMediaType(type); } else { // No match, so release the interface pFilter->Release(); } } pEnum->Release(); return hr; }