| 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 #ifndef MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ | 5 #ifndef MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ |
| 6 #define MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ | 6 #define MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | |
| 11 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 12 #include "media/base/audio_renderer_mixer_input.h" | 11 #include "media/base/audio_renderer_mixer_input.h" |
| 13 #include "media/base/audio_renderer_sink.h" | 12 #include "media/base/audio_renderer_sink.h" |
| 14 #include "media/base/multi_channel_resampler.h" | 13 #include "media/base/multi_channel_resampler.h" |
| 15 | 14 |
| 16 namespace media { | 15 namespace media { |
| 17 | 16 |
| 18 // Mixes a set of AudioRendererMixerInputs into a single output stream which is | 17 // Mixes a set of AudioRendererMixerInputs into a single output stream which is |
| 19 // funneled into a single shared AudioRendererSink; saving a bundle on renderer | 18 // funneled into a single shared AudioRendererSink; saving a bundle on renderer |
| 20 // side resources. Resampling is done post-mixing as it is the most expensive | 19 // side resources. Resampling is done post-mixing as it is the most expensive |
| 21 // process. If the input sample rate matches the audio hardware sample rate, no | 20 // process. If the input sample rate matches the audio hardware sample rate, no |
| 22 // resampling is done. | 21 // resampling is done. |
| 23 class MEDIA_EXPORT AudioRendererMixer | 22 class MEDIA_EXPORT AudioRendererMixer |
| 24 : NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback) { | 23 : NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback) { |
| 25 public: | 24 public: |
| 26 AudioRendererMixer(const AudioParameters& input_params, | 25 AudioRendererMixer(const AudioParameters& input_params, |
| 27 const AudioParameters& output_params, | 26 const AudioParameters& output_params, |
| 28 const scoped_refptr<AudioRendererSink>& sink); | 27 const scoped_refptr<AudioRendererSink>& sink); |
| 29 virtual ~AudioRendererMixer(); | 28 virtual ~AudioRendererMixer(); |
| 30 | 29 |
| 31 // Add or remove a mixer input from mixing; called by AudioRendererMixerInput. | 30 // Add or remove a mixer input from mixing; called by AudioRendererMixerInput. |
| 32 void AddMixerInput(const scoped_refptr<AudioRendererMixerInput>& input); | 31 void AddMixerInput(const scoped_refptr<AudioRendererMixerInput>& input); |
| 33 void RemoveMixerInput(const scoped_refptr<AudioRendererMixerInput>& input); | 32 void RemoveMixerInput(const scoped_refptr<AudioRendererMixerInput>& input); |
| 34 | 33 |
| 35 private: | 34 private: |
| 36 FRIEND_TEST_ALL_PREFIXES(AudioRendererMixerTest, VectorFMAC); | |
| 37 FRIEND_TEST_ALL_PREFIXES(AudioRendererMixerTest, VectorFMACBenchmark); | |
| 38 | |
| 39 // AudioRendererSink::RenderCallback implementation. | 35 // AudioRendererSink::RenderCallback implementation. |
| 40 virtual int Render(AudioBus* audio_bus, | 36 virtual int Render(AudioBus* audio_bus, |
| 41 int audio_delay_milliseconds) OVERRIDE; | 37 int audio_delay_milliseconds) OVERRIDE; |
| 42 virtual void OnRenderError() OVERRIDE; | 38 virtual void OnRenderError() OVERRIDE; |
| 43 | 39 |
| 44 // Handles mixing and volume adjustment. Fully fills |audio_bus| with mixed | 40 // Handles mixing and volume adjustment. Fully fills |audio_bus| with mixed |
| 45 // audio data. When resampling is necessary, ProvideInput() will be called | 41 // audio data. When resampling is necessary, ProvideInput() will be called |
| 46 // by MultiChannelResampler when more data is necessary. | 42 // by MultiChannelResampler when more data is necessary. |
| 47 void ProvideInput(AudioBus* audio_bus); | 43 void ProvideInput(AudioBus* audio_bus); |
| 48 | 44 |
| 49 // Multiply each element of |src| (up to |len|) by |scale| and add to |dest|. | |
| 50 static void VectorFMAC(const float src[], float scale, int len, float dest[]); | |
| 51 static void VectorFMAC_C(const float src[], float scale, int len, | |
| 52 float dest[]); | |
| 53 // SSE optimized VectorFMAC, requires |src|, |dest| to be 16-byte aligned. | |
| 54 static void VectorFMAC_SSE(const float src[], float scale, int len, | |
| 55 float dest[]); | |
| 56 | |
| 57 // Output sink for this mixer. | 45 // Output sink for this mixer. |
| 58 scoped_refptr<AudioRendererSink> audio_sink_; | 46 scoped_refptr<AudioRendererSink> audio_sink_; |
| 59 | 47 |
| 60 // Set of mixer inputs to be mixed by this mixer. Access is thread-safe | 48 // Set of mixer inputs to be mixed by this mixer. Access is thread-safe |
| 61 // through |mixer_inputs_lock_|. | 49 // through |mixer_inputs_lock_|. |
| 62 typedef std::set< scoped_refptr<AudioRendererMixerInput> > | 50 typedef std::set< scoped_refptr<AudioRendererMixerInput> > |
| 63 AudioRendererMixerInputSet; | 51 AudioRendererMixerInputSet; |
| 64 AudioRendererMixerInputSet mixer_inputs_; | 52 AudioRendererMixerInputSet mixer_inputs_; |
| 65 base::Lock mixer_inputs_lock_; | 53 base::Lock mixer_inputs_lock_; |
| 66 | 54 |
| 67 // Vector for rendering audio data from each mixer input. | 55 // Vector for rendering audio data from each mixer input. |
| 68 scoped_ptr<AudioBus> mixer_input_audio_bus_; | 56 scoped_ptr<AudioBus> mixer_input_audio_bus_; |
| 69 | 57 |
| 70 // Handles resampling post-mixing. | 58 // Handles resampling post-mixing. |
| 71 scoped_ptr<MultiChannelResampler> resampler_; | 59 scoped_ptr<MultiChannelResampler> resampler_; |
| 72 | 60 |
| 73 // The audio delay in milliseconds received by the last Render() call. | 61 // The audio delay in milliseconds received by the last Render() call. |
| 74 int current_audio_delay_milliseconds_; | 62 int current_audio_delay_milliseconds_; |
| 75 | 63 |
| 76 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer); | 64 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer); |
| 77 }; | 65 }; |
| 78 | 66 |
| 79 } // namespace media | 67 } // namespace media |
| 80 | 68 |
| 81 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ | 69 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ |
| OLD | NEW |