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_BUS_H_ | 5 #ifndef MEDIA_BASE_AUDIO_BUS_H_ |
6 #define MEDIA_BASE_AUDIO_BUS_H_ | 6 #define MEDIA_BASE_AUDIO_BUS_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/aligned_memory.h" | 10 #include "base/memory/aligned_memory.h" |
| 11 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "media/base/media_export.h" | 13 #include "media/base/media_export.h" |
13 | 14 |
14 namespace media { | 15 namespace media { |
15 class AudioParameters; | 16 class AudioParameters; |
16 | 17 |
17 // Scoped container for "busing" audio channel data around. Each channel is | 18 // Scoped container for "busing" audio channel data around. Each channel is |
18 // stored in planar format and guaranteed to be aligned by kChannelAlignment. | 19 // stored in planar format and guaranteed to be aligned by kChannelAlignment. |
19 // AudioBus objects can be created normally or via wrapping. Normally, AudioBus | 20 // AudioBus objects can be created normally or via wrapping. Normally, AudioBus |
20 // will dice up a contiguous memory block for channel data. When wrapped, | 21 // will dice up a contiguous memory block for channel data. When wrapped, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 // Scale internal channel values by |volume| >= 0. If an invalid value | 104 // Scale internal channel values by |volume| >= 0. If an invalid value |
104 // is provided, no adjustment is done. | 105 // is provided, no adjustment is done. |
105 void Scale(float volume); | 106 void Scale(float volume); |
106 | 107 |
107 // Swaps channels identified by |a| and |b|. The caller needs to make sure | 108 // Swaps channels identified by |a| and |b|. The caller needs to make sure |
108 // the channels are valid. | 109 // the channels are valid. |
109 void SwapChannels(int a, int b); | 110 void SwapChannels(int a, int b); |
110 | 111 |
111 virtual ~AudioBus(); | 112 virtual ~AudioBus(); |
112 | 113 |
113 private: | 114 protected: |
114 AudioBus(int channels, int frames); | 115 AudioBus(int channels, int frames); |
115 AudioBus(int channels, int frames, float* data); | 116 AudioBus(int channels, int frames, float* data); |
116 AudioBus(int frames, const std::vector<float*>& channel_data); | 117 AudioBus(int frames, const std::vector<float*>& channel_data); |
117 explicit AudioBus(int channels); | 118 explicit AudioBus(int channels); |
118 | 119 |
| 120 private: |
119 // Helper method for building |channel_data_| from a block of memory. |data| | 121 // Helper method for building |channel_data_| from a block of memory. |data| |
120 // must be at least BlockSize() bytes in size. | 122 // must be at least BlockSize() bytes in size. |
121 void BuildChannelData(int channels, int aligned_frame, float* data); | 123 void BuildChannelData(int channels, int aligned_frame, float* data); |
122 | 124 |
123 // Contiguous block of channel memory. | 125 // Contiguous block of channel memory. |
124 scoped_ptr<float, base::AlignedFreeDeleter> data_; | 126 scoped_ptr<float, base::AlignedFreeDeleter> data_; |
125 | 127 |
126 std::vector<float*> channel_data_; | 128 std::vector<float*> channel_data_; |
127 int frames_; | 129 int frames_; |
128 | 130 |
129 // Protect SetChannelData() and set_frames() for use by CreateWrapper(). | 131 // Protect SetChannelData() and set_frames() for use by CreateWrapper(). |
130 bool can_set_channel_data_; | 132 bool can_set_channel_data_; |
131 | 133 |
132 DISALLOW_COPY_AND_ASSIGN(AudioBus); | 134 DISALLOW_COPY_AND_ASSIGN(AudioBus); |
133 }; | 135 }; |
134 | 136 |
| 137 // RefCounted version of AudioBus. This is not meant for general use. Only use |
| 138 // this when your lifetime requirements make it impossible to use an |
| 139 // AudioBus scoped_ptr. |
| 140 class MEDIA_EXPORT AudioBusRefCounted |
| 141 : public media::AudioBus, |
| 142 public base::RefCountedThreadSafe<AudioBusRefCounted> { |
| 143 public: |
| 144 static scoped_refptr<AudioBusRefCounted> Create(int channels, int frames); |
| 145 |
| 146 private: |
| 147 friend class base::RefCountedThreadSafe<AudioBusRefCounted>; |
| 148 |
| 149 AudioBusRefCounted(int channels, int frames); |
| 150 virtual ~AudioBusRefCounted(); |
| 151 |
| 152 DISALLOW_COPY_AND_ASSIGN(AudioBusRefCounted); |
| 153 }; |
| 154 |
135 } // namespace media | 155 } // namespace media |
136 | 156 |
137 #endif // MEDIA_BASE_AUDIO_BUS_H_ | 157 #endif // MEDIA_BASE_AUDIO_BUS_H_ |
OLD | NEW |