summaryrefslogtreecommitdiff
path: root/media/base/audio_converter.cc
diff options
context:
space:
mode:
Diffstat (limited to 'media/base/audio_converter.cc')
-rw-r--r--media/base/audio_converter.cc49
1 files changed, 26 insertions, 23 deletions
diff --git a/media/base/audio_converter.cc b/media/base/audio_converter.cc
index d0c45136da..cdc6642b5f 100644
--- a/media/base/audio_converter.cc
+++ b/media/base/audio_converter.cc
@@ -25,7 +25,8 @@ namespace media {
AudioConverter::AudioConverter(const AudioParameters& input_params,
const AudioParameters& output_params,
bool disable_fifo)
- : downmix_early_(false),
+ : chunk_size_(output_params.frames_per_buffer()),
+ downmix_early_(false),
resampler_frame_delay_(0),
input_channel_count_(input_params.channels()) {
CHECK(input_params.IsValid());
@@ -41,16 +42,6 @@ AudioConverter::AudioConverter(const AudioParameters& input_params,
// Pare off data as early as we can for efficiency.
downmix_early_ = input_params.channels() > output_params.channels();
- if (downmix_early_) {
- DVLOG(1) << "Remixing channel layout prior to resampling.";
- // |unmixed_audio_| will be allocated on the fly.
- } else {
- // Instead, if we're not downmixing early we need a temporary AudioBus
- // which matches the input channel count but uses the output frame size
- // since we'll mix into the AudioBus from the output stream.
- unmixed_audio_ = AudioBus::Create(
- input_params.channels(), output_params.frames_per_buffer());
- }
}
// Only resample if necessary since it's expensive.
@@ -86,12 +77,11 @@ AudioConverter::AudioConverter(const AudioParameters& input_params,
if (input_params.frames_per_buffer() != output_params.frames_per_buffer()) {
DVLOG(1) << "Rebuffering from " << input_params.frames_per_buffer()
<< " to " << output_params.frames_per_buffer();
+ chunk_size_ = input_params.frames_per_buffer();
audio_fifo_.reset(new AudioPullFifo(
- downmix_early_ ? output_params.channels() :
- input_params.channels(),
- input_params.frames_per_buffer(), base::Bind(
- &AudioConverter::SourceCallback,
- base::Unretained(this))));
+ downmix_early_ ? output_params.channels() : input_params.channels(),
+ chunk_size_,
+ base::Bind(&AudioConverter::SourceCallback, base::Unretained(this))));
}
}
@@ -119,6 +109,12 @@ void AudioConverter::Reset() {
resampler_->Flush();
}
+int AudioConverter::ChunkSize() const {
+ if (!resampler_)
+ return chunk_size_;
+ return resampler_->ChunkSize();
+}
+
void AudioConverter::ConvertWithDelay(const base::TimeDelta& initial_delay,
AudioBus* dest) {
initial_delay_ = initial_delay;
@@ -133,6 +129,10 @@ void AudioConverter::ConvertWithDelay(const base::TimeDelta& initial_delay,
// resampling we can save a lot of processing time. Vice versa, we don't want
// to increase the channel count prior to resampling for the same reason.
bool needs_mixing = channel_mixer_ && !downmix_early_;
+
+ if (needs_mixing)
+ CreateUnmixedAudioIfNecessary(dest->frames());
+
AudioBus* temp_dest = needs_mixing ? unmixed_audio_.get() : dest;
DCHECK(temp_dest);
@@ -168,13 +168,11 @@ void AudioConverter::SourceCallback(int fifo_frame_delay, AudioBus* dest) {
AudioBus::Create(input_channel_count_, dest->frames());
}
- if (needs_downmix &&
- (!unmixed_audio_ || unmixed_audio_->frames() != dest->frames())) {
- // If we're downmixing early we need a temporary AudioBus which matches
- // the the input channel count and input frame size since we're passing
- // |unmixed_audio_| directly to the |source_callback_|.
- unmixed_audio_ = AudioBus::Create(input_channel_count_, dest->frames());
- }
+ // If we're downmixing early we need a temporary AudioBus which matches
+ // the the input channel count and input frame size since we're passing
+ // |unmixed_audio_| directly to the |source_callback_|.
+ if (needs_downmix)
+ CreateUnmixedAudioIfNecessary(dest->frames());
AudioBus* temp_dest = needs_downmix ? unmixed_audio_.get() : dest;
@@ -243,4 +241,9 @@ void AudioConverter::ProvideInput(int resampler_frame_delay, AudioBus* dest) {
SourceCallback(0, dest);
}
+void AudioConverter::CreateUnmixedAudioIfNecessary(int frames) {
+ if (!unmixed_audio_ || unmixed_audio_->frames() != frames)
+ unmixed_audio_ = AudioBus::Create(input_channel_count_, frames);
+}
+
} // namespace media