gstbufferpool.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /* GStreamer
  2. * Copyright (C) 2010 Wim Taymans <wim.taymans@gmail.com>
  3. *
  4. * gstbufferpool.h: Header for GstBufferPool object
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Library General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library 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. * Library General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Library General Public
  17. * License along with this library; if not, write to the
  18. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  19. * Boston, MA 02110-1301, USA.
  20. */
  21. #ifndef __GST_BUFFER_POOL_H__
  22. #define __GST_BUFFER_POOL_H__
  23. #include <gst/gstminiobject.h>
  24. #include <gst/gstpad.h>
  25. #include <gst/gstbuffer.h>
  26. G_BEGIN_DECLS
  27. typedef struct _GstBufferPoolPrivate GstBufferPoolPrivate;
  28. typedef struct _GstBufferPoolClass GstBufferPoolClass;
  29. #define GST_TYPE_BUFFER_POOL (gst_buffer_pool_get_type())
  30. #define GST_IS_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_BUFFER_POOL))
  31. #define GST_IS_BUFFER_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_BUFFER_POOL))
  32. #define GST_BUFFER_POOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_BUFFER_POOL, GstBufferPoolClass))
  33. #define GST_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_BUFFER_POOL, GstBufferPool))
  34. #define GST_BUFFER_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_BUFFER_POOL, GstBufferPoolClass))
  35. #define GST_BUFFER_POOL_CAST(obj) ((GstBufferPool *)(obj))
  36. /**
  37. * GstBufferPoolAcquireFlags:
  38. * @GST_BUFFER_POOL_ACQUIRE_FLAG_NONE: no flags
  39. * @GST_BUFFER_POOL_ACQUIRE_FLAG_KEY_UNIT: buffer is keyframe
  40. * @GST_BUFFER_POOL_ACQUIRE_FLAG_DONTWAIT: when the bufferpool is empty, acquire_buffer
  41. * will by default block until a buffer is released into the pool again. Setting
  42. * this flag makes acquire_buffer return #GST_FLOW_EOS instead of blocking.
  43. * @GST_BUFFER_POOL_ACQUIRE_FLAG_DISCONT: buffer is discont
  44. * @GST_BUFFER_POOL_ACQUIRE_FLAG_LAST: last flag, subclasses can use private flags
  45. * starting from this value.
  46. *
  47. * Additional flags to control the allocation of a buffer
  48. */
  49. typedef enum {
  50. GST_BUFFER_POOL_ACQUIRE_FLAG_NONE = 0,
  51. GST_BUFFER_POOL_ACQUIRE_FLAG_KEY_UNIT = (1 << 0),
  52. GST_BUFFER_POOL_ACQUIRE_FLAG_DONTWAIT = (1 << 1),
  53. GST_BUFFER_POOL_ACQUIRE_FLAG_DISCONT = (1 << 2),
  54. GST_BUFFER_POOL_ACQUIRE_FLAG_LAST = (1 << 16),
  55. } GstBufferPoolAcquireFlags;
  56. typedef struct _GstBufferPoolAcquireParams GstBufferPoolAcquireParams;
  57. /**
  58. * GstBufferPoolAcquireParams:
  59. * @format: the format of @start and @stop
  60. * @start: the start position
  61. * @stop: the stop position
  62. * @flags: additional flags
  63. *
  64. * Parameters passed to the gst_buffer_pool_acquire_buffer() function to control the
  65. * allocation of the buffer.
  66. *
  67. * The default implementation ignores the @start and @stop members but other
  68. * implementations can use this extra information to decide what buffer to
  69. * return.
  70. */
  71. struct _GstBufferPoolAcquireParams {
  72. GstFormat format;
  73. gint64 start;
  74. gint64 stop;
  75. GstBufferPoolAcquireFlags flags;
  76. /*< private >*/
  77. gpointer _gst_reserved[GST_PADDING];
  78. };
  79. /**
  80. * GST_BUFFER_POOL_IS_FLUSHING:
  81. * @pool: a GstBufferPool
  82. *
  83. * Check if the bufferpool is flushing. Subclasses might want to check the
  84. * state of the pool in the acquire function.
  85. */
  86. #define GST_BUFFER_POOL_IS_FLUSHING(pool) (g_atomic_int_get (&pool->flushing))
  87. /**
  88. * GstBufferPool:
  89. *
  90. * The structure of a #GstBufferPool. Use the associated macros to access the public
  91. * variables.
  92. */
  93. struct _GstBufferPool {
  94. GstObject object;
  95. /*< protected >*/
  96. gint flushing;
  97. /*< private >*/
  98. GstBufferPoolPrivate *priv;
  99. gpointer _gst_reserved[GST_PADDING];
  100. };
  101. /**
  102. * GstBufferPoolClass:
  103. * @object_class: Object parent class
  104. * @get_options: get a list of options supported by this pool
  105. * @set_config: apply the bufferpool configuration. The default configuration
  106. * will parse the default config parameters
  107. * @start: start the bufferpool. The default implementation will preallocate
  108. * min-buffers buffers and put them in the queue
  109. * @stop: stop the bufferpool. the default implementation will free the
  110. * preallocated buffers. This function is called when all the buffers are
  111. * returned to the pool.
  112. * @acquire_buffer: get a new buffer from the pool. The default implementation
  113. * will take a buffer from the queue and optionally wait for a buffer to
  114. * be released when there are no buffers available.
  115. * @alloc_buffer: allocate a buffer. the default implementation allocates
  116. * buffers from the configured memory allocator and with the configured
  117. * parameters. All metadata that is present on the allocated buffer will
  118. * be marked as #GST_META_FLAG_POOLED and #GST_META_FLAG_LOCKED and will
  119. * not be removed from the buffer in @reset_buffer. The buffer should
  120. * have the GST_BUFFER_FLAG_TAG_MEMORY cleared.
  121. * @reset_buffer: reset the buffer to its state when it was freshly allocated.
  122. * The default implementation will clear the flags, timestamps and
  123. * will remove the metadata without the #GST_META_FLAG_POOLED flag (even
  124. * the metadata with #GST_META_FLAG_LOCKED). If the
  125. * #GST_BUFFER_FLAG_TAG_MEMORY was set, this function can also try to
  126. * restore the memory and clear the #GST_BUFFER_FLAG_TAG_MEMORY again.
  127. * @release_buffer: release a buffer back in the pool. The default
  128. * implementation will put the buffer back in the queue and notify any
  129. * blocking acquire_buffer calls when the #GST_BUFFER_FLAG_TAG_MEMORY
  130. * is not set on the buffer. If #GST_BUFFER_FLAG_TAG_MEMORY is set, the
  131. * buffer will be freed with @free_buffer.
  132. * @free_buffer: free a buffer. The default implementation unrefs the buffer.
  133. * @flush_start: enter the flushing state. (Since 1.4)
  134. * @flush_stop: leave the flushign state. (Since 1.4)
  135. *
  136. * The GstBufferPool class.
  137. */
  138. struct _GstBufferPoolClass {
  139. GstObjectClass object_class;
  140. /*< public >*/
  141. const gchar ** (*get_options) (GstBufferPool *pool);
  142. gboolean (*set_config) (GstBufferPool *pool, GstStructure *config);
  143. gboolean (*start) (GstBufferPool *pool);
  144. gboolean (*stop) (GstBufferPool *pool);
  145. GstFlowReturn (*acquire_buffer) (GstBufferPool *pool, GstBuffer **buffer,
  146. GstBufferPoolAcquireParams *params);
  147. GstFlowReturn (*alloc_buffer) (GstBufferPool *pool, GstBuffer **buffer,
  148. GstBufferPoolAcquireParams *params);
  149. void (*reset_buffer) (GstBufferPool *pool, GstBuffer *buffer);
  150. void (*release_buffer) (GstBufferPool *pool, GstBuffer *buffer);
  151. void (*free_buffer) (GstBufferPool *pool, GstBuffer *buffer);
  152. void (*flush_start) (GstBufferPool *pool);
  153. void (*flush_stop) (GstBufferPool *pool);
  154. /*< private >*/
  155. gpointer _gst_reserved[GST_PADDING - 2];
  156. };
  157. GType gst_buffer_pool_get_type (void);
  158. /* allocation */
  159. GstBufferPool * gst_buffer_pool_new (void);
  160. /* state management */
  161. gboolean gst_buffer_pool_set_active (GstBufferPool *pool, gboolean active);
  162. gboolean gst_buffer_pool_is_active (GstBufferPool *pool);
  163. gboolean gst_buffer_pool_set_config (GstBufferPool *pool, GstStructure *config);
  164. GstStructure * gst_buffer_pool_get_config (GstBufferPool *pool);
  165. const gchar ** gst_buffer_pool_get_options (GstBufferPool *pool);
  166. gboolean gst_buffer_pool_has_option (GstBufferPool *pool, const gchar *option);
  167. void gst_buffer_pool_set_flushing (GstBufferPool *pool, gboolean flushing);
  168. /* helpers for configuring the config structure */
  169. void gst_buffer_pool_config_set_params (GstStructure *config, GstCaps *caps,
  170. guint size, guint min_buffers, guint max_buffers);
  171. gboolean gst_buffer_pool_config_get_params (GstStructure *config, GstCaps **caps,
  172. guint *size, guint *min_buffers, guint *max_buffers);
  173. void gst_buffer_pool_config_set_allocator (GstStructure *config, GstAllocator *allocator,
  174. const GstAllocationParams *params);
  175. gboolean gst_buffer_pool_config_get_allocator (GstStructure *config, GstAllocator **allocator,
  176. GstAllocationParams *params);
  177. /* options */
  178. guint gst_buffer_pool_config_n_options (GstStructure *config);
  179. void gst_buffer_pool_config_add_option (GstStructure *config, const gchar *option);
  180. const gchar * gst_buffer_pool_config_get_option (GstStructure *config, guint index);
  181. gboolean gst_buffer_pool_config_has_option (GstStructure *config, const gchar *option);
  182. gboolean gst_buffer_pool_config_validate_params (GstStructure *config, GstCaps *caps,
  183. guint size, guint min_buffers, guint max_buffers);
  184. /* buffer management */
  185. GstFlowReturn gst_buffer_pool_acquire_buffer (GstBufferPool *pool, GstBuffer **buffer,
  186. GstBufferPoolAcquireParams *params);
  187. void gst_buffer_pool_release_buffer (GstBufferPool *pool, GstBuffer *buffer);
  188. G_END_DECLS
  189. #endif /* __GST_BUFFER_POOL_H__ */