Closed Bug 1732409 Opened 3 years ago Closed 3 years ago

Prepare for dispatching devicechange events even without an actively capturing MediaStreamTrack

Categories

(Core :: WebRTC: Audio/Video, enhancement, P1)

enhancement

Tracking

()

RESOLVED FIXED
97 Branch
Tracking Status
firefox97 --- fixed

People

(Reporter: karlt, Assigned: karlt)

References

Details

Attachments

(12 files, 6 obsolete files)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

Gecko currently dispatches "devicechange" events only when

  1. there is an actively capturing MediaStreamTrack, or
  2. the origin has a permission for permanent access to a camera or microphone.

"fully active and has focus" has subsequently been added to the spec as a sufficient condition. This provides for "audiooutput" devices even when getUserMedia() is not used.

The permissions check was replaced in the spec with a [[canExposeDeviceInfo]] MediaDevices slot, set on getUserMedia() grant.
This makes the actively capturing test redundant as a track cannot become active without a getUserMedia() grant.

Removing the actively capturing test will resolve a defect where actively capturing tracks can be prematurely GC'd causing loss of "devicechange" events.

With provision of "devicechange" events in more circumstances, we should only add events for devices that should be exposed.

Depends on: 1732410

"User Agents MAY add fuzzing on the timing of events to avoid cross-origin activity correlation."
Waiting for focus before dispatch would provide the best protection against cross-origin activity correlation. With the plan to wait for focus in enumerateDevices(), there would be little value in dispatching "devicechange" before enumerateDevices() could proceed.

Severity: -- → N/A
Priority: -- → P1
Depends on: 1734267
Depends on: 1738186
Depends on: 1744358
Depends on: 1744364

"devicechange" events should be dispatched only when devices are physically added or removed rather then when they become exposed to content through getUserMedia() or selectAudioOutput(). To provide this, a record of the ordered set of system physical devices at the time when devicechange event decisions were last performed will be kept on each MediaDevices object. This record can be compared with subsequent sets to determine whether the changes should be exposed in a "devicechange" event.

This approach overcomes a number of issues with the spec's approach of keeping a [[storedDeviceList]] that includes only exposed devices and is reset on exposure decision changes.

To reduce to memory footprint of these device set records, the sets will be shared across Window/MediaDevices objects where appropriate.

to aid in debugging.

Depends on D132894

and ignore fake:false so that it behaves like a missing/default fake parameter
and does not override "media.navigator.streams.fake".

Neither of these combinations are required in tests, but the fake:true
override provides simpler testing of real-world scenarios, such as bug
1743524, even when loopback prefs are set, as is the preferred default test
configuration.

Also, adjusting the logic in this way so that fake: in getUserMedia()
behaves similarly to ShouldResistFingerprinting() in enumerateDevices() will
allow simplification of EnumerateDevicesImpl() parameters and moving the logic
for the effect of preferences on enumeration to one place.

Depends on D132895

"media.navigator.permission.disabled" exists for controlling the permission
prompt separately.

This will allow consolidation of camera and microphone preference handling
into EnumerateRawDevices(). Although auto-disabling permission with
"media.navigator.streams.fake" is sometimes useful for tests, it is actually
easier to consider them independently because sometimes the auto-disabling
needs to be overridden.

The logic to disable the permission prompt with content-exposed fake:true
parameter is maintained as is.

The CamerasParent usage of "media.navigator.permission.fake" seems to have
been a misunderstanding in
https://hg.mozilla.org/mozilla-central/rev/c5d6c3e00c91dd0595a12b145c66cf4f2a890591#l6.129

Depends on D132896

This is performed for
"media.navigator.streams.fake"
"media.video_loopback_dev"
"media.audio_loopback_dev"

Depends on D132897

reducing the complexity in EnumerateDevicesImpl() and facilitating a future
call to perform a similar operation in an enumerateDevices() refactor for
device-change event analysis.

Depends on D132898

EventTarget::SetEventHandler() will cause EventListenerAdded() to be called.

Depends on D132899

MediaDevices are suitable for use on any thread.
This will support a simple override of devices from enumerateDevices() when
resistFingerprinting is set.

Depends on D132900

Provides that the list added must match the list removed.

Depends on D132901

The same list of physical devices can, in a subsequent patch, be returned to
multiple Windows, so that their MediaDevices objects can efficiently keep (and
share) a record of the set of devices when the last "devicechange" event was
queued.

Depends on D132902

enumerateDevices() and devicechange events both require focus.
Focus emulation facilitates running tests on developer machines.

Depends on D132903

The device MUST be uniquely identified by its identifier and its kind.
https://w3c.github.io/mediacapture-main/#dom-mediadeviceinfo-deviceid

A change in name now behaves like a change in device, which is useful for
devicechange event tests.

Depends on D132904

"media.ondevicechange.fakeDeviceChangeEvent.enabled" does not change any
devices and so will not generate any events if/when no-op devicechange events
are filtered out.

The test is rearranged to reduce the wait for no event and run some steps in
parallel, so that the test runs in half the time. This benefit will
accumulate as more scenarios are added to the test.

Depends on D132905

There was little value in dispatching devicechange before enumerateDevices
could proceed.

Depends on D132906

"fully active and has focus" is now a sufficient condition for dispatching "devicechange" events if the change in devices should be visible from enumerateDevices().
https://github.com/w3c/mediacapture-main/pull/574/files#diff-1217ca1c44ff30a33dd50c49d03b5cadc9633c789df8ff9370ed4a42859e1211R3146

