Closed Bug 1565689 Opened 5 years ago Closed 5 years ago

centralized media control service in chrome process

Categories

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

defect

Tracking

()

RESOLVED FIXED
mozilla70
Tracking Status
firefox70 --- fixed

People

(Reporter: alwu, Assigned: alwu)

References

Details

Attachments

(7 files, 1 obsolete file)

In the past, we use AudioChannelService to manage all media within one process, we did play, pause, stop those media and managed audio focus all in AudioChannelService.

However, since e10s, we have had multiple content processes and will have more in Fission. AudioChannelService no longer has an ability to manage media together which might started in different processes.

Therefore, we will implement a new service in chrome process which can manage media among different processes. In the first step, we would start from supporting play, pause and stop which we already have supported on Android by using the media control interface or managing audio focus among tabs.

In the future, we can extend the service to support hardware media key, using media key to control all (or one) tabs at the same time, or support something like having a media control in desktop. Like what Chrome did [1].

[1] https://www.theverge.com/2019/7/6/20684353/google-chrome-global-media-controls-play-button-pause-experimental-test-canary

Here is my current draft, in case that someone has an interest about it.
Will add some tests and split patches later.

Bugbug thinks this bug is a enhancement, but please change it back in case of error.

Type: defect → enhancement

It's actually a defect, because we have this feature long time ago but it has been broken since we switch to e10s.

Type: enhancement → defect

In order to have a centralized audio control in the parent process, we create two new classes here.

  • MediaController
    MediaController is a class used to control certain amount of media in the content process. Every controller corresponds to a browsing context.
    For example, TabMediaController would correspond to the top level browsing context, which mean it can control all media in the specific tab.

  • MediaControlService
    As there might be multiple tabs playing audio, so there would be multiple controllers. MediaControlService is a place to manage all of them, you can access specific controller through MediaControlService by providing controller ID.
    Everytime a controller becomes active, which means there is a media starts in corresponding browsing context, then controller would be added into the list of the MediaControlService. And it would be removed from the list when the media in corresponding browsering context stopped.

In order to support audio competing among different tabs, we implement a new class AudioFocusManager.

AudioFocusManager is used to assign the audio focus to different requester and decide which requester can own audio focus when audio competing happens.
When the audio competing happens, the last request would be a winner who can still own the audio focus, and all the other requesters would lose the audio focus.
Now MediaController is the onlt requester, it would request the audio focus when it becomes audible and revoke the audio focus when the controller is no longer active.

We don't want to enable audio competing by default, so hide this feature behind a static pref.

We implement some helpful functions in MediaControlUtils which can be used to notify controller when media starts/stops playing or become audible/inaudible.

For now, we can temporarily notify these changes in AudioChannelService where we have already known when media has these kinds of status changing.

This patch implements how to use MediaController to control corresponding media in content processes.

Attachment #9077824 - Attachment is obsolete: true
See Also: → 1567454
Blocks: 1571493
Pushed by alwu@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/0de7b1db3ef9 part1 : implement MediaController and MediaControlService. r=baku https://hg.mozilla.org/integration/autoland/rev/ba665f96330d part2 : implement AudioFocusManager. r=baku https://hg.mozilla.org/integration/autoland/rev/177f2b26c892 part3 : use static pref to control audio competing. r=baku https://hg.mozilla.org/integration/autoland/rev/faaa4e9ba8d3 part4 : notify controller about media active state and audible state changed from content processes. r=baku https://hg.mozilla.org/integration/autoland/rev/4f508252b015 part5 : control media from chrome process. r=farre,baku https://hg.mozilla.org/integration/autoland/rev/278340adf69c part6 : add gtests. r=baku https://hg.mozilla.org/integration/autoland/rev/36ea91bf28f7 part7 : add browser test. r=baku

Have updated the fix, waiting for the try result and will push them again if all results are good.

Flags: needinfo?(alwu)
Pushed by alwu@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/1d27d083e974 part1 : implement MediaController and MediaControlService. r=baku https://hg.mozilla.org/integration/autoland/rev/1ca26f550f4b part2 : implement AudioFocusManager. r=baku https://hg.mozilla.org/integration/autoland/rev/d3db3285e933 part3 : use static pref to control audio competing. r=baku https://hg.mozilla.org/integration/autoland/rev/d9f7fcbef3ee part4 : notify controller about media active state and audible state changed from content processes. r=baku https://hg.mozilla.org/integration/autoland/rev/9014276e070a part5 : control media from chrome process. r=farre,baku https://hg.mozilla.org/integration/autoland/rev/49c41a9238f9 part6 : add gtests. r=baku https://hg.mozilla.org/integration/autoland/rev/9ebf6f8a4fda part7 : add browser test. r=baku

From the push result [1], although there are some orange failures, but all of them seem not related with my change, and I didn't see any assertion or suspious failure this time.

[1] https://treeherder.mozilla.org/#/jobs?repo=try&revision=41d891a3d473e706243a9d3131a7ea70e79f620c&selectedJob=260625544

Flags: needinfo?(alwu)
Pushed by alwu@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/f6383bdf9dfd part1 : implement MediaController and MediaControlService. r=baku https://hg.mozilla.org/integration/autoland/rev/c1a2ecc4098e part2 : implement AudioFocusManager. r=baku https://hg.mozilla.org/integration/autoland/rev/2642920cf299 part3 : use static pref to control audio competing. r=baku https://hg.mozilla.org/integration/autoland/rev/5790ef015c5b part4 : notify controller about media active state and audible state changed from content processes. r=baku https://hg.mozilla.org/integration/autoland/rev/d138720d49a9 part5 : control media from chrome process. r=farre,baku https://hg.mozilla.org/integration/autoland/rev/bd22cb43dc59 part6 : add gtests. r=baku https://hg.mozilla.org/integration/autoland/rev/8016ae836490 part7 : add browser test. r=baku
Blocks: 1577367
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: