Commit Graph

120 Commits

Author SHA1 Message Date
alwu
5fb309e36a Bug 1582508 - part7 : create a chrome-only method to get the playback state from the main controller. r=webidl,Ehsan
Implement a chrome-only method `getCurrentMediaSessionPlaybackState()` to expose current actual playback state in testing.

The reason we create an new enum `MediaSessionPlaybackTestState` is because of building issue. If we use `MediaSessionPlaybackState` directly in the `ChromeUtils.webidl`, then the codegen would automatically add an header include of `MediaSessionBinding.h` in the `ChromeUtilsBinding.h`, which would cause the complier complaining about lots of undeclared identifier.

Differential Revision: https://phabricator.services.mozilla.com/D66344

--HG--
extra : moz-landing-system : lando
2020-03-17 01:01:31 +00:00
alwu
9aea20214c Bug 1582508 - part6 : add actual playback state in the media controller r=chunmin
Implement the way of determining the actual playback state from the guessed playback state and the declared playback state.

[1] https://w3c.github.io/mediasession/#actual-playback-state

Differential Revision: https://phabricator.services.mozilla.com/D66343

--HG--
extra : moz-landing-system : lando
2020-03-17 00:39:12 +00:00
alwu
252ad6b503 Bug 1582508 - part5 : replace 'PlaybackState' with 'MediaSessionPlaybackState'. r=chunmin
`PlaybackState` and `MediaSessionPlaybackState` are actually quite similar, and we don't want to have to many states to confuse reader and do unnecessary tranform between two states. Therefore, replaceing  `PlaybackState` with `MediaSessionPlaybackState`.

Differential Revision: https://phabricator.services.mozilla.com/D66342

--HG--
extra : moz-landing-system : lando
2020-03-17 00:03:55 +00:00
alwu
e80c4c9e70 Bug 1582508 - part2 : change naming of 'mState' to 'mGuessedPlaybackState' r=chunmin
The playback state of the media controller is actually mapping to the guessed playback state [1] of the spec, so we rename it to make it clearer in the process of determining the acutal playback state [2].

[1] https://w3c.github.io/mediasession/#guessed-playback-state
[2] https://w3c.github.io/mediasession/#actual-playback-state

Differential Revision: https://phabricator.services.mozilla.com/D66339

--HG--
extra : moz-landing-system : lando
2020-03-14 01:18:31 +00:00
alwu
f1ffb8000a Bug 1620470 - part2 : add test. r=MeFisto94
Differential Revision: https://phabricator.services.mozilla.com/D65665

--HG--
extra : moz-landing-system : lando
2020-03-09 17:11:05 +00:00
alwu
2748adcf50 Bug 1615112 - part3 : add test. r=MeFisto94
Differential Revision: https://phabricator.services.mozilla.com/D65657

--HG--
extra : moz-landing-system : lando
2020-03-09 16:58:31 +00:00
Mark Banner
2c4e35b0a6 Bug 1620218 - Automatic code fixes for Prettier 1.18.2 upgrade. r=mossop,webcompat-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D65509

--HG--
extra : moz-landing-system : lando
2020-03-08 21:45:16 +00:00
alwu
6557ceeb66 Bug 1617033 - part9 : add test. r=chunmin
Differential Revision: https://phabricator.services.mozilla.com/D63929

--HG--
extra : moz-landing-system : lando
2020-03-06 17:53:28 +00:00
alwu
7eec59aab2 Bug 1617033 - part7 : modify tests to allow simulating media keys would always happen after controller's playback changes. r=chunmin
Whenever pressing the media control keys, it would not only change the media playback state, but also change the playback state of the media controller. Therefore, we want to ensure simulating events always happen after media controller changes its playback state.

In addition, for `play/pause` key, it would check controller's playback state to decide if we should file `play` event or `pause` event, so we definitely have to do that only after the controller changes its playback state.

Changing a file to non-autoplay to prevent missing the `main-media-controller-playback-changed` notification, because we can control when to start media and ensure we have already create a listener for that event.

For non-browser test, we have no way to listen to that notification, which could only be observed in the chrome process, so we do a hack to listen `timeupdate` several times to wait and hope the controller has been created and changed its state in the chrome process.

Differential Revision: https://phabricator.services.mozilla.com/D63926

