Rella
Rella

Reputation: 66935

How to get a list of video capture devices (web cameras) on Mac OS? (C++)

So all I need is simple - a list of currently avaliable video capture devices (web cameras). I need it in simple or C++ console app. By list I mean something like such console output:

1) Asus Web Camera
2) Sony Web Camera

So It seems simple but I have one requirement - use of native OS apis as much as possible - no external libs - after all - all we want is to print out a a list - not to fly onto the moon!) (and no use of objective-C, please - pure C/C++)

How to do such thing?


also from this series:

Upvotes: 5

Views: 6392

Answers (2)

alperenkilic
alperenkilic

Reputation: 47

clearly you can use system_profiler SPUSBDataType in terminal that is the answer:

USB:

    USB 3.1 Bus:

      Host Controller Driver: AppleT8103USBXHCI

        USB Camera-OV580:

          Product ID: 0x058a
          Vendor ID: 0x05a9  (OmniVision Technologies, Inc.)
          Version: 1.00
          Speed: Up to 5 Gb/s
          Manufacturer: Omnivision Technologies, Inc.
          Location ID: 0x01200000 / 1
          Current Available (mA): 900
          Current Required (mA): 512
          Extra Operating Current (mA): 0

    USB 3.1 Bus:

      Host Controller Driver: AppleT8103USBXHCI

Upvotes: 0

Ken Aspeslagh
Ken Aspeslagh

Reputation: 11594

You need to use SGGetChannelDeviceList, which is part of the QuickTime C API. Each device can have multiple inputs. The proper way to parse it is like this:

    // 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
                }
            }
        }       
    }

Upvotes: 4

Related Questions