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, | 41 int number_of_frames, |
43 int audio_delay_milliseconds) OVERRIDE; | 42 int audio_delay_milliseconds) OVERRIDE; |
44 virtual void OnRenderError() OVERRIDE; | 43 virtual void OnRenderError() OVERRIDE; |
45 | 44 |
46 // Handles mixing and volume adjustment. Renders |number_of_frames| into | 45 // Handles mixing and volume adjustment. Renders |number_of_frames| into |
47 // |audio_data|. When resampling is necessary, ProvideInput() will be called | 46 // |audio_bus|. When resampling is necessary, ProvideInput() will be called |
48 // by MultiChannelResampler when more data is necessary. | 47 // by MultiChannelResampler when more data is necessary. |
49 void ProvideInput(const std::vector<float*>& audio_data, | 48 void ProvideInput(AudioBus* audio_bus, int number_of_frames); |
50 int number_of_frames); | |
51 | 49 |
52 // Multiply each element of |src| (up to |len|) by |scale| and add to |dest|. | 50 // 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[]); | 51 static void VectorFMAC(const float src[], float scale, int len, float dest[]); |
54 static void VectorFMAC_C(const float src[], float scale, int len, | 52 static void VectorFMAC_C(const float src[], float scale, int len, |
55 float dest[]); | 53 float dest[]); |
56 // SSE optimized VectorFMAC, requires |src|, |dest| to be 16-byte aligned. | 54 // SSE optimized VectorFMAC, requires |src|, |dest| to be 16-byte aligned. |
57 static void VectorFMAC_SSE(const float src[], float scale, int len, | 55 static void VectorFMAC_SSE(const float src[], float scale, int len, |
58 float dest[]); | 56 float dest[]); |
59 | 57 |
60 // Output sink for this mixer. | 58 // Output sink for this mixer. |
61 scoped_refptr<AudioRendererSink> audio_sink_; | 59 scoped_refptr<AudioRendererSink> audio_sink_; |
62 | 60 |
63 // Set of mixer inputs to be mixed by this mixer. Access is thread-safe | 61 // Set of mixer inputs to be mixed by this mixer. Access is thread-safe |
64 // through |mixer_inputs_lock_|. | 62 // through |mixer_inputs_lock_|. |
65 typedef std::set< scoped_refptr<AudioRendererMixerInput> > | 63 typedef std::set< scoped_refptr<AudioRendererMixerInput> > |
66 AudioRendererMixerInputSet; | 64 AudioRendererMixerInputSet; |
67 AudioRendererMixerInputSet mixer_inputs_; | 65 AudioRendererMixerInputSet mixer_inputs_; |
68 base::Lock mixer_inputs_lock_; | 66 base::Lock mixer_inputs_lock_; |
69 | 67 |
70 // Vector for rendering audio data from each mixer input. | 68 // Vector for rendering audio data from each mixer input. |
71 int mixer_input_audio_data_size_; | 69 scoped_ptr<AudioBus> mixer_input_audio_bus_; |
72 std::vector<float*> mixer_input_audio_data_; | |
73 | 70 |
74 // Handles resampling post-mixing. | 71 // Handles resampling post-mixing. |
75 scoped_ptr<MultiChannelResampler> resampler_; | 72 scoped_ptr<MultiChannelResampler> resampler_; |
76 | 73 |
77 // The audio delay in milliseconds received by the last Render() call. | 74 // The audio delay in milliseconds received by the last Render() call. |
78 int current_audio_delay_milliseconds_; | 75 int current_audio_delay_milliseconds_; |
79 | 76 |
80 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer); | 77 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer); |
81 }; | 78 }; |
82 | 79 |
83 } // namespace media | 80 } // namespace media |
84 | 81 |
85 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ | 82 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ |
OLD | NEW |