--HG--
extra : moz-landing-system : lando
2020-03-06 17:51:48 +00:00
alwu
dd40c9b01a Bug 1617033 - part6 : make utility functions more general. r=chunmin
By providing element Id, we can use these functions to access video element on other files.

Differential Revision: https://phabricator.services.mozilla.com/D64173

--HG--
extra : moz-landing-system : lando
2020-03-06 17:50:18 +00:00
alwu
ec0addbd74 Bug 1617033 - part5 : remove unecessary async. r=chunmin
`async` is actually useless here because we don't have anything to do after `await` so we could return the promise `SpecialPowers.spawn()` generate instead.

Differential Revision: https://phabricator.services.mozilla.com/D63944

--HG--
extra : moz-landing-system : lando
2020-03-06 17:48:54 +00:00
alwu
5d71e398e6 Bug 1592037 - part7 : add metadata test. r=MeFisto94
Differential Revision: https://phabricator.services.mozilla.com/D64850

--HG--
extra : moz-landing-system : lando
2020-03-04 16:53:11 +00:00
alwu
71f97d6fff Bug 1592037 - part6 : implement a chrome-only method for accessing current active media metadata during testing. r=bzbarsky
Create a chrome-only method to get the current media metadata to know if we correctly update the media metadata or not. That method would only be used for testing.

Differential Revision: https://phabricator.services.mozilla.com/D64849

--HG--
extra : moz-landing-system : lando
2020-03-05 19:43:50 +00:00
alwu
5195e0f6ab Bug 1592037 - part5 : make sure we send main-media-controller-changed everytime the main controller is changed. r=MeFisto94
This change can help us ensure doing something after we unset the media controller, which is helpful in testing.

Differential Revision: https://phabricator.services.mozilla.com/D64848

--HG--
extra : moz-landing-system : lando
2020-03-04 16:44:27 +00:00
alwu
e0bf4b873c Bug 1592037 - part4 : update metadata to the event source. r=MeFisto94
Whenever the main controller updates its metadata, we should also notify the event source to update the metadata, because we don't want to show the wrong metadata on the virtual control interface.

In this patch, we add a new media event to notify this situation and create a new method `SetMediaMetadata()` on the `MediaControlKeysEventSource`. But we leave that function empty for now, and will have follow-up bugs to handle setting metadata on each different platforms.

Differential Revision: https://phabricator.services.mozilla.com/D64847

--HG--
extra : moz-landing-system : lando
2020-03-04 21:34:45 +00:00
alwu
1a104771e5 Bug 1611328 - part2 : let media session controller store top level session Id r=chunmin
As we would like to use `mTopLevelBCId` in `MediaSessionController` as well in order to get the corresponding browsing context, so move `mTopLevelBCId` to the `MediaSessionController`.

Differential Revision: https://phabricator.services.mozilla.com/D62535

--HG--
extra : moz-landing-system : lando
2020-02-20 19:04:36 +00:00
Marc Streckfuss
0954bfbeae Bug 1616800 - MediaControl: MediaControlKeysManager now checks the result of EventSource#Open(). r=alwu
Differential Revision: https://phabricator.services.mozilla.com/D63459

--HG--
extra : moz-landing-system : lando
2020-02-20 18:17:15 +00:00
alwu
b8bfeff446 Bug 1611332 - part7 : add test for checking active session among tabs. r=bzbarsky
Differential Revision: https://phabricator.services.mozilla.com/D61372

--HG--
extra : moz-landing-system : lando
2020-02-11 18:46:05 +00:00
alwu
b960039aa9 Bug 1611332 - part4 : directly notify context where media session exists if we have active media session. r=chunmin,bzbarsky
Since we can determine which browsing context contains an active media session via `MediaSessionController`, we should notify that context directly in order to access correct media session. Especially after we enable Fission, browsing contexts could exist in different processes, so choosing the right context to notify is really important.

Differential Revision: https://phabricator.services.mozilla.com/D60937

--HG--
extra : moz-landing-system : lando
2020-02-11 20:55:51 +00:00
alwu
624272960a Bug 1611332 - part2 : implement MediaSessionController which is used to update media session and store media metadata. r=chunmin
Create a class `MediaSessionController` which is used to track all alive media sessions within a tab and store their metadata which could be used to show on the virtual media control interface. That class would also be responsible to select an active media session with in a tab.

Differential Revision: https://phabricator.services.mozilla.com/D60935

