| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_renderer.h" | 5 #include "content/renderer/media/webrtc_audio_renderer.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "content/renderer/media/audio_device_factory.h" | 10 #include "content/renderer/media/audio_device_factory.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 } else if (sample_rate == 44100) { | 151 } else if (sample_rate == 44100) { |
| 152 // The resampler in WebRTC does not support 441 as input. We hard code | 152 // The resampler in WebRTC does not support 441 as input. We hard code |
| 153 // the size to 440 (~0.9977ms) instead and rely on the internal jitter | 153 // the size to 440 (~0.9977ms) instead and rely on the internal jitter |
| 154 // buffer in WebRTC to deal with the resulting drift. | 154 // buffer in WebRTC to deal with the resulting drift. |
| 155 // TODO(henrika): ensure that WebRTC supports 44100Hz and use 441 instead. | 155 // TODO(henrika): ensure that WebRTC supports 44100Hz and use 441 instead. |
| 156 buffer_size = 440; | 156 buffer_size = 440; |
| 157 } else { | 157 } else { |
| 158 return false; | 158 return false; |
| 159 } | 159 } |
| 160 | 160 |
| 161 int channels = ChannelLayoutToChannelCount(channel_layout); |
| 161 source_params.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 162 source_params.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 162 channel_layout, 0, sample_rate, 16, buffer_size); | 163 channel_layout, channels, 0, |
| 164 sample_rate, 16, buffer_size); |
| 163 | 165 |
| 164 // Set up audio parameters for the sink, i.e., the native audio output stream. | 166 // Set up audio parameters for the sink, i.e., the native audio output stream. |
| 165 // We strive to open up using native parameters to achieve best possible | 167 // We strive to open up using native parameters to achieve best possible |
| 166 // performance and to ensure that no FIFO is needed on the browser side to | 168 // performance and to ensure that no FIFO is needed on the browser side to |
| 167 // match the client request. Any mismatch between the source and the sink is | 169 // match the client request. Any mismatch between the source and the sink is |
| 168 // taken care of in this class instead using a pull FIFO. | 170 // taken care of in this class instead using a pull FIFO. |
| 169 | 171 |
| 170 media::AudioParameters sink_params; | 172 media::AudioParameters sink_params; |
| 171 | 173 |
| 172 buffer_size = hardware_config->GetOutputBufferSize(); | 174 buffer_size = hardware_config->GetOutputBufferSize(); |
| 173 sink_params.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 175 sink_params.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 174 channel_layout, 0, sample_rate, 16, buffer_size); | 176 channel_layout, channels, 0, sample_rate, 16, buffer_size); |
| 175 | 177 |
| 176 // Create a FIFO if re-buffering is required to match the source input with | 178 // Create a FIFO if re-buffering is required to match the source input with |
| 177 // the sink request. The source acts as provider here and the sink as | 179 // the sink request. The source acts as provider here and the sink as |
| 178 // consumer. | 180 // consumer. |
| 179 if (source_params.frames_per_buffer() != sink_params.frames_per_buffer()) { | 181 if (source_params.frames_per_buffer() != sink_params.frames_per_buffer()) { |
| 180 DVLOG(1) << "Rebuffering from " << source_params.frames_per_buffer() | 182 DVLOG(1) << "Rebuffering from " << source_params.frames_per_buffer() |
| 181 << " to " << sink_params.frames_per_buffer(); | 183 << " to " << sink_params.frames_per_buffer(); |
| 182 audio_fifo_.reset(new media::AudioPullFifo( | 184 audio_fifo_.reset(new media::AudioPullFifo( |
| 183 source_params.channels(), | 185 source_params.channels(), |
| 184 source_params.frames_per_buffer(), | 186 source_params.frames_per_buffer(), |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 } | 346 } |
| 345 | 347 |
| 346 // De-interleave each channel and convert to 32-bit floating-point | 348 // De-interleave each channel and convert to 32-bit floating-point |
| 347 // with nominal range -1.0 -> +1.0 to match the callback format. | 349 // with nominal range -1.0 -> +1.0 to match the callback format. |
| 348 audio_bus->FromInterleaved(buffer_.get(), | 350 audio_bus->FromInterleaved(buffer_.get(), |
| 349 audio_bus->frames(), | 351 audio_bus->frames(), |
| 350 sizeof(buffer_[0])); | 352 sizeof(buffer_[0])); |
| 351 } | 353 } |
| 352 | 354 |
| 353 } // namespace content | 355 } // namespace content |
| OLD | NEW |