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> | 11 #include <algorithm> |
12 | 12 |
13 #include "webrtc/modules/audio_device/audio_device_buffer.h" | 13 #include "webrtc/modules/audio_device/audio_device_buffer.h" |
14 | 14 |
15 #include "webrtc/base/arraysize.h" | 15 #include "webrtc/base/arraysize.h" |
16 #include "webrtc/base/bind.h" | 16 #include "webrtc/base/bind.h" |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
18 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" |
19 #include "webrtc/base/format_macros.h" | 19 #include "webrtc/base/format_macros.h" |
20 #include "webrtc/base/timeutils.h" | 20 #include "webrtc/base/timeutils.h" |
21 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" | |
21 #include "webrtc/modules/audio_device/audio_device_config.h" | 22 #include "webrtc/modules/audio_device/audio_device_config.h" |
23 #include "webrtc/system_wrappers/include/metrics.h" | |
22 | 24 |
23 namespace webrtc { | 25 namespace webrtc { |
24 | 26 |
25 static const char kTimerQueueName[] = "AudioDeviceBufferTimer"; | 27 static const char kTimerQueueName[] = "AudioDeviceBufferTimer"; |
26 | 28 |
27 // Time between two sucessive calls to LogStats(). | 29 // Time between two sucessive calls to LogStats(). |
28 static const size_t kTimerIntervalInSeconds = 10; | 30 static const size_t kTimerIntervalInSeconds = 10; |
29 static const size_t kTimerIntervalInMilliseconds = | 31 static const size_t kTimerIntervalInMilliseconds = |
30 kTimerIntervalInSeconds * rtc::kNumMillisecsPerSec; | 32 kTimerIntervalInSeconds * rtc::kNumMillisecsPerSec; |
31 | 33 |
(...skipping 20 matching lines...) Expand all Loading... | |
52 clock_drift_(0), | 54 clock_drift_(0), |
53 num_stat_reports_(0), | 55 num_stat_reports_(0), |
54 rec_callbacks_(0), | 56 rec_callbacks_(0), |
55 last_rec_callbacks_(0), | 57 last_rec_callbacks_(0), |
56 play_callbacks_(0), | 58 play_callbacks_(0), |
57 last_play_callbacks_(0), | 59 last_play_callbacks_(0), |
58 rec_samples_(0), | 60 rec_samples_(0), |
59 last_rec_samples_(0), | 61 last_rec_samples_(0), |
60 play_samples_(0), | 62 play_samples_(0), |
61 last_play_samples_(0), | 63 last_play_samples_(0), |
62 last_log_stat_time_(0) { | 64 last_log_stat_time_(0), |
65 max_rec_level_(0), | |
66 max_play_level_(0), | |
67 num_rec_level_is_zero_(0) { | |
63 LOG(INFO) << "AudioDeviceBuffer::ctor"; | 68 LOG(INFO) << "AudioDeviceBuffer::ctor"; |
64 // TODO(henrika): improve buffer handling and ensure that we don't allocate | 69 // TODO(henrika): improve buffer handling and ensure that we don't allocate |
65 // more than what is required. | 70 // more than what is required. |
66 play_buffer_.reset(new int8_t[kMaxBufferSizeBytes]); | 71 play_buffer_.reset(new int8_t[kMaxBufferSizeBytes]); |
67 rec_buffer_.reset(new int8_t[kMaxBufferSizeBytes]); | 72 rec_buffer_.reset(new int8_t[kMaxBufferSizeBytes]); |
68 } | 73 } |
69 | 74 |
70 AudioDeviceBuffer::~AudioDeviceBuffer() { | 75 AudioDeviceBuffer::~AudioDeviceBuffer() { |
71 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 76 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
72 LOG(INFO) << "AudioDeviceBuffer::~dtor"; | 77 LOG(INFO) << "AudioDeviceBuffer::~dtor"; |
73 | 78 |
74 size_t total_diff_time = 0; | 79 size_t total_diff_time = 0; |
75 int num_measurements = 0; | 80 int num_measurements = 0; |
76 LOG(INFO) << "[playout diff time => #measurements]"; | 81 LOG(INFO) << "[playout diff time => #measurements]"; |
77 for (size_t diff = 0; diff < arraysize(playout_diff_times_); ++diff) { | 82 for (size_t diff = 0; diff < arraysize(playout_diff_times_); ++diff) { |
78 uint32_t num_elements = playout_diff_times_[diff]; | 83 uint32_t num_elements = playout_diff_times_[diff]; |
79 if (num_elements > 0) { | 84 if (num_elements > 0) { |
80 total_diff_time += num_elements * diff; | 85 total_diff_time += num_elements * diff; |
81 num_measurements += num_elements; | 86 num_measurements += num_elements; |
82 LOG(INFO) << "[" << diff << " => " << num_elements << "]"; | 87 LOG(INFO) << "[" << diff << " => " << num_elements << "]"; |
83 } | 88 } |
84 } | 89 } |
85 if (num_measurements > 0) { | 90 if (num_measurements > 0) { |
86 LOG(INFO) << "total_diff_time: " << total_diff_time; | 91 LOG(INFO) << "total_diff_time: " << total_diff_time; |
87 LOG(INFO) << "num_measurements: " << num_measurements; | 92 LOG(INFO) << "num_measurements: " << num_measurements; |
88 LOG(INFO) << "average: " | 93 LOG(INFO) << "average: " |
89 << static_cast<float>(total_diff_time) / num_measurements; | 94 << static_cast<float>(total_diff_time) / num_measurements; |
90 } | 95 } |
96 | |
97 // Add UMA histogram to keep track of the case when only zeros have been | |
98 // recorded. Ensure that recording callbacks have started and that at least | |
99 // one timer event has been able to update |num_rec_level_is_zero_|. | |
100 // I am avoiding use of the task queue here since we are under destruction | |
101 // and reading these members on the creating thread feels safe. | |
102 if (rec_callbacks_ > 0 && num_stat_reports_ > 0) { | |
103 RTC_LOGGED_HISTOGRAM_BOOLEAN("WebRTC.Audio.RecordedOnlyZeros", | |
tommi
2016/10/24 12:19:15
since this is only logged in certain cases, there'
| |
104 static_cast<int>(num_stat_reports_ == num_rec_level_is_zero_)); | |
tommi
2016/10/24 12:19:15
fix indent
| |
105 } | |
91 } | 106 } |
92 | 107 |
93 int32_t AudioDeviceBuffer::RegisterAudioCallback( | 108 int32_t AudioDeviceBuffer::RegisterAudioCallback( |
94 AudioTransport* audio_callback) { | 109 AudioTransport* audio_callback) { |
95 LOG(INFO) << __FUNCTION__; | 110 LOG(INFO) << __FUNCTION__; |
96 rtc::CritScope lock(&_critSectCb); | 111 rtc::CritScope lock(&_critSectCb); |
97 audio_transport_cb_ = audio_callback; | 112 audio_transport_cb_ = audio_callback; |
98 return 0; | 113 return 0; |
99 } | 114 } |
100 | 115 |
101 int32_t AudioDeviceBuffer::InitPlayout() { | 116 int32_t AudioDeviceBuffer::InitPlayout() { |
102 LOG(INFO) << __FUNCTION__; | 117 LOG(INFO) << __FUNCTION__; |
103 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 118 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
104 last_playout_time_ = rtc::TimeMillis(); | 119 ResetPlayStats(); |
105 if (!timer_has_started_) { | 120 if (!timer_has_started_) { |
106 StartTimer(); | 121 StartTimer(); |
107 timer_has_started_ = true; | 122 timer_has_started_ = true; |
108 } | 123 } |
109 return 0; | 124 return 0; |
110 } | 125 } |
111 | 126 |
112 int32_t AudioDeviceBuffer::InitRecording() { | 127 int32_t AudioDeviceBuffer::InitRecording() { |
113 LOG(INFO) << __FUNCTION__; | 128 LOG(INFO) << __FUNCTION__; |
114 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 129 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
130 ResetRecStats(); | |
115 if (!timer_has_started_) { | 131 if (!timer_has_started_) { |
116 StartTimer(); | 132 StartTimer(); |
117 timer_has_started_ = true; | 133 timer_has_started_ = true; |
118 } | 134 } |
119 return 0; | 135 return 0; |
120 } | 136 } |
121 | 137 |
122 int32_t AudioDeviceBuffer::SetRecordingSampleRate(uint32_t fsHz) { | 138 int32_t AudioDeviceBuffer::SetRecordingSampleRate(uint32_t fsHz) { |
123 LOG(INFO) << "SetRecordingSampleRate(" << fsHz << ")"; | 139 LOG(INFO) << "SetRecordingSampleRate(" << fsHz << ")"; |
124 rtc::CritScope lock(&_critSect); | 140 rtc::CritScope lock(&_critSect); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 for (size_t i = 0; i < rec_samples_per_10ms_; i++) { | 275 for (size_t i = 0; i < rec_samples_per_10ms_; i++) { |
260 *ptr16Out = *ptr16In; | 276 *ptr16Out = *ptr16In; |
261 ptr16Out++; | 277 ptr16Out++; |
262 ptr16In++; | 278 ptr16In++; |
263 ptr16In++; | 279 ptr16In++; |
264 } | 280 } |
265 } | 281 } |
266 | 282 |
267 // Update some stats but do it on the task queue to ensure that the members | 283 // Update some stats but do it on the task queue to ensure that the members |
268 // are modified and read on the same thread. | 284 // are modified and read on the same thread. |
269 task_queue_.PostTask( | 285 task_queue_.PostTask(rtc::Bind(&AudioDeviceBuffer::UpdateRecStats, this, |
270 rtc::Bind(&AudioDeviceBuffer::UpdateRecStats, this, num_samples)); | 286 audio_buffer, num_samples)); |
tommi
2016/10/24 12:19:14
isn't this a bug? audio_buffer will for sure not
henrika_webrtc
2016/10/24 13:05:14
Correct. It has been fixed since this CL landed. I
| |
271 return 0; | 287 return 0; |
272 } | 288 } |
273 | 289 |
274 int32_t AudioDeviceBuffer::DeliverRecordedData() { | 290 int32_t AudioDeviceBuffer::DeliverRecordedData() { |
275 RTC_DCHECK(audio_transport_cb_); | 291 RTC_DCHECK(audio_transport_cb_); |
276 rtc::CritScope lock(&_critSectCb); | 292 rtc::CritScope lock(&_critSectCb); |
277 | 293 |
278 if (!audio_transport_cb_) { | 294 if (!audio_transport_cb_) { |
279 LOG(LS_WARNING) << "Invalid audio transport"; | 295 LOG(LS_WARNING) << "Invalid audio transport"; |
280 return 0; | 296 return 0; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 res = audio_transport_cb_->NeedMorePlayData( | 345 res = audio_transport_cb_->NeedMorePlayData( |
330 play_samples_per_10ms_, play_bytes_per_sample_, play_channels_, | 346 play_samples_per_10ms_, play_bytes_per_sample_, play_channels_, |
331 play_sample_rate_, &play_buffer_[0], num_samples_out, &elapsed_time_ms, | 347 play_sample_rate_, &play_buffer_[0], num_samples_out, &elapsed_time_ms, |
332 &ntp_time_ms); | 348 &ntp_time_ms); |
333 if (res != 0) { | 349 if (res != 0) { |
334 LOG(LS_ERROR) << "NeedMorePlayData() failed"; | 350 LOG(LS_ERROR) << "NeedMorePlayData() failed"; |
335 } | 351 } |
336 | 352 |
337 // Update some stats but do it on the task queue to ensure that access of | 353 // Update some stats but do it on the task queue to ensure that access of |
338 // members is serialized hence avoiding usage of locks. | 354 // members is serialized hence avoiding usage of locks. |
339 task_queue_.PostTask( | 355 task_queue_.PostTask(rtc::Bind(&AudioDeviceBuffer::UpdatePlayStats, this, |
340 rtc::Bind(&AudioDeviceBuffer::UpdatePlayStats, this, num_samples_out)); | 356 &play_buffer_[0], num_samples_out)); |
tommi
2016/10/24 12:19:15
this looks like a race. We're holding a lock here
henrika_webrtc
2016/10/24 13:05:14
Agree. Has been changed since this CL landed.
| |
341 return static_cast<int32_t>(num_samples_out); | 357 return static_cast<int32_t>(num_samples_out); |
342 } | 358 } |
343 | 359 |
344 int32_t AudioDeviceBuffer::GetPlayoutData(void* audio_buffer) { | 360 int32_t AudioDeviceBuffer::GetPlayoutData(void* audio_buffer) { |
345 rtc::CritScope lock(&_critSect); | 361 rtc::CritScope lock(&_critSect); |
346 memcpy(audio_buffer, &play_buffer_[0], play_bytes_per_10ms_); | 362 memcpy(audio_buffer, &play_buffer_[0], play_bytes_per_10ms_); |
347 return static_cast<int32_t>(play_samples_per_10ms_); | 363 return static_cast<int32_t>(play_samples_per_10ms_); |
348 } | 364 } |
349 | 365 |
350 void AudioDeviceBuffer::UpdatePlayoutParameters() { | 366 void AudioDeviceBuffer::UpdatePlayoutParameters() { |
351 RTC_CHECK(play_bytes_per_sample_); | 367 RTC_CHECK(play_bytes_per_sample_); |
352 rtc::CritScope lock(&_critSect); | 368 rtc::CritScope lock(&_critSect); |
353 // Update the required buffer size given sample rate and number of channels. | 369 // Update the required buffer size given sample rate and number of channels. |
354 play_samples_per_10ms_ = static_cast<size_t>(play_sample_rate_ * 10 / 1000); | 370 play_samples_per_10ms_ = static_cast<size_t>(play_sample_rate_ * 10 / 1000); |
355 play_bytes_per_10ms_ = play_bytes_per_sample_ * play_samples_per_10ms_; | 371 play_bytes_per_10ms_ = play_bytes_per_sample_ * play_samples_per_10ms_; |
356 RTC_DCHECK_LE(play_bytes_per_10ms_, kMaxBufferSizeBytes); | 372 RTC_DCHECK_LE(play_bytes_per_10ms_, kMaxBufferSizeBytes); |
357 } | 373 } |
358 | 374 |
359 void AudioDeviceBuffer::UpdateRecordingParameters() { | 375 void AudioDeviceBuffer::UpdateRecordingParameters() { |
360 RTC_CHECK(rec_bytes_per_sample_); | 376 RTC_CHECK(rec_bytes_per_sample_); |
361 rtc::CritScope lock(&_critSect); | 377 rtc::CritScope lock(&_critSect); |
362 // Update the required buffer size given sample rate and number of channels. | 378 // Update the required buffer size given sample rate and number of channels. |
363 rec_samples_per_10ms_ = static_cast<size_t>(rec_sample_rate_ * 10 / 1000); | 379 rec_samples_per_10ms_ = static_cast<size_t>(rec_sample_rate_ * 10 / 1000); |
364 rec_bytes_per_10ms_ = rec_bytes_per_sample_ * rec_samples_per_10ms_; | 380 rec_bytes_per_10ms_ = rec_bytes_per_sample_ * rec_samples_per_10ms_; |
365 RTC_DCHECK_LE(rec_bytes_per_10ms_, kMaxBufferSizeBytes); | 381 RTC_DCHECK_LE(rec_bytes_per_10ms_, kMaxBufferSizeBytes); |
366 } | 382 } |
367 | 383 |
368 void AudioDeviceBuffer::StartTimer() { | 384 void AudioDeviceBuffer::StartTimer() { |
385 num_stat_reports_ = 0; | |
369 last_log_stat_time_ = rtc::TimeMillis(); | 386 last_log_stat_time_ = rtc::TimeMillis(); |
370 task_queue_.PostDelayedTask(rtc::Bind(&AudioDeviceBuffer::LogStats, this), | 387 task_queue_.PostDelayedTask(rtc::Bind(&AudioDeviceBuffer::LogStats, this), |
371 kTimerIntervalInMilliseconds); | 388 kTimerIntervalInMilliseconds); |
372 } | 389 } |
373 | 390 |
374 void AudioDeviceBuffer::LogStats() { | 391 void AudioDeviceBuffer::LogStats() { |
375 RTC_DCHECK(task_queue_.IsCurrent()); | 392 RTC_DCHECK(task_queue_.IsCurrent()); |
376 | 393 |
377 int64_t now_time = rtc::TimeMillis(); | 394 int64_t now_time = rtc::TimeMillis(); |
378 int64_t next_callback_time = now_time + kTimerIntervalInMilliseconds; | 395 int64_t next_callback_time = now_time + kTimerIntervalInMilliseconds; |
379 int64_t time_since_last = rtc::TimeDiff(now_time, last_log_stat_time_); | 396 int64_t time_since_last = rtc::TimeDiff(now_time, last_log_stat_time_); |
380 last_log_stat_time_ = now_time; | 397 last_log_stat_time_ = now_time; |
381 | 398 |
382 // Log the latest statistics but skip the first 10 seconds since we are not | 399 // Log the latest statistics but skip the first 10 seconds since we are not |
383 // sure of the exact starting point. I.e., the first log printout will be | 400 // sure of the exact starting point. I.e., the first log printout will be |
384 // after ~20 seconds. | 401 // after ~20 seconds. |
385 if (++num_stat_reports_ > 1) { | 402 if (++num_stat_reports_ > 1) { |
386 uint32_t diff_samples = rec_samples_ - last_rec_samples_; | 403 uint32_t diff_samples = rec_samples_ - last_rec_samples_; |
387 uint32_t rate = diff_samples / kTimerIntervalInSeconds; | 404 uint32_t rate = diff_samples / kTimerIntervalInSeconds; |
388 LOG(INFO) << "[REC : " << time_since_last << "msec, " | 405 LOG(INFO) << "[REC : " << time_since_last << "msec, " |
389 << rec_sample_rate_ / 1000 | 406 << rec_sample_rate_ / 1000 |
390 << "kHz] callbacks: " << rec_callbacks_ - last_rec_callbacks_ | 407 << "kHz] callbacks: " << rec_callbacks_ - last_rec_callbacks_ |
391 << ", " | 408 << ", " |
392 << "samples: " << diff_samples << ", " | 409 << "samples: " << diff_samples << ", " |
393 << "rate: " << rate; | 410 << "rate: " << rate << ", " |
411 << "level: " << max_rec_level_; | |
394 | 412 |
395 diff_samples = play_samples_ - last_play_samples_; | 413 diff_samples = play_samples_ - last_play_samples_; |
396 rate = diff_samples / kTimerIntervalInSeconds; | 414 rate = diff_samples / kTimerIntervalInSeconds; |
397 LOG(INFO) << "[PLAY: " << time_since_last << "msec, " | 415 LOG(INFO) << "[PLAY: " << time_since_last << "msec, " |
398 << play_sample_rate_ / 1000 | 416 << play_sample_rate_ / 1000 |
399 << "kHz] callbacks: " << play_callbacks_ - last_play_callbacks_ | 417 << "kHz] callbacks: " << play_callbacks_ - last_play_callbacks_ |
400 << ", " | 418 << ", " |
401 << "samples: " << diff_samples << ", " | 419 << "samples: " << diff_samples << ", " |
402 << "rate: " << rate; | 420 << "rate: " << rate << ", " |
421 << "level: " << max_play_level_; | |
422 } | |
423 | |
424 // Count number of times we detect "no audio" corresponding to a case where | |
425 // all level measurements have been zero. | |
426 if (max_rec_level_ == 0) { | |
427 ++num_rec_level_is_zero_; | |
403 } | 428 } |
404 | 429 |
405 last_rec_callbacks_ = rec_callbacks_; | 430 last_rec_callbacks_ = rec_callbacks_; |
406 last_play_callbacks_ = play_callbacks_; | 431 last_play_callbacks_ = play_callbacks_; |
407 last_rec_samples_ = rec_samples_; | 432 last_rec_samples_ = rec_samples_; |
408 last_play_samples_ = play_samples_; | 433 last_play_samples_ = play_samples_; |
434 max_rec_level_ = 0; | |
435 max_play_level_ = 0; | |
409 | 436 |
410 int64_t time_to_wait_ms = next_callback_time - rtc::TimeMillis(); | 437 int64_t time_to_wait_ms = next_callback_time - rtc::TimeMillis(); |
411 RTC_DCHECK_GT(time_to_wait_ms, 0) << "Invalid timer interval"; | 438 RTC_DCHECK_GT(time_to_wait_ms, 0) << "Invalid timer interval"; |
412 | 439 |
413 // Update some stats but do it on the task queue to ensure that access of | 440 // Update some stats but do it on the task queue to ensure that access of |
414 // members is serialized hence avoiding usage of locks. | 441 // members is serialized hence avoiding usage of locks. |
415 task_queue_.PostDelayedTask(rtc::Bind(&AudioDeviceBuffer::LogStats, this), | 442 task_queue_.PostDelayedTask(rtc::Bind(&AudioDeviceBuffer::LogStats, this), |
416 time_to_wait_ms); | 443 time_to_wait_ms); |
417 } | 444 } |
418 | 445 |
419 void AudioDeviceBuffer::UpdateRecStats(size_t num_samples) { | 446 void AudioDeviceBuffer::ResetRecStats() { |
447 rec_callbacks_ = 0; | |
tommi
2016/10/24 12:19:15
what if any of these are not 0 already? Are we mi
| |
448 last_rec_callbacks_ = 0; | |
449 rec_samples_ = 0; | |
450 last_rec_samples_ = 0; | |
451 max_rec_level_ = 0; | |
452 num_rec_level_is_zero_ = 0; | |
453 } | |
454 | |
455 void AudioDeviceBuffer::ResetPlayStats() { | |
456 last_playout_time_ = rtc::TimeMillis(); | |
457 play_callbacks_ = 0; | |
458 last_play_callbacks_ = 0; | |
459 play_samples_ = 0; | |
460 last_play_samples_ = 0; | |
461 max_play_level_ = 0; | |
462 } | |
463 | |
464 void AudioDeviceBuffer::UpdateRecStats(const void* audio_buffer, | |
465 size_t num_samples) { | |
420 RTC_DCHECK(task_queue_.IsCurrent()); | 466 RTC_DCHECK(task_queue_.IsCurrent()); |
tommi
2016/10/24 12:19:14
see above. if this runs on the task queue, it look
henrika_webrtc
2016/10/24 13:05:14
Acknowledged.
| |
421 ++rec_callbacks_; | 467 ++rec_callbacks_; |
422 rec_samples_ += num_samples; | 468 rec_samples_ += num_samples; |
469 | |
470 // Find the max absolute value in an audio packet twice per second and update | |
471 // |max_rec_level_| to track the largest value. | |
472 if (rec_callbacks_ % 50 == 0) { | |
473 int16_t max_abs = WebRtcSpl_MaxAbsValueW16( | |
474 static_cast<int16_t*>(const_cast<void*>(audio_buffer)), | |
475 num_samples * rec_channels_); | |
476 if (max_abs > max_rec_level_) { | |
477 max_rec_level_ = max_abs; | |
478 } | |
479 } | |
423 } | 480 } |
424 | 481 |
425 void AudioDeviceBuffer::UpdatePlayStats(size_t num_samples) { | 482 void AudioDeviceBuffer::UpdatePlayStats(const void* audio_buffer, |
483 size_t num_samples) { | |
426 RTC_DCHECK(task_queue_.IsCurrent()); | 484 RTC_DCHECK(task_queue_.IsCurrent()); |
tommi
2016/10/24 12:19:14
same here
henrika_webrtc
2016/10/24 13:05:14
Acknowledged.
| |
427 ++play_callbacks_; | 485 ++play_callbacks_; |
428 play_samples_ += num_samples; | 486 play_samples_ += num_samples; |
487 | |
488 // Find the max absolute value in an audio packet twice per second and update | |
489 // |max_play_level_| to track the largest value. | |
490 if (play_callbacks_ % 50 == 0) { | |
491 int16_t max_abs = WebRtcSpl_MaxAbsValueW16( | |
492 static_cast<int16_t*>(const_cast<void*>(audio_buffer)), | |
493 num_samples * play_channels_); | |
494 if (max_abs > max_play_level_) { | |
495 max_play_level_ = max_abs; | |
496 } | |
497 } | |
429 } | 498 } |
430 | 499 |
431 } // namespace webrtc | 500 } // namespace webrtc |
OLD | NEW |