Esempio n. 1
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. 2
0
IPin * GetOutPin( IBaseFilter * pFilter, int PinNum )
{
    IEnumPins * pEnum = 0;
    HRESULT hr = pFilter->EnumPins( &pEnum );
    pEnum->Reset( );
    ULONG Fetched;
    do
    {
        Fetched = 0;
        IPin * pPin = 0;
        pEnum->Next( 1, &pPin, &Fetched );
        if( Fetched )
        {
            PIN_DIRECTION pd;
            pPin->QueryDirection( &pd);
            pPin->Release( );
            if( pd == PINDIR_OUTPUT )
            {
                if( PinNum == 0 )
                {
                    pEnum->Release( );
                    return pPin;
                }
                PinNum--;
            }
        }
    }
    while( Fetched );
    pEnum->Release( );
    return NULL;
}
Esempio n. 3
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. 4
0
bool isRenderer(IBaseFilter* filt)
{
	if (!filt) return false;

	IEnumPins*	pinList;
	int nrOutput = 0;
	int nrInput = 0;
	IPin*		pin = NULL;

	if (FAILED(filt->EnumPins(&pinList))) return false;
	pinList->Reset();
	while (pinList->Next(1, &pin, NULL) == S_OK)
	{
		if (getPinInfo(pin).dir == PINDIR_OUTPUT) nrOutput++;
		else nrInput++;
		pin->Release();
	}
	pinList->Release();

	#ifdef _DEBUG
		FILTER_INFO info;
		filt->QueryFilterInfo(&info);
		char str[100];
		WideCharToMultiByte( CP_ACP, 0, info.achName, -1, str, 100, NULL, NULL );
		_RPT0(_CRT_WARN,str);
		_RPT2(_CRT_WARN," %d %d\n", nrOutput, nrInput);
	#endif

	return nrOutput == 0 && nrInput == 1;  // the only filters that have no outputs are renderers
}
void videoInputCamera::NukeDownstream(IBaseFilter *pBF){
	IPin *pP, *pTo;
	ULONG u;
	IEnumPins *pins = NULL;
	PIN_INFO pininfo;
	HRESULT hr = pBF->EnumPins(&pins);
	pins->Reset();
	while (hr == NOERROR)
	{
		hr = pins->Next(1, &pP, &u);
		if (hr == S_OK && pP)
		{
			pP->ConnectedTo(&pTo);
			if (pTo)
			{
				hr = pTo->QueryPinInfo(&pininfo);
				if (hr == NOERROR)
				{
					if (pininfo.dir == PINDIR_INPUT)
					{
						NukeDownstream(pininfo.pFilter);
						pGraphBuilder->Disconnect(pTo);
						pGraphBuilder->Disconnect(pP);
						pGraphBuilder->RemoveFilter(pininfo.pFilter);
					}
					pininfo.pFilter->Release();
					pininfo.pFilter = NULL;
				}
				pTo->Release();
			}
			pP->Release();
		}
	}
	if (pins) pins->Release();
}
Esempio n. 6
0
/* 构建滤波器链表,添加各个滤波器,链接并运行链表*/
HRESULT CVMR_Capture::Init(int iDeviceID,HWND hWnd, int iWidth, int iHeight)
{
	HRESULT hr;
	
	//再次调用函数,释放已经建立的链表
	CloseInterfaces();

	// 创建IGraphBuilder
    hr = CoCreateInstance(CLSID_FilterGraph, NULL, 
					CLSCTX_INPROC_SERVER, 
					IID_IGraphBuilder, (void **)&m_pGB);

    if (SUCCEEDED(hr))
    {
        // 创建VMR并添加到Graph中
        InitializeWindowlessVMR(hWnd);        
		
		// 把指定的设备捆绑到一个滤波器
		if(!BindFilter(iDeviceID, &m_pDF))
			return S_FALSE;
		// 添加采集设备滤波器到Graph中
		hr = m_pGB->AddFilter(m_pDF, L"Video Capture");
		if (FAILED(hr)) return hr;
		
		// 获取捕获滤波器的引脚
		IEnumPins  *pEnum;
		m_pDF->EnumPins(&pEnum);
		hr |= pEnum->Reset();
		hr |= pEnum->Next(1, &m_pCamOutPin, NULL); 
			
        // 获取媒体控制和事件接口
        hr |= m_pGB->QueryInterface(IID_IMediaControl, (void **)&m_pMC);
        hr |= m_pGB->QueryInterface(IID_IMediaEventEx, (void **)&m_pME);     

		// 设置窗口通知消息处理
        //hr = pME->SetNotifyWindow((OAHWND)hWnd, WM_GRAPHNOTIFY, 0);
		
		// 匹配视频分辨率,对视频显示窗口设置
		hr |= InitVideoWindow(hWnd,iWidth, iHeight);

		// 为捕获图像帧申请内存
		m_nFramelen=iWidth*iHeight*3;
		m_pFrame=(BYTE*) new BYTE[m_nFramelen];		

		// 运行Graph,捕获视频
		m_psCurrent = STOPPED;
		hr |= m_pGB->Render(m_pCamOutPin);
		hr |= m_pMC->Run();

		if (FAILED(hr)) return hr;

		m_psCurrent = RUNNING;
	}

	return hr;
}
HRESULT CDShowUtility::GetFirstUnConnectedPin(IBaseFilter *pFilter, PIN_DIRECTION PinDir, IPin **ppPin)
{
    *ppPin = NULL;

    IEnumPins *pEnum = NULL;
    IPin *pPin = NULL;

    HRESULT hr = pFilter->EnumPins(&pEnum);

    if (FAILED(hr))
    {
        return hr;
    }
    pEnum->Reset();

    while (pEnum->Next(1, &pPin, NULL) == S_OK)
    {
        PIN_DIRECTION ThisPinDir;
        pPin->QueryDirection(&ThisPinDir);

        if (PinDir == ThisPinDir)
        {
            IPin *pTmp = 0;
            hr = pPin->ConnectedTo(&pTmp);
            
            if (NULL != pTmp)
            {
                pTmp->Release();
            }

            if (SUCCEEDED(hr))
            {
                //已经连接了
                pPin->Release();
                continue;
            }
            else
            {
                pEnum->Release();
                *ppPin = pPin;

                return S_OK;
            }
        }

        pPin->Release();

    }

    pEnum->Release();

    return E_FAIL;
}
Esempio n. 8
0
HRESULT Captura::Iniciar(int iDeviceID,HWND hWnd, int iWidth, int iHeight)
{
	HRESULT hr;
	// Coger la interfaz de DirectShow
    hr=CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, 
                         IID_IGraphBuilder, (void **)&m_pGB);

    if(SUCCEEDED(hr))
    {
        // Crear la superficie de mezcla y meterla en el Graph
        IniciarWindowlessVMR(hWnd);
		  // Enlazar el filtro
      	if(!EnlazarFiltro(iDeviceID, &m_pDF))
			return S_FALSE;

   		hr=m_pGB->AddFilter(m_pDF, L"Video Capture");
		if (FAILED(hr))
		return hr;

      		/*CComPtr<IEnumPins>*/IEnumPins* pEnum;
	        m_pDF->EnumPins(&pEnum);

   	 	hr = pEnum->Reset();
		hr = pEnum->Next(1, &m_pCamOutPin, NULL);



        // Preguntar a los interfaces
        hr = m_pGB->QueryInterface(IID_IMediaControl, (void **)&m_pMC);

       hr = m_pGB->QueryInterface(IID_IMediaEventEx, (void **)&m_pME);

	    	hr = IniciarVentanaVideo(hWnd,iWidth, iHeight);

		m_nTamFrame=iWidth*iHeight*3;
		m_pFrame=(BYTE*) new BYTE[m_nTamFrame];

        
		
		// Ejecutar el Graph

		m_psEstado=PARADO;
        
		hr = m_pGB->Render(m_pCamOutPin);
		hr = m_pMC->Run();
		m_psEstado=EJECUTANDO;

        
	}
	return hr;

}
Esempio n. 9
0
HRESULT CKTVDlg::EnumPinsOnFilter( IBaseFilter *pFilter, PIN_DIRECTION PinDir , int index)
{
    HRESULT r;
    IEnumPins  *pEnum = NULL;
    IPin *pPin = NULL;

    // Verify filter interface
    if (!pFilter)
        return E_NOINTERFACE;

    // Get pin enumerator
    r = pFilter->EnumPins(&pEnum);
    if (FAILED(r))
        return r;

    pEnum->Reset();

    // Enumerate all pins on this filter
    while((r = pEnum->Next(1, &pPin, 0)) == S_OK)
    {
        PIN_DIRECTION PinDirThis;

        r = pPin->QueryDirection(&PinDirThis);
        if (FAILED(r))
        {
            pPin->Release();
            continue;
        }

        // Does the pin's direction match the requested direction?
        if (PinDir == PinDirThis)
        {
            PIN_INFO pininfo={0};

            // Direction matches, so add pin name to listbox
            r = pPin->QueryPinInfo(&pininfo);
            if (SUCCEEDED(r))
            {
                wstring str = pininfo.achName;
                m_captureFilterVec[index].PinVec.push_back(str);
            }

            // The pininfo structure contains a reference to an IBaseFilter,
            // so you must release its reference to prevent resource a leak.
            pininfo.pFilter->Release();
        }
        pPin->Release();
    }
    pEnum->Release();

    return r;
}
Esempio n. 10
0
// Tear down everything downstream of a given filter
void __fastcall NukeDownstream(IBaseFilter * pf, IGraphBuilder * pGB)
{
			IPin *pP = 0;
			IPin *pTo = 0;
			ULONG u;
			IEnumPins *pins = NULL;
			PIN_INFO pininfo;

			if (!pf)
				return;

			// Enumerate all filter pins
			HRESULT hr = pf->EnumPins(&pins);
			// Go to beginning of enumeration
			pins->Reset();

			while(hr == NOERROR)
			{
				hr = pins->Next(1, &pP, &u);
				if(hr == S_OK && pP)
				{
					pP->ConnectedTo(&pTo);
					if(pTo)
					{
						hr = pTo->QueryPinInfo(&pininfo);
						if(hr == NOERROR)
						{
							if(pininfo.dir == PINDIR_INPUT)
							{
								NukeDownstream(pininfo.pFilter, pGB);
								pGB->Disconnect(pTo);
								pGB->Disconnect(pP);
								pGB->RemoveFilter(pininfo.pFilter);
							}
							pininfo.pFilter->Release();
							pininfo.pFilter = NULL;
						}
						pTo->Release();
						pTo = NULL;
					}
					pP->Release();
					pP = NULL;
				}
			}
			if(pins)
			{
				pins->Release();
				pins = NULL;
			}
}
Esempio n. 11
0
	HRESULT GetAMConfigForMultiPin(IUnknown* pUnk, PIN_DIRECTION direct, 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 == direct))
						{
							IKsPropertySet* pPS;
							hr = pPin->QueryInterface(IID_IKsPropertySet, (void**)&pPS);
							if (SUCCEEDED(hr))
							{
								GUID guid = { 0 };
								DWORD dwReturn = 0;
								hr = pPS->Get(AMPROPSETID_Pin, AMPROPERTY_PIN_CATEGORY, 0, 0, &guid, sizeof(guid), &dwReturn);
								if (SUCCEEDED(hr) && ::IsEqualGUID(guid, PIN_CATEGORY_CAPTURE))
								{
									hr = pPin->QueryInterface(IID_IAMStreamConfig, (void**)ppConfig);
									bFound = SUCCEEDED(hr);
								}
								pPS->Release();
							}
						}
						pPin->Release();
					}
				}
				pEnumPins->Release();
			}
			pBaseFilter->Release();
		}
		return hr;
	}
