mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-03 15:06:34 +00:00
[143/906] Add init and reset callbacks in GstGLFilter to run arbitrary gl code at start and stop. Useful to init and cleanup custom gl resources.
This commit is contained in:
parent
a54a462705
commit
ce17f1a2db
4 changed files with 215 additions and 173 deletions
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* GStreamer
|
* GStreamer
|
||||||
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
||||||
|
* Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Library General Public
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* GStreamer
|
* GStreamer
|
||||||
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
||||||
|
* Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Library General Public
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* GStreamer
|
* GStreamer
|
||||||
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
||||||
|
* Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Library General Public
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
@ -29,45 +30,48 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
||||||
|
|
||||||
|
|
||||||
static GstStaticPadTemplate gst_gl_filter_src_pad_template =
|
static GstStaticPadTemplate gst_gl_filter_src_pad_template =
|
||||||
GST_STATIC_PAD_TEMPLATE ("src",
|
GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
GST_PAD_SRC,
|
GST_PAD_SRC,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_STATIC_CAPS (GST_GL_VIDEO_CAPS)
|
GST_STATIC_CAPS (GST_GL_VIDEO_CAPS)
|
||||||
);
|
);
|
||||||
|
|
||||||
static GstStaticPadTemplate gst_gl_filter_sink_pad_template =
|
static GstStaticPadTemplate gst_gl_filter_sink_pad_template =
|
||||||
GST_STATIC_PAD_TEMPLATE ("sink",
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
||||||
GST_PAD_SINK,
|
GST_PAD_SINK,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_STATIC_CAPS (GST_GL_VIDEO_CAPS)
|
GST_STATIC_CAPS (GST_GL_VIDEO_CAPS)
|
||||||
);
|
);
|
||||||
|
|
||||||
#define DEBUG_INIT(bla) \
|
#define DEBUG_INIT(bla) \
|
||||||
GST_DEBUG_CATEGORY_INIT (gst_gl_filter_debug, "glfilter", 0, "glfilter element");
|
GST_DEBUG_CATEGORY_INIT (gst_gl_filter_debug, "glfilter", 0, "glfilter element");
|
||||||
|
|
||||||
GST_BOILERPLATE_FULL (GstGLFilter, gst_gl_filter, GstBaseTransform,
|
GST_BOILERPLATE_FULL (GstGLFilter, gst_gl_filter, GstBaseTransform,
|
||||||
GST_TYPE_BASE_TRANSFORM, DEBUG_INIT);
|
GST_TYPE_BASE_TRANSFORM, DEBUG_INIT);
|
||||||
|
|
||||||
static void gst_gl_filter_set_property (GObject * object, guint prop_id,
|
static void gst_gl_filter_set_property (GObject * object, guint prop_id,
|
||||||
const GValue * value, GParamSpec * pspec);
|
const GValue * value, GParamSpec * pspec);
|
||||||
static void gst_gl_filter_get_property (GObject * object, guint prop_id,
|
static void gst_gl_filter_get_property (GObject * object, guint prop_id,
|
||||||
GValue * value, GParamSpec * pspec);
|
GValue * value, GParamSpec * pspec);
|
||||||
|
|
||||||
static GstCaps* gst_gl_filter_transform_caps (GstBaseTransform* bt,
|
static GstCaps* gst_gl_filter_transform_caps (GstBaseTransform* bt,
|
||||||
GstPadDirection direction, GstCaps* caps);
|
GstPadDirection direction, GstCaps* caps);
|
||||||
static void gst_gl_filter_reset (GstGLFilter * filter);
|
static void gst_gl_filter_reset (GstGLFilter * filter);
|
||||||
static gboolean gst_gl_filter_start (GstBaseTransform * bt);
|
static gboolean gst_gl_filter_start (GstBaseTransform * bt);
|
||||||
static gboolean gst_gl_filter_stop (GstBaseTransform * bt);
|
static gboolean gst_gl_filter_stop (GstBaseTransform * bt);
|
||||||
static gboolean gst_gl_filter_get_unit_size (GstBaseTransform * trans,
|
static gboolean gst_gl_filter_get_unit_size (GstBaseTransform * trans,
|
||||||
GstCaps * caps, guint * size);
|
GstCaps * caps, guint * size);
|
||||||
static GstFlowReturn gst_gl_filter_transform (GstBaseTransform * bt,
|
static GstFlowReturn gst_gl_filter_transform (GstBaseTransform * bt,
|
||||||
GstBuffer * inbuf, GstBuffer * outbuf);
|
GstBuffer * inbuf, GstBuffer * outbuf);
|
||||||
static GstFlowReturn gst_gl_filter_prepare_output_buffer (GstBaseTransform *
|
static GstFlowReturn gst_gl_filter_prepare_output_buffer (GstBaseTransform *
|
||||||
trans, GstBuffer * input, gint size, GstCaps * caps, GstBuffer ** buf);
|
trans, GstBuffer * input, gint size, GstCaps * caps, GstBuffer ** buf);
|
||||||
static gboolean gst_gl_filter_set_caps (GstBaseTransform * bt, GstCaps * incaps,
|
static gboolean gst_gl_filter_set_caps (GstBaseTransform * bt, GstCaps * incaps,
|
||||||
GstCaps * outcaps);
|
GstCaps * outcaps);
|
||||||
static gboolean gst_gl_filter_do_transform (GstGLFilter * filter,
|
static gboolean gst_gl_filter_do_transform (GstGLFilter * filter,
|
||||||
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
|
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
|
||||||
|
/* GstGLDisplayThreadFunc */
|
||||||
|
static void gst_gl_filter_start_gl (GstGLDisplay *display, gpointer data);
|
||||||
|
static void gst_gl_filter_stop_gl (GstGLDisplay *display, gpointer data);
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -76,244 +80,271 @@ gst_gl_filter_base_init (gpointer klass)
|
||||||
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
||||||
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
gst_element_class_add_pad_template (element_class,
|
||||||
gst_static_pad_template_get (&gst_gl_filter_src_pad_template));
|
gst_static_pad_template_get (&gst_gl_filter_src_pad_template));
|
||||||
gst_element_class_add_pad_template (element_class,
|
gst_element_class_add_pad_template (element_class,
|
||||||
gst_static_pad_template_get (&gst_gl_filter_sink_pad_template));
|
gst_static_pad_template_get (&gst_gl_filter_sink_pad_template));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_gl_filter_class_init (GstGLFilterClass * klass)
|
gst_gl_filter_class_init (GstGLFilterClass * klass)
|
||||||
{
|
{
|
||||||
GObjectClass *gobject_class;
|
GObjectClass *gobject_class;
|
||||||
|
|
||||||
gobject_class = (GObjectClass *) klass;
|
gobject_class = (GObjectClass *) klass;
|
||||||
gobject_class->set_property = gst_gl_filter_set_property;
|
gobject_class->set_property = gst_gl_filter_set_property;
|
||||||
gobject_class->get_property = gst_gl_filter_get_property;
|
gobject_class->get_property = gst_gl_filter_get_property;
|
||||||
|
|
||||||
GST_BASE_TRANSFORM_CLASS (klass)->transform_caps =
|
GST_BASE_TRANSFORM_CLASS (klass)->transform_caps =
|
||||||
gst_gl_filter_transform_caps;
|
gst_gl_filter_transform_caps;
|
||||||
GST_BASE_TRANSFORM_CLASS (klass)->transform = gst_gl_filter_transform;
|
GST_BASE_TRANSFORM_CLASS (klass)->transform = gst_gl_filter_transform;
|
||||||
GST_BASE_TRANSFORM_CLASS (klass)->start = gst_gl_filter_start;
|
GST_BASE_TRANSFORM_CLASS (klass)->start = gst_gl_filter_start;
|
||||||
GST_BASE_TRANSFORM_CLASS (klass)->stop = gst_gl_filter_stop;
|
GST_BASE_TRANSFORM_CLASS (klass)->stop = gst_gl_filter_stop;
|
||||||
GST_BASE_TRANSFORM_CLASS (klass)->set_caps = gst_gl_filter_set_caps;
|
GST_BASE_TRANSFORM_CLASS (klass)->set_caps = gst_gl_filter_set_caps;
|
||||||
GST_BASE_TRANSFORM_CLASS (klass)->get_unit_size = gst_gl_filter_get_unit_size;
|
GST_BASE_TRANSFORM_CLASS (klass)->get_unit_size = gst_gl_filter_get_unit_size;
|
||||||
GST_BASE_TRANSFORM_CLASS (klass)->prepare_output_buffer =
|
GST_BASE_TRANSFORM_CLASS (klass)->prepare_output_buffer =
|
||||||
gst_gl_filter_prepare_output_buffer;
|
gst_gl_filter_prepare_output_buffer;
|
||||||
|
|
||||||
klass->set_caps = NULL;
|
klass->set_caps = NULL;
|
||||||
klass->filter = NULL;
|
klass->filter = NULL;
|
||||||
klass->onInitFBO = NULL;
|
klass->display_init_cb = NULL;
|
||||||
klass->onReset = NULL;
|
klass->display_reset_cb = NULL;
|
||||||
|
klass->onInitFBO = NULL;
|
||||||
|
klass->onReset = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_gl_filter_init (GstGLFilter * filter, GstGLFilterClass * klass)
|
gst_gl_filter_init (GstGLFilter * filter, GstGLFilterClass * klass)
|
||||||
{
|
{
|
||||||
//gst_element_create_all_pads (GST_ELEMENT (filter));
|
//gst_element_create_all_pads (GST_ELEMENT (filter));
|
||||||
|
|
||||||
filter->sinkpad = gst_element_get_static_pad (GST_ELEMENT (filter), "sink");
|
filter->sinkpad = gst_element_get_static_pad (GST_ELEMENT (filter), "sink");
|
||||||
filter->srcpad = gst_element_get_static_pad (GST_ELEMENT (filter), "src");
|
filter->srcpad = gst_element_get_static_pad (GST_ELEMENT (filter), "src");
|
||||||
|
|
||||||
gst_gl_filter_reset (filter);
|
gst_gl_filter_reset (filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_gl_filter_set_property (GObject * object, guint prop_id,
|
gst_gl_filter_set_property (GObject * object, guint prop_id,
|
||||||
const GValue * value, GParamSpec * pspec)
|
const GValue * value, GParamSpec * pspec)
|
||||||
{
|
{
|
||||||
//GstGLFilter *filter = GST_GL_FILTER (object);
|
//GstGLFilter *filter = GST_GL_FILTER (object);
|
||||||
|
|
||||||
switch (prop_id)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_gl_filter_get_property (GObject * object, guint prop_id,
|
gst_gl_filter_get_property (GObject * object, guint prop_id,
|
||||||
GValue * value, GParamSpec * pspec)
|
GValue * value, GParamSpec * pspec)
|
||||||
{
|
{
|
||||||
//GstGLFilter *filter = GST_GL_FILTER (object);
|
//GstGLFilter *filter = GST_GL_FILTER (object);
|
||||||
|
|
||||||
switch (prop_id)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_gl_filter_reset (GstGLFilter* filter)
|
gst_gl_filter_reset (GstGLFilter* filter)
|
||||||
{
|
{
|
||||||
GstGLFilterClass* filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
GstGLFilterClass* filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
||||||
|
|
||||||
if (filter_class->onReset)
|
if (filter_class->onReset)
|
||||||
filter_class->onReset (filter);
|
filter_class->onReset (filter);
|
||||||
|
|
||||||
if (filter->display)
|
if (filter->display)
|
||||||
{
|
{
|
||||||
//blocking call, delete the FBO
|
if (filter_class->display_reset_cb != NULL) {
|
||||||
gst_gl_display_del_fbo (filter->display, filter->fbo,
|
gst_gl_display_thread_add (filter->display, gst_gl_filter_stop_gl, filter);
|
||||||
filter->depthbuffer);
|
|
||||||
g_object_unref (filter->display);
|
|
||||||
filter->display = NULL;
|
|
||||||
}
|
}
|
||||||
filter->width = 0;
|
//blocking call, delete the FBO
|
||||||
filter->height = 0;
|
gst_gl_display_del_fbo (filter->display, filter->fbo,
|
||||||
filter->fbo = 0;
|
filter->depthbuffer);
|
||||||
filter->depthbuffer = 0;
|
g_object_unref (filter->display);
|
||||||
|
filter->display = NULL;
|
||||||
|
}
|
||||||
|
filter->width = 0;
|
||||||
|
filter->height = 0;
|
||||||
|
filter->fbo = 0;
|
||||||
|
filter->depthbuffer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_gl_filter_start (GstBaseTransform* bt)
|
gst_gl_filter_start (GstBaseTransform* bt)
|
||||||
{
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_gl_filter_stop (GstBaseTransform* bt)
|
gst_gl_filter_stop (GstBaseTransform* bt)
|
||||||
{
|
{
|
||||||
GstGLFilter *filter = GST_GL_FILTER (bt);
|
GstGLFilter *filter = GST_GL_FILTER (bt);
|
||||||
|
|
||||||
gst_gl_filter_reset (filter);
|
gst_gl_filter_reset (filter);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_gl_filter_start_gl (GstGLDisplay *display, gpointer data)
|
||||||
|
{
|
||||||
|
GstGLFilter *filter = GST_GL_FILTER (data);
|
||||||
|
GstGLFilterClass *filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
||||||
|
|
||||||
|
filter_class->display_init_cb (filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_gl_filter_stop_gl (GstGLDisplay *display, gpointer data)
|
||||||
|
{
|
||||||
|
GstGLFilter *filter = GST_GL_FILTER (data);
|
||||||
|
GstGLFilterClass *filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
||||||
|
|
||||||
|
filter_class->display_reset_cb (filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstCaps*
|
static GstCaps*
|
||||||
gst_gl_filter_transform_caps (GstBaseTransform* bt,
|
gst_gl_filter_transform_caps (GstBaseTransform* bt,
|
||||||
GstPadDirection direction, GstCaps* caps)
|
GstPadDirection direction, GstCaps* caps)
|
||||||
{
|
{
|
||||||
//GstGLFilter* filter = GST_GL_FILTER (bt);
|
//GstGLFilter* filter = GST_GL_FILTER (bt);
|
||||||
GstStructure* structure = gst_caps_get_structure (caps, 0);
|
GstStructure* structure = gst_caps_get_structure (caps, 0);
|
||||||
GstCaps* ret = gst_caps_copy (caps);
|
GstCaps* ret = gst_caps_copy (caps);
|
||||||
const GValue* par = NULL;
|
const GValue* par = NULL;
|
||||||
|
|
||||||
structure = gst_structure_copy (gst_caps_get_structure (ret, 0));
|
structure = gst_structure_copy (gst_caps_get_structure (ret, 0));
|
||||||
|
|
||||||
|
gst_structure_set (structure,
|
||||||
|
"width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
|
||||||
|
"height", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
|
||||||
|
|
||||||
|
gst_caps_merge_structure (ret, gst_structure_copy (structure));
|
||||||
|
|
||||||
|
if ((par = gst_structure_get_value (structure, "pixel-aspect-ratio")))
|
||||||
|
{
|
||||||
gst_structure_set (structure,
|
gst_structure_set (structure,
|
||||||
"width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
|
"pixel-aspect-ratio", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
|
||||||
"height", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
|
gst_caps_merge_structure (ret, structure);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
gst_structure_free (structure);
|
||||||
|
|
||||||
gst_caps_merge_structure (ret, gst_structure_copy (structure));
|
GST_DEBUG_OBJECT (bt, "returning caps: %" GST_PTR_FORMAT, ret);
|
||||||
|
|
||||||
if ((par = gst_structure_get_value (structure, "pixel-aspect-ratio")))
|
return ret;
|
||||||
{
|
|
||||||
gst_structure_set (structure,
|
|
||||||
"pixel-aspect-ratio", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
|
|
||||||
gst_caps_merge_structure (ret, structure);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
gst_structure_free (structure);
|
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (bt, "returning caps: %" GST_PTR_FORMAT, ret);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_gl_filter_get_unit_size (GstBaseTransform* trans, GstCaps* caps,
|
gst_gl_filter_get_unit_size (GstBaseTransform* trans, GstCaps* caps,
|
||||||
guint* size)
|
guint* size)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
gint width = 0;
|
gint width = 0;
|
||||||
gint height = 0;
|
gint height = 0;
|
||||||
|
|
||||||
ret = gst_gl_buffer_parse_caps (caps, &width, &height);
|
ret = gst_gl_buffer_parse_caps (caps, &width, &height);
|
||||||
if (ret)
|
if (ret)
|
||||||
*size = gst_gl_buffer_get_size (width, height);
|
*size = gst_gl_buffer_get_size (width, height);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_gl_filter_prepare_output_buffer (GstBaseTransform* trans,
|
gst_gl_filter_prepare_output_buffer (GstBaseTransform* trans,
|
||||||
GstBuffer* inbuf, gint size, GstCaps* caps, GstBuffer** buf)
|
GstBuffer* inbuf, gint size, GstCaps* caps, GstBuffer** buf)
|
||||||
{
|
{
|
||||||
GstGLFilter* filter = NULL;
|
GstGLFilter* filter = NULL;
|
||||||
GstGLBuffer* gl_inbuf = GST_GL_BUFFER (inbuf);
|
GstGLBuffer* gl_inbuf = GST_GL_BUFFER (inbuf);
|
||||||
GstGLBuffer* gl_outbuf = NULL;
|
GstGLBuffer* gl_outbuf = NULL;
|
||||||
|
|
||||||
filter = GST_GL_FILTER (trans);
|
filter = GST_GL_FILTER (trans);
|
||||||
|
|
||||||
if (filter->display == NULL)
|
if (filter->display == NULL)
|
||||||
{
|
{
|
||||||
GstGLFilterClass* filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
GstGLFilterClass* filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
||||||
|
|
||||||
filter->display = g_object_ref (gl_inbuf->display);
|
filter->display = g_object_ref (gl_inbuf->display);
|
||||||
|
|
||||||
//blocking call, generate a FBO
|
//blocking call, generate a FBO
|
||||||
gst_gl_display_gen_fbo (filter->display, filter->width, filter->height,
|
gst_gl_display_gen_fbo (filter->display, filter->width, filter->height,
|
||||||
&filter->fbo, &filter->depthbuffer);
|
&filter->fbo, &filter->depthbuffer);
|
||||||
|
|
||||||
if (filter_class->onInitFBO)
|
if (filter_class->display_init_cb != NULL) {
|
||||||
filter_class->onInitFBO (filter);
|
gst_gl_display_thread_add (filter->display, gst_gl_filter_start_gl, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
gl_outbuf = gst_gl_buffer_new (filter->display,
|
if (filter_class->onInitFBO)
|
||||||
filter->width, filter->height);
|
filter_class->onInitFBO (filter);
|
||||||
|
}
|
||||||
|
|
||||||
*buf = GST_BUFFER (gl_outbuf);
|
gl_outbuf = gst_gl_buffer_new (filter->display,
|
||||||
gst_buffer_set_caps (*buf, caps);
|
filter->width, filter->height);
|
||||||
|
|
||||||
if (gl_outbuf->texture)
|
*buf = GST_BUFFER (gl_outbuf);
|
||||||
return GST_FLOW_OK;
|
gst_buffer_set_caps (*buf, caps);
|
||||||
else
|
|
||||||
return GST_FLOW_UNEXPECTED;
|
if (gl_outbuf->texture)
|
||||||
|
return GST_FLOW_OK;
|
||||||
|
else
|
||||||
|
return GST_FLOW_UNEXPECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_gl_filter_set_caps (GstBaseTransform* bt, GstCaps* incaps,
|
gst_gl_filter_set_caps (GstBaseTransform* bt, GstCaps* incaps,
|
||||||
GstCaps* outcaps)
|
GstCaps* outcaps)
|
||||||
{
|
{
|
||||||
GstGLFilter* filter = GST_GL_FILTER (bt);
|
GstGLFilter* filter = GST_GL_FILTER (bt);
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
GstGLFilterClass* filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
GstGLFilterClass* filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
||||||
|
|
||||||
ret = gst_gl_buffer_parse_caps (outcaps, &filter->width, &filter->height);
|
ret = gst_gl_buffer_parse_caps (outcaps, &filter->width, &filter->height);
|
||||||
|
|
||||||
if (filter_class->set_caps)
|
if (filter_class->set_caps)
|
||||||
filter_class->set_caps (filter, incaps, outcaps);
|
filter_class->set_caps (filter, incaps, outcaps);
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
{
|
{
|
||||||
GST_DEBUG ("bad caps");
|
GST_DEBUG ("bad caps");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_ERROR ("set_caps %d %d", filter->width, filter->height);
|
GST_ERROR ("set_caps %d %d", filter->width, filter->height);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_gl_filter_transform (GstBaseTransform* bt, GstBuffer* inbuf,
|
gst_gl_filter_transform (GstBaseTransform* bt, GstBuffer* inbuf,
|
||||||
GstBuffer* outbuf)
|
GstBuffer* outbuf)
|
||||||
{
|
{
|
||||||
GstGLFilter* filter;
|
GstGLFilter* filter;
|
||||||
GstGLBuffer* gl_inbuf = GST_GL_BUFFER (inbuf);
|
GstGLBuffer* gl_inbuf = GST_GL_BUFFER (inbuf);
|
||||||
GstGLBuffer* gl_outbuf = GST_GL_BUFFER (outbuf);
|
GstGLBuffer* gl_outbuf = GST_GL_BUFFER (outbuf);
|
||||||
|
|
||||||
filter = GST_GL_FILTER (bt);
|
filter = GST_GL_FILTER (bt);
|
||||||
|
|
||||||
gst_gl_filter_do_transform (filter, gl_inbuf, gl_outbuf);
|
gst_gl_filter_do_transform (filter, gl_inbuf, gl_outbuf);
|
||||||
|
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_gl_filter_do_transform (GstGLFilter* filter,
|
gst_gl_filter_do_transform (GstGLFilter* filter,
|
||||||
GstGLBuffer* inbuf, GstGLBuffer* outbuf)
|
GstGLBuffer* inbuf, GstGLBuffer* outbuf)
|
||||||
{
|
{
|
||||||
GstGLFilterClass* filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
GstGLFilterClass* filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
||||||
|
|
||||||
filter_class->filter (filter, inbuf, outbuf);
|
filter_class->filter (filter, inbuf, outbuf);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* convenience functions to simplify filter development */
|
/* convenience functions to simplify filter development */
|
||||||
|
@ -323,11 +354,11 @@ gst_gl_filter_render_to_target (GstGLFilter *filter,
|
||||||
GLuint input, GLuint target,
|
GLuint input, GLuint target,
|
||||||
GLCB func, gpointer data)
|
GLCB func, gpointer data)
|
||||||
{
|
{
|
||||||
gst_gl_display_use_fbo (filter->display, filter->width, filter->height,
|
gst_gl_display_use_fbo (filter->display, filter->width, filter->height,
|
||||||
filter->fbo, filter->depthbuffer, target,
|
filter->fbo, filter->depthbuffer, target,
|
||||||
func,
|
func,
|
||||||
filter->width, filter->height, input,
|
filter->width, filter->height, input,
|
||||||
0, filter->width, 0, filter->height,
|
0, filter->width, 0, filter->height,
|
||||||
GST_GL_DISPLAY_PROJECTION_ORTHO2D,
|
GST_GL_DISPLAY_PROJECTION_ORTHO2D,
|
||||||
data);
|
data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* GStreamer
|
* GStreamer
|
||||||
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
||||||
|
* Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Library General Public
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
@ -40,34 +41,42 @@ typedef struct _GstGLFilterClass GstGLFilterClass;
|
||||||
|
|
||||||
|
|
||||||
typedef gboolean (*GstGLFilterSetCaps) (GstGLFilter* filter,
|
typedef gboolean (*GstGLFilterSetCaps) (GstGLFilter* filter,
|
||||||
GstCaps* incaps, GstCaps* outcaps);
|
GstCaps* incaps, GstCaps* outcaps);
|
||||||
typedef gboolean (*GstGLFilterProcessFunc) (GstGLFilter *filter,
|
typedef gboolean (*GstGLFilterProcessFunc) (GstGLFilter *filter,
|
||||||
GstGLBuffer *inbuf, GstGLBuffer *outbuf);
|
GstGLBuffer *inbuf, GstGLBuffer *outbuf);
|
||||||
typedef void (*GstGLFilterOnInitFBO) (GstGLFilter *filter);
|
typedef void (*GstGLFilterOnInitFBO) (GstGLFilter *filter);
|
||||||
typedef void (*GstGLFilterOnReset) (GstGLFilter *filter);
|
typedef void (*GstGLFilterOnReset) (GstGLFilter *filter);
|
||||||
|
|
||||||
|
typedef void (*GstGLFilterGLStartFunc) (GstGLFilter *filter);
|
||||||
|
typedef void (*GstGLFilterGLStopFunc) (GstGLFilter *filter);
|
||||||
|
|
||||||
struct _GstGLFilter
|
struct _GstGLFilter
|
||||||
{
|
{
|
||||||
GstBaseTransform base_transform;
|
GstBaseTransform base_transform;
|
||||||
|
|
||||||
GstPad *srcpad;
|
GstPad *srcpad;
|
||||||
GstPad *sinkpad;
|
GstPad *sinkpad;
|
||||||
|
|
||||||
GstGLDisplay *display;
|
GstGLDisplay *display;
|
||||||
|
|
||||||
gint width;
|
gint width;
|
||||||
gint height;
|
gint height;
|
||||||
GLuint fbo;
|
GLuint fbo;
|
||||||
GLuint depthbuffer;
|
GLuint depthbuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstGLFilterClass
|
struct _GstGLFilterClass
|
||||||
{
|
{
|
||||||
GstBaseTransformClass base_transform_class;
|
GstBaseTransformClass base_transform_class;
|
||||||
GstGLFilterSetCaps set_caps;
|
GstGLFilterSetCaps set_caps;
|
||||||
GstGLFilterProcessFunc filter;
|
GstGLFilterProcessFunc filter;
|
||||||
GstGLFilterOnInitFBO onInitFBO;
|
GstGLFilterOnInitFBO onInitFBO;
|
||||||
GstGLFilterOnReset onReset;
|
|
||||||
|
GstGLFilterOnReset onReset;
|
||||||
|
|
||||||
|
/* useful to init and cleanup custom gl resources */
|
||||||
|
GstGLFilterGLStartFunc display_init_cb; /* run arbitrary gl code at start */
|
||||||
|
GstGLFilterGLStopFunc display_reset_cb; /* run arbitrary gl code at stop */
|
||||||
};
|
};
|
||||||
|
|
||||||
GType gst_gl_filter_get_type(void);
|
GType gst_gl_filter_get_type(void);
|
||||||
|
|
Loading…
Reference in a new issue