Chromium Code Reviews| 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 "media/audio/audio_output_resampler.h" | 5 #include "media/audio/audio_output_resampler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 } | 192 } |
| 193 | 193 |
| 194 Initialize(); | 194 Initialize(); |
| 195 } | 195 } |
| 196 | 196 |
| 197 AudioOutputResampler::~AudioOutputResampler() {} | 197 AudioOutputResampler::~AudioOutputResampler() {} |
| 198 | 198 |
| 199 void AudioOutputResampler::Initialize() { | 199 void AudioOutputResampler::Initialize() { |
| 200 io_ratio_ = 1; | 200 io_ratio_ = 1; |
| 201 | 201 |
| 202 double in_buffer_s = static_cast<double>(params_.frames_per_buffer()) / | |
| 203 static_cast<double>(params_.sample_rate()); | |
| 204 double out_buffer_s = | |
| 205 static_cast<double>(output_params_.frames_per_buffer()) / | |
| 206 static_cast<double>(output_params_.sample_rate()); | |
| 207 if (in_buffer_s != out_buffer_s) { | |
| 208 int out_buffer_size = static_cast<int>( | |
| 209 in_buffer_s * output_params_.sample_rate() + 0.5); | |
| 210 output_params_.Reset(output_params_.format(), | |
| 211 output_params_.channel_layout(), | |
| 212 output_params_.sample_rate(), | |
| 213 output_params_.bits_per_sample(), | |
| 214 out_buffer_size); | |
| 215 } | |
|
Chris Rogers
2012/09/18 17:36:29
Why do we need special logic here when we have Aud
| |
| 202 // TODO(dalecurtis): Add channel remixing. http://crbug.com/138762 | 216 // TODO(dalecurtis): Add channel remixing. http://crbug.com/138762 |
| 203 DCHECK_EQ(params_.channels(), output_params_.channels()); | 217 DCHECK_EQ(params_.channels(), output_params_.channels()); |
| 204 // Only resample or rebuffer if the input parameters don't match the output | 218 // Only resample or rebuffer if the input parameters don't match the output |
| 205 // parameters to avoid any unnecessary work. | 219 // parameters to avoid any unnecessary work. |
| 206 if (params_.channels() != output_params_.channels() || | 220 if (params_.channels() != output_params_.channels() || |
| 207 params_.sample_rate() != output_params_.sample_rate() || | 221 params_.sample_rate() != output_params_.sample_rate() || |
| 208 params_.bits_per_sample() != output_params_.bits_per_sample() || | 222 params_.bits_per_sample() != output_params_.bits_per_sample() || |
| 209 params_.frames_per_buffer() != output_params_.frames_per_buffer()) { | 223 params_.frames_per_buffer() != output_params_.frames_per_buffer()) { |
| 210 if (params_.sample_rate() != output_params_.sample_rate()) { | 224 if (params_.sample_rate() != output_params_.sample_rate()) { |
| 211 double io_sample_rate_ratio = params_.sample_rate() / | 225 double io_sample_rate_ratio = params_.sample_rate() / |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 source_callback_->OnError(stream, code); | 462 source_callback_->OnError(stream, code); |
| 449 } | 463 } |
| 450 | 464 |
| 451 void OnMoreDataResampler::WaitTillDataReady() { | 465 void OnMoreDataResampler::WaitTillDataReady() { |
| 452 base::AutoLock auto_lock(source_lock_); | 466 base::AutoLock auto_lock(source_lock_); |
| 453 if (source_callback_ && !outstanding_audio_bytes_) | 467 if (source_callback_ && !outstanding_audio_bytes_) |
| 454 source_callback_->WaitTillDataReady(); | 468 source_callback_->WaitTillDataReady(); |
| 455 } | 469 } |
| 456 | 470 |
| 457 } // namespace media | 471 } // namespace media |
| OLD | NEW |