Index: content/renderer/media/audio_device.cc |
diff --git a/content/renderer/media/audio_device.cc b/content/renderer/media/audio_device.cc |
index 3f89e93ced06d84d6e3524353648f45c4abe2a88..d4e344a7b3bb0aeaa237c5df2e10dbbe0943b3c7 100644 |
--- a/content/renderer/media/audio_device.cc |
+++ b/content/renderer/media/audio_device.cc |
@@ -178,6 +178,15 @@ void AudioDevice::ShutDownOnIOThread() { |
stream_id_ = 0; |
} |
+ // We can run into an issue where ShutDownOnIOThread is called right after |
+ // OnStreamCreated is called in cases where Start/Stop are called before we |
+ // get the OnStreamCreated callback. To handle that corner case, we call |
+ // Stop(). In most cases, the thread will already be stopped. |
+ // Another situation is when the IO thread goes away before Stop() is called |
+ // in which case, we cannot use the message loop to close the thread handle |
+ // and can't not rely on the main thread existing either. |
+ base::ThreadRestrictions::ScopedAllowIO allow_io; |
+ audio_thread_.Stop(NULL); |
audio_callback_.reset(); |
} |
@@ -218,6 +227,7 @@ void AudioDevice::OnStreamCreated( |
return; |
} |
+ DCHECK(audio_thread_.IsStopped()); |
audio_callback_.reset(new AudioDevice::AudioThreadCallback(audio_parameters_, |
handle, length, callback_)); |
audio_thread_.Start(audio_callback_.get(), socket_handle, "AudioDevice"); |
@@ -234,6 +244,7 @@ void AudioDevice::Send(IPC::Message* message) { |
} |
void AudioDevice::WillDestroyCurrentMessageLoop() { |
+ LOG(ERROR) << "IO loop going away before the audio device has been stopped"; |
ShutDownOnIOThread(); |
} |