Esempio n. 12
0
//取设备输出Pin
IPin* CCaptureDevice::GetPin(void)
{
	IPin * foundPin = NULL;

	if( m_pBaseFilter )
	{
		//创建枚举
		IEnumPins * pinEnum = NULL;
		if (m_pBaseFilter->EnumPins(&pinEnum)==S_OK)
		{
			//复位
			pinEnum->Reset();

			//循环每个PIN
			ULONG fetchCount = 0;
			IPin * pin = NULL;
			while ( !foundPin && S_OK==(pinEnum->Next(1, &pin, &fetchCount)) && fetchCount )
			{
				if (pin)
				{
					//得到PIN信息
					PIN_INFO pinInfo;
					if (S_OK==pin->QueryPinInfo(&pinInfo))
					{
						//检测是否是输出PIN
						if (pinInfo.dir == PINDIR_OUTPUT)
						{
//							pin->AddRef(); //加一引用
							foundPin = pin; //返回PIN
						}
						pinInfo.pFilter->Release();
					}
					pin->Release();
				}
			}
			pinEnum->Release();
		}
	}
//	if (foundPin)
//	{
//		foundPin->Release();
//	}
    return foundPin;
}
Esempio n. 13
0
//取设备输出Pin
IPin* CGraphBuilder::GetPin(PIN_DIRECTION PinDirection)
{
	IPin * foundPin = NULL;

	if( m_pBaseFilter )
	{
		//创建枚举
		IEnumPins * pinEnum = NULL;
		if ( m_pBaseFilter->EnumPins(&pinEnum)==S_OK )
		{
			//复位
			pinEnum->Reset();

			//循环每个PIN
			ULONG fetchCount = 0;
			IPin * pin = NULL;
			while ( !foundPin && S_OK==(pinEnum->Next(1, &pin, &fetchCount)) && fetchCount )
			{
				if (pin)
				{
					//得到PIN信息
					PIN_INFO pinInfo;
					if ( S_OK==pin->QueryPinInfo(&pinInfo) )
					{
						//检测是否是输出PIN
						if (pinInfo.dir == PinDirection)
						{
							pin->AddRef(); //加一引用
							foundPin = pin; //返回PIN
						}
						pinInfo.pFilter->Release();
					}
					pin->Release();
				}
			}
			pinEnum->Release();
		}
	}
	if (foundPin)
	{
		foundPin->Release();
	}
    return foundPin;
}
Esempio n. 14
0
// Tear down everything upstream of a given filter
void NukeUpstream(IGraphBuilder * inGraph, IBaseFilter * inFilter) 
{
	if (inGraph && inFilter)
	{
		IEnumPins * pinEnum = 0;
		if (SUCCEEDED(inFilter->EnumPins(&pinEnum)))
		{
			pinEnum->Reset();
			IPin * pin = 0;
			ULONG cFetched = 0;
			bool pass = true;
			while (pass && SUCCEEDED(pinEnum->Next(1, &pin, &cFetched)))
			{
				if (pin && cFetched)
				{
					IPin * connectedPin = 0;
					pin->ConnectedTo(&connectedPin);
					if(connectedPin) 
					{
						PIN_INFO pininfo;
						if (SUCCEEDED(connectedPin->QueryPinInfo(&pininfo)))
						{
							if(pininfo.dir == PINDIR_OUTPUT) 
							{
								NukeUpstream(inGraph, pininfo.pFilter);
								inGraph->Disconnect(connectedPin);
								inGraph->Disconnect(pin);
								inGraph->RemoveFilter(pininfo.pFilter);
							}
							pininfo.pFilter->Release();
						}
						connectedPin->Release();
					}
					pin->Release();
				}
				else
				{
					pass = false;
				}
			}
			pinEnum->Release();
		}
	}
}
Esempio n. 15
0
IPin* getInputPin(IBaseFilter* filt)
{
	IPin* pin = NULL;
	IEnumPins* pinList;

	if (!filt) return NULL;

	//get the input
	if (SUCCEEDED(filt->EnumPins(&pinList)))
	{
		pinList->Reset();
		while (pinList->Next(1, &pin, NULL) == S_OK && getPinInfo(pin).dir != PINDIR_INPUT) pin->Release();
		pinList->Release();

		if (getPinInfo(pin).dir != PINDIR_INPUT) return NULL;
	}

	return pin;
}
Esempio n. 16
0
void CCaptureDevice::EnumInputList( ENUMINPUTCALLBACK EnumInputCallBack, LPVOID lp )
{
	char pinName[128];
	if (m_pBaseFilter)
	{
		IEnumPins * pinEnum = NULL;
		if ( m_pBaseFilter->EnumPins(&pinEnum) == S_OK )
		{
			pinEnum->Reset();

			BOOL bCancel  = FALSE;
			IPin * pin = NULL;
			ULONG fetchCount = 0;
			while (!bCancel && pinEnum->Next(1, &pin, &fetchCount)==S_OK && fetchCount)
			{
				if (pin)
				{
					PIN_INFO pinInfo;
					if ( pin->QueryPinInfo(&pinInfo)==S_OK )
					{
						pinInfo.pFilter->Release();
						if (pinInfo.dir == PINDIR_INPUT)
						{
							::WideCharToMultiByte(CP_ACP, 0, pinInfo.achName, 
								-1,	pinName, 128, NULL, NULL);
							if( EnumInputCallBack( pinName, pin, lp, bCancel ) != S_OK )
								bCancel = TRUE;
						}
						pin->Release();
						pin = NULL;
					}
				}
				else
				{
					bCancel = FALSE;
				}
			}
			pinEnum->Release();
		}
	}
}
Esempio n. 17
0
	HRESULT RemoveFilter(IGraphBuilder* pGraphBuilder, IBaseFilter* pBaseFilter)
	{
		CheckPointer(pGraphBuilder, E_POINTER);
		CheckPointer(pBaseFilter, E_PENDING);

		IEnumPins *pEnumPins = NULL;
		HRESULT hr = pBaseFilter->EnumPins(&pEnumPins);
		if (FAILED(hr)) return hr;
		pEnumPins->Reset();

		IPin *pPinFrom = 0, *pPinTo = 0;
		while ((hr = pEnumPins->Next(1, &pPinFrom, NULL)) == S_OK)
		{
			if (SUCCEEDED(hr))
			{
				hr = pPinFrom->ConnectedTo(&pPinTo);
				if (SUCCEEDED(hr))
				{
					PIN_INFO info;
					hr = pPinTo->QueryPinInfo(&info);
					if (SUCCEEDED(hr))	
					{
						if (info.dir == PINDIR_INPUT)
						{
							RemoveFilter(pGraphBuilder, info.pFilter);
							pGraphBuilder->Disconnect(pPinTo);
							pGraphBuilder->Disconnect(pPinFrom);
							pGraphBuilder->RemoveFilter(info.pFilter);
						}
						info.pFilter->Release();
					}
					pPinTo->Release();
				}
				pPinFrom->Release();
			}
		}
		pEnumPins->Release();
		return S_OK;
	}
