You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.8KB

  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 <stdatomic.h>
  21. #include <stdint.h>
  22. #include "internal.h"
  23. #include "buffer.h"
  24. #include "thread.h"
  25. /**
  26. * The buffer was av_realloc()ed, so it is reallocatable.
  27. */
  28. #define BUFFER_FLAG_REALLOCATABLE (1 << 0)
  29. struct AVBuffer {
  30. uint8_t *data; /**< data described by this buffer */
  31. buffer_size_t size; /**< size of data in bytes */
  32. /**
  33. * number of existing AVBufferRef instances referring to this buffer
  34. */
  35. atomic_uint refcount;
  36. /**
  37. * a callback for freeing the data
  38. */
  39. void (*free)(void *opaque, uint8_t *data);
  40. /**
  41. * an opaque pointer, to be used by the freeing callback
  42. */
  43. void *opaque;
  44. /**
  45. * A combination of AV_BUFFER_FLAG_*
  46. */
  47. int flags;
  48. /**
  49. * A combination of BUFFER_FLAG_*
  50. */
  51. int flags_internal;
  52. };
  53. typedef struct BufferPoolEntry {
  54. uint8_t *data;
  55. /*
  56. * Backups of the original opaque/free of the AVBuffer corresponding to
  57. * data. They will be used to free the buffer when the pool is freed.
  58. */
  59. void *opaque;
  60. void (*free)(void *opaque, uint8_t *data);
  61. AVBufferPool *pool;
  62. struct BufferPoolEntry *next;
  63. } BufferPoolEntry;
  64. struct AVBufferPool {
  65. AVMutex mutex;
  66. BufferPoolEntry *pool;
  67. /*
  68. * This is used to track when the pool is to be freed.
  69. * The pointer to the pool itself held by the caller is considered to
  70. * be one reference. Each buffer requested by the caller increases refcount
  71. * by one, returning the buffer to the pool decreases it by one.
  72. * refcount reaches zero when the buffer has been uninited AND all the
  73. * buffers have been released, then it's safe to free the pool and all
  74. * the buffers in it.
  75. */
  76. atomic_uint refcount;
  77. buffer_size_t size;
  78. void *opaque;
  79. AVBufferRef* (*alloc)(buffer_size_t size);
  80. AVBufferRef* (*alloc2)(void *opaque, buffer_size_t size);
  81. void (*pool_free)(void *opaque);
  82. };
  83. #endif /* AVUTIL_BUFFER_INTERNAL_H */