Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Unified Diff: media/audio/audio_input_device.cc

Issue 2076793002: Cleanup AudioDeviceThread to reduce locking and unused features. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/audio/audio_input_device.cc
diff --git a/media/audio/audio_input_device.cc b/media/audio/audio_input_device.cc
index fc6b39285ad363aeb2e7591eacfcd77b8d97bfbb..71518d79951b35a678dc654afb3c70072b289399 100644
--- a/media/audio/audio_input_device.cc
+++ b/media/audio/audio_input_device.cc
@@ -94,7 +94,7 @@ void AudioInputDevice::Stop() {
{
base::AutoLock auto_lock(audio_thread_lock_);
- audio_thread_.Stop(base::MessageLoop::current());
+ audio_thread_.reset();
stopping_hack_ = true;
}
@@ -143,11 +143,12 @@ void AudioInputDevice::OnStreamCreated(
if (stopping_hack_)
return;
- DCHECK(audio_thread_.IsStopped());
+ DCHECK(!audio_callback_);
+ DCHECK(!audio_thread_);
audio_callback_.reset(new AudioInputDevice::AudioThreadCallback(
audio_parameters_, handle, length, total_segments, callback_));
- audio_thread_.Start(
- audio_callback_.get(), socket_handle, "AudioInputDevice", true);
+ audio_thread_.reset(new AudioDeviceThread(audio_callback_.get(),
+ socket_handle, "AudioInputDevice"));
state_ = RECORDING;
ipc_->RecordStream();
@@ -182,9 +183,13 @@ void AudioInputDevice::OnStateChanged(
// TODO(tommi): Add an explicit contract for clearing the callback
// object. Possibly require calling Initialize again or provide
// a callback object via Start() and clear it in Stop().
- if (!audio_thread_.IsStopped())
- callback_->OnCaptureError(
- "AudioInputDevice::OnStateChanged - audio thread still running");
+ {
+ base::AutoLock auto_lock_(audio_thread_lock_);
tommi (sloooow) - chröme 2016/06/16 22:19:22 auto_lock
+ if (audio_thread_) {
+ callback_->OnCaptureError(
+ "AudioInputDevice::OnStateChanged - audio thread still running");
+ }
+ }
break;
default:
NOTREACHED();
@@ -198,11 +203,7 @@ void AudioInputDevice::OnIPCClosed() {
ipc_.reset();
}
-AudioInputDevice::~AudioInputDevice() {
- // TODO(henrika): The current design requires that the user calls
- // Stop before deleting this class.
- DCHECK(audio_thread_.IsStopped());
-}
+AudioInputDevice::~AudioInputDevice() {}
void AudioInputDevice::StartUpOnIOThread() {
DCHECK(task_runner()->BelongsToCurrentThread());
@@ -241,7 +242,7 @@ void AudioInputDevice::ShutDownOnIOThread() {
// and can't not rely on the main thread existing either.
base::AutoLock auto_lock_(audio_thread_lock_);
base::ThreadRestrictions::ScopedAllowIO allow_io;
- audio_thread_.Stop(NULL);
+ audio_thread_.reset();
audio_callback_.reset();
stopping_hack_ = false;
}

Powered by Google App Engine
This is Rietveld 408576698