framepool.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * Copyright (c) 2015 Matthieu Bouron <matthieu.bouron stupeflix.com>
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVFILTER_FRAMEPOOL_H
  21. #define AVFILTER_FRAMEPOOL_H
  22. #include "libavutil/buffer.h"
  23. #include "libavutil/frame.h"
  24. /**
  25. * Frame pool. This structure is opaque and not meant to be accessed
  26. * directly. It is allocated with ff_frame_pool_init() and freed with
  27. * ff_frame_pool_uninit().
  28. */
  29. typedef struct FFFramePool FFFramePool;
  30. /**
  31. * Allocate and initialize a video frame pool.
  32. *
  33. * @param alloc a function that will be used to allocate new frame buffers when
  34. * the pool is empty. May be NULL, then the default allocator will be used
  35. * (av_buffer_alloc()).
  36. * @param width width of each frame in this pool
  37. * @param height height of each frame in this pool
  38. * @param format format of each frame in this pool
  39. * @param align buffers alignement of each frame in this pool
  40. * @return newly created video frame pool on success, NULL on error.
  41. */
  42. FFFramePool *ff_frame_pool_video_init(AVBufferRef* (*alloc)(int size),
  43. int width,
  44. int height,
  45. enum AVPixelFormat format,
  46. int align);
  47. /**
  48. * Allocate and initialize an audio frame pool.
  49. *
  50. * @param alloc a function that will be used to allocate new frame buffers when
  51. * the pool is empty. May be NULL, then the default allocator will be used
  52. * (av_buffer_alloc()).
  53. * @param channels channels of each frame in this pool
  54. * @param nb_samples number of samples of each frame in this pool
  55. * @param format format of each frame in this pool
  56. * @param align buffers alignement of each frame in this pool
  57. * @return newly created audio frame pool on success, NULL on error.
  58. */
  59. FFFramePool *ff_frame_pool_audio_init(AVBufferRef* (*alloc)(int size),
  60. int channels,
  61. int samples,
  62. enum AVSampleFormat format,
  63. int align);
  64. /**
  65. * Deallocate the frame pool. It is safe to call this function while
  66. * some of the allocated frame are still in use.
  67. *
  68. * @param pool pointer to the frame pool to be freed. It will be set to NULL.
  69. */
  70. void ff_frame_pool_uninit(FFFramePool **pool);
  71. /**
  72. * Get the video frame pool configuration.
  73. *
  74. * @param width width of each frame in this pool
  75. * @param height height of each frame in this pool
  76. * @param format format of each frame in this pool
  77. * @param align buffers alignement of each frame in this pool
  78. * @return 0 on success, a negative AVERROR otherwise.
  79. */
  80. int ff_frame_pool_get_video_config(FFFramePool *pool,
  81. int *width,
  82. int *height,
  83. enum AVPixelFormat *format,
  84. int *align);
  85. /**
  86. * Get the audio frame pool configuration.
  87. *
  88. * @param channels channels of each frame in this pool
  89. * @param nb_samples number of samples of each frame in this pool
  90. * @param format format of each frame in this pool
  91. * @param align buffers alignement of each frame in this pool
  92. * @return 0 on success, a negative AVERROR otherwise.
  93. */
  94. int ff_frame_pool_get_audio_config(FFFramePool *pool,
  95. int *channels,
  96. int *nb_samples,
  97. enum AVSampleFormat *format,
  98. int *align);
  99. /**
  100. * Allocate a new AVFrame, reussing old buffers from the pool when available.
  101. * This function may be called simultaneously from multiple threads.
  102. *
  103. * @return a new AVFrame on success, NULL on error.
  104. */
  105. AVFrame *ff_frame_pool_get(FFFramePool *pool);
  106. #endif /* AVFILTER_FRAMEPOOL_H */