MMSGraph.cpp
资源名称:p2p_vod.rar [点击查看]
上传用户:liguizhu
上传日期:2015-11-01
资源大小:2422k
文件大小:21k
源码类别:
P2P编程
开发平台:
Visual C++
- /*
- * Openmysee
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
- #include "stdafx.h"
- #include "mmsgraph.h"
- #include "configFile.h"
- #include "string.h"
- // {6B6D0800-9ADA-11d0-A520-00A0D10129C0}
- DEFINE_GUID(CLSID_NetShowSource,
- 0x6b6d0800, 0x9ada, 0x11d0, 0xa5, 0x20, 0x0, 0xa0, 0xd1, 0x1, 0x29, 0xc0);
- //////////////////////////////////////////////
- // Only for Debug
- static DWORD g_dwRegister;
- static HRESULT AddGraphToRot(IUnknown *pUnkGraph, DWORD *pdwRegister)
- {
- #ifdef _DEBUG
- IMoniker * pMoniker;
- IRunningObjectTable *pROT;
- HRESULT hr;
- hr = GetRunningObjectTable(0, &pROT);
- if (FAILED(hr)) return hr;
- WCHAR wsz[128];
- wsprintfW(wsz, L"FilterGraph %08x pid %08x", (DWORD_PTR)pUnkGraph, GetCurrentProcessId());
- hr = CreateItemMoniker(L"!", wsz, &pMoniker);
- if (SUCCEEDED(hr))
- {
- hr = pROT->Register(0, pUnkGraph, pMoniker, pdwRegister);
- pMoniker->Release();
- }
- pROT->Release();
- return hr;
- #endif
- return S_OK;
- }
- static void RemoveGraphFromRot(DWORD pdwRegister)
- {
- #ifdef _DEBUG
- IRunningObjectTable *pROT;
- if (SUCCEEDED(GetRunningObjectTable(0, &pROT)))
- {
- pROT->Revoke(pdwRegister);
- pROT->Release();
- }
- #endif
- }
- /////////////////////////////////////////////////////////////////
- // CMMSGraph
- CMMSGraph::CMMSGraph(string strChannel, string strMMSAddr, HRESULT *hr)
- {
- m_pGB = NULL;
- m_pMC = NULL;
- m_pMMSSource = NULL;
- m_pSink = NULL;
- m_pAsfAcmHandler = NULL;
- m_pAsfIcmHandler = NULL;
- m_pAudioSmartTee = NULL;
- m_pTVConfig = NULL;
- m_pMMSInfo = new MMSGRAPHINFO;
- m_pMMSInfo->fDataRate = 0.0;
- m_pMMSInfo->fTotalBytes=0;
- m_pMMSInfo->m_oldtotalbyte=0;
- m_pMMSInfo->mmsState = INIT;
- m_pMMSInfo->llTimeEscaped = 0;
- m_pMMSInfo->strChannelName = strChannel;
- m_pMMSInfo->strMMSAddr = strMMSAddr;
- m_pMMSInfo->llTimeEscaped = 0;
- m_pMMSInfo->m_time=0;
- m_bReconnecting = false;
- *hr = Initialize();
- }
- CMMSGraph::~CMMSGraph()
- {
- m_bReconnecting = false;
- SAFE_RELEASE(m_pSink);
- SAFE_RELEASE(m_pTVConfig);
- Uninitialize();
- if(m_pMMSInfo)
- {
- delete m_pMMSInfo;
- m_pMMSInfo = NULL;
- }
- }
- STDMETHODIMP CMMSGraph::Run()
- {
- if(m_pMC)
- return m_pMC->Run();
- return E_FAIL;
- }
- STDMETHODIMP CMMSGraph::Stop()
- {
- if(m_pMC)
- return m_pMC->Stop();
- return E_FAIL;
- }
- STDMETHODIMP CMMSGraph::Pause()
- {
- if(m_pMC)
- return m_pMC->Pause();
- return E_FAIL;
- }
- STDMETHODIMP CMMSGraph::Uninitialize()
- {
- RemoveGraphFromRot(g_dwRegister);
- DisassembleGraph();
- // release all objects
- SAFE_RELEASE(m_pGB);
- SAFE_RELEASE(m_pMC);
- // release COM lib
- CoUninitialize();
- return S_OK;
- }
- STDMETHODIMP CMMSGraph::BuildGraph(bool bAssumeAudioFirst)
- {
- // add/config source filter
- if(FAILED(CreateAddFilter(CLSID_NetShowSource, &m_pMMSSource)))
- {
- AfxMessageBox("can not create & add mms source filter!");
- return E_FAIL;
- }
- IFileSourceFilter *pSF;
- if(FAILED(m_pMMSSource->QueryInterface(IID_IFileSourceFilter, (VOID**)&pSF)))
- {
- AfxMessageBox("can not query interface of mms source filter!");
- return E_FAIL;
- }
- WCHAR wstrAddr[1024];
- MultiByteToWideChar(CP_ACP,
- MB_PRECOMPOSED | MB_USEGLYPHCHARS,
- m_pMMSInfo->strMMSAddr.data(),
- -1,
- wstrAddr,
- sizeof(wstrAddr) / sizeof(WCHAR));
- HRESULT hr;
- hr = pSF->Load(wstrAddr, NULL);
- if(FAILED(hr))
- {
- string strError;
- char s[100];
- wsprintf(s, "无法读取mms流:%s,请检查这个流是否可用。", m_pMMSInfo->strMMSAddr.data());
- strError.append(s);
- //AfxMessageBox(strError.data());
- return FALSE;
- }
- pSF->Release();
- /*
- IEnumPins* enumPin = NULL;
- hr = m_pMMSSource->EnumPins(&enumPin);
- IPin* pins = NULL
- hr = enumPin->Next(1, &pins, NULL);
- AM_MEDIA_TYPE type;
- hr = pins->ConnectionMediaType(&type);
- if(type.formattype == FORMAT_VideoInfo) {
- pins->ConnectedTo(
- }
- */
- if(m_pSink == NULL) {
- // add our sink filter
- if(FAILED(CreateAddFilter(CLSID_TVStreamSink, &m_pSink)))
- {
- AfxMessageBox("can not create & add capture filter!");
- return E_FAIL;
- }
- if(FAILED(m_pSink->QueryInterface(IID_ITVSouceConfig, (VOID**)&m_pTVConfig)))
- {
- AfxMessageBox("can not query interface of captureserver!");
- return E_FAIL;
- }
- }
- else {
- // No filter name specified, cannot convert
- // try to add it to the filter graph
- hr = m_pGB->AddFilter(m_pSink, NULL);
- if(hr != S_OK)
- {
- AfxMessageBox("can not add capture filter!");
- return E_FAIL;
- }
- }
- // connect graph
- // audio channel
- BOOL bHasAudio = TRUE;
- BOOL bHasVideo = TRUE;
- if(SUCCEEDED(FindASFHandler("ASF ACM Handler")))
- {
- VERIFY(SUCCEEDED(m_pGB->AddFilter(m_pAsfAcmHandler, NULL)));
- hr = ConnectPins(m_pMMSSource, bAssumeAudioFirst?__T("Stream 1"):__T("Stream 2"), m_pAsfAcmHandler,NULL);
- if(hr != S_OK) {
- DisassembleGraph();
- hr = BuildGraph(false);
- return hr;
- }
- hr = ConnectPins(m_pAsfAcmHandler, NULL, m_pSink, __T("Audio"));
- if(hr != S_OK) {
- ASSERT(0);
- bHasAudio = FALSE;
- RemoveFilter(m_pAsfAcmHandler);
- SAFE_RELEASE(m_pAsfAcmHandler);
- }
- /*
- if((FAILED(ConnectPins(m_pMMSSource, __T("Stream 1"), m_pAsfAcmHandler,NULL) &&
- FAILED(ConnectPins(m_pMMSSource, __T("Stream 2"), m_pAsfAcmHandler,NULL)) ||
- FAILED(ConnectPins(m_pAsfAcmHandler, NULL, m_pSink, __T("Audio"))))))
- {
- ASSERT(0);
- bHasAudio = FALSE;
- RemoveFilter(m_pAsfAcmHandler);
- SAFE_RELEASE(m_pAsfAcmHandler);
- }
- */
- }
- else
- bHasAudio = FALSE;
- // video channel
- if(SUCCEEDED(FindASFHandler("ASF ICM Handler")))
- {
- VERIFY(SUCCEEDED(m_pGB->AddFilter(m_pAsfIcmHandler, NULL)));
- hr = ConnectPins(m_pMMSSource, bAssumeAudioFirst?__T("Stream 2"):__T("Stream 1"), m_pAsfIcmHandler,NULL);
- if(hr != S_OK) {
- DisassembleGraph();
- hr = BuildGraph(false);
- return hr;
- }
- hr = ConnectPins(m_pAsfIcmHandler, NULL, m_pSink, __T("Video"));
- if(hr != S_OK) {
- ASSERT(0);
- bHasVideo = FALSE;
- RemoveFilter(m_pAsfIcmHandler);
- SAFE_RELEASE(m_pAsfIcmHandler);
- }
- /*
- if((FAILED(ConnectPins(m_pMMSSource, __T("Stream 2"), m_pAsfIcmHandler,NULL) &&
- FAILED(ConnectPins(m_pMMSSource, __T("Stream 1"), m_pAsfIcmHandler,NULL)) ||
- FAILED(ConnectPins(m_pAsfIcmHandler, NULL, m_pSink, __T("Video"))))))
- {
- ASSERT(0);
- bHasVideo = FALSE;
- RemoveFilter(m_pAsfIcmHandler);
- SAFE_RELEASE(m_pAsfIcmHandler);
- }
- */
- #ifdef TIME_EXPIRE
- /// 如果过了2006-03-21日,就返回错误
- tm expire_tm;
- memset(&expire_tm, 0, sizeof(expire_tm));
- expire_tm.tm_year = 106;
- expire_tm.tm_mon = 2;
- expire_tm.tm_mday = 21;
- time_t expire_seconds = mktime(&expire_tm);
- time_t now;
- time( &now ); /* Get time as long integer. */
- if(now > expire_seconds)
- return E_FAIL;
- #endif
- }
- else
- bHasVideo = FALSE;
- if(!bHasVideo && !bHasAudio)
- {
- AfxMessageBox("Sorry, MMS Server cant get media. plz check mms address is right!");
- return E_FAIL;
- }
- if(!bHasVideo)
- {
- // AfxMessageBox("warning:no video captured!");
- //return S_FALSE;
- m_pTVConfig->SetAudioOrVideoOnly(TRUE); // set audio only
- }
- if(!bHasAudio)
- {
- AfxMessageBox("warning:no audio captured!");
- return S_FALSE;
- }
- return 1 ;
- }
- STDMETHODIMP CMMSGraph::DisassembleGraph()
- {
- Stop();
- // remove all filters from graph
- RemoveFilter(m_pMMSSource);
- RemoveFilter(m_pSink);
- if(m_pAsfAcmHandler)
- RemoveFilter(m_pAsfAcmHandler);
- if(m_pAsfAcmHandler)
- RemoveFilter(m_pAsfIcmHandler);
- if(m_pAudioSmartTee)
- RemoveFilter(m_pAudioSmartTee);
- SAFE_RELEASE(m_pMMSSource);
- SAFE_RELEASE(m_pAsfIcmHandler);
- SAFE_RELEASE(m_pAsfAcmHandler);
- SAFE_RELEASE(m_pAudioSmartTee);
- return S_OK;
- }
- MMSGRAPHINFO *CMMSGraph::GetMMSGraphInfo()
- {
- ////////////Get the value of the ResStartTime
- CString str_path;
- GetModuleFileName(NULL,str_path.GetBuffer(MAX_PATH),MAX_PATH);
- str_path.ReleaseBuffer();
- int index = str_path.ReverseFind('\');
- str_path= str_path.Left(index+1);
- int ResStartTime = 10;
- static bool reconnecting = false;
- // speed
- m_pMMSInfo->fDataRate = m_pTVConfig->GetCompressedSpeed();
- m_pMMSInfo->fTotalBytes=m_pTVConfig->GetTotalBytes(); //get current totalbytes
- if(m_pMMSInfo->fTotalBytes>m_pMMSInfo->m_oldtotalbyte) //if we got new data
- {
- if (m_pMMSInfo->mmsState==RUNNING)
- m_pMMSInfo->llTimeEscaped++;
- m_pMMSInfo->m_time=0; //recount
- }
- else if(m_pMMSInfo->mmsState != STOPPED )//if data stopped
- {
- m_pMMSInfo->m_time++;
- if(m_pTVConfig->EndOfStream() || m_pMMSInfo->m_time >= ResStartTime) {
- if(!m_bReconnecting) {
- m_bReconnecting = true;
- HRESULT ret = this->DisassembleGraph();
- ret = this->BuildGraph();
- ret = this->Run();
- m_bReconnecting = false;
- }
- m_pMMSInfo->m_time=0; //recount
- }
- }
- if (m_pMMSInfo->m_time==0)
- m_pMMSInfo->m_oldtotalbyte=m_pMMSInfo->fTotalBytes;
- // state
- OAFilterState os;
- m_pMC->GetState(100, &os);
- if(os == State_Running)
- m_pMMSInfo->mmsState = RUNNING;
- else if(os == State_Stopped) {
- m_pMMSInfo->mmsState = STOPPED;
- if(m_bReconnecting)
- m_pMMSInfo->mmsState = RECONNECTING;
- }
- else if(os == State_Paused)
- m_pMMSInfo->mmsState = PAUSED;
- else
- m_pMMSInfo->mmsState = INIT;
- // time escaped
- return m_pMMSInfo;
- }
- STDMETHODIMP CMMSGraph::CreateAddFilter(CLSID clsidFilter,
- IBaseFilter** ppIFilter,
- LPCTSTR pstrFilterName)
- {
- HRESULT hr;
- ASSERT(m_pGB);
- ASSERT(ppIFilter);
- (*ppIFilter) = NULL;
- // try to instantiate the filter
- hr = CoCreateInstance(clsidFilter,
- NULL,
- CLSCTX_INPROC,
- IID_IBaseFilter,
- (LPVOID*)(ppIFilter));
- if(FAILED(hr))
- {
- TRACE("Could not instantiate filter");
- return hr;
- }
- // Check for unicode or not
- #ifndef _UNICODE
- if(pstrFilterName)
- {
- // not unicode, we need to unicodify the string
- WCHAR wstrFilterName[256];
- MultiByteToWideChar(CP_ACP,
- MB_PRECOMPOSED | MB_USEGLYPHCHARS,
- pstrFilterName,
- -1,
- wstrFilterName,
- sizeof(wstrFilterName) / sizeof(WCHAR));
- // try to add it to the filter graph
- hr = m_pGB->AddFilter(*ppIFilter, wstrFilterName);
- }
- else
- {
- // No filter name specified, cannot convert
- // try to add it to the filter graph
- hr = m_pGB->AddFilter(*ppIFilter, NULL);
- }
- #else
- // already unicode, no need to change anything
- // try to add it to the filter graph
- hr = m_pGB->AddFilter(*ppIFilter, pstrFilterName);
- #endif
- // check the result of the operation
- if(FAILED(hr))
- {
- TRACE("Could not add filter to filter graphn");
- // free the filter definitely
- (*ppIFilter)->Release();
- (*ppIFilter) = NULL;
- return hr;
- }
- // that's it
- return hr;
- }
- STDMETHODIMP CMMSGraph::RemoveFilter(IBaseFilter* pIFilter)
- {
- HRESULT hr;
- // Parameters...
- if(!pIFilter)
- // DON'T return an error, this is expected
- return NOERROR;
- ASSERT(m_pGB);
- // Just remove it from the graph
- hr = m_pGB->RemoveFilter(pIFilter);
- // Check the result
- if(FAILED(hr))
- TRACE("Could not remove filter from filter graphn");
- return hr;
- }
- STDMETHODIMP CMMSGraph::ConnectPins(IBaseFilter* pIFilterOutput,
- LPCTSTR pstrPinNameOutput,
- IBaseFilter* pIFilterInput,
- LPCTSTR pstrPinNameInput,
- AM_MEDIA_TYPE* pmt)
- {
- HRESULT hr;
- ASSERT(m_pGB);
- // Parameters...
- if((!pIFilterOutput) || (!pIFilterInput))
- {
- //ASSERT(pIFilterOutput && pIFilterInput);
- TRACE("ConnectPins called with NULL parametern");
- return E_INVALIDARG;
- }
- // Find the first pin
- IPin* pIPinOutput = FindPinOnFilter(pIFilterOutput,
- pstrPinNameOutput,
- PINDIR_OUTPUT);
- if(!pIPinOutput)
- {
- // ASSERT(pIPinOutput);
- return E_FAIL;
- }
- // Find the second pin
- IPin* pIPinInput = FindPinOnFilter(pIFilterInput,
- pstrPinNameInput,
- PINDIR_INPUT);
- if(!pIPinInput)
- {
- //ASSERT(pIPinInput);
- // release the other pin
- pIPinOutput->Release();
- return E_FAIL;
- }
- if(FAILED(pIPinOutput->Disconnect()))
- {
- //ASSERT(FALSE);
- return E_FAIL;
- }
- if(FAILED(pIPinInput->Disconnect()))
- {
- //ASSERT(FALSE);
- return E_FAIL;
- }
- // Now just connect the two pins
- if(NULL == pmt || pmt->cbFormat == 0)
- hr = m_pGB->Connect(pIPinOutput, pIPinInput);
- else
- hr = m_pGB->ConnectDirect(pIPinOutput, pIPinInput, pmt);
- if(FAILED(hr))
- TRACE("Could not connect pins!");
- // Release the two pins and return the result
- pIPinOutput->Release();
- pIPinInput->Release();
- return hr;
- }
- STDMETHODIMP CMMSGraph::DisconnectPin(IBaseFilter *pIFilter,
- LPCTSTR pstrPinName,
- PIN_DIRECTION dir)
- {
- HRESULT hr;
- ASSERT(m_pGB);
- // Parameters...
- if(!pIFilter)
- // DON'T fail on this, it is expected
- return NOERROR;
- // Find the pin
- IPin* pIPin = FindPinOnFilter(pIFilter, pstrPinName, dir);
- if(!pIPin)
- {
- TRACE("Could not find specified filter pinn");
- return E_FAIL;
- }
- // Find the pin it's connected to
- IPin* pIPinConnected;
- hr = pIPin->ConnectedTo(&pIPinConnected);
- if((FAILED(hr)) || (!pIPinConnected))
- {
- // Function call failed, pin not connected, nothing to do!
- pIPin->Release();
- return NOERROR;
- }
- // Try to disconnect the input pin first
- if (dir == PINDIR_INPUT)
- {
- // ok now disconnect both of them
- hr = m_pGB->Disconnect(pIPin);
- if(FAILED(hr))
- {
- // just forget everything
- ASSERT(SUCCEEDED(hr));
- pIPin->Release();
- pIPinConnected->Release();
- TRACE("Disconnect failed on input pinn");
- return hr;
- }
- hr = m_pGB->Disconnect(pIPinConnected);
- if(FAILED(hr))
- {
- ASSERT(SUCCEEDED(hr));
- TRACE("Disconnect failed on output pinn");
- }
- }
- else
- {
- // ok now disconnect both of them
- hr = m_pGB->Disconnect(pIPinConnected);
- if(FAILED(hr))
- {
- ASSERT(SUCCEEDED(hr));
- // just forget everything
- pIPin->Release();
- pIPinConnected->Release();
- TRACE("Disconnect failed on input pinn");
- return hr;
- }
- hr = m_pGB->Disconnect(pIPin);
- if(FAILED(hr))
- {
- ASSERT(SUCCEEDED(hr));
- TRACE("Disconnect failed on output pinn");
- }
- }
- // Just release the two pins and return last result
- pIPin->Release();
- pIPinConnected->Release();
- return hr;
- }
- STDMETHODIMP_(BOOL) CMMSGraph::IsConnected(IBaseFilter *pFilter,
- LPCTSTR pstrPinName,
- PIN_DIRECTION pd)
- {
- ASSERT(m_pGB);
- // Parameters...
- if((!pFilter))
- {
- ASSERT(pFilter);
- TRACE("ConnectPins called with NULL parametern");
- return FALSE;
- }
- // Find the pin
- IPin* pIPin = FindPinOnFilter(pFilter,
- pstrPinName,
- pd);
- if(!pIPin)
- {
- ASSERT(pIPin);
- return FALSE;
- }
- IPin *pNextPin = NULL;
- pIPin->ConnectedTo(&pNextPin);
- if(!pNextPin)
- {
- return FALSE;
- }
- pIPin->Release();
- pNextPin->Release();
- //That's it...
- return TRUE;
- }
- STDMETHODIMP_(IPin*) CMMSGraph::FindPinOnFilter(IBaseFilter* pIFilter,
- LPCTSTR pstrPinName,
- PIN_DIRECTION dir)
- {
- HRESULT hr;
- IEnumPins* pIEnumPins;
- IPin* pIPin;
- PIN_INFO pi;
- ASSERT(m_pGB);
- // Parameters...
- if(!pIFilter)
- return NULL;
- // Enumerate pins on the filter
- hr = pIFilter->EnumPins(&pIEnumPins);
- if(FAILED(hr))
- // pin was not found!
- return NULL;
- // Loop till we find no more pins
- IPin* pIPinFound = NULL;
- while( (!pIPinFound) && (pIEnumPins->Next(1, &pIPin, NULL)==S_OK) )
- {
- // Is this the pin?
- hr = pIPin->QueryPinInfo(&pi);
- if(!FAILED(hr))
- {
- // check if it is the right direction
- if(pi.dir == dir)
- {
- // Let the graph builder find the right filter
- TCHAR strFoundPinName[256];
- #ifndef _UNICODE
- // not unicode, we need to de-unicodify the returned pin name
- WideCharToMultiByte(CP_ACP, NULL,
- pi.achName, -1,
- strFoundPinName, sizeof(strFoundPinName),
- NULL, NULL);
- #else
- // just make a copy of the string
- lstrcpyn(strFoundPinName, pi.achName, sizeof(strFoundPinName));
- #endif
- // check if there is a pin name specified
- if(!pstrPinName)
- {
- // no name specified, take the first pin found
- pIPinFound = pIPin;
- pIPinFound->AddRef();
- }
- // check if we have the right pin name
- else if(lstrcmp(strFoundPinName, pstrPinName)==0)
- {
- // yes we have!
- pIPinFound = pIPin;
- pIPinFound->AddRef();
- }
- }
- // release the PIN_INFO data
- pi.pFilter->Release();
- }
- // release the IPin pointer
- pIPin->Release();
- }
- // Finished with the enumerator, let it go (be free)
- pIEnumPins->Release();
- // Return whatever we have found
- return pIPinFound;
- }
- HRESULT CMMSGraph::FindASFHandler(string strFilterName)
- {
- HRESULT hr;
- IMoniker *pMoniker =NULL;
- ULONG cFetched;
- // Create the system device enumerator
- ICreateDevEnum* pDevEnum = NULL;
- hr = CoCreateInstance (CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,
- IID_ICreateDevEnum, (void **) &pDevEnum);
- if (FAILED(hr))
- {
- TRACE1(TEXT("Couldn't create system enumerator! hr=0x%x"), hr);
- return hr;
- }
- IEnumMoniker *pClassEnum = NULL;
- hr = pDevEnum->CreateClassEnumerator(CLSID_LegacyAmFilterCategory, &pClassEnum, 0);
- if (FAILED(hr))
- {
- pDevEnum->Release();
- TRACE1(TEXT("Couldn't create class enumerator! hr=0x%x"), hr);
- return hr;
- }
- if (pClassEnum == NULL)
- {
- pDevEnum->Release();
- return E_FAIL;
- }
- BOOL bFinded = FALSE;
- while (S_OK == (pClassEnum->Next (1, &pMoniker, &cFetched)))
- {
- IPropertyBag *pPropBag;
- hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
- (void **)&pPropBag);
- if (SUCCEEDED(hr))
- {
- VARIANT varName;
- VariantInit(&varName);
- hr = pPropBag->Read(L"FriendlyName", &varName, 0);
- if (SUCCEEDED(hr))
- {
- int cch = lstrlenW(varName.bstrVal) + 1;
- CHAR* lpszFilterName = new char[cch * 2];
- if (!lpszFilterName)
- return E_OUTOFMEMORY;
- WideCharToMultiByte(GetACP(), 0, varName.bstrVal, -1,
- lpszFilterName, cch, NULL, NULL);
- string str;
- str.append(lpszFilterName);
- if(strFilterName == str)
- {
- if(str == "ASF ACM Handler")
- {
- pMoniker->BindToObject(NULL, NULL,
- IID_IBaseFilter,
- (VOID**)&m_pAsfAcmHandler);
- bFinded = TRUE;
- }
- else if(str == "ASF ICM Handler")
- {
- pMoniker->BindToObject(NULL, NULL,
- IID_IBaseFilter,
- (VOID**)&m_pAsfIcmHandler);
- bFinded = TRUE;
- }
- else
- ASSERT(FALSE);
- delete [] lpszFilterName;
- VariantClear(&varName);
- pPropBag->Release();
- pMoniker->Release();
- break;
- }
- delete [] lpszFilterName;
- }
- VariantClear(&varName);
- pPropBag->Release();
- }
- pMoniker->Release();
- }
- pClassEnum->Release();
- pDevEnum->Release();
- if(bFinded)
- return S_OK;
- return E_FAIL;
- }
- STDMETHODIMP CMMSGraph::Initialize()
- {
- HRESULT hr = CoInitialize(NULL);
- if (FAILED(hr))
- {
- TRACE0("ERROR - Could not initialize COM library");
- return hr;
- }
- // Create the filter graph manager and query for interfaces.
- hr = CoCreateInstance(CLSID_FilterGraph,
- NULL,
- CLSCTX_INPROC_SERVER,
- IID_IGraphBuilder,
- (void **)&m_pGB);
- if (FAILED(hr))
- {
- TRACE0("ERROR - Could not create the Filter Graph Manager.");
- return hr;
- }
- hr = m_pGB->QueryInterface(IID_IMediaControl, (void **)&m_pMC);
- if (FAILED(hr))
- {
- TRACE0("ERROR - Could not Get IMediaControl");
- return hr;
- }
- AddGraphToRot(m_pGB, &g_dwRegister);
- if(!BuildGraph())
- {
- return -1 ;
- }
- return S_OK;
- }