1 /*
2  * GStreamer
3  * Copyright (C) 2009 Julien Isorce <julien.isorce@mail.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 /**
22  * SECTION:element-deinterlace
23  * @title: deinterlace
24  *
25  * Deinterlacing using based on fragment shaders.
26  *
27  * ## Examples
28  * |[
29  * gst-launch-1.0 videotestsrc ! glupload ! gldeinterlace ! glimagesink
30  * ]|
31  * FBO (Frame Buffer Object) and GLSL (OpenGL Shading Language) are required.
32  *
33  */
34 
35 #ifdef HAVE_CONFIG_H
36 #include "config.h"
37 #endif
38 
39 #include <gst/gl/gstglfuncs.h>
40 
41 #include "gstgldeinterlace.h"
42 
43 #define GST_CAT_DEFAULT gst_gl_deinterlace_debug
44 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
45 
46 enum
47 {
48   PROP_0,
49   PROP_METHOD
50 };
51 
52 #define DEBUG_INIT \
53   GST_DEBUG_CATEGORY_INIT (gst_gl_deinterlace_debug, "gldeinterlace", 0, "gldeinterlace element");
54 #define gst_gl_deinterlace_parent_class parent_class
55 G_DEFINE_TYPE_WITH_CODE (GstGLDeinterlace, gst_gl_deinterlace,
56     GST_TYPE_GL_FILTER, DEBUG_INIT);
57 
58 static void gst_gl_deinterlace_set_property (GObject * object,
59     guint prop_id, const GValue * value, GParamSpec * pspec);
60 static void gst_gl_deinterlace_get_property (GObject * object,
61     guint prop_id, GValue * value, GParamSpec * pspec);
62 
63 static gboolean gst_gl_deinterlace_start (GstBaseTransform * trans);
64 static gboolean gst_gl_deinterlace_reset (GstBaseTransform * trans);
65 static GstCaps *gst_gl_deinterlace_transform_internal_caps (GstGLFilter *
66     filter, GstPadDirection direction, GstCaps * caps, GstCaps * caps_filter);
67 static gboolean gst_gl_deinterlace_init_fbo (GstGLFilter * filter);
68 static gboolean gst_gl_deinterlace_filter (GstGLFilter * filter,
69     GstBuffer * inbuf, GstBuffer * outbuf);
70 static gboolean gst_gl_deinterlace_filter_texture (GstGLFilter * filter,
71     GstGLMemory * in_tex, GstGLMemory * out_tex);
72 static gboolean gst_gl_deinterlace_vfir_callback (GstGLFilter * filter,
73     GstGLMemory * in_tex, gpointer stuff);
74 static gboolean gst_gl_deinterlace_greedyh_callback (GstGLFilter * filter,
75     GstGLMemory * in_tex, gpointer stuff);
76 
77 /* *INDENT-OFF* */
78 static const gchar *greedyh_fragment_source =
79   "uniform sampler2D tex;\n"
80   "uniform sampler2D tex_prev;\n"
81   "uniform float max_comb;\n"
82   "uniform float motion_threshold;\n"
83   "uniform float motion_sense;\n"
84   "uniform float width;\n"
85   "uniform float height;\n"
86   "varying vec2 v_texcoord;\n"
87 
88   "void main () {\n"
89   "  if (int(mod(v_texcoord.y * height, 2.0)) == 0) {\n"
90   "    gl_FragColor = vec4(texture2D(tex_prev, v_texcoord).rgb, 1.0);\n"
91   "  } else {\n"
92   "    vec2 texcoord_L1_a1, texcoord_L3_a1, texcoord_L1, texcoord_L3, texcoord_L1_1, texcoord_L3_1;\n"
93   "    vec3 L1_a1, L3_a1, L1, L3, L1_1, L3_1;\n"
94 
95   "    texcoord_L1 = vec2(v_texcoord.x, v_texcoord.y - 1.0 / height);\n"
96   "    texcoord_L3 = vec2(v_texcoord.x, v_texcoord.y + 1.0 / height);\n"
97   "    L1 = texture2D(tex_prev, texcoord_L1).rgb;\n"
98   "    L3 = texture2D(tex_prev, texcoord_L3).rgb;\n"
99   "    if (v_texcoord.x == 1.0 && v_texcoord.y == 1.0) {\n"
100   "      L1_1 = L1;\n"
101   "      L3_1 = L3;\n"
102   "    } else {\n"
103   "      texcoord_L1_1 = vec2(v_texcoord.x + 1.0 / width, v_texcoord.y - 1.0 / height);\n"
104   "      texcoord_L3_1 = vec2(v_texcoord.x + 1.0 / width, v_texcoord.y + 1.0 / height);\n"
105   "      L1_1 = texture2D(tex_prev, texcoord_L1_1).rgb;\n"
106   "      L3_1 = texture2D(tex_prev, texcoord_L3_1).rgb;\n"
107   "    }\n"
108 
109   "    if (int(ceil(v_texcoord.x + v_texcoord.y)) == 0) {\n"
110   "      L1_a1 = L1;\n"
111   "      L3_a1 = L3;\n"
112   "    } else {\n"
113   "      texcoord_L1_a1 = vec2(v_texcoord.x - 1.0 / width, v_texcoord.y - 1.0 / height);\n"
114   "      texcoord_L3_a1 = vec2(v_texcoord.x - 1.0 / width, v_texcoord.y + 1.0 / height);\n"
115   "      L1_a1 = texture2D(tex_prev, texcoord_L1_a1).rgb;\n"
116   "      L3_a1 = texture2D(tex_prev, texcoord_L3_a1).rgb;\n"
117   "    }\n"
118           //STEP 1
119   "    vec3 avg_a1 = (L1_a1 + L3_a1) / 2.0;\n"
120   "    vec3 avg = (L1 + L3) / 2.0;\n"
121   "    vec3 avg_1 = (L1_1 + L3_1) / 2.0;\n"
122   "    vec3 avg_s = (avg_a1 + avg_1) / 2.0;\n"
123   "    vec3 avg_sc = (avg_s + avg) / 2.0;\n"
124   "    vec3 L2 = texture2D(tex, v_texcoord).rgb;\n"
125   "    vec3 LP2 = texture2D(tex_prev, v_texcoord).rgb;\n"
126   "    vec3 best;\n"
127   "    if (abs(L2.r - avg_sc.r) < abs(LP2.r - avg_sc.r)) {\n"
128   "      best.r = L2.r;\n" "    } else {\n"
129   "      best.r = LP2.r;\n"
130   "    }\n"
131 
132   "    if (abs(L2.g - avg_sc.g) < abs(LP2.g - avg_sc.g)) {\n"
133   "      best.g = L2.g;\n"
134   "    } else {\n"
135   "      best.g = LP2.g;\n"
136   "    }\n"
137 
138   "    if (abs(L2.b - avg_sc.b) < abs(LP2.b - avg_sc.b)) {\n"
139   "      best.b = L2.b;\n"
140   "    } else {\n"
141   "      best.b = LP2.b;\n"
142   "    }\n"
143           //STEP 2
144   "    vec3 last;\n"
145   "    last.r = clamp(best.r, max(min(L1.r, L3.r) - max_comb, 0.0), min(max(L1.r, L3.r) + max_comb, 1.0));\n"
146   "    last.g = clamp(best.g, max(min(L1.g, L3.g) - max_comb, 0.0), min(max(L1.g, L3.g) + max_comb, 1.0));\n"
147   "    last.b = clamp(best.b, max(min(L1.b, L3.b) - max_comb, 0.0), min(max(L1.b, L3.b) + max_comb, 1.0));\n"
148           //STEP 3
149   "    const vec3 luma = vec3 (0.299011, 0.586987, 0.114001);"
150   "    float mov = min(max(abs(dot(L2 - LP2, luma)) - motion_threshold, 0.0) * motion_sense, 1.0);\n"
151   "    last = last * (1.0 - mov) + avg_sc * mov;\n"
152   "    gl_FragColor = vec4(last, 1.0);\n"
153   "  }\n"
154   "}\n";
155 
156 const gchar *vfir_fragment_source =
157   "uniform sampler2D tex;\n"
158   "uniform float width;\n"
159   "uniform float height;\n"
160   "varying vec2 v_texcoord;\n"
161   "void main()\n"
162   "{\n"
163   "  vec2 topcoord, botcoord;\n"
164   "  vec4 cur_color, top_color, bot_color;\n"
165   "  topcoord.x = v_texcoord.x;\n"
166   "  botcoord.x = v_texcoord.x;\n"
167   "  if (v_texcoord.y == 0.0 || v_texcoord.y == 1.0) {\n"
168   "    topcoord.y = v_texcoord.y ;\n"
169   "    botcoord.y = v_texcoord.y ;\n"
170   "  }\n"
171   "  else {\n"
172   "    topcoord.y = v_texcoord.y - 1.0/height;\n"
173   "    botcoord.y = v_texcoord.y + 1.0/height;\n"
174   "  }\n"
175   "  cur_color = texture2D(tex, v_texcoord);\n"
176   "  top_color = texture2D(tex, topcoord);\n"
177   "  bot_color = texture2D(tex, botcoord);\n"
178   "  gl_FragColor = 0.5*cur_color + 0.25*top_color + 0.25*bot_color;\n"
179   "}";
180 /* *INDENT-ON* */
181 
182 /* dont' forget to edit the following when a new method is added */
183 typedef enum
184 {
185   GST_GL_DEINTERLACE_VFIR,
186   GST_GL_DEINTERLACE_GREEDYH
187 } GstGLDeinterlaceMethod;
188 
189 static const GEnumValue *
gst_gl_deinterlace_get_methods(void)190 gst_gl_deinterlace_get_methods (void)
191 {
192   static const GEnumValue method_types[] = {
193     {GST_GL_DEINTERLACE_VFIR, "Blur Vertical", "vfir"},
194     {GST_GL_DEINTERLACE_GREEDYH, "Motion Adaptive: Advanced Detection",
195         "greedyh"},
196     {0, NULL, NULL}
197   };
198   return method_types;
199 }
200 
201 #define GST_TYPE_GL_DEINTERLACE_METHODS (gst_gl_deinterlace_method_get_type ())
202 static GType
gst_gl_deinterlace_method_get_type(void)203 gst_gl_deinterlace_method_get_type (void)
204 {
205   static GType gl_deinterlace_method_type = 0;
206   if (!gl_deinterlace_method_type) {
207     gl_deinterlace_method_type =
208         g_enum_register_static ("GstGLDeinterlaceMethod",
209         gst_gl_deinterlace_get_methods ());
210   }
211   return gl_deinterlace_method_type;
212 }
213 
214 static void
gst_gl_deinterlace_set_method(GstGLDeinterlace * deinterlace,guint method_types)215 gst_gl_deinterlace_set_method (GstGLDeinterlace * deinterlace,
216     guint method_types)
217 {
218   switch (method_types) {
219     case GST_GL_DEINTERLACE_VFIR:
220       deinterlace->deinterlacefunc = gst_gl_deinterlace_vfir_callback;
221       deinterlace->current_method = method_types;
222       break;
223     case GST_GL_DEINTERLACE_GREEDYH:
224       deinterlace->deinterlacefunc = gst_gl_deinterlace_greedyh_callback;
225       deinterlace->current_method = method_types;
226       break;
227     default:
228       g_assert_not_reached ();
229       break;
230   }
231 }
232 
233 static void
gst_gl_deinterlace_class_init(GstGLDeinterlaceClass * klass)234 gst_gl_deinterlace_class_init (GstGLDeinterlaceClass * klass)
235 {
236   GObjectClass *gobject_class;
237   GstElementClass *element_class;
238 
239   gobject_class = (GObjectClass *) klass;
240   element_class = GST_ELEMENT_CLASS (klass);
241 
242   gst_gl_filter_add_rgba_pad_templates (GST_GL_FILTER_CLASS (klass));
243 
244   gobject_class->set_property = gst_gl_deinterlace_set_property;
245   gobject_class->get_property = gst_gl_deinterlace_get_property;
246 
247   gst_element_class_set_metadata (element_class,
248       "OpenGL deinterlacing filter", "Deinterlace",
249       "Deinterlacing based on fragment shaders",
250       "Julien Isorce <julien.isorce@mail.com>");
251 
252   g_object_class_install_property (gobject_class,
253       PROP_METHOD,
254       g_param_spec_enum ("method",
255           "Deinterlace Method",
256           "Select which deinterlace method apply to GL video texture",
257           GST_TYPE_GL_DEINTERLACE_METHODS,
258           GST_GL_DEINTERLACE_VFIR, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
259 
260   GST_BASE_TRANSFORM_CLASS (klass)->start = gst_gl_deinterlace_start;
261   GST_BASE_TRANSFORM_CLASS (klass)->stop = gst_gl_deinterlace_reset;
262 
263   GST_GL_FILTER_CLASS (klass)->transform_internal_caps =
264       gst_gl_deinterlace_transform_internal_caps;
265   GST_GL_FILTER_CLASS (klass)->filter = gst_gl_deinterlace_filter;
266   GST_GL_FILTER_CLASS (klass)->filter_texture =
267       gst_gl_deinterlace_filter_texture;
268   GST_GL_FILTER_CLASS (klass)->init_fbo = gst_gl_deinterlace_init_fbo;
269 
270   GST_GL_BASE_FILTER_CLASS (klass)->supported_gl_api =
271       GST_GL_API_OPENGL | GST_GL_API_GLES2 | GST_GL_API_OPENGL3;
272 }
273 
274 static void
gst_gl_deinterlace_init(GstGLDeinterlace * filter)275 gst_gl_deinterlace_init (GstGLDeinterlace * filter)
276 {
277   filter->shaderstable = NULL;
278   filter->deinterlacefunc = gst_gl_deinterlace_vfir_callback;
279   filter->current_method = GST_GL_DEINTERLACE_VFIR;
280   filter->prev_buffer = NULL;
281   filter->prev_tex = NULL;
282 }
283 
284 static gboolean
gst_gl_deinterlace_start(GstBaseTransform * trans)285 gst_gl_deinterlace_start (GstBaseTransform * trans)
286 {
287   GstGLDeinterlace *deinterlace_filter = GST_GL_DEINTERLACE (trans);
288 
289   deinterlace_filter->shaderstable = g_hash_table_new (g_str_hash, g_str_equal);
290 
291   return GST_BASE_TRANSFORM_CLASS (parent_class)->start (trans);
292 }
293 
294 static void
gst_gl_deinterlace_ghash_func_clean(gpointer key,gpointer value,gpointer data)295 gst_gl_deinterlace_ghash_func_clean (gpointer key, gpointer value,
296     gpointer data)
297 {
298   GstGLShader *shader = (GstGLShader *) value;
299 
300   gst_object_unref (shader);
301 
302   value = NULL;
303 }
304 
305 static gboolean
gst_gl_deinterlace_reset(GstBaseTransform * trans)306 gst_gl_deinterlace_reset (GstBaseTransform * trans)
307 {
308   GstGLDeinterlace *deinterlace_filter = GST_GL_DEINTERLACE (trans);
309 
310   gst_buffer_replace (&deinterlace_filter->prev_buffer, NULL);
311 
312   //blocking call, wait the opengl thread has destroyed the shader
313   if (deinterlace_filter->shaderstable) {
314     /* release shaders in the gl thread */
315     g_hash_table_foreach (deinterlace_filter->shaderstable,
316         gst_gl_deinterlace_ghash_func_clean, deinterlace_filter);
317 
318     /* clean the htable without calling values destructors
319      * because shaders have been released in the glthread
320      * through the foreach func */
321     g_hash_table_unref (deinterlace_filter->shaderstable);
322     deinterlace_filter->shaderstable = NULL;
323   }
324 
325   return GST_BASE_TRANSFORM_CLASS (parent_class)->stop (trans);
326 }
327 
328 static GstCaps *
gst_gl_deinterlace_transform_internal_caps(GstGLFilter * filter,GstPadDirection direction,GstCaps * caps,GstCaps * caps_filter)329 gst_gl_deinterlace_transform_internal_caps (GstGLFilter * filter,
330     GstPadDirection direction, GstCaps * caps, GstCaps * caps_filter)
331 {
332   gint len;
333   GstCaps *res;
334   GstStructure *s;
335 
336   res = gst_caps_copy (caps);
337 
338   for (len = gst_caps_get_size (res); len > 0; len--) {
339     s = gst_caps_get_structure (res, len - 1);
340     if (direction == GST_PAD_SINK) {
341       gst_structure_remove_field (s, "interlace-mode");
342     }
343   }
344 
345   return res;
346 }
347 
348 static void
gst_gl_deinterlace_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)349 gst_gl_deinterlace_set_property (GObject * object, guint prop_id,
350     const GValue * value, GParamSpec * pspec)
351 {
352   GstGLDeinterlace *filter = GST_GL_DEINTERLACE (object);
353 
354   switch (prop_id) {
355     case PROP_METHOD:
356       gst_gl_deinterlace_set_method (filter, g_value_get_enum (value));
357       break;
358     default:
359       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
360       break;
361   }
362 }
363 
364 static void
gst_gl_deinterlace_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)365 gst_gl_deinterlace_get_property (GObject * object, guint prop_id,
366     GValue * value, GParamSpec * pspec)
367 {
368   GstGLDeinterlace *filter = GST_GL_DEINTERLACE (object);
369 
370   switch (prop_id) {
371     case PROP_METHOD:
372       g_value_set_enum (value, filter->current_method);
373       break;
374     default:
375       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
376       break;
377   }
378 }
379 
380 static gboolean
gst_gl_deinterlace_init_fbo(GstGLFilter * filter)381 gst_gl_deinterlace_init_fbo (GstGLFilter * filter)
382 {
383   return TRUE;
384 }
385 
386 static gboolean
gst_gl_deinterlace_filter_texture(GstGLFilter * filter,GstGLMemory * in_tex,GstGLMemory * out_tex)387 gst_gl_deinterlace_filter_texture (GstGLFilter * filter, GstGLMemory * in_tex,
388     GstGLMemory * out_tex)
389 {
390   GstGLDeinterlace *deinterlace_filter = GST_GL_DEINTERLACE (filter);
391 
392   //blocking call, use a FBO
393   gst_gl_filter_render_to_target (filter, in_tex, out_tex,
394       deinterlace_filter->deinterlacefunc, deinterlace_filter);
395 
396   return TRUE;
397 }
398 
399 static gboolean
gst_gl_deinterlace_filter(GstGLFilter * filter,GstBuffer * inbuf,GstBuffer * outbuf)400 gst_gl_deinterlace_filter (GstGLFilter * filter, GstBuffer * inbuf,
401     GstBuffer * outbuf)
402 {
403   GstGLDeinterlace *deinterlace_filter = GST_GL_DEINTERLACE (filter);
404 
405   gst_gl_filter_filter_texture (filter, inbuf, outbuf);
406 
407   gst_buffer_replace (&deinterlace_filter->prev_buffer, inbuf);
408 
409   return TRUE;
410 }
411 
412 static GstGLShader *
gst_gl_deinterlace_get_fragment_shader(GstGLFilter * filter,const gchar * shader_name,const gchar * shader_source)413 gst_gl_deinterlace_get_fragment_shader (GstGLFilter * filter,
414     const gchar * shader_name, const gchar * shader_source)
415 {
416   GstGLShader *shader = NULL;
417   GstGLDeinterlace *deinterlace_filter = GST_GL_DEINTERLACE (filter);
418   GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
419   const gchar *frags[2];
420 
421   shader = g_hash_table_lookup (deinterlace_filter->shaderstable, shader_name);
422 
423   frags[0] =
424       gst_gl_shader_string_get_highest_precision (context,
425       GST_GLSL_VERSION_NONE,
426       GST_GLSL_PROFILE_ES | GST_GLSL_PROFILE_COMPATIBILITY);
427   frags[1] = shader_source;
428 
429   if (!shader) {
430     GError *error = NULL;
431 
432     if (!(shader = gst_gl_shader_new_link_with_stages (context, &error,
433                 gst_glsl_stage_new_default_vertex (context),
434                 gst_glsl_stage_new_with_strings (context, GL_FRAGMENT_SHADER,
435                     GST_GLSL_VERSION_NONE,
436                     GST_GLSL_PROFILE_ES | GST_GLSL_PROFILE_COMPATIBILITY, 2,
437                     frags), NULL))) {
438       GST_ELEMENT_ERROR (deinterlace_filter, RESOURCE, NOT_FOUND,
439           ("Failed to initialize %s shader", shader_name), (NULL));
440     }
441 
442     filter->draw_attr_position_loc =
443         gst_gl_shader_get_attribute_location (shader, "a_position");
444     filter->draw_attr_texture_loc =
445         gst_gl_shader_get_attribute_location (shader, "a_texcoord");
446   }
447 
448   g_hash_table_insert (deinterlace_filter->shaderstable, (gchar *) shader_name,
449       shader);
450 
451   return shader;
452 }
453 
454 static gboolean
gst_gl_deinterlace_vfir_callback(GstGLFilter * filter,GstGLMemory * in_tex,gpointer user_data)455 gst_gl_deinterlace_vfir_callback (GstGLFilter * filter, GstGLMemory * in_tex,
456     gpointer user_data)
457 {
458   GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
459   const GstGLFuncs *gl = context->gl_vtable;
460   GstGLShader *shader;
461 
462   shader = gst_gl_deinterlace_get_fragment_shader (filter, "vfir",
463       vfir_fragment_source);
464 
465   if (!shader)
466     return FALSE;
467 
468 #if GST_GL_HAVE_OPENGL
469   if (USING_OPENGL (context)) {
470     gl->MatrixMode (GL_PROJECTION);
471     gl->LoadIdentity ();
472   }
473 #endif
474 
475   gst_gl_shader_use (shader);
476 
477   gl->ActiveTexture (GL_TEXTURE0);
478   gl->BindTexture (GL_TEXTURE_2D, gst_gl_memory_get_texture_id (in_tex));
479 
480   gst_gl_shader_set_uniform_1i (shader, "tex", 0);
481   gst_gl_shader_set_uniform_1f (shader, "width",
482       GST_VIDEO_INFO_WIDTH (&filter->out_info));
483   gst_gl_shader_set_uniform_1f (shader, "height",
484       GST_VIDEO_INFO_HEIGHT (&filter->out_info));
485 
486   gst_gl_filter_draw_fullscreen_quad (filter);
487 
488   return TRUE;
489 }
490 
491 static gboolean
gst_gl_deinterlace_greedyh_callback(GstGLFilter * filter,GstGLMemory * in_tex,gpointer user_data)492 gst_gl_deinterlace_greedyh_callback (GstGLFilter * filter, GstGLMemory * in_tex,
493     gpointer user_data)
494 {
495   GstGLShader *shader;
496   GstGLDeinterlace *deinterlace_filter = GST_GL_DEINTERLACE (filter);
497   GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
498   GstGLFuncs *gl = context->gl_vtable;
499 
500   shader =
501       gst_gl_deinterlace_get_fragment_shader (filter, "greedhy",
502       greedyh_fragment_source);
503 
504   if (!shader)
505     return FALSE;
506 
507 #if GST_GL_HAVE_OPENGL
508   if (USING_OPENGL (context)) {
509     gl->MatrixMode (GL_PROJECTION);
510     gl->LoadIdentity ();
511   }
512 #endif
513 
514   gst_gl_shader_use (shader);
515 
516   if (G_LIKELY (deinterlace_filter->prev_tex != NULL)) {
517     gl->ActiveTexture (GL_TEXTURE1);
518     gst_gl_shader_set_uniform_1i (shader, "tex_prev", 1);
519     gl->BindTexture (GL_TEXTURE_2D,
520         gst_gl_memory_get_texture_id (deinterlace_filter->prev_tex));
521   }
522 
523   gl->ActiveTexture (GL_TEXTURE0);
524   gl->BindTexture (GL_TEXTURE_2D, gst_gl_memory_get_texture_id (in_tex));
525 
526   gst_gl_shader_set_uniform_1i (shader, "tex", 0);
527   gst_gl_shader_set_uniform_1f (shader, "max_comb", 5.0f / 255.0f);
528   gst_gl_shader_set_uniform_1f (shader, "motion_threshold", 25.0f / 255.0f);
529   gst_gl_shader_set_uniform_1f (shader, "motion_sense", 30.0f / 255.0f);
530 
531   gst_gl_shader_set_uniform_1f (shader, "width",
532       GST_VIDEO_INFO_WIDTH (&filter->out_info));
533   gst_gl_shader_set_uniform_1f (shader, "height",
534       GST_VIDEO_INFO_HEIGHT (&filter->out_info));
535 
536   gst_gl_filter_draw_fullscreen_quad (filter);
537 
538   /* we keep the previous buffer around so this is safe */
539   deinterlace_filter->prev_tex = in_tex;
540 
541   return TRUE;
542 }
543