Exemplo n.º 1
0
oexBOOL CIpAddress::LookupUrl( oexCSTR x_pUrl, oexINT32 x_uPort, oexINT32 x_uType )
{
    // Lose old info
    Destroy();

    // Ensure we have a valid pointer
    if ( !oexVERIFY_PTR( x_pUrl ) )
        return oexFALSE;

    // Crack the url
    CPropertyBag pbUrl = ParseUrl( x_pUrl );
    if ( !pbUrl.Size() )
        return oexFALSE;

    // Did we get a host name?
    if ( !pbUrl[ oexT( "host" ) ].ToString().Length() )
        return oexFALSE;

    // Get the port
    if ( !x_uPort )
        x_uPort = pbUrl[ oexT( "port" ) ].ToLong();

    // Save the type
    m_uType = x_uType;

    return LookupHost( pbUrl[ oexT( "host" ) ].ToString().Ptr(), x_uPort );
}
Exemplo n.º 2
0
static int v4w_open_videodevice(V4wState *s, int format, MSVideoSize *vsize)
{
	// Initialize COM
	CoInitialize(NULL);

	// get a Graph
	HRESULT hr=s->m_pGraph.CoCreateInstance(CLSID_FilterGraph);
	if(FAILED(hr))
	{
		return -1;
	}

	// get a CaptureGraphBuilder2
#if !defined(_WIN32_WCE)
	hr=s->m_pBuilder.CoCreateInstance(CLSID_CaptureGraphBuilder2);
#else
	hr=s->m_pBuilder.CoCreateInstance(CLSID_CaptureGraphBuilder);
#endif
	if(FAILED(hr))
	{
		return -2;
	}

	// connect capture graph builder with the graph
	s->m_pBuilder->SetFiltergraph(s->m_pGraph);

	// get mediacontrol so we can start and stop the filter graph
	hr=s->m_pGraph.QueryInterface(&(s->m_pControl));
	if(FAILED(hr))
	{
		return -3;
	}

	// get DXFilter
	s->m_pDXFilter = new CDXFilter(NULL, &hr, FALSE);
	if(s->m_pDXFilter==NULL)
	{
		return -4;
	}
	s->m_pDXFilter->AddRef();
	if(FAILED(hr))
	{
		return -4;
	}

	CMediaType mt;
	mt.SetType(&MEDIATYPE_Video);

	if (format==MS_YUV420P)
	{
		GUID m = (GUID)FOURCCMap(MAKEFOURCC('I','4','2','0'));
		mt.SetSubtype(&m);
		mt.SetSubtype(&MEDIASUBTYPE_YV12);
	}
	else //if (format==MS_RGB24)
	{
		mt.SetSubtype(&MEDIASUBTYPE_RGB24);
	}

	//mt.SetSubtype(&MEDIASUBTYPE_IYUV);
	//mt.SetSubtype(&MEDIASUBTYPE_YUYV);
	//mt.SetSubtype(&MEDIASUBTYPE_RGB24);
	//mt.SetSampleSize();
	mt.formattype = FORMAT_VideoInfo;
	mt.SetTemporalCompression(FALSE);

	VIDEOINFO *pvi = (VIDEOINFO *)
	mt.AllocFormatBuffer(sizeof(VIDEOINFO));
	if (NULL == pvi)
		return E_OUTOFMEMORY;
	ZeroMemory(pvi, sizeof(VIDEOINFO));
	if (format==MS_YUV420P)
	{
		pvi->bmiHeader.biCompression = MAKEFOURCC('I','4','2','0');
		pvi->bmiHeader.biCompression = MAKEFOURCC('Y','V','1','2');
		pvi->bmiHeader.biBitCount = 12;
	}
	else
	{
		pvi->bmiHeader.biCompression = BI_RGB;
		pvi->bmiHeader.biBitCount = 24;
	}
	pvi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	pvi->bmiHeader.biWidth = vsize->width;
	pvi->bmiHeader.biHeight = vsize->height;
	pvi->bmiHeader.biPlanes = 1;
	pvi->bmiHeader.biSizeImage = GetBitmapSize(&pvi->bmiHeader);
	pvi->bmiHeader.biClrImportant = 0;
	mt.SetSampleSize(pvi->bmiHeader.biSizeImage);
	mt.SetFormat((BYTE*)pvi, sizeof(VIDEOINFO));

	hr = s->m_pDXFilter->SetAcceptedMediaType(&mt);
	if(FAILED(hr))
	{
		return -5;
	}

	hr = s->m_pDXFilter->SetCallback(Callback); 
	if(FAILED(hr))
	{
		return -6;
	}

	hr = s->m_pDXFilter->QueryInterface(IID_IBaseFilter,
	 (LPVOID *)&s->m_pIDXFilter);
	if(FAILED(hr))
	{
		return -7;
	}

	hr = s->m_pGraph->AddFilter(s->m_pIDXFilter, L"DXFilter Filter");
	if(FAILED(hr))
	{
		return -8;
	}

#ifdef WM6
	ICreateDevEnum *pCreateDevEnum = NULL;
	IEnumMoniker *pEnumMoniker = NULL;
	IMoniker *pMoniker = NULL;

	ULONG nFetched = 0;

	hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, 
		IID_ICreateDevEnum, (PVOID *)&pCreateDevEnum);
	if(FAILED(hr))
	{
		return -9;
	}

	hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
		&pEnumMoniker, 0);
	if (FAILED(hr) || pEnumMoniker == NULL) {
		//printf("no device\n");
		return -10;
	}

	pEnumMoniker->Reset();

	hr = pEnumMoniker->Next(1, &pMoniker, &nFetched);
	if(FAILED(hr) || pMoniker==NULL)
	{
		return -11;
	}

	hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**)&s->m_pDeviceFilter );
	if(FAILED(hr))
	{
		return -12;
	}

	s->m_pGraph->AddFilter(s->m_pDeviceFilter, L"Device Filter");

	pMoniker->Release();
	pEnumMoniker->Release();
	pCreateDevEnum->Release();
