From 8527e1cd6613fc9a147cdb10566aaaf20d5d14cf Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Fri, 6 Jul 2012 18:57:39 +1000 Subject: [PATCH] [516/906] add skeleton GstGLMeta the GstVideoMeta _map/unmap functions still need implementing --- gst-libs/gst/gl/Makefile.am | 2 + gst-libs/gst/gl/gstglmeta.c | 136 ++++++++++++++++++++++++++++++++++++ gst-libs/gst/gl/gstglmeta.h | 76 ++++++++++++++++++++ 3 files changed, 214 insertions(+) create mode 100644 gst-libs/gst/gl/gstglmeta.c create mode 100644 gst-libs/gst/gl/gstglmeta.h diff --git a/gst-libs/gst/gl/Makefile.am b/gst-libs/gst/gl/Makefile.am index 1b825ccbdb..5232446705 100644 --- a/gst-libs/gst/gl/Makefile.am +++ b/gst-libs/gst/gl/Makefile.am @@ -11,6 +11,7 @@ EXTRA_DIST = \ libgstgl_@GST_API_VERSION@_la_SOURCES = \ gstgldisplay.c \ gstglmemory.c \ + gstglmeta.c \ gstglfilter.c \ gstglmixer.c \ gstglshader.c \ @@ -34,6 +35,7 @@ libgstgl_@GST_API_VERSION@include_HEADERS = \ gstglwindow.h \ gstgldisplay.h \ gstglmemory.h \ + gstglmeta.h \ gstgles2.h \ gstglfilter.h \ gstglmixer.h \ diff --git a/gst-libs/gst/gl/gstglmeta.c b/gst-libs/gst/gl/gstglmeta.c new file mode 100644 index 0000000000..b60ce6348d --- /dev/null +++ b/gst-libs/gst/gl/gstglmeta.c @@ -0,0 +1,136 @@ +/* + * GStreamer + * Copyright (C) 2012 Matthew Waters + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include "gstglmeta.h" + +/* GstVideoMeta map/unmap */ +gboolean +gst_gl_meta_map (GstVideoMeta * meta, guint plane, GstMapInfo * info, + gpointer * data, gint * stride, GstMapFlags flags) +{ + return FALSE; +} + +gboolean +gst_gl_meta_unmap (GstVideoMeta * meta, guint plane, GstMapInfo * info) +{ + return FALSE; +} + +static void +gst_gl_meta_init (GstGLMeta * gl_meta, gpointer params, GstBuffer * buffer) +{ + gl_meta->buffer = buffer; +} + +void +gst_gl_meta_free (GstGLMeta * gl_meta, GstBuffer * buffer) +{ + if (gl_meta->display) { + g_object_unref (gl_meta->display); + gl_meta->display = NULL; + } +} + +static gboolean +gst_gl_meta_transform (GstBuffer * dest, GstMeta * meta, + GstBuffer * buffer, GQuark type, gpointer data) +{ + GstGLMeta *dmeta, *smeta; + + smeta = (GstGLMeta *) meta; + + if (GST_META_TRANSFORM_IS_COPY (type)) { + GstMetaTransformCopy *copy = data; + + if (!copy->region) { + /* only copy if the complete data is copied as well */ + dmeta = + (GstGLMeta *) gst_buffer_add_meta (dest, GST_GL_META_INFO, + smeta->display); + dmeta->buffer = dest; + + dmeta->memory = + (GstGLMemory *) gst_memory_copy (GST_MEMORY_CAST (smeta->memory), 0, + -1); + } + } + return TRUE; +} + +GType +gst_gl_meta_api_get_type (void) +{ + static volatile GType type; + static const gchar *tags[] = { "memory", NULL }; /* don't know what to set here */ + + if (g_once_init_enter (&type)) { + GType _type = gst_meta_api_type_register ("GstGLMetaAPI", tags); + g_once_init_leave (&type, _type); + } + return type; +} + +const GstMetaInfo * +gst_gl_meta_get_info (void) +{ + static const GstMetaInfo *gl_meta_info = NULL; + + if (gl_meta_info == NULL) { + gl_meta_info = + gst_meta_register (GST_GL_META_API_TYPE, "GstGLMeta", + sizeof (GstGLMeta), (GstMetaInitFunction) gst_gl_meta_init, + (GstMetaFreeFunction) gst_gl_meta_free, + (GstMetaTransformFunction) gst_gl_meta_transform); + } + return gl_meta_info; +} + +/** + * gst_buffer_add_gl_meta: + * @buffer: a #GstBuffer + * @display: the #GstGLDisplay to use + * + * Creates and adds a #GstGLMeta to a @buffer. + * + * Returns: (transfer full): a newly created #GstGLMeta + */ +GstGLMeta * +gst_buffer_add_gl_meta (GstBuffer * buffer, GstGLDisplay * display) +{ + GstGLMeta *gl_meta; + + gl_meta = (GstGLMeta *) gst_buffer_add_meta (buffer, GST_GL_META_INFO, NULL); + + gl_meta->display = g_object_ref (display); + + g_assert (gst_buffer_n_memory (buffer) == 1); + + gl_meta->memory = (GstGLMemory *) gst_buffer_get_memory (buffer, 0); + + return gl_meta; +} diff --git a/gst-libs/gst/gl/gstglmeta.h b/gst-libs/gst/gl/gstglmeta.h new file mode 100644 index 0000000000..f611d6dd23 --- /dev/null +++ b/gst-libs/gst/gl/gstglmeta.h @@ -0,0 +1,76 @@ +/* + * GStreame + * Copyright (C) 2007 Matthew Waters + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef _GST_GL_META_H_ +#define _GST_GL_META_H_ + +#include +#include +#include + +#include "gstgldisplay.h" +#include "gstglmemory.h" + +G_BEGIN_DECLS + +typedef struct _GstGLMeta GstGLMeta; + +GType gst_gl_meta_api_get_type (void); +#define GST_GL_META_API_TYPE (gst_gl_meta_api_get_type()) +#define GST_GL_META_INFO (gst_gl_meta_get_info()) +const GstMetaInfo * gst_gl_meta_get_info (void); + +/** + * GstGLMeta: + * @meta: parent #GstMeta + * @buffer: #GstBuffer this meta belongs to + * @video_meta: the #GstVideoMeta associated with this meta + * @display: the #GstGLDisplay + * @texture_id: the GL texture associated with this meta + * + * Extra buffer metadata describing OpenGL objects + */ +struct _GstGLMeta { + GstMeta meta; + GstBuffer *buffer; + + GstGLDisplay *display; + + GstGLMemory *memory; +}; + +#ifndef OPENGL_ES2 +# define GST_GL_VIDEO_CAPS \ + GST_VIDEO_CAPS_MAKE ("{ RGB, RGBx, RGBA, BGR, BGRx, BGRA, xRGB, xBGR, ARGB, ABGR, I420, YV12, YUY2, UYVY, AYUV }") +#else /* OPENGL_ES2 */ +# define GST_GL_VIDEO_CAPS \ + GST_VIDEO_CAPS_MAKE ("{ RGB, RGBx, RGBA, I420, YV12, YUY2, UYVY, AYUV }") +#endif /* OPENGL_ES2 */ + +#define gst_buffer_get_gl_meta(b) ((GstGLMeta*)gst_buffer_get_meta((b),GST_GL_META_API_TYPE)) +GstGLMeta * gst_buffer_add_gl_meta (GstBuffer * buffer, GstGLDisplay * display); + +gboolean gst_gl_meta_map (GstVideoMeta *meta, guint plane, GstMapInfo *info, + gpointer *data, gint * stride, GstMapFlags flags); +gboolean gst_gl_meta_unmap (GstVideoMeta *meta, guint plane, GstMapInfo *info); + +G_END_DECLS + +#endif /* _GST_GL_META_H_ */