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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 Initialize(); | 96 Initialize(); |
97 // Record UMA statistics for the hardware configuration. | 97 // Record UMA statistics for the hardware configuration. |
98 RecordStats(output_params_); | 98 RecordStats(output_params_); |
99 } | 99 } |
100 | 100 |
101 AudioOutputResampler::~AudioOutputResampler() {} | 101 AudioOutputResampler::~AudioOutputResampler() {} |
102 | 102 |
103 void AudioOutputResampler::Initialize() { | 103 void AudioOutputResampler::Initialize() { |
104 io_ratio_ = 1; | 104 io_ratio_ = 1; |
105 | 105 |
106 if (params_.frames_per_buffer() != output_params_.frames_per_buffer()) { | |
DaleCurtis
2012/09/17 23:54:45
I don't understand what you're trying to do here.
no longer working on chromium
2012/09/18 09:37:30
The idea is simple. Basically, we should allow the
| |
107 double in_buffer_s = static_cast<double>(params_.frames_per_buffer()) / | |
108 static_cast<double>(params_.sample_rate()); | |
109 double out_buffer_s = | |
110 static_cast<double>(output_params_.frames_per_buffer()) / | |
111 static_cast<double>(output_params_.sample_rate()); | |
112 if (in_buffer_s != out_buffer_s) { | |
113 int out_buffer_size = in_buffer_s * output_params_.sample_rate(); | |
no longer working on chromium
2012/09/17 21:56:28
I will add + 0.5 to do the correct truncation here
| |
114 output_params_.Reset(output_params_.format(), | |
115 output_params_.channel_layout(), | |
116 output_params_.sample_rate(), | |
117 output_params_.bits_per_sample(), | |
118 out_buffer_size); | |
119 } | |
120 } | |
121 | |
106 // TODO(dalecurtis): Add channel remixing. http://crbug.com/138762 | 122 // TODO(dalecurtis): Add channel remixing. http://crbug.com/138762 |
107 DCHECK_EQ(params_.channels(), output_params_.channels()); | 123 DCHECK_EQ(params_.channels(), output_params_.channels()); |
108 // Only resample or rebuffer if the input parameters don't match the output | 124 // Only resample or rebuffer if the input parameters don't match the output |
109 // parameters to avoid any unnecessary work. | 125 // parameters to avoid any unnecessary work. |
110 if (params_.channels() != output_params_.channels() || | 126 if (params_.channels() != output_params_.channels() || |
111 params_.sample_rate() != output_params_.sample_rate() || | 127 params_.sample_rate() != output_params_.sample_rate() || |
112 params_.bits_per_sample() != output_params_.bits_per_sample() || | 128 params_.bits_per_sample() != output_params_.bits_per_sample()) { |
113 params_.frames_per_buffer() != output_params_.frames_per_buffer()) { | |
114 // Only resample if necessary since it's expensive. | 129 // Only resample if necessary since it's expensive. |
115 if (params_.sample_rate() != output_params_.sample_rate()) { | 130 if (params_.sample_rate() != output_params_.sample_rate()) { |
116 DVLOG(1) << "Resampling from " << params_.sample_rate() << " to " | 131 DVLOG(1) << "Resampling from " << params_.sample_rate() << " to " |
117 << output_params_.sample_rate(); | 132 << output_params_.sample_rate(); |
118 double io_sample_rate_ratio = params_.sample_rate() / | 133 double io_sample_rate_ratio = params_.sample_rate() / |
119 static_cast<double>(output_params_.sample_rate()); | 134 static_cast<double>(output_params_.sample_rate()); |
120 // Include the I/O resampling ratio in our global I/O ratio. | 135 // Include the I/O resampling ratio in our global I/O ratio. |
121 io_ratio_ *= io_sample_rate_ratio; | 136 io_ratio_ *= io_sample_rate_ratio; |
122 resampler_.reset(new MultiChannelResampler( | 137 resampler_.reset(new MultiChannelResampler( |
123 output_params_.channels(), io_sample_rate_ratio, base::Bind( | 138 output_params_.channels(), io_sample_rate_ratio, base::Bind( |
124 &AudioOutputResampler::ProvideInput, base::Unretained(this)))); | 139 &AudioOutputResampler::ProvideInput, base::Unretained(this)))); |
125 } | 140 } |
126 | 141 |
127 // Include bits per channel differences. | 142 // Include bits per channel differences. |
128 io_ratio_ *= static_cast<double>(params_.bits_per_sample()) / | 143 io_ratio_ *= static_cast<double>(params_.bits_per_sample()) / |
129 output_params_.bits_per_sample(); | 144 output_params_.bits_per_sample(); |
130 | 145 |
131 // Include channel count differences. | 146 // Include channel count differences. |
132 io_ratio_ *= static_cast<double>(params_.channels()) / | 147 io_ratio_ *= static_cast<double>(params_.channels()) / |
133 output_params_.channels(); | 148 output_params_.channels(); |
134 | 149 |
135 // Since the resampler / output device may want a different buffer size than | 150 // Since the resampler / output device may want a different buffer size than |
136 // the caller asked for, we need to use a FIFO to ensure that both sides | 151 // the caller asked for, we need to use a FIFO to ensure that both sides |
137 // read in chunk sizes they're configured for. | 152 // read in chunk sizes they're configured for. |
138 if (params_.sample_rate() != output_params_.sample_rate() || | 153 if (params_.sample_rate() != output_params_.sample_rate()) { |
139 params_.frames_per_buffer() != output_params_.frames_per_buffer()) { | |
140 DVLOG(1) << "Rebuffering from " << params_.frames_per_buffer() | 154 DVLOG(1) << "Rebuffering from " << params_.frames_per_buffer() |
141 << " to " << output_params_.frames_per_buffer(); | 155 << " to " << output_params_.frames_per_buffer(); |
142 audio_fifo_.reset(new AudioPullFifo( | 156 audio_fifo_.reset(new AudioPullFifo( |
143 params_.channels(), params_.frames_per_buffer(), base::Bind( | 157 params_.channels(), params_.frames_per_buffer(), base::Bind( |
144 &AudioOutputResampler::SourceCallback_Locked, | 158 &AudioOutputResampler::SourceCallback_Locked, |
145 base::Unretained(this)))); | 159 base::Unretained(this)))); |
146 } | 160 } |
147 | 161 |
148 DVLOG(1) << "I/O ratio is " << io_ratio_; | 162 DVLOG(1) << "I/O ratio is " << io_ratio_; |
149 } else { | 163 } else { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 source_callback_->OnError(stream, code); | 330 source_callback_->OnError(stream, code); |
317 } | 331 } |
318 | 332 |
319 void AudioOutputResampler::WaitTillDataReady() { | 333 void AudioOutputResampler::WaitTillDataReady() { |
320 base::AutoLock auto_lock(source_lock_); | 334 base::AutoLock auto_lock(source_lock_); |
321 if (source_callback_ && !outstanding_audio_bytes_) | 335 if (source_callback_ && !outstanding_audio_bytes_) |
322 source_callback_->WaitTillDataReady(); | 336 source_callback_->WaitTillDataReady(); |
323 } | 337 } |
324 | 338 |
325 } // namespace media | 339 } // namespace media |
OLD | NEW |