mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 01:00:37 +00:00
gl: add new gldownloadelement
Simply transforms caps to/from raw/glmemory capsfeatures
This commit is contained in:
parent
782b343f7d
commit
df50ba0491
4 changed files with 247 additions and 0 deletions
|
@ -4,6 +4,7 @@ libgstopengl_la_SOURCES = \
|
|||
gstopengl.c \
|
||||
gstglbasemixer.c \
|
||||
gstgluploadelement.c \
|
||||
gstgldownloadelement.c \
|
||||
gstglcolorconvertelement.c \
|
||||
gstglimagesink.c \
|
||||
gstglfiltercube.c \
|
||||
|
@ -21,6 +22,7 @@ libgstopengl_la_SOURCES = \
|
|||
noinst_HEADERS = \
|
||||
gstglbasemixer.h \
|
||||
gstgluploadelement.h \
|
||||
gstgldownloadelement.h \
|
||||
gstglcolorconvertelement.h \
|
||||
gstglimagesink.h \
|
||||
gstglfiltercube.h \
|
||||
|
|
183
ext/gl/gstgldownloadelement.c
Normal file
183
ext/gl/gstgldownloadelement.c
Normal file
|
@ -0,0 +1,183 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2012 Matthew Waters <ystree00@gmail.com>
|
||||
*
|
||||
* 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., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <gst/gl/gl.h>
|
||||
#include "gstgldownloadelement.h"
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (gst_gl_download_element_debug);
|
||||
#define GST_CAT_DEFAULT gst_gl_download_element_debug
|
||||
|
||||
#define gst_gl_download_element_parent_class parent_class
|
||||
G_DEFINE_TYPE_WITH_CODE (GstGLDownloadElement, gst_gl_download_element,
|
||||
GST_TYPE_GL_BASE_FILTER,
|
||||
GST_DEBUG_CATEGORY_INIT (gst_gl_download_element_debug, "gldownloadelement",
|
||||
0, "download element");
|
||||
);
|
||||
static void gst_gl_download_element_finalize (GObject * object);
|
||||
|
||||
static gboolean gst_gl_download_element_get_unit_size (GstBaseTransform * trans,
|
||||
GstCaps * caps, gsize * size);
|
||||
static GstCaps *gst_gl_download_element_transform_caps (GstBaseTransform * bt,
|
||||
GstPadDirection direction, GstCaps * caps, GstCaps * filter);
|
||||
static gboolean gst_gl_download_element_set_caps (GstBaseTransform * bt,
|
||||
GstCaps * in_caps, GstCaps * out_caps);
|
||||
static GstFlowReturn
|
||||
gst_gl_download_element_prepare_output_buffer (GstBaseTransform * bt,
|
||||
GstBuffer * buffer, GstBuffer ** outbuf);
|
||||
static GstFlowReturn gst_gl_download_element_transform (GstBaseTransform * bt,
|
||||
GstBuffer * buffer, GstBuffer * outbuf);
|
||||
|
||||
static GstStaticPadTemplate gst_gl_download_element_src_pad_template =
|
||||
GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS ("video/x-raw; video/x-raw(memory:GLMemory)"));
|
||||
|
||||
static GstStaticPadTemplate gst_gl_download_element_sink_pad_template =
|
||||
GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS ("video/x-raw(memory:GLMemory)"));
|
||||
|
||||
static void
|
||||
gst_gl_download_element_class_init (GstGLDownloadElementClass * klass)
|
||||
{
|
||||
GstBaseTransformClass *bt_class = GST_BASE_TRANSFORM_CLASS (klass);
|
||||
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
||||
|
||||
bt_class->transform_caps = gst_gl_download_element_transform_caps;
|
||||
bt_class->set_caps = gst_gl_download_element_set_caps;
|
||||
bt_class->get_unit_size = gst_gl_download_element_get_unit_size;
|
||||
bt_class->prepare_output_buffer =
|
||||
gst_gl_download_element_prepare_output_buffer;
|
||||
bt_class->transform = gst_gl_download_element_transform;
|
||||
|
||||
bt_class->passthrough_on_same_caps = TRUE;
|
||||
|
||||
gst_element_class_add_pad_template (element_class,
|
||||
gst_static_pad_template_get (&gst_gl_download_element_src_pad_template));
|
||||
gst_element_class_add_pad_template (element_class,
|
||||
gst_static_pad_template_get (&gst_gl_download_element_sink_pad_template));
|
||||
|
||||
gst_element_class_set_metadata (element_class,
|
||||
"OpenGL uploader", "Filter/Video",
|
||||
"Uploads data into OpenGL", "Matthew Waters <matthew@centricular.com>");
|
||||
|
||||
G_OBJECT_CLASS (klass)->finalize = gst_gl_download_element_finalize;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_gl_download_element_init (GstGLDownloadElement * download)
|
||||
{
|
||||
gst_base_transform_set_prefer_passthrough (GST_BASE_TRANSFORM (download),
|
||||
TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_gl_download_element_finalize (GObject * object)
|
||||
{
|
||||
G_OBJECT_CLASS (gst_gl_download_element_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_gl_download_element_set_caps (GstBaseTransform * bt, GstCaps * in_caps,
|
||||
GstCaps * out_caps)
|
||||
{
|
||||
GstVideoInfo out_info;
|
||||
|
||||
if (!gst_video_info_from_caps (&out_info, out_caps))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GstCaps *
|
||||
_set_caps_features (const GstCaps * caps, const gchar * feature_name)
|
||||
{
|
||||
GstCaps *tmp = gst_caps_copy (caps);
|
||||
guint n = gst_caps_get_size (tmp);
|
||||
guint i = 0;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
gst_caps_set_features (tmp, i,
|
||||
gst_caps_features_from_string (feature_name));
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static GstCaps *
|
||||
gst_gl_download_element_transform_caps (GstBaseTransform * bt,
|
||||
GstPadDirection direction, GstCaps * caps, GstCaps * filter)
|
||||
{
|
||||
GstCaps *result, *tmp;
|
||||
|
||||
if (direction == GST_PAD_SRC) {
|
||||
tmp = _set_caps_features (caps, GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
|
||||
tmp = gst_caps_merge (gst_caps_ref (caps), tmp);
|
||||
} else {
|
||||
tmp = _set_caps_features (caps, GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY);
|
||||
tmp = gst_caps_merge (gst_caps_ref (caps), tmp);
|
||||
}
|
||||
|
||||
if (filter) {
|
||||
result = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
|
||||
gst_caps_unref (tmp);
|
||||
} else {
|
||||
result = tmp;
|
||||
}
|
||||
|
||||
GST_DEBUG_OBJECT (bt, "returning caps %" GST_PTR_FORMAT, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_gl_download_element_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
|
||||
gsize * size)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
GstVideoInfo info;
|
||||
|
||||
ret = gst_video_info_from_caps (&info, caps);
|
||||
if (ret)
|
||||
*size = GST_VIDEO_INFO_SIZE (&info);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GstFlowReturn
|
||||
gst_gl_download_element_prepare_output_buffer (GstBaseTransform * bt,
|
||||
GstBuffer * inbuf, GstBuffer ** outbuf)
|
||||
{
|
||||
*outbuf = inbuf;
|
||||
|
||||
return GST_FLOW_OK;
|
||||
}
|
||||
|
||||
static GstFlowReturn
|
||||
gst_gl_download_element_transform (GstBaseTransform * bt,
|
||||
GstBuffer * inbuf, GstBuffer * outbuf)
|
||||
{
|
||||
return GST_FLOW_OK;
|
||||
}
|
56
ext/gl/gstgldownloadelement.h
Normal file
56
ext/gl/gstgldownloadelement.h
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2012 Matthew Waters <ystree00@gmail.com>
|
||||
*
|
||||
* 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., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GST_GL_DOWNLOAD_ELEMENT_H__
|
||||
#define __GST_GL_DOWNLOAD_ELEMENT_H__
|
||||
|
||||
#include <gst/video/video.h>
|
||||
#include <gst/gstmemory.h>
|
||||
|
||||
#include <gst/gl/gl.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
GType gst_gl_download_element_get_type (void);
|
||||
#define GST_TYPE_GL_DOWNLOAD_ELEMENT (gst_gl_download_element_get_type())
|
||||
#define GST_GL_DOWNLOAD_ELEMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GL_DOWNLOAD_ELEMENT,GstGLDownloadElement))
|
||||
#define GST_GL_DOWNLOAD_ELEMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_GL_DISPLAY,GstGLDownloadElementClass))
|
||||
#define GST_IS_GL_DOWNLOAD_ELEMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GL_DOWNLOAD_ELEMENT))
|
||||
#define GST_IS_GL_DOWNLOAD_ELEMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_GL_DOWNLOAD_ELEMENT))
|
||||
#define GST_GL_DOWNLOAD_ELEMENT_CAST(obj) ((GstGLDownloadElement*)(obj))
|
||||
|
||||
typedef struct _GstGLDownloadElement GstGLDownloadElement;
|
||||
typedef struct _GstGLDownloadElementClass GstGLDownloadElementClass;
|
||||
|
||||
struct _GstGLDownloadElement
|
||||
{
|
||||
/* <private> */
|
||||
GstGLBaseFilter parent;
|
||||
};
|
||||
|
||||
struct _GstGLDownloadElementClass
|
||||
{
|
||||
/* <private> */
|
||||
GstGLBaseFilterClass object_class;
|
||||
};
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_GL_DOWNLOAD_ELEMENT_H__ */
|
|
@ -45,6 +45,7 @@
|
|||
|
||||
#include "gstglimagesink.h"
|
||||
#include "gstgluploadelement.h"
|
||||
#include "gstgldownloadelement.h"
|
||||
#include "gstglcolorconvertelement.h"
|
||||
|
||||
#include "gstglfiltercube.h"
|
||||
|
@ -119,6 +120,11 @@ plugin_init (GstPlugin * plugin)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gst_element_register (plugin, "gldownload",
|
||||
GST_RANK_SECONDARY, GST_TYPE_GL_DOWNLOAD_ELEMENT)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gst_element_register (plugin, "glcolorconvert",
|
||||
GST_RANK_SECONDARY, GST_TYPE_GL_COLOR_CONVERT_ELEMENT)) {
|
||||
return FALSE;
|
||||
|
|
Loading…
Reference in a new issue