Home | History | Annotate | Download | only in utility
      1 /*
      2  *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
      3  *
      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
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     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.
     13 
     14 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_RING_BUFFER_H_
     15 #define WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_RING_BUFFER_H_
     16 
     17 #include <stddef.h> // size_t
     18 
     19 int WebRtc_CreateBuffer(void** handle,
     20                         size_t element_count,
     21                         size_t element_size);
     22 int WebRtc_InitBuffer(void* handle);
     23 int WebRtc_FreeBuffer(void* handle);
     24 
     25 // Reads data from the buffer. The |data_ptr| will point to the address where
     26 // it is located. If all |element_count| data are feasible to read without
     27 // buffer wrap around |data_ptr| will point to the location in the buffer.
     28 // Otherwise, the data will be copied to |data| (memory allocation done by the
     29 // user) and |data_ptr| points to the address of |data|. |data_ptr| is only
     30 // guaranteed to be valid until the next call to WebRtc_WriteBuffer().
     31 // Returns number of elements read.
     32 size_t WebRtc_ReadBuffer(void* handle,
     33                          void** data_ptr,
     34                          void* data,
     35                          size_t element_count);
     36 
     37 // Writes |data| to buffer and returns the number of elements written.
     38 size_t WebRtc_WriteBuffer(void* handle, const void* data, size_t element_count);
     39 
     40 // Moves the buffer read position and returns the number of elements moved.
     41 // Positive |element_count| moves the read position towards the write position,
     42 // that is, flushing the buffer. Negative |element_count| moves the read
     43 // position away from the the write position, that is, stuffing the buffer.
     44 // Returns number of elements moved.
     45 int WebRtc_MoveReadPtr(void* handle, int element_count);
     46 
     47 // Returns number of available elements to read.
     48 size_t WebRtc_available_read(const void* handle);
     49 
     50 // Returns number of available elements for write.
     51 size_t WebRtc_available_write(const void* handle);
     52 
     53 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_RING_BUFFER_H_
     54