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

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

Issue 10909185: Add Mac OS X synchronized audio I/O back-end (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
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 <vector> 8 #include <vector>
9 9
10 #include "base/memory/aligned_memory.h" 10 #include "base/memory/aligned_memory.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "media/base/media_export.h" 12 #include "media/base/media_export.h"
13 13
14 #if defined(OS_MACOSX)
15 struct AudioBufferList;
16 #endif
17
14 namespace media { 18 namespace media {
15 class AudioParameters; 19 class AudioParameters;
16 20
17 // Scoped container for "busing" audio channel data around. Each channel is 21 // Scoped container for "busing" audio channel data around. Each channel is
18 // stored in planar format and guaranteed to be aligned by kChannelAlignment. 22 // stored in planar format and guaranteed to be aligned by kChannelAlignment.
19 // AudioBus objects can be created normally or via wrapping. Normally, AudioBus 23 // AudioBus objects can be created normally or via wrapping. Normally, AudioBus
20 // will dice up a contiguous memory block for channel data. When wrapped, 24 // will dice up a contiguous memory block for channel data. When wrapped,
21 // AudioBus instead routes requests for channel data to the wrapped object. 25 // AudioBus instead routes requests for channel data to the wrapped object.
22 class MEDIA_EXPORT AudioBus { 26 class MEDIA_EXPORT AudioBus {
23 public: 27 public:
24 // Guaranteed alignment of each channel's data; use 16-byte alignment for easy 28 // Guaranteed alignment of each channel's data; use 16-byte alignment for easy
25 // SSE optimizations. 29 // SSE optimizations.
26 enum { kChannelAlignment = 16 }; 30 enum { kChannelAlignment = 16 };
27 31
32 AudioBus(int channels, int frames);
33 AudioBus(int channels, int frames, float* data);
34 AudioBus(int frames, const std::vector<float*>& channel_data);
35
36 #if defined(OS_MACOSX)
37 AudioBus(int channels, int frames, AudioBufferList* buffer_list);
scherkus (not reviewing) 2012/09/17 14:51:17 let's try to close out this issue sooner rather th
38 #endif
39
40 ~AudioBus();
41
28 // Creates a new AudioBus and allocates |channels| of length |frames|. Uses 42 // Creates a new AudioBus and allocates |channels| of length |frames|. Uses
29 // channels() and frames_per_buffer() from AudioParameters if given. 43 // channels() and frames_per_buffer() from AudioParameters if given.
30 static scoped_ptr<AudioBus> Create(int channels, int frames); 44 static scoped_ptr<AudioBus> Create(int channels, int frames);
31 static scoped_ptr<AudioBus> Create(const AudioParameters& params); 45 static scoped_ptr<AudioBus> Create(const AudioParameters& params);
32 46
33 // Creates a new AudioBus from an existing channel vector. Does not transfer 47 // Creates a new AudioBus from an existing channel vector. Does not transfer
34 // ownership of |channel_data| to AudioBus; i.e., |channel_data| must outlive 48 // ownership of |channel_data| to AudioBus; i.e., |channel_data| must outlive
35 // the returned AudioBus. Each channel must be aligned by kChannelAlignment. 49 // the returned AudioBus. Each channel must be aligned by kChannelAlignment.
36 static scoped_ptr<AudioBus> WrapVector( 50 static scoped_ptr<AudioBus> WrapVector(
37 int frames, const std::vector<float*>& channel_data); 51 int frames, const std::vector<float*>& channel_data);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 int channels() const { return channel_data_.size(); } 92 int channels() const { return channel_data_.size(); }
79 int frames() const { return frames_; } 93 int frames() const { return frames_; }
80 94
81 // Helper method for zeroing out all channels of audio data. 95 // Helper method for zeroing out all channels of audio data.
82 void Zero(); 96 void Zero();
83 void ZeroFrames(int frames); 97 void ZeroFrames(int frames);
84 void ZeroFramesPartial(int start_frame, int frames); 98 void ZeroFramesPartial(int start_frame, int frames);
85 99
86 private: 100 private:
87 friend class scoped_ptr<AudioBus>; 101 friend class scoped_ptr<AudioBus>;
88 ~AudioBus();
89
90 AudioBus(int channels, int frames);
91 AudioBus(int channels, int frames, float* data);
92 AudioBus(int frames, const std::vector<float*>& channel_data);
93 102
94 // Helper method for building |channel_data_| from a block of memory. |data| 103 // Helper method for building |channel_data_| from a block of memory. |data|
95 // must be at least BlockSize() bytes in size. 104 // must be at least BlockSize() bytes in size.
96 void BuildChannelData(int channels, int aligned_frame, float* data); 105 void BuildChannelData(int channels, int aligned_frame, float* data);
97 106
98 // Contiguous block of channel memory. 107 // Contiguous block of channel memory.
99 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> data_; 108 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> data_;
100 109
101 std::vector<float*> channel_data_; 110 std::vector<float*> channel_data_;
102 int frames_; 111 int frames_;
103 112
104 DISALLOW_COPY_AND_ASSIGN(AudioBus); 113 DISALLOW_COPY_AND_ASSIGN(AudioBus);
105 }; 114 };
106 115
107 } // namespace media 116 } // namespace media
108 117
109 #endif // MEDIA_BASE_AUDIO_BUS_H_ 118 #endif // MEDIA_BASE_AUDIO_BUS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698