NickSullivan-6817 avatar image
1 Vote"
NickSullivan-6817 asked jadailey-MSFT commented

MediaCapture.CaptureDeviceExclusiveControlStatusChanged Event not triggered when legacy app accesses camera stream

CONTEXT: I would like to know when any other app grabs hold of the RGB camera stream, so I can stop streaming the IR stream of an RGB-IR device (IR LEDs cause an undesirable effect on the RGB stream).

The best way I could think was to monitor ExclusiveControl being grabbed on the RGB stream. This works with newer apps (e.g. Camera app), which presumably use the Windows.Media.Capture API. However, for legacy apps (e.g. AmCap, YouCam), this event only gets triggered when the app lets go of the stream (i.e. NOT when starting up). I assume these apps are using the UVC API to access it, hence the difference.

Can you confirm whether this is a bug or not, and when it might be resolved? If you have an alternative suggestion on how to monitor the RGB stream, please let me know!

In order to work past the fact that CaptureDeviceExclusiveControlStatusChanged() does not trigger on camera startup for legacy apps, I tried hooking into FormatChanged. This appears to work, but will only trigger if I have a MediaFrameReader instance streaming. Is this necessary? I feel I should be able to hook in and receive notifications without having to turn the camera on.

FYI: I have also filed this on the Feedback Hub, here:
However, I did not get feedback previously when I have filed there.

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Not sure I follow. Are you writing a UWP app or a legacy app?

What is the "undesirable effect" that is caused by the IR LEDs?

0 Votes 0 ·

Hi jadailey,

I am writing a Desktop Bridge App, but am trying to exclusively use the UWP API when accessing the camera (i.e. Windows.Media.Devices). We are transitioning over to UWP only.

The 'undesirable effect' is that the IR LEDs, when on, cause a red hue on the RGB stream. This is due to the fact that most webcams have imperfect IR-cut filters (filters to cut-out the IR band of the sensor).

I hope that answers your questions... Please let me know if anything is still unclear.

0 Votes 0 ·

Yeah, that does help to clarify. Please seem my answer.

0 Votes 0 ·

1 Answer

jadailey-MSFT avatar image
1 Vote"
jadailey-MSFT answered jadailey-MSFT commented

Unfortunately the CaptureDeviceExclusiveControlStatusChanged event will not work the way you are expecting. This is due to the code we added in the creators update to allow for UVC devices to be shared between apps. This sharing is completely automatic in the UWP space but legacy apps are unaware of this functionality for backward compatibility reasons. In other words there is no default communication plumed between the UVC sharing service in UWP and legacy media APIs. So there is no way to guarantee that CaptureDeviceExclusiveControlStatusChanged will get triggered if the RGB camera is allocated by a legacy media API.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you very much for the response. I understand, though it's a bit unfortunate. Out of curiosity, is there any alternative way I could monitor for camera usage as I've described? I am aware of two other events I can hook into, with varying results: (a) FormatChanged, and (b) MediaCapture.CameraStreamStateChanged.

For (a), I have the issue I described above, where I only receive the event if a MediaFrameReader instance is streaming on my end.

For (b), I can't seem to get the event to occur in any scenario whatsoever. From reading the documentation, I can understand that this may trigger only during explicit recording. I guess I am just hoping it isn't the case, since it would be quite useful. From testing, I can never get this event to trigger and the state always appears to be NotStreaming (even when streaming).

Again, I really appreciate the quick feedback. If it makes more sense to open a separate query just for these, I can do that as well.

0 Votes 0 ·

AFAIK there is no way to tell if another device has been enabled by a legacy media API outside of going through MF to get the source and using IKSControl to query the driver directly. This isn't something that is gong to be available in UWP. Again, this is because of the shared frame buffer layer discussed in my post above. I wish I had a better answer for you but I don't think there is an easy solution for your scenario.


0 Votes 0 ·