From 0b3a6389c054dff7cc9da10a326eedbd4d9f5e61 Mon Sep 17 00:00:00 2001 From: henrika Date: Fri, 11 Nov 2016 02:28:50 -0800 Subject: [PATCH] Ensures that AudioDeviceBuffer::StopPeriodicLogging works as intended. Minor fix to resolve https://bugs.chromium.org/p/webrtc/issues/detail?id=6560&desc=2#c5 BUG=webrtc:6560 NOTRY=TRUE Review-Url: https://codereview.webrtc.org/2496543002 Cr-Commit-Position: refs/heads/master@{#15036} --- webrtc/modules/audio_device/audio_device_buffer.cc | 14 +++++++++++--- webrtc/modules/audio_device/audio_device_buffer.h | 6 ++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/webrtc/modules/audio_device/audio_device_buffer.cc b/webrtc/modules/audio_device/audio_device_buffer.cc index 4102a610d1..d40b05e70a 100644 --- a/webrtc/modules/audio_device/audio_device_buffer.cc +++ b/webrtc/modules/audio_device/audio_device_buffer.cc @@ -68,7 +68,8 @@ AudioDeviceBuffer::AudioDeviceBuffer() play_stat_count_(0), play_start_time_(0), rec_start_time_(0), - only_silence_recorded_(true) { + only_silence_recorded_(true), + log_stats_(false) { LOG(INFO) << "AudioDeviceBuffer::ctor"; playout_thread_checker_.DetachFromThread(); recording_thread_checker_.DetachFromThread(); @@ -429,16 +430,23 @@ void AudioDeviceBuffer::StopPeriodicLogging() { void AudioDeviceBuffer::LogStats(LogState state) { RTC_DCHECK_RUN_ON(&task_queue_); int64_t now_time = rtc::TimeMillis(); + if (state == AudioDeviceBuffer::LOG_START) { // Reset counters at start. We will not add any logging in this state but // the timer will started by posting a new (delayed) task. num_stat_reports_ = 0; last_timer_task_time_ = now_time; + log_stats_ = true; } else if (state == AudioDeviceBuffer::LOG_STOP) { // Stop logging and posting new tasks. - return; + log_stats_ = false; } else if (state == AudioDeviceBuffer::LOG_ACTIVE) { - // Default state. Just keep on logging. + // Keep logging unless logging was disabled while task was posted. + } + + // Avoid adding more logs since we are in STOP mode. + if (!log_stats_) { + return; } int64_t next_callback_time = now_time + kTimerIntervalInMilliseconds; diff --git a/webrtc/modules/audio_device/audio_device_buffer.h b/webrtc/modules/audio_device/audio_device_buffer.h index 0e7a22dda5..167ebd234a 100644 --- a/webrtc/modules/audio_device/audio_device_buffer.h +++ b/webrtc/modules/audio_device/audio_device_buffer.h @@ -234,6 +234,12 @@ class AudioDeviceBuffer { // Set to true at construction and modified to false as soon as one audio- // level estimate larger than zero is detected. bool only_silence_recorded_; + + // Set to true when logging of audio stats is enabled for the first time in + // StartPeriodicLogging() and set to false by StopPeriodicLogging(). + // Setting this member to false prevents (possiby invalid) log messages from + // being printed in the LogStats() task. + bool log_stats_ ACCESS_ON(task_queue_); }; } // namespace webrtc