Bug 146837 - Media Session: add plumbing for delivering start/end-of-interruption events
Summary: Media Session: add plumbing for delivering start/end-of-interruption events
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks: 145411
  Show dependency treegraph
 
Reported: 2015-07-10 10:23 PDT by Matt Rajca
Modified: 2015-07-13 16:40 PDT (History)
6 users (show)

See Also:


Attachments
Patch (12.77 KB, patch)
2015-07-10 10:39 PDT, Matt Rajca
no flags Details | Formatted Diff | Diff
Patch (17.81 KB, patch)
2015-07-10 10:42 PDT, Matt Rajca
no flags Details | Formatted Diff | Diff
Patch (18.06 KB, patch)
2015-07-10 13:50 PDT, Matt Rajca
no flags Details | Formatted Diff | Diff
Patch (20.90 KB, patch)
2015-07-13 10:43 PDT, Matt Rajca
no flags Details | Formatted Diff | Diff
Patch (20.68 KB, patch)
2015-07-13 11:46 PDT, Matt Rajca
thorton: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Rajca 2015-07-10 10:23:57 PDT
The platform should be able to send start-of-interruption events to MediaSessions so we can invoke the media session interruption algorithm (4.5.2).
Comment 1 Radar WebKit Bug Importer 2015-07-10 10:24:56 PDT
<rdar://problem/21768356>
Comment 2 Matt Rajca 2015-07-10 10:39:05 PDT
Created attachment 256588 [details]
Patch
Comment 3 Matt Rajca 2015-07-10 10:42:38 PDT
Created attachment 256589 [details]
Patch
Comment 4 Eric Carlson 2015-07-10 10:57:18 PDT
Comment on attachment 256589 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=256589&action=review

