00001 /* 00002 * iaxclient: a cross-platform IAX softphone library 00003 * 00004 * Copyrights: 00005 * Copyright (c) 1999-2000 Ross Bencina and Phil Burk 00006 * Copyright (C) 2007, Wimba, Inc. 00007 * 00008 * Contributors: 00009 * <see below> 00010 * Peter Grayson <jpgrayson@gmail.com> 00011 * 00012 * This program is free software, distributed under the terms of 00013 * the GNU Lesser (Library) General Public License. 00014 */ 00015 00016 /* 00017 * Ring Buffer utility. 00018 * 00019 * Author: Phil Burk, http://www.softsynth.com 00020 * modified for SMP safety on OS X by Bjorn Roche. 00021 * also allowed for const where possible. 00022 * Note that this is safe only for a single-thread reader 00023 * and a single-thread writer. 00024 * 00025 * Originally distributed with the PortAudio Portable Audio Library. 00026 * For more information see: http://www.portaudio.com 00027 * Copyright (c) 1999-2000 Ross Bencina and Phil Burk 00028 * 00029 * Permission is hereby granted, free of charge, to any person obtaining 00030 * a copy of this software and associated documentation files 00031 * (the "Software"), to deal in the Software without restriction, 00032 * including without limitation the rights to use, copy, modify, merge, 00033 * publish, distribute, sublicense, and/or sell copies of the Software, 00034 * and to permit persons to whom the Software is furnished to do so, 00035 * subject to the following conditions: 00036 * 00037 * The above copyright notice and this permission notice shall be 00038 * included in all copies or substantial portions of the Software. 00039 * 00040 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00041 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00042 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00043 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 00044 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 00045 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00046 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00047 */ 00048 00049 /* 00050 * The text above constitutes the entire PortAudio license; however, 00051 * the PortAudio community also makes the following non-binding requests: 00052 * 00053 * Any person wishing to distribute modifications to the Software is 00054 * requested to send the modifications to the original developer so that 00055 * they can be incorporated into the canonical version. It is also 00056 * requested that these non-binding requests be included along with the 00057 * license above. 00058 */ 00059 00060 #ifndef RINGBUFFER_H 00061 #define RINGBUFFER_H 00062 00063 #ifdef __cplusplus 00064 extern "C" 00065 { 00066 #endif /* __cplusplus */ 00067 00068 typedef struct rb_RingBuffer 00069 { 00070 long bufferSize; /* Number of bytes in FIFO. Power of 2. Set by rb_InitializeRingBuffer. */ 00071 long writeIndex; /* Index of next writable byte. Set by rb_AdvanceRingBufferWriteIndex. */ 00072 long readIndex; /* Index of next readable byte. Set by rb_AdvanceRingBufferReadIndex. */ 00073 long bigMask; /* Used for wrapping indices with extra bit to distinguish full/empty. */ 00074 long smallMask; /* Used for fitting indices to buffer. */ 00075 char *buffer; 00076 }rb_RingBuffer; 00077 00089 long rb_InitializeRingBuffer( rb_RingBuffer *rbuf, long numBytes, void *dataPtr ); 00090 00095 void rb_FlushRingBuffer( rb_RingBuffer *rbuf ); 00096 00103 long rb_GetRingBufferWriteAvailable( rb_RingBuffer *rbuf ); 00104 00111 long rb_GetRingBufferReadAvailable( rb_RingBuffer *rbuf ); 00112 00123 long rb_WriteRingBuffer( rb_RingBuffer *rbuf, const void *data, long numBytes ); 00124 00135 long rb_ReadRingBuffer( rb_RingBuffer *rbuf, void *data, long numBytes ); 00136 00157 long rb_GetRingBufferWriteRegions( rb_RingBuffer *rbuf, long numBytes, 00158 void **dataPtr1, long *sizePtr1, 00159 void **dataPtr2, long *sizePtr2 ); 00160 00169 long rb_AdvanceRingBufferWriteIndex( rb_RingBuffer *rbuf, long numBytes ); 00170 00191 long rb_GetRingBufferReadRegions( rb_RingBuffer *rbuf, long numBytes, 00192 void **dataPtr1, long *sizePtr1, 00193 void **dataPtr2, long *sizePtr2 ); 00194 00203 long rb_AdvanceRingBufferReadIndex( rb_RingBuffer *rbuf, long numBytes ); 00204 00205 #ifdef __cplusplus 00206 } 00207 #endif /* __cplusplus */ 00208 #endif /* RINGBUFFER_H */