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 // AudioConverter is a complete mixing, resampling, buffering, and channel | 5 // AudioConverter is a complete mixing, resampling, buffering, and channel |
6 // mixing solution for converting data from one set of AudioParameters to | 6 // mixing solution for converting data from one set of AudioParameters to |
7 // another. | 7 // another. |
8 // | 8 // |
9 // For efficiency, pieces are only invoked when necessary; i.e., | 9 // For efficiency, pieces are only invoked when necessary; i.e., |
10 // - The resampler is only used if sample rates differ. | 10 // - The resampler is only used if sample rates differ. |
11 // - The FIFO is only used if buffer sizes differ. | 11 // - The FIFO is only used if buffer sizes differ. |
12 // - The channel mixer is only used if channel layouts differ. | 12 // - The channel mixer is only used if channel layouts differ. |
13 // | 13 // |
14 // Additionally, since resampling is the most expensive operation, input mixing | 14 // Additionally, since resampling is the most expensive operation, input mixing |
15 // and channel down mixing are done prior to resampling. Likewise, channel up | 15 // and channel down mixing are done prior to resampling. Likewise, channel up |
16 // mixing is performed after resampling. | 16 // mixing is performed after resampling. |
17 | 17 |
18 #ifndef MEDIA_BASE_AUDIO_CONVERTER_H_ | 18 #ifndef MEDIA_BASE_AUDIO_CONVERTER_H_ |
19 #define MEDIA_BASE_AUDIO_CONVERTER_H_ | 19 #define MEDIA_BASE_AUDIO_CONVERTER_H_ |
20 | 20 |
21 #include <list> | 21 #include <list> |
| 22 #include <memory> |
22 | 23 |
23 #include "base/callback.h" | 24 #include "base/callback.h" |
24 #include "base/macros.h" | 25 #include "base/macros.h" |
25 #include "base/memory/scoped_ptr.h" | |
26 #include "base/time/time.h" | 26 #include "base/time/time.h" |
27 #include "media/base/audio_parameters.h" | 27 #include "media/base/audio_parameters.h" |
28 #include "media/base/media_export.h" | 28 #include "media/base/media_export.h" |
29 | 29 |
30 namespace media { | 30 namespace media { |
31 | 31 |
32 class AudioBus; | 32 class AudioBus; |
33 class AudioPullFifo; | 33 class AudioPullFifo; |
34 class ChannelMixer; | 34 class ChannelMixer; |
35 class MultiChannelResampler; | 35 class MultiChannelResampler; |
36 | 36 |
37 // Converts audio data between two AudioParameters formats. Sample usage: | 37 // Converts audio data between two AudioParameters formats. Sample usage: |
38 // AudioParameters input(...), output(...); | 38 // AudioParameters input(...), output(...); |
39 // AudioConverter ac(input, output); | 39 // AudioConverter ac(input, output); |
40 // scoped_ptr<AudioBus> output_audio_bus = AudioBus::Create(output); | 40 // std::unique_ptr<AudioBus> output_audio_bus = AudioBus::Create(output); |
41 // ac.AddInput(<AudioConverter::InputCallback* 1>); | 41 // ac.AddInput(<AudioConverter::InputCallback* 1>); |
42 // ac.AddInput(<AudioConverter::InputCallback* 2>); | 42 // ac.AddInput(<AudioConverter::InputCallback* 2>); |
43 // ac.Convert(output_audio_bus.get()); | 43 // ac.Convert(output_audio_bus.get()); |
44 // | 44 // |
45 // Convert() will ask for input audio data from each InputCallback and convert | 45 // Convert() will ask for input audio data from each InputCallback and convert |
46 // the data into the provided AudioBus. | 46 // the data into the provided AudioBus. |
47 class MEDIA_EXPORT AudioConverter { | 47 class MEDIA_EXPORT AudioConverter { |
48 public: | 48 public: |
49 // Interface for inputs into the converter. Each InputCallback is added or | 49 // Interface for inputs into the converter. Each InputCallback is added or |
50 // removed from Convert() processing via AddInput() and RemoveInput(). | 50 // removed from Convert() processing via AddInput() and RemoveInput(). |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 107 |
108 // (Re)creates the temporary |unmixed_audio_| buffer if necessary. | 108 // (Re)creates the temporary |unmixed_audio_| buffer if necessary. |
109 void CreateUnmixedAudioIfNecessary(int frames); | 109 void CreateUnmixedAudioIfNecessary(int frames); |
110 | 110 |
111 // Set of inputs for Convert(). | 111 // Set of inputs for Convert(). |
112 typedef std::list<InputCallback*> InputCallbackSet; | 112 typedef std::list<InputCallback*> InputCallbackSet; |
113 InputCallbackSet transform_inputs_; | 113 InputCallbackSet transform_inputs_; |
114 | 114 |
115 // Used to buffer data between the client and the output device in cases where | 115 // Used to buffer data between the client and the output device in cases where |
116 // the client buffer size is not the same as the output device buffer size. | 116 // the client buffer size is not the same as the output device buffer size. |
117 scoped_ptr<AudioPullFifo> audio_fifo_; | 117 std::unique_ptr<AudioPullFifo> audio_fifo_; |
118 int chunk_size_; | 118 int chunk_size_; |
119 | 119 |
120 // Handles resampling. | 120 // Handles resampling. |
121 scoped_ptr<MultiChannelResampler> resampler_; | 121 std::unique_ptr<MultiChannelResampler> resampler_; |
122 | 122 |
123 // Handles channel transforms. |unmixed_audio_| is a temporary destination | 123 // Handles channel transforms. |unmixed_audio_| is a temporary destination |
124 // for audio data before it goes into the channel mixer. | 124 // for audio data before it goes into the channel mixer. |
125 scoped_ptr<ChannelMixer> channel_mixer_; | 125 std::unique_ptr<ChannelMixer> channel_mixer_; |
126 scoped_ptr<AudioBus> unmixed_audio_; | 126 std::unique_ptr<AudioBus> unmixed_audio_; |
127 | 127 |
128 // Temporary AudioBus destination for mixing inputs. | 128 // Temporary AudioBus destination for mixing inputs. |
129 scoped_ptr<AudioBus> mixer_input_audio_bus_; | 129 std::unique_ptr<AudioBus> mixer_input_audio_bus_; |
130 | 130 |
131 // Since resampling is expensive, figure out if we should downmix channels | 131 // Since resampling is expensive, figure out if we should downmix channels |
132 // before resampling. | 132 // before resampling. |
133 bool downmix_early_; | 133 bool downmix_early_; |
134 | 134 |
135 // Used to calculate buffer delay information for InputCallbacks. | 135 // Used to calculate buffer delay information for InputCallbacks. |
136 base::TimeDelta input_frame_duration_; | 136 base::TimeDelta input_frame_duration_; |
137 base::TimeDelta output_frame_duration_; | 137 base::TimeDelta output_frame_duration_; |
138 base::TimeDelta initial_delay_; | 138 base::TimeDelta initial_delay_; |
139 int resampler_frame_delay_; | 139 int resampler_frame_delay_; |
140 | 140 |
141 // Number of channels of input audio data. Set during construction via the | 141 // Number of channels of input audio data. Set during construction via the |
142 // value from the input AudioParameters class. Preserved to recreate internal | 142 // value from the input AudioParameters class. Preserved to recreate internal |
143 // AudioBus structures on demand in response to varying frame size requests. | 143 // AudioBus structures on demand in response to varying frame size requests. |
144 const int input_channel_count_; | 144 const int input_channel_count_; |
145 | 145 |
146 DISALLOW_COPY_AND_ASSIGN(AudioConverter); | 146 DISALLOW_COPY_AND_ASSIGN(AudioConverter); |
147 }; | 147 }; |
148 | 148 |
149 } // namespace media | 149 } // namespace media |
150 | 150 |
151 #endif // MEDIA_BASE_AUDIO_CONVERTER_H_ | 151 #endif // MEDIA_BASE_AUDIO_CONVERTER_H_ |
OLD | NEW |