OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_BUFFER_H_ | 5 #ifndef MEDIA_BASE_AUDIO_BUFFER_H_ |
6 #define MEDIA_BASE_AUDIO_BUFFER_H_ | 6 #define MEDIA_BASE_AUDIO_BUFFER_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/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "media/base/channel_layout.h" | 14 #include "media/base/channel_layout.h" |
15 #include "media/base/media_export.h" | 15 #include "media/base/media_export.h" |
16 #include "media/base/sample_format.h" | 16 #include "media/base/sample_format.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 AudioBus; | 26 class AudioBus; |
20 | 27 |
28 namespace interfaces { | |
29 class AudioBuffer; | |
30 } | |
31 | |
21 // An audio buffer that takes a copy of the data passed to it, holds it, and | 32 // An audio buffer that takes a copy of the data passed to it, holds it, and |
22 // copies it into an AudioBus when needed. Also supports an end of stream | 33 // copies it into an AudioBus when needed. Also supports an end of stream |
23 // marker. | 34 // marker. |
24 class MEDIA_EXPORT AudioBuffer | 35 class MEDIA_EXPORT AudioBuffer |
25 : public base::RefCountedThreadSafe<AudioBuffer> { | 36 : public base::RefCountedThreadSafe<AudioBuffer> { |
26 public: | 37 public: |
27 // Alignment of each channel's data; this must match what ffmpeg expects | 38 // Alignment of each channel's data; this must match what ffmpeg expects |
28 // (which may be 0, 16, or 32, depending on the processor). Selecting 32 in | 39 // (which may be 0, 16, or 32, depending on the processor). Selecting 32 in |
29 // order to work on all processors. | 40 // order to work on all processors. |
30 enum { kChannelAlignment = 32 }; | 41 enum { kChannelAlignment = 32 }; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 | 126 |
116 // If there's no data in this buffer, it represents end of stream. | 127 // If there's no data in this buffer, it represents end of stream. |
117 bool end_of_stream() const { return end_of_stream_; } | 128 bool end_of_stream() const { return end_of_stream_; } |
118 | 129 |
119 // Access to the raw buffer for ffmpeg to write directly to. Data for planar | 130 // Access to the raw buffer for ffmpeg to write directly to. Data for planar |
120 // data is grouped by channel. There is only 1 entry for interleaved formats. | 131 // data is grouped by channel. There is only 1 entry for interleaved formats. |
121 const std::vector<uint8*>& channel_data() const { return channel_data_; } | 132 const std::vector<uint8*>& channel_data() const { return channel_data_; } |
122 | 133 |
123 private: | 134 private: |
124 friend class base::RefCountedThreadSafe<AudioBuffer>; | 135 friend class base::RefCountedThreadSafe<AudioBuffer>; |
136 friend struct mojo::TypeConverter<mojo::StructPtr<interfaces::AudioBuffer>, | |
137 scoped_refptr<AudioBuffer>>; | |
xhwang
2015/11/23 22:22:18
Add a comment why we need this friend here.
jrummell
2015/11/24 02:37:53
Done.
| |
125 | 138 |
126 // Allocates aligned contiguous buffer to hold all channel data (1 block for | 139 // Allocates aligned contiguous buffer to hold all channel data (1 block for |
127 // interleaved data, |channel_count| blocks for planar data), copies | 140 // interleaved data, |channel_count| blocks for planar data), copies |
128 // [data,data+data_size) to the allocated buffer(s). If |data| is null, no | 141 // [data,data+data_size) to the allocated buffer(s). If |data| is null, no |
129 // data is copied. If |create_buffer| is false, no data buffer is created (or | 142 // data is copied. If |create_buffer| is false, no data buffer is created (or |
130 // copied to). | 143 // copied to). |
131 AudioBuffer(SampleFormat sample_format, | 144 AudioBuffer(SampleFormat sample_format, |
132 ChannelLayout channel_layout, | 145 ChannelLayout channel_layout, |
133 int channel_count, | 146 int channel_count, |
134 int sample_rate, | 147 int sample_rate, |
135 int frame_count, | 148 int frame_count, |
136 bool create_buffer, | 149 bool create_buffer, |
137 const uint8* const* data, | 150 const uint8* const* data, |
138 const base::TimeDelta timestamp); | 151 const base::TimeDelta timestamp); |
139 | 152 |
140 virtual ~AudioBuffer(); | 153 virtual ~AudioBuffer(); |
141 | 154 |
142 const SampleFormat sample_format_; | 155 const SampleFormat sample_format_; |
143 const ChannelLayout channel_layout_; | 156 const ChannelLayout channel_layout_; |
144 const int channel_count_; | 157 const int channel_count_; |
145 const int sample_rate_; | 158 const int sample_rate_; |
146 int adjusted_frame_count_; | 159 int adjusted_frame_count_; |
147 int trim_start_; | 160 int trim_start_; |
148 const bool end_of_stream_; | 161 const bool end_of_stream_; |
149 base::TimeDelta timestamp_; | 162 base::TimeDelta timestamp_; |
150 base::TimeDelta duration_; | 163 base::TimeDelta duration_; |
151 | 164 |
152 // Contiguous block of channel data. | 165 // Contiguous block of channel data. |
153 scoped_ptr<uint8, base::AlignedFreeDeleter> data_; | 166 scoped_ptr<uint8, base::AlignedFreeDeleter> data_; |
167 size_t data_size_; | |
154 | 168 |
155 // For planar data, points to each channels data. | 169 // For planar data, points to each channels data. |
156 std::vector<uint8*> channel_data_; | 170 std::vector<uint8*> channel_data_; |
157 | 171 |
158 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioBuffer); | 172 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioBuffer); |
159 }; | 173 }; |
160 | 174 |
161 } // namespace media | 175 } // namespace media |
162 | 176 |
163 #endif // MEDIA_BASE_AUDIO_BUFFER_H_ | 177 #endif // MEDIA_BASE_AUDIO_BUFFER_H_ |
OLD | NEW |