Windows 7 - Enumerate List Of Record Devices (Audio & Video)

Asked By Dale on 26-May-08 11:15 AM
Anyone got a nice code snippet to list all the audio/video record devices.

The SDK has a nice code for getting all the PROFILES  but I cant find
anything for Audio and Video devices.


Vegethalia replied on 29-May-08 08:58 PM
There is a sample for that in the SDK, but, anyway...

HRESULT WMEncApiWrapper::GetDevicePlugInList(PluginInfoArray
&piaPlugins)
{
CComPtr<IWMEncSourcePluginInfoManager> pEncSrcPlugin;
CComPtr<IWMEncPluginInfo> pEncPluginInfo;
WMENC_SOURCE_TYPE srcType;
VARIANT_BOOL bResources, bAux;
CComBSTR bstr;
PLUGIN_INFO Plugin;
long lNumPlugs, lNumRes;
short iFlags;
int i, j;
HRESULT hr=3DS_OK;

if(m_pEncoder) {
do {
hr=3Dm_pEncoder->get_SourcePluginInfoManager(&pEncSrcPlugin);
if(FAILED(hr)) break;
hr=3DpEncSrcPlugin->get_Count(&lNumPlugs);
if(FAILED(hr)) break;
for(i=3D0; i<lNumPlugs; i++) {
hr=3DpEncSrcPlugin->Item(i, &pEncPluginInfo);
if(FAILED(hr)) break;
hr=3DpEncPluginInfo->get_SchemeType(&bstr);
if(FAILED(hr)) break;
if(_tcsicmp(bstr, CComBSTR("DEVICE"))=3D=3D0) {
hr=3DpEncPluginInfo->get_Resources(&bResources);
if(FAILED(hr)) break;
if(bResources=3D=3DVARIANT_TRUE) {
bstr.Empty();
hr=3DpEncPluginInfo->get_Name(&bstr);
if(FAILED(hr)) break;
Plugin.sPluginName=3Dbstr;
bstr.Empty();
hr=3DpEncPluginInfo->get_CLSID(&bstr);
if(FAILED(hr)) break;
Plugin.sCLSID=3Dbstr;
bstr.Empty();
hr=3DpEncPluginInfo->get_Copyright(&bstr);
if(FAILED(hr)) break;
Plugin.sCopyright=3Dbstr;
bstr.Empty();
hr=3DpEncPluginInfo->get_InfoURL(&bstr);
if(FAILED(hr)) break;
Plugin.sURL=3Dbstr;
hr=3DpEncPluginInfo->get_MediaType(&srcType);
if(FAILED(hr)) break;
Plugin.MediaType=3DsrcType;
hr=3DpEncPluginInfo->get_Exclusive(&bAux);
if(FAILED(hr)) break;
Plugin.bExclusive=3D(bAux=3D=3DVARIANT_FALSE);
hr=3DpEncPluginInfo->get_Hidden(&bAux);
if(FAILED(hr)) break;
Plugin.bHidden=3D(bAux=3D=3DVARIANT_TRUE);
Plugin.SchemeType=3DWMEncApiWrapper::PS_DEVICE;
hr=3DpEncPluginInfo->get_TransformFlags(&iFlags);
if(FAILED(hr)) break;
Plugin.TransformFlags=3D(PLUGIN_TRANSFORMFLAGS)iFlags;
hr=3DpEncPluginInfo->get_Count(&lNumRes);
if(FAILED(hr)) break;
for(j=3D0; j<lNumRes; j++) {
bstr.Empty();
hr=3DpEncPluginInfo->Item(j, &bstr);
if(FAILED(hr)) break;
Plugin.sResourceName=3Dbstr;
piaPlugins.Add(Plugin);
}
if(FAILED(hr)) break;
}
}
pEncPluginInfo.Release();
if(FAILED(hr)) break;
}
}while(false);

return hr;
}
else {
return E_POINTER;
}
}

I Hope this helps!

Vegethalia
----------------------------------------------
http://naturarea.pleyhades.com
Paul Kirkaas replied on 27-May-08 06:30 AM
Hi, Dale:

Look at the Examples section of the SDK, under "Listing all Devices"; I
think that's what you're looking for.

I don't have a "nice" code snippet, but I have some C++ code that works,
and populates 2 CComboBoxes (1 for audio & 1 for video) and initializes
them to the DV device, if present.  It's part of a CDialog class, and
uses various member variables, etc, so it won't just compile & run, and
you'll have to figure out what the various parameters are, but it might
give you an idea.  It also uses a template function, because you need to
iterate through two essentially identical classes -- one that's for
internal sources, and one that's for external DV devices.  The code
follows below; I hope it helps.

Paul

--