Esempio n. 18
0
    BOOL EnumPins(void)
    {
        IEnumPins *enumpins;
        if (m_pFilter->EnumPins(&enumpins) != S_OK)
            return FALSE;

        enumpins->Reset();

        IPin *pin;
        PIN_INFO pInfo;

        // FIXME: ffdshow has 2 input pins "In" and "In Text"
        // there is not way to check mediatype before connection
        // I think I need a list of pins and then probe for all :(
        while ((m_res = enumpins->Next(1, &pin, NULL)) == S_OK)
        {
            pin->QueryPinInfo(&pInfo);
            /* wprintf(L"Pin: %s - %s\n", pInfo.achName, (pInfo.dir == PINDIR_INPUT) ? L"Input" : L"Output"); */
            if (!m_pInputPin && (pInfo.dir == PINDIR_INPUT))
                m_pInputPin = pin;
            else if (!m_pOutputPin && (pInfo.dir == PINDIR_OUTPUT))
                m_pOutputPin = pin;

            pin->Release();
            m_pFilter->Release();
        }

        enumpins->Release();
        if (!(m_pInputPin && m_pInputPin))
            return FALSE;

        if (m_pInputPin->QueryInterface(IID_IMemInputPin, (LPVOID *) &m_pImp) != S_OK)
            return FALSE;

        return TRUE;
    }
