diff options
author | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2013-03-29 14:46:00 +0100 |
---|---|---|
committer | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2013-03-29 16:07:23 +0100 |
commit | 5f79a8cb933e1b2a1fad54d854ff89495e621333 (patch) | |
tree | be8dc8089a1ec77ee12c9553b76f9d3e5327e504 | |
parent | 8fe9f5a6ea63b4ef7d57c659e1047ffcbf92797d (diff) |
videometa: API: Add GstVideoGLTextureUploadMeta
This allows elements to specify a function to upload
a buffer content to a specific OpenGL texture ID. It
could be used by the vaapi elements to provide a way
for eglglessink or WebKit to upload a VA surface to
an GL texture without the respective sinks knowing
anything about VA.
-rw-r--r-- | gst-libs/gst/video/gstvideometa.c | 89 | ||||
-rw-r--r-- | gst-libs/gst/video/gstvideometa.h | 37 |
2 files changed, 126 insertions, 0 deletions
diff --git a/gst-libs/gst/video/gstvideometa.c b/gst-libs/gst/video/gstvideometa.c index 74c24e2ff..b36b67a08 100644 --- a/gst-libs/gst/video/gstvideometa.c +++ b/gst-libs/gst/video/gstvideometa.c @@ -378,3 +378,92 @@ gst_video_meta_transform_scale_get_quark (void) } return _value; } + + +GType +gst_video_gl_texture_upload_meta_api_get_type (void) +{ + static volatile GType type = 0; + static const gchar *tags[] = { "memory", NULL }; + + if (g_once_init_enter (&type)) { + GType _type = + gst_meta_api_type_register ("GstVideoGLTextureUploadMetaAPI", tags); + g_once_init_leave (&type, _type); + } + return type; +} + +static void +gst_video_gl_texture_upload_meta_free (GstMeta * meta, GstBuffer * buffer) +{ + GstVideoGLTextureUploadMeta *vmeta = (GstVideoGLTextureUploadMeta *) meta; + + if (vmeta->destroy_notify) + vmeta->destroy_notify (vmeta->user_data); +} + +const GstMetaInfo * +gst_video_gl_texture_upload_meta_get_info (void) +{ + static const GstMetaInfo *info = NULL; + + if (g_once_init_enter (&info)) { + const GstMetaInfo *meta = + gst_meta_register (GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE, + "GstVideoGLTextureUploadMeta", + sizeof (GstVideoGLTextureUploadMeta), + NULL, + gst_video_gl_texture_upload_meta_free, + NULL); + g_once_init_leave (&info, meta); + } + return info; +} + +/** + * gst_buffer_add_video_meta: + * @buffer: a #GstBuffer + * @flags: #GstVideoFrameFlags + * @format: a #GstVideoFormat + * @width: the width + * @height: the height + * + * Attaches GstVideoMeta metadata to @buffer with the given parameters and the + * default offsets and strides for @format and @width x @height. + * + * This function calculates the default offsets and strides and then calls + * gst_buffer_add_video_meta_full() with them. + * + * Returns: the #GstVideoMeta on @buffer. + */ +GstVideoGLTextureUploadMeta * +gst_buffer_add_video_gl_texture_upload_meta (GstBuffer * buffer, + GstVideoGLTextureUpload upload, gpointer user_data, + GDestroyNotify destroy_notify) +{ + GstVideoGLTextureUploadMeta *meta; + + g_return_val_if_fail (buffer != NULL, NULL); + g_return_val_if_fail (upload != NULL, NULL); + + meta = + (GstVideoGLTextureUploadMeta *) gst_buffer_add_meta (buffer, + GST_VIDEO_GL_TEXTURE_UPLOAD_META_INFO, NULL); + + meta->buffer = buffer; + meta->upload = upload; + meta->user_data = user_data; + meta->destroy_notify = destroy_notify; + + return meta; +} + +gboolean +gst_video_gl_texture_upload_meta_upload (GstVideoGLTextureUploadMeta * meta, + guint format, guint texture_id) +{ + g_return_val_if_fail (meta != NULL, FALSE); + + return meta->upload (meta, format, texture_id); +} diff --git a/gst-libs/gst/video/gstvideometa.h b/gst-libs/gst/video/gstvideometa.h index 74f55bbec..5485c48cf 100644 --- a/gst-libs/gst/video/gstvideometa.h +++ b/gst-libs/gst/video/gstvideometa.h @@ -138,6 +138,43 @@ typedef struct { GstVideoInfo *out_info; } GstVideoMetaTransform; +#define GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE (gst_video_gl_texture_upload_meta_api_get_type()) +#define GST_VIDEO_GL_TEXTURE_UPLOAD_META_INFO (gst_video_gl_texture_upload_meta_get_info()) + +typedef struct _GstVideoGLTextureUploadMeta GstVideoGLTextureUploadMeta; +typedef gboolean (*GstVideoGLTextureUpload) (GstVideoGLTextureUploadMeta *meta, guint format, guint texture_id); + +/** + * GstVideoGLTextureUploadMeta: + * @meta: parent #GstMeta + * @buffer: the buffer of this meta + * @upload: the function to upload the buffer to a specific texture ID + * @user_data: user data for the implementor of @upload + * @destroy_notify: #GDestroyNotify for destroying @user_data + * + * Extra buffer metadata for uploading a buffer to an OpenGL texture + * ID. The caller of gst_video_gl_texture_upload_meta_upload() must + * have OpenGL set up and call this from a thread where it is valid + * to upload something to an OpenGL texture. + */ + +struct _GstVideoGLTextureUploadMeta { + GstMeta meta; + + GstBuffer *buffer; + GstVideoGLTextureUpload upload; + + gpointer user_data; + GDestroyNotify destroy_notify; +}; + +#define gst_buffer_get_video_gl_texture_upload_meta(b) ((GstVideoGLTextureUploadMeta*)gst_buffer_get_meta((b),GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE)) +GstVideoGLTextureUploadMeta * gst_buffer_add_video_gl_texture_upload_meta (GstBuffer *buffer, GstVideoGLTextureUpload upload, gpointer user_data, GDestroyNotify destroy_notify); +gboolean gst_video_gl_texture_upload_meta_upload (GstVideoGLTextureUploadMeta *meta, guint format, guint texture_id); + +GType gst_video_gl_texture_upload_meta_api_get_type (void); +const GstMetaInfo * gst_video_gl_texture_upload_meta_get_info (void); + G_END_DECLS #endif /* __GST_VIDEO_META_H__ */ |