Bug 229327 - Prevent AudioSession category from moving out of PlayAndRecord too quickly
Summary: Prevent AudioSession category from moving out of PlayAndRecord too quickly
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-08-20 01:50 PDT by youenn fablet
Modified: 2021-08-21 00:01 PDT (History)
16 users (show)

See Also:


Attachments
Patch (8.65 KB, patch)
2021-08-20 02:01 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (9.11 KB, patch)
2021-08-20 02:09 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (9.47 KB, patch)
2021-08-20 04:41 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (11.32 KB, patch)
2021-08-20 05:48 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (11.48 KB, patch)
2021-08-20 07:15 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (11.56 KB, patch)
2021-08-20 09:02 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (11.58 KB, patch)
2021-08-20 09:06 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch for landing (11.71 KB, patch)
2021-08-20 10:57 PDT, youenn fablet
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description youenn fablet 2021-08-20 01:50:29 PDT
Prevent AudioSession category to move out of PlayAndRecord to quickly
Comment 1 youenn fablet 2021-08-20 01:56:02 PDT
<rdar://81997024>
Comment 2 youenn fablet 2021-08-20 02:01:50 PDT
Created attachment 435954 [details]
Patch
Comment 3 youenn fablet 2021-08-20 02:05:44 PDT
<rdar://81283764>
Comment 4 youenn fablet 2021-08-20 02:09:08 PDT
Created attachment 435955 [details]
Patch
Comment 5 youenn fablet 2021-08-20 02:21:07 PDT
We could remove individual MediaStreamTrack registration by making sure the Document media state is updated synchronously. I left this as a follow-up to make this patch small.
Comment 6 youenn fablet 2021-08-20 04:41:33 PDT
Created attachment 435971 [details]
Patch
Comment 7 youenn fablet 2021-08-20 05:48:33 PDT
Created attachment 435976 [details]
Patch
Comment 8 youenn fablet 2021-08-20 07:15:00 PDT
Created attachment 435981 [details]
Patch
Comment 9 youenn fablet 2021-08-20 07:15:55 PDT
(In reply to youenn fablet from comment #5)
> We could remove individual MediaStreamTrack registration by making sure the
> Document media state is updated synchronously. I left this as a follow-up to
> make this patch small.

Initial version was using Document to ensure PlayAndRecord sticks.
New version is moving the logic inside MediaSessionManagerCocoa which is more appropriate.
Comment 10 Eric Carlson 2021-08-20 08:57:00 PDT
Comment on attachment 435981 [details]
Patch

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

> Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm:154
> +    if (AudioSession::sharedSession().category() == AudioSession::CategoryType::PlayAndRecord && isPlayingAudio)
> +        category = AudioSession::CategoryType::PlayAndRecord;

Nit: it would be easier to understand if this was first:

    if (captureCount  || AudioSession::sharedSession().category() == AudioSession::CategoryType::PlayAndRecord && isPlayingAudio)
        category = AudioSession::CategoryType::PlayAndRecord;
    else if (...

> LayoutTests/http/tests/media/media-stream/audio-capture-and-category.https.html:45
> +     assert_equals(internals.audioSessionCategory(), "PlayAndRecord", "category when capturing");

Nit: it would be good to make this assert message different from the one above so if the test fails we can tell which test was the problem.
Comment 11 youenn fablet 2021-08-20 09:02:43 PDT
Created attachment 435995 [details]
Patch
Comment 12 youenn fablet 2021-08-20 09:06:33 PDT
Created attachment 435996 [details]
Patch
Comment 13 youenn fablet 2021-08-20 09:07:14 PDT
> > Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm:154
> > +    if (AudioSession::sharedSession().category() == AudioSession::CategoryType::PlayAndRecord && isPlayingAudio)
> > +        category = AudioSession::CategoryType::PlayAndRecord;
> 
> Nit: it would be easier to understand if this was first:

Done

> > LayoutTests/http/tests/media/media-stream/audio-capture-and-category.https.html:45
> > +     assert_equals(internals.audioSessionCategory(), "PlayAndRecord", "category when capturing");
> 
> Nit: it would be good to make this assert message different from the one
> above so if the test fails we can tell which test was the problem.

Done as well.
Comment 14 Eric Carlson 2021-08-20 09:51:30 PDT
Comment on attachment 435996 [details]
Patch

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

r=me once the bots are happy

> LayoutTests/http/tests/media/media-stream/audio-capture-and-category.https.html:46
> +     assert_equals(internals.audioSessionCategory(), "PlayAndRecord", "category when capturing");

Maybe "category when capturing and playing audio"

> LayoutTests/http/tests/media/media-stream/audio-capture-and-category.https.html:48
> +     stream.getAudioTracks()[0].stop();

As we discussed, it would be good to either comment here or use a url src for the audio element to make it obvious that audio will continue to play when the capture track is stopped.

> LayoutTests/http/tests/media/media-stream/audio-capture-and-category.https.html:51
> +     assert_equals(internals.audioSessionCategory(), "PlayAndRecord", "category when document did capture but is not capturing anymore");

Maybe "category when capture has stopped but audio continues to play"
Comment 15 youenn fablet 2021-08-20 10:57:19 PDT
Created attachment 436008 [details]
Patch for landing
Comment 16 EWS 2021-08-21 00:01:30 PDT
Committed r281367 (240782@main): <https://commits.webkit.org/240782@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 436008 [details].