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

2

5

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:

Mincing answered 26/12, 2010 at 0:11 Comment(4)
You are making life really difficult by not allowing glibc. Making direct syscalls (that's the OS API) is not much fun.Marozik
@Ben Voigt: you say it is possible using just glibc?Mincing
It's possible using no libraries, theoretically. It's possible to rewrite OS-X in pure assembly. However it would be a huge waste of time, since you'd spend a lot of time duplicating library code inside your program, when you could have just linked with it. All I'm saying is that it's ok to say "I'd like to minimize the dependencies", but saying "no external libraries at all" is somewhat ridiculous.Marozik
@Ben: I think he just means he wants to do it as simple and directly as possible, and not use 3rd party libraries, right?Horning
H
4

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
                }
            }
        }       
    }
Horning answered 26/12, 2010 at 19:0 Comment(4)
what are the includes needed?Mincing
QuickTime.h You know there's a lot of sample code on Apple's website that should get you started.Horning
FYI, the C API is deprecated. You're supposed to be using Objective-C for stuff like this.Horning
Have you tried to compile such code? because it seems not compilable=( what shall I do? Can you provide compilable C++ code please?Mincing
G
0

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
Geotaxis answered 13/12, 2021 at 16:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.