gstbufferlist.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* GStreamer
  2. * Copyright (C) 2009 Axis Communications <dev-gstreamer at axis dot com>
  3. * @author Jonas Holmberg <jonas dot holmberg at axis dot com>
  4. *
  5. * gstbufferlist.h: Header for GstBufferList object
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Library General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the
  19. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  20. * Boston, MA 02110-1301, USA.
  21. */
  22. #ifndef __GST_BUFFER_LIST_H__
  23. #define __GST_BUFFER_LIST_H__
  24. #include <gst/gstbuffer.h>
  25. G_BEGIN_DECLS
  26. GST_EXPORT GType _gst_buffer_list_type;
  27. #define GST_TYPE_BUFFER_LIST (_gst_buffer_list_type)
  28. #define GST_IS_BUFFER_LIST(obj) (GST_IS_MINI_OBJECT_TYPE(obj, GST_TYPE_BUFFER_LIST))
  29. #define GST_BUFFER_LIST_CAST(obj) ((GstBufferList *)obj)
  30. #define GST_BUFFER_LIST(obj) (GST_BUFFER_LIST_CAST(obj))
  31. typedef struct _GstBufferList GstBufferList;
  32. /**
  33. * GstBufferListFunc:
  34. * @buffer: (out) (nullable): pointer the buffer
  35. * @idx: the index of @buffer
  36. * @user_data: user data passed to gst_buffer_list_foreach()
  37. *
  38. * A function that will be called from gst_buffer_list_foreach(). The @buffer
  39. * field will point to a the reference of the buffer at @idx.
  40. *
  41. * When this function returns %TRUE, the next buffer will be
  42. * returned. When %FALSE is returned, gst_buffer_list_foreach() will return.
  43. *
  44. * When @buffer is set to %NULL, the item will be removed from the bufferlist.
  45. * When @buffer has been made writable, the new buffer reference can be assigned
  46. * to @buffer. This function is responsible for unreffing the old buffer when
  47. * removing or modifying.
  48. *
  49. * Returns: %FALSE when gst_buffer_list_foreach() should stop
  50. */
  51. typedef gboolean (*GstBufferListFunc) (GstBuffer **buffer, guint idx,
  52. gpointer user_data);
  53. /* refcounting */
  54. /**
  55. * gst_buffer_list_ref:
  56. * @list: a #GstBufferList
  57. *
  58. * Increases the refcount of the given buffer list by one.
  59. *
  60. * Note that the refcount affects the writability of @list and its data, see
  61. * gst_buffer_list_make_writable(). It is important to note that keeping
  62. * additional references to GstBufferList instances can potentially increase
  63. * the number of memcpy operations in a pipeline.
  64. *
  65. * Returns: (transfer full): @list
  66. */
  67. #ifdef _FOOL_GTK_DOC_
  68. G_INLINE_FUNC GstBufferList * gst_buffer_list_ref (GstBufferList * list);
  69. #endif
  70. static inline GstBufferList *
  71. gst_buffer_list_ref (GstBufferList * list)
  72. {
  73. return GST_BUFFER_LIST_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST (
  74. list)));
  75. }
  76. /**
  77. * gst_buffer_list_unref:
  78. * @list: (transfer full): a #GstBufferList
  79. *
  80. * Decreases the refcount of the buffer list. If the refcount reaches 0, the
  81. * buffer list will be freed.
  82. */
  83. #ifdef _FOOL_GTK_DOC_
  84. G_INLINE_FUNC void gst_buffer_list_unref (GstBufferList * list);
  85. #endif
  86. static inline void
  87. gst_buffer_list_unref (GstBufferList * list)
  88. {
  89. gst_mini_object_unref (GST_MINI_OBJECT_CAST (list));
  90. }
  91. /* copy */
  92. /**
  93. * gst_buffer_list_copy:
  94. * @list: a #GstBufferList
  95. *
  96. * Create a shallow copy of the given buffer list. This will make a newly
  97. * allocated copy of the source list with copies of buffer pointers. The
  98. * refcount of buffers pointed to will be increased by one.
  99. *
  100. * Returns: (transfer full): a new copy of @list.
  101. */
  102. #ifdef _FOOL_GTK_DOC_
  103. G_INLINE_FUNC GstBufferList * gst_buffer_list_copy (const GstBufferList * list);
  104. #endif
  105. static inline GstBufferList *
  106. gst_buffer_list_copy (const GstBufferList * list)
  107. {
  108. return GST_BUFFER_LIST_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (list)));
  109. }
  110. /**
  111. * gst_buffer_list_is_writable:
  112. * @list: a #GstBufferList
  113. *
  114. * Tests if you can safely add buffers and groups into a buffer list.
  115. */
  116. #define gst_buffer_list_is_writable(list) gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (list))
  117. /**
  118. * gst_buffer_list_make_writable:
  119. * @list: (transfer full): a #GstBufferList
  120. *
  121. * Makes a writable buffer list from the given buffer list. If the source buffer
  122. * list is already writable, this will simply return the same buffer list. A
  123. * copy will otherwise be made using gst_buffer_list_copy().
  124. *
  125. * Returns: (transfer full): a writable list, which may or may not be the
  126. * same as @list
  127. */
  128. #define gst_buffer_list_make_writable(list) GST_BUFFER_LIST_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (list)))
  129. GType gst_buffer_list_get_type (void);
  130. /* allocation */
  131. GstBufferList * gst_buffer_list_new (void) G_GNUC_MALLOC;
  132. GstBufferList * gst_buffer_list_new_sized (guint size) G_GNUC_MALLOC;
  133. guint gst_buffer_list_length (GstBufferList *list);
  134. GstBuffer * gst_buffer_list_get (GstBufferList *list, guint idx);
  135. void gst_buffer_list_insert (GstBufferList *list, gint idx, GstBuffer *buffer);
  136. void gst_buffer_list_remove (GstBufferList *list, guint idx, guint length);
  137. gboolean gst_buffer_list_foreach (GstBufferList *list,
  138. GstBufferListFunc func,
  139. gpointer user_data);
  140. #define gst_buffer_list_add(l,b) gst_buffer_list_insert((l),-1,(b));
  141. G_END_DECLS
  142. #endif /* __GST_BUFFER_LIST_H__ */