OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 // A ring buffer to hold arbitrary data. Provides no thread safety. Unless | 11 // A ring buffer to hold arbitrary data. Provides no thread safety. Unless |
12 // otherwise specified, functions return 0 on success and -1 on error. | 12 // otherwise specified, functions return 0 on success and -1 on error. |
13 | 13 |
14 #include "webrtc/common_audio/ring_buffer.h" | 14 #include "webrtc/common_audio/ring_buffer.h" |
15 | 15 |
16 #include <stddef.h> // size_t | 16 #include <stddef.h> // size_t |
17 #include <stdlib.h> | 17 #include <stdlib.h> |
18 #include <string.h> | 18 #include <string.h> |
19 | 19 |
20 enum Wrap { | |
21 SAME_WRAP, | |
22 DIFF_WRAP | |
23 }; | |
24 | |
25 struct RingBuffer { | |
26 size_t read_pos; | |
27 size_t write_pos; | |
28 size_t element_count; | |
29 size_t element_size; | |
30 enum Wrap rw_wrap; | |
31 char* data; | |
32 }; | |
33 | |
34 // Get address of region(s) from which we can read data. | 20 // Get address of region(s) from which we can read data. |
35 // If the region is contiguous, |data_ptr_bytes_2| will be zero. | 21 // If the region is contiguous, |data_ptr_bytes_2| will be zero. |
36 // If non-contiguous, |data_ptr_bytes_2| will be the size in bytes of the second | 22 // If non-contiguous, |data_ptr_bytes_2| will be the size in bytes of the second |
37 // region. Returns room available to be read or |element_count|, whichever is | 23 // region. Returns room available to be read or |element_count|, whichever is |
38 // smaller. | 24 // smaller. |
39 static size_t GetBufferReadRegions(RingBuffer* buf, | 25 static size_t GetBufferReadRegions(RingBuffer* buf, |
40 size_t element_count, | 26 size_t element_count, |
41 void** data_ptr_1, | 27 void** data_ptr_1, |
42 size_t* data_ptr_bytes_1, | 28 size_t* data_ptr_bytes_1, |
43 void** data_ptr_2, | 29 void** data_ptr_2, |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 } | 224 } |
239 } | 225 } |
240 | 226 |
241 size_t WebRtc_available_write(const RingBuffer* self) { | 227 size_t WebRtc_available_write(const RingBuffer* self) { |
242 if (!self) { | 228 if (!self) { |
243 return 0; | 229 return 0; |
244 } | 230 } |
245 | 231 |
246 return self->element_count - WebRtc_available_read(self); | 232 return self->element_count - WebRtc_available_read(self); |
247 } | 233 } |
OLD | NEW |