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