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

Side by Side Diff: webrtc/modules/audio_device/audio_device_buffer.cc

Issue 2190343002: Adds delta-time logging for audio playout (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixed div by zero Created 4 years, 4 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 | « webrtc/modules/audio_device/audio_device_buffer.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 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <algorithm>
12
11 #include "webrtc/modules/audio_device/audio_device_buffer.h" 13 #include "webrtc/modules/audio_device/audio_device_buffer.h"
12 14
15 #include "webrtc/base/arraysize.h"
13 #include "webrtc/base/bind.h" 16 #include "webrtc/base/bind.h"
14 #include "webrtc/base/checks.h" 17 #include "webrtc/base/checks.h"
15 #include "webrtc/base/logging.h" 18 #include "webrtc/base/logging.h"
16 #include "webrtc/base/format_macros.h" 19 #include "webrtc/base/format_macros.h"
17 #include "webrtc/base/timeutils.h" 20 #include "webrtc/base/timeutils.h"
18 #include "webrtc/modules/audio_device/audio_device_config.h" 21 #include "webrtc/modules/audio_device/audio_device_config.h"
19 22
20 namespace webrtc { 23 namespace webrtc {
21 24
22 static const int kHighDelayThresholdMs = 300; 25 static const int kHighDelayThresholdMs = 300;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 last_play_samples_(0), 68 last_play_samples_(0),
66 last_log_stat_time_(0) { 69 last_log_stat_time_(0) {
67 LOG(INFO) << "AudioDeviceBuffer::ctor"; 70 LOG(INFO) << "AudioDeviceBuffer::ctor";
68 memset(_recBuffer, 0, kMaxBufferSizeBytes); 71 memset(_recBuffer, 0, kMaxBufferSizeBytes);
69 memset(_playBuffer, 0, kMaxBufferSizeBytes); 72 memset(_playBuffer, 0, kMaxBufferSizeBytes);
70 } 73 }
71 74
72 AudioDeviceBuffer::~AudioDeviceBuffer() { 75 AudioDeviceBuffer::~AudioDeviceBuffer() {
73 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 76 RTC_DCHECK(thread_checker_.CalledOnValidThread());
74 LOG(INFO) << "AudioDeviceBuffer::~dtor"; 77 LOG(INFO) << "AudioDeviceBuffer::~dtor";
78
79 size_t total_diff_time = 0;
80 int num_measurements = 0;
81 LOG(INFO) << "[playout diff time => #measurements]";
82 for (size_t diff = 0; diff < arraysize(playout_diff_times_); ++diff) {
83 uint32_t num_elements = playout_diff_times_[diff];
84 if (num_elements > 0) {
85 total_diff_time += num_elements * diff;
86 num_measurements += num_elements;
87 LOG(INFO) << "[" << diff << " => " << num_elements << "]";
88 }
89 }
90 if (num_measurements > 0) {
91 LOG(INFO) << "total_diff_time: " << total_diff_time;
92 LOG(INFO) << "num_measurements: " << num_measurements;
93 LOG(INFO) << "average: "
94 << static_cast<float>(total_diff_time) / num_measurements;
95 }
96
75 _recFile.Flush(); 97 _recFile.Flush();
76 _recFile.CloseFile(); 98 _recFile.CloseFile();
77 delete &_recFile; 99 delete &_recFile;
78 100
79 _playFile.Flush(); 101 _playFile.Flush();
80 _playFile.CloseFile(); 102 _playFile.CloseFile();
81 delete &_playFile; 103 delete &_playFile;
82 } 104 }
83 105
84 int32_t AudioDeviceBuffer::RegisterAudioCallback( 106 int32_t AudioDeviceBuffer::RegisterAudioCallback(
85 AudioTransport* audioCallback) { 107 AudioTransport* audioCallback) {
86 LOG(INFO) << __FUNCTION__; 108 LOG(INFO) << __FUNCTION__;
87 rtc::CritScope lock(&_critSectCb); 109 rtc::CritScope lock(&_critSectCb);
88 _ptrCbAudioTransport = audioCallback; 110 _ptrCbAudioTransport = audioCallback;
89 return 0; 111 return 0;
90 } 112 }
91 113
92 int32_t AudioDeviceBuffer::InitPlayout() { 114 int32_t AudioDeviceBuffer::InitPlayout() {
93 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 115 RTC_DCHECK(thread_checker_.CalledOnValidThread());
94 LOG(INFO) << __FUNCTION__; 116 LOG(INFO) << __FUNCTION__;
117 last_playout_time_ = rtc::TimeMillis();
95 if (!timer_has_started_) { 118 if (!timer_has_started_) {
96 StartTimer(); 119 StartTimer();
97 timer_has_started_ = true; 120 timer_has_started_ = true;
98 } 121 }
99 return 0; 122 return 0;
100 } 123 }
101 124
102 int32_t AudioDeviceBuffer::InitRecording() { 125 int32_t AudioDeviceBuffer::InitRecording() {
103 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 126 RTC_DCHECK(thread_checker_.CalledOnValidThread());
104 LOG(INFO) << __FUNCTION__; 127 LOG(INFO) << __FUNCTION__;
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 } 349 }
327 350
328 return 0; 351 return 0;
329 } 352 }
330 353
331 int32_t AudioDeviceBuffer::RequestPlayoutData(size_t nSamples) { 354 int32_t AudioDeviceBuffer::RequestPlayoutData(size_t nSamples) {
332 uint32_t playSampleRate = 0; 355 uint32_t playSampleRate = 0;
333 size_t playBytesPerSample = 0; 356 size_t playBytesPerSample = 0;
334 size_t playChannels = 0; 357 size_t playChannels = 0;
335 358
359 // Measure time since last function call and update an array where the
360 // position/index corresponds to time differences (in milliseconds) between
361 // two successive playout callbacks, and the stored value is the number of
362 // times a given time difference was found.
363 int64_t now_time = rtc::TimeMillis();
364 size_t diff_time = rtc::TimeDiff(now_time, last_playout_time_);
365 // Truncate at 500ms to limit the size of the array.
366 diff_time = std::min(kMaxDeltaTimeInMs, diff_time);
367 last_playout_time_ = now_time;
368 playout_diff_times_[diff_time]++;
369
336 // TOOD(henrika): improve bad locking model and make it more clear that only 370 // TOOD(henrika): improve bad locking model and make it more clear that only
337 // 10ms buffer sizes is supported in WebRTC. 371 // 10ms buffer sizes is supported in WebRTC.
338 { 372 {
339 rtc::CritScope lock(&_critSect); 373 rtc::CritScope lock(&_critSect);
340 374
341 // Store copies under lock and use copies hereafter to avoid race with 375 // Store copies under lock and use copies hereafter to avoid race with
342 // setter methods. 376 // setter methods.
343 playSampleRate = _playSampleRate; 377 playSampleRate = _playSampleRate;
344 playBytesPerSample = _playBytesPerSample; 378 playBytesPerSample = _playBytesPerSample;
345 playChannels = _playChannels; 379 playChannels = _playChannels;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 rec_samples_ += num_samples; 491 rec_samples_ += num_samples;
458 } 492 }
459 493
460 void AudioDeviceBuffer::UpdatePlayStats(size_t num_samples) { 494 void AudioDeviceBuffer::UpdatePlayStats(size_t num_samples) {
461 RTC_DCHECK(task_queue_.IsCurrent()); 495 RTC_DCHECK(task_queue_.IsCurrent());
462 ++play_callbacks_; 496 ++play_callbacks_;
463 play_samples_ += num_samples; 497 play_samples_ += num_samples;
464 } 498 }
465 499
466 } // namespace webrtc 500 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_device/audio_device_buffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698