yading@11: /* yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #ifndef AVUTIL_BUFFER_INTERNAL_H yading@11: #define AVUTIL_BUFFER_INTERNAL_H yading@11: yading@11: #include yading@11: yading@11: #include "buffer.h" yading@11: yading@11: /** yading@11: * The buffer is always treated as read-only. yading@11: */ yading@11: #define BUFFER_FLAG_READONLY (1 << 0) yading@11: /** yading@11: * The buffer was av_realloc()ed, so it is reallocatable. yading@11: */ yading@11: #define BUFFER_FLAG_REALLOCATABLE (1 << 1) yading@11: yading@11: struct AVBuffer { yading@11: uint8_t *data; /**< data described by this buffer */ yading@11: int size; /**< size of data in bytes */ yading@11: yading@11: /** yading@11: * number of existing AVBufferRef instances referring to this buffer yading@11: */ yading@11: volatile int refcount; yading@11: yading@11: /** yading@11: * a callback for freeing the data yading@11: */ yading@11: void (*free)(void *opaque, uint8_t *data); yading@11: yading@11: /** yading@11: * an opaque pointer, to be used by the freeing callback yading@11: */ yading@11: void *opaque; yading@11: yading@11: /** yading@11: * A combination of BUFFER_FLAG_* yading@11: */ yading@11: int flags; yading@11: }; yading@11: yading@11: typedef struct BufferPoolEntry { yading@11: uint8_t *data; yading@11: yading@11: /* yading@11: * Backups of the original opaque/free of the AVBuffer corresponding to yading@11: * data. They will be used to free the buffer when the pool is freed. yading@11: */ yading@11: void *opaque; yading@11: void (*free)(void *opaque, uint8_t *data); yading@11: yading@11: AVBufferPool *pool; yading@11: struct BufferPoolEntry * volatile next; yading@11: } BufferPoolEntry; yading@11: yading@11: struct AVBufferPool { yading@11: BufferPoolEntry * volatile pool; yading@11: yading@11: /* yading@11: * This is used to track when the pool is to be freed. yading@11: * The pointer to the pool itself held by the caller is considered to yading@11: * be one reference. Each buffer requested by the caller increases refcount yading@11: * by one, returning the buffer to the pool decreases it by one. yading@11: * refcount reaches zero when the buffer has been uninited AND all the yading@11: * buffers have been released, then it's safe to free the pool and all yading@11: * the buffers in it. yading@11: */ yading@11: volatile int refcount; yading@11: yading@11: volatile int nb_allocated; yading@11: yading@11: int size; yading@11: AVBufferRef* (*alloc)(int size); yading@11: }; yading@11: yading@11: #endif /* AVUTIL_BUFFER_INTERNAL_H */