#else
	WCHAR wzDeviceName[ MAX_PATH + 1 ];
	CComVariant   varCamName;
	CPropertyBag PropBag;
    CComPtr<IPersistPropertyBag>    pPropertyBag;
	GetFirstCameraDriver(wzDeviceName);

	hr = s->m_pDeviceFilter.CoCreateInstance( CLSID_VideoCapture ); 
	if (FAILED(hr))
	{
		return -8;
	}

	s->m_pDeviceFilter.QueryInterface( &pPropertyBag );
	varCamName = wzDeviceName;
	if(( varCamName.vt == VT_BSTR ) == NULL ) {
	  return E_OUTOFMEMORY;
	}
	PropBag.Write( L"VCapName", &varCamName );   
	pPropertyBag->Load( &PropBag, NULL );
	pPropertyBag.Release();

	hr = s->m_pGraph->AddFilter( s->m_pDeviceFilter, L"Video capture source" );
#endif

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

	// get null renderer
	s->m_pNullRenderer = NULL;
#if 0
	hr=s->m_pNullRenderer.CoCreateInstance(CLSID_NullRenderer);
	if(FAILED(hr))
	{
		return -13;
	}
#endif
	if (s->m_pNullRenderer!=NULL)
	{
		s->m_pGraph->AddFilter(s->m_pNullRenderer, L"Null Renderer");
	}

	hr = s->m_pBuilder->RenderStream(&PIN_CATEGORY_PREVIEW,
		&MEDIATYPE_Video, s->m_pDeviceFilter, s->m_pIDXFilter, s->m_pNullRenderer);
	if (FAILED(hr))
	{
		//hr = s->m_pBuilder->RenderStream(&PIN_CATEGORY_CAPTURE,
		//	&MEDIATYPE_Video, s->m_pDeviceFilter, s->m_pIDXFilter, s->m_pNullRenderer);
		if (FAILED(hr))
		{
			return -14;
		}
	}
	
	//m_pDXFilter->SetBufferSamples(TRUE);


		// Create the System Device Enumerator.
IFilterMapper *pMapper = NULL;
//IEnumMoniker *pEnum = NULL;
IEnumRegFilters *pEnum = NULL;

hr = CoCreateInstance(CLSID_FilterMapper, 
    NULL, CLSCTX_INPROC, IID_IFilterMapper, 
    (void **) &pMapper);

if (FAILED(hr))
{
    // Error handling omitted for clarity.
}

GUID arrayInTypes[2];
arrayInTypes[0] = MEDIATYPE_Video;
arrayInTypes[1] = MEDIASUBTYPE_dvsd;

hr = pMapper->EnumMatchingFilters(
        &pEnum,
        MERIT_HW_COMPRESSOR, // Minimum merit.
        FALSE,               // At least one input pin?
        MEDIATYPE_NULL,
        MEDIASUBTYPE_NULL,
        FALSE,              // Must be a renderer?
        FALSE,               // At least one output pin?
        MEDIATYPE_NULL,                  
        MEDIASUBTYPE_NULL);              

