1 /* Generic video mixer plugin
2 * Copyright (C) 2004 Wim Taymans <wim@fluendo.com>
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.
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.
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.
21 * SECTION:element-videomixer
23 * Videomixer can accept AYUV and BGRA video streams. For each of the requested
24 * sink pads it will compare the incoming geometry and framerate to define the
25 * output parameters. Indeed output video frames will have the geometry of the
26 * biggest incoming video stream and the framerate of the fastest incoming one.
28 * All sink pads must be either AYUV or BGRA, but a mixture of them is not
29 * supported. The src pad will have the same colorspace as the sinks.
30 * No colorspace conversion is done.
33 * Individual parameters for each input stream can be configured on the
37 * <title>Sample pipelines</title>
39 * gst-launch videotestsrc pattern=1 ! video/x-raw-yuv, framerate=\(fraction\)10/1, width=100, height=100 ! videobox border-alpha=0 alpha=0.5 top=-70 bottom=-70 right=-220 ! videomixer name=mix ! ffmpegcolorspace ! xvimagesink videotestsrc ! video/x-raw-yuv, framerate=\(fraction\)5/1, width=320, height=240 ! alpha alpha=0.7 ! mix.
40 * ]| A pipeline to demonstrate videomixer used together with videobox.
41 * This should show a 320x240 pixels video test source with some transparency
42 * showing the background checker pattern. Another video test source with just
43 * the snow pattern of 100x100 pixels is overlayed on top of the first one on
44 * the left vertically centered with a small transparency showing the first
45 * video test source behind and the checker pattern under it. Note that the
46 * framerate of the output video is 10 frames per second.
48 * gst-launch videotestsrc pattern=1 ! video/x-raw-rgb, framerate=\(fraction\)10/1, width=100, height=100 ! videomixer name=mix ! ffmpegcolorspace ! ximagesink videotestsrc ! video/x-raw-rgb, framerate=\(fraction\)5/1, width=320, height=240 ! mix.
49 * ]| A pipeline to demostrate bgra mixing. (This does not demonstrate alpha blending).
51 * gst-launch videotestsrc pattern=1 ! video/x-raw-yuv,format =\(fourcc\)I420, framerate=\(fraction\)10/1, width=100, height=100 ! videomixer name=mix ! ffmpegcolorspace ! ximagesink videotestsrc ! video/x-raw-yuv,format=\(fourcc\)I420, framerate=\(fraction\)5/1, width=320, height=240 ! mix.
52 * ]| A pipeline to test I420
61 #include <gst/base/gstcollectpads.h>
62 #include <gst/controller/gstcontroller.h>
63 #include <gst/video/video.h>
72 #include "videomixer.h"
74 GST_DEBUG_CATEGORY_STATIC (gst_videomixer_debug);
75 #define GST_CAT_DEFAULT gst_videomixer_debug
77 #define GST_VIDEO_MIXER_GET_STATE_LOCK(mix) \
78 (GST_VIDEO_MIXER(mix)->state_lock)
79 #define GST_VIDEO_MIXER_STATE_LOCK(mix) \
80 (g_mutex_lock(GST_VIDEO_MIXER_GET_STATE_LOCK (mix)))
81 #define GST_VIDEO_MIXER_STATE_UNLOCK(mix) \
82 (g_mutex_unlock(GST_VIDEO_MIXER_GET_STATE_LOCK (mix)))
84 static GType gst_videomixer_get_type (void);
87 static void gst_videomixer_pad_class_init (GstVideoMixerPadClass * klass);
88 static void gst_videomixer_pad_init (GstVideoMixerPad * mixerpad);
90 static void gst_videomixer_pad_get_property (GObject * object, guint prop_id,
91 GValue * value, GParamSpec * pspec);
92 static void gst_videomixer_pad_set_property (GObject * object, guint prop_id,
93 const GValue * value, GParamSpec * pspec);
95 static gboolean gst_videomixer_src_event (GstPad * pad, GstEvent * event);
96 static gboolean gst_videomixer_sink_event (GstPad * pad, GstEvent * event);
98 static void gst_videomixer_sort_pads (GstVideoMixer * mix);
100 /*AYUV function definitions see file: blend_ayuv*/
101 void gst_videomixer_blend_ayuv_ayuv (guint8 * src, gint xpos, gint ypos,
102 gint src_width, gint src_height, gdouble src_alpha,
103 guint8 * dest, gint dest_width, gint dest_height);
104 void gst_videomixer_fill_ayuv_checker (guint8 * dest, gint width, gint height);
105 void gst_videomixer_fill_ayuv_color (guint8 * dest, gint width, gint height,
106 gint colY, gint colU, gint colV);
107 size_t gst_videomixer_calculate_frame_size_ayuv (gint width, gint height);
108 /*BGRA function definitions see file: blend_ayuv*/
109 void gst_videomixer_blend_bgra_bgra (guint8 * src, gint xpos, gint ypos,
110 gint src_width, gint src_height, gdouble src_alpha,
111 guint8 * dest, gint dest_width, gint dest_height);
112 void gst_videomixer_fill_bgra_checker (guint8 * dest, gint width, gint height);
113 void gst_videomixer_fill_bgra_color (guint8 * dest, gint width, gint height,
114 gint colY, gint colU, gint colV);
115 size_t gst_videomixer_calculate_frame_size_bgra (gint width, gint height);
116 /*I420 function definitions see file: blend_i420.c*/
117 void gst_videomixer_blend_i420_i420 (guint8 * src, gint xpos, gint ypos,
118 gint src_width, gint src_height, gdouble src_alpha,
119 guint8 * dest, gint dest_width, gint dest_heighty);
120 void gst_videomixer_fill_i420_checker (guint8 * dest, gint width, gint height);
121 void gst_videomixer_fill_i420_color (guint8 * dest, gint width, gint height,
122 gint colY, gint colU, gint colV);
123 size_t gst_videomixer_calculate_frame_size_i420 (gint width, gint height);
125 #define DEFAULT_PAD_ZORDER 0
126 #define DEFAULT_PAD_XPOS 0
127 #define DEFAULT_PAD_YPOS 0
128 #define DEFAULT_PAD_ALPHA 1.0
139 gst_videomixer_pad_get_type (void)
141 static GType videomixer_pad_type = 0;
143 if (!videomixer_pad_type) {
144 static const GTypeInfo videomixer_pad_info = {
145 sizeof (GstVideoMixerPadClass),
148 (GClassInitFunc) gst_videomixer_pad_class_init,
151 sizeof (GstVideoMixerPad),
153 (GInstanceInitFunc) gst_videomixer_pad_init,
156 videomixer_pad_type = g_type_register_static (GST_TYPE_PAD,
157 "GstVideoMixerPad", &videomixer_pad_info, 0);
159 return videomixer_pad_type;
163 gst_videomixer_pad_class_init (GstVideoMixerPadClass * klass)
165 GObjectClass *gobject_class;
167 gobject_class = (GObjectClass *) klass;
169 gobject_class->set_property =
170 GST_DEBUG_FUNCPTR (gst_videomixer_pad_set_property);
171 gobject_class->get_property =
172 GST_DEBUG_FUNCPTR (gst_videomixer_pad_get_property);
174 g_object_class_install_property (gobject_class, ARG_PAD_ZORDER,
175 g_param_spec_uint ("zorder", "Z-Order", "Z Order of the picture",
176 0, 10000, DEFAULT_PAD_ZORDER,
177 G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
178 g_object_class_install_property (gobject_class, ARG_PAD_XPOS,
179 g_param_spec_int ("xpos", "X Position", "X Position of the picture",
180 G_MININT, G_MAXINT, DEFAULT_PAD_XPOS,
181 G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
182 g_object_class_install_property (gobject_class, ARG_PAD_YPOS,
183 g_param_spec_int ("ypos", "Y Position", "Y Position of the picture",
184 G_MININT, G_MAXINT, DEFAULT_PAD_YPOS,
185 G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
186 g_object_class_install_property (gobject_class, ARG_PAD_ALPHA,
187 g_param_spec_double ("alpha", "Alpha", "Alpha of the picture", 0.0, 1.0,
188 DEFAULT_PAD_ALPHA, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
192 gst_videomixer_pad_get_property (GObject * object, guint prop_id,
193 GValue * value, GParamSpec * pspec)
195 GstVideoMixerPad *pad = GST_VIDEO_MIXER_PAD (object);
199 g_value_set_uint (value, pad->zorder);
202 g_value_set_int (value, pad->xpos);
205 g_value_set_int (value, pad->ypos);
208 g_value_set_double (value, pad->alpha);
211 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
217 gst_videomixer_pad_set_property (GObject * object, guint prop_id,
218 const GValue * value, GParamSpec * pspec)
220 GstVideoMixerPad *pad;
223 pad = GST_VIDEO_MIXER_PAD (object);
224 mix = GST_VIDEO_MIXER (gst_pad_get_parent (GST_PAD (pad)));
228 GST_VIDEO_MIXER_STATE_LOCK (mix);
229 pad->zorder = g_value_get_uint (value);
230 gst_videomixer_sort_pads (mix);
231 GST_VIDEO_MIXER_STATE_UNLOCK (mix);
234 pad->xpos = g_value_get_int (value);
237 pad->ypos = g_value_get_int (value);
240 pad->alpha = g_value_get_double (value);
243 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
247 gst_object_unref (mix);
251 gst_videomixer_set_master_geometry (GstVideoMixer * mix)
254 gint width = 0, height = 0, fps_n = 0, fps_d = 0;
255 GstVideoMixerPad *master = NULL;
257 walk = mix->sinkpads;
259 GstVideoMixerPad *mixpad = GST_VIDEO_MIXER_PAD (walk->data);
261 walk = g_slist_next (walk);
263 /* Biggest input geometry will be our output geometry */
264 width = MAX (width, mixpad->in_width);
265 height = MAX (height, mixpad->in_height);
267 /* If mix framerate < mixpad framerate, using fractions */
268 GST_DEBUG_OBJECT (mix, "comparing framerate %d/%d to mixpad's %d/%d",
269 fps_n, fps_d, mixpad->fps_n, mixpad->fps_d);
270 if ((!fps_n && !fps_d) ||
271 ((gint64) fps_n * mixpad->fps_d < (gint64) mixpad->fps_n * fps_d)) {
272 fps_n = mixpad->fps_n;
273 fps_d = mixpad->fps_d;
274 GST_DEBUG_OBJECT (mixpad, "becomes the master pad");
280 if (mix->master != master || mix->in_width != width
281 || mix->in_height != height || mix->fps_n != fps_n
282 || mix->fps_d != fps_d) {
285 mix->master = master;
286 mix->in_width = width;
287 mix->in_height = height;
294 gst_videomixer_pad_sink_setcaps (GstPad * pad, GstCaps * vscaps)
297 GstVideoMixerPad *mixpad;
298 GstStructure *structure;
299 gint in_width, in_height;
300 gboolean ret = FALSE;
301 const GValue *framerate;
302 GST_INFO_OBJECT (pad, "setcaps:\n%" GST_PTR_FORMAT, vscaps);
304 mix = GST_VIDEO_MIXER (gst_pad_get_parent (pad));
305 mixpad = GST_VIDEO_MIXER_PAD (pad);
310 GST_DEBUG_OBJECT (mixpad, "setcaps triggered");
312 structure = gst_caps_get_structure (vscaps, 0);
314 if (!gst_structure_get_int (structure, "width", &in_width)
315 || !gst_structure_get_int (structure, "height", &in_height)
316 || (framerate = gst_structure_get_value (structure, "framerate")) == NULL)
319 GST_VIDEO_MIXER_STATE_LOCK (mix);
320 mixpad->fps_n = gst_value_get_fraction_numerator (framerate);
321 mixpad->fps_d = gst_value_get_fraction_denominator (framerate);
323 mixpad->in_width = in_width;
324 mixpad->in_height = in_height;
326 gst_videomixer_set_master_geometry (mix);
327 GST_VIDEO_MIXER_STATE_UNLOCK (mix);
332 gst_object_unref (mix);
338 * We accept the caps if it has the same format as other sink pads in
342 gst_videomixer_pad_sink_acceptcaps (GstPad * pad, GstCaps * vscaps)
346 GstCaps *acceptedCaps;
347 mix = GST_VIDEO_MIXER (gst_pad_get_parent (pad));
348 GST_DEBUG_OBJECT (pad, "TRACE: \n%" GST_PTR_FORMAT, vscaps);
349 GST_VIDEO_MIXER_STATE_LOCK (mix);
352 acceptedCaps = gst_pad_get_fixed_caps_func (GST_PAD (mix->master));
353 acceptedCaps = gst_caps_make_writable (acceptedCaps);
354 GST_LOG ("\nmaster's caps\n%" GST_PTR_FORMAT "\n", acceptedCaps);
355 if (GST_CAPS_IS_SIMPLE (acceptedCaps)) {
357 gst_caps_get_size (gst_pad_get_pad_template_caps (pad));
359 for (i = 0; i < templCapsSize; i++) {
360 GstCaps *caps1 = gst_caps_copy (acceptedCaps);
362 gst_caps_copy_nth (gst_pad_get_pad_template_caps (pad), i);
363 gst_caps_merge (caps1, caps2);
364 gst_caps_do_simplify (caps1);
365 if (GST_CAPS_IS_SIMPLE (caps1)) {
366 gst_caps_replace (&acceptedCaps, caps1);
367 gst_caps_unref (caps1);
370 gst_caps_unref (caps1);
374 acceptedCaps = gst_pad_get_fixed_caps_func (pad);
376 GST_INFO ("\n\n%" GST_PTR_FORMAT "\n\n", vscaps);
377 GST_INFO ("\n\n*********\n%" GST_PTR_FORMAT "\n\n", acceptedCaps);
379 ret = gst_caps_is_always_compatible (vscaps, acceptedCaps);
380 gst_caps_unref (acceptedCaps);
381 GST_VIDEO_MIXER_STATE_UNLOCK (mix);
382 gst_object_unref (mix);
387 gst_videomixer_pad_link (GstPad * pad, GstPad * peer, gpointer data)
389 GST_DEBUG_OBJECT (pad, "connected");
393 gst_videomixer_pad_unlink (GstPad * pad, GstPad * peer, gpointer data)
395 GST_DEBUG_OBJECT (pad, "unlinked");
399 gst_videomixer_pad_init (GstVideoMixerPad * mixerpad)
401 g_signal_connect (mixerpad, "linked",
402 G_CALLBACK (gst_videomixer_pad_link), mixerpad);
403 g_signal_connect (mixerpad, "unlinked",
404 G_CALLBACK (gst_videomixer_pad_unlink), mixerpad);
406 /* setup some pad functions */
407 gst_pad_set_setcaps_function (GST_PAD (mixerpad),
408 gst_videomixer_pad_sink_setcaps);
409 gst_pad_set_acceptcaps_function (GST_PAD (mixerpad),
410 GST_DEBUG_FUNCPTR (gst_videomixer_pad_sink_acceptcaps));
412 mixerpad->zorder = DEFAULT_PAD_ZORDER;
413 mixerpad->xpos = DEFAULT_PAD_XPOS;
414 mixerpad->ypos = DEFAULT_PAD_YPOS;
415 mixerpad->alpha = DEFAULT_PAD_ALPHA;
419 /* elementfactory information */
420 static const GstElementDetails gst_videomixer_details =
421 GST_ELEMENT_DETAILS ("Video mixer",
422 "Filter/Editor/Video",
423 "Mix multiple video streams",
424 "Wim Taymans <wim@fluendo.com>");
426 /* VideoMixer signals and args */
433 #define DEFAULT_BACKGROUND VIDEO_MIXER_BACKGROUND_CHECKER
440 #define GST_TYPE_VIDEO_MIXER_BACKGROUND (gst_video_mixer_background_get_type())
442 gst_video_mixer_background_get_type (void)
444 static GType video_mixer_background_type = 0;
446 static const GEnumValue video_mixer_background[] = {
447 {VIDEO_MIXER_BACKGROUND_CHECKER, "Checker pattern", "checker"},
448 {VIDEO_MIXER_BACKGROUND_BLACK, "Black", "black"},
449 {VIDEO_MIXER_BACKGROUND_WHITE, "White", "white"},
453 if (!video_mixer_background_type) {
454 video_mixer_background_type =
455 g_enum_register_static ("GstVideoMixerBackground",
456 video_mixer_background);
458 return video_mixer_background_type;
461 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
464 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV") ";" GST_VIDEO_CAPS_BGRA ";"
465 GST_VIDEO_CAPS_YUV ("I420"))
468 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink_%d",
471 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV") ";" GST_VIDEO_CAPS_BGRA ";"
472 GST_VIDEO_CAPS_YUV ("I420"))
475 static void gst_videomixer_finalize (GObject * object);
477 static GstCaps *gst_videomixer_getcaps (GstPad * pad);
478 static gboolean gst_videomixer_setcaps (GstPad * pad, GstCaps * caps);
479 static gboolean gst_videomixer_query (GstPad * pad, GstQuery * query);
481 static GstFlowReturn gst_videomixer_collected (GstCollectPads * pads,
482 GstVideoMixer * mix);
483 static GstPad *gst_videomixer_request_new_pad (GstElement * element,
484 GstPadTemplate * templ, const gchar * name);
485 static void gst_videomixer_release_pad (GstElement * element, GstPad * pad);
487 static void gst_videomixer_set_property (GObject * object, guint prop_id,
488 const GValue * value, GParamSpec * pspec);
489 static void gst_videomixer_get_property (GObject * object, guint prop_id,
490 GValue * value, GParamSpec * pspec);
491 static GstStateChangeReturn gst_videomixer_change_state (GstElement * element,
492 GstStateChange transition);
494 /*static guint gst_videomixer_signals[LAST_SIGNAL] = { 0 }; */
496 static void gst_videomixer_child_proxy_init (gpointer g_iface,
497 gpointer iface_data);
498 static void _do_init (GType object_type);
500 GST_BOILERPLATE_FULL (GstVideoMixer, gst_videomixer, GstElement,
501 GST_TYPE_ELEMENT, _do_init);
504 _do_init (GType object_type)
506 const GInterfaceInfo child_proxy_info = {
507 (GInterfaceInitFunc) gst_videomixer_child_proxy_init,
511 g_type_add_interface_static (object_type, GST_TYPE_CHILD_PROXY,
513 GST_INFO ("GstChildProxy interface registered");
517 gst_videomixer_child_proxy_get_child_by_index (GstChildProxy * child_proxy,
520 GstVideoMixer *mix = GST_VIDEO_MIXER (child_proxy);
523 GST_VIDEO_MIXER_STATE_LOCK (mix);
524 if ((obj = g_slist_nth_data (mix->sinkpads, index)))
525 gst_object_ref (obj);
526 GST_VIDEO_MIXER_STATE_UNLOCK (mix);
531 gst_videomixer_child_proxy_get_children_count (GstChildProxy * child_proxy)
534 GstVideoMixer *mix = GST_VIDEO_MIXER (child_proxy);
536 GST_VIDEO_MIXER_STATE_LOCK (mix);
537 count = mix->numpads;
538 GST_VIDEO_MIXER_STATE_UNLOCK (mix);
539 GST_INFO ("Children Count: %d", count);
544 gst_videomixer_child_proxy_init (gpointer g_iface, gpointer iface_data)
546 GstChildProxyInterface *iface = g_iface;
548 GST_INFO ("intializing child proxy interface");
549 iface->get_child_by_index = gst_videomixer_child_proxy_get_child_by_index;
550 iface->get_children_count = gst_videomixer_child_proxy_get_children_count;
554 gst_videomixer_base_init (gpointer g_class)
556 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
558 gst_element_class_add_pad_template (element_class,
559 gst_static_pad_template_get (&src_factory));
560 gst_element_class_add_pad_template (element_class,
561 gst_static_pad_template_get (&sink_factory));
563 gst_element_class_set_details (element_class, &gst_videomixer_details);
567 gst_videomixer_class_init (GstVideoMixerClass * klass)
569 GObjectClass *gobject_class;
570 GstElementClass *gstelement_class;
572 gobject_class = (GObjectClass *) klass;
573 gstelement_class = (GstElementClass *) klass;
575 parent_class = g_type_class_peek_parent (klass);
577 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_videomixer_finalize);
579 gobject_class->get_property = gst_videomixer_get_property;
580 gobject_class->set_property = gst_videomixer_set_property;
582 g_object_class_install_property (gobject_class, ARG_BACKGROUND,
583 g_param_spec_enum ("background", "Background", "Background type",
584 GST_TYPE_VIDEO_MIXER_BACKGROUND,
585 DEFAULT_BACKGROUND, G_PARAM_READWRITE));
587 gstelement_class->request_new_pad =
588 GST_DEBUG_FUNCPTR (gst_videomixer_request_new_pad);
589 gstelement_class->release_pad =
590 GST_DEBUG_FUNCPTR (gst_videomixer_release_pad);
591 gstelement_class->change_state =
592 GST_DEBUG_FUNCPTR (gst_videomixer_change_state);
594 /* Register the pad class */
595 (void) (GST_TYPE_VIDEO_MIXER_PAD);
599 gst_videomixer_collect_free (GstVideoMixerCollect * mixcol)
601 if (mixcol->buffer) {
602 gst_buffer_unref (mixcol->buffer);
603 mixcol->buffer = NULL;
608 gst_videomixer_reset (GstVideoMixer * mix)
616 mix->fps_n = mix->fps_d = 0;
617 mix->setcaps = FALSE;
618 mix->sendseg = FALSE;
619 mix->segment_position = 0;
620 mix->segment_rate = 1.0;
624 /* clean up collect data */
625 walk = mix->collect->data;
627 GstVideoMixerCollect *data = (GstVideoMixerCollect *) walk->data;
629 gst_videomixer_collect_free (data);
630 walk = g_slist_next (walk);
633 mix->next_sinkpad = 0;
637 gst_videomixer_init (GstVideoMixer * mix, GstVideoMixerClass * g_class)
639 GstElementClass *klass = GST_ELEMENT_GET_CLASS (mix);
642 gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
644 gst_pad_set_getcaps_function (GST_PAD (mix->srcpad),
645 GST_DEBUG_FUNCPTR (gst_videomixer_getcaps));
646 gst_pad_set_setcaps_function (GST_PAD (mix->srcpad),
647 GST_DEBUG_FUNCPTR (gst_videomixer_setcaps));
648 gst_pad_set_query_function (GST_PAD (mix->srcpad),
649 GST_DEBUG_FUNCPTR (gst_videomixer_query));
650 gst_pad_set_event_function (GST_PAD (mix->srcpad),
651 GST_DEBUG_FUNCPTR (gst_videomixer_src_event));
652 gst_element_add_pad (GST_ELEMENT (mix), mix->srcpad);
654 mix->collect = gst_collect_pads_new ();
655 mix->background = DEFAULT_BACKGROUND;
657 gst_collect_pads_set_function (mix->collect,
658 (GstCollectPadsFunction) GST_DEBUG_FUNCPTR (gst_videomixer_collected),
661 mix->state_lock = g_mutex_new ();
662 /* initialize variables */
663 gst_videomixer_reset (mix);
667 gst_videomixer_finalize (GObject * object)
669 GstVideoMixer *mix = GST_VIDEO_MIXER (object);
671 gst_object_unref (mix->collect);
672 g_mutex_free (mix->state_lock);
674 G_OBJECT_CLASS (parent_class)->finalize (object);
678 gst_videomixer_query_duration (GstVideoMixer * mix, GstQuery * query)
687 gst_query_parse_duration (query, &format, NULL);
693 /* Take maximum of all durations */
694 it = gst_element_iterate_sink_pads (GST_ELEMENT_CAST (mix));
696 GstIteratorResult ires;
699 ires = gst_iterator_next (it, &item);
701 case GST_ITERATOR_DONE:
704 case GST_ITERATOR_OK:
706 GstPad *pad = GST_PAD_CAST (item);
709 /* ask sink peer for duration */
710 res &= gst_pad_query_peer_duration (pad, &format, &duration);
711 /* take max from all valid return values */
713 /* valid unknown length, stop searching */
714 if (duration == -1) {
718 /* else see if bigger than current max */
719 else if (duration > max)
722 gst_object_unref (pad);
725 case GST_ITERATOR_RESYNC:
728 gst_iterator_resync (it);
736 gst_iterator_free (it);
739 /* and store the max */
740 GST_DEBUG_OBJECT (mix, "Total duration in format %s: %"
741 GST_TIME_FORMAT, gst_format_get_name (format), GST_TIME_ARGS (max));
742 gst_query_set_duration (query, format, max);
749 gst_videomixer_query_latency (GstVideoMixer * mix, GstQuery * query)
751 GstClockTime min, max;
761 max = GST_CLOCK_TIME_NONE;
763 /* Take maximum of all latency values */
764 it = gst_element_iterate_sink_pads (GST_ELEMENT_CAST (mix));
766 GstIteratorResult ires;
769 ires = gst_iterator_next (it, &item);
771 case GST_ITERATOR_DONE:
774 case GST_ITERATOR_OK:
776 GstPad *pad = GST_PAD_CAST (item);
780 GstClockTime min_cur, max_cur;
784 peerquery = gst_query_new_latency ();
786 /* Ask peer for latency */
787 res &= gst_pad_peer_query (pad, peerquery);
789 /* take max from all valid return values */
791 gst_query_parse_latency (peerquery, &live_cur, &min_cur, &max_cur);
796 if (max_cur != GST_CLOCK_TIME_NONE &&
797 ((max != GST_CLOCK_TIME_NONE && max_cur > max) ||
798 (max == GST_CLOCK_TIME_NONE)))
801 live = live || live_cur;
804 gst_query_unref (peerquery);
805 gst_object_unref (pad);
808 case GST_ITERATOR_RESYNC:
811 max = GST_CLOCK_TIME_NONE;
813 gst_iterator_resync (it);
821 gst_iterator_free (it);
824 /* store the results */
825 GST_DEBUG_OBJECT (mix, "Calculated total latency: live %s, min %"
826 GST_TIME_FORMAT ", max %" GST_TIME_FORMAT,
827 (live ? "yes" : "no"), GST_TIME_ARGS (min), GST_TIME_ARGS (max));
828 gst_query_set_latency (query, live, min, max);
835 gst_videomixer_query (GstPad * pad, GstQuery * query)
837 GstVideoMixer *mix = GST_VIDEO_MIXER (gst_pad_get_parent (pad));
838 gboolean res = FALSE;
840 switch (GST_QUERY_TYPE (query)) {
841 case GST_QUERY_POSITION:
845 gst_query_parse_position (query, &format, NULL);
848 case GST_FORMAT_TIME:
849 /* FIXME, bring to stream time, might be tricky */
850 gst_query_set_position (query, format, mix->last_ts);
858 case GST_QUERY_DURATION:
859 res = gst_videomixer_query_duration (mix, query);
861 case GST_QUERY_LATENCY:
862 res = gst_videomixer_query_latency (mix, query);
865 /* FIXME, needs a custom query handler because we have multiple
867 res = gst_pad_query_default (pad, query);
871 gst_object_unref (mix);
876 gst_videomixer_getcaps (GstPad * pad)
880 GstStructure *structure;
882 GST_LOG_OBJECT (pad, "TRACE");
884 mix = GST_VIDEO_MIXER (gst_pad_get_parent (pad));
888 gst_caps_copy (gst_pad_get_pad_template_caps (GST_PAD (mix->master)));
890 caps = gst_caps_copy (gst_pad_get_pad_template_caps (mix->srcpad));
893 numCaps = gst_caps_get_size (caps) - 1;
894 for (; numCaps >= 0; numCaps--) {
895 structure = gst_caps_get_structure (caps, numCaps);
896 if (mix->out_width != 0) {
897 gst_structure_set (structure, "width", G_TYPE_INT, mix->out_width, NULL);
899 if (mix->out_height != 0) {
900 gst_structure_set (structure, "height", G_TYPE_INT, mix->out_height,
903 if (mix->fps_d != 0) {
904 gst_structure_set (structure,
905 "framerate", GST_TYPE_FRACTION, mix->fps_n, mix->fps_d, NULL);
909 gst_object_unref (mix);
915 gst_videomixer_setcaps (GstPad * pad, GstCaps * caps)
918 GstVideoMixer *mixer;
920 element = gst_pad_get_parent_element (pad);
922 mixer = GST_VIDEO_MIXER (element);
924 GST_INFO_OBJECT (mixer, "set src caps: \n%" GST_PTR_FORMAT, caps);
926 str = gst_caps_get_structure (caps, 0);
928 if (gst_structure_has_name (str, "video/x-raw-yuv")) {
931 ret = gst_structure_get_fourcc (str, "format", &format);
934 mixer->fill_checker = NULL;
935 mixer->fill_color = NULL;
936 mixer->calculate_frame_size = NULL;
937 } else if (format == GST_STR_FOURCC ("AYUV")) {
938 mixer->blend = gst_videomixer_blend_ayuv_ayuv;
939 mixer->fill_checker = gst_videomixer_fill_ayuv_checker;
940 mixer->fill_color = gst_videomixer_fill_ayuv_color;
941 mixer->calculate_frame_size = gst_videomixer_calculate_frame_size_ayuv;
942 } else if (format == GST_STR_FOURCC ("I420")) {
943 mixer->blend = gst_videomixer_blend_i420_i420;
944 mixer->fill_checker = gst_videomixer_fill_i420_checker;
945 mixer->fill_color = gst_videomixer_fill_i420_color;
946 mixer->calculate_frame_size = gst_videomixer_calculate_frame_size_i420;
949 mixer->fill_checker = NULL;
950 mixer->fill_color = NULL;
951 mixer->calculate_frame_size = NULL;
953 } else if (gst_structure_has_name (str, "video/x-raw-rgb")) {
954 mixer->blend = gst_videomixer_blend_bgra_bgra;
955 mixer->fill_checker = gst_videomixer_fill_bgra_checker;
956 mixer->fill_color = gst_videomixer_fill_bgra_color;
957 mixer->calculate_frame_size = gst_videomixer_calculate_frame_size_bgra;
960 mixer->fill_checker = NULL;
961 mixer->fill_color = NULL;
962 mixer->calculate_frame_size = NULL;
964 gst_object_unref (element);
970 gst_videomixer_request_new_pad (GstElement * element,
971 GstPadTemplate * templ, const gchar * req_name)
973 GstVideoMixer *mix = NULL;
974 GstVideoMixerPad *mixpad = NULL;
975 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
977 g_return_val_if_fail (templ != NULL, NULL);
979 if (templ->direction != GST_PAD_SINK) {
980 g_warning ("videomixer: request pad that is not a SINK pad\n");
984 g_return_val_if_fail (GST_IS_VIDEO_MIXER (element), NULL);
986 mix = GST_VIDEO_MIXER (element);
988 if (templ == gst_element_class_get_pad_template (klass, "sink_%d")) {
991 GstVideoMixerCollect *mixcol = NULL;
993 if (req_name == NULL || strlen (req_name) < 6) {
994 /* no name given when requesting the pad, use next available int */
995 serial = mix->next_sinkpad++;
997 /* parse serial number from requested padname */
998 serial = atoi (&req_name[5]);
999 if (serial >= mix->next_sinkpad)
1000 mix->next_sinkpad = serial + 1;
1002 /* create new pad with the name */
1003 name = g_strdup_printf ("sink_%d", serial);
1004 mixpad = g_object_new (GST_TYPE_VIDEO_MIXER_PAD, "name", name, "direction",
1005 templ->direction, "template", templ, NULL);
1008 GST_VIDEO_MIXER_STATE_LOCK (mix);
1009 mixpad->zorder = mix->numpads;
1010 mixpad->xpos = DEFAULT_PAD_XPOS;
1011 mixpad->ypos = DEFAULT_PAD_YPOS;
1012 mixpad->alpha = DEFAULT_PAD_ALPHA;
1014 mixcol = (GstVideoMixerCollect *)
1015 gst_collect_pads_add_pad (mix->collect, GST_PAD (mixpad),
1016 sizeof (GstVideoMixerCollect));
1018 /* FIXME: hacked way to override/extend the event function of
1019 * GstCollectPads; because it sets its own event function giving the
1020 * element no access to events */
1021 mix->collect_event =
1022 (GstPadEventFunction) GST_PAD_EVENTFUNC (GST_PAD (mixpad));
1023 gst_pad_set_event_function (GST_PAD (mixpad),
1024 GST_DEBUG_FUNCPTR (gst_videomixer_sink_event));
1026 /* Keep track of each other */
1027 mixcol->mixpad = mixpad;
1028 mixpad->mixcol = mixcol;
1030 /* Keep an internal list of mixpads for zordering */
1031 mix->sinkpads = g_slist_append (mix->sinkpads, mixpad);
1033 GST_VIDEO_MIXER_STATE_UNLOCK (mix);
1035 g_warning ("videomixer: this is not our template!\n");
1039 /* add the pad to the element */
1040 gst_element_add_pad (element, GST_PAD (mixpad));
1041 gst_child_proxy_child_added (GST_OBJECT (mix), GST_OBJECT (mixpad));
1043 return GST_PAD (mixpad);
1047 gst_videomixer_release_pad (GstElement * element, GstPad * pad)
1049 GstVideoMixer *mix = NULL;
1050 GstVideoMixerPad *mixpad;
1052 mix = GST_VIDEO_MIXER (element);
1053 GST_VIDEO_MIXER_STATE_LOCK (mix);
1054 if (G_UNLIKELY (g_slist_find (mix->sinkpads, pad) == NULL)) {
1055 g_warning ("Unknown pad %s", GST_PAD_NAME (pad));
1059 mixpad = GST_VIDEO_MIXER_PAD (pad);
1061 mix->sinkpads = g_slist_remove (mix->sinkpads, pad);
1062 gst_videomixer_collect_free (mixpad->mixcol);
1063 gst_collect_pads_remove_pad (mix->collect, pad);
1064 gst_child_proxy_child_removed (GST_OBJECT (mix), GST_OBJECT (mixpad));
1065 /* determine possibly new geometry and master */
1066 gst_videomixer_set_master_geometry (mix);
1068 GST_VIDEO_MIXER_STATE_UNLOCK (mix);
1070 gst_element_remove_pad (element, pad);
1073 GST_VIDEO_MIXER_STATE_UNLOCK (mix);
1077 pad_zorder_compare (const GstVideoMixerPad * pad1,
1078 const GstVideoMixerPad * pad2)
1080 return pad1->zorder - pad2->zorder;
1084 gst_videomixer_sort_pads (GstVideoMixer * mix)
1086 mix->sinkpads = g_slist_sort (mix->sinkpads,
1087 (GCompareFunc) pad_zorder_compare);
1090 /* try to get a buffer on all pads. As long as the queued value is
1091 * negative, we skip buffers */
1093 gst_videomixer_fill_queues (GstVideoMixer * mix)
1095 GSList *walk = NULL;
1096 gboolean eos = TRUE;
1098 g_return_val_if_fail (GST_IS_VIDEO_MIXER (mix), FALSE);
1100 /* try to make sure we have a buffer from each usable pad first */
1101 walk = mix->collect->data;
1103 GstCollectData *data = (GstCollectData *) walk->data;
1104 GstVideoMixerCollect *mixcol = (GstVideoMixerCollect *) data;
1105 GstVideoMixerPad *mixpad = mixcol->mixpad;
1107 walk = g_slist_next (walk);
1109 if (mixcol->buffer == NULL) {
1110 GstBuffer *buf = NULL;
1112 GST_LOG ("we need a new buffer");
1114 buf = gst_collect_pads_pop (mix->collect, data);
1119 GST_LOG ("we have a buffer !");
1121 mixcol->buffer = buf;
1122 duration = GST_BUFFER_DURATION (mixcol->buffer);
1123 /* no duration on the buffer, use the framerate */
1124 if (!GST_CLOCK_TIME_IS_VALID (duration)) {
1125 if (mixpad->fps_n == 0) {
1126 duration = GST_CLOCK_TIME_NONE;
1128 duration = GST_SECOND * mixpad->fps_d / mixpad->fps_n;
1131 if (GST_CLOCK_TIME_IS_VALID (duration))
1132 mixpad->queued += duration;
1133 else if (!mixpad->queued)
1134 mixpad->queued = GST_CLOCK_TIME_NONE;
1136 GST_LOG ("pop returned a NULL buffer");
1139 if (mix->sendseg && (mixpad == mix->master)) {
1142 GstSegment *segment = &data->segment;
1144 /* FIXME, use rate/applied_rate as set on all sinkpads.
1145 * - currently we just set rate as received from last seek-event
1146 * We could potentially figure out the duration as well using
1147 * the current segment positions and the stated stop positions.
1148 * Also we just start from stream time 0 which is rather
1149 * weird. For non-synchronized mixing, the time should be
1150 * the min of the stream times of all received segments,
1151 * rationale being that the duration is at least going to
1152 * be as long as the earliest stream we start mixing. This
1153 * would also be correct for synchronized mixing but then
1154 * the later streams would be delayed until the stream times
1157 GST_INFO ("_sending play segment");
1159 start = segment->accum;
1161 /* get the duration of the segment if we can and add it to the accumulated
1162 * time on the segment. */
1163 if (segment->stop != -1 && segment->start != -1)
1164 stop = start + (segment->stop - segment->start);
1168 event = gst_event_new_new_segment_full (FALSE, segment->rate, 1.0,
1169 segment->format, start, stop, start + mix->segment_position);
1170 gst_pad_push_event (mix->srcpad, event);
1171 mix->sendseg = FALSE;
1174 if (mixcol->buffer != NULL && GST_CLOCK_TIME_IS_VALID (mixpad->queued)) {
1175 /* got a buffer somewhere so we're not eos */
1183 /* blend all buffers present on the pads */
1185 gst_videomixer_blend_buffers (GstVideoMixer * mix, GstBuffer * outbuf)
1189 walk = mix->sinkpads;
1190 while (walk) { /* We walk with this list because it's ordered */
1191 GstVideoMixerPad *pad = GST_VIDEO_MIXER_PAD (walk->data);
1192 GstVideoMixerCollect *mixcol = pad->mixcol;
1194 walk = g_slist_next (walk);
1196 if (mixcol->buffer != NULL) {
1197 GstClockTime timestamp;
1201 seg = &mixcol->collect.segment;
1203 timestamp = GST_BUFFER_TIMESTAMP (mixcol->buffer);
1206 gst_segment_to_stream_time (seg, GST_FORMAT_TIME, timestamp);
1208 /* sync object properties on stream time */
1209 if (GST_CLOCK_TIME_IS_VALID (stream_time))
1210 gst_object_sync_values (G_OBJECT (pad), stream_time);
1212 if (G_UNLIKELY (mix->blend == NULL)) {
1213 GST_ERROR_OBJECT (mix, "blend function not set");
1215 (mix->blend) (GST_BUFFER_DATA (mixcol->buffer),
1216 pad->xpos, pad->ypos, pad->in_width, pad->in_height, pad->alpha,
1217 GST_BUFFER_DATA (outbuf), mix->out_width, mix->out_height);
1220 if (pad == mix->master) {
1221 gint64 running_time;
1224 gst_segment_to_running_time (seg, GST_FORMAT_TIME, timestamp);
1226 /* outgoing buffers need the running_time */
1227 GST_BUFFER_TIMESTAMP (outbuf) = running_time;
1228 GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (mixcol->buffer);
1230 mix->last_ts = running_time;
1231 if (GST_BUFFER_DURATION_IS_VALID (outbuf))
1232 mix->last_ts += GST_BUFFER_DURATION (outbuf);
1238 /* remove buffers from the queue that were expired in the
1239 * interval of the master, we also prepare the queued value
1240 * in the pad so that we can skip and fill buffers later on */
1242 gst_videomixer_update_queues (GstVideoMixer * mix)
1247 interval = mix->master->queued;
1248 if (interval <= 0) {
1249 if (mix->fps_n == 0) {
1250 interval = G_MAXINT64;
1252 interval = GST_SECOND * mix->fps_d / mix->fps_n;
1254 GST_LOG_OBJECT (mix, "set interval to %" G_GUINT64_FORMAT, interval);
1257 walk = mix->sinkpads;
1259 GstVideoMixerPad *pad = GST_VIDEO_MIXER_PAD (walk->data);
1260 GstVideoMixerCollect *mixcol = pad->mixcol;
1262 walk = g_slist_next (walk);
1264 if (mixcol->buffer != NULL) {
1265 pad->queued -= interval;
1266 GST_LOG_OBJECT (pad, "queued now %" G_GINT64_FORMAT, pad->queued);
1267 if (pad->queued <= 0) {
1268 GST_LOG ("unreffing buffer");
1269 gst_buffer_unref (mixcol->buffer);
1270 mixcol->buffer = NULL;
1276 static GstFlowReturn
1277 gst_videomixer_collected (GstCollectPads * pads, GstVideoMixer * mix)
1279 GstFlowReturn ret = GST_FLOW_OK;
1280 GstBuffer *outbuf = NULL;
1282 gboolean eos = FALSE;
1284 g_return_val_if_fail (GST_IS_VIDEO_MIXER (mix), GST_FLOW_ERROR);
1286 GST_LOG ("all pads are collected");
1287 GST_VIDEO_MIXER_STATE_LOCK (mix);
1289 eos = gst_videomixer_fill_queues (mix);
1292 /* Push EOS downstream */
1293 GST_LOG ("all our sinkpads are EOS, pushing downstream");
1294 gst_pad_push_event (mix->srcpad, gst_event_new_eos ());
1295 ret = GST_FLOW_WRONG_STATE;
1299 /* If geometry has changed we need to set new caps on the buffer */
1300 if (mix->in_width != mix->out_width || mix->in_height != mix->out_height
1302 GstCaps *newcaps = NULL;
1304 newcaps = gst_caps_make_writable
1305 (gst_pad_get_negotiated_caps (GST_PAD (mix->master)));
1306 gst_caps_set_simple (newcaps,
1307 "width", G_TYPE_INT, mix->in_width,
1308 "height", G_TYPE_INT, mix->in_height, NULL);
1310 mix->out_width = mix->in_width;
1311 mix->out_height = mix->in_height;
1312 mix->setcaps = FALSE;
1314 /* Calculating out buffer size from input size */
1315 gst_pad_set_caps (mix->srcpad, newcaps);
1316 outsize = mix->calculate_frame_size (mix->out_width, mix->out_height);
1318 gst_pad_alloc_buffer_and_set_caps (mix->srcpad, GST_BUFFER_OFFSET_NONE,
1319 outsize, newcaps, &outbuf);
1320 gst_caps_unref (newcaps);
1321 } else { /* Otherwise we just allocate a buffer from current caps */
1322 /* Calculating out buffer size from input size */
1323 outsize = mix->calculate_frame_size (mix->out_width, mix->out_height);
1325 gst_pad_alloc_buffer_and_set_caps (mix->srcpad, GST_BUFFER_OFFSET_NONE,
1326 outsize, GST_PAD_CAPS (mix->srcpad), &outbuf);
1329 if (ret != GST_FLOW_OK) {
1333 switch (mix->background) {
1334 case VIDEO_MIXER_BACKGROUND_CHECKER:
1335 if (G_UNLIKELY (mix->fill_checker == NULL)) {
1338 mix->fill_checker (GST_BUFFER_DATA (outbuf), mix->out_width,
1342 case VIDEO_MIXER_BACKGROUND_BLACK:
1343 if (G_UNLIKELY (mix->fill_color == NULL)) {
1346 mix->fill_color (GST_BUFFER_DATA (outbuf), mix->out_width,
1347 mix->out_height, 16, 128, 128);
1350 case VIDEO_MIXER_BACKGROUND_WHITE:
1352 if (G_UNLIKELY (mix->fill_color == NULL)) {
1355 mix->fill_color (GST_BUFFER_DATA (outbuf), mix->out_width,
1356 mix->out_height, 240, 128, 128);
1361 gst_videomixer_blend_buffers (mix, outbuf);
1363 gst_videomixer_update_queues (mix);
1364 GST_VIDEO_MIXER_STATE_UNLOCK (mix);
1366 ret = gst_pad_push (mix->srcpad, outbuf);
1374 GST_VIDEO_MIXER_STATE_UNLOCK (mix);
1380 forward_event_func (GstPad * pad, GValue * ret, GstEvent * event)
1382 gst_event_ref (event);
1383 GST_LOG_OBJECT (pad, "About to send event %s", GST_EVENT_TYPE_NAME (event));
1384 if (!gst_pad_push_event (pad, event)) {
1385 g_value_set_boolean (ret, FALSE);
1386 GST_WARNING_OBJECT (pad, "Sending event %p (%s) failed.",
1387 event, GST_EVENT_TYPE_NAME (event));
1389 GST_LOG_OBJECT (pad, "Sent event %p (%s).",
1390 event, GST_EVENT_TYPE_NAME (event));
1392 gst_object_unref (pad);
1396 /* forwards the event to all sinkpads, takes ownership of the
1399 * Returns: TRUE if the event could be forwarded on all
1403 forward_event (GstVideoMixer * mix, GstEvent * event)
1406 GValue vret = { 0 };
1408 GST_LOG_OBJECT (mix, "Forwarding event %p (%s)", event,
1409 GST_EVENT_TYPE_NAME (event));
1411 g_value_init (&vret, G_TYPE_BOOLEAN);
1412 g_value_set_boolean (&vret, TRUE);
1413 it = gst_element_iterate_sink_pads (GST_ELEMENT_CAST (mix));
1414 gst_iterator_fold (it, (GstIteratorFoldFunction) forward_event_func, &vret,
1416 gst_iterator_free (it);
1417 gst_event_unref (event);
1419 return g_value_get_boolean (&vret);
1423 gst_videomixer_src_event (GstPad * pad, GstEvent * event)
1428 mix = GST_VIDEO_MIXER (gst_pad_get_parent (pad));
1430 switch (GST_EVENT_TYPE (event)) {
1432 /* QoS might be tricky */
1435 case GST_EVENT_SEEK:
1439 GstSeekType curtype;
1443 /* parse the seek parameters */
1444 gst_event_parse_seek (event, NULL, NULL, &flags, &curtype,
1447 /* check if we are flushing */
1448 if (flags & GST_SEEK_FLAG_FLUSH) {
1449 /* make sure we accept nothing anymore and return WRONG_STATE */
1450 gst_collect_pads_set_flushing (mix->collect, TRUE);
1452 /* flushing seek, start flush downstream, the flush will be done
1453 * when all pads received a FLUSH_STOP. */
1454 gst_pad_push_event (mix->srcpad, gst_event_new_flush_start ());
1457 /* now wait for the collected to be finished and mark a new
1459 GST_OBJECT_LOCK (mix->collect);
1460 if (curtype == GST_SEEK_TYPE_SET)
1461 mix->segment_position = cur;
1463 mix->segment_position = 0;
1464 mix->sendseg = TRUE;
1465 GST_OBJECT_UNLOCK (mix->collect);
1467 result = forward_event (mix, event);
1470 case GST_EVENT_NAVIGATION:
1471 /* navigation is rather pointless. */
1475 /* just forward the rest for now */
1476 result = forward_event (mix, event);
1479 gst_object_unref (mix);
1485 gst_videomixer_sink_event (GstPad * pad, GstEvent * event)
1487 GstVideoMixer *videomixer;
1490 videomixer = GST_VIDEO_MIXER (gst_pad_get_parent (pad));
1492 GST_DEBUG ("Got %s event on pad %s:%s", GST_EVENT_TYPE_NAME (event),
1493 GST_DEBUG_PAD_NAME (pad));
1495 switch (GST_EVENT_TYPE (event)) {
1496 case GST_EVENT_FLUSH_STOP:
1497 /* mark a pending new segment. This event is synchronized
1498 * with the streaming thread so we can safely update the
1499 * variable without races. It's somewhat weird because we
1500 * assume the collectpads forwarded the FLUSH_STOP past us
1501 * and downstream (using our source pad, the bastard!).
1503 videomixer->sendseg = TRUE;
1505 case GST_EVENT_NEWSEGMENT:
1506 videomixer->sendseg = TRUE;
1512 /* now GstCollectPads can take care of the rest, e.g. EOS */
1513 ret = videomixer->collect_event (pad, event);
1515 gst_object_unref (videomixer);
1521 gst_videomixer_get_property (GObject * object,
1522 guint prop_id, GValue * value, GParamSpec * pspec)
1524 GstVideoMixer *mix = GST_VIDEO_MIXER (object);
1527 case ARG_BACKGROUND:
1528 g_value_set_enum (value, mix->background);
1531 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1537 gst_videomixer_set_property (GObject * object,
1538 guint prop_id, const GValue * value, GParamSpec * pspec)
1540 GstVideoMixer *mix = GST_VIDEO_MIXER (object);
1543 case ARG_BACKGROUND:
1544 mix->background = g_value_get_enum (value);
1547 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1552 static GstStateChangeReturn
1553 gst_videomixer_change_state (GstElement * element, GstStateChange transition)
1556 GstStateChangeReturn ret;
1558 g_return_val_if_fail (GST_IS_VIDEO_MIXER (element), GST_STATE_CHANGE_FAILURE);
1560 mix = GST_VIDEO_MIXER (element);
1562 switch (transition) {
1563 case GST_STATE_CHANGE_READY_TO_PAUSED:
1564 GST_LOG ("starting collectpads");
1565 gst_collect_pads_start (mix->collect);
1567 case GST_STATE_CHANGE_PAUSED_TO_READY:
1568 GST_LOG ("stopping collectpads");
1569 gst_collect_pads_stop (mix->collect);
1575 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1577 switch (transition) {
1578 case GST_STATE_CHANGE_PAUSED_TO_READY:
1579 gst_videomixer_reset (mix);
1589 plugin_init (GstPlugin * plugin)
1591 GST_DEBUG_CATEGORY_INIT (gst_videomixer_debug, "videomixer", 0,
1594 return gst_element_register (plugin, "videomixer", GST_RANK_PRIMARY,
1595 GST_TYPE_VIDEO_MIXER);
1598 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1601 "Video mixer", plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME,