annotate ffmpeg/libavutil/fifo.h @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * This file is part of FFmpeg.
yading@11 3 *
yading@11 4 * FFmpeg is free software; you can redistribute it and/or
yading@11 5 * modify it under the terms of the GNU Lesser General Public
yading@11 6 * License as published by the Free Software Foundation; either
yading@11 7 * version 2.1 of the License, or (at your option) any later version.
yading@11 8 *
yading@11 9 * FFmpeg is distributed in the hope that it will be useful,
yading@11 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 12 * Lesser General Public License for more details.
yading@11 13 *
yading@11 14 * You should have received a copy of the GNU Lesser General Public
yading@11 15 * License along with FFmpeg; if not, write to the Free Software
yading@11 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 17 */
yading@11 18
yading@11 19 /**
yading@11 20 * @file
yading@11 21 * a very simple circular buffer FIFO implementation
yading@11 22 */
yading@11 23
yading@11 24 #ifndef AVUTIL_FIFO_H
yading@11 25 #define AVUTIL_FIFO_H
yading@11 26
yading@11 27 #include <stdint.h>
yading@11 28 #include "avutil.h"
yading@11 29 #include "attributes.h"
yading@11 30
yading@11 31 typedef struct AVFifoBuffer {
yading@11 32 uint8_t *buffer;
yading@11 33 uint8_t *rptr, *wptr, *end;
yading@11 34 uint32_t rndx, wndx;
yading@11 35 } AVFifoBuffer;
yading@11 36
yading@11 37 /**
yading@11 38 * Initialize an AVFifoBuffer.
yading@11 39 * @param size of FIFO
yading@11 40 * @return AVFifoBuffer or NULL in case of memory allocation failure
yading@11 41 */
yading@11 42 AVFifoBuffer *av_fifo_alloc(unsigned int size);
yading@11 43
yading@11 44 /**
yading@11 45 * Free an AVFifoBuffer.
yading@11 46 * @param f AVFifoBuffer to free
yading@11 47 */
yading@11 48 void av_fifo_free(AVFifoBuffer *f);
yading@11 49
yading@11 50 /**
yading@11 51 * Reset the AVFifoBuffer to the state right after av_fifo_alloc, in particular it is emptied.
yading@11 52 * @param f AVFifoBuffer to reset
yading@11 53 */
yading@11 54 void av_fifo_reset(AVFifoBuffer *f);
yading@11 55
yading@11 56 /**
yading@11 57 * Return the amount of data in bytes in the AVFifoBuffer, that is the
yading@11 58 * amount of data you can read from it.
yading@11 59 * @param f AVFifoBuffer to read from
yading@11 60 * @return size
yading@11 61 */
yading@11 62 int av_fifo_size(AVFifoBuffer *f);
yading@11 63
yading@11 64 /**
yading@11 65 * Return the amount of space in bytes in the AVFifoBuffer, that is the
yading@11 66 * amount of data you can write into it.
yading@11 67 * @param f AVFifoBuffer to write into
yading@11 68 * @return size
yading@11 69 */
yading@11 70 int av_fifo_space(AVFifoBuffer *f);
yading@11 71
yading@11 72 /**
yading@11 73 * Feed data from an AVFifoBuffer to a user-supplied callback.
yading@11 74 * @param f AVFifoBuffer to read from
yading@11 75 * @param buf_size number of bytes to read
yading@11 76 * @param func generic read function
yading@11 77 * @param dest data destination
yading@11 78 */
yading@11 79 int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void (*func)(void*, void*, int));
yading@11 80
yading@11 81 /**
yading@11 82 * Feed data from a user-supplied callback to an AVFifoBuffer.
yading@11 83 * @param f AVFifoBuffer to write to
yading@11 84 * @param src data source; non-const since it may be used as a
yading@11 85 * modifiable context by the function defined in func
yading@11 86 * @param size number of bytes to write
yading@11 87 * @param func generic write function; the first parameter is src,
yading@11 88 * the second is dest_buf, the third is dest_buf_size.
yading@11 89 * func must return the number of bytes written to dest_buf, or <= 0 to
yading@11 90 * indicate no more data available to write.
yading@11 91 * If func is NULL, src is interpreted as a simple byte array for source data.
yading@11 92 * @return the number of bytes written to the FIFO
yading@11 93 */
yading@11 94 int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int));
yading@11 95
yading@11 96 /**
yading@11 97 * Resize an AVFifoBuffer.
yading@11 98 * In case of reallocation failure, the old FIFO is kept unchanged.
yading@11 99 *
yading@11 100 * @param f AVFifoBuffer to resize
yading@11 101 * @param size new AVFifoBuffer size in bytes
yading@11 102 * @return <0 for failure, >=0 otherwise
yading@11 103 */
yading@11 104 int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size);
yading@11 105
yading@11 106 /**
yading@11 107 * Enlarge an AVFifoBuffer.
yading@11 108 * In case of reallocation failure, the old FIFO is kept unchanged.
yading@11 109 * The new fifo size may be larger than the requested size.
yading@11 110 *
yading@11 111 * @param f AVFifoBuffer to resize
yading@11 112 * @param additional_space the amount of space in bytes to allocate in addition to av_fifo_size()
yading@11 113 * @return <0 for failure, >=0 otherwise
yading@11 114 */
yading@11 115 int av_fifo_grow(AVFifoBuffer *f, unsigned int additional_space);
yading@11 116
yading@11 117 /**
yading@11 118 * Read and discard the specified amount of data from an AVFifoBuffer.
yading@11 119 * @param f AVFifoBuffer to read from
yading@11 120 * @param size amount of data to read in bytes
yading@11 121 */
yading@11 122 void av_fifo_drain(AVFifoBuffer *f, int size);
yading@11 123
yading@11 124 /**
yading@11 125 * Return a pointer to the data stored in a FIFO buffer at a certain offset.
yading@11 126 * The FIFO buffer is not modified.
yading@11 127 *
yading@11 128 * @param f AVFifoBuffer to peek at, f must be non-NULL
yading@11 129 * @param offs an offset in bytes, its absolute value must be less
yading@11 130 * than the used buffer size or the returned pointer will
yading@11 131 * point outside to the buffer data.
yading@11 132 * The used buffer size can be checked with av_fifo_size().
yading@11 133 */
yading@11 134 static inline uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs)
yading@11 135 {
yading@11 136 uint8_t *ptr = f->rptr + offs;
yading@11 137 if (ptr >= f->end)
yading@11 138 ptr = f->buffer + (ptr - f->end);
yading@11 139 else if (ptr < f->buffer)
yading@11 140 ptr = f->end - (f->buffer - ptr);
yading@11 141 return ptr;
yading@11 142 }
yading@11 143
yading@11 144 #endif /* AVUTIL_FIFO_H */