2014-03-16 10:23:16 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:element-gleffects.
|
2017-03-08 18:01:13 +00:00
|
|
|
* @title: gleffects.
|
2014-03-16 10:23:16 +00:00
|
|
|
*
|
|
|
|
* GL Shading Language effects.
|
|
|
|
*
|
2017-03-08 18:01:13 +00:00
|
|
|
* ## Examples
|
2014-03-16 10:23:16 +00:00
|
|
|
* |[
|
2015-12-14 02:09:46 +00:00
|
|
|
* gst-launch-1.0 videotestsrc ! glupload ! gleffects effect=5 ! glimagesink
|
2014-03-16 10:23:16 +00:00
|
|
|
* ]|
|
|
|
|
* FBO (Frame Buffer Object) and GLSL (OpenGL Shading Language) are required.
|
2017-03-08 18:01:13 +00:00
|
|
|
*
|
2014-03-16 10:23:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gst/gl/gstglconfig.h>
|
|
|
|
#include "gstgleffects.h"
|
|
|
|
|
|
|
|
#define GST_CAT_DEFAULT gst_gl_effects_debug
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
|
|
|
|
2015-04-05 18:18:56 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0 = 0x0,
|
|
|
|
PROP_EFFECT = 0x1 << 1,
|
|
|
|
PROP_HSWAP = 0x1 << 2,
|
|
|
|
PROP_INVERT = 0x1 << 3
|
|
|
|
};
|
|
|
|
|
2014-03-16 10:23:16 +00:00
|
|
|
#define DEBUG_INIT \
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_gl_effects_debug, "gleffects", 0, "gleffects element");
|
|
|
|
|
2015-04-26 19:39:06 +00:00
|
|
|
#define gst_gl_effects_parent_class parent_class
|
2014-03-16 10:23:16 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstGLEffects, gst_gl_effects, GST_TYPE_GL_FILTER,
|
|
|
|
DEBUG_INIT);
|
|
|
|
|
|
|
|
static void gst_gl_effects_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_gl_effects_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
2015-04-26 19:39:06 +00:00
|
|
|
static gboolean gst_gl_effects_init_resources (GstBaseTransform * trans);
|
|
|
|
static gboolean gst_gl_effects_reset_resources (GstBaseTransform * trans);
|
2014-03-16 10:23:16 +00:00
|
|
|
|
|
|
|
static gboolean gst_gl_effects_on_init_gl_context (GstGLFilter * filter);
|
|
|
|
|
|
|
|
static void gst_gl_effects_ghash_func_clean (gpointer key, gpointer value,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static gboolean gst_gl_effects_filter_texture (GstGLFilter * filter,
|
2016-07-11 14:30:22 +00:00
|
|
|
GstGLMemory * in_tex, GstGLMemory * out_tex);
|
2015-04-05 18:18:56 +00:00
|
|
|
static gboolean gst_gl_effects_filters_is_property_supported (const
|
|
|
|
GstGLEffectsFilterDescriptor *, gint property);
|
2014-03-16 10:23:16 +00:00
|
|
|
|
|
|
|
/* dont' forget to edit the following when a new effect is added */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
GST_GL_EFFECT_IDENTITY,
|
|
|
|
GST_GL_EFFECT_MIRROR,
|
|
|
|
GST_GL_EFFECT_SQUEEZE,
|
|
|
|
GST_GL_EFFECT_STRETCH,
|
|
|
|
GST_GL_EFFECT_TUNNEL,
|
|
|
|
GST_GL_EFFECT_FISHEYE,
|
|
|
|
GST_GL_EFFECT_TWIRL,
|
|
|
|
GST_GL_EFFECT_BULGE,
|
|
|
|
GST_GL_EFFECT_SQUARE,
|
|
|
|
GST_GL_EFFECT_HEAT,
|
|
|
|
GST_GL_EFFECT_SEPIA,
|
|
|
|
GST_GL_EFFECT_XPRO,
|
|
|
|
GST_GL_EFFECT_LUMA_XPRO,
|
|
|
|
GST_GL_EFFECT_XRAY,
|
|
|
|
GST_GL_EFFECT_SIN,
|
|
|
|
GST_GL_EFFECT_GLOW,
|
2015-03-22 10:20:49 +00:00
|
|
|
GST_GL_EFFECT_SOBEL,
|
2015-03-22 10:13:30 +00:00
|
|
|
GST_GL_EFFECT_BLUR,
|
2015-03-22 10:22:52 +00:00
|
|
|
GST_GL_EFFECT_LAPLACIAN,
|
2014-03-16 10:23:16 +00:00
|
|
|
GST_GL_N_EFFECTS
|
|
|
|
} GstGLEffectsEffect;
|
|
|
|
|
2015-04-05 18:18:56 +00:00
|
|
|
static const GEnumValue *
|
|
|
|
gst_gl_effects_get_effects (void)
|
2014-03-16 10:23:16 +00:00
|
|
|
{
|
|
|
|
static const GEnumValue effect_types[] = {
|
|
|
|
{GST_GL_EFFECT_IDENTITY, "Do nothing Effect", "identity"},
|
|
|
|
{GST_GL_EFFECT_MIRROR, "Mirror Effect", "mirror"},
|
|
|
|
{GST_GL_EFFECT_SQUEEZE, "Squeeze Effect", "squeeze"},
|
|
|
|
{GST_GL_EFFECT_STRETCH, "Stretch Effect", "stretch"},
|
2015-03-30 12:49:01 +00:00
|
|
|
{GST_GL_EFFECT_TUNNEL, "Light Tunnel Effect", "tunnel"},
|
2014-03-16 10:23:16 +00:00
|
|
|
{GST_GL_EFFECT_FISHEYE, "FishEye Effect", "fisheye"},
|
|
|
|
{GST_GL_EFFECT_TWIRL, "Twirl Effect", "twirl"},
|
|
|
|
{GST_GL_EFFECT_BULGE, "Bulge Effect", "bulge"},
|
|
|
|
{GST_GL_EFFECT_SQUARE, "Square Effect", "square"},
|
|
|
|
{GST_GL_EFFECT_HEAT, "Heat Signature Effect", "heat"},
|
|
|
|
{GST_GL_EFFECT_SEPIA, "Sepia Toning Effect", "sepia"},
|
|
|
|
{GST_GL_EFFECT_XPRO, "Cross Processing Effect", "xpro"},
|
|
|
|
{GST_GL_EFFECT_LUMA_XPRO, "Luma Cross Processing Effect", "lumaxpro"},
|
|
|
|
{GST_GL_EFFECT_XRAY, "Glowing negative effect", "xray"},
|
|
|
|
{GST_GL_EFFECT_SIN, "All Grey but Red Effect", "sin"},
|
|
|
|
{GST_GL_EFFECT_GLOW, "Glow Lighting Effect", "glow"},
|
2015-03-22 10:20:49 +00:00
|
|
|
{GST_GL_EFFECT_SOBEL, "Sobel edge detection Effect", "sobel"},
|
2015-03-22 10:13:30 +00:00
|
|
|
{GST_GL_EFFECT_BLUR, "Blur with 9x9 separable convolution Effect", "blur"},
|
2015-03-22 10:22:52 +00:00
|
|
|
{GST_GL_EFFECT_LAPLACIAN, "Laplacian Convolution Demo Effect", "laplacian"},
|
2014-03-16 10:23:16 +00:00
|
|
|
{0, NULL, NULL}
|
|
|
|
};
|
2015-04-05 18:18:56 +00:00
|
|
|
return effect_types;
|
|
|
|
}
|
2014-03-16 10:23:16 +00:00
|
|
|
|
2015-04-05 18:18:56 +00:00
|
|
|
#define GST_TYPE_GL_EFFECTS_EFFECT (gst_gl_effects_effect_get_type ())
|
|
|
|
static GType
|
|
|
|
gst_gl_effects_effect_get_type (void)
|
|
|
|
{
|
|
|
|
static GType gl_effects_effect_type = 0;
|
2014-03-16 10:23:16 +00:00
|
|
|
if (!gl_effects_effect_type) {
|
|
|
|
gl_effects_effect_type =
|
2015-04-05 18:18:56 +00:00
|
|
|
g_enum_register_static ("GstGLEffectsEffect",
|
|
|
|
gst_gl_effects_get_effects ());
|
2014-03-16 10:23:16 +00:00
|
|
|
}
|
|
|
|
return gl_effects_effect_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_effects_set_effect (GstGLEffects * effects, gint effect_type)
|
|
|
|
{
|
2015-03-13 10:25:35 +00:00
|
|
|
GstGLBaseFilterClass *filter_class = GST_GL_BASE_FILTER_GET_CLASS (effects);
|
2014-03-16 10:23:16 +00:00
|
|
|
|
|
|
|
switch (effect_type) {
|
|
|
|
case GST_GL_EFFECT_IDENTITY:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_identity;
|
2014-11-27 10:05:45 +00:00
|
|
|
filter_class->supported_gl_api =
|
|
|
|
GST_GL_API_GLES2 | GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
|
|
|
effects->current_effect = effect_type;
|
2014-03-16 10:23:16 +00:00
|
|
|
break;
|
|
|
|
case GST_GL_EFFECT_MIRROR:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_mirror;
|
2014-11-27 10:05:45 +00:00
|
|
|
filter_class->supported_gl_api =
|
|
|
|
GST_GL_API_GLES2 | GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
|
|
|
effects->current_effect = effect_type;
|
2014-03-16 10:23:16 +00:00
|
|
|
break;
|
|
|
|
case GST_GL_EFFECT_SQUEEZE:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_squeeze;
|
2014-11-27 10:05:45 +00:00
|
|
|
filter_class->supported_gl_api =
|
|
|
|
GST_GL_API_GLES2 | GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
|
|
|
effects->current_effect = effect_type;
|
2014-03-16 10:23:16 +00:00
|
|
|
break;
|
|
|
|
case GST_GL_EFFECT_STRETCH:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_stretch;
|
2015-03-30 12:49:01 +00:00
|
|
|
filter_class->supported_gl_api =
|
|
|
|
GST_GL_API_GLES2 | GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
|
|
|
effects->current_effect = effect_type;
|
2014-03-16 10:23:16 +00:00
|
|
|
break;
|
|
|
|
case GST_GL_EFFECT_TUNNEL:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_tunnel;
|
2015-03-30 12:49:01 +00:00
|
|
|
filter_class->supported_gl_api =
|
|
|
|
GST_GL_API_GLES2 | GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
|
|
|
effects->current_effect = effect_type;
|
2014-03-16 10:23:16 +00:00
|
|
|
break;
|
|
|
|
case GST_GL_EFFECT_FISHEYE:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_fisheye;
|
2015-03-30 12:49:01 +00:00
|
|
|
filter_class->supported_gl_api =
|
|
|
|
GST_GL_API_GLES2 | GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
|
|
|
effects->current_effect = effect_type;
|
2014-03-16 10:23:16 +00:00
|
|
|
break;
|
|
|
|
case GST_GL_EFFECT_TWIRL:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_twirl;
|
2015-03-30 12:49:01 +00:00
|
|
|
filter_class->supported_gl_api =
|
|
|
|
GST_GL_API_GLES2 | GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
|
|
|
effects->current_effect = effect_type;
|
2014-03-16 10:23:16 +00:00
|
|
|
break;
|
|
|
|
case GST_GL_EFFECT_BULGE:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_bulge;
|
2015-03-30 12:49:01 +00:00
|
|
|
filter_class->supported_gl_api =
|
|
|
|
GST_GL_API_GLES2 | GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
|
|
|
effects->current_effect = effect_type;
|
2014-03-16 10:23:16 +00:00
|
|
|
break;
|
|
|
|
case GST_GL_EFFECT_SQUARE:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_square;
|
2015-03-30 12:49:01 +00:00
|
|
|
filter_class->supported_gl_api =
|
|
|
|
GST_GL_API_GLES2 | GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
|
|
|
effects->current_effect = effect_type;
|
2014-03-16 10:23:16 +00:00
|
|
|
break;
|
|
|
|
case GST_GL_EFFECT_HEAT:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_heat;
|
2015-03-30 12:49:01 +00:00
|
|
|
filter_class->supported_gl_api =
|
|
|
|
GST_GL_API_GLES2 | GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
|
|
|
effects->current_effect = effect_type;
|
2014-03-16 10:23:16 +00:00
|
|
|
break;
|
|
|
|
case GST_GL_EFFECT_SEPIA:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_sepia;
|
2015-03-30 12:49:01 +00:00
|
|
|
filter_class->supported_gl_api =
|
|
|
|
GST_GL_API_GLES2 | GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
|
|
|
effects->current_effect = effect_type;
|
2014-03-16 10:23:16 +00:00
|
|
|
break;
|
|
|
|
case GST_GL_EFFECT_XPRO:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_xpro;
|
2015-03-30 12:49:01 +00:00
|
|
|
filter_class->supported_gl_api =
|
|
|
|
GST_GL_API_GLES2 | GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
|
|
|
effects->current_effect = effect_type;
|
2014-03-16 10:23:16 +00:00
|
|
|
break;
|
|
|
|
case GST_GL_EFFECT_LUMA_XPRO:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_luma_xpro;
|
2015-03-30 12:49:01 +00:00
|
|
|
filter_class->supported_gl_api =
|
|
|
|
GST_GL_API_GLES2 | GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
|
|
|
effects->current_effect = effect_type;
|
2014-03-16 10:23:16 +00:00
|
|
|
break;
|
|
|
|
case GST_GL_EFFECT_SIN:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_sin;
|
2015-03-30 12:49:01 +00:00
|
|
|
filter_class->supported_gl_api =
|
|
|
|
GST_GL_API_GLES2 | GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
|
|
|
effects->current_effect = effect_type;
|
|
|
|
break;
|
|
|
|
case GST_GL_EFFECT_XRAY:
|
2016-07-11 12:24:43 +00:00
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_xray;
|
2015-03-30 12:49:01 +00:00
|
|
|
filter_class->supported_gl_api =
|
|
|
|
GST_GL_API_GLES2 | GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
|
|
|
effects->current_effect = effect_type;
|
2014-03-16 10:23:16 +00:00
|
|
|
break;
|
|
|
|
case GST_GL_EFFECT_GLOW:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_glow;
|
2015-03-30 12:49:01 +00:00
|
|
|
filter_class->supported_gl_api =
|
2015-03-22 10:13:30 +00:00
|
|
|
GST_GL_API_GLES2 | GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
|
|
|
effects->current_effect = effect_type;
|
|
|
|
break;
|
2015-03-22 10:20:49 +00:00
|
|
|
case GST_GL_EFFECT_SOBEL:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_sobel;
|
|
|
|
filter_class->supported_gl_api =
|
|
|
|
GST_GL_API_GLES2 | GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
|
|
|
effects->current_effect = effect_type;
|
|
|
|
break;
|
2015-03-22 10:13:30 +00:00
|
|
|
case GST_GL_EFFECT_BLUR:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_blur;
|
|
|
|
filter_class->supported_gl_api =
|
2015-03-30 12:49:01 +00:00
|
|
|
GST_GL_API_GLES2 | GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
|
|
|
effects->current_effect = effect_type;
|
2014-03-16 10:23:16 +00:00
|
|
|
break;
|
2015-03-22 10:22:52 +00:00
|
|
|
case GST_GL_EFFECT_LAPLACIAN:
|
|
|
|
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_laplacian;
|
|
|
|
filter_class->supported_gl_api =
|
|
|
|
GST_GL_API_GLES2 | GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
|
|
|
effects->current_effect = effect_type;
|
|
|
|
break;
|
2014-03-16 10:23:16 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2015-03-30 12:49:01 +00:00
|
|
|
|
2014-03-16 10:23:16 +00:00
|
|
|
effects->current_effect = effect_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* init resources that need a gl context */
|
2016-11-07 15:21:20 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_effects_gl_start (GstGLBaseFilter * base_filter)
|
2014-03-16 10:23:16 +00:00
|
|
|
{
|
2016-11-07 15:21:20 +00:00
|
|
|
GstGLEffects *effects = GST_GL_EFFECTS (base_filter);
|
|
|
|
GstGLFilter *filter = GST_GL_FILTER (base_filter);
|
|
|
|
GstGLContext *context = base_filter->context;
|
2016-07-11 14:30:22 +00:00
|
|
|
GstGLBaseMemoryAllocator *base_alloc;
|
|
|
|
GstGLAllocationParams *params;
|
|
|
|
gint i;
|
|
|
|
|
2016-11-07 15:21:20 +00:00
|
|
|
if (!GST_GL_BASE_FILTER_CLASS (parent_class)->gl_start (base_filter))
|
|
|
|
return FALSE;
|
|
|
|
|
2016-07-11 14:30:22 +00:00
|
|
|
base_alloc = (GstGLBaseMemoryAllocator *)
|
2016-12-07 08:51:27 +00:00
|
|
|
gst_allocator_find (GST_GL_MEMORY_ALLOCATOR_NAME);
|
2016-07-11 14:30:22 +00:00
|
|
|
params =
|
|
|
|
(GstGLAllocationParams *) gst_gl_video_allocation_params_new (context,
|
2017-03-13 03:28:47 +00:00
|
|
|
NULL, &filter->out_info, 0, NULL, GST_GL_TEXTURE_TARGET_2D, GST_GL_RGBA);
|
2014-03-16 10:23:16 +00:00
|
|
|
|
|
|
|
for (i = 0; i < NEEDED_TEXTURES; i++) {
|
2016-07-11 14:30:22 +00:00
|
|
|
if (effects->midtexture[i])
|
|
|
|
gst_memory_unref (GST_MEMORY_CAST (effects->midtexture[i]));
|
2014-07-23 02:25:31 +00:00
|
|
|
|
2016-07-11 14:30:22 +00:00
|
|
|
effects->midtexture[i] =
|
|
|
|
(GstGLMemory *) gst_gl_base_memory_alloc (base_alloc, params);
|
2014-03-16 10:23:16 +00:00
|
|
|
}
|
2016-07-11 14:30:22 +00:00
|
|
|
|
|
|
|
gst_object_unref (base_alloc);
|
|
|
|
gst_gl_allocation_params_free (params);
|
2016-11-07 15:21:20 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2014-03-16 10:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* free resources that need a gl context */
|
|
|
|
static void
|
2016-11-07 15:21:20 +00:00
|
|
|
gst_gl_effects_gl_stop (GstGLBaseFilter * base_filter)
|
2014-03-16 10:23:16 +00:00
|
|
|
{
|
2016-11-07 15:21:20 +00:00
|
|
|
GstGLEffects *effects = GST_GL_EFFECTS (base_filter);
|
|
|
|
const GstGLFuncs *gl = base_filter->context->gl_vtable;
|
2014-05-08 15:08:08 +00:00
|
|
|
gint i = 0;
|
2014-03-16 10:23:16 +00:00
|
|
|
|
|
|
|
for (i = 0; i < NEEDED_TEXTURES; i++) {
|
2016-07-11 14:30:22 +00:00
|
|
|
gst_memory_unref (GST_MEMORY_CAST (effects->midtexture[i]));
|
2014-03-16 10:23:16 +00:00
|
|
|
}
|
2016-11-07 15:21:20 +00:00
|
|
|
|
2014-03-16 10:23:16 +00:00
|
|
|
for (i = 0; i < GST_GL_EFFECTS_N_CURVES; i++) {
|
2014-05-08 15:08:08 +00:00
|
|
|
gl->DeleteTextures (1, &effects->curve[i]);
|
2014-03-16 10:23:16 +00:00
|
|
|
effects->curve[i] = 0;
|
|
|
|
}
|
2016-11-07 15:21:20 +00:00
|
|
|
|
|
|
|
GST_GL_BASE_FILTER_CLASS (parent_class)->gl_stop (base_filter);
|
2014-03-16 10:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_effects_class_init (GstGLEffectsClass * klass)
|
|
|
|
{
|
2015-04-05 18:18:56 +00:00
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
2014-03-16 10:23:16 +00:00
|
|
|
|
2015-04-26 19:39:06 +00:00
|
|
|
GST_BASE_TRANSFORM_CLASS (klass)->start = gst_gl_effects_init_resources;
|
|
|
|
GST_BASE_TRANSFORM_CLASS (klass)->stop = gst_gl_effects_reset_resources;
|
|
|
|
|
2016-11-07 15:21:20 +00:00
|
|
|
GST_GL_BASE_FILTER_CLASS (klass)->gl_start = gst_gl_effects_gl_start;
|
|
|
|
GST_GL_BASE_FILTER_CLASS (klass)->gl_stop = gst_gl_effects_gl_stop;
|
|
|
|
|
2014-03-16 10:23:16 +00:00
|
|
|
GST_GL_FILTER_CLASS (klass)->filter_texture = gst_gl_effects_filter_texture;
|
2015-04-26 19:42:03 +00:00
|
|
|
GST_GL_FILTER_CLASS (klass)->init_fbo = gst_gl_effects_on_init_gl_context;
|
2014-03-16 10:23:16 +00:00
|
|
|
|
2015-04-05 18:18:56 +00:00
|
|
|
klass->filter_descriptor = NULL;
|
2014-03-16 10:23:16 +00:00
|
|
|
|
|
|
|
gst_element_class_set_metadata (element_class,
|
|
|
|
"Gstreamer OpenGL Effects", "Filter/Effect/Video",
|
|
|
|
"GL Shading Language effects",
|
|
|
|
"Filippo Argiolas <filippo.argiolas@gmail.com>");
|
2014-11-27 10:05:45 +00:00
|
|
|
|
2015-03-13 10:25:35 +00:00
|
|
|
GST_GL_BASE_FILTER_CLASS (klass)->supported_gl_api =
|
2014-11-27 10:05:45 +00:00
|
|
|
GST_GL_API_OPENGL | GST_GL_API_GLES2 | GST_GL_API_OPENGL3;
|
2014-03-16 10:23:16 +00:00
|
|
|
}
|
|
|
|
|
2015-04-05 18:18:56 +00:00
|
|
|
static void
|
|
|
|
gst_gl_effects_filter_class_init (GstGLEffectsClass * klass,
|
|
|
|
const GstGLEffectsFilterDescriptor * filter_descriptor)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2016-03-10 14:40:39 +00:00
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
2015-04-05 18:18:56 +00:00
|
|
|
|
|
|
|
klass->filter_descriptor = filter_descriptor;
|
|
|
|
|
|
|
|
gobject_class->set_property = gst_gl_effects_set_property;
|
|
|
|
gobject_class->get_property = gst_gl_effects_get_property;
|
|
|
|
|
|
|
|
/* if filterDescriptor is null it's a generic gleffects */
|
|
|
|
if (!filter_descriptor) {
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_EFFECT,
|
|
|
|
g_param_spec_enum ("effect",
|
|
|
|
"Effect",
|
|
|
|
"Select which effect apply to GL video texture",
|
|
|
|
GST_TYPE_GL_EFFECTS_EFFECT,
|
|
|
|
GST_GL_EFFECT_IDENTITY,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2016-03-10 14:40:39 +00:00
|
|
|
} else {
|
|
|
|
gchar *description = g_strdup_printf ("GL Shading Language effects - %s",
|
|
|
|
filter_descriptor->filter_longname);
|
|
|
|
|
|
|
|
gst_element_class_set_metadata (element_class,
|
|
|
|
filter_descriptor->filter_longname, "Filter/Effect/Video",
|
|
|
|
description, "Filippo Argiolas <filippo.argiolas@gmail.com>");
|
|
|
|
|
|
|
|
g_free (description);
|
2015-04-05 18:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_HSWAP,
|
|
|
|
g_param_spec_boolean ("hswap",
|
|
|
|
"Horizontal Swap",
|
|
|
|
"Switch video texture left to right, useful with webcams",
|
|
|
|
FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
/* FIXME: make it work on every effect */
|
|
|
|
if (gst_gl_effects_filters_is_property_supported (filter_descriptor,
|
|
|
|
PROP_INVERT)) {
|
|
|
|
g_object_class_install_property (gobject_class, PROP_INVERT,
|
|
|
|
g_param_spec_boolean ("invert", "Invert the colors for sobel effect",
|
|
|
|
"Invert colors to get dark edges on bright background when using sobel effect",
|
|
|
|
FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-16 10:23:16 +00:00
|
|
|
static void
|
2016-07-11 14:30:22 +00:00
|
|
|
set_horizontal_swap (GstGLEffects * effects)
|
2014-03-16 10:23:16 +00:00
|
|
|
{
|
|
|
|
#if GST_GL_HAVE_OPENGL
|
2016-07-11 14:30:22 +00:00
|
|
|
GstGLContext *context = GST_GL_BASE_FILTER (effects)->context;
|
|
|
|
const GstGLFuncs *gl = context->gl_vtable;
|
2014-03-16 10:23:16 +00:00
|
|
|
|
|
|
|
if (gst_gl_context_get_gl_api (context) & GST_GL_API_OPENGL) {
|
|
|
|
const gfloat mirrormatrix[16] = {
|
|
|
|
-1.0, 0.0, 0.0, 0.0,
|
|
|
|
0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0
|
|
|
|
};
|
|
|
|
|
|
|
|
gl->MatrixMode (GL_MODELVIEW);
|
|
|
|
gl->LoadMatrixf (mirrormatrix);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_effects_init (GstGLEffects * effects)
|
|
|
|
{
|
|
|
|
effects->horizontal_swap = FALSE;
|
2015-03-22 10:20:49 +00:00
|
|
|
effects->invert = FALSE;
|
2015-04-05 18:18:56 +00:00
|
|
|
effects->effect = gst_gl_effects_identity;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_effects_filter_init (GstGLEffects * effects)
|
|
|
|
{
|
|
|
|
gst_gl_effects_set_effect (effects,
|
|
|
|
GST_GL_EFFECTS_GET_CLASS (effects)->filter_descriptor->effect);
|
2014-03-16 10:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_effects_ghash_func_clean (gpointer key, gpointer value, gpointer data)
|
|
|
|
{
|
|
|
|
GstGLShader *shader = (GstGLShader *) value;
|
|
|
|
|
2016-11-10 08:14:24 +00:00
|
|
|
gst_object_unref (shader);
|
2014-03-16 10:23:16 +00:00
|
|
|
|
|
|
|
value = NULL;
|
|
|
|
}
|
|
|
|
|
2015-04-26 19:39:06 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_effects_reset_resources (GstBaseTransform * trans)
|
2014-03-16 10:23:16 +00:00
|
|
|
{
|
2015-04-26 19:39:06 +00:00
|
|
|
GstGLEffects *effects = GST_GL_EFFECTS (trans);
|
2014-03-16 10:23:16 +00:00
|
|
|
|
|
|
|
/* release shaders in the gl thread */
|
|
|
|
g_hash_table_foreach (effects->shaderstable, gst_gl_effects_ghash_func_clean,
|
2015-04-26 19:39:06 +00:00
|
|
|
effects);
|
2014-03-16 10:23:16 +00:00
|
|
|
|
|
|
|
/* clean the htable without calling values destructors
|
|
|
|
* because shaders have been released in the glthread
|
|
|
|
* through the foreach func */
|
|
|
|
g_hash_table_unref (effects->shaderstable);
|
|
|
|
effects->shaderstable = NULL;
|
2015-04-26 19:39:06 +00:00
|
|
|
|
|
|
|
return GST_BASE_TRANSFORM_CLASS (parent_class)->stop (trans);
|
2014-03-16 10:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_effects_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstGLEffects *effects = GST_GL_EFFECTS (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_EFFECT:
|
|
|
|
gst_gl_effects_set_effect (effects, g_value_get_enum (value));
|
|
|
|
break;
|
|
|
|
case PROP_HSWAP:
|
|
|
|
effects->horizontal_swap = g_value_get_boolean (value);
|
|
|
|
break;
|
2015-03-22 10:20:49 +00:00
|
|
|
case PROP_INVERT:
|
|
|
|
effects->invert = g_value_get_boolean (value);
|
|
|
|
break;
|
2014-03-16 10:23:16 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_effects_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstGLEffects *effects = GST_GL_EFFECTS (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_EFFECT:
|
|
|
|
g_value_set_enum (value, effects->current_effect);
|
|
|
|
break;
|
|
|
|
case PROP_HSWAP:
|
|
|
|
g_value_set_boolean (value, effects->horizontal_swap);
|
|
|
|
break;
|
2015-03-22 10:20:49 +00:00
|
|
|
case PROP_INVERT:
|
|
|
|
g_value_set_boolean (value, effects->invert);
|
|
|
|
break;
|
2014-03-16 10:23:16 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-26 19:39:06 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_effects_init_resources (GstBaseTransform * trans)
|
2014-03-16 10:23:16 +00:00
|
|
|
{
|
2015-04-26 19:39:06 +00:00
|
|
|
GstGLEffects *effects = GST_GL_EFFECTS (trans);
|
2014-03-16 10:23:16 +00:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
effects->shaderstable = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
|
|
|
|
for (i = 0; i < NEEDED_TEXTURES; i++) {
|
|
|
|
effects->midtexture[i] = 0;
|
|
|
|
}
|
|
|
|
for (i = 0; i < GST_GL_EFFECTS_N_CURVES; i++) {
|
|
|
|
effects->curve[i] = 0;
|
|
|
|
}
|
2015-04-26 19:39:06 +00:00
|
|
|
|
|
|
|
return GST_BASE_TRANSFORM_CLASS (parent_class)->start (trans);
|
2014-03-16 10:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_gl_effects_on_init_gl_context (GstGLFilter * filter)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2016-07-11 14:30:22 +00:00
|
|
|
gst_gl_effects_filter_texture (GstGLFilter * filter, GstGLMemory * in_tex,
|
|
|
|
GstGLMemory * out_tex)
|
2014-03-16 10:23:16 +00:00
|
|
|
{
|
|
|
|
GstGLEffects *effects = GST_GL_EFFECTS (filter);
|
|
|
|
|
|
|
|
effects->intexture = in_tex;
|
|
|
|
effects->outtexture = out_tex;
|
|
|
|
|
|
|
|
if (effects->horizontal_swap == TRUE)
|
2016-07-11 14:30:22 +00:00
|
|
|
set_horizontal_swap (effects);
|
2014-03-16 10:23:16 +00:00
|
|
|
|
|
|
|
effects->effect (effects);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-03-30 12:49:01 +00:00
|
|
|
|
|
|
|
GstGLShader *
|
|
|
|
gst_gl_effects_get_fragment_shader (GstGLEffects * effects,
|
2015-08-10 14:38:32 +00:00
|
|
|
const gchar * shader_name, const gchar * shader_source_gles2)
|
2015-03-30 12:49:01 +00:00
|
|
|
{
|
2015-05-26 02:47:40 +00:00
|
|
|
GstGLShader *shader = NULL;
|
2015-03-30 12:49:01 +00:00
|
|
|
GstGLFilter *filter = GST_GL_FILTER (effects);
|
|
|
|
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
|
|
|
|
|
|
|
|
shader = g_hash_table_lookup (effects->shaderstable, shader_name);
|
|
|
|
|
|
|
|
if (!shader) {
|
2015-09-04 06:02:32 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
if (!(shader = gst_gl_shader_new_link_with_stages (context, &error,
|
|
|
|
gst_glsl_stage_new_default_vertex (context),
|
|
|
|
gst_glsl_stage_new_with_string (context, GL_FRAGMENT_SHADER,
|
2015-12-29 06:04:57 +00:00
|
|
|
GST_GLSL_VERSION_NONE,
|
|
|
|
GST_GLSL_PROFILE_ES | GST_GLSL_PROFILE_COMPATIBILITY,
|
2015-09-04 06:02:32 +00:00
|
|
|
shader_source_gles2), NULL))) {
|
2015-08-10 14:38:32 +00:00
|
|
|
GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND,
|
2015-09-04 06:02:32 +00:00
|
|
|
("Failed to initialize %s shader", shader_name), (NULL));
|
2015-03-30 12:49:01 +00:00
|
|
|
}
|
2015-05-26 02:47:40 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
filter->draw_attr_position_loc =
|
|
|
|
gst_gl_shader_get_attribute_location (shader, "a_position");
|
|
|
|
filter->draw_attr_texture_loc =
|
|
|
|
gst_gl_shader_get_attribute_location (shader, "a_texcoord");
|
|
|
|
}
|
2015-05-26 02:47:40 +00:00
|
|
|
|
2015-08-10 14:38:32 +00:00
|
|
|
g_hash_table_insert (effects->shaderstable, (gchar *) shader_name, shader);
|
2015-03-30 12:49:01 +00:00
|
|
|
|
|
|
|
return shader;
|
|
|
|
}
|
2015-04-05 18:18:56 +00:00
|
|
|
|
|
|
|
static const GstGLEffectsFilterDescriptor *
|
|
|
|
gst_gl_effects_filters_supported_properties (void)
|
|
|
|
{
|
|
|
|
/* Horizontal swap property is supported by all filters */
|
|
|
|
static const GstGLEffectsFilterDescriptor effects[] = {
|
|
|
|
{GST_GL_EFFECT_SOBEL, PROP_INVERT, NULL},
|
|
|
|
{GST_GL_EFFECT_LAPLACIAN, PROP_INVERT, NULL},
|
|
|
|
{0, 0, NULL}
|
|
|
|
};
|
|
|
|
return effects;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline gboolean
|
|
|
|
gst_gl_effects_filters_is_property_supported (const GstGLEffectsFilterDescriptor
|
|
|
|
* descriptor, gint property)
|
|
|
|
{
|
|
|
|
/* generic filter (NULL descriptor) supports all properties */
|
|
|
|
return !descriptor || (descriptor->supported_properties & property);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const GstGLEffectsFilterDescriptor *
|
|
|
|
gst_gl_effects_filters_descriptors (void)
|
|
|
|
{
|
|
|
|
static GstGLEffectsFilterDescriptor *descriptors = NULL;
|
|
|
|
if (!descriptors) {
|
2015-05-27 12:05:11 +00:00
|
|
|
const GEnumValue *e;
|
2015-04-05 18:18:56 +00:00
|
|
|
const GEnumValue *effect = gst_gl_effects_get_effects ();
|
2015-05-27 12:05:11 +00:00
|
|
|
const GstGLEffectsFilterDescriptor *defined;
|
|
|
|
guint n_filters = 0, i;
|
|
|
|
|
|
|
|
for (e = effect; NULL != e->value_nick; ++e, ++n_filters) {
|
2015-04-05 18:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
descriptors = g_new0 (GstGLEffectsFilterDescriptor, n_filters + 1);
|
2015-05-27 12:05:11 +00:00
|
|
|
for (i = 0; i < n_filters; ++i, ++effect) {
|
2015-04-05 18:18:56 +00:00
|
|
|
descriptors[i].effect = effect->value;
|
|
|
|
descriptors[i].filter_name = effect->value_nick;
|
2016-03-10 14:40:39 +00:00
|
|
|
descriptors[i].filter_longname = effect->value_name;
|
2015-04-05 18:18:56 +00:00
|
|
|
}
|
|
|
|
|
2015-05-27 12:05:11 +00:00
|
|
|
for (defined = gst_gl_effects_filters_supported_properties ();
|
2015-04-05 18:18:56 +00:00
|
|
|
0 != defined->supported_properties; ++defined) {
|
|
|
|
|
2015-05-27 12:05:11 +00:00
|
|
|
for (i = 0; i < n_filters; ++i) {
|
2015-04-05 18:18:56 +00:00
|
|
|
if (descriptors[i].effect == defined->effect) {
|
|
|
|
descriptors[i].supported_properties = defined->supported_properties;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i >= n_filters) {
|
|
|
|
GST_WARNING ("Could not match gstgleffects-%s descriptor",
|
|
|
|
defined->filter_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return descriptors;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_gl_effects_register_filters (GstPlugin * plugin, GstRank rank)
|
|
|
|
{
|
|
|
|
static volatile gsize registered = 0;
|
|
|
|
|
|
|
|
if (g_once_init_enter (®istered)) {
|
|
|
|
GTypeInfo info = {
|
|
|
|
sizeof (GstGLEffectsClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_gl_effects_filter_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GstGLEffects),
|
|
|
|
0,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
GType generic_type =
|
|
|
|
g_type_register_static (GST_TYPE_GL_EFFECTS, "GstGLEffectsGeneric",
|
|
|
|
&info, 0);
|
|
|
|
|
|
|
|
if (gst_element_register (plugin, "gleffects", rank, generic_type)) {
|
2015-05-27 12:05:11 +00:00
|
|
|
const GstGLEffectsFilterDescriptor *filters;
|
|
|
|
for (filters = gst_gl_effects_filters_descriptors ();
|
|
|
|
NULL != filters->filter_name; ++filters) {
|
2015-04-05 18:18:56 +00:00
|
|
|
gchar *name = g_strdup_printf ("gleffects_%s", filters->filter_name);
|
|
|
|
GTypeInfo info = {
|
|
|
|
sizeof (GstGLEffectsClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_gl_effects_filter_class_init,
|
|
|
|
NULL,
|
|
|
|
filters,
|
|
|
|
sizeof (GstGLEffects),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_gl_effects_filter_init
|
|
|
|
};
|
|
|
|
GType type =
|
|
|
|
g_type_register_static (GST_TYPE_GL_EFFECTS, name, &info, 0);
|
|
|
|
if (!gst_element_register (plugin, name, rank, type)) {
|
|
|
|
GST_WARNING ("Could not register %s", name);
|
|
|
|
}
|
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_once_init_leave (®istered, generic_type);
|
|
|
|
}
|
|
|
|
return registered;
|
|
|
|
}
|