--HG--
extra : moz-landing-system : lando
2020-02-11 00:30:47 +00:00
alwu
01a006163b Bug 1613600 - only set playback state for opened event source. r=MeFisto94
Differential Revision: https://phabricator.services.mozilla.com/D61791

--HG--
extra : moz-landing-system : lando
2020-02-11 12:49:29 +00:00
alwu
7bfc3e2bf5 Bug 1611031 - always trigger corespending controller method when receving media control key events. r=chunmin
The check here was used to prevent calling play or pause during playing or pausing.

However, according to the spec [1], even if media session is playing, we would still want to trigger its play action handler when play action happens. So we should forward all media control key events to the content, not to block any of them.

[1] https://w3c.github.io/mediasession/#handle-media-session-action

Differential Revision: https://phabricator.services.mozilla.com/D60918

--HG--
extra : moz-landing-system : lando
2020-01-24 21:31:34 +00:00
alwu
cf1623f1d3 Bug 1611021 - part2 : align some event names in MediaControlKeysTestEvent with MediaSessionAction's action name. r=bzbarsky
It allows us to share the same event name when writing test code like the following:

```
const action = "previoustrack";
mediaSession.setActionHandler(action, () => { ... });
specialPower.generateMediaControlKeyTestEvent(action);
```

Differential Revision: https://phabricator.services.mozilla.com/D60784

--HG--
extra : moz-landing-system : lando
2020-01-23 19:54:18 +00:00
alwu
e409c9441c Bug 1610723 - implement controller's track selection and seek methods. r=chunmin
Differential Revision: https://phabricator.services.mozilla.com/D60625

--HG--
extra : moz-landing-system : lando
2020-01-22 21:21:16 +00:00
alwu
30eceba5cd Bug 1610158 - ensure we have called controller's shutdown before it gets destroyed. r=chunmin
Ensure we have called controller's shutdown before it gets destroyed and not to change its internal status after shutdown.

Differential Revision: https://phabricator.services.mozilla.com/D60563

--HG--
extra : moz-landing-system : lando
2020-01-22 01:47:59 +00:00
Noemi Erli
20e4c02f56 Backed out changeset a4ab563e998c (bug 1610158) for causing failures in MediaController.cpp 2020-01-22 02:37:31 +02:00
alwu
a5b3ab80fc Bug 1610158 - ensure we have called controller's shutdown before it gets destroyed. r=chunmin
Ensure we have called controller's shutdown before it gets destroyed and not to change its internal status after shutdown.

Differential Revision: https://phabricator.services.mozilla.com/D60563

--HG--
extra : moz-landing-system : lando
2020-01-21 23:21:34 +00:00
alwu
08b87ffa96 Bug 1606782 - part5 : handle audio competing first r=chunmin,bryce
Currently we append the new controller first, then clear all controllers when handling audio competing, and finally add the new controller to `mOwningFocusControllers` again.

We can handle audio competing first, then adding the new controller, which can avoid adding same controller twice.

Differential Revision: https://phabricator.services.mozilla.com/D58735

--HG--
extra : moz-landing-system : lando
2020-01-16 00:06:59 +00:00
alwu
c24d1b97f6 Bug 1606782 - part4 : make audio focus manager independent from other components. r=chunmin,bryce
Before applying D58591, `AudioFocusMagager` depends on `MediaControlService` to access media controller. Now we still depend on `CanonicalBrowsingContext` to access media controller, which make us not able to have a unit test without any other components.

Therefore, we can simply store the reference of media controller in `AudioFocusManager` to avoid relying on the implementation of other components.

Differential Revision: https://phabricator.services.mozilla.com/D58734

--HG--
extra : moz-landing-system : lando
2020-01-15 23:26:29 +00:00
alwu
a80f1b0e4a Bug 1606782 - part3 : replace assertion with returning result of register/unregister controller r=chunmin,bryce
We should ensure that controllers has been removed from the service when it destroys. Therefore, we remove the assertion in `MediaControlService::RegisterActiveMediaController()` and `MediaControlService::UnregisterActiveMediaController()`, and return the result to allow caller to know if it has been registered or unregistered or not in order to do error handling or add assertions.

Differential Revision: https://phabricator.services.mozilla.com/D59286

