Esempio n. 1
0
int VideoCapture::Connect(const wchar_t* deviceName)
{
        if (GetStatus() != OK)
                return -1;

        hr = m_pCapture->SetFiltergraph(m_pGraph);
        if (FAILED(hr)) 
                return -2;

        IBaseFilter* pSrcFilter = NULL;
        hr = FindCaptureDevice(deviceName, &pSrcFilter);
        if (FAILED(hr)) 
                return -3;        

        // Add Capture filter to our graph.
        hr = m_pGraph->AddFilter(pSrcFilter, L"Video Capture");
        if (FAILED(hr)) {
                pSrcFilter->Release();
                return -3;
        }

        //Add Sample Grabber filter
        IBaseFilter* pGrabberFilter = NULL;
        hr = AddSampleGrabber(&pGrabberFilter);
        if (FAILED(hr)) {
                pSrcFilter->Release();
                return -4;
        }

        IBaseFilter* pNullFilter = NULL;
        hr = AddNullRenderer(&pNullFilter);
        if (FAILED(hr)) {
                pGrabberFilter->Release();
                pSrcFilter->Release();
                return -5;
        }        


        // Render the preview pin on the video capture filter        
        hr = m_pCapture->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,
                                      pSrcFilter, pGrabberFilter, pNullFilter);
        if (FAILED(hr)) {
                pNullFilter->Release();
                pGrabberFilter->Release();
                pSrcFilter->Release();
                return -6;
        }
        
        pNullFilter->Release();
        pGrabberFilter->Release();
        pSrcFilter->Release();

        m_Status = CONNECTED;        

        hr = GetMediaType();
        if (FAILED(hr))                 
                return -7;        
                
        return 0;
}
Esempio n. 2
0
void VideoCapture::EnumResolutions()
{
	int iCount, iSize, iChosen=-1;
	IBaseFilter *pSource;
   	CComPtr <ICaptureGraphBuilder2> pCaptB;
	VIDEO_STREAM_CONFIG_CAPS caps;
	HRESULT hr;
	bool response;

	IAMStreamConfig *pConfig;

	devices_resolutions = new DeviceResolutions[nDevices];

	pCaptB.CoCreateInstance(CLSID_CaptureGraphBuilder2);

	for (unsigned int iDevice=0; iDevice<nDevices; iDevice++)
	{
		response = BindFilter(iDevice, &pSource);

		hr = pCaptB->FindInterface(
        &PIN_CATEGORY_CAPTURE,
        &MEDIATYPE_Video,
        pSource,
        IID_IAMStreamConfig,
        (void**)&pConfig);

		if (!SUCCEEDED(hr))
		{
			pSource->Release();
			devices_resolutions[iDevice].nResolutions = 0;
			continue;
		}

		pConfig->GetNumberOfCapabilities(&iCount, &iSize);

		devices_resolutions[iDevice].SetNResolutions(iCount);


		for(int i=0; i < iCount; i++) {
			AM_MEDIA_TYPE *pmt;
			if( pConfig->GetStreamCaps(i, &pmt, reinterpret_cast<BYTE*>(&caps)) == S_OK ) {

				VIDEOINFOHEADER *pVih = 
					reinterpret_cast<VIDEOINFOHEADER*>(pmt->pbFormat);
				
				devices_resolutions[iDevice].x[i] = caps.InputSize.cx;
				devices_resolutions[iDevice].y[i] = caps.InputSize.cy;
				devices_resolutions[iDevice].color_space[i] = pmt->subtype;
				devices_resolutions[iDevice].compression[i] = pVih->bmiHeader.biCompression;
				DeleteMediaType(pmt);
			}
		}

		pSource->Release();
		pConfig->Release();

		pSource = 0;
	}
}
static gboolean
gst_dshowvideodec_destroy_graph_and_filters (GstDshowVideoDec * vdec)
{
  HRESULT hres;

  if (vdec->mediafilter) {
    vdec->mediafilter->Stop();
  }

  if (vdec->fakesrc) {
    if (vdec->filtergraph) {
      IBaseFilter *filter;
      hres = vdec->fakesrc->QueryInterface(IID_IBaseFilter,
          (void **) &filter);
      if (SUCCEEDED (hres)) {
        vdec->filtergraph->RemoveFilter(filter);
        filter->Release();
      }
    }

    vdec->fakesrc->Release();
    vdec->fakesrc = NULL;
  }
  if (vdec->decfilter) {
    if (vdec->filtergraph)
      vdec->filtergraph->RemoveFilter(vdec->decfilter);
    vdec->decfilter->Release();
    vdec->decfilter = NULL;
  }
  if (vdec->fakesink) {
    if (vdec->filtergraph) {
      IBaseFilter *filter;
      hres = vdec->fakesink->QueryInterface(IID_IBaseFilter,
          (void **) &filter);
      if (SUCCEEDED (hres)) {
        vdec->filtergraph->RemoveFilter(filter);
        filter->Release();
      }
    }

    vdec->fakesink->Release();
    vdec->fakesink = NULL;
  }
  if (vdec->mediafilter) {
    vdec->mediafilter->Release();
    vdec->mediafilter = NULL;
  }
  if (vdec->filtergraph) {
    vdec->filtergraph->Release();
    vdec->filtergraph = NULL;
  }

  vdec->setup = FALSE;

  return TRUE;
}
Esempio n. 4
0
HRESULT CAccessSys::BuildCapture(void)
{
	HRESULT hr;
	IBaseFilter *pSrcFilter = NULL;
	IBaseFilter *pMpeg2Filter = NULL;

	if (b_buildCapture){
		return S_OK;
	}

	// Get DirectShow interfaces
	hr = GetInterfaces();
	if (FAILED(hr))
	{
		Msg(TEXT("Failed to get video interfaces!  hr=0x%x"), hr);
		return hr;
	}


	pSrcFilter = p_streams[0].p_device_filter;

	// Render the preview pin on the video capture filter
	// Use this instead of g_pGraph->RenderFile
	p_VideoFilter = new CMyCapVideoFilter(this, NULL, &m_lock, NULL);
    hr = p_graph->AddFilter(p_VideoFilter, L"video filter");
	hr = p_capture_graph_builder2->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
                                                pSrcFilter, NULL, p_VideoFilter);
	if (FAILED(hr))
	{
		Msg(TEXT("Couldn't render the video capture stream to my filter.  hr=0x%x\r\n")
			TEXT("The capture device may already be in use by another application.\r\n\r\n")
			TEXT("The sample will now close."), hr);
		pSrcFilter->Release();
		return hr;
	}

	pSrcFilter = p_streams[1].p_device_filter;

	p_AudioFilter = new CMyCapAudioFilter(this, NULL, &m_alock, NULL);
    hr = p_graph->AddFilter(p_AudioFilter, L"audio filter");
	hr = p_capture_graph_builder2->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Audio,
                                                pSrcFilter, NULL, p_AudioFilter);

	if (FAILED(hr))
	{
		Msg(TEXT("Couldn't render the audio capture stream to my audio filter.  hr=0x%x\r\n")
			TEXT("The capture device may already be in use by another application.\r\n\r\n")
			TEXT("The sample will now close."), hr);
		pSrcFilter->Release();
		return hr;
	}
    b_buildCapture = true;
	return S_OK;
}
Esempio n. 5
0
//
// The GraphBuilder interface provides a FindFilterByName() method,
// which provides similar functionality to the method below.
// This local method is provided for educational purposes.
//
IBaseFilter *FindFilterFromName(IGraphBuilder *pGB, LPTSTR szNameToFind)
{
    USES_CONVERSION;

    HRESULT hr;
    IEnumFilters *pEnum = NULL;
    IBaseFilter *pFilter = NULL;
    ULONG cFetched;
    BOOL bFound = FALSE;

    // Verify graph builder interface
    if (!pGB)
        return NULL;

    // Get filter enumerator
    hr = pGB->EnumFilters(&pEnum);
    if (FAILED(hr))
        return NULL;

    // Enumerate all filters in the graph
    while((pEnum->Next(1, &pFilter, &cFetched) == S_OK) && (!bFound))
    {
        FILTER_INFO FilterInfo;
        TCHAR szName[256];
        
        hr = pFilter->QueryFilterInfo(&FilterInfo);
        if (FAILED(hr))
        {
            pFilter->Release();
            pEnum->Release();
            return NULL;
        }

        // Compare this filter's name with the one we want
        lstrcpy(szName, W2T(FilterInfo.achName));
        if (! lstrcmp(szName, szNameToFind))
        {
            bFound = TRUE;
        }

        FilterInfo.pGraph->Release();

        // If we found the right filter, don't release its interface.
        // The caller will use it and release it later.
        if (!bFound)
            pFilter->Release();
        else
            break;
    }
    pEnum->Release();

    return (bFound ? pFilter : NULL);
}
Esempio n. 6
0
//
// FindSubtitleFilter
//
// be careful with this method, can cause deadlock with CSync::Stop, so should only be called in Run()
HRESULT CTsReaderFilter::FindSubtitleFilter()
{
  if( m_pDVBSubtitle )
  {
    return S_OK;
  }
  //LogDebug( "FindSubtitleFilter - start");

  IEnumFilters * piEnumFilters = NULL;
  if (GetFilterGraph() && SUCCEEDED(GetFilterGraph()->EnumFilters(&piEnumFilters)))
  {
    IBaseFilter * pFilter;
    while (piEnumFilters->Next(1, &pFilter, 0) == NOERROR )
    {
      FILTER_INFO filterInfo;
      if (pFilter->QueryFilterInfo(&filterInfo) == S_OK)
      {
        if (!wcsicmp(L"MediaPortal DVBSub2", filterInfo.achName))
        {
          HRESULT fhr = pFilter->QueryInterface( IID_IDVBSubtitle2, ( void**)&m_pDVBSubtitle );
          assert( fhr == S_OK);
          //LogDebug("Testing that DVBSub2 works");
          m_pDVBSubtitle->Test(1);
        }
        filterInfo.pGraph->Release();
      }
      pFilter->Release();
      pFilter = NULL;
    }
    piEnumFilters->Release();
  }
  //LogDebug( "FindSubtitleFilter - End");
  return S_OK;
}
HRESULT CDShowUtility::FindFilterInterface(IGraphBuilder *pGraph, REFGUID iid, void **ppUnk)
{
    if (!pGraph || !ppUnk) 
    {
        return E_POINTER;
    }

    HRESULT hr = E_FAIL;
    IEnumFilters *pEnum = NULL;
    IBaseFilter *pF = NULL;

    if (FAILED(pGraph->EnumFilters(&pEnum)))
    {
        return E_FAIL;
    }

    //分别调用 Queryinterface, 枚举filter Graph 中的所有Filter 
    while (S_OK == pEnum->Next(1, &pF, 0))
    {
        hr = pF->QueryInterface(iid, ppUnk);
        pF->Release();

        if (SUCCEEDED(hr))
        {
            break;
        }
    }

    pEnum->Release();
    return hr;    
}
BOOL VerifyVMR9(void)
{
    HRESULT hr;

    // Verify that the VMR exists on this system
    IBaseFilter* pBF = NULL;
    hr = CoCreateInstance(CLSID_VideoMixingRenderer9, NULL,
                          CLSCTX_INPROC,
                          IID_IBaseFilter,
                          (LPVOID *)&pBF);
    if(SUCCEEDED(hr))
    {
        pBF->Release();
        return TRUE;
    }
    else
    {
        MessageBox(NULL,
            TEXT("This application requires the VMR-9.\r\n\r\n")

            TEXT("The VMR-9 is not enabled when viewing through a Remote\r\n")
            TEXT(" Desktop session. You can run VMR-enabled applications only\r\n") 
            TEXT("on your local computer.\r\n\r\n")

            TEXT("\r\nThis sample will now exit."),

            TEXT("Video Mixing Renderer (VMR9) capabilities are required"), MB_OK);

        return FALSE;
    }
}
Esempio n. 9
0
HRESULT CBDReaderFilter::FindSubtitleFilter()
{
  if (m_pDVBSubtitle)
    return S_OK;

  HRESULT hr = S_FALSE;
  ULONG fetched = 0;

  IEnumFilters * piEnumFilters = NULL;
  if (GetFilterGraph() && SUCCEEDED(GetFilterGraph()->EnumFilters(&piEnumFilters)))
  {
    IBaseFilter * pFilter;
    while (piEnumFilters->Next(1, &pFilter, &fetched) == NOERROR)
    {
      FILTER_INFO filterInfo;
      if (pFilter->QueryFilterInfo(&filterInfo) == S_OK)
      {
        if (!wcsicmp(L"MediaPortal DVBSub3", filterInfo.achName))
          hr = pFilter->QueryInterface(IID_IDVBSubtitle3, (void**)&m_pDVBSubtitle);

        filterInfo.pGraph->Release();
      }
      pFilter->Release();
      pFilter = NULL;
    }
    piEnumFilters->Release();
  }

  return hr;
}
Esempio n. 10
0
HRESULT VideoCapture::FindCaptureDevice(const wchar_t* deviceName, IBaseFilter** ppSrcFilter)
{
        ICreateDevEnum *pSysDevEnum = NULL;
        hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
                              IID_ICreateDevEnum, (void **)&pSysDevEnum);
        if (FAILED(hr)) 
                return hr;        

        // Obtain a class enumerator for the video input devices category.
        IEnumMoniker *pEnumCat = NULL;
        hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0);
        if (hr == S_OK) {
                // Enumerate the monikers.
                IMoniker *pMoniker = NULL;
                ULONG cFetched;
                while (pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK) {
                        IPropertyBag *pPropBag;
                        hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
                                                     (void **)&pPropBag);
                        if (SUCCEEDED(hr)) {
                                // To retrieve the filter's friendly name
                                VARIANT varName;
                                VariantInit(&varName);
                                hr = pPropBag->Read(L"FriendlyName", &varName, 0);
                                if (SUCCEEDED(hr)) {
                                        if (wcscmp(deviceName, varName.bstrVal) == 0) {
                                                m_DeviceName = varName.bstrVal;
                                                VariantClear(&varName);    

                                                IBaseFilter* pFilter;
                                                hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter,
                                                                            (void**)&pFilter);
                                                if (SUCCEEDED(hr)) {
                                                        *ppSrcFilter = pFilter;
                                                        (*ppSrcFilter)->AddRef();
                                                        pFilter->Release();
                                                }
                                                
                                                pPropBag->Release();        
                                                pMoniker->Release();
                                                pEnumCat->Release();
                                                pSysDevEnum->Release();
                                                return hr;
                                        }                                        
                                }
                                VariantClear(&varName);                                
                                pPropBag->Release();
                        }
                        pMoniker->Release();
                }
                pEnumCat->Release();
        }
        else {
                pSysDevEnum->Release(); 
                return hr;
        }

        pSysDevEnum->Release();
        return -1;        
}
Esempio n. 11
0
HRESULT FindFilterInterface(
	IGraphBuilder *pGraph, // Pointer to the Filter Graph Manager.
	REFGUID iid,           // IID of the interface to retrieve.
	void **ppUnk)          // Receives the interface pointer.
{
	if (!pGraph || !ppUnk) return E_POINTER;

	HRESULT hr = E_FAIL;
	IEnumFilters *pEnum = NULL;
	IBaseFilter *pF = NULL;
	if (FAILED(pGraph->EnumFilters(&pEnum)))
	{
		return E_FAIL;
	}
	// Query every filter for the interface.
	while (S_OK == pEnum->Next(1, &pF, 0))
	{
		hr = pF->QueryInterface(iid, ppUnk);
		pF->Release();
		if (SUCCEEDED(hr))
		{
			break;
		}
	}
	pEnum->Release();
	return hr;
}
Esempio n. 12
0
	HRESULT GetPinCountForOneType(IUnknown* pUnk, PIN_DIRECTION direction, LPDWORD pPinCount)
	{
		(*pPinCount) = 0;
		IBaseFilter* pBaseFilter = NULL;
		HRESULT hr = pUnk->QueryInterface(IID_IBaseFilter, (VOID**)&pBaseFilter);
		if (SUCCEEDED(hr))
		{
			IEnumPins* pEnumPins = NULL;
			hr = pBaseFilter->EnumPins(&pEnumPins);
			if (SUCCEEDED(hr))
			{
				pEnumPins->Reset();
				if (SUCCEEDED(hr))
				{
					IPin* pPin = NULL;
					BOOL bFound = FALSE;
					DWORD dwFetched = 0;
					while (((pEnumPins->Next(1, &pPin, &dwFetched)) == S_OK) && !bFound)
					{
						PIN_DIRECTION fetchedDir;
						hr = pPin->QueryDirection(&fetchedDir);
						if (SUCCEEDED(hr) && (fetchedDir == direction))
						{
							(*pPinCount)++;
						}
						pPin->Release();
					}
				}
				pEnumPins->Release();
			}
			pBaseFilter->Release();
		}
		return hr;
	}
