cf78f9f7cc3ec0f75dc5d24e02e0120fcbe7f093
[platform/upstream/gst-plugins-good.git] / gst / videomixer / videomixer.c
1 /* Generic video mixer plugin
2  * Copyright (C) 2004 Wim Taymans <wim@fluendo.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <gst/gst.h>
25 #include <gst/base/gstcollectpads.h>
26
27 #include <string.h>
28
29 GST_DEBUG_CATEGORY_STATIC (gst_videomixer_debug);
30 #define GST_CAT_DEFAULT gst_videomixer_debug
31
32 #define GST_TYPE_VIDEO_MIXER_PAD (gst_videomixer_pad_get_type())
33 #define GST_VIDEO_MIXER_PAD(obj) \
34         (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VIDEO_MIXER_PAD, GstVideoMixerPad))
35 #define GST_VIDEO_MIXER_PAD_CLASS(klass) \
36         (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VIDEO_MIXER_PAD, GstVideoMixerPadiClass))
37 #define GST_IS_VIDEO_MIXER_PAD(obj) \
38         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VIDEO_MIXER_PAD))
39 #define GST_IS_VIDEO_MIXER_PAD_CLASS(obj) \
40         (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VIDEO_MIXER_PAD))
41
42 typedef struct _GstVideoMixerPad GstVideoMixerPad;
43 typedef struct _GstVideoMixerPadClass GstVideoMixerPadClass;
44 typedef struct _GstVideoMixerCollect GstVideoMixerCollect;
45
46 #define GST_TYPE_VIDEO_MIXER (gst_videomixer_get_type())
47 #define GST_VIDEO_MIXER(obj) \
48         (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VIDEO_MIXER, GstVideoMixer))
49 #define GST_VIDEO_MIXER_CLASS(klass) \
50         (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VIDEO_MIXER, GstVideoMixerClass))
51 #define GST_IS_VIDEO_MIXER(obj) \
52         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VIDEO_MIXER))
53 #define GST_IS_VIDEO_MIXER_CLASS(obj) \
54         (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VIDEO_MIXER))
55
56 static GType gst_videomixer_get_type (void);
57
58 typedef struct _GstVideoMixer GstVideoMixer;
59 typedef struct _GstVideoMixerClass GstVideoMixerClass;
60
61 static void gst_videomixer_pad_base_init (gpointer g_class);
62 static void gst_videomixer_pad_class_init (GstVideoMixerPadClass * klass);
63 static void gst_videomixer_pad_init (GstVideoMixerPad * mixerpad);
64
65 static void gst_videomixer_pad_get_property (GObject * object, guint prop_id,
66     GValue * value, GParamSpec * pspec);
67 static void gst_videomixer_pad_set_property (GObject * object, guint prop_id,
68     const GValue * value, GParamSpec * pspec);
69
70 static void gst_videomixer_sort_pads (GstVideoMixer * mix);
71
72 #define DEFAULT_PAD_ZORDER 0
73 #define DEFAULT_PAD_XPOS   0
74 #define DEFAULT_PAD_YPOS   0
75 #define DEFAULT_PAD_ALPHA  1.0
76 enum
77 {
78   ARG_PAD_0,
79   ARG_PAD_ZORDER,
80   ARG_PAD_XPOS,
81   ARG_PAD_YPOS,
82   ARG_PAD_ALPHA,
83 };
84
85 struct _GstVideoMixerCollect
86 {
87   GstCollectData collect;       /* we extend the CollectData */
88
89   GstBuffer *buffer;            /* the queued buffer for this pad */
90
91   GstVideoMixerPad *mixpad;
92 };
93
94 /* all information needed for one video stream */
95 struct _GstVideoMixerPad
96 {
97   GstPad parent;                /* subclass the pad */
98
99   guint64 queued;
100
101   guint in_width, in_height;
102   gint in_framerate_numerator;
103   gint in_framerate_denominator;
104
105   gint xpos, ypos;
106   guint zorder;
107   gint blend_mode;
108   gdouble alpha;
109
110   GstVideoMixerCollect *mixcol;
111 };
112
113 struct _GstVideoMixerPadClass
114 {
115   GstPadClass parent_class;
116 };
117
118 static GType
119 gst_videomixer_pad_get_type (void)
120 {
121   static GType videomixer_pad_type = 0;
122
123   if (!videomixer_pad_type) {
124     static const GTypeInfo videomixer_pad_info = {
125       sizeof (GstVideoMixerPadClass),
126       gst_videomixer_pad_base_init,
127       NULL,
128       (GClassInitFunc) gst_videomixer_pad_class_init,
129       NULL,
130       NULL,
131       sizeof (GstVideoMixerPad),
132       0,
133       (GInstanceInitFunc) gst_videomixer_pad_init,
134     };
135
136     videomixer_pad_type = g_type_register_static (GST_TYPE_PAD,
137         "GstVideoMixerPad", &videomixer_pad_info, 0);
138   }
139   return videomixer_pad_type;
140 }
141
142 static void
143 gst_videomixer_pad_base_init (gpointer g_class)
144 {
145 }
146
147 static void
148 gst_videomixer_pad_class_init (GstVideoMixerPadClass * klass)
149 {
150   GObjectClass *gobject_class;
151
152   gobject_class = (GObjectClass *) klass;
153
154   gobject_class->set_property =
155       GST_DEBUG_FUNCPTR (gst_videomixer_pad_set_property);
156   gobject_class->get_property =
157       GST_DEBUG_FUNCPTR (gst_videomixer_pad_get_property);
158
159   g_object_class_install_property (gobject_class, ARG_PAD_ZORDER,
160       g_param_spec_uint ("zorder", "Z-Order", "Z Order of the picture",
161           0, 10000, DEFAULT_PAD_ZORDER, G_PARAM_READWRITE));
162   g_object_class_install_property (gobject_class, ARG_PAD_XPOS,
163       g_param_spec_int ("xpos", "X Position", "X Position of the picture",
164           G_MININT, G_MAXINT, DEFAULT_PAD_XPOS, G_PARAM_READWRITE));
165   g_object_class_install_property (gobject_class, ARG_PAD_YPOS,
166       g_param_spec_int ("ypos", "Y Position", "Y Position of the picture",
167           G_MININT, G_MAXINT, DEFAULT_PAD_YPOS, G_PARAM_READWRITE));
168   g_object_class_install_property (gobject_class, ARG_PAD_ALPHA,
169       g_param_spec_double ("alpha", "Alpha", "Alpha of the picture",
170           0.0, 1.0, DEFAULT_PAD_ALPHA, G_PARAM_READWRITE));
171 }
172
173 static void
174 gst_videomixer_pad_get_property (GObject * object, guint prop_id,
175     GValue * value, GParamSpec * pspec)
176 {
177   GstVideoMixerPad *pad = GST_VIDEO_MIXER_PAD (object);
178
179   switch (prop_id) {
180     case ARG_PAD_ZORDER:
181       g_value_set_uint (value, pad->zorder);
182       break;
183     case ARG_PAD_XPOS:
184       g_value_set_int (value, pad->xpos);
185       break;
186     case ARG_PAD_YPOS:
187       g_value_set_int (value, pad->ypos);
188       break;
189     case ARG_PAD_ALPHA:
190       g_value_set_double (value, pad->alpha);
191       break;
192     default:
193       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
194       break;
195   }
196 }
197
198 static void
199 gst_videomixer_pad_set_property (GObject * object, guint prop_id,
200     const GValue * value, GParamSpec * pspec)
201 {
202   GstVideoMixerPad *pad;
203   GstVideoMixer *mix;
204
205   pad = GST_VIDEO_MIXER_PAD (object);
206   mix = GST_VIDEO_MIXER (gst_pad_get_parent (GST_PAD (pad)));
207
208   switch (prop_id) {
209     case ARG_PAD_ZORDER:
210       pad->zorder = g_value_get_uint (value);
211       gst_videomixer_sort_pads (mix);
212       break;
213     case ARG_PAD_XPOS:
214       pad->xpos = g_value_get_int (value);
215       break;
216     case ARG_PAD_YPOS:
217       pad->ypos = g_value_get_int (value);
218       break;
219     case ARG_PAD_ALPHA:
220       pad->alpha = g_value_get_double (value);
221       break;
222     default:
223       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
224       break;
225   }
226
227   gst_object_unref (mix);
228 }
229
230 typedef enum
231 {
232   VIDEO_MIXER_BACKGROUND_CHECKER,
233   VIDEO_MIXER_BACKGROUND_BLACK,
234   VIDEO_MIXER_BACKGROUND_WHITE,
235 }
236 GstVideoMixerBackground;
237
238 struct _GstVideoMixer
239 {
240   GstElement element;
241
242   /* pad */
243   GstPad *srcpad;
244
245   /* Sink pads using Collect Pads from core's base library */
246   GstCollectPads *collect;
247   /* sinkpads, a GSList of GstVideoMixerPads */
248   GSList *sinkpads;
249
250   gint numpads;
251
252   /* the master pad */
253   GstVideoMixerPad *master;
254
255   gint in_width, in_height;
256   gint out_width, out_height;
257
258   GstVideoMixerBackground background;
259
260   gint in_framerate_numerator;
261   gint in_framerate_denominator;
262 };
263
264 struct _GstVideoMixerClass
265 {
266   GstElementClass parent_class;
267 };
268
269 static gboolean
270 gst_videomixer_pad_sink_setcaps (GstPad * pad, GstCaps * vscaps)
271 {
272   GstVideoMixer *mix;
273   GstVideoMixerPad *mixpad;
274   GstStructure *structure;
275   gint in_width, in_height;
276   gboolean ret = FALSE;
277   const GValue *framerate;
278
279   mix = GST_VIDEO_MIXER (gst_pad_get_parent (pad));
280   mixpad = GST_VIDEO_MIXER_PAD (pad);
281
282   GST_DEBUG ("videomixer: setcaps triggered on %s", gst_pad_get_name (pad));
283
284   structure = gst_caps_get_structure (vscaps, 0);
285
286   if (!gst_structure_get_int (structure, "width", &in_width)
287       || !gst_structure_get_int (structure, "height", &in_height)
288       || (framerate = gst_structure_get_value (structure, "framerate")) != NULL)
289     goto beach;
290
291   mixpad->in_framerate_numerator = gst_value_get_fraction_numerator (framerate);
292   mixpad->in_framerate_denominator =
293       gst_value_get_fraction_denominator (framerate);
294
295   mixpad->in_width = in_width;
296   mixpad->in_height = in_height;
297
298   mixpad->xpos = 0;
299   mixpad->ypos = 0;
300
301   mix->in_width = MAX (mix->in_width, mixpad->in_width);
302   mix->in_height = MAX (mix->in_height, mixpad->in_height);
303
304   /* If mix framerate < mixpad framerate, using fractions */
305   if ((gint64) mix->in_framerate_numerator * mixpad->in_framerate_denominator <
306       (gint64) mixpad->in_framerate_numerator * mix->in_framerate_denominator) {
307     mix->in_framerate_numerator = mixpad->in_framerate_numerator;
308     mix->in_framerate_denominator = mixpad->in_framerate_denominator;
309     mix->master = mixpad;
310   }
311
312   ret = TRUE;
313
314 beach:
315   gst_object_unref (mix);
316
317   return ret;
318 }
319
320 static void
321 gst_videomixer_pad_link (GstPad * pad, GstPad * peer, gpointer data)
322 {
323   GST_DEBUG_OBJECT (pad, "connected");
324 }
325
326 static void
327 gst_videomixer_pad_unlink (GstPad * pad, GstPad * peer, gpointer data)
328 {
329   GST_DEBUG_OBJECT (pad, "unlinked");
330 }
331
332 static void
333 gst_videomixer_pad_init (GstVideoMixerPad * mixerpad)
334 {
335   g_signal_connect (mixerpad, "linked",
336       G_CALLBACK (gst_videomixer_pad_link), mixerpad);
337   g_signal_connect (mixerpad, "unlinked",
338       G_CALLBACK (gst_videomixer_pad_unlink), mixerpad);
339
340   /* setup some pad functions */
341   gst_pad_set_setcaps_function (GST_PAD (mixerpad),
342       gst_videomixer_pad_sink_setcaps);
343
344   mixerpad->zorder = DEFAULT_PAD_ZORDER;
345   mixerpad->xpos = DEFAULT_PAD_XPOS;
346   mixerpad->ypos = DEFAULT_PAD_YPOS;
347   mixerpad->alpha = DEFAULT_PAD_ALPHA;
348 }
349
350
351 /* elementfactory information */
352 static GstElementDetails gst_videomixer_details =
353 GST_ELEMENT_DETAILS ("video mixer",
354     "Filter/Editor/Video",
355     "Mix multiple video streams",
356     "Wim Taymans <wim@fluendo.com>");
357
358 /* VideoMixer signals and args */
359 enum
360 {
361   /* FILL ME */
362   LAST_SIGNAL
363 };
364
365 #define DEFAULT_BACKGROUND VIDEO_MIXER_BACKGROUND_CHECKER
366 enum
367 {
368   ARG_0,
369   ARG_BACKGROUND,
370 };
371
372 #define GST_TYPE_VIDEO_MIXER_BACKGROUND (gst_video_mixer_background_get_type())
373 static GType
374 gst_video_mixer_background_get_type (void)
375 {
376   static GType video_mixer_background_type = 0;
377   static GEnumValue video_mixer_background[] = {
378     {VIDEO_MIXER_BACKGROUND_CHECKER, "0", "Checker pattern"},
379     {VIDEO_MIXER_BACKGROUND_BLACK, "1", "Black"},
380     {VIDEO_MIXER_BACKGROUND_WHITE, "2", "White"},
381     {0, NULL, NULL},
382   };
383
384   if (!video_mixer_background_type) {
385     video_mixer_background_type =
386         g_enum_register_static ("GstVideoMixerBackground",
387         video_mixer_background);
388   }
389   return video_mixer_background_type;
390 }
391
392 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
393     GST_PAD_SRC,
394     GST_PAD_ALWAYS,
395     GST_STATIC_CAPS ("video/x-raw-yuv,"
396         "format = (fourcc) AYUV,"
397         "width = (int) [ 1, max ],"
398         "height = (int) [ 1, max ]," "framerate = (fraction) [ 0/1, MAX ]")
399     );
400
401 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink_%d",
402     GST_PAD_SINK,
403     GST_PAD_REQUEST,
404     GST_STATIC_CAPS ("video/x-raw-yuv,"
405         "format = (fourcc) AYUV,"
406         "width = (int) [ 1, max ],"
407         "height = (int) [ 1, max ]," "framerate = (fraction) [ 0/1, MAX ]")
408     );
409
410 static void gst_videomixer_base_init (gpointer g_class);
411 static void gst_videomixer_class_init (GstVideoMixerClass * klass);
412 static void gst_videomixer_init (GstVideoMixer * videomixer);
413
414 static GstCaps *gst_videomixer_getcaps (GstPad * pad);
415
416 static GstFlowReturn gst_videomixer_collected (GstCollectPads * pads,
417     GstVideoMixer * mix);
418 static GstPad *gst_videomixer_request_new_pad (GstElement * element,
419     GstPadTemplate * templ, const gchar * name);
420 static void gst_videomixer_set_property (GObject * object, guint prop_id,
421     const GValue * value, GParamSpec * pspec);
422 static void gst_videomixer_get_property (GObject * object, guint prop_id,
423     GValue * value, GParamSpec * pspec);
424 static GstStateChangeReturn gst_videomixer_change_state (GstElement * element,
425     GstStateChange transition);
426
427 static GstElementClass *parent_class = NULL;
428
429 /*static guint gst_videomixer_signals[LAST_SIGNAL] = { 0 }; */
430
431 static GType
432 gst_videomixer_get_type (void)
433 {
434   static GType videomixer_type = 0;
435
436   if (!videomixer_type) {
437     static const GTypeInfo videomixer_info = {
438       sizeof (GstVideoMixerClass),
439       gst_videomixer_base_init,
440       NULL,
441       (GClassInitFunc) gst_videomixer_class_init,
442       NULL,
443       NULL,
444       sizeof (GstVideoMixer),
445       0,
446       (GInstanceInitFunc) gst_videomixer_init,
447     };
448
449     videomixer_type =
450         g_type_register_static (GST_TYPE_ELEMENT, "GstVideoMixer",
451         &videomixer_info, 0);
452   }
453   return videomixer_type;
454 }
455
456 static void
457 gst_videomixer_base_init (gpointer g_class)
458 {
459   GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
460
461   gst_element_class_add_pad_template (element_class,
462       gst_static_pad_template_get (&src_factory));
463   gst_element_class_add_pad_template (element_class,
464       gst_static_pad_template_get (&sink_factory));
465
466   gst_element_class_set_details (element_class, &gst_videomixer_details);
467 }
468
469 static void
470 gst_videomixer_class_init (GstVideoMixerClass * klass)
471 {
472   GObjectClass *gobject_class;
473   GstElementClass *gstelement_class;
474
475   gobject_class = (GObjectClass *) klass;
476   gstelement_class = (GstElementClass *) klass;
477
478   parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
479
480   gobject_class->get_property = gst_videomixer_get_property;
481   gobject_class->set_property = gst_videomixer_set_property;
482
483   g_object_class_install_property (gobject_class, ARG_BACKGROUND,
484       g_param_spec_enum ("background", "Background", "Background type",
485           GST_TYPE_VIDEO_MIXER_BACKGROUND,
486           DEFAULT_BACKGROUND, G_PARAM_READWRITE));
487
488   gstelement_class->request_new_pad = gst_videomixer_request_new_pad;
489   gstelement_class->change_state = gst_videomixer_change_state;
490 }
491
492 static void
493 gst_videomixer_init (GstVideoMixer * mix)
494 {
495   GstElementClass *klass = GST_ELEMENT_GET_CLASS (mix);
496
497   mix->srcpad =
498       gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
499           "src"), "src");
500   gst_pad_set_getcaps_function (GST_PAD (mix->srcpad), gst_videomixer_getcaps);
501   gst_element_add_pad (GST_ELEMENT (mix), mix->srcpad);
502
503   mix->collect = gst_collect_pads_new ();
504   mix->background = DEFAULT_BACKGROUND;
505   mix->in_width = 0;
506   mix->in_height = 0;
507   mix->out_width = 0;
508   mix->out_height = 0;
509
510   gst_collect_pads_set_function (mix->collect,
511       (GstCollectPadsFunction) gst_videomixer_collected, mix);
512 }
513
514 static GstCaps *
515 gst_videomixer_getcaps (GstPad * pad)
516 {
517   GstVideoMixer *mix;
518   GstCaps *caps;
519   GstStructure *structure;
520
521   mix = GST_VIDEO_MIXER (gst_pad_get_parent (pad));
522   caps = gst_caps_copy (gst_pad_get_pad_template_caps (mix->srcpad));
523
524   structure = gst_caps_get_structure (caps, 0);
525
526   if (mix->out_width != 0) {
527     gst_structure_set (structure, "width", G_TYPE_INT, mix->out_width, NULL);
528   }
529   if (mix->out_height != 0) {
530     gst_structure_set (structure, "height", G_TYPE_INT, mix->out_height, NULL);
531   }
532   if (mix->in_framerate_denominator != 0) {
533     gst_structure_set (structure,
534         "framerate", GST_TYPE_FRACTION, mix->in_framerate_numerator,
535         mix->in_framerate_denominator, NULL);
536   }
537
538   gst_object_unref (mix);
539
540   return caps;
541 }
542
543 static GstPad *
544 gst_videomixer_request_new_pad (GstElement * element,
545     GstPadTemplate * templ, const gchar * req_name)
546 {
547   GstVideoMixer *mix = NULL;
548   GstVideoMixerPad *mixpad = NULL;
549   GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
550
551   g_return_val_if_fail (templ != NULL, NULL);
552
553   if (templ->direction != GST_PAD_SINK) {
554     g_warning ("videomixer: request pad that is not a SINK pad\n");
555     return NULL;
556   }
557
558   g_return_val_if_fail (GST_IS_VIDEO_MIXER (element), NULL);
559
560   mix = GST_VIDEO_MIXER (element);
561
562   if (templ == gst_element_class_get_pad_template (klass, "sink_%d")) {
563     gint serial = 0;
564     gchar *name = NULL;
565     GstVideoMixerCollect *mixcol = NULL;
566
567     if (req_name == NULL || strlen (req_name) < 6) {
568       /* no name given when requesting the pad, use random serial number */
569       serial = rand ();
570     } else {
571       /* parse serial number from requested padname */
572       serial = atoi (&req_name[5]);
573     }
574     /* create new pad with the name */
575     name = g_strdup_printf ("sink_%d", serial);
576     mixpad = g_object_new (GST_TYPE_VIDEO_MIXER_PAD, "name", name, "direction",
577         templ->direction, "template", templ, NULL);
578     g_free (name);
579
580     mixpad->zorder = mix->numpads;
581     mixpad->xpos = DEFAULT_PAD_XPOS;
582     mixpad->ypos = DEFAULT_PAD_YPOS;
583     mixpad->alpha = DEFAULT_PAD_ALPHA;
584
585     mixcol = (GstVideoMixerCollect *)
586         gst_collect_pads_add_pad (mix->collect, GST_PAD (mixpad),
587         sizeof (GstVideoMixerCollect));
588
589     /* Keep track of eachother */
590     mixcol->mixpad = mixpad;
591     mixpad->mixcol = mixcol;
592
593     /* Keep an internal list of mixpads for zordering */
594     mix->sinkpads = g_slist_append (mix->sinkpads, mixpad);
595     mix->numpads++;
596   } else {
597     g_warning ("videomixer: this is not our template!\n");
598     return NULL;
599   }
600
601   /* dd the pad to the element */
602   gst_element_add_pad (element, GST_PAD (mixpad));
603
604   return GST_PAD (mixpad);
605 }
606
607 #define BLEND_NORMAL(Y1,U1,V1,Y2,U2,V2,alpha,Y,U,V)     \
608         Y = ((Y1*(255-alpha))+(Y2*alpha))>>8;           \
609         U = ((U1*(255-alpha))+(U2*alpha))>>8;           \
610         V = ((V1*(255-alpha))+(V2*alpha))>>8;
611
612 #define BLEND_ADD(Y1,U1,V1,Y2,U2,V2,alpha,Y,U,V)                \
613         Y = Y1+((Y2*alpha)>>8);                                 \
614         U = U1+(((127*(255-alpha)+(U2*alpha)))>>8)-127;         \
615         V = V1+(((127*(255-alpha)+(V2*alpha)))>>8)-127;         \
616         if (Y>255) {                                            \
617           gint mult = MAX (0, 288-Y);                           \
618           U = ((U*mult) + (127*(32-mult)))>>5;                  \
619           V = ((V*mult) + (127*(32-mult)))>>5;                  \
620           Y = 255;                                              \
621         }                                                       \
622         U = MIN (U,255);                                        \
623         V = MIN (V,255);
624
625 #define BLEND_SUBTRACT(Y1,U1,V1,Y2,U2,V2,alpha,Y,U,V)           \
626         Y = Y1-((Y2*alpha)>>8);                                 \
627         U = U1+(((127*(255-alpha)+(U2*alpha)))>>8)-127;         \
628         V = V1+(((127*(255-alpha)+(V2*alpha)))>>8)-127;         \
629         if (Y<0) {                                              \
630           gint mult = MIN (32, -Y);                             \
631           U = ((U*(32-mult)) + (127*mult))>>5;                  \
632           V = ((V*(32-mult)) + (127*mult))>>5;                  \
633           Y = 0;                                                \
634         }
635
636 #define BLEND_DARKEN(Y1,U1,V1,Y2,U2,V2,alpha,Y,U,V)     \
637         if (Y1 < Y2) {                                  \
638           Y = Y1; U = U1; V = V1;                       \
639         }                                               \
640         else {                                          \
641           Y = ((Y1*(255-alpha))+(Y2*alpha))>>8;         \
642           U = ((U1*(255-alpha))+(U2*alpha))>>8;         \
643           V = ((V1*(255-alpha))+(V2*alpha))>>8;         \
644         }
645
646 #define BLEND_LIGHTEN(Y1,U1,V1,Y2,U2,V2,alpha,Y,U,V)    \
647         if (Y1 > Y2) {                                  \
648           Y = Y1; U = U1; V = V1;                       \
649         }                                               \
650         else {                                          \
651           Y = ((Y1*(255-alpha))+(Y2*alpha))>>8;         \
652           U = ((U1*(255-alpha))+(U2*alpha))>>8;         \
653           V = ((V1*(255-alpha))+(V2*alpha))>>8;         \
654         }
655
656 #define BLEND_MULTIPLY(Y1,U1,V1,Y2,U2,V2,alpha,Y,U,V)                   \
657         Y = (Y1*(256*(255-alpha) +(Y2*alpha)))>>16;                     \
658         U = ((U1*(255-alpha)*256)+(alpha*(U1*Y2+128*(256-Y2))))>>16;    \
659         V = ((V1*(255-alpha)*256)+(alpha*(V1*Y2+128*(256-Y2))))>>16;
660
661 #define BLEND_DIFFERENCE(Y1,U1,V1,Y2,U2,V2,alpha,Y,U,V)         \
662         Y = ABS((gint)Y1-(gint)Y2)+127;                         \
663         U = ABS((gint)U1-(gint)U2)+127;                         \
664         V = ABS((gint)V1-(gint)V2)+127;                         \
665         Y = ((Y*alpha)+(Y1*(255-alpha)))>>8;                    \
666         U = ((U*alpha)+(U1*(255-alpha)))>>8;                    \
667         V = ((V*alpha)+(V1*(255-alpha)))>>8;                    \
668         if (Y>255) {                                            \
669           gint mult = MAX (0, 288-Y);                           \
670           U = ((U*mult) + (127*(32-mult)))>>5;                  \
671           V = ((V*mult) + (127*(32-mult)))>>5;                  \
672           Y = 255;                                              \
673         } else if (Y<0) {                                       \
674           gint mult = MIN (32, -Y);                             \
675           U = ((U*(32-mult)) + (127*mult))>>5;                  \
676           V = ((V*(32-mult)) + (127*mult))>>5;                  \
677           Y = 0;                                                \
678         }                                                       \
679         U = CLAMP(U, 0, 255);                                   \
680         V = CLAMP(V, 0, 255);
681
682 #define BLEND_EXCLUSION(Y1,U1,V1,Y2,U2,V2,alpha,Y,U,V)          \
683         Y = ((gint)(Y1^0xff)*Y2+(gint)(Y2^0xff)*Y1)>>8;         \
684         U = ((gint)(U1^0xff)*Y2+(gint)(Y2^0xff)*U1)>>8;         \
685         V = ((gint)(V1^0xff)*Y2+(gint)(Y2^0xff)*V1)>>8;         \
686         Y = ((Y*alpha)+(Y1*(255-alpha)))>>8;                    \
687         U = ((U*alpha)+(U1*(255-alpha)))>>8;                    \
688         V = ((V*alpha)+(V1*(255-alpha)))>>8;                    \
689         if (Y>255) {                                            \
690           gint mult = MAX (0, 288-Y);                           \
691           U = ((U*mult) + (127*(32-mult)))>>5;                  \
692           V = ((V*mult) + (127*(32-mult)))>>5;                  \
693           Y = 255;                                              \
694         } else if (Y<0) {                                       \
695           gint mult = MIN (32, -Y);                             \
696           U = ((U*(32-mult)) + (127*mult))>>5;                  \
697           V = ((V*(32-mult)) + (127*mult))>>5;                  \
698           Y = 0;                                                \
699         }                                                       \
700         U = CLAMP(U, 0, 255);                                   \
701         V = CLAMP(V, 0, 255);
702
703 #define BLEND_SOFTLIGHT(Y1,U1,V1,Y2,U2,V2,alpha,Y,U,V)          \
704         Y = (gint)Y1+(gint)Y2 - 127;                            \
705         U = (gint)U1+(gint)U2 - 127;                            \
706         V = (gint)V1+(gint)V2 - 127;                            \
707         Y = ((Y*alpha)+(Y1*(255-alpha)))>>8;                    \
708         U = ((U*alpha)+(U1*(255-alpha)))>>8;                    \
709         V = ((V*alpha)+(V1*(255-alpha)))>>8;                    \
710         if (Y>255) {                                            \
711           gint mult = MAX (0, 288-Y);                           \
712           U = ((U*mult) + (127*(32-mult)))>>5;                  \
713           V = ((V*mult) + (127*(32-mult)))>>5;                  \
714           Y = 255;                                              \
715         } else if (Y<0) {                                       \
716           gint mult = MIN (32, -Y);                             \
717           U = ((U*(32-mult)) + (127*mult))>>5;                  \
718           V = ((V*(32-mult)) + (127*mult))>>5;                  \
719           Y = 0;                                                \
720         }                                                       \
721
722 #define BLEND_HARDLIGHT(Y1,U1,V1,Y2,U2,V2,alpha,Y,U,V)          \
723         Y = (gint)Y1+(gint)Y2*2 - 255;                          \
724         U = (gint)U1+(gint)U2 - 127;                            \
725         V = (gint)V1+(gint)V2 - 127;                            \
726         Y = ((Y*alpha)+(Y1*(255-alpha)))>>8;                    \
727         U = ((U*alpha)+(U1*(255-alpha)))>>8;                    \
728         V = ((V*alpha)+(V1*(255-alpha)))>>8;                    \
729         if (Y>255) {                                            \
730           gint mult = MAX (0, 288-Y);                           \
731           U = ((U*mult) + (127*(32-mult)))>>5;                  \
732           V = ((V*mult) + (127*(32-mult)))>>5;                  \
733           Y = 255;                                              \
734         } else if (Y<0) {                                       \
735           gint mult = MIN (32, -Y);                             \
736           U = ((U*(32-mult)) + (127*mult))>>5;                  \
737           V = ((V*(32-mult)) + (127*mult))>>5;                  \
738           Y = 0;                                                \
739         }                                                       \
740
741 #define BLEND_MODE BLEND_NORMAL
742 #if 0
743 #define BLEND_MODE BLEND_NORMAL
744 #define BLEND_MODE BLEND_ADD
745 #define BLEND_MODE BLEND_SUBTRACT
746 #define BLEND_MODE BLEND_LIGHTEN
747 #define BLEND_MODE BLEND_DARKEN
748 #define BLEND_MODE BLEND_MULTIPLY
749 #define BLEND_MODE BLEND_DIFFERENCE
750 #define BLEND_MODE BLEND_EXCLUSION
751 #define BLEND_MODE BLEND_SOFTLIGHT
752 #define BLEND_MODE BLEND_HARDLIGHT
753 #endif
754
755 #define ROUND_UP_2(x) (((x) + 1) & ~1)
756 #define ROUND_UP_4(x) (((x) + 3) & ~3)
757 #define ROUND_UP_8(x) (((x) + 7) & ~7)
758
759 /* note that this function does packing conversion and blending at the
760  * same time */
761 static void
762 gst_videomixer_blend_ayuv_ayuv (guint8 * src, gint xpos, gint ypos,
763     gint src_width, gint src_height, gdouble src_alpha,
764     guint8 * dest, gint dest_width, gint dest_height)
765 {
766   gint alpha, b_alpha;
767   gint i, j;
768   gint src_stride, dest_stride;
769   gint src_add, dest_add;
770   gint Y, U, V;
771
772   src_stride = ROUND_UP_2 (src_width) * 4;
773   dest_stride = ROUND_UP_2 (dest_width) * 4;
774
775   b_alpha = (gint) (src_alpha * 255);
776
777   /* adjust src pointers for negative sizes */
778   if (xpos < 0) {
779     src += -xpos * 4;
780     src_width -= -xpos;
781     xpos = 0;
782   }
783   if (ypos < 0) {
784     src += -ypos * src_stride;
785     src_height -= -ypos;
786     ypos = 0;
787   }
788   /* adjust width/height if the src is bigger than dest */
789   if (xpos + src_width > dest_width) {
790     src_width = dest_width - xpos;
791   }
792   if (ypos + src_height > dest_height) {
793     src_height = dest_height - ypos;
794   }
795
796   src_add = src_stride - (4 * ROUND_UP_2 (src_width));
797   dest_add = dest_stride - (4 * ROUND_UP_2 (src_width));
798
799   dest = dest + 4 * xpos + (ypos * dest_stride);
800
801   /* we convert a square of 2x2 samples to generate 4 Luma and 2 chroma samples */
802   for (i = 0; i < ROUND_UP_2 (src_height); i++) {
803     for (j = 0; j < ROUND_UP_2 (src_width); j++) {
804       alpha = (src[0] * b_alpha) >> 8;
805       BLEND_MODE (dest[1], dest[2], dest[3], src[1], src[2], src[3],
806           alpha, Y, U, V);
807       dest[0] = 0xff;
808       dest[1] = Y;
809       dest[2] = U;
810       dest[3] = V;
811
812       src += 4;
813       dest += 4;
814     }
815     src += src_add;
816     dest += dest_add;
817   }
818 }
819
820 #undef BLEND_MODE
821
822 static int
823 pad_zorder_compare (const GstVideoMixerPad * pad1,
824     const GstVideoMixerPad * pad2)
825 {
826   return pad1->zorder - pad2->zorder;
827 }
828
829 static void
830 gst_videomixer_sort_pads (GstVideoMixer * mix)
831 {
832   mix->sinkpads = g_slist_sort (mix->sinkpads,
833       (GCompareFunc) pad_zorder_compare);
834 }
835
836 /* fill a buffer with a checkerboard pattern */
837 static void
838 gst_videomixer_fill_checker (guint8 * dest, gint width, gint height)
839 {
840   gint stride;
841   gint i, j;
842   static int tab[] = { 80, 160, 80, 160 };
843
844   stride = ROUND_UP_2 (width);
845
846   for (i = 0; i < height; i++) {
847     for (j = 0; j < stride; j++) {
848       *dest++ = 0xff;
849       *dest++ = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)];
850       *dest++ = 128;
851       *dest++ = 128;
852     }
853   }
854 }
855
856 static void
857 gst_videomixer_fill_color (guint8 * dest, gint width, gint height,
858     gint colY, gint colU, gint colV)
859 {
860   gint stride;
861   gint i, j;
862
863   stride = ROUND_UP_2 (width);
864
865   for (i = 0; i < height; i++) {
866     for (j = 0; j < stride; j++) {
867       *dest++ = 0xff;
868       *dest++ = colY;
869       *dest++ = colU;
870       *dest++ = colV;
871     }
872   }
873 }
874
875 /* try to get a buffer on all pads. As long as the queued value is
876  * negative, we skip buffers */
877 static gboolean
878 gst_videomixer_fill_queues (GstVideoMixer * mix)
879 {
880   GSList *walk = NULL;
881   gboolean eos = TRUE;
882
883   g_return_val_if_fail (GST_IS_VIDEO_MIXER (mix), FALSE);
884
885   /* try to make sure we have a buffer from each usable pad first */
886   walk = mix->collect->data;
887   while (walk) {
888     GstCollectData *data = (GstCollectData *) walk->data;
889     GstVideoMixerCollect *mixcol = (GstVideoMixerCollect *) data;
890     GstVideoMixerPad *mixpad = mixcol->mixpad;
891
892     walk = g_slist_next (walk);
893
894     if (mixcol->buffer == NULL) {
895       GstBuffer *buf = NULL;
896
897       GST_LOG ("we need a new buffer");
898
899       buf = gst_collect_pads_pop (mix->collect, data);
900
901       if (buf) {
902         guint64 duration;
903
904         GST_LOG ("we have a buffer !");
905
906         mixcol->buffer = buf;
907         duration = GST_BUFFER_DURATION (mixcol->buffer);
908         /* no duration on the buffer, use the framerate */
909         if (!GST_CLOCK_TIME_IS_VALID (duration)) {
910           if (mixpad->in_framerate_numerator == 0) {
911             duration = GST_CLOCK_TIME_NONE;
912           } else {
913             duration = GST_SECOND * mixpad->in_framerate_denominator /
914                 mixpad->in_framerate_numerator;
915           }
916         }
917         if (GST_CLOCK_TIME_IS_VALID (duration))
918           mixpad->queued += duration;
919         else if (!mixpad->queued)
920           mixpad->queued = GST_CLOCK_TIME_NONE;
921       } else {
922         GST_LOG ("pop returned a NULL buffer");
923       }
924     }
925     if (mixcol->buffer !=
926         NULL /* && GST_CLOCK_TIME_IS_VALID (mixpad->queued) */ ) {
927       /* got a buffer somewhere so we're not eos */
928       eos = FALSE;
929     }
930   }
931
932   return eos;
933 }
934
935 /* blend all buffers present on the pads */
936 static void
937 gst_videomixer_blend_buffers (GstVideoMixer * mix, GstBuffer * outbuf)
938 {
939   GSList *walk;
940
941   walk = mix->sinkpads;
942   while (walk) {                /* We walk with this list because it's ordered */
943     GstVideoMixerPad *pad = GST_VIDEO_MIXER_PAD (walk->data);
944     GstVideoMixerCollect *mixcol = pad->mixcol;
945
946     walk = g_slist_next (walk);
947
948     if (mixcol->buffer != NULL) {
949       gst_videomixer_blend_ayuv_ayuv (GST_BUFFER_DATA (mixcol->buffer),
950           pad->xpos, pad->ypos,
951           pad->in_width, pad->in_height,
952           pad->alpha,
953           GST_BUFFER_DATA (outbuf), mix->out_width, mix->out_height);
954       if (pad == mix->master) {
955         GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (mixcol->buffer);
956         GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (mixcol->buffer);
957       }
958     }
959   }
960 }
961
962 /* remove buffers from the queue that were expired in the
963  * interval of the master, we also prepare the queued value
964  * in the pad so that we can skip and fill buffers later on */
965 static void
966 gst_videomixer_update_queues (GstVideoMixer * mix)
967 {
968   GSList *walk;
969   guint64 interval;
970
971   interval = mix->master->queued;
972   if (interval <= 0) {
973     if (mix->in_framerate_numerator == 0) {
974       interval = G_MAXINT64;
975     } else {
976       interval = GST_SECOND * mix->in_framerate_denominator /
977           mix->in_framerate_numerator;
978     }
979   }
980
981   walk = mix->sinkpads;
982   while (walk) {
983     GstVideoMixerPad *pad = GST_VIDEO_MIXER_PAD (walk->data);
984     GstVideoMixerCollect *mixcol = pad->mixcol;
985
986     walk = g_slist_next (walk);
987
988     if (mixcol->buffer != NULL && GST_CLOCK_TIME_IS_VALID (pad->queued)) {
989       pad->queued -= interval;
990       GST_DEBUG_OBJECT (pad, "queued now %lld", pad->queued);
991       if (pad->queued == 0) {
992         GST_DEBUG ("unreffing buffer");
993         gst_buffer_unref (mixcol->buffer);
994         mixcol->buffer = NULL;
995       }
996     }
997   }
998 }
999
1000 /*
1001  * The basic idea is to get a buffer on all pads and mix them together.
1002  * Based on the framerate, buffers are removed from the queues to make room
1003  * for a new buffer. 
1004  
1005 static void
1006 gst_videomixer_loop (GstElement * element)
1007 {
1008   GstVideoMixer *mix;
1009   GstBuffer *outbuf;
1010   gint outsize;
1011   gint new_width, new_height;
1012   gboolean eos;
1013
1014   mix = GST_VIDEO_MIXER (element);
1015
1016   eos = gst_videomixer_fill_queues (mix);
1017   if (eos) {
1018     gst_pad_push (mix->srcpad, GST_DATA (gst_event_new (GST_EVENT_EOS)));
1019     gst_element_set_eos (GST_ELEMENT (mix));
1020     return;
1021   }
1022
1023   new_width = mix->in_width;
1024   new_height = mix->in_height;
1025
1026   if (new_width != mix->out_width ||
1027       new_height != mix->out_height || !GST_PAD_CAPS (mix->srcpad)) {
1028     GstCaps *newcaps;
1029
1030     newcaps = gst_caps_make_writable (
1031         gst_pad_get_negotiated_caps (GST_PAD (mix->master)));
1032     gst_caps_set_simple (newcaps, "format", GST_TYPE_FOURCC,
1033         GST_STR_FOURCC ("AYUV"), "width", G_TYPE_INT, new_width, "height",
1034         G_TYPE_INT, new_height, NULL);
1035
1036     if (GST_PAD_LINK_FAILED (gst_pad_try_set_caps (mix->srcpad, newcaps))) {
1037       GST_ELEMENT_ERROR (mix, CORE, NEGOTIATION, (NULL), (NULL));
1038       return;
1039     }
1040
1041     mix->out_width = new_width;
1042     mix->out_height = new_height;
1043   }
1044
1045   outsize = ROUND_UP_2 (mix->out_width) * ROUND_UP_2 (mix->out_height) * 4;
1046
1047   outbuf = gst_pad_alloc_buffer (mix->srcpad, GST_BUFFER_OFFSET_NONE, outsize);
1048   switch (mix->background) {
1049     case VIDEO_MIXER_BACKGROUND_CHECKER:
1050       gst_videomixer_fill_checker (GST_BUFFER_DATA (outbuf),
1051           new_width, new_height);
1052       break;
1053     case VIDEO_MIXER_BACKGROUND_BLACK:
1054       gst_videomixer_fill_color (GST_BUFFER_DATA (outbuf),
1055           new_width, new_height, 16, 128, 128);
1056       break;
1057     case VIDEO_MIXER_BACKGROUND_WHITE:
1058       gst_videomixer_fill_color (GST_BUFFER_DATA (outbuf),
1059           new_width, new_height, 240, 128, 128);
1060       break;
1061   }
1062
1063   gst_videomixer_blend_buffers (mix, outbuf);
1064
1065   gst_videomixer_update_queues (mix);
1066
1067   gst_pad_push (mix->srcpad, GST_DATA (outbuf));
1068 }*/
1069
1070 static GstFlowReturn
1071 gst_videomixer_collected (GstCollectPads * pads, GstVideoMixer * mix)
1072 {
1073   GstFlowReturn ret = GST_FLOW_OK;
1074   GstBuffer *outbuf = NULL;
1075   size_t outsize = 0;
1076   gboolean eos = FALSE;
1077
1078   g_return_val_if_fail (GST_IS_VIDEO_MIXER (mix), GST_FLOW_ERROR);
1079
1080   GST_LOG ("all pads are collected");
1081
1082   eos = gst_videomixer_fill_queues (mix);
1083
1084   if (eos) {
1085     /* Push EOS downstream */
1086     GST_LOG ("all our sinkpads are EOS, pushing downstream");
1087     gst_pad_push_event (mix->srcpad, gst_event_new_eos ());
1088     ret = GST_FLOW_WRONG_STATE;
1089     goto beach;
1090   }
1091
1092   /* Calculating out buffer size from input size */
1093   outsize = ROUND_UP_2 (mix->in_width) * ROUND_UP_2 (mix->in_height) * 4;
1094
1095   /* If geometry has changed we need to set new caps on the buffer */
1096   if (mix->in_width != mix->out_width || mix->in_height != mix->out_height) {
1097     GstCaps *newcaps = NULL;
1098
1099     newcaps = gst_caps_make_writable
1100         (gst_pad_get_negotiated_caps (GST_PAD (mix->master)));
1101     gst_caps_set_simple (newcaps,
1102         "format", GST_TYPE_FOURCC, GST_STR_FOURCC ("AYUV"),
1103         "width", G_TYPE_INT, mix->in_width,
1104         "height", G_TYPE_INT, mix->in_height, NULL);
1105
1106     mix->out_width = mix->in_width;
1107     mix->out_height = mix->in_height;
1108
1109     ret = gst_pad_alloc_buffer (mix->srcpad, GST_BUFFER_OFFSET_NONE, outsize,
1110         newcaps, &outbuf);
1111     gst_caps_unref (newcaps);
1112   } else {                      /* Otherwise we just allocate a buffer from current caps */
1113     ret = gst_pad_alloc_buffer (mix->srcpad, GST_BUFFER_OFFSET_NONE, outsize,
1114         GST_PAD_CAPS (mix->srcpad), &outbuf);
1115   }
1116
1117   if (ret != GST_FLOW_OK) {
1118     goto beach;
1119   }
1120
1121   switch (mix->background) {
1122     case VIDEO_MIXER_BACKGROUND_CHECKER:
1123       gst_videomixer_fill_checker (GST_BUFFER_DATA (outbuf),
1124           mix->out_width, mix->out_height);
1125       break;
1126     case VIDEO_MIXER_BACKGROUND_BLACK:
1127       gst_videomixer_fill_color (GST_BUFFER_DATA (outbuf),
1128           mix->out_width, mix->out_height, 16, 128, 128);
1129       break;
1130     case VIDEO_MIXER_BACKGROUND_WHITE:
1131       gst_videomixer_fill_color (GST_BUFFER_DATA (outbuf),
1132           mix->out_width, mix->out_height, 240, 128, 128);
1133       break;
1134   }
1135
1136   gst_videomixer_blend_buffers (mix, outbuf);
1137
1138   gst_videomixer_update_queues (mix);
1139
1140   ret = gst_pad_push (mix->srcpad, outbuf);
1141
1142 beach:
1143   return ret;
1144 }
1145
1146 static void
1147 gst_videomixer_get_property (GObject * object,
1148     guint prop_id, GValue * value, GParamSpec * pspec)
1149 {
1150   GstVideoMixer *mix = GST_VIDEO_MIXER (object);
1151
1152   switch (prop_id) {
1153     case ARG_BACKGROUND:
1154       g_value_set_enum (value, mix->background);
1155       break;
1156     default:
1157       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1158       break;
1159   }
1160 }
1161
1162 static void
1163 gst_videomixer_set_property (GObject * object,
1164     guint prop_id, const GValue * value, GParamSpec * pspec)
1165 {
1166   GstVideoMixer *mix = GST_VIDEO_MIXER (object);
1167
1168   switch (prop_id) {
1169     case ARG_BACKGROUND:
1170       mix->background = g_value_get_enum (value);
1171       break;
1172     default:
1173       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1174       break;
1175   }
1176 }
1177
1178 static GstStateChangeReturn
1179 gst_videomixer_change_state (GstElement * element, GstStateChange transition)
1180 {
1181   GstVideoMixer *mix;
1182   GstStateChangeReturn ret;
1183
1184   g_return_val_if_fail (GST_IS_VIDEO_MIXER (element), GST_STATE_CHANGE_FAILURE);
1185
1186   mix = GST_VIDEO_MIXER (element);
1187
1188   switch (transition) {
1189     case GST_STATE_CHANGE_READY_TO_PAUSED:
1190       GST_LOG ("starting collectpads");
1191       gst_collect_pads_start (mix->collect);
1192       break;
1193     case GST_STATE_CHANGE_PAUSED_TO_READY:
1194       GST_LOG ("stopping collectpads");
1195       gst_collect_pads_stop (mix->collect);
1196       break;
1197     default:
1198       break;
1199   }
1200
1201   ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1202
1203   return ret;
1204 }
1205
1206 static gboolean
1207 plugin_init (GstPlugin * plugin)
1208 {
1209   GST_DEBUG_CATEGORY_INIT (gst_videomixer_debug, "videomixer", 0,
1210       "video mixer");
1211
1212   return gst_element_register (plugin, "videomixer", GST_RANK_PRIMARY,
1213       GST_TYPE_VIDEO_MIXER);
1214 }
1215
1216 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1217     GST_VERSION_MINOR,
1218     "videomixer",
1219     "Video mixer", plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME,
1220     GST_PACKAGE_ORIGIN)