gstallocator.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* GStreamer
  2. * Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.be>
  3. *
  4. * gstallocator.h: Header for memory allocation
  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_ALLOCATOR_H__
  22. #define __GST_ALLOCATOR_H__
  23. #include <gst/gstmemory.h>
  24. #include <gst/gstobject.h>
  25. G_BEGIN_DECLS
  26. typedef struct _GstAllocatorPrivate GstAllocatorPrivate;
  27. typedef struct _GstAllocatorClass GstAllocatorClass;
  28. #define GST_TYPE_ALLOCATOR (gst_allocator_get_type())
  29. #define GST_IS_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_ALLOCATOR))
  30. #define GST_IS_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_ALLOCATOR))
  31. #define GST_ALLOCATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_ALLOCATOR, GstAllocatorClass))
  32. #define GST_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_ALLOCATOR, GstAllocator))
  33. #define GST_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_ALLOCATOR, GstAllocatorClass))
  34. #define GST_ALLOCATOR_CAST(obj) ((GstAllocator *)(obj))
  35. #define GST_TYPE_ALLOCATION_PARAMS (gst_allocation_params_get_type())
  36. GType gst_allocation_params_get_type(void);
  37. typedef struct _GstAllocationParams GstAllocationParams;
  38. /**
  39. * gst_memory_alignment:
  40. *
  41. * The default memory alignment in bytes - 1
  42. * an alignment of 7 would be the same as what malloc() guarantees.
  43. */
  44. GST_EXPORT gsize gst_memory_alignment;
  45. /**
  46. * GST_ALLOCATOR_SYSMEM:
  47. *
  48. * The allocator name for the default system memory allocator
  49. */
  50. #define GST_ALLOCATOR_SYSMEM "SystemMemory"
  51. /**
  52. * GstAllocationParams:
  53. * @flags: flags to control allocation
  54. * @align: the desired alignment of the memory
  55. * @prefix: the desired prefix
  56. * @padding: the desired padding
  57. *
  58. * Parameters to control the allocation of memory
  59. */
  60. struct _GstAllocationParams {
  61. GstMemoryFlags flags;
  62. gsize align;
  63. gsize prefix;
  64. gsize padding;
  65. /*< private >*/
  66. gpointer _gst_reserved[GST_PADDING];
  67. };
  68. /**
  69. * GstAllocatorFlags:
  70. * @GST_ALLOCATOR_FLAG_CUSTOM_ALLOC: The allocator has a custom alloc function.
  71. * @GST_ALLOCATOR_FLAG_LAST: first flag that can be used for custom purposes
  72. *
  73. * Flags for allocators.
  74. */
  75. typedef enum {
  76. GST_ALLOCATOR_FLAG_CUSTOM_ALLOC = (GST_OBJECT_FLAG_LAST << 0),
  77. GST_ALLOCATOR_FLAG_LAST = (GST_OBJECT_FLAG_LAST << 16)
  78. } GstAllocatorFlags;
  79. /**
  80. * GstAllocator:
  81. * @mem_map: the implementation of the GstMemoryMapFunction
  82. * @mem_unmap: the implementation of the GstMemoryUnmapFunction
  83. * @mem_copy: the implementation of the GstMemoryCopyFunction
  84. * @mem_share: the implementation of the GstMemoryShareFunction
  85. * @mem_is_span: the implementation of the GstMemoryIsSpanFunction
  86. * @mem_map_full: the implementation of the GstMemoryMapFullFunction.
  87. * Will be used instead of @mem_map if present. (Since 1.6)
  88. * @mem_unmap_full: the implementation of the GstMemoryUnmapFullFunction.
  89. * Will be used instead of @mem_unmap if present. (Since 1.6)
  90. *
  91. * The #GstAllocator is used to create new memory.
  92. */
  93. struct _GstAllocator
  94. {
  95. GstObject object;
  96. const gchar *mem_type;
  97. /*< public >*/
  98. GstMemoryMapFunction mem_map;
  99. GstMemoryUnmapFunction mem_unmap;
  100. GstMemoryCopyFunction mem_copy;
  101. GstMemoryShareFunction mem_share;
  102. GstMemoryIsSpanFunction mem_is_span;
  103. GstMemoryMapFullFunction mem_map_full;
  104. GstMemoryUnmapFullFunction mem_unmap_full;
  105. /*< private >*/
  106. gpointer _gst_reserved[GST_PADDING - 2];
  107. GstAllocatorPrivate *priv;
  108. };
  109. /**
  110. * GstAllocatorClass:
  111. * @object_class: Object parent class
  112. * @alloc: implementation that acquires memory
  113. * @free: implementation that releases memory
  114. *
  115. * The #GstAllocator is used to create new memory.
  116. */
  117. struct _GstAllocatorClass {
  118. GstObjectClass object_class;
  119. /*< public >*/
  120. GstMemory * (*alloc) (GstAllocator *allocator, gsize size,
  121. GstAllocationParams *params);
  122. void (*free) (GstAllocator *allocator, GstMemory *memory);
  123. /*< private >*/
  124. gpointer _gst_reserved[GST_PADDING];
  125. };
  126. GType gst_allocator_get_type(void);
  127. /* allocators */
  128. void gst_allocator_register (const gchar *name, GstAllocator *allocator);
  129. GstAllocator * gst_allocator_find (const gchar *name);
  130. void gst_allocator_set_default (GstAllocator * allocator);
  131. /* allocation parameters */
  132. void gst_allocation_params_init (GstAllocationParams *params);
  133. GstAllocationParams *
  134. gst_allocation_params_copy (const GstAllocationParams *params) G_GNUC_MALLOC;
  135. void gst_allocation_params_free (GstAllocationParams *params);
  136. /* allocating memory blocks */
  137. GstMemory * gst_allocator_alloc (GstAllocator * allocator, gsize size,
  138. GstAllocationParams *params);
  139. void gst_allocator_free (GstAllocator * allocator, GstMemory *memory);
  140. GstMemory * gst_memory_new_wrapped (GstMemoryFlags flags, gpointer data, gsize maxsize,
  141. gsize offset, gsize size, gpointer user_data,
  142. GDestroyNotify notify);
  143. #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
  144. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstAllocationParams, gst_allocation_params_free)
  145. #endif
  146. G_END_DECLS
  147. #endif /* __GST_ALLOCATOR_H__ */