示例#1
0
//-----------------------------------------------------------------------------
// GetPin
// Find the pin of the specified format type on the given filter
// This method leaves an outstanding reference on the pin if successful
HRESULT CDSUtils::GetPin(IBaseFilter* pFilter, const GUID* pFormat, PIN_DIRECTION PinDir, IPin** ppPin)
{
	HRESULT hr = S_OK;

	if (pFilter && pFormat && ppPin)
	{
		CComPtr<IEnumPins> pIEnumPins = NULL;
		hr = pFilter->EnumPins(&pIEnumPins);
		if (SUCCEEDED(hr))
		{
			// find the pin with the specified format
			IPin* pIPin = NULL;
			while (S_OK == pIEnumPins->Next(1, &pIPin, NULL))
			{
				// match the pin direction
				PIN_DIRECTION pinDir;
				pIPin->QueryDirection(&pinDir);
				if (pinDir == PinDir)
				{
					// match pin direction check the first media type returned from the upstream pin
					CComPtr<IEnumMediaTypes> pIEnumMT = NULL;
					hr = pIPin->EnumMediaTypes(&pIEnumMT);
					if (SUCCEEDED(hr))
					{
						AM_MEDIA_TYPE* pmt = NULL;
						hr = pIEnumMT->Next(1, &pmt, NULL);
						if (S_OK == hr)
						{
							if (pmt->majortype == *pFormat)
							{
								// found the pin with the specified format
								*ppPin = pIPin;
								DeleteMediaType(pmt);
								break;
							}
							else
							{
								DeleteMediaType(pmt);
							}
						}
					}
				}
				SAFE_RELEASE(pIPin);
			}

			if (NULL == *ppPin)
			{
				// failed to find the named pin
				hr = E_FAIL;
			}
		}
	}
	else
	{
		hr = E_INVALIDARG;
	}

	return hr;
}
IPin* FindDecoderSubpictureOutputPin(IBaseFilter* pFilter)
{
    IEnumPins* pEnum = NULL;
    HRESULT hr = pFilter->EnumPins(&pEnum);
    if (hr != NOERROR)
        return NULL;

    ULONG ulFound;
    IPin *pPin = NULL;
    hr = E_FAIL;

    while(S_OK == pEnum->Next(1, &pPin, &ulFound))
    {
		PIN_INFO PinInfo;
		//
		// grab this, so we can examine its name field
		//
	    hr = pPin->QueryPinInfo(&PinInfo);
	    if(SUCCEEDED(hr))
		{
			PinInfo.pFilter->Release();
			//
			// check direction
			//
			if (PinInfo.dir == PINDIR_OUTPUT)
			{
				// Make sure its not connected yet and its a video type.
				IPin* dummyPin = NULL;
				hr = pPin->ConnectedTo(&dummyPin);
				SAFE_RELEASE(dummyPin);
				if (hr == VFW_E_NOT_CONNECTED)
				{
					IEnumMediaTypes *mtEnum = NULL;
					pPin->EnumMediaTypes(&mtEnum);
					AM_MEDIA_TYPE *pMT = NULL;
					while (S_OK == mtEnum->Next(1, &pMT, NULL))
					{
						if (pMT->majortype == MEDIATYPE_Video)
						{
							DeleteMediaType(pMT);
							SAFE_RELEASE(mtEnum);
							SAFE_RELEASE(pEnum);
							return pPin;
						}
						DeleteMediaType(pMT);
					}
					SAFE_RELEASE(mtEnum);
				}
			}
		}
        pPin->Release();
    } 
    SAFE_RELEASE(pEnum);
	return NULL;
}
示例#3
0
HRESULT MiniPlayer::findPin(IBaseFilter *pFilter, int dir, const GUID &mediaMajorType, IPin **pOutPin)
{
	IEnumPins *pEnumPins = NULL;
	IEnumMediaTypes *pEnumMediaTypes = NULL;
	IPin *pPin = NULL;
	PIN_INFO pinInfo;
	//FILTER_INFO filterInfo;
	AM_MEDIA_TYPE *pMediaType = NULL;

	//HRESULT hr = pFilter->QueryFilterInfo(&filterInfo);
	//if(hr == S_OK)
	//{
	//	ctrace(L"%s Pins:\n", filterInfo.achName);
	//}

	HRESULT hr = pFilter->EnumPins(&pEnumPins);
	if(FAILED(hr)) return hr;

	
	while(pEnumPins->Next(1, &pPin, NULL) == S_OK)
	{
		hr = pPin->QueryPinInfo(&pinInfo);
		if(FAILED(hr)) continue;

		if(pinInfo.dir == dir)
		{
			hr = pPin->EnumMediaTypes(&pEnumMediaTypes);
			if(FAILED(hr))continue;

			while(pEnumMediaTypes->Next(1, &pMediaType, NULL) == S_OK)
			{
				if(pMediaType->majortype == mediaMajorType)
				{
					*pOutPin = pPin;
					return S_OK;
				}
			}
			pEnumMediaTypes->Release();
		}
	}

	pEnumPins->Release();

	return -1;
}
示例#4
0
HRESULT RecordGraph::GetUnconnectedPin(IBaseFilter *pFilter, PIN_DIRECTION PinDir, IPin **ppPin, GUID MediaType)
{
	*ppPin = 0;
	IEnumPins *pEnum = 0;
	IPin *pPin = 0;
	HRESULT hr = pFilter->EnumPins(&pEnum);
	if(FAILED(hr))
		return hr;
	while (pEnum->Next(1, &pPin, NULL) == S_OK)
	{
		PIN_DIRECTION ThisPinDir;
		pPin->QueryDirection(&ThisPinDir);
		if (ThisPinDir == PinDir)
		{
			IPin *pTmp = 0;
			hr = pPin->ConnectedTo(&pTmp);
			if (SUCCEEDED(hr))
				pTmp->Release();
			else
			{	IEnumMediaTypes *pEnumMediaType = NULL;
			hr = pPin->EnumMediaTypes(&pEnumMediaType);
			if (MediaType == MEDIATYPE_NULL)
			{
				pEnum->Release();
				*ppPin = pPin;
				pPin->Release();
				return S_OK;
			}else if(SUCCEEDED(this->CheckMediaType(pEnumMediaType, MediaType)))
			{
				pEnum->Release();
				*ppPin = pPin;
				pPin->Release();
				return S_OK;
			} 
			pEnumMediaType->Release();
			}
		}
		pPin->Release();
	}
	pEnum->Release();
	return E_FAIL;
}
示例#5
0
void MiniPlayer::listAllPins(IBaseFilter *pFilter)
{
	IEnumPins *pEnumPins = NULL;
	IEnumMediaTypes *pEnumMediaTypes = NULL;
	IPin *pPin = NULL;
	PIN_INFO pinInfo;
	FILTER_INFO filterInfo;
	AM_MEDIA_TYPE *pMediaType = NULL;

	HRESULT hr = pFilter->QueryFilterInfo(&filterInfo);
	if(hr == S_OK)
	{
		ctrace(L"%s Pins:\n", filterInfo.achName);
	}

	hr = pFilter->EnumPins(&pEnumPins);
	if(FAILED(hr)) return;

	while(pEnumPins->Next(1, &pPin, NULL) == S_OK)
	{
		hr = pPin->QueryPinInfo(&pinInfo);
		if(FAILED(hr)) continue;

		ctrace(L"\t [%s] %s: ", (pinInfo.dir == PINDIR_INPUT)? L"INPUT": L"OUTPUT", pinInfo.achName);
		hr = pPin->EnumMediaTypes(&pEnumMediaTypes);
		if(FAILED(hr))continue;

		while(pEnumMediaTypes->Next(1, &pMediaType, NULL) == S_OK)
		{
			if(pMediaType->majortype == MEDIATYPE_Video)
				ctrace("Video ");
			if(pMediaType->majortype == MEDIATYPE_Audio)
				ctrace("Audio ");
		}

		ctrace("\n");
		pEnumMediaTypes->Release();
	}

	pEnumPins->Release();
}
示例#6
0
HRESULT CTMReceiverGraph::GetUnconnectedPin(CComPtr<IBaseFilter> pFilter, PIN_DIRECTION PinDir, IPin **ppPin, GUID MediaType)
{
	*ppPin = 0;
	CComPtr<IEnumPins> pEnum = 0;
	IPin* pPin = 0;
	HRESULT hr = pFilter->EnumPins(&pEnum);
	if(FAILED(hr))
		return hr;
	while (pEnum->Next(1, &pPin, NULL) == S_OK)
	{
		PIN_DIRECTION ThisPinDir;
		pPin->QueryDirection(&ThisPinDir);
		if (ThisPinDir == PinDir)
		{
			CComPtr<IPin> pTmp = 0;
			hr = pPin->ConnectedTo(&pTmp);
			if (SUCCEEDED(hr))
			{}
			else
			{	
				CComPtr<IEnumMediaTypes> pEnumMediaType = NULL;
				hr = pPin->EnumMediaTypes(&pEnumMediaType);
				if (MediaType == MEDIATYPE_NULL)
				{
					*ppPin = pPin;
					return S_OK;
				}else if(SUCCEEDED(this->CheckMediaType(pEnumMediaType, MediaType)))
				{
					*ppPin = pPin;
					return S_OK;
				} 
			}
		}
	}
	return E_FAIL;
}
int try_format_size(V4wState *s, int format, int width, int height, GUID *pPinCategory)
{
	HRESULT hr=S_OK;
	IEnumPins *pEnum=0;
	ULONG ulFound;
	IPin *pPin;

	GUID guid_format;
	DWORD biCompression;
	DWORD biBitCount;

	// Verify input
	if (!s->m_pDeviceFilter)
		return -1;

	if (format == MS_YUV420P)
		guid_format = (GUID)FOURCCMap(MAKEFOURCC('I','4','2','0'));
	else if (format == MS_YUYV)
		guid_format = MEDIASUBTYPE_YUYV;
	else if (format == MS_UYVY)
		guid_format = MEDIASUBTYPE_UYVY;
	else if (format == MS_RGB24)
		guid_format = MEDIASUBTYPE_RGB24;
	else if (format == MS_YUY2)
		guid_format = MEDIASUBTYPE_YUY2;

	if (format == MS_YUV420P)
		biCompression = MAKEFOURCC('I','4','2','0');
	else if (format == MS_YUYV)
		biCompression = MAKEFOURCC('Y','U','Y','V');
	else if (format == MS_UYVY)
		biCompression = MAKEFOURCC('U','Y','V','Y');
	else if (format == MS_RGB24)
		biCompression = BI_RGB;
	else if (format == MS_YUY2)
		biCompression = MAKEFOURCC('Y','U','Y','2');

	if (format == MS_YUV420P)
		biBitCount = 12;
	else if (format == MS_YUYV)
		biBitCount = 16;
	else if (format == MS_UYVY)
		biBitCount = 16;
	else if (format == MS_RGB24)
		biBitCount = 24;
	else if (format == MS_YUY2)
		biBitCount = 16;

	// Get pin enumerator
	hr = s->m_pDeviceFilter->EnumPins(&pEnum);
	if(FAILED(hr)) 
		return -1;

	pEnum->Reset();

	// Count every pin on the filter
	while(S_OK == pEnum->Next(1, &pPin, &ulFound))
	{
		PIN_DIRECTION pindir = (PIN_DIRECTION) 3;

		hr = pPin->QueryDirection(&pindir);

		if(pindir != PINDIR_INPUT)
		{
			IEnumMediaTypes *ppEnum;
			ULONG ulFound2;
			hr = pPin->EnumMediaTypes(&ppEnum);
			if(FAILED(hr)) 
				continue;

			GUID pCurrentPinCategory;
			GetPinCategory(pPin, &pCurrentPinCategory);
			if (*pPinCategory!=pCurrentPinCategory)
				continue;

			AM_MEDIA_TYPE *ppMediaTypes;
			while(S_OK == ppEnum->Next(1, &ppMediaTypes, &ulFound2))
			{
				if (ppMediaTypes->formattype != FORMAT_VideoInfo)
					continue;
				if (ppMediaTypes->majortype != MEDIATYPE_Video)
					continue;
				if (ppMediaTypes->subtype != guid_format)
					continue;
				VIDEOINFO *pvi = (VIDEOINFO *)ppMediaTypes->pbFormat;
				if (pvi->bmiHeader.biCompression!=biCompression)
					continue;
				if (pvi->bmiHeader.biBitCount!=biBitCount)
					continue;
				if (pvi->bmiHeader.biHeight!=height)
					continue;
				if (pvi->bmiHeader.biWidth!=width)
					continue;

				s->vsize.width = width;
				s->vsize.height = height;

				pPin->Release();
				pEnum->Release();
				return 0;
			}
		}

		pPin->Release();
	} 

	pEnum->Release();
	return -1;
}
int dump_format(IBaseFilter *m_pDeviceFilter)
{
	HRESULT hr=S_OK;
	IEnumPins *pEnum=0;
	ULONG ulFound;
	IPin *pPin;
	GUID pPinCategory;

	// Verify input
	if (!m_pDeviceFilter)
		return -1;

	// Get pin enumerator
	hr = m_pDeviceFilter->EnumPins(&pEnum);
	if(FAILED(hr)) 
		return -1;

	pEnum->Reset();

	// Count every pin on the filter
	while(S_OK == pEnum->Next(1, &pPin, &ulFound))
	{
		PIN_DIRECTION pindir = (PIN_DIRECTION) 3;

		hr = pPin->QueryDirection(&pindir);

		if(pindir != PINDIR_INPUT)
		{
			IEnumMediaTypes *ppEnum;
			ULONG ulFound2;

			GetPinCategory(pPin, &pPinCategory);
			if (pPinCategory!=PIN_CATEGORY_CAPTURE
				&& pPinCategory!=PIN_CATEGORY_PREVIEW)
				continue;

			hr = pPin->EnumMediaTypes(&ppEnum);
			if(FAILED(hr)) 
				continue;

			AM_MEDIA_TYPE *ppMediaTypes;
			while(S_OK == ppEnum->Next(1, &ppMediaTypes, &ulFound2))
			{
				if (ppMediaTypes->formattype != FORMAT_VideoInfo)
					continue;
				if (ppMediaTypes->majortype != MEDIATYPE_Video)
					continue;
				VIDEOINFO *pvi = (VIDEOINFO *)ppMediaTypes->pbFormat;
				if (pvi->bmiHeader.biCompression==0)
					ms_message("camera video format 'RGB' %ix%i/%i planes=%i",
						pvi->bmiHeader.biWidth,
						pvi->bmiHeader.biHeight,
						pvi->bmiHeader.biBitCount,
						pvi->bmiHeader.biPlanes);
				else
					ms_message("camera video format '%.4s' %ix%i/%i planes=%i",
						&pvi->bmiHeader.biCompression,
						pvi->bmiHeader.biWidth,
						pvi->bmiHeader.biHeight,
						pvi->bmiHeader.biBitCount,
						pvi->bmiHeader.biPlanes);
			}
		}

		pPin->Release();
	}

	pEnum->Release();
	return -1;
}
示例#9
0
HRESULT CDXGraph::RenderAVIFile(CString mSourceFile)
{
	if(pGraph != NULL)
	{
		//Add Grabber Filter
		IBaseFilter *pGrabberF = NULL;
		this->AddGrabber(&pGrabberF);
		//Add src filter
		IBaseFilter *pSrc;
		HRESULT hr = pGraph->AddSourceFilter(mSourceFile, L"Source", &pSrc);
		if(FAILED(hr)) return hr;
		//Add Avi splitter filter
		IBaseFilter *pAviSplitter = NULL;
		hr = CoCreateInstance(CLSID_AviSplitter, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&pAviSplitter);
		hr = pGraph->AddFilter(pAviSplitter, L"AVI Splitter");
		//Add Mpeg4s decoder dmo filter
		IBaseFilter *pMp4Decoder = NULL;
		hr = CoCreateInstance(CLSID_MPEG4SDecoder, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&pMp4Decoder);
		hr = pGraph->AddFilter(pMp4Decoder, L"Mp4 Decoder");

		//Audio
		//add mp3 decoder
		IBaseFilter *pMP3Decoder = NULL;
		hr = CoCreateInstance(CLSID_MP3Decoder, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&pMP3Decoder);
		hr = pGraph->AddFilter(pMP3Decoder, L"MP3 Decoder");

		//add direct sound device
		IBaseFilter *pDSoundDevice = NULL;
		hr = CoCreateInstance(CLSID_DSoundRender,NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&pDSoundDevice);
		hr = pGraph->AddFilter(pDSoundDevice, L"Sound Renderer");

		//connect filters via pins
		hr = ConnectFilters(pGraph, pSrc, pAviSplitter, MEDIATYPE_NULL);
		//Split to audio and video
		IEnumPins *pEnum = 0;
		IPin *pPin = 0;
		IEnumMediaTypes *pEnumMediaType = 0;
		hr = pAviSplitter->EnumPins(&pEnum);
		bool audio_connected = false, video_connected = false;
		while(pEnum->Next(1, &pPin, NULL) == S_OK)
		{
			hr = pPin->EnumMediaTypes(&pEnumMediaType);
			//if this is video output pin
			if(SUCCEEDED(this->CheckMediaType(pEnumMediaType, MEDIATYPE_Video)))
			{
				IPin *pMP4DecoderInput = NULL;
				hr = this->GetUnconnectedPin(pMp4Decoder, PINDIR_INPUT, &pMP4DecoderInput, MEDIATYPE_NULL);
				hr = pGraph->Connect(pPin, pMP4DecoderInput);
				PIN_INFO pInfo;
				pPin->QueryPinInfo(&pInfo);
				pMP4DecoderInput->QueryPinInfo(&pInfo);
				pMP4DecoderInput->Release();
				video_connected = true;
			}
			//if this is audio output pin
			else if (SUCCEEDED(this->CheckMediaType(pEnumMediaType, MEDIATYPE_Audio)))
			{
				IPin *pMP3DecoderInput = NULL;
				hr = this->GetUnconnectedPin(pMP3Decoder, PINDIR_INPUT, &pMP3DecoderInput, MEDIATYPE_NULL);
				hr = pGraph->Connect(pPin, pMP3DecoderInput);
				pMP3DecoderInput->Release();
				audio_connected = true;
			}
			
			pPin->Release();
			pEnumMediaType->Release();
			if (audio_connected && video_connected)
				break;
		}
		pEnum->Release();
		//Connect Audio Renderer
		hr = this->ConnectFilters(pGraph, pMP3Decoder, pDSoundDevice, MEDIATYPE_Audio);

		//Connect the Mp4Decoder to Sample Grabber
		hr = this->ConnectFilters(pGraph, pMp4Decoder, pGrabberF, MEDIATYPE_NULL);

		//get the output pin of grabber, then render pin
		IPin *pOutPin = NULL;
		this->GetUnconnectedPin(pGrabberF, PINDIR_OUTPUT, &pOutPin, MEDIATYPE_NULL);
		hr = pGraph->Render(pOutPin);

		pGrabberF->Release();
		pSrc->Release();
		pAviSplitter->Release();
		pMp4Decoder->Release();
		pMP3Decoder->Release();
		pDSoundDevice->Release();
		IEnumFilters *pEnumFilter;
		IBaseFilter *pRenderFilter;
		hr = pGraph->EnumFilters(&pEnumFilter);
		//test the graph
		SaveGraphFile(pGraph, L"D:\\SliderPlayer_264.grf");
		return S_OK;
	}
	return E_FAIL;
}
示例#10
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;
}