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/base/audio_converter.h" | 5 #include "media/base/audio_converter.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 Reset(); | 104 Reset(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void AudioConverter::Reset() { | 107 void AudioConverter::Reset() { |
| 108 if (audio_fifo_) | 108 if (audio_fifo_) |
| 109 audio_fifo_->Clear(); | 109 audio_fifo_->Clear(); |
| 110 if (resampler_) | 110 if (resampler_) |
| 111 resampler_->Flush(); | 111 resampler_->Flush(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void AudioConverter::Convert(AudioBus* dest) { | 114 void AudioConverter::ConvertWithDelay(base::TimeDelta initial_delay, |
|
no longer working on chromium
2013/04/30 08:42:23
nit, const base::TimeDelta& ?
| |
| 115 AudioBus* dest) { | |
| 116 initial_delay_ = initial_delay; | |
| 117 | |
| 115 if (transform_inputs_.empty()) { | 118 if (transform_inputs_.empty()) { |
| 116 dest->Zero(); | 119 dest->Zero(); |
| 117 return; | 120 return; |
| 118 } | 121 } |
| 119 | 122 |
| 120 bool needs_mixing = channel_mixer_ && !downmix_early_; | 123 bool needs_mixing = channel_mixer_ && !downmix_early_; |
| 121 AudioBus* temp_dest = needs_mixing ? unmixed_audio_.get() : dest; | 124 AudioBus* temp_dest = needs_mixing ? unmixed_audio_.get() : dest; |
| 122 DCHECK(temp_dest); | 125 DCHECK(temp_dest); |
| 123 | 126 |
| 124 if (!resampler_ && !audio_fifo_) { | 127 if (!resampler_ && !audio_fifo_) { |
| 125 SourceCallback(0, temp_dest); | 128 SourceCallback(0, temp_dest); |
| 126 } else { | 129 } else { |
| 127 if (resampler_) | 130 if (resampler_) |
| 128 resampler_->Resample(temp_dest, temp_dest->frames()); | 131 resampler_->Resample(temp_dest, temp_dest->frames()); |
| 129 else | 132 else |
| 130 ProvideInput(0, temp_dest); | 133 ProvideInput(0, temp_dest); |
| 131 } | 134 } |
| 132 | 135 |
| 133 if (needs_mixing) { | 136 if (needs_mixing) { |
| 134 DCHECK_EQ(temp_dest->frames(), dest->frames()); | 137 DCHECK_EQ(temp_dest->frames(), dest->frames()); |
| 135 channel_mixer_->Transform(temp_dest, dest); | 138 channel_mixer_->Transform(temp_dest, dest); |
| 136 } | 139 } |
| 137 } | 140 } |
| 138 | 141 |
| 142 void AudioConverter::Convert(AudioBus* dest) { | |
| 143 ConvertWithDelay(base::TimeDelta::FromMilliseconds(0), dest); | |
| 144 } | |
| 145 | |
| 139 void AudioConverter::SourceCallback(int fifo_frame_delay, AudioBus* dest) { | 146 void AudioConverter::SourceCallback(int fifo_frame_delay, AudioBus* dest) { |
| 140 bool needs_downmix = channel_mixer_ && downmix_early_; | 147 bool needs_downmix = channel_mixer_ && downmix_early_; |
| 141 | 148 |
| 142 if (!mixer_input_audio_bus_ || | 149 if (!mixer_input_audio_bus_ || |
| 143 mixer_input_audio_bus_->frames() != dest->frames()) { | 150 mixer_input_audio_bus_->frames() != dest->frames()) { |
| 144 mixer_input_audio_bus_ = | 151 mixer_input_audio_bus_ = |
| 145 AudioBus::Create(input_channel_count_, dest->frames()); | 152 AudioBus::Create(input_channel_count_, dest->frames()); |
| 146 } | 153 } |
| 147 | 154 |
| 148 if (needs_downmix && | 155 if (needs_downmix && |
| 149 (!unmixed_audio_ || unmixed_audio_->frames() != dest->frames())) { | 156 (!unmixed_audio_ || unmixed_audio_->frames() != dest->frames())) { |
| 150 // If we're downmixing early we need a temporary AudioBus which matches | 157 // If we're downmixing early we need a temporary AudioBus which matches |
| 151 // the the input channel count and input frame size since we're passing | 158 // the the input channel count and input frame size since we're passing |
| 152 // |unmixed_audio_| directly to the |source_callback_|. | 159 // |unmixed_audio_| directly to the |source_callback_|. |
| 153 unmixed_audio_ = AudioBus::Create(input_channel_count_, dest->frames()); | 160 unmixed_audio_ = AudioBus::Create(input_channel_count_, dest->frames()); |
| 154 } | 161 } |
| 155 | 162 |
| 156 AudioBus* temp_dest = needs_downmix ? unmixed_audio_.get() : dest; | 163 AudioBus* temp_dest = needs_downmix ? unmixed_audio_.get() : dest; |
| 157 | 164 |
| 158 // Sanity check our inputs. | 165 // Sanity check our inputs. |
| 159 DCHECK_EQ(temp_dest->frames(), mixer_input_audio_bus_->frames()); | 166 DCHECK_EQ(temp_dest->frames(), mixer_input_audio_bus_->frames()); |
| 160 DCHECK_EQ(temp_dest->channels(), mixer_input_audio_bus_->channels()); | 167 DCHECK_EQ(temp_dest->channels(), mixer_input_audio_bus_->channels()); |
| 161 | 168 |
| 162 // Calculate the buffer delay for this callback. | 169 // Calculate the buffer delay for this callback. |
| 163 base::TimeDelta buffer_delay; | 170 base::TimeDelta buffer_delay = initial_delay_; |
| 164 if (resampler_) { | 171 if (resampler_) { |
| 165 buffer_delay += base::TimeDelta::FromMicroseconds( | 172 buffer_delay += base::TimeDelta::FromMicroseconds( |
| 166 resampler_frame_delay_ * output_frame_duration_.InMicroseconds()); | 173 resampler_frame_delay_ * output_frame_duration_.InMicroseconds()); |
| 167 } | 174 } |
| 168 if (audio_fifo_) { | 175 if (audio_fifo_) { |
| 169 buffer_delay += base::TimeDelta::FromMicroseconds( | 176 buffer_delay += base::TimeDelta::FromMicroseconds( |
| 170 fifo_frame_delay * input_frame_duration_.InMicroseconds()); | 177 fifo_frame_delay * input_frame_duration_.InMicroseconds()); |
| 171 } | 178 } |
| 172 | 179 |
| 173 // Have each mixer render its data into an output buffer then mix the result. | 180 // Have each mixer render its data into an output buffer then mix the result. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 | 221 |
| 215 void AudioConverter::ProvideInput(int resampler_frame_delay, AudioBus* dest) { | 222 void AudioConverter::ProvideInput(int resampler_frame_delay, AudioBus* dest) { |
| 216 resampler_frame_delay_ = resampler_frame_delay; | 223 resampler_frame_delay_ = resampler_frame_delay; |
| 217 if (audio_fifo_) | 224 if (audio_fifo_) |
| 218 audio_fifo_->Consume(dest, dest->frames()); | 225 audio_fifo_->Consume(dest, dest->frames()); |
| 219 else | 226 else |
| 220 SourceCallback(0, dest); | 227 SourceCallback(0, dest); |
| 221 } | 228 } |
| 222 | 229 |
| 223 } // namespace media | 230 } // namespace media |
| OLD | NEW |