OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/media/webrtc_audio_device_impl.h" | 5 #include "content/renderer/media/webrtc_audio_device_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/win/windows_version.h" | 10 #include "base/win/windows_version.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } | 74 } |
75 | 75 |
76 // Write audio samples in blocks of 10 milliseconds to the registered | 76 // Write audio samples in blocks of 10 milliseconds to the registered |
77 // webrtc::AudioTransport sink. Keep writing until our internal byte | 77 // webrtc::AudioTransport sink. Keep writing until our internal byte |
78 // buffer is empty. | 78 // buffer is empty. |
79 const int16* audio_buffer = audio_data; | 79 const int16* audio_buffer = audio_data; |
80 const int samples_per_10_msec = (sample_rate / 100); | 80 const int samples_per_10_msec = (sample_rate / 100); |
81 CHECK_EQ(number_of_frames % samples_per_10_msec, 0); | 81 CHECK_EQ(number_of_frames % samples_per_10_msec, 0); |
82 int accumulated_audio_samples = 0; | 82 int accumulated_audio_samples = 0; |
83 uint32_t new_volume = 0; | 83 uint32_t new_volume = 0; |
| 84 |
| 85 // The lock here is to protect the racing in the resampler inside webrtc when |
| 86 // there are more than one input stream calling OnData(), which can happen |
| 87 // when the users setup two getUserMedia, one for the microphone, another |
| 88 // for WebAudio. Currently we don't have a better way to fix it except for |
| 89 // adding a lock here to sequence the call. |
| 90 // TODO(xians): Remove this workaround after we move the |
| 91 // webrtc::AudioProcessing module to Chrome. See http://crbug/264611 for |
| 92 // details. |
| 93 base::AutoLock auto_lock(capture_callback_lock_); |
84 while (accumulated_audio_samples < number_of_frames) { | 94 while (accumulated_audio_samples < number_of_frames) { |
85 // Deliver 10ms of recorded 16-bit linear PCM audio. | 95 // Deliver 10ms of recorded 16-bit linear PCM audio. |
86 int new_mic_level = audio_transport_callback_->OnDataAvailable( | 96 int new_mic_level = audio_transport_callback_->OnDataAvailable( |
87 &channels[0], | 97 &channels[0], |
88 channels.size(), | 98 channels.size(), |
89 audio_buffer, | 99 audio_buffer, |
90 sample_rate, | 100 sample_rate, |
91 number_of_channels, | 101 number_of_channels, |
92 samples_per_10_msec, | 102 samples_per_10_msec, |
93 total_delay_ms, | 103 total_delay_ms, |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 for (CapturerList::const_iterator iter = capturers_.begin(); | 450 for (CapturerList::const_iterator iter = capturers_.begin(); |
441 iter != capturers_.end(); ++iter) { | 451 iter != capturers_.end(); ++iter) { |
442 if (!(*iter)->device_id().empty()) | 452 if (!(*iter)->device_id().empty()) |
443 return *iter; | 453 return *iter; |
444 } | 454 } |
445 | 455 |
446 return NULL; | 456 return NULL; |
447 } | 457 } |
448 | 458 |
449 } // namespace content | 459 } // namespace content |
OLD | NEW |