QTCaptureDeviceWasConnectedNotification

536 Views Asked by At

I am developing a Desktop application that lists the webcams connected to the system. When the user selects the web-cam app streams from the device to the QTCaptureView. I have registered to the notification QTCaptureDeviceWasDisconnectedNotification and QTCaptureDeviceWasConnectedNotification so that I remove and add the device to the list whenever device is disconnected and connected.

The problem is that QTCaptureDeviceWasConnectedNotification is posted twice when a device is connected. What is the reason for this?

Also, in one of my Mac Book I get the following problem frequently. The device obtained from QTCaptureDeviceWasConnectedNotification 2nd notification (I get two notifications) does not have the localized description name. Could you please tell me what might have gone wrong here?

2

There are 2 best solutions below

0
On BEST ANSWER

I had the same problem. The reason of such interesting behavior in my case was webcam with built-in microphone. So, when attaching such multi-purpose device there will be two notifications - one for video capture device and second for built-in microphone.

This is list of my general faults that blocked me from understanding the situation (possibly will help you):

  • Was used webcam with built-in microphone
  • Was used [QTCaptureDevice inputDevicesWithMediaType:] instead of [QTCaptureDevice inputDevices]. That blocked me from seeing other types of devices attached (such as microphone)
  • In my test I logged nothing when there is no "video" devices. That's the reason I saw two connected notifications (video,video+mic) and only one disconnected (-mic,-video) - that confused me at first.

Here logs from my test.

On device attach first notification is:

Device++ #0: "AppleHDAEngineInput:1B,0,1,1:4" - "AppleHDA:12"
Device++ #1: "AppleHDAEngineInput:1B,0,1,0:3" - "AppleHDA:12"
Device++ #2: "0xfd100000046d0990" - "UVC Camera VendorID_1133 ProductID_2448"

You can see UVC camera alone. Second notification is:

Device++ #0: "AppleHDAEngineInput:1B,0,1,1:4" - "AppleHDA:12"
Device++ #1: "AppleUSBAudioEngine:Unknown Manufacturer:Logitech Camera:5895DC4F:3" - "AppleUSBAudioDevice:Logitech Camera"
Device++ #2: "AppleHDAEngineInput:1B,0,1,0:3" - "AppleHDA:12"
Device++ #3: "0xfd100000046d0990" - "UVC Camera VendorID_1133 ProductID_2448"

You can see UVC camera and AppleUSBAudioEngine - the microphone.

On device detach there will be two notification also. First one:

Device-- #0: "AppleHDAEngineInput:1B,0,1,1:4" - "AppleHDA:12"
Device-- #1: "AppleHDAEngineInput:1B,0,1,0:3" - "AppleHDA:12"
Device-- #2: "0xfd100000046d0990" - "UVC Camera VendorID_1133 ProductID_2448"

No microphone, UVC camera still there. Second notification:

Device-- #0: "AppleHDAEngineInput:1B,0,1,1:4" - "AppleHDA:12"
Device-- #1: "AppleHDAEngineInput:1B,0,1,0:3" - "AppleHDA:12"

No UVC camera, no microphone.

Also, QTKit possibly can "merge" notifications since sometimes I get only one notification (one for connect and one for disconnect), so actual number of notifications depends not only from number of (sub-)devices connected or disconnected.

For localizedDisplayName - had no problems with it yet.

0
On

I had the same issue so I did some digging, and indeed it seems related to a device that contains audio as well as video.

So I tried to determine if the entry was an audio one or video one, here is what I found:

NSArray *inputDevices = [QTCaptureDevice inputDevices]; 
for(QTCaptureDevice *listDevice in inputDevices) {
    NSLog(@"%@",[[[device formatDescriptions] objectAtIndex:0] mediaType]);
}

The above outputs "vide" or "soun" which are the values for QTMediaTypeVideo and QTMediaTypeSound. So you can check if the above value is QTMediaTypeVideo if you just want to work with the video device.

Not sure if it helps your issue.