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:

Community
  • 1
  • 1
Rella
  • 65,003
  • 109
  • 363
  • 636
  • 1
    You are making life really difficult by not allowing glibc. Making direct syscalls (that's the OS API) is not much fun. – Ben Voigt Dec 26 '10 at 01:23
  • @Ben Voigt: you say it is possible using just glibc? – Rella Dec 26 '10 at 19:07
  • 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. – Ben Voigt Dec 26 '10 at 19:56
  • 1
    @Ben: I think he just means he wants to do it as simple and directly as possible, and not use 3rd party libraries, right? – Ken Aspeslagh Dec 26 '10 at 20:25

2 Answers2

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
                }
            }
        }       
    }
Ken Aspeslagh
  • 11,484
  • 2
  • 36
  • 42
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