gstglmemory.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * GStreamer
  3. * Copyright (C) 2012 Matthew Waters <[email protected]>
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Library General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Library General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Library General Public
  16. * License along with this library; if not, write to the
  17. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  18. * Boston, MA 02110-1301, USA.
  19. */
  20. #ifndef _GST_GL_MEMORY_H_
  21. #define _GST_GL_MEMORY_H_
  22. #include <gst/gst.h>
  23. #include <gst/gstallocator.h>
  24. #include <gst/gstmemory.h>
  25. #include <gst/video/video.h>
  26. #include <gst/gl/gl.h>
  27. G_BEGIN_DECLS
  28. #define GST_TYPE_GL_ALLOCATOR (gst_gl_allocator_get_type())
  29. GType gst_gl_allocator_get_type(void);
  30. #define GST_IS_GL_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_GL_ALLOCATOR))
  31. #define GST_IS_GL_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_GL_ALLOCATOR))
  32. #define GST_GL_ALLOCATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_GL_ALLOCATOR, GstGLAllocatorClass))
  33. #define GST_GL_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_GL_ALLOCATOR, GstGLAllocator))
  34. #define GST_GL_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_GL_ALLOCATOR, GstGLAllocatorClass))
  35. #define GST_GL_ALLOCATOR_CAST(obj) ((GstGLAllocator *)(obj))
  36. /**
  37. * GstGLMemoryFlags:
  38. *
  39. * Flags indicating the current state of a #GstGLMemory
  40. */
  41. typedef enum
  42. {
  43. GST_GL_MEMORY_FLAG_DOWNLOAD_INITTED = (GST_MEMORY_FLAG_LAST << 0),
  44. GST_GL_MEMORY_FLAG_UPLOAD_INITTED = (GST_MEMORY_FLAG_LAST << 1),
  45. GST_GL_MEMORY_FLAG_NEED_DOWNLOAD = (GST_MEMORY_FLAG_LAST << 2),
  46. GST_GL_MEMORY_FLAG_NEED_UPLOAD = (GST_MEMORY_FLAG_LAST << 3)
  47. } GstGLMemoryFlags;
  48. /**
  49. * GST_MAP_GL:
  50. *
  51. * Flag indicating that we should map the GL object instead of to system memory.
  52. *
  53. * Combining #GST_MAP_GL with #GST_MAP_WRITE has the same semantics as though
  54. * you are writing to OpenGL. Conversely, combining #GST_MAP_GL with
  55. * #GST_MAP_READ has the same semantics as though you are reading from OpenGL.
  56. */
  57. #define GST_MAP_GL GST_MAP_FLAG_LAST << 1
  58. /**
  59. * GstGLMemory:
  60. * @mem: the parent object
  61. * @context: the #GstGLContext to use for GL operations
  62. * @tex_id: the texture id for this memory
  63. * @v_format: the video format of this texture
  64. * @gl_format: the format of the texture
  65. * @width: width of the texture
  66. * @height: height of the texture
  67. * @download: the object used to download this texture into @v_format
  68. * @upload: the object used to upload this texture from @v_format
  69. *
  70. * Represents information about a GL texture
  71. */
  72. struct _GstGLMemory
  73. {
  74. GstMemory mem;
  75. GstGLContext *context;
  76. guint tex_id;
  77. GstVideoGLTextureType tex_type;
  78. gint width;
  79. gint height;
  80. gint stride;
  81. gfloat tex_scaling[2];
  82. /* <private> */
  83. GstMapFlags map_flags;
  84. gpointer data;
  85. gboolean data_wrapped;
  86. gboolean texture_wrapped;
  87. GDestroyNotify notify;
  88. gpointer user_data;
  89. guint pbo;
  90. guint unpack_length;
  91. gpointer _gst_reserved[GST_PADDING];
  92. };
  93. #define GST_CAPS_FEATURE_MEMORY_GL_MEMORY "memory:GLMemory"
  94. /**
  95. * GST_GL_MEMORY_ALLOCATOR:
  96. *
  97. * The name of the GL memore allocator
  98. */
  99. #define GST_GL_MEMORY_ALLOCATOR "GLMemory"
  100. /**
  101. * GST_GL_MEMORY_FLAGS:
  102. * @mem: a #GstGLMemory
  103. *
  104. * Get the currently set flags on @mem
  105. */
  106. #define GST_GL_MEMORY_FLAGS(mem) GST_MEMORY_FLAGS(mem)
  107. /**
  108. * GST_GL_MEMORY_FLAG_IS_SET:
  109. * @mem: a #GstGLMemory
  110. * @flag: a flag
  111. *
  112. * Whether @flag is set on @mem
  113. */
  114. #define GST_GL_MEMORY_FLAG_IS_SET(mem,flag) GST_MEMORY_FLAG_IS_SET(mem,flag)
  115. /**
  116. * GST_GL_MEMORY_FLAG_SET:
  117. * @mem: a #GstGLMemory
  118. * @flag: a flag
  119. *
  120. * Set @flag on @mem
  121. */
  122. #define GST_GL_MEMORY_FLAG_SET(mem,flag) GST_MINI_OBJECT_FLAG_SET(mem,flag)
  123. /**
  124. * GST_GL_MEMORY_FLAG_UNSET:
  125. * @mem: a #GstGLMemory
  126. * @flag: a flag
  127. *
  128. * Unset @flag on @mem
  129. */
  130. #define GST_GL_MEMORY_FLAG_UNSET(mem,flag) GST_MEMORY_FLAG_UNSET(mem,flag)
  131. void gst_gl_memory_init (void);
  132. gboolean gst_is_gl_memory (GstMemory * mem);
  133. GstMemory * gst_gl_memory_alloc (GstGLContext * context, GstVideoGLTextureType tex_type,
  134. gint width, gint height, gint stride);
  135. GstGLMemory * gst_gl_memory_wrapped (GstGLContext * context, GstVideoGLTextureType tex_type,
  136. gint width, gint height, gint stride,
  137. gpointer data, gpointer user_data,
  138. GDestroyNotify notify);
  139. GstGLMemory * gst_gl_memory_wrapped_texture (GstGLContext * context, guint texture_id,
  140. GstVideoGLTextureType tex_type,
  141. gint width, gint height,
  142. gpointer user_data, GDestroyNotify notify);
  143. gboolean gst_gl_memory_copy_into_texture (GstGLMemory *gl_mem, guint tex_id,
  144. GstVideoGLTextureType tex_type,
  145. gint width, gint height, gint stride,
  146. gboolean respecify);
  147. gboolean gst_gl_memory_setup_buffer (GstGLContext * context, GstVideoInfo * info,
  148. GstBuffer * buffer);
  149. gboolean gst_gl_memory_setup_wrapped (GstGLContext * context, GstVideoInfo * info,
  150. gpointer data[GST_VIDEO_MAX_PLANES],
  151. GstGLMemory *textures[GST_VIDEO_MAX_PLANES]);
  152. GstVideoGLTextureType gst_gl_texture_type_from_format (GstGLContext *context, GstVideoFormat v_format, guint plane);
  153. /**
  154. * GstGLAllocator
  155. *
  156. * Opaque #GstGLAllocator struct
  157. */
  158. struct _GstGLAllocator
  159. {
  160. GstAllocator parent;
  161. };
  162. /**
  163. * GstGLAllocatorClass:
  164. *
  165. * The #GstGLAllocatorClass only contains private data
  166. */
  167. struct _GstGLAllocatorClass
  168. {
  169. GstAllocatorClass parent_class;
  170. };
  171. G_END_DECLS
  172. #endif /* _GST_GL_MEMORY_H_ */