Esempio n. 19
0
HRESULT SetVboxFrequency( JNIEnv *env, DShowCaptureInfo* pCapInfo, ULONG ulFrequency )
{
    HRESULT hr;
    DWORD dwSupported=0;  
    IEnumPins* pEnumPin;
    IPin* pInputPin;
    ULONG ulFetched;
    PIN_INFO infoPin;

	if ( pCapInfo->pBDATuner == NULL )
		return E_FAIL;

	if( ulFrequency == 0 )
	{
		slog( (env,"VOX tuner skips frequency 0\r\n") );
		return S_OK;
	}

    IBaseFilter* pTunerDevice = pCapInfo->pBDATuner; 
    pTunerDevice->EnumPins(&pEnumPin);

    if( SUCCEEDED( hr = pEnumPin->Reset() ) )
    {
		while((hr = pEnumPin->Next( 1, &pInputPin, &ulFetched )) == S_OK)
		{
			pInputPin->QueryPinInfo(&infoPin);
				
			// Release AddRef'd filter, we don't need it
			if( infoPin.pFilter != NULL )
			infoPin.pFilter->Release();

			if(infoPin.dir == PINDIR_INPUT)
			break;
		}

		if(hr != S_OK)
		{
			slog( (env,"Vbox tuner input pin query failed \r\n") );
			return hr;
		}
    }
    else
    {
		slog( (env,"Vbox tuner reset failed \r\n") );
		return E_FAIL;
    }
    
    IKsPropertySet *pKsPropertySet;
    pInputPin->QueryInterface(&pKsPropertySet);
	
    if (!pKsPropertySet)
    {
		slog( (env,"Vbox tuner input pin's QueryInterface failed \r\n") );

		return E_FAIL;
    }
        
    KSPROPERTY_TUNER_MODE_CAPS_S ModeCaps;
    KSPROPERTY_TUNER_FREQUENCY_S Frequency;
    memset(&ModeCaps,0,sizeof(KSPROPERTY_TUNER_MODE_CAPS_S));
    memset(&Frequency,0,sizeof(KSPROPERTY_TUNER_FREQUENCY_S));
    ModeCaps.Mode = AMTUNER_MODE_TV; 

    // Check either the Property is supported or not by the Tuner drivers 

    hr = pKsPropertySet->QuerySupported(PROPSETID_TUNER, 
          KSPROPERTY_TUNER_MODE_CAPS,&dwSupported);
    if(SUCCEEDED(hr) && dwSupported&KSPROPERTY_SUPPORT_GET)
    {
        DWORD cbBytes=0;
        hr = pKsPropertySet->Get(PROPSETID_TUNER,KSPROPERTY_TUNER_MODE_CAPS,
            INSTANCEDATA_OF_PROPERTY_PTR(&ModeCaps),
            INSTANCEDATA_OF_PROPERTY_SIZE(ModeCaps),
            &ModeCaps,
            sizeof(ModeCaps),
            &cbBytes);  
    }
    else
    {
		SAFE_RELEASE(pKsPropertySet);
		slog( (env,"Vbox tuner input pin's not support GET query \r\n") );
        return E_FAIL; 
    }

    Frequency.Frequency=ulFrequency; // in Hz
    if(ModeCaps.Strategy==KS_TUNER_STRATEGY_DRIVER_TUNES)
        Frequency.TuningFlags=KS_TUNER_TUNING_FINE;
    else
        Frequency.TuningFlags=KS_TUNER_TUNING_EXACT;

    // Here the real magic starts
    //if(ulFrequency>=ModeCaps.MinFrequency && ulFrequency<=ModeCaps.MaxFrequency)
    {
        hr = pKsPropertySet->Set(PROPSETID_TUNER,
            KSPROPERTY_TUNER_FREQUENCY,
            INSTANCEDATA_OF_PROPERTY_PTR(&Frequency),
            INSTANCEDATA_OF_PROPERTY_SIZE(Frequency),
            &Frequency,
            sizeof(Frequency));
        if(FAILED(hr))
        {
			slog( (env,"Vbox tuner input pin's set frequency %d failed hr=0x%x\r\n", Frequency.Frequency, hr ) );
			SAFE_RELEASE(pKsPropertySet);
            return E_FAIL; 
        }
    }

  //  else
  //  {
		//slog( (env,"Vbox tuning frequency %d is out of range (%d %d)\r\n", 
		//	          ulFrequency, ModeCaps.MinFrequency, ModeCaps.MaxFrequency ) );
  //      return E_FAIL;
  //  }

	SAFE_RELEASE(pKsPropertySet);
	slog( (env,"Vbox tuner tuning overider frequency %d  successful. \r\n", ulFrequency) );
    return S_OK;
}
Esempio n. 20
0
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;
}
Esempio n. 21
0
HRESULT CAccessSys::BuildPreview(void)
{
	HRESULT hr;
	IBaseFilter *pSrcFilter = NULL;

	if (b_buildPreview){
		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;
	
	hr = p_capture_graph_builder2->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,
		pSrcFilter, NULL, NULL);
	if (FAILED(hr))
	{
		Msg(TEXT("Couldn't render the video capture stream.  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;
	}

	//{
	//	IEnumPins *ep;
	//	IPin *inputpin = NULL;
	//	IPin *voutputpin = NULL;
	//	IPin *aoutputpin = NULL;
	//	IPin *pin = NULL;
	//	bool bFindI420 = false;
	//	bool bFindPCM = false;

	//	pSrcFilter = p_streams[0].p_device_filter;

	//	pSrcFilter->EnumPins(&ep);
	//	if (SUCCEEDED(hr)){
	//		ep->Reset();
	//		while (SUCCEEDED(hr = ep->Next(1, &pin, 0)) && hr != S_FALSE){
	//			PIN_DIRECTION pinDir;
	//			pin->QueryDirection(&pinDir);
	//			if (pinDir == PINDIR_OUTPUT){
	//				AM_MEDIA_TYPE *pmt;
	//				IEnumMediaTypes *emt;
	//				pin->EnumMediaTypes(&emt);
	//				while (hr = emt->Next(1, &pmt, NULL), hr != S_FALSE){
	//					if (pmt->majortype == MEDIATYPE_Video){
	//						if (pmt->subtype == MEDIASUBTYPE_RGB24){
	//							//Msg(TEXT("MEDIASUBTYPE_RGB24"));
	//						}
	//						else if (pmt->subtype == MEDIASUBTYPE_I420){
	//							//Msg(TEXT("MEDIASUBTYPE_I420"));
	//							bFindI420 = true;
	//						}
	//						else if (pmt->subtype == MEDIASUBTYPE_YUY2){}
	//					}
	//					TCHAR buf[64] = { 0 };
	//					swprintf(buf, TEXT("{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}"),
	//						pmt->subtype.Data1, pmt->subtype.Data2, pmt->subtype.Data3,
	//						pmt->subtype.Data4[0], pmt->subtype.Data4[1],
	//						pmt->subtype.Data4[2], pmt->subtype.Data4[3],
	//						pmt->subtype.Data4[4], pmt->subtype.Data4[5],
	//						pmt->subtype.Data4[6], pmt->subtype.Data4[7]);
	//					//Msg(buf);
	//					DeleteMediaType(pmt);
	//				}
	//				emt->Release();
	//			}
	//			pin->Release();
	//			pin = NULL;
	//		}
	//	}
	//	RELEASE(ep);
	//}

	pSrcFilter = p_streams[1].p_device_filter;
	
    // do not render local audio
	//hr = p_capture_graph_builder2->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Audio,
	//	pSrcFilter, NULL, NULL);
	//if (FAILED(hr))
	//{
	//	Msg(TEXT("Couldn't render the video capture stream.  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;
	//}

    {
        IEnumPins *ep;
        IPin *pin = NULL;

        IAMBufferNegotiation *buffer_negotiation = NULL;
        ALLOCATOR_PROPERTIES props = { -1, -1, -1, -1 };

        pSrcFilter->EnumPins(&ep);
        ep->Reset();
        while (SUCCEEDED(hr = ep->Next(1, &pin, 0)) && hr != S_FALSE){
            if (pin->QueryInterface(IID_IAMBufferNegotiation, (void **)&buffer_negotiation) == S_OK){
                buffer_negotiation->GetAllocatorProperties(&props);
                props.cbBuffer = 4096; // set to 4096 byte: acc encode frame length
                buffer_negotiation->SuggestAllocatorProperties(&props);
                RELEASE(buffer_negotiation);
            }
            RELEASE(pin);
        }
        RELEASE(ep);
    }

	//{
	//	IEnumPins *ep;
	//	IPin *inputpin = NULL;
	//	IPin *voutputpin = NULL;
	//	IPin *aoutputpin = NULL;
	//	IPin *pin = NULL;
	//	bool bFindI420 = false;
	//	bool bFindPCM = false;

	//	//pSrcFilter = p_streams[0].p_device_filter;

	//	pSrcFilter->EnumPins(&ep);
	//	if (SUCCEEDED(hr)){
	//		ep->Reset();
	//		while (SUCCEEDED(hr = ep->Next(1, &pin, 0)) && hr != S_FALSE){
	//			PIN_DIRECTION pinDir;
	//			pin->QueryDirection(&pinDir);
	//			if (pinDir == PINDIR_OUTPUT){
	//				AM_MEDIA_TYPE *pmt;
	//				IEnumMediaTypes *emt;
	//				pin->EnumMediaTypes(&emt);
	//				while (hr = emt->Next(1, &pmt, NULL), hr != S_FALSE){
	//					if (pmt->majortype == MEDIATYPE_Audio){
	//						if (pmt->subtype == MEDIASUBTYPE_PCM){
	//							//Msg(TEXT("MEDIASUBTYPE_PCM"));
	//						}
	//						else if (pmt->subtype == MEDIASUBTYPE_I420){
	//							//Msg(TEXT("MEDIASUBTYPE_I420"));
	//							bFindI420 = true;
	//						}
	//						else{
	//							bFindI420 = true;
	//						}
	//					}
	//					TCHAR buf[64] = { 0 };
	//					swprintf(buf, TEXT("{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}"),
	//						pmt->subtype.Data1, pmt->subtype.Data2, pmt->subtype.Data3,
	//						pmt->subtype.Data4[0], pmt->subtype.Data4[1],
	//						pmt->subtype.Data4[2], pmt->subtype.Data4[3],
	//						pmt->subtype.Data4[4], pmt->subtype.Data4[5],
	//						pmt->subtype.Data4[6], pmt->subtype.Data4[7]);
	//					//Msg(buf);
	//					DeleteMediaType(pmt);
	//				}
	//				emt->Release();
	//			}
	//			pin->Release();
	//			pin = NULL;
	//		}
	//	}
	//	RELEASE(ep);
	//}

	b_buildPreview = true;
	return hr;
}