Skip to content

Commit

Permalink
REGRESSION(266293@main): media/audioSession/audioSessionState.html is…
Browse files Browse the repository at this point in the history
… a flaky failure

https://bugs.webkit.org/show_bug.cgi?id=259524
rdar://112914519

Reviewed by Jean-Yves Avenard.

The flakiness was due to the following steps:
1. With internals, we simulate beginning an interruption from WebProcess, which is sent to GPU process, which does the interuption business.
2. This triggers notification to the WebProcess that the AudioSession state changed. DOMAudioSession schedules a task to check this and fires an event if needed.
3. Very close to simulating the beginning of the interruption, the WebProcess also tries to activate its audio session. On GPUProcess side, this succeeeds, which triggers ending the interruption.
4. The WebProcess is then notified and DOMAudioSession quickly schedules a task to check this and fires an event as needed.
5. In case the WebProcess beginning and end of interruptions are very close, the first DOMAudioSession task will not see a change of the DOMAudioSession state and will quit early without firing an event.

To prevent the flakiness, we enforce RemoteAudioSession::tryToSetActiveInternal to fail when we are in a test interruption and active is true, like would happen in case of a phone call interruption.

* LayoutTests/platform/mac/TestExpectations:
* Source/WebCore/testing/Internals.cpp:
(WebCore::Internals::resetToConsistentState):
* Source/WebKit/WebProcess/GPU/media/RemoteAudioSession.cpp:
(WebKit::RemoteAudioSession::tryToSetActiveInternal):
(WebKit::RemoteAudioSession::endAudioSessionInterruption):
(WebKit::RemoteAudioSession::beginInterruptionForTesting):
(WebKit::RemoteAudioSession::endInterruptionForTesting):
* Source/WebKit/WebProcess/GPU/media/RemoteAudioSession.h:

Canonical link: https://commits.webkit.org/267683@main
  • Loading branch information
youennf committed Sep 6, 2023
1 parent 22c04c6 commit cfee0fe
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 0 additions & 2 deletions LayoutTests/platform/mac/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -2733,8 +2733,6 @@ webkit.org/b/259712 [ Monterey+ ] media/media-source/media-source-paint-after-di

webkit.org/b/259489 [ Monterey+ ] http/tests/media/hls/track-in-band-multiple-cues.html [ Pass Failure ]

webkit.org/b/259524 [ Monterey+ ] media/audioSession/audioSessionState.html [ Pass Failure ]

# rdar://110876540 ASSERTION FAILED: firstChild(): [ macOS ] (258183)
[ Debug ] media/modern-media-controls/tracks-support/text-track-selected-via-media-api.html [ Pass Crash ]

Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/testing/Internals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ void Internals::resetToConsistentState(Page& page)
#if USE(AUDIO_SESSION)
AudioSession::sharedSession().setCategoryOverride(AudioSessionCategory::None);
AudioSession::sharedSession().tryToSetActive(false);
AudioSession::sharedSession().endInterruptionForTesting();
#endif
}

Expand Down
8 changes: 8 additions & 0 deletions Source/WebKit/WebProcess/GPU/media/RemoteAudioSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ void RemoteAudioSession::setPreferredBufferSize(size_t size)

bool RemoteAudioSession::tryToSetActiveInternal(bool active)
{
if (active && m_isInterruptedForTesting)
return false;

auto sendResult = ensureConnection().sendSync(Messages::RemoteAudioSessionProxy::TryToSetActive(active), { });
auto [succeeded] = sendResult.takeReplyOr(false);
if (succeeded)
Expand Down Expand Up @@ -201,11 +204,16 @@ void RemoteAudioSession::endAudioSessionInterruption(MayResume mayResume)

void RemoteAudioSession::beginInterruptionForTesting()
{
m_isInterruptedForTesting = true;
ensureConnection().send(Messages::RemoteAudioSessionProxy::TriggerBeginInterruptionForTesting(), { });
}

void RemoteAudioSession::endInterruptionForTesting()
{
if (!m_isInterruptedForTesting)
return;

m_isInterruptedForTesting = false;
ensureConnection().send(Messages::RemoteAudioSessionProxy::TriggerEndInterruptionForTesting(), { });
}

Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/WebProcess/GPU/media/RemoteAudioSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class RemoteAudioSession final
bool m_isPlayingToBluetoothOverrideChanged { false };
std::optional<RemoteAudioSessionConfiguration> m_configuration;
ThreadSafeWeakPtr<GPUProcessConnection> m_gpuProcessConnection;
bool m_isInterruptedForTesting { false };
};

}
Expand Down

0 comments on commit cfee0fe

Please sign in to comment.