Skip to content

Commit

Permalink
Always clear thread local context.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Mar 18, 2021
1 parent daa067c commit 01258d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 9 additions & 4 deletions webrtc/details/webrtc_openal_adm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,10 +867,16 @@ void AudioDeviceOpenAL::startPlayingOnThread() {
void AudioDeviceOpenAL::stopPlayingOnThread() {
Expects(_data != nullptr);

if (!_data->playing) {
return;
}
sync([&] {
const auto guard = gsl::finally([&] {
if (alEventCallbackSOFT) {
alEventCallbackSOFT(nullptr, nullptr);
}
alcSetThreadContext(nullptr);
});
if (!_data->playing) {
return;
}
_data->playing = false;
if (_playoutFailed) {
return;
Expand All @@ -886,7 +892,6 @@ void AudioDeviceOpenAL::stopPlayingOnThread() {
_data->source = 0;
ranges::fill(_data->buffers, ALuint(0));
}
alcSetThreadContext(nullptr);
});
}

Expand Down
7 changes: 7 additions & 0 deletions webrtc/details/webrtc_openal_adm.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ class AudioDeviceOpenAL : public webrtc::AudioDeviceModule {
void openRecordingDevice();
void openPlayoutDevice();
void closeRecordingDevice();

// NB! stopPlayingOnThread should be called before this,
// to clear the thread local context and event callback.
void closePlayoutDevice();

int restartPlayout();
int restartRecording();
void restartRecordingQueued();
Expand All @@ -138,6 +142,9 @@ class AudioDeviceOpenAL : public webrtc::AudioDeviceModule {
void startCaptureOnThread();
void stopCaptureOnThread();
void startPlayingOnThread();

// NB! closePlayoutDevice should be called after this, so that next time
// we start playing, we set the thread local context and event callback.
void stopPlayingOnThread();

void processData();
Expand Down

0 comments on commit 01258d9

Please sign in to comment.