Skip to content

Commit

Permalink
Check context status before recreating platform destination
Browse files Browse the repository at this point in the history
Changing the channel count in the RealtimeAudioDestinationHandler will
trigger the recreation of the platform destination. This in turn can
activate the audio rendering thread.

This CL adds a check to prevent this from happening after the handler
is garbage collected.

(cherry picked from commit 4997f2b)

Bug: 1497859
Test: Locally confirmed with ASAN
Change-Id: I5d2649f3fd3639779ae40b0ca4ef2fe305653421
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4995928
Commit-Queue: Hongchan Choi <hongchan@chromium.org>
Reviewed-by: Michael Wilson <mjwilson@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1217868}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5004961
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/branch-heads/5993@{#1520}
Cr-Branched-From: 5113507-refs/heads/main@{#1192594}
  • Loading branch information
hoch authored and Chromium LUCI CQ committed Nov 3, 2023
1 parent 2bb1186 commit 3df423a
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,21 @@ void RealtimeAudioDestinationHandler::SetChannelCount(
uint32_t old_channel_count = ChannelCount();
AudioHandler::SetChannelCount(channel_count, exception_state);

// Stop, re-create and start the destination to apply the new channel count.
if (ChannelCount() != old_channel_count && !exception_state.HadException()) {
StopPlatformDestination();
CreatePlatformDestination();
StartPlatformDestination();
// After the context is closed, changing channel count will be ignored
// because it will trigger the recreation of the platform destination. This
// in turn can activate the audio rendering thread.
AudioContext* context = static_cast<AudioContext*>(Context());
CHECK(context);
if (context->ContextState() == AudioContext::kClosed ||
ChannelCount() == old_channel_count ||
exception_state.HadException()) {
return;
}

// Stop, re-create and start the destination to apply the new channel count.
StopPlatformDestination();
CreatePlatformDestination();
StartPlatformDestination();
}

void RealtimeAudioDestinationHandler::StartRendering() {
Expand Down

0 comments on commit 3df423a

Please sign in to comment.