// Enumerate the monikers.
//IMoniker *pMoniker;
REGFILTER *pMoniker;
ULONG cFetched;
while (pEnum->Next(1, &pMoniker, &cFetched) == S_OK)
{
    IPropertyBag *pPropBag = NULL;
#if 0
	hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, 
       (void **)&pPropBag);

    if (SUCCEEDED(hr))
    {
        // To retrieve the friendly name of the filter, do the following:
        VARIANT varName;
        VariantInit(&varName);
        hr = pPropBag->Read(L"FriendlyName", &varName, 0);
        if (SUCCEEDED(hr))
        {
            // Display the name in your UI somehow.
        }
        VariantClear(&varName);

        // To create an instance of the filter, do the following:
        IBaseFilter *pFilter;
        hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter, (void**)&pFilter);
        // Now add the filter to the graph. Remember to release pFilter later.
    
        // Clean up.
        pPropBag->Release();
    }
    pMoniker->Release();
#endif

}

// Clean up.
pMapper->Release();
pEnum->Release();




	s_callback = s;
	hr = s->m_pControl->Run();
	if(FAILED(hr))
	{
		return -15;
	}

	s->rotregvalue=1;
	s->pix_fmt = format;
	s->vsize.height = vsize->height;
	s->vsize.width = vsize->width;
	return 0;
}
Exemplo n.º 3
0
// Assuming formating like...
//  http://user:[email protected]/directory/somefile.php?param=1&param=2
CPropertyBag CIpAddress::ParseUrl( oexCSTR pUrl, oexUINT uMaxBufferSize )
{
	// Ensure a valid pointer
    if ( !pUrl )
        return CPropertyBag();

	// NULL terminated string? tsk, tsk...
	if ( 0 >= uMaxBufferSize )
		uMaxBufferSize = zstr::Length( pUrl );

	// Anything to parse?
	if ( !uMaxBufferSize )
		return CPropertyBag();

	// Propety bag object
    CPropertyBag pb;

	// Read into a string object
    CStr str( pUrl, uMaxBufferSize );

//	pb[ oexT( "scheme" ) ].ToString() = str.Parse( oexT( "://" ) );

	// Read in the scheme
	oexINT nScheme = str.FindSubStr( oexT( "://" ), 3 );
	if ( 0 <= nScheme && nScheme == str.FindSubStr( oexT( ":" ), 1 ) )
		pb[ oexT( "scheme" ) ].ToString() = str.SubStr( 0, nScheme ),
		str.LTrim( nScheme + 3 );

	// Trim off leading forward slashes
//	str.LTrim( oexT( ":" ) );
//	str.LTrim( oexT( "/" ) );

	// Is there a username / password?
	CStr tmp = str.Parse( oexT( "@" ) );
	if ( tmp.Length() )
	{
		// Skip the @
		str++;

		// Divide username and password
		CStr s = tmp.Parse( oexT( ":" ) );
		if ( s.Length () )
		{	pb[ oexT( "username" ) ].ToString() = s;
			tmp++; pb[ oexT( "password" ) ].ToString() = tmp;
		} // end if
		else
			pb[ oexT( "username" ) ].ToString() = tmp;

	} // end if

	// Parse the host
	tmp = str.Parse( oexT( "/" ) );
	if ( tmp.Length() )
	{
		CStr s = tmp.Parse( oexT( ":" ) );
		if ( s.Length () )
		{	pb[ oexT( "host" ) ].ToString() = s;
			tmp++; pb[ oexT( "port" ) ].ToString() = tmp;
		} // end if
		else
			pb[ oexT( "host" ) ].ToString() = tmp;

	} // end if

	// Grab the next token
	tmp = str.Parse( oexT( "?" ) );
	if ( tmp.Length() )
	{
		// Host or path?
		if ( !pb.IsKey( oexT( "host" ) ) )
			pb[ oexT( "host" ) ].ToString() = tmp;
		else
			pb[ oexT( "path" ) ].ToString() = tmp;

		// Parse extra part
		if ( str.Length() )
		{
			// Trim separator if any
			if ( oexT( '?' ) == *str.Ptr() )
			{
				str.LTrim( 1 );

				// Anything left over?
				if ( str.Length() )				
					pb[ oexT( "extra" ) ].ToString() = str.Parse( oexT( "#" ) );

				// Check for fragment
				if ( oexT( '#' ) == *str.Ptr() )
				{
					// Strip off sep
					str.LTrim( 1 );

					// Check for fragment
					if ( str.Length() )
						pb[ oexT( "fragment" ) ].ToString() = str;

				} // end if

				// Then it's all the extra
				else
					pb[ oexT( "extra" ) ].ToString() += str;

			} // end if

		} // end if
		
	} // end if

	// Whatever is left is the host if not yet parsed
	else if ( !pb.IsKey( oexT( "host" ) ) )
	{	CStr s = str.Parse( oexT( ":" ) );
		if ( s.Length () )
		{	pb[ oexT( "host" ) ].ToString() = s;
			str++; pb[ oexT( "port" ) ].ToString() = str;
		} // end if
		else
			pb[ oexT( "host" ) ].ToString() = str;
	} // end else if

	// Then whatever is left is the path
	else
		pb[ oexT( "path" ) ].ToString() = str;

	return pb;
}
Exemplo n.º 4
0
HRESULT
CGraphManager::CreateCaptureGraphInternal()
{
    HRESULT       hr = S_OK;
    CComVariant   varCamName;
    CPropertyBag  PropBag;
    OAEVENT       oaEvent;
	WCHAR	      wzDeviceName[ MAX_PATH + 1 ];

    CComPtr<IMediaEvent>            pMediaEvent;
    CComPtr<IGraphBuilder>          pFilterGraph;
    CComPtr<IPersistPropertyBag>    pPropertyBag;
    CComPtr<IDMOWrapperFilter>      pWrapperFilter;
    CComPtr<IBaseFilter>			pImageSinkFilter;


    //
    // Create the capture graph builder and register the filtergraph manager. 
    //
    CHK( m_pCaptureGraphBuilder.CoCreateInstance( CLSID_CaptureGraphBuilder ));
    CHK( pFilterGraph.CoCreateInstance( CLSID_FilterGraph ));
	
    CHK( m_pCaptureGraphBuilder->SetFiltergraph( pFilterGraph ));


    //
    // Create and initialize the video capture filter
    //
    CHK( m_pVideoCaptureFilter.CoCreateInstance( CLSID_VideoCapture ));
    CHK( m_pVideoCaptureFilter.QueryInterface( &pPropertyBag ));

    // We are loading the driver CAM1 in the video capture filter. 
	CHK( GetFirstCameraDriver( wzDeviceName ));
    varCamName = wzDeviceName;
    if( varCamName.vt != VT_BSTR )
    {
        ERR( E_OUTOFMEMORY );
    }

    CHK( PropBag.Write( L"VCapName", &varCamName ));   
    CHK( pPropertyBag->Load( &PropBag, NULL ));

    // Everything succeeded, the video capture filter is added to the filtergraph
    CHK( pFilterGraph->AddFilter( m_pVideoCaptureFilter, L"Video Capture Filter Source" ));

	//
	// Create the still image filter, and connect it to the video capture filter
	//
	CHK( pImageSinkFilter.CoCreateInstance( CLSID_IMGSinkFilter ));
    CHK( pFilterGraph->AddFilter( pImageSinkFilter, L"Still image filter" ));
	CHK( m_pCaptureGraphBuilder->RenderStream( &PIN_CATEGORY_STILL, &MEDIATYPE_Video, m_pVideoCaptureFilter, NULL, pImageSinkFilter ));
	CHK( pImageSinkFilter.QueryInterface( &m_pImageSinkFilter ));

    //
    // Prevent the data from flowing into the capture stream
    //
 //   CHK( m_pCaptureGraphBuilder->ControlStream( &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, m_pVideoCaptureFilter, 0, 0 ,0,0 ));

    //
    // Let's get the handle for DShow events. The main loop will listen to both notifications from 
    // the UI thread and for DShow notifications
    //
    CHK( pFilterGraph->QueryInterface( IID_IMediaEvent, (void**) &pMediaEvent ));
    CHK( pMediaEvent->GetEventHandle( &oaEvent ));
    m_handle[1] = (HANDLE) oaEvent;

    m_fGraphBuilt = TRUE;
	NotifyMessage( MESSAGE_INFO, L"Builing the graph completed" );

Cleanup:
	if( FAILED( hr ))
	{
		NotifyMessage( MESSAGE_ERROR, L"Builing the graph failed" );
	}
    return hr;
}