Esempio n. 13
0
	HRESULT GetAMConfigForSinglePin(IUnknown* pUnk, PIN_DIRECTION direction, IAMStreamConfig** ppConfig)
	{
		IBaseFilter* pBaseFilter = NULL;
		HRESULT hr = pUnk->QueryInterface(IID_IBaseFilter, (void**)&pBaseFilter);
		if (SUCCEEDED(hr))
		{
			IEnumPins* pEnumPins = NULL;
			hr = pBaseFilter->EnumPins(&pEnumPins);
			if (SUCCEEDED(hr))
			{
				pEnumPins->Reset();
				if (SUCCEEDED(hr))
				{
					IPin* pPin = NULL;
					BOOL bFound = FALSE;
					while (((pEnumPins->Next(1, &pPin, NULL)) == S_OK) && !bFound)
					{
						PIN_DIRECTION fetchedDir;
						hr = pPin->QueryDirection(&fetchedDir);
						if (SUCCEEDED(hr) && (fetchedDir == direction))
						{
							hr = pPin->QueryInterface(IID_IAMStreamConfig, (void**)ppConfig);
							bFound = SUCCEEDED(hr);
						}
						pPin->Release();
					}
				}
				pEnumPins->Release();
			}
			pBaseFilter->Release();
		}
		return hr;
	}
