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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 DCHECK_EQ(audio_bus->frames() % frames_per_10_ms, 0); | 143 DCHECK_EQ(audio_bus->frames() % frames_per_10_ms, 0); |
144 | 144 |
145 // Get audio frames in blocks of 10 milliseconds from the registered | 145 // Get audio frames in blocks of 10 milliseconds from the registered |
146 // webrtc::AudioTransport source. Keep reading until our internal buffer | 146 // webrtc::AudioTransport source. Keep reading until our internal buffer |
147 // is full. | 147 // is full. |
148 uint32_t num_audio_frames = 0; | 148 uint32_t num_audio_frames = 0; |
149 int accumulated_audio_frames = 0; | 149 int accumulated_audio_frames = 0; |
150 int16* audio_data = &render_buffer_[0]; | 150 int16* audio_data = &render_buffer_[0]; |
151 while (accumulated_audio_frames < audio_bus->frames()) { | 151 while (accumulated_audio_frames < audio_bus->frames()) { |
152 // Get 10ms and append output to temporary byte buffer. | 152 // Get 10ms and append output to temporary byte buffer. |
153 uint32_t rtp_ts = 0; | 153 int64_t elapsed_time_ms = -1; |
154 int64_t ntp_ts = 0; | 154 int64_t ntp_time_ms = -1; |
155 if (is_audio_track_processing_enabled_) { | 155 if (is_audio_track_processing_enabled_) { |
156 // When audio processing is enabled in the audio track, we use | 156 // When audio processing is enabled in the audio track, we use |
157 // PullRenderData() instead of NeedMorePlayData() to avoid passing the | 157 // PullRenderData() instead of NeedMorePlayData() to avoid passing the |
158 // render data to the APM in WebRTC as reference signal for echo | 158 // render data to the APM in WebRTC as reference signal for echo |
159 // cancellation. | 159 // cancellation. |
160 static const int kBitsPerByte = 8; | 160 static const int kBitsPerByte = 8; |
161 audio_transport_callback_->PullRenderData(bytes_per_sample * kBitsPerByte, | 161 audio_transport_callback_->PullRenderData(bytes_per_sample * kBitsPerByte, |
162 sample_rate, | 162 sample_rate, |
163 audio_bus->channels(), | 163 audio_bus->channels(), |
164 frames_per_10_ms, | 164 frames_per_10_ms, |
165 audio_data, | 165 audio_data, |
166 &rtp_ts, | 166 &elapsed_time_ms, |
167 &ntp_ts); | 167 &ntp_time_ms); |
168 accumulated_audio_frames += frames_per_10_ms; | 168 accumulated_audio_frames += frames_per_10_ms; |
169 } else { | 169 } else { |
170 // TODO(xians): Remove the following code after the APM in WebRTC is | 170 // TODO(xians): Remove the following code after the APM in WebRTC is |
171 // deprecated. | 171 // deprecated. |
172 audio_transport_callback_->NeedMorePlayData(frames_per_10_ms, | 172 audio_transport_callback_->NeedMorePlayData(frames_per_10_ms, |
173 bytes_per_sample, | 173 bytes_per_sample, |
174 audio_bus->channels(), | 174 audio_bus->channels(), |
175 sample_rate, | 175 sample_rate, |
176 audio_data, | 176 audio_data, |
177 num_audio_frames, | 177 num_audio_frames, |
178 &rtp_ts, | 178 &elapsed_time_ms, |
179 &ntp_ts); | 179 &ntp_time_ms); |
180 accumulated_audio_frames += num_audio_frames; | 180 accumulated_audio_frames += num_audio_frames; |
181 } | 181 } |
182 | 182 |
183 audio_data += bytes_per_10_ms; | 183 audio_data += bytes_per_10_ms; |
184 } | 184 } |
185 | 185 |
186 // De-interleave each channel and convert to 32-bit floating-point | 186 // De-interleave each channel and convert to 32-bit floating-point |
187 // with nominal range -1.0 -> +1.0 to match the callback format. | 187 // with nominal range -1.0 -> +1.0 to match the callback format. |
188 audio_bus->FromInterleaved(&render_buffer_[0], | 188 audio_bus->FromInterleaved(&render_buffer_[0], |
189 audio_bus->frames(), | 189 audio_bus->frames(), |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 | 559 |
560 // Start the Aec dump on the current default capturer. | 560 // Start the Aec dump on the current default capturer. |
561 scoped_refptr<WebRtcAudioCapturer> default_capturer(GetDefaultCapturer()); | 561 scoped_refptr<WebRtcAudioCapturer> default_capturer(GetDefaultCapturer()); |
562 if (!default_capturer) | 562 if (!default_capturer) |
563 return; | 563 return; |
564 | 564 |
565 default_capturer->StartAecDump(aec_dump_file_.Pass()); | 565 default_capturer->StartAecDump(aec_dump_file_.Pass()); |
566 } | 566 } |
567 | 567 |
568 } // namespace content | 568 } // namespace content |
OLD | NEW |