Closed Bug 1308114 Opened 4 years ago Closed 4 years ago

devicechange event is not fired if the script doesn't call getusermedia or enumerateDevices


(Core :: WebRTC: Audio/Video, defect, P2)




Tracking Status
firefox52 --- fixed


(Reporter: mchiang, Assigned: mchiang)




(1 file)

According to the spec, if the script sets navigator.mediaDevices.ondevicechange and the permission state is "always granted", the User Agent MUST fires a devicechange event when a new media input device is made available even though the script never call getusermedia or enumerateDevices.

Currently Nightly won't fire the event in this condition because camera engine is not setup via getusermedia or enumerateDevices.

We need to ensure camera engine setup when the script set ondevicechange handler.
Assignee: nobody → mchiang
Don't forget .addEventListener and microphones (do we have microphones yet?)
Comment on attachment 8798327 [details]
Bug 1308114 - Setup camera engine when the script sets navigator.mediaDevices.ondevicechange;

Up to you if you want to land this with a nit fix, or refactor by adding an IPDL EnsureInitialized() (SendEnsureInitialized/RecvEnsureinitialized).  

Also, is there any easy way to know that we don't need to do this IPC again?  Not a big issue, since this is only on AddDeviceChangeCallback, so the total overhead is very small - Only consider this if it's trivially available, which it probably is not.

::: dom/media/systemservices/CamerasChild.cpp:164
(Diff revision 1)
> +  // CamerasaParent api, e.g., RecvNumberOfCaptureDevices(), is called.
> +
> +  // So here we call NumberOfCaptureDevices in order to setup camera engine
> +  // via EnsureInitialized(aCapEngine)
> +
> +  NumberOfCaptureDevices(CameraEngine);

Your comment is good, though you're relying on a side-effect.  Better (though not mandatory) would be to add an ipdl API to tell CamerasParent to initialize - perhaps simply expose EnsureInitialized(CameraEngine).

Otherwise, to make it slightly more clear, add "Unused <<" or "(void)" to make it clear we're ignoring the return.
Attachment #8798327 - Flags: review?(rjesup) → review+
(In reply to Jan-Ivar Bruaroey [:jib] from comment #2)
> Don't forget .addEventListener
Yes, addEventListener case is also covered.

> and microphones (do we have microphones yet?)
Yes, we listen to both camera and microphone plug in/out event in the camera engine.

Mac: The AVFoundation observer AVCaptureDeviceWasConnectedNotification monitor both audio & video devices.

Linux: We monitor /dev/v4l/by-path/ for camera and /dev/snd/by-path/ for microphone

Windows: We monitor the event WM_DEVICECHANGE for both audio & video devices.
Rank: 27
Priority: -- → P2
Pushed by
Setup camera engine when the script sets navigator.mediaDevices.ondevicechange; r=jesup
Keywords: checkin-needed
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla52
You need to log in before you can comment on or make changes to this bug.