| Index: media/base/audio_renderer_mixer.cc
|
| diff --git a/media/base/audio_renderer_mixer.cc b/media/base/audio_renderer_mixer.cc
|
| index 1ca2f39f7f58d8cff456ba3c7623a974a8da870d..503f139fdc52f1fd1179db5972e6ae799922c27e 100644
|
| --- a/media/base/audio_renderer_mixer.cc
|
| +++ b/media/base/audio_renderer_mixer.cc
|
| @@ -46,11 +46,6 @@ AudioRendererMixer::~AudioRendererMixer() {
|
| // AudioRendererSinks must be stopped before being destructed.
|
| audio_sink_->Stop();
|
|
|
| - // Clean up |mixer_input_audio_data_|.
|
| - for (size_t i = 0; i < mixer_input_audio_data_.size(); ++i)
|
| - base::AlignedFree(mixer_input_audio_data_[i]);
|
| - mixer_input_audio_data_.clear();
|
| -
|
| // Ensures that all mixer inputs have stopped themselves prior to destruction
|
| // and have called RemoveMixerInput().
|
| DCHECK_EQ(mixer_inputs_.size(), 0U);
|
| @@ -68,45 +63,40 @@ void AudioRendererMixer::RemoveMixerInput(
|
| mixer_inputs_.erase(input);
|
| }
|
|
|
| -int AudioRendererMixer::Render(const std::vector<float*>& audio_data,
|
| - int number_of_frames,
|
| +int AudioRendererMixer::Render(AudioBus* audio_bus,
|
| int audio_delay_milliseconds) {
|
| current_audio_delay_milliseconds_ = audio_delay_milliseconds;
|
|
|
| if (resampler_.get())
|
| - resampler_->Resample(audio_data, number_of_frames);
|
| + resampler_->Resample(audio_bus, audio_bus->frames());
|
| else
|
| - ProvideInput(audio_data, number_of_frames);
|
| + ProvideInput(audio_bus);
|
|
|
| // Always return the full number of frames requested, ProvideInput() will pad
|
| // with silence if it wasn't able to acquire enough data.
|
| - return number_of_frames;
|
| + return audio_bus->frames();
|
| }
|
|
|
| -void AudioRendererMixer::ProvideInput(const std::vector<float*>& audio_data,
|
| - int number_of_frames) {
|
| +void AudioRendererMixer::ProvideInput(AudioBus* audio_bus) {
|
| base::AutoLock auto_lock(mixer_inputs_lock_);
|
|
|
| // Allocate staging area for each mixer input's audio data on first call. We
|
| - // won't know how much to allocate until here because of resampling.
|
| - if (mixer_input_audio_data_.size() == 0) {
|
| - mixer_input_audio_data_.reserve(audio_data.size());
|
| - for (size_t i = 0; i < audio_data.size(); ++i) {
|
| - // Allocate audio data with a 16-byte alignment for SSE optimizations.
|
| - mixer_input_audio_data_.push_back(static_cast<float*>(
|
| - base::AlignedAlloc(sizeof(float) * number_of_frames, 16)));
|
| - }
|
| - mixer_input_audio_data_size_ = number_of_frames;
|
| + // won't know how much to allocate until here because of resampling. Ensure
|
| + // our intermediate AudioBus is sized exactly as the original. Resize should
|
| + // only happen once due to the way the resampler works.
|
| + if (!mixer_input_audio_bus_.get() ||
|
| + mixer_input_audio_bus_->frames() != audio_bus->frames()) {
|
| + mixer_input_audio_bus_ =
|
| + AudioBus::Create(audio_bus->channels(), audio_bus->frames());
|
| }
|
|
|
| // Sanity check our inputs.
|
| - DCHECK_LE(number_of_frames, mixer_input_audio_data_size_);
|
| - DCHECK_EQ(audio_data.size(), mixer_input_audio_data_.size());
|
| + DCHECK_EQ(audio_bus->frames(), mixer_input_audio_bus_->frames());
|
| + DCHECK_EQ(audio_bus->channels(), mixer_input_audio_bus_->channels());
|
|
|
| - // Zero |audio_data| so we're mixing into a clean buffer and return silence if
|
| + // Zero |audio_bus| so we're mixing into a clean buffer and return silence if
|
| // we couldn't get enough data from our inputs.
|
| - for (size_t i = 0; i < audio_data.size(); ++i)
|
| - memset(audio_data[i], 0, number_of_frames * sizeof(*audio_data[i]));
|
| + audio_bus->Zero();
|
|
|
| // Have each mixer render its data into an output buffer then mix the result.
|
| for (AudioRendererMixerInputSet::iterator it = mixer_inputs_.begin();
|
| @@ -121,15 +111,14 @@ void AudioRendererMixer::ProvideInput(const std::vector<float*>& audio_data,
|
| continue;
|
|
|
| int frames_filled = input->callback()->Render(
|
| - mixer_input_audio_data_, number_of_frames,
|
| - current_audio_delay_milliseconds_);
|
| + mixer_input_audio_bus_.get(), current_audio_delay_milliseconds_);
|
| if (frames_filled == 0)
|
| continue;
|
|
|
| - // Volume adjust and mix each mixer input into |audio_data| after rendering.
|
| - for (size_t j = 0; j < audio_data.size(); ++j) {
|
| - VectorFMAC(
|
| - mixer_input_audio_data_[j], volume, frames_filled, audio_data[j]);
|
| + // Volume adjust and mix each mixer input into |audio_bus| after rendering.
|
| + for (int i = 0; i < audio_bus->channels(); ++i) {
|
| + VectorFMAC(mixer_input_audio_bus_->channel(i), volume, frames_filled,
|
| + audio_bus->channel(i));
|
| }
|
|
|
| // No need to clamp values as InterleaveFloatToInt() will take care of this
|
|
|