--HG--
extra : moz-landing-system : lando
2020-01-16 00:28:17 +00:00
alwu
c0fb1f5b8e Bug 1606782 - part2 : create media controller via canonical browsing context. r=chunmin,nika
As each media controller corresponds to a tab (a browsing context tree), so the controller's life cycle should be equal to the tab. Currently we use the top-level browsing context to represent a tab, so when that browsing context is being destroyed, we should also destroy the corresponding media controller.

Therefore, `MediaControlService` don't need to have methods to access media controller anymore, we should access media controller directly from the top-level canonical browsing context.

Differential Revision: https://phabricator.services.mozilla.com/D58591

--HG--
extra : moz-landing-system : lando
2020-01-16 18:05:14 +00:00
alwu
c8deb931b0 Bug 1606782 - part1 : rename controller related functions and member to emphasize that only active controller would be added into the controller list in the service. r=chunmin,bryce
To modify variable and function names to emphasize all media controllers added in the service are active controllers. If the controller doesn't have any controlled media, they won't be added into the service.

Differential Revision: https://phabricator.services.mozilla.com/D58589

--HG--
extra : moz-landing-system : lando
2020-01-15 23:26:07 +00:00
alwu
a68bad3c1f Bug 1605769 - part3 : set playback state to the event source according to the play state of the main controller. r=MeFisto94
Based on the main controller's play state to set the correct playback state to the event source.

Differential Revision: https://phabricator.services.mozilla.com/D58261

--HG--
extra : moz-landing-system : lando
2020-01-10 04:13:32 +00:00
alwu
0823bf3111 Bug 1605769 - part2 : create controller manager to select main controller. r=MeFisto94
Implement a class `ControllerManager` to wrap the details of how to select the main controller, which would also be used to monitor main controller's play state change.

Differential Revision: https://phabricator.services.mozilla.com/D58260

--HG--
extra : moz-landing-system : lando
2020-01-10 12:24:13 +00:00
alwu
fd68b00cb4 Bug 1605769 - part1 : use PlaybackState in media controller and add a method to monitor its change r=MeFisto94
We use `PlaybackState` to replace `boolean` which can clearly indicate what controller's current state is and introduce a new method `PlayStateChangedEvent()` which can be used to monitor the play state change of the media controller.

Differential Revision: https://phabricator.services.mozilla.com/D58174

--HG--
extra : moz-landing-system : lando
2020-01-09 04:42:26 +00:00
alwu
b02cf1f17d Bug 1605769 - part0 : extend PlaybackState and move it out from MediaEventSource. r=MeFisto94
Since we would like to use `PlaybackState` in MediaController, we move it out from `MediaEventSource` and put it in `MediaControl.h`, which makes more sense because it actually represents media controller's playback state.

In addition, modify `ePlayed` to `ePlaying` and add one new state `eStopped`.

Differential Revision: https://phabricator.services.mozilla.com/D59100

--HG--
extra : moz-landing-system : lando
2020-01-10 12:23:04 +00:00
alwu
ba4fab1cc2 Bug 1607051 - do not access browsing context after XPCOM is shutdown. r=bryce
After XPCOM is shutdown, `sBrowsingContext` would be released, so using `BrowsingContext::Get()` would cause crash. Therefore, after shutdown XPCOM, we should not access browsing context.

Differential Revision: https://phabricator.services.mozilla.com/D59079

--HG--
extra : moz-landing-system : lando
2020-01-08 17:11:34 +00:00
alwu
4bde50109e Bug 1571493 - part5 : use 'MediaControlKeysEventHandler' to deliver control keys event. r=chunmin
Use `MediaControlKeysEventHandler` to handle the control keys event, which can always find corresponding controlled media if there are some.

Differential Revision: https://phabricator.services.mozilla.com/D57575

--HG--
extra : moz-landing-system : lando
2020-01-03 01:27:24 +00:00
alwu
bdc6a8cae7 Bug 1571493 - part4 : support 'ControlledMediaState' in media controller r=chunmin
Introduce `ControlledMediaState` to media controller, so now we can now how many controlled media are playing, which allow us to update `mIsPlaying` correctly.

Differential Revision: https://phabricator.services.mozilla.com/D57574

--HG--
extra : moz-landing-system : lando
2020-01-03 01:39:33 +00:00
alwu
2d2b857325 Bug 1571493 - part3 : notify media state and audible state changes. r=chunmin
Modify IPC method to support notify `ControlledMediaState` to the media controller, and remove the previous implementation.

