Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

176 lines
5.4 KiB

//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright © 2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 08/10/2003
// PROJECT:
// SUBSYSTEM:
// FILE: LgDirectShowVideoInputEnum.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of LgDirectShowVideoInputEnum.cpp
//----------------------------------------------------------------------------
#include "stdafx.h"
#include "LgDirectShowVideoInputEnum.h"
CLgDirectShowVideoInputEnum::CLgDirectShowVideoInputEnum()
{
::CoInitializeEx( NULL, COINIT_MULTITHREADED );
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgDirectShowVideoInputEnum::CLgDirectShowVideoInputEnum") );
}
CLgDirectShowVideoInputEnum::~CLgDirectShowVideoInputEnum()
{
Destroy();
::CoUninitialize();
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgDirectShowVideoInputEnum::~CLgDirectShowVideoInputEnum") );
}
BOOL CLgDirectShowVideoInputEnum::Create()
{
// destroy old incarnation
Destroy();
// Create the system device enumerator.
ICreateDevEnum *pDevEnum = NULL;
HRESULT hr = ::CoCreateInstance( CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, IID_ICreateDevEnum, (void **)&pDevEnum );
if( FAILED(hr) || !pDevEnum )
{
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgDirectShowVideoInputEnum::Create"), _T("CoCreateInstance(IID_ICreateDevEnum) failed") );
return FALSE;
}
// Create an enumerator for video capture devices.
IEnumMoniker *pClassEnum = NULL;
hr = pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pClassEnum, 0 );
if( FAILED(hr) || !pClassEnum )
{
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgDirectShowVideoInputEnum::Create"), _T("pDevEnum->CreateClassEnumerator failed") );
pDevEnum->Release();
return FALSE;
}
// enumerate all devices
ULONG cFetched;
IMoniker *pMoniker = NULL;
while( pClassEnum->Next(1, &pMoniker, &cFetched) == S_OK )
{
IPropertyBag *pPropBag;
hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag);
if( SUCCEEDED(hr) )
{
DSVID_INFO DeviceInfo;
INT nProperies = 0;
// 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))
{
::WideCharToMultiByte( CP_OEMCP, 0, varName.bstrVal, -1, DeviceInfo.pFrendlyName, MAX_PATH, 0, 0 );
nProperies++;
}
VariantClear(&varName);
pPropBag->Release();
LPWSTR pDisplayName = NULL;
hr = pMoniker->GetDisplayName( NULL, NULL, &pDisplayName );
if( SUCCEEDED(hr) )
{
wcsncpy( DeviceInfo.pDisplayName, pDisplayName, MAX_PATH );
nProperies++;
::CoTaskMemFree( pDisplayName );
}
// if all property is ok
if( nProperies == 2 )
{
m_DeviceArray.Add( DeviceInfo );
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgDirectShowVideoInputEnum::Create"), _T("Found capture device \"%s\" (%S)"), DeviceInfo.pFrendlyName, DeviceInfo.pDisplayName );
}
}
pMoniker->Release();
}
pClassEnum->Release();
pDevEnum->Release();
return TRUE;
}
void CLgDirectShowVideoInputEnum::Destroy()
{
m_DeviceArray.RemoveAll();
}
INT CLgDirectShowVideoInputEnum::GetVideoInputDeviceCount()
{
return m_DeviceArray.GetCount();
}
BOOL CLgDirectShowVideoInputEnum::GetVideoInputDeviceInfo( INT nDevice, PDSVID_INFO pDeviceInfo )
{
if( nDevice < 0 || nDevice >= m_DeviceArray.GetCount() )
return FALSE;
if( !pDeviceInfo )
return FALSE;
*pDeviceInfo = m_DeviceArray[nDevice];
return TRUE;
}
IBaseFilter* CLgDirectShowVideoInputEnum::CreateCaptureFilter( LPCWSTR pDisplayName )
{
if( !pDisplayName )
{
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, NULL, _T("CLgDirectShowVideoInputEnum::CreateCaptureFilter"), _T("pDisplayName is NULL") );
return NULL;
}
IBindCtx *pBindCtx = NULL;
HRESULT hr = ::CreateBindCtx( 0, &pBindCtx );
if( FAILED(hr) || !pBindCtx )
{
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, NULL, _T("CLgDirectShowVideoInputEnum::CreateCaptureFilter"), _T("CreateBindCtx failed with 0x%08X"), hr );
return NULL;
}
IMoniker *pMoniker = NULL;
ULONG nEaten = 0;
hr = MkParseDisplayName( pBindCtx, pDisplayName, &nEaten, &pMoniker );
if( FAILED(hr) || !pMoniker )
{
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, NULL, _T("CLgDirectShowVideoInputEnum::CreateCaptureFilter"), _T("MkParseDisplayName failed with 0x%08X"), hr );
pBindCtx->Release();
return NULL;
}
IBaseFilter *pCaptureFilter = NULL;
hr = pMoniker->BindToObject( pBindCtx, 0, IID_IBaseFilter, (void**) &pCaptureFilter );
pBindCtx->Release();
pMoniker->Release();
if( FAILED(hr) || !pCaptureFilter )
{
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, NULL, _T("CLgDirectShowVideoInputEnum::CreateCaptureFilter"), _T("pMoniker->BindToObject failed with 0x%08X"), hr );
return NULL;
}
return pCaptureFilter;
}
IBaseFilter* CLgDirectShowVideoInputEnum::CreateCaptureFilter( INT nDevice )
{
if( nDevice < 0 || nDevice >= m_DeviceArray.GetCount() )
{
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, NULL, _T("CLgDirectShowVideoInputEnum::CreateCaptureFilter"), _T("Invalid device ID <%d>"), nDevice );
return NULL;
}
return CLgDirectShowVideoInputEnum::CreateCaptureFilter( m_DeviceArray[ nDevice ].pDisplayName );
}