Bug 208583 - [GPUP] Implement RemoteAudioSession
Summary: [GPUP] Implement RemoteAudioSession
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Jer Noble
URL:
Keywords: InRadar
Depends on: 208090
Blocks:
  Show dependency treegraph
 
Reported: 2020-03-04 10:56 PST by Jer Noble
Modified: 2020-03-05 11:43 PST (History)
13 users (show)

See Also:


Attachments
Patch (101.92 KB, patch)
2020-03-04 11:26 PST, Jer Noble
no flags Details | Formatted Diff | Diff
Patch (103.10 KB, patch)
2020-03-04 12:10 PST, Jer Noble
no flags Details | Formatted Diff | Diff
Patch (103.47 KB, patch)
2020-03-04 12:38 PST, Jer Noble
no flags Details | Formatted Diff | Diff
Patch (102.38 KB, patch)
2020-03-04 13:13 PST, Jer Noble
no flags Details | Formatted Diff | Diff
Patch (101.91 KB, patch)
2020-03-04 13:16 PST, Jer Noble
no flags Details | Formatted Diff | Diff
Patch (101.88 KB, patch)
2020-03-04 13:38 PST, Jer Noble
no flags Details | Formatted Diff | Diff
Patch (101.88 KB, patch)
2020-03-04 14:16 PST, Jer Noble
no flags Details | Formatted Diff | Diff
Patch (17.18 KB, patch)
2020-03-04 17:30 PST, Jer Noble
no flags Details | Formatted Diff | Diff
Patch (102.09 KB, patch)
2020-03-04 17:38 PST, Jer Noble
no flags Details | Formatted Diff | Diff
Patch (101.93 KB, patch)
2020-03-04 18:10 PST, Jer Noble
no flags Details | Formatted Diff | Diff
Patch (88.72 KB, patch)
2020-03-05 08:12 PST, Jer Noble
no flags Details | Formatted Diff | Diff
Patch (89.06 KB, patch)
2020-03-05 08:25 PST, Jer Noble
no flags Details | Formatted Diff | Diff
Patch (86.31 KB, patch)
2020-03-05 08:34 PST, Jer Noble
no flags Details | Formatted Diff | Diff
Patch for landing (85.90 KB, patch)
2020-03-05 09:02 PST, Jer Noble
no flags Details | Formatted Diff | Diff
Patch for landing (85.90 KB, patch)
2020-03-05 09:06 PST, Jer Noble
no flags Details | Formatted Diff | Diff
Patch for landing (84.62 KB, patch)
2020-03-05 09:21 PST, Jer Noble
no flags Details | Formatted Diff | Diff
Patch for landing (85.01 KB, patch)
2020-03-05 09:30 PST, Jer Noble
no flags Details | Formatted Diff | Diff
Patch for landing (85.04 KB, patch)
2020-03-05 10:58 PST, Jer Noble
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jer Noble 2020-03-04 10:56:57 PST
[GPUP] Implement RemoteAudioSession
Comment 1 Radar WebKit Bug Importer 2020-03-04 11:16:41 PST
<rdar://problem/60047827>
Comment 2 youenn fablet 2020-03-04 11:18:57 PST
Is it the same as https://bugs.webkit.org/show_bug.cgi?id=208578?
Comment 3 Jer Noble 2020-03-04 11:26:39 PST
Created attachment 392445 [details]
Patch
Comment 4 Jer Noble 2020-03-04 11:34:13 PST
(In reply to youenn fablet from comment #2)
> Is it the same as https://bugs.webkit.org/show_bug.cgi?id=208578?

Oof, looks like it is.
Comment 5 Jer Noble 2020-03-04 11:36:36 PST
(In reply to Jer Noble from comment #4)
> (In reply to youenn fablet from comment #2)
> > Is it the same as https://bugs.webkit.org/show_bug.cgi?id=208578?
> 
> Oof, looks like it is.

That said, I think it's more useful to have an entire remote type rather than doing the commands ad-hoc. Also, the other patch doesn't seem to do the right thing when multiple WebContent processes have different audio categories or buffer sizes.
Comment 6 Jer Noble 2020-03-04 12:10:55 PST
Created attachment 392454 [details]
Patch
Comment 7 Jer Noble 2020-03-04 12:38:05 PST
Created attachment 392457 [details]
Patch
Comment 8 Eric Carlson 2020-03-04 12:42:23 PST
Comment on attachment 392454 [details]
Patch

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

> Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp:363
> +#if ENABLE(LEGACY_ENCRYPTED_MEDIA)
> +    if (decoder.messageReceiverName() == Messages::RemoteLegacyCDMFactoryProxy::messageReceiverName()) {
> +        legacyCdmFactoryProxy().didReceiveMessageFromWebProcess(connection, decoder);
> +        return true;
> +    }
> +
> +    if (decoder.messageReceiverName() == Messages::RemoteLegacyCDMProxy::messageReceiverName()) {
> +        legacyCdmFactoryProxy().didReceiveCDMMessage(connection, decoder);
> +        return true;
> +    }
> +
> +    if (decoder.messageReceiverName() == Messages::RemoteLegacyCDMSessionProxy::messageReceiverName()) {
> +        legacyCdmFactoryProxy().didReceiveCDMSessionMessage(connection, decoder);
> +        return true;
> +    }
> +#endif

Does this belong in another patch?

> Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp:432
> +#if ENABLE(LEGACY_ENCRYPTED_MEDIA)
> +    if (decoder.messageReceiverName() == Messages::RemoteLegacyCDMFactoryProxy::messageReceiverName()) {
> +        legacyCdmFactoryProxy().didReceiveSyncMessageFromWebProcess(connection, decoder, replyEncoder);
> +        return true;
> +    }
> +
> +    if (decoder.messageReceiverName() == Messages::RemoteLegacyCDMProxy::messageReceiverName()) {
> +        legacyCdmFactoryProxy().didReceiveSyncCDMMessage(connection, decoder, replyEncoder);
> +        return true;
> +    }
> +
> +    if (decoder.messageReceiverName() == Messages::RemoteLegacyCDMSessionProxy::messageReceiverName()) {
> +        legacyCdmFactoryProxy().didReceiveSyncCDMSessionMessage(connection, decoder, replyEncoder);
> +        return true;
> +    }
> +#endif

Ditto

> Source/WebKit/GPUProcess/media/RemoteAudioSessionProxyManager.cpp:108
> +    m_session->setCategory(category, policy);

We should log this change.

> Source/WebKit/GPUProcess/media/RemoteAudioSessionProxyManager.cpp:145
> +        // This proxy wants to de-activate, as is the last remaining active

s/as is/and is/

> Source/WebKit/GPUProcess/media/RemoteAudioSessionProxyManager.cpp:158
> +    // proxy with mix with the active proxies. No-op, and return activation

s/with mix/will mix/

> Source/WebKit/GPUProcess/media/RemoteAudioSessionProxyManager.cpp:173
> +        if (otherProxy->category() == AudioSession::AmbientSound)

Nit: it would be nice to encapsulate this logic in a a proxy method. Something like "canMixWithOthers()"?

> Source/WebKit/WebProcess/GPU/media/RemoteAudioSession.cpp:77
> +void RemoteAudioSession::configurationChanged(RemoteAudioSessionConfiguration&& configuration)

This is never called?
Comment 9 Jer Noble 2020-03-04 13:05:34 PST
(In reply to Eric Carlson from comment #8)
> Comment on attachment 392454 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=392454&action=review
> 
> > Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp:363
> > +#if ENABLE(LEGACY_ENCRYPTED_MEDIA)
> > +    if (decoder.messageReceiverName() == Messages::RemoteLegacyCDMFactoryProxy::messageReceiverName()) {
> > +        legacyCdmFactoryProxy().didReceiveMessageFromWebProcess(connection, decoder);
> > +        return true;
> > +    }
> > +
> > +    if (decoder.messageReceiverName() == Messages::RemoteLegacyCDMProxy::messageReceiverName()) {
> > +        legacyCdmFactoryProxy().didReceiveCDMMessage(connection, decoder);
> > +        return true;
> > +    }
> > +
> > +    if (decoder.messageReceiverName() == Messages::RemoteLegacyCDMSessionProxy::messageReceiverName()) {
> > +        legacyCdmFactoryProxy().didReceiveCDMSessionMessage(connection, decoder);
> > +        return true;
> > +    }
> > +#endif
> 
> Does this belong in another patch?

It does; it got mixed in with the Legacy EME patch. Will remove.

> > +    m_session->setCategory(category, policy);
> 
> We should log this change.

Ok. I don't know how we're doing logging in the GPU Process yet, but I'll just do a standard INFO_LOG() statement here.

> > Source/WebKit/GPUProcess/media/RemoteAudioSessionProxyManager.cpp:145
> > +        // This proxy wants to de-activate, as is the last remaining active
> 
> s/as is/and is/

Changed.

> > Source/WebKit/GPUProcess/media/RemoteAudioSessionProxyManager.cpp:158
> > +    // proxy with mix with the active proxies. No-op, and return activation
> 
> s/with mix/will mix/

Changed

> > Source/WebKit/GPUProcess/media/RemoteAudioSessionProxyManager.cpp:173
> > +        if (otherProxy->category() == AudioSession::AmbientSound)
> 
> Nit: it would be nice to encapsulate this logic in a a proxy method.
> Something like "canMixWithOthers()"?

Ok.

> > Source/WebKit/WebProcess/GPU/media/RemoteAudioSession.cpp:77
> > +void RemoteAudioSession::configurationChanged(RemoteAudioSessionConfiguration&& configuration)
> 
> This is never called?

Not yet. Planning for the future.
Comment 10 Jer Noble 2020-03-04 13:10:07 PST
(In reply to Jer Noble from comment #9)
> (In reply to Eric Carlson from comment #8)
> > Comment on attachment 392454 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=392454&action=review
> > 
> 
> > > +    m_session->setCategory(category, policy);
> > 
> > We should log this change.
> 
> Ok. I don't know how we're doing logging in the GPU Process yet, but I'll
> just do a standard INFO_LOG() statement here.

Wait, this will be logged by AudioSession; we should just be able to look through GPUProcess logs for AudioSession::setCategory().
Comment 11 Jer Noble 2020-03-04 13:13:42 PST
Created attachment 392460 [details]
Patch
Comment 12 Jer Noble 2020-03-04 13:16:02 PST
Created attachment 392461 [details]
Patch
Comment 13 Eric Carlson 2020-03-04 13:20:15 PST
(In reply to Jer Noble from comment #10)
> (In reply to Jer Noble from comment #9)
> > (In reply to Eric Carlson from comment #8)
> > > Comment on attachment 392454 [details]
> > > Patch
> > > 
> > > View in context:
> > > https://bugs.webkit.org/attachment.cgi?id=392454&action=review
> > > 
> > 
> > > > +    m_session->setCategory(category, policy);
> > > 
> > > We should log this change.
> > 
> > Ok. I don't know how we're doing logging in the GPU Process yet, but I'll
> > just do a standard INFO_LOG() statement here.
> 

Use GPUConnectionToWebProcess.logger() and WebKit2LogMedia.

> Wait, this will be logged by AudioSession; we should just be able to look
> through GPUProcess logs for AudioSession::setCategory().

AudioSession still uses debug-only logging.
Comment 14 Jer Noble 2020-03-04 13:23:53 PST
(In reply to Eric Carlson from comment #13)
> (In reply to Jer Noble from comment #10)
> > (In reply to Jer Noble from comment #9)
> > > (In reply to Eric Carlson from comment #8)
> > > > Comment on attachment 392454 [details]
> > > > Patch
> > > > 
> > > > View in context:
> > > > https://bugs.webkit.org/attachment.cgi?id=392454&action=review
> > > > 
> > > 
> > > > > +    m_session->setCategory(category, policy);
> > > > 
> > > > We should log this change.
> > > 
> > > Ok. I don't know how we're doing logging in the GPU Process yet, but I'll
> > > just do a standard INFO_LOG() statement here.
> > 
> 
> Use GPUConnectionToWebProcess.logger() and WebKit2LogMedia.

That won't work; this class isn't associated with a specific GPUConnectionToWebProcess. Is there something similar on GPUProcess?
Comment 15 Jer Noble 2020-03-04 13:25:45 PST
(In reply to Jer Noble from comment #14)
> That won't work; this class isn't associated with a specific
> GPUConnectionToWebProcess. Is there something similar on GPUProcess?

To answer my own question, no, there isn't. GPUProcess just uses RELEASE_LOG.
Comment 16 Eric Carlson 2020-03-04 13:27:36 PST
(In reply to Jer Noble from comment #15)
> (In reply to Jer Noble from comment #14)
> > That won't work; this class isn't associated with a specific
> > GPUConnectionToWebProcess. Is there something similar on GPUProcess?
> 
> To answer my own question, no, there isn't. GPUProcess just uses RELEASE_LOG.

Because we need a session ID to know if logging is allowed.
Comment 17 Jer Noble 2020-03-04 13:37:13 PST
(In reply to Eric Carlson from comment #16)
> (In reply to Jer Noble from comment #15)
> > (In reply to Jer Noble from comment #14)
> > > That won't work; this class isn't associated with a specific
> > > GPUConnectionToWebProcess. Is there something similar on GPUProcess?
> > 
> > To answer my own question, no, there isn't. GPUProcess just uses RELEASE_LOG.
> 
> Because we need a session ID to know if logging is allowed.

Okay, I don't think that we're going to be able to solve this with Logger currently; we can't aggregate logs across multiple loggers in a way that is compatible with the goal of disabling logging when not allowed.
Comment 18 Jer Noble 2020-03-04 13:38:38 PST
Created attachment 392471 [details]
Patch
Comment 19 Jer Noble 2020-03-04 14:16:49 PST
Created attachment 392482 [details]
Patch
Comment 20 Jer Noble 2020-03-04 16:46:27 PST
The Mac-wk2 test failures seem to be because MockAudioSharedUnit() is calling into AudioSession inside the UIProcess. On one hand, platformStrategies() should never be null, even in the UIProcess. On the other, why is MockAudioSharedUnit() using AudioSession directly in the first place?
Comment 21 Jer Noble 2020-03-04 17:29:26 PST
It definitely doesn't seem to be correct that platformStrategies() returns a nullable pointer that is never null-checked anywhere. It should either be guaranteed non null (i.e., a reference), or should be null-checked in every place it's called. For expediency's sake, I null-checked inside AudioSession::sharedSession(), but I don't think this is correct. I'll file a different bug on what the correct behavior should be.
Comment 22 Jer Noble 2020-03-04 17:30:00 PST
Created attachment 392518 [details]
Patch
Comment 23 Jer Noble 2020-03-04 17:38:49 PST
Created attachment 392520 [details]
Patch
Comment 24 Jer Noble 2020-03-04 18:10:18 PST
Created attachment 392524 [details]
Patch
Comment 25 Alex Christensen 2020-03-04 22:26:53 PST
Comment on attachment 392524 [details]
Patch

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

> Source/WebKit/GPUProcess/GPUPlatformStrategies.h:42
> +class GPUPlatformStrategies : public WebCore::PlatformStrategies {

Oh please no.  I have worked long and hard to move PlatformStrategies to PageConfiguration, which is the direction they should be going.  If you can't get to or from a Page, fail to do whatever you were about to do.  We should rename PlatformStrategies to LegacyPlatformStrategies.
Comment 26 youenn fablet 2020-03-05 03:24:50 PST
I am removing the usage of MediaSessionManagerCocoa in GPUProcess for now in https://bugs.webkit.org/show_bug.cgi?id=208568, which might help a little.

Ideally, we would like AudioSession::sharedSession() to only be called in GPUProcess when media for GPUProcess is enabled.
There is a small number of non-platform calls to AudioSession::sharedSession() that we could probably update easily.

When we discussed with Eric, the idea was to use PlatformMediaSessionManager as the interface between WebProcess and GPUProcess. This would handle AudioSession management.
That is made somehow harder given PlatformMediaSessionManager unfortunate tight relationships with HTMLMediaElement.
Comment 27 Jer Noble 2020-03-05 07:42:56 PST
(In reply to Alex Christensen from comment #25)
> Comment on attachment 392524 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=392524&action=review
> 
> > Source/WebKit/GPUProcess/GPUPlatformStrategies.h:42
> > +class GPUPlatformStrategies : public WebCore::PlatformStrategies {
> 
> Oh please no.  I have worked long and hard to move PlatformStrategies to
> PageConfiguration, which is the direction they should be going.  If you
> can't get to or from a Page, fail to do whatever you were about to do.  We
> should rename PlatformStrategies to LegacyPlatformStrategies.

AudioSession is a global; Page is the wrong level of abstraction. 

That said, this setting should be a WebProcessCreationParameter, not a setting or a page configuration, which should also be global in the WebProcess. I'll switch this around so that the AudioSession global allows you to set the global object, which will accomplish the same goal without using platformStrategies().
Comment 28 Jer Noble 2020-03-05 08:12:41 PST
Created attachment 392570 [details]
Patch
Comment 29 Jer Noble 2020-03-05 08:25:15 PST
Created attachment 392574 [details]
Patch
Comment 30 Jer Noble 2020-03-05 08:34:05 PST
Created attachment 392575 [details]
Patch
Comment 31 Alex Christensen 2020-03-05 08:52:14 PST
Comment on attachment 392575 [details]
Patch

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

Much better.

> Source/WebKit/GPUProcess/media/RemoteAudioSessionProxyManager.h:51
> +    using SetActiveCompletion = CompletionHandler<void(bool)>;

I think this is unused.

> Source/WebKit/Shared/WebCoreArgumentCoders.h:1035
> +    WebCore::AudioSession::CategoryType,

We usually try to put these in the same header as the enum class.

> Source/WebKit/WebProcess/GPU/media/RemoteAudioSessionConfiguration.h:39
> +    float sampleRate;

These should probably have default initializers to prevent use of uninitialized memory if we make a mistake and don't initialize everything somewhere.
Comment 32 Jer Noble 2020-03-05 08:54:17 PST
Comment on attachment 392575 [details]
Patch

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

>> Source/WebKit/GPUProcess/media/RemoteAudioSessionProxyManager.h:51
>> +    using SetActiveCompletion = CompletionHandler<void(bool)>;
> 
> I think this is unused.

Whoops, will remove.

>> Source/WebKit/Shared/WebCoreArgumentCoders.h:1035
>> +    WebCore::AudioSession::CategoryType,
> 
> We usually try to put these in the same header as the enum class.

Ok, will move.

>> Source/WebKit/WebProcess/GPU/media/RemoteAudioSessionConfiguration.h:39
>> +    float sampleRate;
> 
> These should probably have default initializers to prevent use of uninitialized memory if we make a mistake and don't initialize everything somewhere.

Will do.
Comment 33 Jer Noble 2020-03-05 09:02:03 PST
Created attachment 392578 [details]
Patch for landing
Comment 34 Jer Noble 2020-03-05 09:06:48 PST
Created attachment 392579 [details]
Patch for landing
Comment 35 Jer Noble 2020-03-05 09:21:36 PST
Created attachment 392584 [details]
Patch for landing
Comment 36 Jer Noble 2020-03-05 09:30:15 PST
Created attachment 392585 [details]
Patch for landing
Comment 37 Jer Noble 2020-03-05 10:58:11 PST
Created attachment 392600 [details]
Patch for landing
Comment 38 WebKit Commit Bot 2020-03-05 11:43:18 PST
Comment on attachment 392600 [details]
Patch for landing

Clearing flags on attachment: 392600

Committed r257936: <https://trac.webkit.org/changeset/257936>
Comment 39 WebKit Commit Bot 2020-03-05 11:43:21 PST
All reviewed patches have been landed.  Closing bug.