| 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 #include <vector> | |
| 10 | 9 |
| 11 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| 12 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 13 #include "media/base/audio_renderer_mixer_input.h" | 12 #include "media/base/audio_renderer_mixer_input.h" |
| 14 #include "media/base/audio_renderer_sink.h" | 13 #include "media/base/audio_renderer_sink.h" |
| 15 #include "media/base/multi_channel_resampler.h" | 14 #include "media/base/multi_channel_resampler.h" |
| 16 | 15 |
| 17 namespace media { | 16 namespace media { |
| 18 | 17 |
| 19 // Mixes a set of AudioRendererMixerInputs into a single output stream which is | 18 // Mixes a set of AudioRendererMixerInputs into a single output stream which is |
| (...skipping 11 matching lines...) Expand all Loading... |
| 31 | 30 |
| 32 // Add or remove a mixer input from mixing; called by AudioRendererMixerInput. | 31 // Add or remove a mixer input from mixing; called by AudioRendererMixerInput. |
| 33 void AddMixerInput(const scoped_refptr<AudioRendererMixerInput>& input); | 32 void AddMixerInput(const scoped_refptr<AudioRendererMixerInput>& input); |
| 34 void RemoveMixerInput(const scoped_refptr<AudioRendererMixerInput>& input); | 33 void RemoveMixerInput(const scoped_refptr<AudioRendererMixerInput>& input); |
| 35 | 34 |
| 36 private: | 35 private: |
| 37 FRIEND_TEST_ALL_PREFIXES(AudioRendererMixerTest, VectorFMAC); | 36 FRIEND_TEST_ALL_PREFIXES(AudioRendererMixerTest, VectorFMAC); |
| 38 FRIEND_TEST_ALL_PREFIXES(AudioRendererMixerTest, VectorFMACBenchmark); | 37 FRIEND_TEST_ALL_PREFIXES(AudioRendererMixerTest, VectorFMACBenchmark); |
| 39 | 38 |
| 40 // AudioRendererSink::RenderCallback implementation. | 39 // AudioRendererSink::RenderCallback implementation. |
| 41 virtual int Render(const std::vector<float*>& audio_data, | 40 virtual int Render(AudioBus* audio_bus, |
| 42 int number_of_frames, | |
| 43 int audio_delay_milliseconds) OVERRIDE; | 41 int audio_delay_milliseconds) OVERRIDE; |
| 44 virtual void OnRenderError() OVERRIDE; | 42 virtual void OnRenderError() OVERRIDE; |
| 45 | 43 |
| 46 // Handles mixing and volume adjustment. Renders |number_of_frames| into | 44 // Handles mixing and volume adjustment. Fully fills |audio_bus| with mixed |
| 47 // |audio_data|. When resampling is necessary, ProvideInput() will be called | 45 // audio data. When resampling is necessary, ProvideInput() will be called |
| 48 // by MultiChannelResampler when more data is necessary. | 46 // by MultiChannelResampler when more data is necessary. |
| 49 void ProvideInput(const std::vector<float*>& audio_data, | 47 void ProvideInput(AudioBus* audio_bus); |
| 50 int number_of_frames); | |
| 51 | 48 |
| 52 // Multiply each element of |src| (up to |len|) by |scale| and add to |dest|. | 49 // Multiply each element of |src| (up to |len|) by |scale| and add to |dest|. |
| 53 static void VectorFMAC(const float src[], float scale, int len, float dest[]); | 50 static void VectorFMAC(const float src[], float scale, int len, float dest[]); |
| 54 static void VectorFMAC_C(const float src[], float scale, int len, | 51 static void VectorFMAC_C(const float src[], float scale, int len, |
| 55 float dest[]); | 52 float dest[]); |
| 56 // SSE optimized VectorFMAC, requires |src|, |dest| to be 16-byte aligned. | 53 // SSE optimized VectorFMAC, requires |src|, |dest| to be 16-byte aligned. |
| 57 static void VectorFMAC_SSE(const float src[], float scale, int len, | 54 static void VectorFMAC_SSE(const float src[], float scale, int len, |
| 58 float dest[]); | 55 float dest[]); |
| 59 | 56 |
| 60 // Output sink for this mixer. | 57 // Output sink for this mixer. |
| 61 scoped_refptr<AudioRendererSink> audio_sink_; | 58 scoped_refptr<AudioRendererSink> audio_sink_; |
| 62 | 59 |
| 63 // Set of mixer inputs to be mixed by this mixer. Access is thread-safe | 60 // Set of mixer inputs to be mixed by this mixer. Access is thread-safe |
| 64 // through |mixer_inputs_lock_|. | 61 // through |mixer_inputs_lock_|. |
| 65 typedef std::set< scoped_refptr<AudioRendererMixerInput> > | 62 typedef std::set< scoped_refptr<AudioRendererMixerInput> > |
| 66 AudioRendererMixerInputSet; | 63 AudioRendererMixerInputSet; |
| 67 AudioRendererMixerInputSet mixer_inputs_; | 64 AudioRendererMixerInputSet mixer_inputs_; |
| 68 base::Lock mixer_inputs_lock_; | 65 base::Lock mixer_inputs_lock_; |
| 69 | 66 |
| 70 // Vector for rendering audio data from each mixer input. | 67 // Vector for rendering audio data from each mixer input. |
| 71 int mixer_input_audio_data_size_; | 68 scoped_ptr<AudioBus> mixer_input_audio_bus_; |
| 72 std::vector<float*> mixer_input_audio_data_; | |
| 73 | 69 |
| 74 // Handles resampling post-mixing. | 70 // Handles resampling post-mixing. |
| 75 scoped_ptr<MultiChannelResampler> resampler_; | 71 scoped_ptr<MultiChannelResampler> resampler_; |
| 76 | 72 |
| 77 // The audio delay in milliseconds received by the last Render() call. | 73 // The audio delay in milliseconds received by the last Render() call. |
| 78 int current_audio_delay_milliseconds_; | 74 int current_audio_delay_milliseconds_; |
| 79 | 75 |
| 80 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer); | 76 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer); |
| 81 }; | 77 }; |
| 82 | 78 |
| 83 } // namespace media | 79 } // namespace media |
| 84 | 80 |
| 85 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ | 81 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ |
| OLD | NEW |