Esempio n. 14
0
/* 创建VMR,添加、设置VMR */
HRESULT CVMR_Capture::InitializeWindowlessVMR(HWND hWnd)
{
    IBaseFilter* pVmr = NULL;

    // 创建VMR
    HRESULT hr = CoCreateInstance(CLSID_VideoMixingRenderer, NULL,
                                  CLSCTX_INPROC, IID_IBaseFilter, (void**)&pVmr);
    if (SUCCEEDED(hr)) 
    {	
		//添加VMR到滤波器链表中
        hr = m_pGB->AddFilter(pVmr, L"Video Mixing Renderer");
        if (SUCCEEDED(hr)) 
        {
            // 设置无窗口渲染模式
            IVMRFilterConfig* pConfig;
            hr = pVmr->QueryInterface(IID_IVMRFilterConfig, (void**)&pConfig);
            if( SUCCEEDED(hr)) 
            {
                pConfig->SetRenderingMode(VMRMode_Windowless);
                pConfig->Release();
            }

			// 设置传入的窗口为显示窗口
            hr = pVmr->QueryInterface(IID_IVMRWindowlessControl, (void**)&m_pWC);
            if( SUCCEEDED(hr)) 
            {
                m_pWC->SetVideoClippingWindow(hWnd);
            }
        }
        pVmr->Release();
    }

    return hr;
}
Esempio n. 15
0
//
//  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();
    }
}
Esempio n. 16
0
//Добавляет к текущему Filter Graph оболочку 'DMOWrapper' и вызывает инициализацию
//DMO объекта с именем lpwDMOName
//Перед вызовом этой функции необходимо вызвать UpdateDMOArray(...) (если она не вызывалась)
//В случае ошибки функция вернет значение меньше нуля
int CDirectShow::AddDMOToFilterGraph(LPCWSTR lpwDMOName)
{
	if (!m_pGraphBuilder) return -1;
	if (!m_lDMOCount) return -1;
	IBaseFilter *pDMOWBaseFilter = NULL;
	IDMOWrapperFilter *pDMOWrapper;
	for (m_lCounter = 0; m_lCounter < m_lDMOCount; m_lCounter++)
	{
		if (_wcsicmp(m_lpwDMONames[m_lCounter], lpwDMOName) == 0)
		{
			if (FAILED(CoCreateInstance(CLSID_DMOWrapperFilter, NULL, CLSCTX_INPROC,
				IID_IBaseFilter, (LPVOID *)&pDMOWBaseFilter))) return -1;
			if (FAILED(pDMOWBaseFilter->QueryInterface(IID_IDMOWrapperFilter,
				(LPVOID *)&pDMOWrapper))) return -1;
			pDMOWrapper->Init(m_cDMOCLSIDs[m_lCounter], m_gidRecentDMOCat);
			pDMOWrapper->Release();
			m_pGraphBuilder->AddFilter(pDMOWBaseFilter, m_lpwDMONames[m_lCounter]);
			pDMOWBaseFilter->Release();
		}
		else
		{
			if (m_lCounter >= (m_lDMOCount - 1))
				return -1; else continue;
		}
	}
	return 0;
}
Esempio n. 17
0
/*****************************Private*Routine******************************\
* VerifyVMR
*
\**************************************************************************/
BOOL VerifyVMR(void)
{
    HRESULT hres;

    CoInitialize(NULL);

    // Verify that the VMR exists on this system
    IBaseFilter* pBF = NULL;
    hres = CoCreateInstance(CLSID_VideoMixingRenderer,
        NULL,
        CLSCTX_INPROC,
        IID_IBaseFilter,
        (LPVOID *)&pBF);
    if(SUCCEEDED(hres))
    {
        pBF->Release();
        CoUninitialize();
        return TRUE;
    }
    else
    {
        MessageBox(NULL, 
            TEXT("This application requires the Video Mixing Renderer, which is present\r\n")
            TEXT("only on Windows XP.\r\n\r\n")
            TEXT("The Video Mixing Renderer (VMR) is also not enabled when viewing a \r\n")
            TEXT("remote Windows XP machine through a Remote Desktop session.\r\n")
            TEXT("You can run VMR-enabled applications only on your local machine.")
            TEXT("\r\n\r\nThis sample will now exit."),
            TEXT("Video Mixing Renderer capabilities are required"), MB_OK);

        CoUninitialize();
        return FALSE;
    }
}
Esempio n. 18
0
HRESULT FindInterfaceAnywhere(
	IGraphBuilder *pGraph, 
	REFGUID iid, 
	void **ppUnk)
{
	if (!pGraph || !ppUnk) return E_POINTER;
	HRESULT hr = E_FAIL;
	IEnumFilters *pEnum = 0;
	if (FAILED(pGraph->EnumFilters(&pEnum)))
	{
		return E_FAIL;
	}
	// Loop through every filter in the graph.
	IBaseFilter *pF = 0;
	while (S_OK == pEnum->Next(1, &pF, 0))
	{
		hr = pF->QueryInterface(iid, ppUnk);
		if (FAILED(hr))
		{
			// The filter does not expose the interface, but maybe
			// one of its pins does.
			hr = FindPinInterface(pF, iid, ppUnk);
		}
		pF->Release();
		if (SUCCEEDED(hr))
		{
			break;
		}
	}
	pEnum->Release();
	return hr;
}
Esempio n. 19
0
HRESULT
recChannel_t::remap(void)
{
     __CONTEXT("recChannel_t::remap");
	IBaseFilter * pFilter = NULL;
	int hr = 0;	
	pControl->StopWhenReady();
	IPin * pin = NULL;

	hr = pGraph->FindFilterByName(L"AVI Decompressor",&pFilter);
	
	if (!hr) 
	{
		hr = pGraph->RemoveFilter(pFilter);
		errorCheck(hr);
		pFilter->Release();
	}

	hr = pGraph->FindFilterByName(L"Video Renderer",&pFilter);
	if (!hr)
	{
	
		while ((hr = GetConnectedPin(pFilter,PINDIR_INPUT,&pin))==0)
		{
			pin->Disconnect();
		}
	}

	if (pOutput) pOutput->Disconnect();

	remaped = true;
	return 0;

}
Esempio n. 20
0
/*  Display filter or pin */
CDisp::CDisp(IUnknown *pUnk)
{
    IBaseFilter *pf;
    HRESULT hr = pUnk->QueryInterface(IID_IBaseFilter, (void **)&pf);
    if(SUCCEEDED(hr))
    {
        FILTER_INFO fi;
        hr = pf->QueryFilterInfo(&fi);
        if(SUCCEEDED(hr))
        {
            QueryFilterInfoReleaseGraph(fi);

            m_pString = new TCHAR[lstrlenW(fi.achName)  + 1];
            if(m_pString)
            {
                wsprintf(m_pString, TEXT("%ls"), fi.achName);
            }
        }

        pf->Release();

        return;
    }

    IPin *pp;
    hr = pUnk->QueryInterface(IID_IPin, (void **)&pp);
    if(SUCCEEDED(hr))
    {
        CDisp::CDisp(pp);
        pp->Release();
        return;
    }
}
HRESULT CVMR_Capture::InitializeWindowlessVMR(HWND hWnd)
{
    IBaseFilter* pVmr = NULL;

    // Create the VMR and add it to the filter graph.
    HRESULT hr = CoCreateInstance(CLSID_VideoMixingRenderer, NULL,
                                  CLSCTX_INPROC, IID_IBaseFilter, (void**)&pVmr);
    if (SUCCEEDED(hr)) 
    {
        hr = m_pGB->AddFilter(pVmr, L"Video Mixing Renderer");
        if (SUCCEEDED(hr)) 
        {
            // Set the rendering mode and number of streams.  
            IVMRFilterConfig* pConfig;

            hr = pVmr->QueryInterface(IID_IVMRFilterConfig, (void**)&pConfig);
            if( SUCCEEDED(hr)) 
            {
                pConfig->SetRenderingMode(VMRMode_Windowless);
                pConfig->Release();
            }

            hr = pVmr->QueryInterface(IID_IVMRWindowlessControl, (void**)&m_pWC);
            if( SUCCEEDED(hr)) 
            {
                m_pWC->SetVideoClippingWindow(hWnd);
                
            }
        }
        pVmr->Release();
    }

    return hr;
}
void DirectShowPlayerService::doReleaseAudioOutput(QMutexLocker *locker)
{
    m_pendingTasks |= m_executedTasks & (Play | Pause);

    if (IMediaControl *control = com_cast<IMediaControl>(m_graph, IID_IMediaControl)) {
        control->Stop();
        control->Release();
    }

    IBaseFilter *decoder = getConnected(m_audioOutput, PINDIR_INPUT);
    if (!decoder) {
        decoder = m_audioOutput;
        decoder->AddRef();
    }

    // {DCFBDCF6-0DC2-45f5-9AB2-7C330EA09C29}
    static const GUID iid_IFilterChain = {
        0xDCFBDCF6, 0x0DC2, 0x45f5, {0x9A, 0xB2, 0x7C, 0x33, 0x0E, 0xA0, 0x9C, 0x29} };

    if (IFilterChain *chain = com_cast<IFilterChain>(m_graph, iid_IFilterChain)) {
        chain->RemoveChain(decoder, m_audioOutput);
        chain->Release();
    } else {
        m_graph->RemoveFilter(m_audioOutput);
    }

    decoder->Release();

    m_executedTasks &= ~SetAudioOutput;

    m_loop->wake();
}
IBaseFilter *DirectShowPlayerService::getConnected(
        IBaseFilter *filter, PIN_DIRECTION direction) const
{
    IBaseFilter *connected = 0;

    IEnumPins *pins = 0;

    if (SUCCEEDED(filter->EnumPins(&pins))) {
        for (IPin *pin = 0; pins->Next(1, &pin, 0) == S_OK; pin->Release()) {
            PIN_DIRECTION dir;
            if (SUCCEEDED(pin->QueryDirection(&dir)) && dir == direction) {
                IPin *peer = 0;
                if (SUCCEEDED(pin->ConnectedTo(&peer))) {
                    PIN_INFO info;

                    if (SUCCEEDED(peer->QueryPinInfo(&info))) {
                        if (connected) {
                            qWarning("DirectShowPlayerService::getConnected: "
                                "Multiple connected filters");
                            connected->Release();
                        }
                        connected = info.pFilter;
                    }
                    peer->Release();
                }
            }
        }
        pins->Release();
    }
    return connected;
}
//Show Filter in FilterGpragh
int show_filters_in_filtergraph(IGraphBuilder *pGraph){
	printf("Filters in FilterGpragh=======\n");
	USES_CONVERSION;
	IEnumFilters *pFilterEnum=NULL;
	if(FAILED(pGraph->EnumFilters(&pFilterEnum))){
		pFilterEnum->Release();
		return -1;
	}
	pFilterEnum->Reset();
	IBaseFilter * filter = NULL;
	ULONG fetchCount = 0;
	//Pin Info
	while (SUCCEEDED(pFilterEnum->Next(1, &filter, &fetchCount)) && fetchCount){
		if (!filter){
			continue;
		}
		FILTER_INFO FilterInfo;
		if (FAILED(filter->QueryFilterInfo(&FilterInfo))){
			continue;
		}
		printf("[%s]\n",W2A(FilterInfo.achName));
		filter->Release();
	}
	pFilterEnum->Release();
	printf("==============================\n");
	return 0;
}
Esempio n. 25
0
//查找Filter上某一个接口,只要找到FilterGraph上某一个Filter有该接口即返回
BOOL FindFilterInterface(IGraphBuilder* pGraphBuilder, REFGUID iid, void** ppUnk)
{
	if(!pGraphBuilder || !ppUnk)
		return FALSE;

	IEnumFilters* pEnumFilter = NULL;
	IBaseFilter* pFilter = NULL;

	if(FAILED(pGraphBuilder->EnumFilters(&pEnumFilter)))
	{
		return FALSE;
	}

	HRESULT hr = E_FAIL;
	while(S_OK == pEnumFilter->Next(1,&pFilter,NULL))
	{
		hr = pFilter->QueryInterface(iid,ppUnk);
		pFilter->Release();
		if(SUCCEEDED(hr))
		{
			pEnumFilter->Release();
			return TRUE;
		}
	}

	pEnumFilter->Release();
	return FALSE;
}
Esempio n. 26
0
/*****************************Public*Routine******************************\
* FindInterfaceFromFilterGraph
*
\**************************************************************************/
HRESULT
CMovie::FindInterfaceFromFilterGraph(
    REFIID iid, // interface to look for
    LPVOID *lp  // place to return interface pointer in
    )
{
    IEnumFilters* pEF;
    IBaseFilter*  pFilter;

    // Grab an enumerator for the filter graph.
    HRESULT hr = m_Fg->EnumFilters(&pEF);

    if(FAILED(hr))
    {
        return hr;
    }

    // Check out each filter.
    while(pEF->Next(1, &pFilter, NULL) == S_OK)
    {
        hr = pFilter->QueryInterface(iid, lp);
        pFilter->Release();

        if(SUCCEEDED(hr))
        {
            break;
        }
    }

    pEF->Release();

    return hr;
}
Esempio n. 27
0
void CFilterProp::ShowProperties()
{
	if ( !pGB ) return;

    HRESULT hr;
    IBaseFilter *pFilter = NULL;
    TCHAR szNameToFind[128];
    ISpecifyPropertyPages *pSpecify;

    // Read the current filter name from the list box
    int nCurSel = m_ListFilters.GetCurSel();
    m_ListFilters.GetText(nCurSel, szNameToFind);

    // Read the current list box name and find it in the graph
    pFilter = FindFilterFromName(szNameToFind);
    if (!pFilter)
        return;

    // Discover if this filter contains a property page
    hr = pFilter->QueryInterface(IID_ISpecifyPropertyPages, (void **)&pSpecify);
    if (SUCCEEDED(hr)) 
    {
        do 
        {
            FILTER_INFO FilterInfo;
            hr = pFilter->QueryFilterInfo(&FilterInfo);
            if (FAILED(hr))
                break;

            CAUUID caGUID;
            hr = pSpecify->GetPages(&caGUID);
            if (FAILED(hr))
                break;

            pSpecify->Release();
        
            // Display the filter's property page
            OleCreatePropertyFrame(
                m_hWnd,                 // Parent window
                0,                      // x (Reserved)
                0,                      // y (Reserved)
                FilterInfo.achName,     // Caption for the dialog box
                1,                      // Number of filters
                (IUnknown **)&pFilter,  // Pointer to the filter 
                caGUID.cElems,          // Number of property pages
                caGUID.pElems,          // Pointer to property page CLSIDs
                0,                      // Locale identifier
                0,                      // Reserved
                NULL                    // Reserved
            );
            CoTaskMemFree(caGUID.pElems);
            FilterInfo.pGraph->Release(); 

        } while(0);
    }

    pFilter->Release();

}
Esempio n. 28
0
/******************************Public*Routine******************************\
* AddVideoMixingRendererToFG
*
\**************************************************************************/
HRESULT
CMovie::AddVideoMixingRendererToFG()
{
    IBaseFilter* pBF = NULL;
    HRESULT hRes = CoCreateInstance(CLSID_VideoMixingRenderer9, NULL, CLSCTX_INPROC,
                                    IID_IBaseFilter, (LPVOID *)&pBF);

    if(SUCCEEDED(hRes))
    {
        hRes = m_Fg->AddFilter(pBF, L"Video Mixing Renderer 9");

        if(SUCCEEDED(hRes))
        {
            // Test VMRConfig, VMRMonitorConfig
            IVMRFilterConfig9* pConfig;
            HRESULT hRes2 = pBF->QueryInterface(IID_IVMRFilterConfig9, (LPVOID *)&pConfig);
            if(SUCCEEDED(hRes2))
            {
                hRes2 = pConfig->SetNumberOfStreams(2);
                hRes2 = pConfig->SetRenderingMode(VMR9Mode_Windowless);
                //hRes2 = pConfig->SetRenderingPrefs(RenderPrefs_AllowOverlays);
                pConfig->Release();
            }

            IVMRMonitorConfig9* pMonitorConfig;
            HRESULT hRes3 = pBF->QueryInterface(IID_IVMRMonitorConfig9, (LPVOID *)&pMonitorConfig);
            if(SUCCEEDED(hRes3))
            {
                UINT iCurrentMonitor;
                HRESULT hr4 = pMonitorConfig->GetMonitor(&iCurrentMonitor);
                pMonitorConfig->Release();
            }

            hRes = pBF->QueryInterface(IID_IVMRWindowlessControl9, (LPVOID *)&m_Wc);
        }
    }

    if(pBF)
    {
        pBF->Release();
    }

    if(SUCCEEDED(hRes))
    {
        HRESULT hr = m_Wc->SetVideoClippingWindow(m_hwndApp);
        hr = m_Wc->SetAspectRatioMode(VMR_ARMODE_LETTER_BOX);
    }
    else
    {
        if(m_Wc)
        {
            m_Wc->Release();
            m_Wc = NULL;
        }
    }

    return hRes;
}
Esempio n. 29
0
/******************************Public*Routine******************************\
* AddVideoMixingRendererToFG
*
\**************************************************************************/
HRESULT
CMpegMovie::AddVideoMixingRendererToFG()
{
	if ( m_Vw ) {

		return FALSE;

	}	else {


    IBaseFilter* pBF = NULL;
    HRESULT hRes = CoCreateInstance(CLSID_VideoMixingRenderer,
        NULL,
        CLSCTX_INPROC,
        IID_IBaseFilter,
        (LPVOID *)&pBF);


    if(SUCCEEDED(hRes))
    {
        hRes = m_Fg->AddFilter(pBF, L"Video Mixing Renderer");

        if(SUCCEEDED(hRes))
        {
				hRes = SetRenderingMode(pBF, VMRMode_Renderless);
				
				hRes = pBF->QueryInterface(IID_IVMRSurfaceAllocatorNotify,
							(LPVOID *)&m_San);

				hRes = CreateDefaultAllocatorPresenter();
				hRes = m_San->AdviseSurfaceAllocator(MY_USER_ID, this);

        }
    }

    if(pBF)
    {
        pBF->Release();
    }

    if(SUCCEEDED(hRes))
    {
        HRESULT hr = m_Wc->SetVideoClippingWindow(m_hwndApp);
        hr = m_Wc->SetAspectRatioMode(VMR_ARMODE_LETTER_BOX);
    }
    else
    {
        if(m_Wc)
        {
            m_Wc->Release();
            m_Wc = NULL;
        }
    }

    return hRes;

	}
}
Esempio n. 30
0
BOOL CVMR9Graph::BuildAndRenderGraph(bool withSound)
{
	USES_CONVERSION;

  int nLayer = 0;
  HRESULT hr;

	// ENSURE that a valid graph builder is available
	if (m_pGraphBuilder == NULL) {
		BOOL bRet = BuildFilterGraph(withSound);
		if (!bRet) return bRet;
	}

  // ENSURE that the filter graph is in a stop state
	OAFilterState filterState;
	m_pMediaControl->GetState(500, &filterState);
	if (filterState != State_Stopped) {
		m_pMediaControl->Stop();
	}

  	// CHECK a source filter availaibility for the layer
	if (m_srcFilterArray[nLayer] == NULL) {
		char pszFilterName[10];
		sprintf(pszFilterName, "SRC%02d", nLayer);
		IBaseFilter* pBaseFilter = NULL;
		hr = m_pGraphBuilder->AddSourceFilter(A2W(m_pszFileName), A2W(pszFilterName), &pBaseFilter);
		if (FAILED(hr)) {
			ReportError("Could not find a source filter for this file", hr);
			return FALSE;
		}
		m_srcFilterArray[nLayer] = pBaseFilter;
	} else {
		// suppress the old src filter
		IBaseFilter* pBaseFilter = m_srcFilterArray[nLayer];
		RemoveFilterChain(pBaseFilter, m_pVMRBaseFilter);
		pBaseFilter->Release();
		m_srcFilterArray[nLayer] = NULL;
		// create a new src filter
		char pszFilterName[10];
		sprintf(pszFilterName, "SRC%02d", nLayer);
		hr = m_pGraphBuilder->AddSourceFilter(A2W(m_pszFileName), A2W(pszFilterName), &pBaseFilter);
		m_srcFilterArray[nLayer] = pBaseFilter;
		if (FAILED(hr)) {
			m_srcFilterArray[nLayer] = NULL;
			ReportError("Could not load the file", hr);
			return FALSE;
		}
	}

	// RENDER the graph
	BOOL bRet = RenderGraph();
	if (!bRet) return bRet;

  return TRUE;
}