> Source/WebCore/Modules/mediasession/MediaSessionEvents.h:33
> +enum MediaEventType {

This should be "enum class".

> Source/WebCore/Modules/mediasession/MediaSessionEvents.h:39
> +enum MediaSessionInterruptingCategory {

Ditto.

> Source/WebCore/page/Page.cpp:1230
> +void Page::handleStartOfInterruptionEvent(MediaSessionInterruptingCategory category)
> +{
> +}

Please add notImplemented();
Comment 5 Matt Rajca 2015-07-10 11:11:27 PDT
(In reply to comment #4)
> Comment on attachment 256589 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=256589&action=review
> 
> > Source/WebCore/Modules/mediasession/MediaSessionEvents.h:33
> > +enum MediaEventType {
> 
> This should be "enum class".

These are "enums" so we can cast to them from WKMediaEventTypes. We can't do that with a strongly-typed "enum class".

> 
> > Source/WebCore/Modules/mediasession/MediaSessionEvents.h:39
> > +enum MediaSessionInterruptingCategory {
> 
> Ditto.
> 
> > Source/WebCore/page/Page.cpp:1230
> > +void Page::handleStartOfInterruptionEvent(MediaSessionInterruptingCategory category)
> > +{
> > +}
> 
> Please add notImplemented();

Added.
Comment 6 Matt Rajca 2015-07-10 13:50:51 PDT
Created attachment 256610 [details]
Patch
Comment 7 Tim Horton 2015-07-10 14:16:44 PDT
Comment on attachment 256610 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=256610&action=review

> Source/WebKit2/UIProcess/API/C/WKPage.cpp:2197
> +    switch (wkCategory) {

I realize there's only one user, but the enum conversion functions are usually separate static methods. Maybe just keep that in mind if we end up needing this code again?

> Source/WebKit2/WebProcess/WebPage/WebPage.h:746
> +    void handleStartOfInterruptionEvent(uint32_t /* WebCore::MediaSessionInterruptingCategory */);

Since this is on WebPage, it should be more clear that it's about media. Also, maybe just "handleMediaInterruptionEvent", with a state/phase to indicate whether it's starting or ending? Won't you eventually need the end case too?
Comment 8 Eric Carlson 2015-07-10 14:31:08 PDT
Comment on attachment 256610 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=256610&action=review

> Source/WebKit2/UIProcess/API/C/WKPage.cpp:2192
> +void WKPageHandleStartOfInterruptionEvent(WKPageRef page, WKMediaSessionInterruptingCategory wkCategory)

You should COMPILE_ASSERT([value in MediaEventType] == [value in WKMediaEventTypes] for each value to make sure the enums stay in sync. See HTMLTrackElement.cpp for an example.
Comment 9 Eric Carlson 2015-07-10 14:32:18 PDT
Comment on attachment 256610 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=256610&action=review

>> Source/WebKit2/UIProcess/API/C/WKPage.cpp:2192
>> +void WKPageHandleStartOfInterruptionEvent(WKPageRef page, WKMediaSessionInterruptingCategory wkCategory)
> 
> You should COMPILE_ASSERT([value in MediaEventType] == [value in WKMediaEventTypes] for each value to make sure the enums stay in sync. See HTMLTrackElement.cpp for an example.

Or rather, if you do that then you can use a static_cast to convert values.
Comment 10 Matt Rajca 2015-07-13 10:43:55 PDT
Created attachment 256706 [details]
Patch
Comment 11 Matt Rajca 2015-07-13 10:46:02 PDT
(In reply to comment #7)
> Comment on attachment 256610 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=256610&action=review
> 
> > Source/WebKit2/UIProcess/API/C/WKPage.cpp:2197
> > +    switch (wkCategory) {
> 
> I realize there's only one user, but the enum conversion functions are
> usually separate static methods. Maybe just keep that in mind if we end up
> needing this code again?

Will do.

> 
> > Source/WebKit2/WebProcess/WebPage/WebPage.h:746
> > +    void handleStartOfInterruptionEvent(uint32_t /* WebCore::MediaSessionInterruptingCategory */);
> 
> Since this is on WebPage, it should be more clear that it's about media.
> Also, maybe just "handleMediaInterruptionEvent", with a state/phase to
> indicate whether it's starting or ending? Won't you eventually need the end
> case too?

I renamed it to 'handleMediaSessionInterruptionEvent' and added an enum for the event type (currently either start-of-interruption and end-of-interruption).
Comment 12 Matt Rajca 2015-07-13 10:47:09 PDT
(In reply to comment #9)
> Comment on attachment 256610 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=256610&action=review
> 
> >> Source/WebKit2/UIProcess/API/C/WKPage.cpp:2192
> >> +void WKPageHandleStartOfInterruptionEvent(WKPageRef page, WKMediaSessionInterruptingCategory wkCategory)
> > 
> > You should COMPILE_ASSERT([value in MediaEventType] == [value in WKMediaEventTypes] for each value to make sure the enums stay in sync. See HTMLTrackElement.cpp for an example.
> 
> Or rather, if you do that then you can use a static_cast to convert values.

Added the static assertions.
Comment 13 Tim Horton 2015-07-13 11:21:05 PDT
Comment on attachment 256706 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=256706&action=review

> Source/WebKit2/WebProcess/WebPage/WebPage.cpp:191
> +#include "WKPagePrivate.h"

Put the enums in a new header (probably in Shared/API/C) that you include in both places (and install as a private header), do not import UIProcess API headers here!
Comment 14 Matt Rajca 2015-07-13 11:46:35 PDT
Created attachment 256708 [details]
Patch
Comment 15 Matt Rajca 2015-07-13 11:46:45 PDT
(In reply to comment #13)
> Comment on attachment 256706 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=256706&action=review
> 
> > Source/WebKit2/WebProcess/WebPage/WebPage.cpp:191
> > +#include "WKPagePrivate.h"
> 
> Put the enums in a new header (probably in Shared/API/C) that you include in
> both places (and install as a private header), do not import UIProcess API
> headers here!

That header import was left over from a previous revision of the patch. Removed.
Comment 16 Tim Horton 2015-07-13 15:11:25 PDT
Comment on attachment 256708 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=256708&action=review

> Source/WebKit2/UIProcess/API/C/WKPage.cpp:2193
> +// NOTE: The values in the WKMediaSessionInterruptingCategory enum must stay in sync with those in WebCore::MediaSessionInterruptingCategory.

Why must they? You do a proper conversion below.
Comment 17 Matt Rajca 2015-07-13 15:45:55 PDT
(In reply to comment #16)
> Comment on attachment 256708 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=256708&action=review
> 
> > Source/WebKit2/UIProcess/API/C/WKPage.cpp:2193
> > +// NOTE: The values in the WKMediaSessionInterruptingCategory enum must stay in sync with those in WebCore::MediaSessionInterruptingCategory.
> 
> Why must they? You do a proper conversion below.

We cast from a WKMediaSessionInterruptionEvent to a MediaSessionInterruptionEvent in WebPage.cpp. We need to ensure the enums' values are the same, otherwise we'll get them mixed up after casting.
Comment 18 Matt Rajca 2015-07-13 15:52:47 PDT
Committed r186791: <http://trac.webkit.org/changeset/186791>
Comment 19 Tim Horton 2015-07-13 16:40:37 PDT
(In reply to comment #17)
> (In reply to comment #16)
> > Comment on attachment 256708 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=256708&action=review
> > 
> > > Source/WebKit2/UIProcess/API/C/WKPage.cpp:2193
> > > +// NOTE: The values in the WKMediaSessionInterruptingCategory enum must stay in sync with those in WebCore::MediaSessionInterruptingCategory.
> > 
> > Why must they? You do a proper conversion below.
> 
> We cast from a WKMediaSessionInterruptionEvent to a
> MediaSessionInterruptionEvent in WebPage.cpp. We need to ensure the enums'
> values are the same, otherwise we'll get them mixed up after casting.

I'm not sure why we have a proper conversion function in one direction and just cast in the other direction?