2008-08-11 13:40:39 +00:00
|
|
|
/*
|
2008-06-11 18:33:53 +00:00
|
|
|
* GStreamer
|
2008-09-20 13:44:24 +00:00
|
|
|
* Copyright (C) 2007 David Schleef <ds@schleef.org>
|
2008-06-11 18:33:53 +00:00
|
|
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
2008-08-11 07:52:16 +00:00
|
|
|
* Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
|
2008-06-11 18:33:53 +00:00
|
|
|
*
|
|
|
|
* 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
|
2012-11-08 11:53:56 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2008-06-11 18:33:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstglfilter.h"
|
|
|
|
|
|
|
|
#define GST_CAT_DEFAULT gst_gl_filter_debug
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
|
|
|
|
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_gl_filter_src_pad_template =
|
2013-11-14 04:27:52 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
2009-02-11 06:39:14 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2013-11-14 04:27:52 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (GST_GL_DOWNLOAD_FORMATS) "; "
|
|
|
|
GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
|
|
|
(GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META,
|
|
|
|
"RGBA"))
|
2008-06-11 18:33:53 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_gl_filter_sink_pad_template =
|
2013-11-14 04:27:52 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
2009-02-11 06:39:14 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2013-11-14 04:27:52 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (GST_GL_UPLOAD_FORMATS) "; "
|
|
|
|
GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
|
|
|
(GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META,
|
|
|
|
"RGBA"))
|
2008-06-11 18:33:53 +00:00
|
|
|
);
|
|
|
|
|
2009-11-17 22:47:24 +00:00
|
|
|
/* Properties */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2013-08-29 14:22:31 +00:00
|
|
|
PROP_OTHER_CONTEXT
|
2009-11-17 22:47:24 +00:00
|
|
|
};
|
|
|
|
|
2012-05-30 03:46:21 +00:00
|
|
|
#define DEBUG_INIT \
|
2008-06-11 18:33:53 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_gl_filter_debug, "glfilter", 0, "glfilter element");
|
2012-08-15 06:52:48 +00:00
|
|
|
#define gst_gl_filter_parent_class parent_class
|
2012-05-30 03:46:21 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstGLFilter, gst_gl_filter, GST_TYPE_BASE_TRANSFORM,
|
|
|
|
DEBUG_INIT);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
|
|
|
static void gst_gl_filter_set_property (GObject * object, guint prop_id,
|
2009-02-11 06:39:14 +00:00
|
|
|
const GValue * value, GParamSpec * pspec);
|
2008-06-11 18:33:53 +00:00
|
|
|
static void gst_gl_filter_get_property (GObject * object, guint prop_id,
|
2009-02-11 06:39:14 +00:00
|
|
|
GValue * value, GParamSpec * pspec);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2013-11-12 23:43:16 +00:00
|
|
|
static void gst_gl_filter_set_context (GstElement * element,
|
|
|
|
GstContext * context);
|
2012-08-15 06:52:48 +00:00
|
|
|
static gboolean gst_gl_filter_query (GstBaseTransform * trans,
|
|
|
|
GstPadDirection direction, GstQuery * query);
|
2009-02-11 06:39:14 +00:00
|
|
|
static GstCaps *gst_gl_filter_transform_caps (GstBaseTransform * bt,
|
2012-06-03 10:40:53 +00:00
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * filter);
|
2012-09-25 07:59:27 +00:00
|
|
|
static GstCaps *gst_gl_filter_fixate_caps (GstBaseTransform * bt,
|
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
|
2008-06-11 18:33:53 +00:00
|
|
|
static void gst_gl_filter_reset (GstGLFilter * filter);
|
|
|
|
static gboolean gst_gl_filter_start (GstBaseTransform * bt);
|
|
|
|
static gboolean gst_gl_filter_stop (GstBaseTransform * bt);
|
|
|
|
static gboolean gst_gl_filter_get_unit_size (GstBaseTransform * trans,
|
2012-06-03 10:40:53 +00:00
|
|
|
GstCaps * caps, gsize * size);
|
2008-06-11 18:33:53 +00:00
|
|
|
static GstFlowReturn gst_gl_filter_transform (GstBaseTransform * bt,
|
2009-02-11 06:39:14 +00:00
|
|
|
GstBuffer * inbuf, GstBuffer * outbuf);
|
2012-07-09 12:27:48 +00:00
|
|
|
static gboolean gst_gl_filter_propose_allocation (GstBaseTransform * trans,
|
|
|
|
GstQuery * decide_query, GstQuery * query);
|
|
|
|
static gboolean gst_gl_filter_decide_allocation (GstBaseTransform * trans,
|
|
|
|
GstQuery * query);
|
2008-06-11 18:33:53 +00:00
|
|
|
static gboolean gst_gl_filter_set_caps (GstBaseTransform * bt, GstCaps * incaps,
|
2009-02-11 06:39:14 +00:00
|
|
|
GstCaps * outcaps);
|
2012-06-03 10:40:53 +00:00
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
/* GstGLContextThreadFunc */
|
|
|
|
static void gst_gl_filter_start_gl (GstGLContext * context, gpointer data);
|
|
|
|
static void gst_gl_filter_stop_gl (GstGLContext * context, gpointer data);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_filter_class_init (GstGLFilterClass * klass)
|
|
|
|
{
|
2008-08-11 07:52:16 +00:00
|
|
|
GObjectClass *gobject_class;
|
2012-05-30 03:46:21 +00:00
|
|
|
GstElementClass *element_class;
|
2008-08-11 07:52:16 +00:00
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
2012-06-03 10:40:53 +00:00
|
|
|
element_class = GST_ELEMENT_CLASS (klass);
|
2012-05-30 03:46:21 +00:00
|
|
|
|
2012-06-03 10:40:53 +00:00
|
|
|
gobject_class->set_property = gst_gl_filter_set_property;
|
2008-08-11 07:52:16 +00:00
|
|
|
gobject_class->get_property = gst_gl_filter_get_property;
|
|
|
|
|
|
|
|
GST_BASE_TRANSFORM_CLASS (klass)->transform_caps =
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_filter_transform_caps;
|
2012-09-25 07:59:27 +00:00
|
|
|
GST_BASE_TRANSFORM_CLASS (klass)->fixate_caps = gst_gl_filter_fixate_caps;
|
2008-08-11 07:52:16 +00:00
|
|
|
GST_BASE_TRANSFORM_CLASS (klass)->transform = gst_gl_filter_transform;
|
2012-08-15 06:52:48 +00:00
|
|
|
GST_BASE_TRANSFORM_CLASS (klass)->query = gst_gl_filter_query;
|
2008-08-11 07:52:16 +00:00
|
|
|
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)->set_caps = gst_gl_filter_set_caps;
|
2012-07-09 12:27:48 +00:00
|
|
|
GST_BASE_TRANSFORM_CLASS (klass)->propose_allocation =
|
|
|
|
gst_gl_filter_propose_allocation;
|
|
|
|
GST_BASE_TRANSFORM_CLASS (klass)->decide_allocation =
|
|
|
|
gst_gl_filter_decide_allocation;
|
2008-08-11 07:52:16 +00:00
|
|
|
GST_BASE_TRANSFORM_CLASS (klass)->get_unit_size = gst_gl_filter_get_unit_size;
|
|
|
|
|
2013-11-12 23:43:16 +00:00
|
|
|
element_class->set_context = gst_gl_filter_set_context;
|
|
|
|
|
2013-08-29 14:22:31 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_OTHER_CONTEXT,
|
|
|
|
g_param_spec_object ("other-context",
|
2009-11-17 22:47:24 +00:00
|
|
|
"External OpenGL context",
|
|
|
|
"Give an external OpenGL context with which to share textures",
|
2013-08-29 14:22:31 +00:00
|
|
|
GST_GL_TYPE_CONTEXT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-11-17 22:47:24 +00:00
|
|
|
|
2012-05-30 03:46:21 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&gst_gl_filter_src_pad_template));
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&gst_gl_filter_sink_pad_template));
|
|
|
|
|
2008-08-11 07:52:16 +00:00
|
|
|
klass->set_caps = NULL;
|
|
|
|
klass->filter = NULL;
|
|
|
|
klass->display_init_cb = NULL;
|
|
|
|
klass->display_reset_cb = NULL;
|
|
|
|
klass->onInitFBO = NULL;
|
2008-08-14 18:02:04 +00:00
|
|
|
klass->onStart = NULL;
|
|
|
|
klass->onStop = NULL;
|
2008-08-11 07:52:16 +00:00
|
|
|
klass->onReset = NULL;
|
2012-09-18 14:32:30 +00:00
|
|
|
klass->filter_texture = NULL;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-30 03:46:21 +00:00
|
|
|
gst_gl_filter_init (GstGLFilter * filter)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2008-08-11 07:52:16 +00:00
|
|
|
gst_gl_filter_reset (filter);
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_filter_set_property (GObject * object, guint prop_id,
|
2009-02-11 06:39:14 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2009-11-17 22:47:24 +00:00
|
|
|
GstGLFilter *filter = GST_GL_FILTER (object);
|
2008-08-11 07:52:16 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
switch (prop_id) {
|
2013-08-29 14:22:31 +00:00
|
|
|
case PROP_OTHER_CONTEXT:
|
2009-11-17 22:47:24 +00:00
|
|
|
{
|
2013-08-29 14:22:31 +00:00
|
|
|
if (filter->other_context)
|
|
|
|
gst_object_unref (filter->other_context);
|
|
|
|
filter->other_context = g_value_dup_object (value);
|
2009-11-17 22:47:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-02-11 06:39:14 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2008-08-11 07:52:16 +00:00
|
|
|
}
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_filter_get_property (GObject * object, guint prop_id,
|
2009-02-11 06:39:14 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2013-07-17 23:42:31 +00:00
|
|
|
GstGLFilter *filter = GST_GL_FILTER (object);
|
2008-08-11 07:52:16 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
switch (prop_id) {
|
2013-08-29 14:22:31 +00:00
|
|
|
case PROP_OTHER_CONTEXT:
|
|
|
|
g_value_set_object (value, filter->other_context);
|
2013-07-17 23:42:31 +00:00
|
|
|
break;
|
2009-02-11 06:39:14 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2008-08-11 07:52:16 +00:00
|
|
|
}
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 23:43:16 +00:00
|
|
|
static void
|
|
|
|
gst_gl_filter_set_context (GstElement * element, GstContext * context)
|
|
|
|
{
|
|
|
|
GstGLFilter *filter = GST_GL_FILTER (element);
|
|
|
|
|
|
|
|
gst_gl_handle_set_context (element, context, &filter->display);
|
|
|
|
}
|
|
|
|
|
2012-08-15 06:52:48 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_filter_query (GstBaseTransform * trans, GstPadDirection direction,
|
|
|
|
GstQuery * query)
|
|
|
|
{
|
|
|
|
GstGLFilter *filter;
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
filter = GST_GL_FILTER (trans);
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
2013-11-12 23:43:16 +00:00
|
|
|
case GST_QUERY_CONTEXT:
|
|
|
|
{
|
|
|
|
res = gst_gl_handle_context_query ((GstElement *) filter, query,
|
|
|
|
&filter->display);
|
|
|
|
break;
|
|
|
|
}
|
2012-08-15 06:52:48 +00:00
|
|
|
default:
|
|
|
|
res =
|
|
|
|
GST_BASE_TRANSFORM_CLASS (parent_class)->query (trans, direction,
|
|
|
|
query);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2008-06-11 18:33:53 +00:00
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_filter_reset (GstGLFilter * filter)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLFilterClass *filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
2008-08-11 13:40:39 +00:00
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
if (filter->context) {
|
2008-10-13 21:14:27 +00:00
|
|
|
if (filter_class->onReset)
|
|
|
|
filter_class->onReset (filter);
|
|
|
|
|
2008-08-11 07:52:16 +00:00
|
|
|
if (filter_class->display_reset_cb != NULL) {
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_thread_add (filter->context, gst_gl_filter_stop_gl,
|
2009-02-11 06:39:14 +00:00
|
|
|
filter);
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
2008-08-11 07:52:16 +00:00
|
|
|
//blocking call, delete the FBO
|
2013-09-24 06:37:11 +00:00
|
|
|
if (filter->fbo != 0) {
|
|
|
|
gst_gl_context_del_fbo (filter->context, filter->fbo,
|
|
|
|
filter->depthbuffer);
|
|
|
|
}
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_object_unref (filter->context);
|
|
|
|
filter->context = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filter->display) {
|
2013-06-13 04:36:41 +00:00
|
|
|
gst_object_unref (filter->display);
|
2013-10-24 11:28:57 +00:00
|
|
|
filter->display = NULL;
|
2008-08-11 07:52:16 +00:00
|
|
|
}
|
2010-04-29 06:27:29 +00:00
|
|
|
|
2008-08-11 07:52:16 +00:00
|
|
|
filter->fbo = 0;
|
|
|
|
filter->depthbuffer = 0;
|
2010-04-29 06:27:29 +00:00
|
|
|
filter->default_shader = NULL;
|
2013-08-29 14:22:31 +00:00
|
|
|
if (filter->other_context)
|
|
|
|
gst_object_unref (filter->other_context);
|
|
|
|
filter->other_context = NULL;
|
2013-11-12 23:43:16 +00:00
|
|
|
|
|
|
|
if (filter->context)
|
|
|
|
gst_object_unref (filter->context);
|
|
|
|
filter->context = NULL;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_filter_start (GstBaseTransform * bt)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2008-08-14 18:02:04 +00:00
|
|
|
GstGLFilter *filter = GST_GL_FILTER (bt);
|
|
|
|
GstGLFilterClass *filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
2010-05-05 09:21:31 +00:00
|
|
|
|
2013-11-12 23:43:16 +00:00
|
|
|
if (!gst_gl_ensure_display (filter, &filter->display))
|
|
|
|
return FALSE;
|
2009-10-04 00:23:45 +00:00
|
|
|
|
2008-08-14 18:02:04 +00:00
|
|
|
if (filter_class->onStart)
|
|
|
|
filter_class->onStart (filter);
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2008-08-11 07:52:16 +00:00
|
|
|
return TRUE;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_filter_stop (GstBaseTransform * bt)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2008-08-11 07:52:16 +00:00
|
|
|
GstGLFilter *filter = GST_GL_FILTER (bt);
|
2008-08-14 18:02:04 +00:00
|
|
|
GstGLFilterClass *filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
|
|
|
|
|
|
|
if (filter_class->onStop)
|
|
|
|
filter_class->onStop (filter);
|
2008-08-11 07:52:16 +00:00
|
|
|
|
|
|
|
gst_gl_filter_reset (filter);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2008-08-11 07:52:16 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_filter_start_gl (GstGLContext * context, gpointer data)
|
2008-08-11 07:52:16 +00:00
|
|
|
{
|
|
|
|
GstGLFilter *filter = GST_GL_FILTER (data);
|
|
|
|
GstGLFilterClass *filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
2008-08-11 13:40:39 +00:00
|
|
|
|
2008-08-11 07:52:16 +00:00
|
|
|
filter_class->display_init_cb (filter);
|
|
|
|
}
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2008-08-11 07:52:16 +00:00
|
|
|
static void
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_filter_stop_gl (GstGLContext * context, gpointer data)
|
2008-08-11 07:52:16 +00:00
|
|
|
{
|
|
|
|
GstGLFilter *filter = GST_GL_FILTER (data);
|
|
|
|
GstGLFilterClass *filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
2008-08-11 13:40:39 +00:00
|
|
|
|
2008-08-11 07:52:16 +00:00
|
|
|
filter_class->display_reset_cb (filter);
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
2012-09-25 07:59:27 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_gl_filter_fixate_caps (GstBaseTransform * bt,
|
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
|
|
|
|
{
|
|
|
|
GstStructure *ins, *outs;
|
|
|
|
const GValue *from_par, *to_par;
|
|
|
|
GValue fpar = { 0, }, tpar = {
|
|
|
|
0,};
|
|
|
|
|
|
|
|
othercaps = gst_caps_truncate (othercaps);
|
|
|
|
othercaps = gst_caps_make_writable (othercaps);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (bt, "trying to fixate othercaps %" GST_PTR_FORMAT
|
|
|
|
" based on caps %" GST_PTR_FORMAT, othercaps, caps);
|
|
|
|
|
|
|
|
ins = gst_caps_get_structure (caps, 0);
|
|
|
|
outs = gst_caps_get_structure (othercaps, 0);
|
|
|
|
|
|
|
|
from_par = gst_structure_get_value (ins, "pixel-aspect-ratio");
|
|
|
|
to_par = gst_structure_get_value (outs, "pixel-aspect-ratio");
|
|
|
|
|
|
|
|
/* If we're fixating from the sinkpad we always set the PAR and
|
|
|
|
* assume that missing PAR on the sinkpad means 1/1 and
|
|
|
|
* missing PAR on the srcpad means undefined
|
|
|
|
*/
|
|
|
|
if (direction == GST_PAD_SINK) {
|
|
|
|
if (!from_par) {
|
|
|
|
g_value_init (&fpar, GST_TYPE_FRACTION);
|
|
|
|
gst_value_set_fraction (&fpar, 1, 1);
|
|
|
|
from_par = &fpar;
|
|
|
|
}
|
|
|
|
if (!to_par) {
|
|
|
|
g_value_init (&tpar, GST_TYPE_FRACTION);
|
|
|
|
gst_value_set_fraction (&tpar, 1, 1);
|
|
|
|
to_par = &tpar;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!to_par) {
|
|
|
|
g_value_init (&tpar, GST_TYPE_FRACTION);
|
|
|
|
gst_value_set_fraction (&tpar, 1, 1);
|
|
|
|
to_par = &tpar;
|
|
|
|
|
|
|
|
gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
if (!from_par) {
|
|
|
|
g_value_init (&fpar, GST_TYPE_FRACTION);
|
|
|
|
gst_value_set_fraction (&fpar, 1, 1);
|
|
|
|
from_par = &fpar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we have both PAR but they might not be fixated */
|
|
|
|
{
|
|
|
|
gint from_w, from_h, from_par_n, from_par_d, to_par_n, to_par_d;
|
|
|
|
gint w = 0, h = 0;
|
|
|
|
gint from_dar_n, from_dar_d;
|
|
|
|
gint num, den;
|
|
|
|
|
|
|
|
/* from_par should be fixed */
|
|
|
|
g_return_val_if_fail (gst_value_is_fixed (from_par), othercaps);
|
|
|
|
|
|
|
|
from_par_n = gst_value_get_fraction_numerator (from_par);
|
|
|
|
from_par_d = gst_value_get_fraction_denominator (from_par);
|
|
|
|
|
|
|
|
gst_structure_get_int (ins, "width", &from_w);
|
|
|
|
gst_structure_get_int (ins, "height", &from_h);
|
|
|
|
|
|
|
|
gst_structure_get_int (outs, "width", &w);
|
|
|
|
gst_structure_get_int (outs, "height", &h);
|
|
|
|
|
|
|
|
/* if both width and height are already fixed, we can't do anything
|
|
|
|
* about it anymore */
|
|
|
|
if (w && h) {
|
|
|
|
gint n = 1, d = 1;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (bt, "dimensions already set to %dx%d, not fixating",
|
|
|
|
w, h);
|
|
|
|
if (!gst_value_is_fixed (to_par)) {
|
|
|
|
GST_DEBUG_OBJECT (bt, "fixating to_par to %dx%d", n, d);
|
|
|
|
if (gst_structure_has_field (outs, "pixel-aspect-ratio"))
|
|
|
|
gst_structure_fixate_field_nearest_fraction (outs,
|
|
|
|
"pixel-aspect-ratio", 1, 1);
|
|
|
|
else if (n != d)
|
|
|
|
gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
|
|
|
|
1, 1, NULL);
|
|
|
|
}
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate input DAR */
|
|
|
|
if (!gst_util_fraction_multiply (from_w, from_h, from_par_n, from_par_d,
|
|
|
|
&from_dar_n, &from_dar_d)) {
|
|
|
|
GST_ELEMENT_ERROR (bt, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (bt, "Input DAR is %d/%d", from_dar_n, from_dar_d);
|
|
|
|
|
|
|
|
/* If either width or height are fixed there's not much we
|
|
|
|
* can do either except choosing a height or width and PAR
|
|
|
|
* that matches the DAR as good as possible
|
|
|
|
*/
|
|
|
|
if (h) {
|
|
|
|
gint num, den;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (bt, "height is fixed (%d)", h);
|
|
|
|
|
|
|
|
if (!gst_value_is_fixed (to_par)) {
|
|
|
|
gst_value_set_fraction (&tpar, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PAR is fixed, choose the height that is nearest to the
|
|
|
|
* height with the same DAR */
|
|
|
|
to_par_n = gst_value_get_fraction_numerator (to_par);
|
|
|
|
to_par_d = gst_value_get_fraction_denominator (to_par);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (bt, "PAR is fixed %d/%d", to_par_n, to_par_d);
|
|
|
|
|
|
|
|
if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, to_par_d,
|
|
|
|
to_par_n, &num, &den)) {
|
|
|
|
GST_ELEMENT_ERROR (bt, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = (guint) gst_util_uint64_scale_int (h, num, den);
|
|
|
|
gst_structure_fixate_field_nearest_int (outs, "width", w);
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
} else if (w) {
|
|
|
|
gint num, den;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (bt, "width is fixed (%d)", w);
|
|
|
|
|
|
|
|
if (!gst_value_is_fixed (to_par)) {
|
|
|
|
gst_value_set_fraction (&tpar, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PAR is fixed, choose the height that is nearest to the
|
|
|
|
* height with the same DAR */
|
|
|
|
to_par_n = gst_value_get_fraction_numerator (to_par);
|
|
|
|
to_par_d = gst_value_get_fraction_denominator (to_par);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (bt, "PAR is fixed %d/%d", to_par_n, to_par_d);
|
|
|
|
|
|
|
|
if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, to_par_d,
|
|
|
|
to_par_n, &num, &den)) {
|
|
|
|
GST_ELEMENT_ERROR (bt, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
h = (guint) gst_util_uint64_scale_int (w, den, num);
|
|
|
|
gst_structure_fixate_field_nearest_int (outs, "height", h);
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
} else if (gst_value_is_fixed (to_par)) {
|
|
|
|
GstStructure *tmp;
|
|
|
|
gint set_h, set_w, f_h, f_w;
|
|
|
|
|
|
|
|
to_par_n = gst_value_get_fraction_numerator (to_par);
|
|
|
|
to_par_d = gst_value_get_fraction_denominator (to_par);
|
|
|
|
|
|
|
|
/* Calculate scale factor for the PAR change */
|
|
|
|
if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, to_par_n,
|
|
|
|
to_par_d, &num, &den)) {
|
|
|
|
GST_ELEMENT_ERROR (bt, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to keep the input height */
|
|
|
|
tmp = gst_structure_copy (outs);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "height", from_h);
|
|
|
|
gst_structure_get_int (tmp, "height", &set_h);
|
|
|
|
|
|
|
|
/* This might have failed but try to scale the width
|
|
|
|
* to keep the DAR nonetheless */
|
|
|
|
w = (guint) gst_util_uint64_scale_int (set_h, num, den);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "width", w);
|
|
|
|
gst_structure_get_int (tmp, "width", &set_w);
|
|
|
|
gst_structure_free (tmp);
|
|
|
|
|
|
|
|
/* We kept the DAR and the height is nearest to the original height */
|
|
|
|
if (set_w == w) {
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
|
|
|
|
G_TYPE_INT, set_h, NULL);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
f_h = set_h;
|
|
|
|
f_w = set_w;
|
|
|
|
|
|
|
|
/* If the former failed, try to keep the input width at least */
|
|
|
|
tmp = gst_structure_copy (outs);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "width", from_w);
|
|
|
|
gst_structure_get_int (tmp, "width", &set_w);
|
|
|
|
|
|
|
|
/* This might have failed but try to scale the width
|
|
|
|
* to keep the DAR nonetheless */
|
|
|
|
h = (guint) gst_util_uint64_scale_int (set_w, den, num);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "height", h);
|
|
|
|
gst_structure_get_int (tmp, "height", &set_h);
|
|
|
|
gst_structure_free (tmp);
|
|
|
|
|
|
|
|
/* We kept the DAR and the width is nearest to the original width */
|
|
|
|
if (set_h == h) {
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
|
|
|
|
G_TYPE_INT, set_h, NULL);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If all this failed, keep the height that was nearest to the orignal
|
|
|
|
* height and the nearest possible width. This changes the DAR but
|
|
|
|
* there's not much else to do here.
|
|
|
|
*/
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, f_w, "height", G_TYPE_INT,
|
|
|
|
f_h, NULL);
|
|
|
|
goto done;
|
|
|
|
} else {
|
|
|
|
GstStructure *tmp;
|
|
|
|
gint set_h, set_w, set_par_n, set_par_d, tmp2;
|
|
|
|
|
|
|
|
/* width, height and PAR are not fixed */
|
|
|
|
|
|
|
|
/* First try to keep the height and width as good as possible
|
|
|
|
* and scale PAR */
|
|
|
|
tmp = gst_structure_copy (outs);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "height", from_h);
|
|
|
|
gst_structure_get_int (tmp, "height", &set_h);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "width", from_w);
|
|
|
|
gst_structure_get_int (tmp, "width", &set_w);
|
|
|
|
|
|
|
|
if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_h, set_w,
|
|
|
|
&to_par_n, &to_par_d)) {
|
|
|
|
GST_ELEMENT_ERROR (bt, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_structure_has_field (tmp, "pixel-aspect-ratio"))
|
|
|
|
gst_structure_set_value (tmp, "pixel-aspect-ratio", to_par);
|
|
|
|
gst_structure_fixate_field_nearest_fraction (tmp, "pixel-aspect-ratio",
|
|
|
|
to_par_n, to_par_d);
|
|
|
|
gst_structure_get_fraction (tmp, "pixel-aspect-ratio", &set_par_n,
|
|
|
|
&set_par_d);
|
|
|
|
gst_structure_free (tmp);
|
|
|
|
|
|
|
|
if (set_par_n == to_par_n && set_par_d == to_par_d) {
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
|
|
|
|
G_TYPE_INT, set_h, NULL);
|
|
|
|
|
|
|
|
if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
|
|
|
|
set_par_n != set_par_d)
|
|
|
|
gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
|
|
|
|
set_par_n, set_par_d, NULL);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise try to scale width to keep the DAR with the set
|
|
|
|
* PAR and height */
|
|
|
|
if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_par_d,
|
|
|
|
set_par_n, &num, &den)) {
|
|
|
|
GST_ELEMENT_ERROR (bt, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = (guint) gst_util_uint64_scale_int (set_h, num, den);
|
|
|
|
tmp = gst_structure_copy (outs);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "width", w);
|
|
|
|
gst_structure_get_int (tmp, "width", &tmp2);
|
|
|
|
gst_structure_free (tmp);
|
|
|
|
|
|
|
|
if (tmp2 == w) {
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, tmp2, "height",
|
|
|
|
G_TYPE_INT, set_h, NULL);
|
|
|
|
if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
|
|
|
|
set_par_n != set_par_d)
|
|
|
|
gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
|
|
|
|
set_par_n, set_par_d, NULL);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ... or try the same with the height */
|
|
|
|
h = (guint) gst_util_uint64_scale_int (set_w, den, num);
|
|
|
|
tmp = gst_structure_copy (outs);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "height", h);
|
|
|
|
gst_structure_get_int (tmp, "height", &tmp2);
|
|
|
|
gst_structure_free (tmp);
|
|
|
|
|
|
|
|
if (tmp2 == h) {
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
|
|
|
|
G_TYPE_INT, tmp2, NULL);
|
|
|
|
if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
|
|
|
|
set_par_n != set_par_d)
|
|
|
|
gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
|
|
|
|
set_par_n, set_par_d, NULL);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If all fails we can't keep the DAR and take the nearest values
|
|
|
|
* for everything from the first try */
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
|
|
|
|
G_TYPE_INT, set_h, NULL);
|
|
|
|
if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
|
|
|
|
set_par_n != set_par_d)
|
|
|
|
gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
|
|
|
|
set_par_n, set_par_d, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
othercaps = gst_caps_fixate (othercaps);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (bt, "fixated othercaps to %" GST_PTR_FORMAT, othercaps);
|
|
|
|
|
|
|
|
if (from_par == &fpar)
|
|
|
|
g_value_unset (&fpar);
|
|
|
|
if (to_par == &tpar)
|
|
|
|
g_value_unset (&tpar);
|
|
|
|
|
|
|
|
return othercaps;
|
|
|
|
}
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_gl_filter_transform_caps (GstBaseTransform * bt,
|
2012-06-03 10:40:53 +00:00
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * filter)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2008-08-11 07:52:16 +00:00
|
|
|
//GstGLFilter* filter = GST_GL_FILTER (bt);
|
2012-06-03 10:40:53 +00:00
|
|
|
GstStructure *structure;
|
2013-11-15 09:49:43 +00:00
|
|
|
GstCapsFeatures *features;
|
2012-07-09 12:27:48 +00:00
|
|
|
GstCaps *newcaps, *result;
|
2012-06-03 10:40:53 +00:00
|
|
|
const GValue *par;
|
2012-07-09 12:27:48 +00:00
|
|
|
guint i, n;
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2012-06-03 10:40:53 +00:00
|
|
|
par = NULL;
|
2012-07-09 12:27:48 +00:00
|
|
|
newcaps = gst_caps_new_empty ();
|
|
|
|
n = gst_caps_get_size (caps);
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
structure = gst_caps_get_structure (caps, i);
|
2013-11-15 09:49:43 +00:00
|
|
|
features = gst_caps_get_features (caps, i);
|
2012-07-09 12:27:48 +00:00
|
|
|
|
2013-11-15 09:49:43 +00:00
|
|
|
if (i > 0
|
|
|
|
&& gst_caps_is_subset_structure_full (newcaps, structure, features))
|
2012-07-09 12:27:48 +00:00
|
|
|
continue;
|
2012-06-03 10:40:53 +00:00
|
|
|
|
2012-07-09 12:27:48 +00:00
|
|
|
structure = gst_structure_copy (structure);
|
2013-11-15 09:49:43 +00:00
|
|
|
features = gst_caps_features_copy (features);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2012-09-25 07:59:27 +00:00
|
|
|
gst_structure_set (structure,
|
|
|
|
"width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
|
|
|
|
"height", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
|
2012-07-09 12:27:48 +00:00
|
|
|
|
2012-09-16 11:42:08 +00:00
|
|
|
gst_structure_remove_field (structure, "format");
|
|
|
|
|
2012-07-09 12:27:48 +00:00
|
|
|
if ((par = gst_structure_get_value (structure, "pixel-aspect-ratio"))) {
|
|
|
|
gst_structure_set (structure,
|
|
|
|
"pixel-aspect-ratio", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1,
|
|
|
|
NULL);
|
|
|
|
}
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2013-11-15 09:49:43 +00:00
|
|
|
gst_caps_append_structure_full (newcaps, structure, features);
|
2012-07-09 12:27:48 +00:00
|
|
|
}
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2012-07-09 12:27:48 +00:00
|
|
|
if (filter) {
|
|
|
|
result =
|
|
|
|
gst_caps_intersect_full (filter, newcaps, GST_CAPS_INTERSECT_FIRST);
|
|
|
|
gst_caps_unref (newcaps);
|
|
|
|
newcaps = result;
|
|
|
|
}
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2012-06-03 10:40:53 +00:00
|
|
|
GST_DEBUG_OBJECT (bt, "returning caps: %" GST_PTR_FORMAT, newcaps);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2012-06-03 10:40:53 +00:00
|
|
|
return newcaps;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_filter_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
|
2012-06-03 10:40:53 +00:00
|
|
|
gsize * size)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2008-08-11 07:52:16 +00:00
|
|
|
gboolean ret = FALSE;
|
2012-06-03 10:40:53 +00:00
|
|
|
GstVideoInfo info;
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2012-06-03 10:40:53 +00:00
|
|
|
ret = gst_video_info_from_caps (&info, caps);
|
2008-08-11 13:40:39 +00:00
|
|
|
if (ret)
|
2012-06-03 10:40:53 +00:00
|
|
|
*size = GST_VIDEO_INFO_SIZE (&info);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2008-08-11 07:52:16 +00:00
|
|
|
return TRUE;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_filter_set_caps (GstBaseTransform * bt, GstCaps * incaps,
|
|
|
|
GstCaps * outcaps)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2012-06-03 10:40:53 +00:00
|
|
|
GstGLFilter *filter;
|
|
|
|
GstGLFilterClass *filter_class;
|
|
|
|
|
|
|
|
filter = GST_GL_FILTER (bt);
|
|
|
|
filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2012-09-16 11:42:08 +00:00
|
|
|
if (!gst_video_info_from_caps (&filter->in_info, incaps))
|
|
|
|
goto wrong_caps;
|
|
|
|
if (!gst_video_info_from_caps (&filter->out_info, outcaps))
|
2012-08-10 05:31:20 +00:00
|
|
|
goto wrong_caps;
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2012-08-10 05:31:20 +00:00
|
|
|
if (filter_class->set_caps) {
|
|
|
|
if (!filter_class->set_caps (filter, incaps, outcaps))
|
2013-04-24 04:22:40 +00:00
|
|
|
goto error;
|
2011-11-24 15:02:32 +00:00
|
|
|
}
|
2009-10-04 00:23:45 +00:00
|
|
|
|
2012-09-16 11:42:08 +00:00
|
|
|
GST_DEBUG ("set_caps %dx%d", GST_VIDEO_INFO_WIDTH (&filter->out_info),
|
|
|
|
GST_VIDEO_INFO_HEIGHT (&filter->out_info));
|
2012-08-10 05:31:20 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2012-08-10 05:31:20 +00:00
|
|
|
/* ERRORS */
|
|
|
|
wrong_caps:
|
|
|
|
{
|
|
|
|
GST_WARNING ("Wrong caps");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-04-24 04:22:40 +00:00
|
|
|
error:
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
2012-07-09 12:27:48 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_filter_propose_allocation (GstBaseTransform * trans,
|
|
|
|
GstQuery * decide_query, GstQuery * query)
|
|
|
|
{
|
|
|
|
GstGLFilter *filter = GST_GL_FILTER (trans);
|
|
|
|
GstBufferPool *pool;
|
|
|
|
GstStructure *config;
|
|
|
|
GstCaps *caps;
|
|
|
|
guint size;
|
|
|
|
gboolean need_pool;
|
2013-11-12 13:41:01 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
GstStructure *gl_context;
|
2012-07-09 12:27:48 +00:00
|
|
|
|
|
|
|
gst_query_parse_allocation (query, &caps, &need_pool);
|
|
|
|
|
|
|
|
if (caps == NULL)
|
|
|
|
goto no_caps;
|
|
|
|
|
|
|
|
if ((pool = filter->pool))
|
|
|
|
gst_object_ref (pool);
|
|
|
|
|
|
|
|
if (pool != NULL) {
|
|
|
|
GstCaps *pcaps;
|
|
|
|
|
|
|
|
/* we had a pool, check caps */
|
|
|
|
GST_DEBUG_OBJECT (filter, "check existing pool caps");
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
gst_buffer_pool_config_get_params (config, &pcaps, &size, NULL, NULL);
|
|
|
|
|
|
|
|
if (!gst_caps_is_equal (caps, pcaps)) {
|
|
|
|
GST_DEBUG_OBJECT (filter, "pool has different caps");
|
|
|
|
/* different caps, we can't use this pool */
|
|
|
|
gst_object_unref (pool);
|
|
|
|
pool = NULL;
|
|
|
|
}
|
|
|
|
gst_structure_free (config);
|
|
|
|
}
|
2013-11-12 13:41:01 +00:00
|
|
|
|
|
|
|
if (!gst_gl_ensure_display (filter, &filter->display))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!filter->context) {
|
|
|
|
filter->context = gst_gl_context_new (filter->display);
|
|
|
|
if (!gst_gl_context_create (filter->context, filter->other_context, &error))
|
|
|
|
goto context_error;
|
|
|
|
}
|
|
|
|
|
2012-07-09 12:27:48 +00:00
|
|
|
if (pool == NULL && need_pool) {
|
|
|
|
GstVideoInfo info;
|
|
|
|
|
|
|
|
if (!gst_video_info_from_caps (&info, caps))
|
|
|
|
goto invalid_caps;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (filter, "create new pool");
|
2013-09-15 04:23:43 +00:00
|
|
|
pool = gst_gl_buffer_pool_new (filter->context);
|
2012-07-09 12:27:48 +00:00
|
|
|
|
|
|
|
/* the normal size of a frame */
|
|
|
|
size = info.size;
|
|
|
|
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
gst_buffer_pool_config_set_params (config, caps, size, 0, 0);
|
|
|
|
if (!gst_buffer_pool_set_config (pool, config))
|
|
|
|
goto config_failed;
|
|
|
|
}
|
|
|
|
/* we need at least 2 buffer because we hold on to the last one */
|
|
|
|
gst_query_add_allocation_pool (query, pool, size, 1, 0);
|
2013-11-12 13:41:01 +00:00
|
|
|
gst_object_unref (pool);
|
2012-07-09 12:27:48 +00:00
|
|
|
|
|
|
|
/* we also support various metadata */
|
|
|
|
gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, 0);
|
|
|
|
|
2013-11-12 13:41:01 +00:00
|
|
|
gl_context =
|
|
|
|
gst_structure_new ("GstVideoGLTextureUploadMeta", "gst.gl.GstGLContext",
|
|
|
|
GST_GL_TYPE_CONTEXT, filter->context, NULL);
|
|
|
|
gst_query_add_allocation_meta (query,
|
|
|
|
GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE, gl_context);
|
|
|
|
gst_structure_free (gl_context);
|
2012-07-09 12:27:48 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_caps:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (trans, "no caps specified");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
invalid_caps:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (trans, "invalid caps specified");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
config_failed:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (trans, "failed setting config");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-11-12 13:41:01 +00:00
|
|
|
context_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (trans, RESOURCE, NOT_FOUND, ("%s", error->message),
|
|
|
|
(NULL));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-07-09 12:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_gl_filter_decide_allocation (GstBaseTransform * trans, GstQuery * query)
|
|
|
|
{
|
|
|
|
GstGLFilter *filter = GST_GL_FILTER (trans);
|
2013-11-12 13:41:01 +00:00
|
|
|
GstGLFilterClass *filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
2012-07-09 12:27:48 +00:00
|
|
|
GstBufferPool *pool = NULL;
|
|
|
|
GstStructure *config;
|
|
|
|
GstCaps *caps;
|
|
|
|
guint min, max, size;
|
|
|
|
gboolean update_pool;
|
2013-11-12 13:41:01 +00:00
|
|
|
guint idx;
|
|
|
|
GError *error = NULL;
|
|
|
|
guint in_width, in_height, out_width, out_height;
|
2012-07-09 12:27:48 +00:00
|
|
|
|
|
|
|
gst_query_parse_allocation (query, &caps, NULL);
|
|
|
|
|
|
|
|
if (gst_query_get_n_allocation_pools (query) > 0) {
|
|
|
|
gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
|
|
|
|
|
|
|
|
update_pool = TRUE;
|
|
|
|
} else {
|
|
|
|
GstVideoInfo vinfo;
|
|
|
|
|
|
|
|
gst_video_info_init (&vinfo);
|
|
|
|
gst_video_info_from_caps (&vinfo, caps);
|
|
|
|
size = vinfo.size;
|
|
|
|
min = max = 0;
|
|
|
|
update_pool = FALSE;
|
|
|
|
}
|
|
|
|
|
2013-11-12 13:41:01 +00:00
|
|
|
if (!gst_gl_ensure_display (filter, &filter->display))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (gst_query_find_allocation_meta (query,
|
|
|
|
GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE, &idx)) {
|
|
|
|
GstGLContext *context;
|
|
|
|
const GstStructure *upload_meta_params;
|
|
|
|
|
|
|
|
gst_query_parse_nth_allocation_meta (query, idx, &upload_meta_params);
|
|
|
|
if (gst_structure_get (upload_meta_params, "gst.gl.GstGLContext",
|
|
|
|
GST_GL_TYPE_CONTEXT, &context, NULL) && context)
|
|
|
|
gst_object_replace ((GstObject **) & filter->context,
|
|
|
|
(GstObject *) context);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!filter->context) {
|
|
|
|
filter->context = gst_gl_context_new (filter->display);
|
|
|
|
if (!gst_gl_context_create (filter->context, filter->other_context, &error))
|
|
|
|
goto context_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
in_width = GST_VIDEO_INFO_WIDTH (&filter->in_info);
|
|
|
|
in_height = GST_VIDEO_INFO_HEIGHT (&filter->in_info);
|
|
|
|
out_width = GST_VIDEO_INFO_WIDTH (&filter->out_info);
|
|
|
|
out_height = GST_VIDEO_INFO_HEIGHT (&filter->out_info);
|
|
|
|
|
2013-11-14 04:27:52 +00:00
|
|
|
if (!filter->upload) {
|
|
|
|
filter->upload = gst_gl_upload_new (filter->context);
|
|
|
|
gst_gl_upload_init_format (filter->upload,
|
|
|
|
GST_VIDEO_INFO_FORMAT (&filter->in_info), in_width, in_height,
|
|
|
|
out_width, out_height);
|
|
|
|
}
|
2013-11-12 13:41:01 +00:00
|
|
|
//blocking call, generate a FBO
|
|
|
|
if (!gst_gl_context_gen_fbo (filter->context, out_width, out_height,
|
|
|
|
&filter->fbo, &filter->depthbuffer))
|
|
|
|
goto context_error;
|
|
|
|
|
|
|
|
gst_gl_context_gen_texture (filter->context, &filter->in_tex_id,
|
|
|
|
GST_VIDEO_FORMAT_RGBA, in_width, in_height);
|
|
|
|
|
|
|
|
gst_gl_context_gen_texture (filter->context, &filter->out_tex_id,
|
|
|
|
GST_VIDEO_FORMAT_RGBA, out_width, out_height);
|
|
|
|
|
|
|
|
if (filter_class->display_init_cb != NULL) {
|
|
|
|
gst_gl_context_thread_add (filter->context, gst_gl_filter_start_gl, filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filter_class->onInitFBO) {
|
|
|
|
if (!filter_class->onInitFBO (filter))
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2012-07-09 12:27:48 +00:00
|
|
|
if (!pool)
|
2013-09-15 04:23:43 +00:00
|
|
|
pool = gst_gl_buffer_pool_new (filter->context);
|
2012-07-09 12:27:48 +00:00
|
|
|
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
gst_buffer_pool_config_set_params (config, caps, size, min, max);
|
|
|
|
gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
|
|
|
|
gst_buffer_pool_set_config (pool, config);
|
|
|
|
|
|
|
|
if (update_pool)
|
|
|
|
gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
|
|
|
|
else
|
|
|
|
gst_query_add_allocation_pool (query, pool, size, min, max);
|
|
|
|
|
|
|
|
gst_object_unref (pool);
|
|
|
|
|
|
|
|
return TRUE;
|
2013-11-12 13:41:01 +00:00
|
|
|
|
|
|
|
context_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (trans, RESOURCE, NOT_FOUND, ("%s", error->message),
|
|
|
|
(NULL));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (trans, LIBRARY, INIT,
|
|
|
|
("Subclass failed to initialize."), (NULL));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-07-09 12:27:48 +00:00
|
|
|
}
|
|
|
|
|
2012-09-27 05:53:46 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_filter_filter_texture:
|
|
|
|
* @filter: a #GstGLFilter
|
|
|
|
* @inbuf: an input buffer
|
|
|
|
* @outbuf: an output buffer
|
|
|
|
*
|
|
|
|
* Perform automatic upload if needed, call filter_texture vfunc and then an
|
|
|
|
* automatic download if needed.
|
|
|
|
*
|
|
|
|
* Returns: whether the transformation succeeded
|
|
|
|
*/
|
2012-09-20 13:06:49 +00:00
|
|
|
gboolean
|
2012-09-18 14:32:30 +00:00
|
|
|
gst_gl_filter_filter_texture (GstGLFilter * filter, GstBuffer * inbuf,
|
|
|
|
GstBuffer * outbuf)
|
|
|
|
{
|
|
|
|
GstGLFilterClass *filter_class;
|
|
|
|
guint in_tex, out_tex;
|
2013-11-14 04:27:52 +00:00
|
|
|
GstVideoFrame out_frame;
|
|
|
|
gboolean ret, out_gl_mem;
|
|
|
|
GstVideoGLTextureUploadMeta *out_tex_upload_meta;
|
2012-09-18 14:32:30 +00:00
|
|
|
|
|
|
|
filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
|
|
|
|
2013-11-14 04:27:52 +00:00
|
|
|
if (!gst_gl_upload_perform_with_buffer (filter->upload, inbuf, &in_tex))
|
2012-09-18 14:32:30 +00:00
|
|
|
return FALSE;
|
2013-11-14 04:27:52 +00:00
|
|
|
|
2012-09-18 14:32:30 +00:00
|
|
|
if (!gst_video_frame_map (&out_frame, &filter->out_info, outbuf,
|
|
|
|
GST_MAP_WRITE | GST_MAP_GL)) {
|
2013-11-14 04:27:52 +00:00
|
|
|
ret = FALSE;
|
|
|
|
goto inbuf_error;
|
2012-09-18 14:32:30 +00:00
|
|
|
}
|
|
|
|
|
2013-11-14 04:27:52 +00:00
|
|
|
out_gl_mem = gst_is_gl_memory (out_frame.map[0].memory);
|
|
|
|
out_tex_upload_meta = gst_buffer_get_video_gl_texture_upload_meta (outbuf);
|
2012-09-25 07:59:27 +00:00
|
|
|
|
2013-11-14 04:27:52 +00:00
|
|
|
if (out_gl_mem) {
|
2012-09-25 07:59:27 +00:00
|
|
|
out_tex = *(guint *) out_frame.data[0];
|
2013-11-14 04:27:52 +00:00
|
|
|
} else {
|
|
|
|
GST_LOG ("Output Buffer does not contain correct memory, "
|
2012-09-18 14:32:30 +00:00
|
|
|
"attempting to wrap for download");
|
|
|
|
|
2012-09-25 07:59:27 +00:00
|
|
|
if (!filter->download) {
|
2013-09-15 04:23:43 +00:00
|
|
|
filter->download = gst_gl_download_new (filter->context);
|
2012-09-25 07:59:27 +00:00
|
|
|
|
2013-07-18 10:21:57 +00:00
|
|
|
if (!gst_gl_download_init_format (filter->download,
|
|
|
|
GST_VIDEO_FRAME_FORMAT (&out_frame),
|
|
|
|
GST_VIDEO_FRAME_WIDTH (&out_frame),
|
|
|
|
GST_VIDEO_FRAME_HEIGHT (&out_frame))) {
|
|
|
|
GST_ELEMENT_ERROR (filter, RESOURCE, NOT_FOUND,
|
|
|
|
("%s", "Failed to init download format"), (NULL));
|
2013-11-14 04:27:52 +00:00
|
|
|
ret = FALSE;
|
|
|
|
goto error;
|
2013-07-18 10:21:57 +00:00
|
|
|
}
|
2012-09-25 07:59:27 +00:00
|
|
|
}
|
|
|
|
out_tex = filter->out_tex_id;
|
2012-09-18 14:32:30 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 04:36:41 +00:00
|
|
|
GST_DEBUG ("calling filter_texture with textures in:%i out:%i", in_tex,
|
|
|
|
out_tex);
|
|
|
|
|
2012-09-25 07:59:27 +00:00
|
|
|
g_assert (filter_class->filter_texture);
|
2012-09-18 14:32:30 +00:00
|
|
|
ret = filter_class->filter_texture (filter, in_tex, out_tex);
|
|
|
|
|
2013-11-14 04:27:52 +00:00
|
|
|
if (!out_gl_mem && !out_tex_upload_meta) {
|
2013-07-18 10:21:57 +00:00
|
|
|
if (!gst_gl_download_perform_with_data (filter->download, out_tex,
|
|
|
|
out_frame.data)) {
|
|
|
|
GST_ELEMENT_ERROR (filter, RESOURCE, NOT_FOUND,
|
|
|
|
("%s", "Failed to download video frame"), (NULL));
|
2013-11-14 04:27:52 +00:00
|
|
|
ret = FALSE;
|
|
|
|
goto error;
|
2013-07-18 10:21:57 +00:00
|
|
|
}
|
2012-09-18 14:32:30 +00:00
|
|
|
}
|
|
|
|
|
2013-11-14 04:27:52 +00:00
|
|
|
error:
|
2012-09-18 14:32:30 +00:00
|
|
|
gst_video_frame_unmap (&out_frame);
|
2013-11-14 04:27:52 +00:00
|
|
|
inbuf_error:
|
|
|
|
gst_gl_upload_release_buffer (filter->upload);
|
2012-09-18 14:32:30 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-06-11 18:33:53 +00:00
|
|
|
static GstFlowReturn
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_filter_transform (GstBaseTransform * bt, GstBuffer * inbuf,
|
|
|
|
GstBuffer * outbuf)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLFilter *filter;
|
2012-06-03 10:40:53 +00:00
|
|
|
GstGLFilterClass *filter_class;
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2008-08-11 07:52:16 +00:00
|
|
|
filter = GST_GL_FILTER (bt);
|
2012-06-03 10:40:53 +00:00
|
|
|
filter_class = GST_GL_FILTER_GET_CLASS (bt);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2013-11-12 23:43:16 +00:00
|
|
|
if (!gst_gl_ensure_display (filter, &filter->display))
|
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
|
2012-09-18 14:32:30 +00:00
|
|
|
g_assert (filter_class->filter || filter_class->filter_texture);
|
|
|
|
|
2012-06-03 10:40:53 +00:00
|
|
|
if (filter_class->filter)
|
|
|
|
filter_class->filter (filter, inbuf, outbuf);
|
2012-09-18 14:32:30 +00:00
|
|
|
else if (filter_class->filter_texture)
|
|
|
|
gst_gl_filter_filter_texture (filter, inbuf, outbuf);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2008-08-11 07:52:16 +00:00
|
|
|
return GST_FLOW_OK;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
2008-08-10 09:22:34 +00:00
|
|
|
/* convenience functions to simplify filter development */
|
2012-09-25 07:59:27 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_filter_render_to_target:
|
|
|
|
* @filter: a #GstGLFilter
|
|
|
|
* @resize: whether to automatically resize the texture between the input size
|
|
|
|
* and the output size
|
|
|
|
* @input: the input texture
|
|
|
|
* @target: the output texture
|
|
|
|
* @func: the function to transform @input into @output. called with @data
|
|
|
|
* @data: the data associated with @func
|
|
|
|
*
|
|
|
|
* Transforms @input into @output using @func on through FBO. @resize should
|
|
|
|
* only ever be %TRUE whenever @input is the input texture of @filter.
|
|
|
|
*/
|
2008-08-10 09:22:34 +00:00
|
|
|
void
|
2012-09-25 07:59:27 +00:00
|
|
|
gst_gl_filter_render_to_target (GstGLFilter * filter, gboolean resize,
|
2009-02-11 06:39:14 +00:00
|
|
|
GLuint input, GLuint target, GLCB func, gpointer data)
|
2008-08-10 09:22:34 +00:00
|
|
|
{
|
2012-09-25 07:59:27 +00:00
|
|
|
guint in_width, in_height, out_width, out_height;
|
|
|
|
|
|
|
|
out_width = GST_VIDEO_INFO_WIDTH (&filter->out_info);
|
|
|
|
out_height = GST_VIDEO_INFO_HEIGHT (&filter->out_info);
|
|
|
|
if (resize) {
|
|
|
|
in_width = GST_VIDEO_INFO_WIDTH (&filter->in_info);
|
|
|
|
in_height = GST_VIDEO_INFO_HEIGHT (&filter->in_info);
|
|
|
|
} else {
|
|
|
|
in_width = out_width;
|
|
|
|
in_height = out_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_LOG ("rendering to target. in:%ux%u out:%ux%u", in_width, in_height,
|
|
|
|
out_width, out_height);
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_use_fbo (filter->context,
|
2012-09-25 07:59:27 +00:00
|
|
|
out_width, out_height,
|
2009-02-11 06:39:14 +00:00
|
|
|
filter->fbo, filter->depthbuffer, target,
|
2012-09-25 07:59:27 +00:00
|
|
|
func, in_width, in_height, input, 0,
|
|
|
|
in_width, 0, in_height, GST_GL_DISPLAY_PROJECTION_ORTHO2D, data);
|
2008-08-10 09:22:34 +00:00
|
|
|
}
|
2010-04-29 06:27:29 +00:00
|
|
|
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_OPENGL
|
2010-04-29 06:27:29 +00:00
|
|
|
static void
|
|
|
|
_draw_with_shader_cb (gint width, gint height, guint texture, gpointer stuff)
|
|
|
|
{
|
|
|
|
GstGLFilter *filter = GST_GL_FILTER (stuff);
|
2013-09-15 04:23:43 +00:00
|
|
|
GstGLFuncs *gl = filter->context->gl_vtable;
|
2010-04-29 06:27:29 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->MatrixMode (GL_PROJECTION);
|
|
|
|
gl->LoadIdentity ();
|
2010-04-29 06:27:29 +00:00
|
|
|
|
|
|
|
gst_gl_shader_use (filter->default_shader);
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ActiveTexture (GL_TEXTURE1);
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->Enable (GL_TEXTURE_2D);
|
|
|
|
gl->BindTexture (GL_TEXTURE_2D, texture);
|
|
|
|
gl->Disable (GL_TEXTURE_2D);
|
2010-04-29 06:27:29 +00:00
|
|
|
|
|
|
|
gst_gl_shader_set_uniform_1i (filter->default_shader, "tex", 1);
|
2013-11-15 07:28:49 +00:00
|
|
|
gst_gl_shader_set_uniform_1f (filter->default_shader, "width", width);
|
|
|
|
gst_gl_shader_set_uniform_1f (filter->default_shader, "height", height);
|
2010-04-29 06:27:29 +00:00
|
|
|
|
2012-09-25 07:59:27 +00:00
|
|
|
gst_gl_filter_draw_texture (filter, texture, width, height);
|
2010-04-29 06:27:29 +00:00
|
|
|
}
|
|
|
|
|
2012-09-25 07:59:27 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_filter_render_to_target_with_shader:
|
|
|
|
* @filter: a #GstGLFilter
|
|
|
|
* @resize: whether to automatically resize the texture between the input size
|
|
|
|
* and the output size
|
|
|
|
* @input: the input texture
|
|
|
|
* @target: the output texture
|
|
|
|
* @shader: the shader to use.
|
|
|
|
*
|
2012-09-27 05:53:46 +00:00
|
|
|
* Transforms @input into @output using @shader on FBO. @resize should
|
2012-09-25 07:59:27 +00:00
|
|
|
* only ever be %TRUE whenever @input is the input texture of @filter.
|
|
|
|
*
|
2012-09-27 05:53:46 +00:00
|
|
|
* See also: gst_gl_filter_render_to_target()
|
2012-09-25 07:59:27 +00:00
|
|
|
*/
|
2010-04-29 06:27:29 +00:00
|
|
|
/* attach target to a FBO, use shader, pass input as "tex" uniform to
|
|
|
|
* the shader, render input to a quad */
|
|
|
|
void
|
|
|
|
gst_gl_filter_render_to_target_with_shader (GstGLFilter * filter,
|
2012-09-25 07:59:27 +00:00
|
|
|
gboolean resize, GLuint input, GLuint target, GstGLShader * shader)
|
2010-04-29 06:27:29 +00:00
|
|
|
{
|
2013-09-15 04:23:43 +00:00
|
|
|
g_return_if_fail (gst_gl_context_get_gl_api (filter->context) &
|
2012-12-06 07:40:26 +00:00
|
|
|
GST_GL_API_OPENGL);
|
|
|
|
|
2010-04-29 06:27:29 +00:00
|
|
|
filter->default_shader = shader;
|
2012-09-25 07:59:27 +00:00
|
|
|
gst_gl_filter_render_to_target (filter, resize, input, target,
|
|
|
|
_draw_with_shader_cb, filter);
|
2010-04-29 06:27:29 +00:00
|
|
|
}
|
|
|
|
|
2012-09-25 07:59:27 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_filter_draw_texture:
|
|
|
|
* @filter: a #GstGLFilter
|
|
|
|
* @texture: the texture to draw
|
|
|
|
* @width: width of @texture
|
|
|
|
* @height: height of texture
|
|
|
|
*
|
|
|
|
* Draws @texture into the OpenGL scene at the specified @width and @height.
|
|
|
|
*/
|
2010-04-29 06:27:29 +00:00
|
|
|
void
|
2012-09-25 07:59:27 +00:00
|
|
|
gst_gl_filter_draw_texture (GstGLFilter * filter, GLuint texture,
|
|
|
|
guint width, guint height)
|
2010-04-29 06:27:29 +00:00
|
|
|
{
|
2013-09-15 04:23:43 +00:00
|
|
|
GstGLFuncs *gl = filter->context->gl_vtable;
|
2013-01-16 04:21:44 +00:00
|
|
|
|
2013-08-07 09:42:46 +00:00
|
|
|
GLfloat verts[] = { -1.0f, -1.0f,
|
2013-01-16 04:21:44 +00:00
|
|
|
1.0f, -1.0f,
|
|
|
|
1.0f, 1.0f,
|
|
|
|
-1.0f, 1.0f
|
|
|
|
};
|
2013-11-15 07:28:49 +00:00
|
|
|
GLfloat texcoords[] = { 0.0f, 0.0f,
|
|
|
|
1.0f, 0.0f,
|
|
|
|
1.0f, 1.0f,
|
|
|
|
0.0f, 1.0f
|
2013-01-16 04:21:44 +00:00
|
|
|
};
|
|
|
|
|
2012-09-25 07:59:27 +00:00
|
|
|
GST_DEBUG ("drawing texture:%u dimensions:%ux%u", texture, width, height);
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ActiveTexture (GL_TEXTURE0);
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->Enable (GL_TEXTURE_2D);
|
|
|
|
gl->BindTexture (GL_TEXTURE_2D, texture);
|
2010-04-29 06:27:29 +00:00
|
|
|
|
2013-01-16 11:41:18 +00:00
|
|
|
gl->ClientActiveTexture (GL_TEXTURE0);
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->EnableClientState (GL_VERTEX_ARRAY);
|
|
|
|
gl->EnableClientState (GL_TEXTURE_COORD_ARRAY);
|
2013-01-16 11:41:18 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->VertexPointer (2, GL_FLOAT, 0, &verts);
|
2013-08-07 09:42:46 +00:00
|
|
|
gl->TexCoordPointer (2, GL_FLOAT, 0, &texcoords);
|
2010-04-29 06:27:29 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->DrawArrays (GL_TRIANGLE_FAN, 0, 4);
|
2010-04-29 06:27:29 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->DisableClientState (GL_VERTEX_ARRAY);
|
|
|
|
gl->DisableClientState (GL_TEXTURE_COORD_ARRAY);
|
2010-04-29 06:27:29 +00:00
|
|
|
}
|
2013-01-09 14:13:23 +00:00
|
|
|
#endif /* GST_GL_HAVE_OPENGL */
|