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

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: 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
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
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 last_play_samples_(0), 65 last_play_samples_(0),
66 last_log_stat_time_(0) { 66 last_log_stat_time_(0) {
67 LOG(INFO) << "AudioDeviceBuffer::ctor"; 67 LOG(INFO) << "AudioDeviceBuffer::ctor";
68 memset(_recBuffer, 0, kMaxBufferSizeBytes); 68 memset(_recBuffer, 0, kMaxBufferSizeBytes);
69 memset(_playBuffer, 0, kMaxBufferSizeBytes); 69 memset(_playBuffer, 0, kMaxBufferSizeBytes);
70 } 70 }
71 71
72 AudioDeviceBuffer::~AudioDeviceBuffer() { 72 AudioDeviceBuffer::~AudioDeviceBuffer() {
73 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 73 RTC_DCHECK(thread_checker_.CalledOnValidThread());
74 LOG(INFO) << "AudioDeviceBuffer::~dtor"; 74 LOG(INFO) << "AudioDeviceBuffer::~dtor";
75
76 int total_diff_time = 0;
77 int num_measurements = 0;
78 while (!playout_diff_time_map_.empty()) {
magjed_webrtc 2016/07/29 10:07:11 Use a range-based loop instead: for (const auto& k
henrika_webrtc 2016/07/29 11:11:00 Thanks.
79 int time_diff = playout_diff_time_map_.begin()->first;
80 int num_elements = playout_diff_time_map_.begin()->second;
81 total_diff_time += num_elements * time_diff;
82 num_measurements += num_elements;
83 LOG(INFO) << time_diff << " => " << num_elements;
84 playout_diff_time_map_.erase(playout_diff_time_map_.begin());
85 }
86 LOG(INFO) << "total_diff_time: " << total_diff_time;
87 LOG(INFO) << "num_measurements: " << num_measurements;
88 LOG(INFO) << "average: "
89 << static_cast<float>(total_diff_time) / num_measurements;
90
91
75 _recFile.Flush(); 92 _recFile.Flush();
76 _recFile.CloseFile(); 93 _recFile.CloseFile();
77 delete &_recFile; 94 delete &_recFile;
78 95
79 _playFile.Flush(); 96 _playFile.Flush();
80 _playFile.CloseFile(); 97 _playFile.CloseFile();
81 delete &_playFile; 98 delete &_playFile;
82 } 99 }
83 100
84 int32_t AudioDeviceBuffer::RegisterAudioCallback( 101 int32_t AudioDeviceBuffer::RegisterAudioCallback(
85 AudioTransport* audioCallback) { 102 AudioTransport* audioCallback) {
86 LOG(INFO) << __FUNCTION__; 103 LOG(INFO) << __FUNCTION__;
87 rtc::CritScope lock(&_critSectCb); 104 rtc::CritScope lock(&_critSectCb);
88 _ptrCbAudioTransport = audioCallback; 105 _ptrCbAudioTransport = audioCallback;
89 return 0; 106 return 0;
90 } 107 }
91 108
92 int32_t AudioDeviceBuffer::InitPlayout() { 109 int32_t AudioDeviceBuffer::InitPlayout() {
93 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 110 RTC_DCHECK(thread_checker_.CalledOnValidThread());
94 LOG(INFO) << __FUNCTION__; 111 LOG(INFO) << __FUNCTION__;
112 last_playout_time_ = rtc::TimeMillis();
95 if (!timer_has_started_) { 113 if (!timer_has_started_) {
96 StartTimer(); 114 StartTimer();
97 timer_has_started_ = true; 115 timer_has_started_ = true;
98 } 116 }
99 return 0; 117 return 0;
100 } 118 }
101 119
102 int32_t AudioDeviceBuffer::InitRecording() { 120 int32_t AudioDeviceBuffer::InitRecording() {
103 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 121 RTC_DCHECK(thread_checker_.CalledOnValidThread());
104 LOG(INFO) << __FUNCTION__; 122 LOG(INFO) << __FUNCTION__;
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 } 344 }
327 345
328 return 0; 346 return 0;
329 } 347 }
330 348
331 int32_t AudioDeviceBuffer::RequestPlayoutData(size_t nSamples) { 349 int32_t AudioDeviceBuffer::RequestPlayoutData(size_t nSamples) {
332 uint32_t playSampleRate = 0; 350 uint32_t playSampleRate = 0;
333 size_t playBytesPerSample = 0; 351 size_t playBytesPerSample = 0;
334 size_t playChannels = 0; 352 size_t playChannels = 0;
335 353
354 // Measure time since last function call and update a map where the key value
355 // corresponds to time differences (in milliseconds), and the mapped element
356 // represents the number of times a given time difference was found.
357 // Writing to map can be done without a lock since it is only read once at
358 // destruction when no audio is running.
359 int64_t now_time = rtc::TimeMillis();
360 int64_t diff_time = rtc::TimeDiff(now_time, last_playout_time_);
magjed_webrtc 2016/07/29 10:07:11 Consider using diff_time = std::min(1000, diff_tim
henrika_webrtc 2016/07/29 11:11:00 Will add the cap, thanks! Would like to keep the
magjed_webrtc 2016/07/29 12:16:07 The map has a big overhead per element and will ne
henrika_webrtc 2016/07/29 12:50:24 Will change
361 last_playout_time_ = now_time;
362 playout_diff_time_map_[diff_time]++;
363
336 // TOOD(henrika): improve bad locking model and make it more clear that only 364 // TOOD(henrika): improve bad locking model and make it more clear that only
337 // 10ms buffer sizes is supported in WebRTC. 365 // 10ms buffer sizes is supported in WebRTC.
338 { 366 {
339 rtc::CritScope lock(&_critSect); 367 rtc::CritScope lock(&_critSect);
340 368
341 // Store copies under lock and use copies hereafter to avoid race with 369 // Store copies under lock and use copies hereafter to avoid race with
342 // setter methods. 370 // setter methods.
343 playSampleRate = _playSampleRate; 371 playSampleRate = _playSampleRate;
344 playBytesPerSample = _playBytesPerSample; 372 playBytesPerSample = _playBytesPerSample;
345 playChannels = _playChannels; 373 playChannels = _playChannels;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 rec_samples_ += num_samples; 485 rec_samples_ += num_samples;
458 } 486 }
459 487
460 void AudioDeviceBuffer::UpdatePlayStats(size_t num_samples) { 488 void AudioDeviceBuffer::UpdatePlayStats(size_t num_samples) {
461 RTC_DCHECK(task_queue_.IsCurrent()); 489 RTC_DCHECK(task_queue_.IsCurrent());
462 ++play_callbacks_; 490 ++play_callbacks_;
463 play_samples_ += num_samples; 491 play_samples_ += num_samples;
464 } 492 }
465 493
466 } // namespace webrtc 494 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698