2008-08-13 14:01:21 +00:00
|
|
|
/*
|
2008-06-10 22:59:57 +00:00
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@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
|
2012-11-08 11:53:56 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2008-06-10 22:59:57 +00:00
|
|
|
*/
|
|
|
|
|
2008-09-29 21:45:10 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-glcolorscale
|
|
|
|
*
|
|
|
|
* video frame scaling and colorspace conversion.
|
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Scaling and Color space conversion</title>
|
|
|
|
* <para>
|
2008-10-04 19:34:07 +00:00
|
|
|
* Equivalent to glupload ! gldownload.
|
2008-09-29 21:45:10 +00:00
|
|
|
* </para>
|
2008-10-04 19:34:07 +00:00
|
|
|
* </refsect2>
|
2008-09-29 21:45:10 +00:00
|
|
|
* <refsect2>
|
|
|
|
* <title>Examples</title>
|
|
|
|
* |[
|
2014-08-10 17:07:28 +00:00
|
|
|
* gst-launch-1.0 -v videotestsrc ! video/x-raw ! glcolorscale ! ximagesink
|
2008-09-29 21:45:10 +00:00
|
|
|
* ]| A pipeline to test colorspace conversion.
|
|
|
|
* FBO is required.
|
|
|
|
|[
|
2014-08-10 17:07:28 +00:00
|
|
|
* gst-launch-1.0 -v videotestsrc ! video/x-raw, width=640, height=480, format=AYUV ! glcolorscale ! \
|
|
|
|
* video/x-raw, width=320, height=240, format=YV12 ! videoconvert ! autovideosink
|
2008-09-29 21:45:10 +00:00
|
|
|
* ]| A pipeline to test hardware scaling and colorspace conversion.
|
|
|
|
* FBO and GLSL are required.
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
2008-06-10 22:59:57 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstglcolorscale.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define GST_CAT_DEFAULT gst_gl_colorscale_debug
|
2009-02-11 06:39:14 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
2008-06-10 22:59:57 +00:00
|
|
|
|
|
|
|
/* Properties */
|
|
|
|
enum
|
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
PROP_0
|
2008-06-10 22:59:57 +00:00
|
|
|
};
|
|
|
|
|
2012-05-30 03:46:21 +00:00
|
|
|
#define DEBUG_INIT \
|
2008-06-10 22:59:57 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_gl_colorscale_debug, "glcolorscale", 0, "glcolorscale element");
|
|
|
|
|
2012-05-30 03:46:21 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstGLColorscale, gst_gl_colorscale,
|
2012-09-25 08:07:23 +00:00
|
|
|
GST_TYPE_GL_FILTER, DEBUG_INIT);
|
2008-06-10 22:59:57 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
static void gst_gl_colorscale_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_gl_colorscale_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
2014-04-30 16:30:06 +00:00
|
|
|
static gboolean gst_gl_colorscale_gen_gl_resources (GstGLFilter * filter);
|
|
|
|
static void gst_gl_colorscale_del_gl_resources (GstGLFilter * filter);
|
|
|
|
|
2012-09-25 08:07:23 +00:00
|
|
|
static gboolean gst_gl_colorscale_filter_texture (GstGLFilter * filter,
|
|
|
|
guint in_tex, guint out_tex);
|
|
|
|
static void gst_gl_colorscale_callback (gint width, gint height,
|
|
|
|
guint texture, gpointer stuff);
|
2008-06-10 22:59:57 +00:00
|
|
|
|
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_colorscale_class_init (GstGLColorscaleClass * klass)
|
2008-06-10 22:59:57 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GObjectClass *gobject_class;
|
2012-05-30 03:46:21 +00:00
|
|
|
GstElementClass *element_class;
|
2012-09-25 08:07:23 +00:00
|
|
|
GstGLFilterClass *filter_class;
|
2014-06-24 18:37:17 +00:00
|
|
|
GstBaseTransformClass *basetransform_class = GST_BASE_TRANSFORM_CLASS (klass);
|
2009-02-11 06:39:14 +00:00
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
2012-05-30 03:46:21 +00:00
|
|
|
element_class = GST_ELEMENT_CLASS (klass);
|
2012-09-25 08:07:23 +00:00
|
|
|
filter_class = GST_GL_FILTER_CLASS (klass);
|
2012-05-30 03:46:21 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
gobject_class->set_property = gst_gl_colorscale_set_property;
|
|
|
|
gobject_class->get_property = gst_gl_colorscale_get_property;
|
|
|
|
|
2012-11-21 02:34:15 +00:00
|
|
|
gst_element_class_set_metadata (element_class, "OpenGL color scale",
|
2013-07-17 23:41:05 +00:00
|
|
|
"Filter/Effect/Video", "Colorspace converter and video scaler",
|
2012-05-30 03:46:21 +00:00
|
|
|
"Julien Isorce <julien.isorce@gmail.com>");
|
|
|
|
|
2014-04-30 16:30:06 +00:00
|
|
|
filter_class->onInitFBO =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_colorscale_gen_gl_resources);
|
|
|
|
filter_class->onStop = GST_DEBUG_FUNCPTR (gst_gl_colorscale_del_gl_resources);
|
|
|
|
|
2012-09-25 08:07:23 +00:00
|
|
|
filter_class->filter_texture = gst_gl_colorscale_filter_texture;
|
2014-06-24 18:37:17 +00:00
|
|
|
|
|
|
|
basetransform_class->passthrough_on_same_caps = TRUE;
|
2014-11-27 10:05:45 +00:00
|
|
|
filter_class->supported_gl_api =
|
|
|
|
GST_GL_API_OPENGL | GST_GL_API_OPENGL3 | GST_GL_API_GLES2;
|
2008-06-10 22:59:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-30 03:46:21 +00:00
|
|
|
gst_gl_colorscale_init (GstGLColorscale * colorscale)
|
2008-06-10 22:59:57 +00:00
|
|
|
{
|
2014-04-30 16:30:06 +00:00
|
|
|
colorscale->shader = NULL;
|
2008-06-10 22:59:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_colorscale_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2008-06-10 22:59:57 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2008-06-10 22:59:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_colorscale_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
2008-06-10 22:59:57 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2008-06-10 22:59:57 +00:00
|
|
|
}
|
|
|
|
|
2014-04-30 16:30:06 +00:00
|
|
|
static void
|
|
|
|
_compile_identity_shader (GstGLContext * context, GstGLColorscale * colorscale)
|
|
|
|
{
|
|
|
|
GstGLFilter *filter = GST_GL_FILTER (colorscale);
|
|
|
|
|
|
|
|
colorscale->shader = gst_gl_shader_new (context);
|
|
|
|
|
|
|
|
if (!gst_gl_shader_compile_with_default_vf_and_check (colorscale->shader,
|
|
|
|
&filter->draw_attr_position_loc, &filter->draw_attr_texture_loc)) {
|
|
|
|
gst_gl_context_clear_shader (context);
|
|
|
|
gst_object_unref (colorscale->shader);
|
|
|
|
colorscale->shader = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_gl_colorscale_gen_gl_resources (GstGLFilter * filter)
|
|
|
|
{
|
|
|
|
GstGLColorscale *colorscale = GST_GL_COLORSCALE (filter);
|
|
|
|
|
2014-11-12 12:47:13 +00:00
|
|
|
if (gst_gl_context_get_gl_api (filter->context) & (GST_GL_API_GLES2 |
|
|
|
|
GST_GL_API_OPENGL3)) {
|
2014-05-01 04:11:00 +00:00
|
|
|
gst_gl_context_thread_add (filter->context,
|
|
|
|
(GstGLContextThreadFunc) _compile_identity_shader, colorscale);
|
|
|
|
|
|
|
|
if (!colorscale->shader) {
|
|
|
|
gst_gl_context_set_error (filter->context,
|
|
|
|
"Failed to initialize identity shader");
|
|
|
|
GST_ELEMENT_ERROR (colorscale, RESOURCE, NOT_FOUND, ("%s",
|
|
|
|
gst_gl_context_get_error ()), (NULL));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-04-30 16:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_colorscale_del_gl_resources (GstGLFilter * filter)
|
|
|
|
{
|
|
|
|
GstGLColorscale *colorscale = GST_GL_COLORSCALE (filter);
|
|
|
|
|
|
|
|
if (colorscale->shader) {
|
|
|
|
gst_gl_context_del_shader (filter->context, colorscale->shader);
|
|
|
|
colorscale->shader = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-20 13:45:26 +00:00
|
|
|
static gboolean
|
2012-09-25 08:07:23 +00:00
|
|
|
gst_gl_colorscale_filter_texture (GstGLFilter * filter, guint in_tex,
|
|
|
|
guint out_tex)
|
2012-09-20 13:45:26 +00:00
|
|
|
{
|
|
|
|
GstGLColorscale *colorscale;
|
|
|
|
|
2012-09-25 08:07:23 +00:00
|
|
|
colorscale = GST_GL_COLORSCALE (filter);
|
2012-09-20 13:45:26 +00:00
|
|
|
|
2014-11-12 12:47:13 +00:00
|
|
|
if (gst_gl_context_get_gl_api (filter->context) & (GST_GL_API_GLES2 |
|
|
|
|
GST_GL_API_OPENGL3))
|
2014-05-01 04:11:00 +00:00
|
|
|
gst_gl_filter_render_to_target_with_shader (filter, TRUE, in_tex, out_tex,
|
|
|
|
colorscale->shader);
|
2014-04-30 16:30:06 +00:00
|
|
|
|
2014-05-01 04:11:00 +00:00
|
|
|
if (gst_gl_context_get_gl_api (filter->context) & GST_GL_API_OPENGL)
|
|
|
|
gst_gl_filter_render_to_target (filter, TRUE, in_tex, out_tex,
|
|
|
|
gst_gl_colorscale_callback, colorscale);
|
2012-06-04 08:44:56 +00:00
|
|
|
|
2012-09-20 13:45:26 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2008-06-10 22:59:57 +00:00
|
|
|
|
2012-09-25 08:07:23 +00:00
|
|
|
static void
|
|
|
|
gst_gl_colorscale_callback (gint width, gint height, guint texture,
|
|
|
|
gpointer stuff)
|
2012-09-20 13:45:26 +00:00
|
|
|
{
|
2012-09-25 08:07:23 +00:00
|
|
|
GstGLFilter *filter = GST_GL_FILTER (stuff);
|
2012-09-20 13:45:26 +00:00
|
|
|
|
2014-11-28 00:04:22 +00:00
|
|
|
#if GST_GL_HAVE_OPENGL
|
2014-02-10 20:24:40 +00:00
|
|
|
if (gst_gl_context_get_gl_api (filter->context) & GST_GL_API_OPENGL) {
|
|
|
|
const GstGLFuncs *gl = filter->context->gl_vtable;
|
|
|
|
|
|
|
|
gl->MatrixMode (GL_PROJECTION);
|
|
|
|
gl->LoadIdentity ();
|
|
|
|
}
|
2014-11-27 23:59:46 +00:00
|
|
|
#endif
|
2012-09-20 13:45:26 +00:00
|
|
|
|
2012-09-25 08:07:23 +00:00
|
|
|
gst_gl_filter_draw_texture (filter, texture, width, height);
|
2008-06-10 22:59:57 +00:00
|
|
|
}
|