Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(723)

Side by Side Diff: media/base/audio_bus.h

Issue 2640003002: Implement MojoAudioRendererSink and use it in UtilityMojoMediaClient (Closed)
Patch Set: Rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/audio/audio_device_thread.cc ('k') | media/base/audio_bus.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/aligned_memory.h" 14 #include "base/memory/aligned_memory.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "media/base/media_export.h" 16 #include "media/base/media_export.h"
17 17
18 namespace mojo {
19 template <typename T, typename U>
20 struct TypeConverter;
21 template <typename T>
22 class StructPtr;
23 };
24
18 namespace media { 25 namespace media {
19 class AudioParameters; 26 class AudioParameters;
20 27
28 namespace mojom {
29 class AudioBus;
30 }
31
21 // Represents a sequence of audio frames containing frames() audio samples for 32 // Represents a sequence of audio frames containing frames() audio samples for
22 // each of channels() channels. The data is stored as a set of contiguous 33 // each of channels() channels. The data is stored as a set of contiguous
23 // float arrays with one array per channel. The memory for the arrays is either 34 // float arrays with one array per channel. The memory for the arrays is either
24 // allocated and owned by the AudioBus or it is provided to one of the factory 35 // allocated and owned by the AudioBus or it is provided to one of the factory
25 // methods. AudioBus guarantees that it allocates memory such that float array 36 // methods. AudioBus guarantees that it allocates memory such that float array
26 // for each channel is aligned by AudioBus::kChannelAlignment bytes and it 37 // for each channel is aligned by AudioBus::kChannelAlignment bytes and it
27 // requires the same for memory passed to its Wrap...() factory methods. 38 // requires the same for memory passed to its Wrap...() factory methods.
28 // TODO(chfremer): There are currently no unit tests involving CreateWrapper and 39 // TODO(chfremer): There are currently no unit tests involving CreateWrapper and
29 // SetChannelData, so we need to add them. 40 // SetChannelData, so we need to add them.
30 class MEDIA_EXPORT AudioBus { 41 class MEDIA_EXPORT AudioBus {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 191
181 virtual ~AudioBus(); 192 virtual ~AudioBus();
182 193
183 protected: 194 protected:
184 AudioBus(int channels, int frames); 195 AudioBus(int channels, int frames);
185 AudioBus(int channels, int frames, float* data); 196 AudioBus(int channels, int frames, float* data);
186 AudioBus(int frames, const std::vector<float*>& channel_data); 197 AudioBus(int frames, const std::vector<float*>& channel_data);
187 explicit AudioBus(int channels); 198 explicit AudioBus(int channels);
188 199
189 private: 200 private:
201 // mojo::TypeConverter added as a friend so that AudioBus can be
202 // transferred across a mojo connection.
203 friend struct mojo::TypeConverter<mojo::StructPtr<mojom::AudioBus>, AudioBus>;
204
190 // Helper method for building |channel_data_| from a block of memory. |data| 205 // Helper method for building |channel_data_| from a block of memory. |data|
191 // must be at least CalculateMemorySize(...) bytes in size. 206 // must be at least CalculateMemorySize(...) bytes in size.
192 void BuildChannelData(int channels, int aligned_frame, float* data); 207 void BuildChannelData(int channels, int aligned_frame, float* data);
193 208
194 static void CheckOverflow(int start_frame, int frames, int total_frames); 209 static void CheckOverflow(int start_frame, int frames, int total_frames);
195 210
196 template <class SourceSampleTypeTraits> 211 template <class SourceSampleTypeTraits>
197 static void CopyConvertFromInterleavedSourceToAudioBus( 212 static void CopyConvertFromInterleavedSourceToAudioBus(
198 const typename SourceSampleTypeTraits::ValueType* source_buffer, 213 const typename SourceSampleTypeTraits::ValueType* source_buffer,
199 int write_offset_in_frames, 214 int write_offset_in_frames,
200 int num_frames_to_write, 215 int num_frames_to_write,
201 AudioBus* dest); 216 AudioBus* dest);
202 217
203 template <class TargetSampleTypeTraits> 218 template <class TargetSampleTypeTraits>
204 static void CopyConvertFromAudioBusToInterleavedTarget( 219 static void CopyConvertFromAudioBusToInterleavedTarget(
205 const AudioBus* source, 220 const AudioBus* source,
206 int read_offset_in_frames, 221 int read_offset_in_frames,
207 int num_frames_to_read, 222 int num_frames_to_read,
208 typename TargetSampleTypeTraits::ValueType* dest_buffer); 223 typename TargetSampleTypeTraits::ValueType* dest_buffer);
209 224
210 // Contiguous block of channel memory. 225 // Contiguous block of channel memory.
211 std::unique_ptr<float, base::AlignedFreeDeleter> data_; 226 std::unique_ptr<float, base::AlignedFreeDeleter> data_;
227 size_t data_size_;
212 228
213 // One float pointer per channel pointing to a contiguous block of memory for 229 // One float pointer per channel pointing to a contiguous block of memory for
214 // that channel. If the memory is owned by this instance, this will 230 // that channel. If the memory is owned by this instance, this will
215 // point to the memory in |data_|. Otherwise, it may point to memory provided 231 // point to the memory in |data_|. Otherwise, it may point to memory provided
216 // by the client. 232 // by the client.
217 std::vector<float*> channel_data_; 233 std::vector<float*> channel_data_;
218 int frames_; 234 int frames_;
219 235
220 // Protect SetChannelData() and set_frames() for use by CreateWrapper(). 236 // Protect SetChannelData() and set_frames() for use by CreateWrapper().
221 bool can_set_channel_data_; 237 bool can_set_channel_data_;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 336
321 AudioBusRefCounted(int channels, int frames); 337 AudioBusRefCounted(int channels, int frames);
322 ~AudioBusRefCounted() override; 338 ~AudioBusRefCounted() override;
323 339
324 DISALLOW_COPY_AND_ASSIGN(AudioBusRefCounted); 340 DISALLOW_COPY_AND_ASSIGN(AudioBusRefCounted);
325 }; 341 };
326 342
327 } // namespace media 343 } // namespace media
328 344
329 #endif // MEDIA_BASE_AUDIO_BUS_H_ 345 #endif // MEDIA_BASE_AUDIO_BUS_H_
OLDNEW
« no previous file with comments | « media/audio/audio_device_thread.cc ('k') | media/base/audio_bus.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698