Differential Revision: https://phabricator.services.mozilla.com/D57572

--HG--
extra : moz-landing-system : lando
2020-01-03 01:34:34 +00:00
alwu
9977c552ff Bug 1571493 - part1 : implement 'ContentMediaController' which is used to notify 'MediaControlKeysEvent' for controlled media. r=chunmin
Implement class `ContentMediaController` that is used to dispatch media controls key events to those media which would like to be controlled.

`ContentMediaController` is inherited from two classes, `MediaControlAgent` and `MediaControlKeysEventHandler`. The former one is used for controlled media, the controlled media can register itself to `MediaControlAgent` to receive events and do corresponding operations depending on the event type. The latter one is used to handle events sent from chrome process and dispatch them to the corresponding controlled media.

Differential Revision: https://phabricator.services.mozilla.com/D57570

--HG--
extra : moz-landing-system : lando
2020-01-03 01:29:38 +00:00
Alastor Wu
053826b10f Bug 1604653 - add new methods to set and get playback state for the event source. r=MeFisto94
Differential Revision: https://phabricator.services.mozilla.com/D58159

--HG--
extra : moz-landing-system : lando
2019-12-31 14:10:53 +00:00
Paul Warner
7fec362cac Bug 1591230 - On macOS use MediaPlayer library for media keys when available. r=spohl,alwu
On macOS 10.12.1+, we use `MediaPlayer` library, which has better media key integration, to replace the implementation of `CG EventLoop`.

Differential Revision: https://phabricator.services.mozilla.com/D46890

--HG--
extra : moz-landing-system : lando
2019-12-31 01:41:33 +00:00
Alastor Wu
32f2dfb642 Bug 1605798 - part2 : remove unused functions r=chunmin
We have no plan to use those functions, so remove them in order to keep code clean.

Differential Revision: https://phabricator.services.mozilla.com/D58172

--HG--
extra : moz-landing-system : lando
2019-12-26 18:52:00 +00:00
Alastor Wu
b7b2d91c6a Bug 1605798 - part1 : remove some useless RefPtr usage r=chunmin
When a function returning a pointer, returning a raw pointer is enough. The callers should use `RefPtr` to store this pointer explicitly if they do need to add a refcounting.

In addition, using `RefPtr` in the parameter cannot prevent anything as well.

Differential Revision: https://phabricator.services.mozilla.com/D58171

--HG--
extra : moz-landing-system : lando
2019-12-26 19:49:13 +00:00
Daniel Varga
531690d2c4 Backed out 2 changesets (bug 1605798) for causing mochitest failures at builds/worker/workspace/build/src/dom/media/mediacontrol/MediaController.cpp
Backed out changeset 6ea0907b88ec (bug 1605798)
Backed out changeset 538b05d2ea79 (bug 1605798)
2019-12-26 20:46:44 +02:00
Alastor Wu
cdc46885e3 Bug 1605798 - part2 : remove unused functions r=chunmin
We have no plan to use those functions, so remove them in order to keep code clean.

Differential Revision: https://phabricator.services.mozilla.com/D58172

--HG--
extra : moz-landing-system : lando
2019-12-24 00:19:15 +00:00
Alastor Wu
a0b04bfd73 Bug 1605798 - part1 : remove some useless RefPtr usage r=chunmin
When a function returning a pointer, returning a raw pointer is enough. The callers should use `RefPtr` to store this pointer explicitly if they do need to add a refcounting.

In addition, using `RefPtr` in the parameter cannot prevent anything as well.

Differential Revision: https://phabricator.services.mozilla.com/D58171

--HG--
extra : moz-landing-system : lando
2019-12-26 17:23:08 +00:00
alwu
6c23e730f2 Bug 1604962 - use NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING to support refcounting for abstrach classes. r=chunmin
Inheriting from `nsISupports` is too complicated if we just want to support refcounting. Instead, we can use `NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING` to declare `Add/RemoveRef()` as pure virtual functions in order to create ref-counted abstract classes.

Differential Revision: https://phabricator.services.mozilla.com/D57714

--HG--
extra : moz-landing-system : lando
2019-12-21 00:05:53 +00:00
alwu
a2e90147ab Bug 1604691 - part3 : add test. r=bzbarsky
Differential Revision: https://phabricator.services.mozilla.com/D57913

--HG--
extra : moz-landing-system : lando
2019-12-20 23:46:31 +00:00