所以我需要的只是简单 - 目前可用的视频捕获设备(网络摄像头)列表。我需要在简单或C ++控制台应用程序中。按列表我的意思是像这样的控制台输出:
1) Asus Web Camera
2) Sony Web Camera
所以看起来很简单,但我有一个要求 - 尽可能多地使用本机操作系统apis - 毕竟没有外部库 - 我们想要的就是打印出一个列表 - 不要飞到月球上!)(和没有使用Objective-C,请 - 纯C / C ++)
怎么做这样的事情?
也来自这个系列:
答案 0 :(得分:4)
您需要使用SGGetChannelDeviceList,它是QuickTime C API的一部分。每个设备可以有多个输入。解析它的正确方法是这样的:
// first get a video channel from the sequence grabber
ComponentDescription theDesc;
Component sgCompID;
ComponentResult result;
theDesc.componentType = SeqGrabComponentType;
theDesc.componentSubType = 0L;
theDesc.componentManufacturer = 'appl';
theDesc.componentFlags = 0L;
theDesc.componentFlagsMask = 0L;
sgCompID = FindNextComponent (NULL, &theDesc);
seqGrabber = OpenComponent (sgCompID);
result = SGInitialize (seqGrabber);
result = SGNewChannel (seqGrabber, VideoMediaType, &videoChannel);
SGDeviceList theDevices;
SGGetChannelDeviceList(videoChannel, sgDeviceListDontCheckAvailability | sgDeviceListIncludeInputs, &theDevices);
if (theDevices)
{
int theDeviceIndex;
for (theDeviceIndex = 0; theDeviceIndex != (*theDevices)->count; ++theDeviceIndex)
{
SGDeviceName theDeviceEntry = (*theDevices)->entry[theDeviceIndex];
// name of device is a pstring in theDeviceEntry.name
SGDeviceInputList theInputs = theDeviceEntry.inputs;
if (theInputs != NULL)
{
int theInputIndex;
for ( theInputIndex = 0; theInputIndex != (*theInputs)->count; ++theInputIndex)
{
SGDeviceInputName theInput = (*theInputs)->entry[theInputIndex];
// name of input is a pstring in theInput.name
}
}
}
}