From a6d26ec6a2a6eccb35b3456010956bf4f53a2659 Mon Sep 17 00:00:00 2001 From: henrika Date: Tue, 20 Sep 2016 04:44:04 -0700 Subject: [PATCH] Improves resolution when logging rate in the ADB class. Trivial patch which fixes an issue where logged rate estimates could be invalid. E.g. on iOS, two successive timer interrupts can be ~10.5 seconds and not exactly 10.0 (which is usually the case on Android). In those cases we could log a rate estimate of e.g. ~51000Hz instead of ~48000Hz. This CL fixes that. BUG=NONE Review-Url: https://codereview.webrtc.org/2350103002 Cr-Commit-Position: refs/heads/master@{#14305} --- webrtc/modules/audio_device/audio_device_buffer.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/webrtc/modules/audio_device/audio_device_buffer.cc b/webrtc/modules/audio_device/audio_device_buffer.cc index 0c85fdaf83..77cc74196e 100644 --- a/webrtc/modules/audio_device/audio_device_buffer.cc +++ b/webrtc/modules/audio_device/audio_device_buffer.cc @@ -398,25 +398,25 @@ void AudioDeviceBuffer::LogStats() { // Log the latest statistics but skip the first 10 seconds since we are not // sure of the exact starting point. I.e., the first log printout will be // after ~20 seconds. - if (++num_stat_reports_ > 1) { + if (++num_stat_reports_ > 1 && time_since_last > 0) { uint32_t diff_samples = rec_samples_ - last_rec_samples_; - uint32_t rate = diff_samples / kTimerIntervalInSeconds; + float rate = diff_samples / (static_cast(time_since_last) / 1000.0); LOG(INFO) << "[REC : " << time_since_last << "msec, " << rec_sample_rate_ / 1000 << "kHz] callbacks: " << rec_callbacks_ - last_rec_callbacks_ << ", " << "samples: " << diff_samples << ", " - << "rate: " << rate << ", " + << "rate: " << static_cast(rate + 0.5) << ", " << "level: " << max_rec_level_; diff_samples = play_samples_ - last_play_samples_; - rate = diff_samples / kTimerIntervalInSeconds; + rate = diff_samples / (static_cast(time_since_last) / 1000.0); LOG(INFO) << "[PLAY: " << time_since_last << "msec, " << play_sample_rate_ / 1000 << "kHz] callbacks: " << play_callbacks_ - last_play_callbacks_ << ", " << "samples: " << diff_samples << ", " - << "rate: " << rate << ", " + << "rate: " << static_cast(rate + 0.5) << ", " << "level: " << max_play_level_; }