Print Capture Devices Example for C++
HRESULT PrintDevice(LPCTSTR title, IltmsDevice* device)
{
HRESULT hr;
// print the device properties
_tprintf(_T("--- %s Device ---\n\n"), title);
{
CComBSTR v;
hr = device->get_Name(&v);
if(FAILED(hr))
goto error;
_tprintf(_T("Name = \"%s\"\n"), (LPCTSTR) CString(v));
}
{
CComBSTR v;
hr = device->get_FriendlyName(&v);
if(FAILED(hr))
goto error;
_tprintf(_T("FriendlyName = \"%s\"\n"), (LPCTSTR) CString(v));
}
{
VARIANT_BOOL v;
hr = device->get_Selected(&v);
if(FAILED(hr))
goto error;
_tprintf(_T("Selected = %s\n"), (v == VARIANT_TRUE) ? _T("true") : _T("false"));
}
error:
_tprintf(_T("\n"));
return hr;
}
HRESULT PrintDevices(LPCTSTR title, IltmsDevices* devices)
{
HRESULT hr;
long count;
_tprintf(_T("--- %s Devices ---\n\n"), title);
hr = devices->Refresh();
if(FAILED(hr))
goto error;
hr = devices->get_Count(&count);
if(FAILED(hr))
goto error;
for(long index = 0; index < count; index++)
{
CComPtr<IltmsDevice> device;
hr = devices->Item(index, &device);
if(FAILED(hr))
goto error;
hr = PrintDevice(title, device);
if(FAILED(hr))
goto error;
}
error:
_tprintf(_T("\n"));
return hr;
}
HRESULT PrintLiveStreamDevices(IltmsLiveStream* stream)
{
HRESULT hr;
// print the capture devices to stdout
_tprintf(_T("--- Live Stream Devices ---\n\n"));
{
CComPtr<IltmsDevices> devices;
hr = stream->get_VideoDevices(&devices);
if(FAILED(hr))
goto error;
hr = PrintDevices(_T("Video"), devices);
if(FAILED(hr))
goto error;
}
{
CComPtr<IltmsDevices> devices;
hr = stream->get_AudioDevices(&devices);
if(FAILED(hr))
goto error;
hr = PrintDevices(_T("Audio"), devices);
if(FAILED(hr))
goto error;
}
error:
_tprintf(_T("\n"));
return hr;
}
HRESULT PrintCaptureDevices(IltmsServer* server)
{
HRESULT hr;
CComPtr<IltmsLiveStreams> streams;
CComPtr<IltmsLiveStream> stream;
// create live stream just to enumerate the devices
hr = server->GetLiveStreams(&streams);
if(FAILED(hr))
goto error;
hr = streams->CreateLiveStream(&stream);
if(FAILED(hr))
goto error;
hr = PrintLiveStreamDevices(stream);
if(FAILED(hr))
goto error;
error:
return hr;
}