OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "media/base/audio_buffer_converter.h" | 5 #include "media/base/audio_buffer_converter.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "media/base/audio_buffer.h" | 10 #include "media/base/audio_buffer.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 const scoped_refptr<AudioBuffer>& buffer) { | 138 const scoped_refptr<AudioBuffer>& buffer) { |
139 Flush(); | 139 Flush(); |
140 audio_converter_.reset(); | 140 audio_converter_.reset(); |
141 input_params_.Reset( | 141 input_params_.Reset( |
142 input_params_.format(), | 142 input_params_.format(), |
143 buffer->channel_layout(), | 143 buffer->channel_layout(), |
144 buffer->channel_count(), | 144 buffer->channel_count(), |
145 0, | 145 0, |
146 buffer->sample_rate(), | 146 buffer->sample_rate(), |
147 input_params_.bits_per_sample(), | 147 input_params_.bits_per_sample(), |
148 // This is arbitrary, but small buffer sizes result in a lot of tiny | 148 // If resampling is needed and the FIFO disabled, the AudioConverter will |
149 // ProvideInput calls, so we'll use at least the SincResampler's default | 149 // always request SincResampler::kDefaultRequestSize frames. Otherwise it |
150 // request size. | 150 // will use the output frame size. |
151 std::max(buffer->frame_count(), | 151 buffer->sample_rate() == output_params_.sample_rate() |
152 static_cast<int>(SincResampler::kDefaultRequestSize))); | 152 ? output_params_.frames_per_buffer() |
| 153 : SincResampler::kDefaultRequestSize); |
153 | 154 |
154 io_sample_rate_ratio_ = static_cast<double>(input_params_.sample_rate()) / | 155 io_sample_rate_ratio_ = static_cast<double>(input_params_.sample_rate()) / |
155 output_params_.sample_rate(); | 156 output_params_.sample_rate(); |
156 | 157 |
157 // If |buffer| matches |output_params_| we don't need an AudioConverter at | 158 // If |buffer| matches |output_params_| we don't need an AudioConverter at |
158 // all, and can early-out here. | 159 // all, and can early-out here. |
159 if (!IsConfigChange(output_params_, buffer)) | 160 if (!IsConfigChange(output_params_, buffer)) |
160 return; | 161 return; |
161 | 162 |
| 163 // Note: The FIFO is disabled to avoid extraneous memcpy(). |
162 audio_converter_.reset( | 164 audio_converter_.reset( |
163 new AudioConverter(input_params_, output_params_, true)); | 165 new AudioConverter(input_params_, output_params_, true)); |
164 audio_converter_->AddInput(this); | 166 audio_converter_->AddInput(this); |
165 } | 167 } |
166 | 168 |
167 void AudioBufferConverter::ConvertIfPossible() { | 169 void AudioBufferConverter::ConvertIfPossible() { |
168 DCHECK(audio_converter_); | 170 DCHECK(audio_converter_); |
169 | 171 |
170 int request_frames = 0; | 172 int request_frames = 0; |
171 | 173 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 is_flushing_ = false; | 242 is_flushing_ = false; |
241 audio_converter_->Reset(); | 243 audio_converter_->Reset(); |
242 DCHECK_EQ(input_frames_, 0); | 244 DCHECK_EQ(input_frames_, 0); |
243 DCHECK_EQ(last_input_buffer_offset_, 0); | 245 DCHECK_EQ(last_input_buffer_offset_, 0); |
244 DCHECK_LT(buffered_input_frames_, 1.0); | 246 DCHECK_LT(buffered_input_frames_, 1.0); |
245 DCHECK(queued_inputs_.empty()); | 247 DCHECK(queued_inputs_.empty()); |
246 buffered_input_frames_ = 0.0; | 248 buffered_input_frames_ = 0.0; |
247 } | 249 } |
248 | 250 |
249 } // namespace media | 251 } // namespace media |
OLD | NEW |