container_fifo.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 AVCODEC_CONTAINER_FIFO_H
  19. #define AVCODEC_CONTAINER_FIFO_H
  20. #include <stddef.h>
  21. /**
  22. * ContainerFifo is a FIFO for "containers" - dynamically allocated reusable
  23. * structs (e.g. AVFrame or AVPacket). ContainerFifo uses an internal pool of
  24. * such containers to avoid allocating and freeing them repeatedly.
  25. */
  26. typedef struct ContainerFifo ContainerFifo;
  27. /**
  28. * Allocate a new ContainerFifo for the container type defined by provided
  29. * callbacks.
  30. *
  31. * @param container_alloc allocate a new container instance and return a pointer
  32. * to it, or NULL on failure
  33. * @param container_reset reset the provided container instance to a clean state
  34. * @param container_free free the provided container instance
  35. * @param fifo_write transfer the contents of src to dst, where src is a
  36. * container instance provided to ff_container_fifo_write()
  37. * @param fifo_read transfer the contents of src to dst in other cases
  38. *
  39. * @note fifo_read() and fifo_write() are different parameters in order to allow
  40. * fifo_write() implementations that make a new reference in dst, leaving
  41. * src untouched (see e.g. ff_container_fifo_alloc_avframe())
  42. */
  43. ContainerFifo*
  44. ff_container_fifo_alloc(void* (*container_alloc)(void),
  45. void (*container_reset)(void *obj),
  46. void (*container_free) (void *obj),
  47. int (*fifo_write) (void *dst, void *src),
  48. int (*fifo_read) (void *dst, void *src));
  49. /**
  50. * Allocate a ContainerFifo instance for AVFrames.
  51. * Note that ff_container_fifo_write() will call av_frame_ref() on src, making a
  52. * new reference in dst and leaving src untouched.
  53. *
  54. * @param flags unused currently
  55. */
  56. ContainerFifo *ff_container_fifo_alloc_avframe(unsigned flags);
  57. /**
  58. * Free a ContainerFifo and everything in it.
  59. */
  60. void ff_container_fifo_free(ContainerFifo **pf);
  61. /**
  62. * Write the contents of obj to the FIFO.
  63. *
  64. * The fifo_write() callback previously provided to ff_container_fifo_alloc()
  65. * will be called with obj as src in order to perform the actual transfer.
  66. */
  67. int ff_container_fifo_write(ContainerFifo *pf, void *obj);
  68. /**
  69. * Read the next available object from the FIFO into obj.
  70. *
  71. * The fifo_read() callback previously provided to ff_container_fifo_alloc()
  72. * will be called with obj as dst in order to perform the actual transfer.
  73. */
  74. int ff_container_fifo_read(ContainerFifo *pf, void *obj);
  75. /**
  76. * @return number of objects available for reading
  77. */
  78. size_t ff_container_fifo_can_read(ContainerFifo *pf);
  79. #endif // AVCODEC_CONTAINER_FIFO_H