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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 static scoped_refptr<AudioBuffer> CopyFrom( | 57 static scoped_refptr<AudioBuffer> CopyFrom( |
58 SampleFormat sample_format, | 58 SampleFormat sample_format, |
59 ChannelLayout channel_layout, | 59 ChannelLayout channel_layout, |
60 int channel_count, | 60 int channel_count, |
61 int sample_rate, | 61 int sample_rate, |
62 int frame_count, | 62 int frame_count, |
63 const uint8_t* const* data, | 63 const uint8_t* const* data, |
64 const base::TimeDelta timestamp, | 64 const base::TimeDelta timestamp, |
65 scoped_refptr<AudioBufferMemoryPool> pool = nullptr); | 65 scoped_refptr<AudioBufferMemoryPool> pool = nullptr); |
66 | 66 |
| 67 // Create an AudioBuffer for compressed bitstream. Its channel data is copied |
| 68 // from |data|, and the size is |data_size|. |data| must not be null and |
| 69 // |frame_count| must be >= 0. |
| 70 static scoped_refptr<AudioBuffer> CopyBitstreamFrom( |
| 71 SampleFormat sample_format, |
| 72 ChannelLayout channel_layout, |
| 73 int channel_count, |
| 74 int sample_rate, |
| 75 int frame_count, |
| 76 const uint8_t* const* data, |
| 77 const size_t data_size, |
| 78 const base::TimeDelta timestamp, |
| 79 scoped_refptr<AudioBufferMemoryPool> pool = nullptr); |
| 80 |
67 // Create an AudioBuffer with |frame_count| frames. Buffer is allocated, but | 81 // Create an AudioBuffer with |frame_count| frames. Buffer is allocated, but |
68 // not initialized. Timestamp and duration are set to kNoTimestamp. For | 82 // not initialized. Timestamp and duration are set to kNoTimestamp. For |
69 // optimal efficiency when many buffers are being created, a | 83 // optimal efficiency when many buffers are being created, a |
70 // AudioBufferMemoryPool can be provided to avoid thrashing memory. | 84 // AudioBufferMemoryPool can be provided to avoid thrashing memory. |
71 static scoped_refptr<AudioBuffer> CreateBuffer( | 85 static scoped_refptr<AudioBuffer> CreateBuffer( |
72 SampleFormat sample_format, | 86 SampleFormat sample_format, |
73 ChannelLayout channel_layout, | 87 ChannelLayout channel_layout, |
74 int channel_count, | 88 int channel_count, |
75 int sample_rate, | 89 int sample_rate, |
76 int frame_count, | 90 int frame_count, |
77 scoped_refptr<AudioBufferMemoryPool> pool = nullptr); | 91 scoped_refptr<AudioBufferMemoryPool> pool = nullptr); |
78 | 92 |
| 93 // Create an AudioBuffer for compressed bitstream. Buffer is allocated, but |
| 94 // not initialized. Timestamp and duration are set to kNoTimestamp. |
| 95 static scoped_refptr<AudioBuffer> CreateBitstreamBuffer( |
| 96 SampleFormat sample_format, |
| 97 ChannelLayout channel_layout, |
| 98 int channel_count, |
| 99 int sample_rate, |
| 100 int frame_count, |
| 101 size_t data_size, |
| 102 scoped_refptr<AudioBufferMemoryPool> pool = nullptr); |
| 103 |
79 // Create an empty AudioBuffer with |frame_count| frames. | 104 // Create an empty AudioBuffer with |frame_count| frames. |
80 static scoped_refptr<AudioBuffer> CreateEmptyBuffer( | 105 static scoped_refptr<AudioBuffer> CreateEmptyBuffer( |
81 ChannelLayout channel_layout, | 106 ChannelLayout channel_layout, |
82 int channel_count, | 107 int channel_count, |
83 int sample_rate, | 108 int sample_rate, |
84 int frame_count, | 109 int frame_count, |
85 const base::TimeDelta timestamp); | 110 const base::TimeDelta timestamp); |
86 | 111 |
87 // Create a AudioBuffer indicating we've reached end of stream. | 112 // Create a AudioBuffer indicating we've reached end of stream. |
88 // Calling any method other than end_of_stream() on the resulting buffer | 113 // Calling any method other than end_of_stream() on the resulting buffer |
(...skipping 23 matching lines...) Expand all Loading... |
112 void TrimStart(int frames_to_trim); | 137 void TrimStart(int frames_to_trim); |
113 | 138 |
114 // Trim an AudioBuffer by removing |frames_to_trim| frames from the end. | 139 // Trim an AudioBuffer by removing |frames_to_trim| frames from the end. |
115 // Duration is adjusted to reflect the fewer frames. | 140 // Duration is adjusted to reflect the fewer frames. |
116 void TrimEnd(int frames_to_trim); | 141 void TrimEnd(int frames_to_trim); |
117 | 142 |
118 // Trim an AudioBuffer by removing |end - start| frames from [|start|, |end|). | 143 // Trim an AudioBuffer by removing |end - start| frames from [|start|, |end|). |
119 // Even if |start| is zero, timestamp() is not adjusted, only duration(). | 144 // Even if |start| is zero, timestamp() is not adjusted, only duration(). |
120 void TrimRange(int start, int end); | 145 void TrimRange(int start, int end); |
121 | 146 |
| 147 // Return true if the buffer contains compressed bitstream. |
| 148 bool IsBitstreamFormat(); |
| 149 |
122 // Return the number of channels. | 150 // Return the number of channels. |
123 int channel_count() const { return channel_count_; } | 151 int channel_count() const { return channel_count_; } |
124 | 152 |
125 // Return the number of frames held. | 153 // Return the number of frames held. |
126 int frame_count() const { return adjusted_frame_count_; } | 154 int frame_count() const { return adjusted_frame_count_; } |
127 | 155 |
128 // Return the sample rate. | 156 // Return the sample rate. |
129 int sample_rate() const { return sample_rate_; } | 157 int sample_rate() const { return sample_rate_; } |
130 | 158 |
131 // Return the channel layout. | 159 // Return the channel layout. |
(...skipping 29 matching lines...) Expand all Loading... |
161 // [data,data+data_size) to the allocated buffer(s). If |data| is null, no | 189 // [data,data+data_size) to the allocated buffer(s). If |data| is null, no |
162 // data is copied. If |create_buffer| is false, no data buffer is created (or | 190 // data is copied. If |create_buffer| is false, no data buffer is created (or |
163 // copied to). | 191 // copied to). |
164 AudioBuffer(SampleFormat sample_format, | 192 AudioBuffer(SampleFormat sample_format, |
165 ChannelLayout channel_layout, | 193 ChannelLayout channel_layout, |
166 int channel_count, | 194 int channel_count, |
167 int sample_rate, | 195 int sample_rate, |
168 int frame_count, | 196 int frame_count, |
169 bool create_buffer, | 197 bool create_buffer, |
170 const uint8_t* const* data, | 198 const uint8_t* const* data, |
| 199 const size_t data_size, |
171 const base::TimeDelta timestamp, | 200 const base::TimeDelta timestamp, |
172 scoped_refptr<AudioBufferMemoryPool> pool); | 201 scoped_refptr<AudioBufferMemoryPool> pool); |
173 | 202 |
174 virtual ~AudioBuffer(); | 203 virtual ~AudioBuffer(); |
175 | 204 |
176 const SampleFormat sample_format_; | 205 const SampleFormat sample_format_; |
177 const ChannelLayout channel_layout_; | 206 const ChannelLayout channel_layout_; |
178 const int channel_count_; | 207 const int channel_count_; |
179 int sample_rate_; | 208 int sample_rate_; |
180 int adjusted_frame_count_; | 209 int adjusted_frame_count_; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 base::Lock entry_lock_; | 255 base::Lock entry_lock_; |
227 using MemoryEntry = std::pair<AudioMemory, size_t>; | 256 using MemoryEntry = std::pair<AudioMemory, size_t>; |
228 std::list<MemoryEntry> entries_; | 257 std::list<MemoryEntry> entries_; |
229 | 258 |
230 DISALLOW_COPY_AND_ASSIGN(AudioBufferMemoryPool); | 259 DISALLOW_COPY_AND_ASSIGN(AudioBufferMemoryPool); |
231 }; | 260 }; |
232 | 261 |
233 } // namespace media | 262 } // namespace media |
234 | 263 |
235 #endif // MEDIA_BASE_AUDIO_BUFFER_H_ | 264 #endif // MEDIA_BASE_AUDIO_BUFFER_H_ |
OLD | NEW |