| OLD | NEW |
| 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 Loading... |
| 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 int 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 int 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 LOG(INFO) << "total_diff_time: " << total_diff_time; |
| 91 LOG(INFO) << "num_measurements: " << num_measurements; |
| 92 LOG(INFO) << "average: " |
| 93 << static_cast<float>(total_diff_time) / num_measurements; |
| 94 |
| 75 _recFile.Flush(); | 95 _recFile.Flush(); |
| 76 _recFile.CloseFile(); | 96 _recFile.CloseFile(); |
| 77 delete &_recFile; | 97 delete &_recFile; |
| 78 | 98 |
| 79 _playFile.Flush(); | 99 _playFile.Flush(); |
| 80 _playFile.CloseFile(); | 100 _playFile.CloseFile(); |
| 81 delete &_playFile; | 101 delete &_playFile; |
| 82 } | 102 } |
| 83 | 103 |
| 84 int32_t AudioDeviceBuffer::RegisterAudioCallback( | 104 int32_t AudioDeviceBuffer::RegisterAudioCallback( |
| 85 AudioTransport* audioCallback) { | 105 AudioTransport* audioCallback) { |
| 86 LOG(INFO) << __FUNCTION__; | 106 LOG(INFO) << __FUNCTION__; |
| 87 rtc::CritScope lock(&_critSectCb); | 107 rtc::CritScope lock(&_critSectCb); |
| 88 _ptrCbAudioTransport = audioCallback; | 108 _ptrCbAudioTransport = audioCallback; |
| 89 return 0; | 109 return 0; |
| 90 } | 110 } |
| 91 | 111 |
| 92 int32_t AudioDeviceBuffer::InitPlayout() { | 112 int32_t AudioDeviceBuffer::InitPlayout() { |
| 93 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 113 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 94 LOG(INFO) << __FUNCTION__; | 114 LOG(INFO) << __FUNCTION__; |
| 115 last_playout_time_ = rtc::TimeMillis(); |
| 95 if (!timer_has_started_) { | 116 if (!timer_has_started_) { |
| 96 StartTimer(); | 117 StartTimer(); |
| 97 timer_has_started_ = true; | 118 timer_has_started_ = true; |
| 98 } | 119 } |
| 99 return 0; | 120 return 0; |
| 100 } | 121 } |
| 101 | 122 |
| 102 int32_t AudioDeviceBuffer::InitRecording() { | 123 int32_t AudioDeviceBuffer::InitRecording() { |
| 103 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 124 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 104 LOG(INFO) << __FUNCTION__; | 125 LOG(INFO) << __FUNCTION__; |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 } | 347 } |
| 327 | 348 |
| 328 return 0; | 349 return 0; |
| 329 } | 350 } |
| 330 | 351 |
| 331 int32_t AudioDeviceBuffer::RequestPlayoutData(size_t nSamples) { | 352 int32_t AudioDeviceBuffer::RequestPlayoutData(size_t nSamples) { |
| 332 uint32_t playSampleRate = 0; | 353 uint32_t playSampleRate = 0; |
| 333 size_t playBytesPerSample = 0; | 354 size_t playBytesPerSample = 0; |
| 334 size_t playChannels = 0; | 355 size_t playChannels = 0; |
| 335 | 356 |
| 357 // Measure time since last function call and update an array where the |
| 358 // position/index corresponds to time differences (in milliseconds) between |
| 359 // two successive playout callbacks, and the stored value is the number of |
| 360 // times a given time difference was found. |
| 361 int64_t now_time = rtc::TimeMillis(); |
| 362 size_t diff_time = rtc::TimeDiff(now_time, last_playout_time_); |
| 363 // Truncate at 500ms to limit the size of the array. |
| 364 diff_time = std::min(kMaxDeltaTimeInMs, diff_time); |
| 365 last_playout_time_ = now_time; |
| 366 playout_diff_times_[diff_time]++; |
| 367 |
| 336 // TOOD(henrika): improve bad locking model and make it more clear that only | 368 // TOOD(henrika): improve bad locking model and make it more clear that only |
| 337 // 10ms buffer sizes is supported in WebRTC. | 369 // 10ms buffer sizes is supported in WebRTC. |
| 338 { | 370 { |
| 339 rtc::CritScope lock(&_critSect); | 371 rtc::CritScope lock(&_critSect); |
| 340 | 372 |
| 341 // Store copies under lock and use copies hereafter to avoid race with | 373 // Store copies under lock and use copies hereafter to avoid race with |
| 342 // setter methods. | 374 // setter methods. |
| 343 playSampleRate = _playSampleRate; | 375 playSampleRate = _playSampleRate; |
| 344 playBytesPerSample = _playBytesPerSample; | 376 playBytesPerSample = _playBytesPerSample; |
| 345 playChannels = _playChannels; | 377 playChannels = _playChannels; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 rec_samples_ += num_samples; | 489 rec_samples_ += num_samples; |
| 458 } | 490 } |
| 459 | 491 |
| 460 void AudioDeviceBuffer::UpdatePlayStats(size_t num_samples) { | 492 void AudioDeviceBuffer::UpdatePlayStats(size_t num_samples) { |
| 461 RTC_DCHECK(task_queue_.IsCurrent()); | 493 RTC_DCHECK(task_queue_.IsCurrent()); |
| 462 ++play_callbacks_; | 494 ++play_callbacks_; |
| 463 play_samples_ += num_samples; | 495 play_samples_ += num_samples; |
| 464 } | 496 } |
| 465 | 497 |
| 466 } // namespace webrtc | 498 } // namespace webrtc |
| OLD | NEW |