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

Side by Side Diff: media/audio/audio_input_controller.cc

Issue 2954323002: Fixed AudioInputController muted state related tsan bug. (Closed)
Patch Set: Rebased Created 3 years, 5 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 unified diff | Download patch
« no previous file with comments | « media/audio/audio_input_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/audio/audio_input_controller.h" 5 #include "media/audio/audio_input_controller.h"
6 6
7 #include <inttypes.h> 7 #include <inttypes.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 #endif 193 #endif
194 weak_ptr_factory_(this) { 194 weak_ptr_factory_(this) {
195 DCHECK(creator_task_runner_.get()); 195 DCHECK(creator_task_runner_.get());
196 DCHECK(handler_); 196 DCHECK(handler_);
197 DCHECK(sync_writer_); 197 DCHECK(sync_writer_);
198 } 198 }
199 199
200 AudioInputController::~AudioInputController() { 200 AudioInputController::~AudioInputController() {
201 DCHECK(!audio_callback_); 201 DCHECK(!audio_callback_);
202 DCHECK(!stream_); 202 DCHECK(!stream_);
203 DCHECK(!check_muted_state_timer_.IsRunning()); 203 DCHECK(!check_muted_state_timer_);
204 } 204 }
205 205
206 // static 206 // static
207 scoped_refptr<AudioInputController> AudioInputController::Create( 207 scoped_refptr<AudioInputController> AudioInputController::Create(
208 AudioManager* audio_manager, 208 AudioManager* audio_manager,
209 EventHandler* event_handler, 209 EventHandler* event_handler,
210 SyncWriter* sync_writer, 210 SyncWriter* sync_writer,
211 UserInputMonitor* user_input_monitor, 211 UserInputMonitor* user_input_monitor,
212 const AudioParameters& params, 212 const AudioParameters& params,
213 const std::string& device_id, 213 const std::string& device_id,
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 stream_to_control->SetAutomaticGainControl(enable_agc); 357 stream_to_control->SetAutomaticGainControl(enable_agc);
358 #endif 358 #endif
359 359
360 // Finally, keep the stream pointer around, update the state and notify. 360 // Finally, keep the stream pointer around, update the state and notify.
361 stream_ = stream_to_control; 361 stream_ = stream_to_control;
362 362
363 // Send initial muted state along with OnCreated, to avoid races. 363 // Send initial muted state along with OnCreated, to avoid races.
364 is_muted_ = stream_->IsMuted(); 364 is_muted_ = stream_->IsMuted();
365 handler_->OnCreated(this, is_muted_); 365 handler_->OnCreated(this, is_muted_);
366 366
367 check_muted_state_timer_.Start( 367 // Start a new repeating timer to keep the muted state updated.
368 check_muted_state_timer_.emplace();
369 check_muted_state_timer_->Start(
368 FROM_HERE, base::TimeDelta::FromSeconds(kCheckMutedStateIntervalSeconds), 370 FROM_HERE, base::TimeDelta::FromSeconds(kCheckMutedStateIntervalSeconds),
369 this, &AudioInputController::CheckMutedState); 371 this, &AudioInputController::CheckMutedState);
370 DCHECK(check_muted_state_timer_.IsRunning()); 372 DCHECK(check_muted_state_timer_->IsRunning());
371 } 373 }
372 374
373 void AudioInputController::DoRecord() { 375 void AudioInputController::DoRecord() {
374 DCHECK(task_runner_->BelongsToCurrentThread()); 376 DCHECK(task_runner_->BelongsToCurrentThread());
375 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioInputController.RecordTime"); 377 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioInputController.RecordTime");
376 378
377 if (!stream_ || audio_callback_) 379 if (!stream_ || audio_callback_)
378 return; 380 return;
379 381
380 handler_->OnLog(this, "AIC::DoRecord"); 382 handler_->OnLog(this, "AIC::DoRecord");
381 383
382 if (user_input_monitor_) { 384 if (user_input_monitor_) {
383 user_input_monitor_->EnableKeyPressMonitoring(); 385 user_input_monitor_->EnableKeyPressMonitoring();
384 prev_key_down_count_ = user_input_monitor_->GetKeyPressCount(); 386 prev_key_down_count_ = user_input_monitor_->GetKeyPressCount();
385 } 387 }
386 388
387 stream_create_time_ = base::TimeTicks::Now(); 389 stream_create_time_ = base::TimeTicks::Now();
388 390
389 audio_callback_.reset(new AudioCallback(this)); 391 audio_callback_.reset(new AudioCallback(this));
390 stream_->Start(audio_callback_.get()); 392 stream_->Start(audio_callback_.get());
391 } 393 }
392 394
393 void AudioInputController::DoClose() { 395 void AudioInputController::DoClose() {
394 DCHECK(task_runner_->BelongsToCurrentThread()); 396 DCHECK(task_runner_->BelongsToCurrentThread());
395 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioInputController.CloseTime"); 397 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioInputController.CloseTime");
396 398
397 if (!stream_) 399 if (!stream_)
398 return; 400 return;
399 401
400 check_muted_state_timer_.Stop(); 402 // Stop and destroy the mute check timer.
403 check_muted_state_timer_.reset();
401 404
402 std::string log_string; 405 std::string log_string;
403 static const char kLogStringPrefix[] = "AIC::DoClose:"; 406 static const char kLogStringPrefix[] = "AIC::DoClose:";
404 407
405 // Allow calling unconditionally and bail if we don't have a stream to close. 408 // Allow calling unconditionally and bail if we don't have a stream to close.
406 if (audio_callback_) { 409 if (audio_callback_) {
407 stream_->Stop(); 410 stream_->Stop();
408 411
409 // Sometimes a stream (and accompanying audio track) is created and 412 // Sometimes a stream (and accompanying audio track) is created and
410 // immediately closed or discarded. In this case they are registered as 413 // immediately closed or discarded. In this case they are registered as
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 case AudioParameters::Format::AUDIO_PCM_LOW_LATENCY: 701 case AudioParameters::Format::AUDIO_PCM_LOW_LATENCY:
699 return AudioInputController::StreamType::LOW_LATENCY; 702 return AudioInputController::StreamType::LOW_LATENCY;
700 default: 703 default:
701 // Currently, the remaining supported type is fake. Reconsider if other 704 // Currently, the remaining supported type is fake. Reconsider if other
702 // formats become supported. 705 // formats become supported.
703 return AudioInputController::StreamType::FAKE; 706 return AudioInputController::StreamType::FAKE;
704 } 707 }
705 } 708 }
706 709
707 } // namespace media 710 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_input_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698