Permissions checks are replaced with [[canExposeCameraInfo]] and [[canExposeMicrophoneInfo]] slots set by getUserMedia().
https://github.com/w3c/mediacapture-main/pull/641
https://github.com/w3c/mediacapture-main/pull/773

The "media.navigator.permission.disabled" pref is no longer involved in "devicechange" dispatch decisions.

Depends on D132907

Depends on D132910

The fake MediaStreamConstraints dictionary member has no effect on screen and
window sharing because it affects only microphones and cameras since
https://hg.mozilla.org/mozilla-central/rev/39c9062db9d9

Attachment #9254991 - Attachment description: Bug 1732409 test devicechange with additional devices and different exposure timing r?jib → Bug 1732409 test "devicechange" event with different exposure timing r?jib
Keywords: leave-open
Pushed by ktomlinson@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/21564d1c7057 remove ignored "fake" dictionary member passed when screensharing r=jib https://hg.mozilla.org/integration/autoland/rev/3f3fe6a97855 use is(a,b) instead of ok(a===b) for more info in failure message r=jib https://hg.mozilla.org/integration/autoland/rev/748715ddf3c0 check test assumptions about device info labels r=jib https://hg.mozilla.org/integration/autoland/rev/a82289f4ec60 let fake:true getUserMedia() parameter override loopback prefs r=jib https://hg.mozilla.org/integration/autoland/rev/0a6943f27392 make getUserMedia() permission prompt requirement independent of "media.navigator.streams.fake" r=jib https://hg.mozilla.org/integration/autoland/rev/39bcb53f30ba consolidate camera and microphone preference handling into EnumerateRawDevices r=jib
Pushed by ktomlinson@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/7b6419c9cc70 remove ignored "fake" dictionary member passed when screensharing r=jib https://hg.mozilla.org/integration/autoland/rev/ae9a00796731 use is(a,b) instead of ok(a===b) for more info in failure message r=jib https://hg.mozilla.org/integration/autoland/rev/482eff672f41 check test assumptions about device info labels r=jib
Regressions: 1747190
Flags: needinfo?(karlt)
Pushed by ktomlinson@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/53ee4bd9dd9e remove unnecessary additional SetupDeviceChangeListener() call r=jib https://hg.mozilla.org/integration/autoland/rev/6ace5bb48f4b support main thread enumeration of devices from MediaEngineDefault r=pehrsons https://hg.mozilla.org/integration/autoland/rev/e4b27e4b78aa use an enumerator template for adding and removing pref observation r=jib https://hg.mozilla.org/integration/autoland/rev/214b3fd5a76a emulate focus for webrtc mochitests r=jib https://hg.mozilla.org/integration/autoland/rev/9e5cbf574e40 change fake camera device id when name changes r=jib
Pushed by ktomlinson@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/a1358132987f let fake:true getUserMedia() parameter override loopback prefs r=jib https://hg.mozilla.org/integration/autoland/rev/bbe19c0105fb make getUserMedia() permission prompt requirement independent of "media.navigator.streams.fake" r=jib https://hg.mozilla.org/integration/autoland/rev/e9a430d93229 consolidate camera and microphone preference handling into EnumerateRawDevices r=jib
Pushed by ktomlinson@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/2dcdc75fdf55 move GetPrincipalKey() call to AnonymizeDevices() r=jib
Regressions: 1719578
Depends on: 1747946
See Also: → 1650054
No longer regressions: 1719578
Blocks: 1753131

I'll move the remaining patches to bug 1753131.

No longer blocks: 1498512
Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Summary: Dispatch devicechange events even without an actively capturing MediaStreamTrack → Prepare for dispatching devicechange events even without an actively capturing MediaStreamTrack
Target Milestone: --- → 97 Branch

Comment on attachment 9253816 [details]
Bug 1732409 provide a method to return a cached list of physical devices r?jib

Revision D132903 was moved to bug 1753131. Setting attachment 9253816 [details] to obsolete.

Attachment #9253816 - Attachment is obsolete: true

Comment on attachment 9253819 [details]
Bug 1732409 use fake device name changes to test devicechange events r?jib

Revision D132906 was moved to bug 1753131. Setting attachment 9253819 [details] to obsolete.

Attachment #9253819 - Attachment is obsolete: true

Comment on attachment 9253820 [details]
Bug 1732409 wait for focus before dispatching devicechange events r?jib

Revision D132907 was moved to bug 1753131. Setting attachment 9253820 [details] to obsolete.

Attachment #9253820 - Attachment is obsolete: true

Comment on attachment 9253821 [details]
Bug 1732409 Dispatch devicechange events even without an actively capturing MediaStreamTrack r?jib

Revision D132908 was moved to bug 1753131. Setting attachment 9253821 [details] to obsolete.

Attachment #9253821 - Attachment is obsolete: true

Comment on attachment 9253822 [details]
Bug 1732409 test devicechange events when first device is added or last is removed r?jib

Revision D132909 was moved to bug 1753131. Setting attachment 9253822 [details] to obsolete.

Attachment #9253822 - Attachment is obsolete: true

Comment on attachment 9254991 [details]
Bug 1732409 test "devicechange" event with different exposure timing r?jib

Revision D133604 was moved to bug 1753131. Setting attachment 9254991 [details] to obsolete.

Attachment #9254991 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: