Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 5801e5e98a3ec11f1bbd641dbb39d375f25f3da2
      
https://github.com/WebKit/WebKit/commit/5801e5e98a3ec11f1bbd641dbb39d375f25f3da2
  Author: Youenn Fablet <[email protected]>
  Date:   2026-07-02 (Thu, 02 Jul 2026)

  Changed paths:
    A 
LayoutTests/fast/mediastream/audio-session-active-when-capture-starts-and-stops-expected.txt
    A 
LayoutTests/fast/mediastream/audio-session-active-when-capture-starts-and-stops.html
    A 
LayoutTests/fast/mediastream/audio-session-stays-active-during-capture-expected.txt
    A 
LayoutTests/fast/mediastream/audio-session-stays-active-during-capture.html
    A 
LayoutTests/fast/mediastream/audio-session-stays-active-when-removing-session-during-capture-expected.txt
    A 
LayoutTests/fast/mediastream/audio-session-stays-active-when-removing-session-during-capture.html
    M LayoutTests/platform/glib/TestExpectations
    M Source/WebCore/Modules/mediasession/MediaSession.cpp
    M Source/WebCore/Modules/mediastream/MediaStreamTrack.cpp
    M Source/WebCore/Modules/mediastream/UserMediaRequest.cpp
    M Source/WebCore/platform/LogMessages.in
    M Source/WebCore/platform/audio/MediaSessionManagerInterface.cpp
    M Source/WebCore/platform/audio/MediaSessionManagerInterface.h

  Log Message:
  -----------
  WebProcess AudioSession may not always stay active when microphone capture is 
live
rdar://180505014
https://bugs.webkit.org/show_bug.cgi?id=317747

Reviewed by Eric Carlson.

Microphone capture requires the AudioSession to stay active for the duration of 
the capture.
The WebProcess can drop the AudioSession in two cases that were not properly 
guarded against ongoing capture:
1. Process suspension. MediaSessionManagerInterface::processWillSuspend() 
unconditionally calls maybeDeactivateAudioSession(),
   which would teardown the AudioSession even when an audio capture source was 
active.
   This is not supposed to happen as a process that capture microphone should 
not get suspended.
2. Removal of the last PlatformMediaSession (e.g. a <video> ending) while 
capture is ongoing.
   removeSession() called maybeDeactivateAudioSession() guarded by an inline 
activeAudioSessionRequired() check,
   but the same logic was duplicated at every call site of 
maybeDeactivateAudioSession.

In addition, UserMediaRequest::allow() activated the AudioSession by calling 
AudioSession::singleton().tryToSetActive(true) directly,
bypassing MediaSessionManagerInterface entirely. This left m_becameActive out 
of sync with the actual AudioSession state.

This PR centralizes the "is capture or another session keeping the AudioSession 
alive?" check inside maybeDeactivateAudioSession() itself,
so every caller (process suspension, session removal, capture state change) is 
consistently protected.
Call sites that duplicated the check are simplified.
In the process suspension case, we keep deactivating the audio session using 
ShouldCheckRequiredSession::No to keep existing tests happy,
in particular platform/mac/media/audio-session-deactivated-when-suspended.html.
A future PR should properly mute capture as part of process suspension which 
would allow to deactivate the audio session without 
ShouldCheckRequiredSession::No.

The PR routes UserMediaRequest::allow() through MediaSessionManagerInterface 
via audioCaptureSourceStateChanged(IsCaptureStarting::Yes) so capture 
activation is tracked by the manager and m_becameActive is correct.
We call MediaStreamTrack::audioCaptureSourceStateChanged() synchronously on 
mute/unmute (instead of in the deferred event-dispatch task) so the manager 
observes the new capture state right away.
We switch MediaStreamTrack::isCapturingAudio() and wantsToCaptureAudio() to 
read m_private->muted() (the live underlying state) instead of the 
observer-driven muted() flag, which lags behind by one event-loop turn.
We add a release log when process suspension happens while microphone capture 
is ongoing, to make follow-up diagnoses on devices easier.

Tests: fast/mediastream/audio-session-active-when-capture-starts-and-stops.html
       fast/mediastream/audio-session-stays-active-during-capture.html
       
fast/mediastream/audio-session-stays-active-when-removing-session-during-capture.html

* 
LayoutTests/fast/mediastream/audio-session-active-when-capture-starts-and-stops-expected.txt:
 Added.
* 
LayoutTests/fast/mediastream/audio-session-active-when-capture-starts-and-stops.html:
 Added.
* 
LayoutTests/fast/mediastream/audio-session-stays-active-during-capture-expected.txt:
 Added.
* LayoutTests/fast/mediastream/audio-session-stays-active-during-capture.html: 
Added.
* 
LayoutTests/fast/mediastream/audio-session-stays-active-when-removing-session-during-capture-expected.txt:
 Added.
* 
LayoutTests/fast/mediastream/audio-session-stays-active-when-removing-session-during-capture.html:
 Added.
* LayoutTests/platform/glib/TestExpectations:
* Source/WebCore/Modules/mediasession/MediaSession.cpp:
(WebCore::MediaSession::updateCaptureState):
* Source/WebCore/Modules/mediastream/MediaStreamTrack.cpp:
(WebCore::MediaStreamTrack::trackMutedChanged):
(WebCore::MediaStreamTrack::isCapturingAudio const):
(WebCore::MediaStreamTrack::wantsToCaptureAudio const):
* Source/WebCore/Modules/mediastream/UserMediaRequest.cpp:
(WebCore::UserMediaRequest::allow):
* Source/WebCore/platform/LogMessages.in:
* Source/WebCore/platform/audio/MediaSessionManagerInterface.cpp:
(WebCore::MediaSessionManagerInterface::processWillSuspend):
(WebCore::MediaSessionManagerInterface::audioCaptureSourceStateChanged):
(WebCore::MediaSessionManagerInterface::removeSession):
(WebCore::MediaSessionManagerInterface::maybeDeactivateAudioSession):
* Source/WebCore/platform/audio/MediaSessionManagerInterface.h:

Canonical link: https://commits.webkit.org/316394@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to