//Template function to do same thing with both Digital Video srcs &
//internal sources
template<class IWMEncPluginInfoManager>  HRESULT
getSources(IWMEncPluginInfoManager * pPluginInfoManager, CComboBox *
pCBSrcsVideo, CComboBox * pCBSrcsAudio, char devType)
{
HRESULT hr = 0;
int i;
int j;
int index;
long lCount;
long lResrcCount;
CComBSTR sScheme;
CComBSTR sName;
CString cString;
CString csTest, cMediaType;
VARIANT_BOOL bResources;
CString cType []={"BAD VALUE", "Source", "Transform", "Device
Control"};
CString csMediaType[]={"Media value out of range", "Audio",
WMENC_PLUGIN_TYPE  enumType;//Device, Source, etc.
WMENC_SOURCE_TYPE enumSrceType; //Audio, Video, etc
char * dt = "BAD VALUE";

if (devType == 'D') dt = "DEVICECONTROL";
if (devType == 'S') dt = "DEVICE";
IWMEncPluginInfo* pPlugInfo;

hr = pPluginInfoManager->get_Count(&lCount);
for (i = 0; i < lCount; i++)
{
// Set the IWMEncPluginInfo object to the current plug-in.
if ( SUCCEEDED( hr ) )
{
hr = pPluginInfoManager->Item(i, &pPlugInfo);
}
// Get the plugin type.
pPlugInfo->get_PluginType(&enumType);

// Get the media type (audio, video, etc)
pPlugInfo->get_MediaType(&enumSrceType);
// Find the plug-ins that support resources.
if ( SUCCEEDED( hr ) )
{
hr = pPlugInfo->get_SchemeType(&sScheme);
}
if (_wcsicmp(sScheme, CComBSTR(dt))==0)
{
// Find the devices.
if ( SUCCEEDED( hr ) )
{
hr = pPlugInfo->get_Resources(&bResources);
}
if ((bResources==VARIANT_TRUE) || devType == 'D')
{
// Loop through the resources in the current plug-in.
if ( SUCCEEDED( hr) || devType == 'D' )
{
hr = pPlugInfo->get_Count(&lResrcCount);
}
for (j = 0; j < lResrcCount; j++)
{
// Display the name of the plug-in.
if ( SUCCEEDED( hr ) )
{
hr = pPlugInfo->Item(j, &sName);
cString = sName;

cMediaType.Format("MediaType: <%d> ", enumSrceType);
csTest.Format(" Enum Media Type is: <%d> ",enumSrceType);
if (enumSrceType & 1)
{
cMediaType=" Audio ";
index=pCBSrcsAudio->AddString(cType[enumType] + "  " +csTest+
cMediaType + "//"+cString);
pCBSrcsAudio->SetItemDataPtr( index, (void*)pPlugInfo  );
if (pCBSrcsAudio->GetCount()==1)
pCBSrcsAudio->SetCurSel(0);
if (devType=='D') //It's a DV device; make
default
pCBSrcsAudio->SetCurSel(index);
}
if (enumSrceType & 2)
{
cMediaType=" Video ";
index=pCBSrcsVideo->AddString(cType[enumType] + "  " +csTest+
cMediaType + "//"+cString);
pCBSrcsVideo->SetItemDataPtr( index, (void*)pPlugInfo  );
if (pCBSrcsVideo->GetCount()==1)
pCBSrcsVideo->SetCurSel(0);
if (devType=='D') //It's a DV device; make
default
pCBSrcsVideo->SetCurSel(index);
}
}
//wprintf(CComBSTR("%s\n"), sName);
}
}
}
}

return hr;
}


----------------------
//Get the list of input devices and fill the combo boxes.

int COneClickApp1Dlg::m_PopulateListDevices()
{

IWMEncSourcePluginInfoManager* pSrcPlugMgr;
IWMEncDeviceControlPluginInfoManager* pDCPlugMgr;
//    IWMEncPluginInfo* pPlugInfo;

//Clear out the combo-boxes:

mp_comboAudioDevices->ResetContent( );
mp_comboVideoDevices->ResetContent( );

// Retrieve source and device plug-in info manager objects from
IWMEncoder.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->get_SourcePluginInfoManager(&pSrcPlugMgr);
}
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->get_DeviceControlPluginInfoManager(&pDCPlugMgr);
}
getSources (pSrcPlugMgr, mp_comboVideoDevices,
mp_comboAudioDevices, 'S');
getSources (pDCPlugMgr, mp_comboVideoDevices,mp_comboAudioDevices,
'D');
return 1;
}
Dale replied on 29-May-08 06:11 PM
Any Chance I could get that convert to VB?  Not a C man at all.  Just a
lowbie VB person.  Thank you.