buffer_internal.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef AVUTIL_BUFFER_INTERNAL_H
  19. #define AVUTIL_BUFFER_INTERNAL_H
  20. #include <stdint.h>
  21. #include "buffer.h"
  22. /**
  23. * The buffer is always treated as read-only.
  24. */
  25. #define BUFFER_FLAG_READONLY (1 << 0)
  26. /**
  27. * The buffer was av_realloc()ed, so it is reallocatable.
  28. */
  29. #define BUFFER_FLAG_REALLOCATABLE (1 << 1)
  30. struct AVBuffer {
  31. uint8_t *data; /**< data described by this buffer */
  32. int size; /**< size of data in bytes */
  33. /**
  34. * number of existing AVBufferRef instances referring to this buffer
  35. */
  36. volatile int refcount;
  37. /**
  38. * a callback for freeing the data
  39. */
  40. void (*free)(void *opaque, uint8_t *data);
  41. /**
  42. * an opaque pointer, to be used by the freeing callback
  43. */
  44. void *opaque;
  45. /**
  46. * A combination of BUFFER_FLAG_*
  47. */
  48. int flags;
  49. };
  50. typedef struct BufferPoolEntry {
  51. uint8_t *data;
  52. /*
  53. * Backups of the original opaque/free of the AVBuffer corresponding to
  54. * data. They will be used to free the buffer when the pool is freed.
  55. */
  56. void *opaque;
  57. void (*free)(void *opaque, uint8_t *data);
  58. AVBufferPool *pool;
  59. struct BufferPoolEntry * volatile next;
  60. } BufferPoolEntry;
  61. struct AVBufferPool {
  62. BufferPoolEntry * volatile pool;
  63. /*
  64. * This is used to track when the pool is to be freed.
  65. * The pointer to the pool itself held by the caller is considered to
  66. * be one reference. Each buffer requested by the caller increases refcount
  67. * by one, returning the buffer to the pool decreases it by one.
  68. * refcount reaches zero when the buffer has been uninited AND all the
  69. * buffers have been released, then it's safe to free the pool and all
  70. * the buffers in it.
  71. */
  72. volatile int refcount;
  73. volatile int nb_allocated;
  74. int size;
  75. AVBufferRef* (*alloc)(int size);
  76. };
  77. #endif /* AVUTIL_BUFFER_INTERNAL_H */