2 * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
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-shapewipe
23 * The shapewipe element provides custom transitions on video streams
24 * based on a grayscale bitmap. The state of the transition can be
25 * controlled by the position property and an optional blended border
26 * can be added by the border property.
28 * Transition bitmaps can be downloaded from the
29 * <ulink url="http://cinelerra.org/transitions.php">Cinelerra transition</ulink>
33 * <title>Example launch line</title>
35 * gst-launch -v videotestsrc ! video/x-raw-yuv,width=640,height=480 ! shapewipe position=0.5 name=shape ! videomixer name=mixer ! ffmpegcolorspace ! autovideosink filesrc location=mask.png ! typefind ! decodebin2 ! ffmpegcolorspace ! videoscale ! queue ! shape.mask_sink videotestsrc pattern=snow ! video/x-raw-yuv,width=640,height=480 ! queue ! mixer.
36 * ]| This pipeline adds the transition from mask.png with position 0.5 to an SMPTE test screen and snow.
48 #include <gst/controller/gstcontroller.h>
50 #include "gstshapewipe.h"
52 static void gst_shape_wipe_finalize (GObject * object);
53 static void gst_shape_wipe_get_property (GObject * object, guint prop_id,
54 GValue * value, GParamSpec * pspec);
55 static void gst_shape_wipe_set_property (GObject * object, guint prop_id,
56 const GValue * value, GParamSpec * pspec);
58 static void gst_shape_wipe_reset (GstShapeWipe * self);
60 static GstStateChangeReturn gst_shape_wipe_change_state (GstElement * element,
61 GstStateChange transition);
63 static GstFlowReturn gst_shape_wipe_video_sink_chain (GstPad * pad,
65 static gboolean gst_shape_wipe_video_sink_event (GstPad * pad,
67 static gboolean gst_shape_wipe_video_sink_setcaps (GstPad * pad,
69 static GstCaps *gst_shape_wipe_video_sink_getcaps (GstPad * pad);
70 static GstFlowReturn gst_shape_wipe_video_sink_bufferalloc (GstPad * pad,
71 guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf);
72 static gboolean gst_shape_wipe_video_sink_query (GstPad * pad,
74 static GstFlowReturn gst_shape_wipe_mask_sink_chain (GstPad * pad,
76 static gboolean gst_shape_wipe_mask_sink_event (GstPad * pad, GstEvent * event);
77 static gboolean gst_shape_wipe_mask_sink_setcaps (GstPad * pad, GstCaps * caps);
78 static GstCaps *gst_shape_wipe_mask_sink_getcaps (GstPad * pad);
79 static gboolean gst_shape_wipe_src_event (GstPad * pad, GstEvent * event);
80 static GstCaps *gst_shape_wipe_src_getcaps (GstPad * pad);
81 static gboolean gst_shape_wipe_src_query (GstPad * pad, GstQuery * query);
90 static GstStaticPadTemplate video_sink_pad_template =
91 GST_STATIC_PAD_TEMPLATE ("video_sink",
94 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV")));
96 static GstStaticPadTemplate mask_sink_pad_template =
97 GST_STATIC_PAD_TEMPLATE ("mask_sink",
100 GST_STATIC_CAPS ("video/x-raw-gray, "
103 "width = " GST_VIDEO_SIZE_RANGE ", "
104 "height = " GST_VIDEO_SIZE_RANGE ", " "framerate = 0/1 ; "
105 "video/x-raw-gray, " "bpp = 16, " "depth = 16, "
106 "endianness = BYTE_ORDER, " "width = " GST_VIDEO_SIZE_RANGE ", "
107 "height = " GST_VIDEO_SIZE_RANGE ", " "framerate = 0/1"));
109 static GstStaticPadTemplate src_pad_template =
110 GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
111 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV")));
113 GST_DEBUG_CATEGORY_STATIC (gst_shape_wipe_debug);
114 #define GST_CAT_DEFAULT gst_shape_wipe_debug
116 GST_BOILERPLATE (GstShapeWipe, gst_shape_wipe, GstElement, GST_TYPE_ELEMENT);
119 gst_shape_wipe_base_init (gpointer g_class)
121 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
123 gst_element_class_set_details_simple (gstelement_class,
124 "Shape Wipe transition filter",
125 "Filter/Editor/Video",
126 "Adds a shape wipe transition to a video stream",
127 "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
129 gst_element_class_add_pad_template (gstelement_class,
130 gst_static_pad_template_get (&video_sink_pad_template));
131 gst_element_class_add_pad_template (gstelement_class,
132 gst_static_pad_template_get (&mask_sink_pad_template));
133 gst_element_class_add_pad_template (gstelement_class,
134 gst_static_pad_template_get (&src_pad_template));
138 gst_shape_wipe_class_init (GstShapeWipeClass * klass)
140 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
141 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
143 gobject_class->finalize = gst_shape_wipe_finalize;
144 gobject_class->set_property = gst_shape_wipe_set_property;
145 gobject_class->get_property = gst_shape_wipe_get_property;
147 g_object_class_install_property (gobject_class, PROP_POSITION,
148 g_param_spec_float ("position", "Position", "Position of the mask",
150 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
151 g_object_class_install_property (gobject_class, PROP_BORDER,
152 g_param_spec_float ("border", "Border", "Border of the mask",
154 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
156 gstelement_class->change_state =
157 GST_DEBUG_FUNCPTR (gst_shape_wipe_change_state);
161 gst_shape_wipe_init (GstShapeWipe * self, GstShapeWipeClass * g_class)
163 self->video_sinkpad =
164 gst_pad_new_from_static_template (&video_sink_pad_template, "video_sink");
165 gst_pad_set_chain_function (self->video_sinkpad,
166 GST_DEBUG_FUNCPTR (gst_shape_wipe_video_sink_chain));
167 gst_pad_set_event_function (self->video_sinkpad,
168 GST_DEBUG_FUNCPTR (gst_shape_wipe_video_sink_event));
169 gst_pad_set_setcaps_function (self->video_sinkpad,
170 GST_DEBUG_FUNCPTR (gst_shape_wipe_video_sink_setcaps));
171 gst_pad_set_getcaps_function (self->video_sinkpad,
172 GST_DEBUG_FUNCPTR (gst_shape_wipe_video_sink_getcaps));
173 gst_pad_set_bufferalloc_function (self->video_sinkpad,
174 GST_DEBUG_FUNCPTR (gst_shape_wipe_video_sink_bufferalloc));
175 gst_pad_set_query_function (self->video_sinkpad,
176 GST_DEBUG_FUNCPTR (gst_shape_wipe_video_sink_query));
177 gst_element_add_pad (GST_ELEMENT (self), self->video_sinkpad);
180 gst_pad_new_from_static_template (&mask_sink_pad_template, "mask_sink");
181 gst_pad_set_chain_function (self->mask_sinkpad,
182 GST_DEBUG_FUNCPTR (gst_shape_wipe_mask_sink_chain));
183 gst_pad_set_event_function (self->mask_sinkpad,
184 GST_DEBUG_FUNCPTR (gst_shape_wipe_mask_sink_event));
185 gst_pad_set_setcaps_function (self->mask_sinkpad,
186 GST_DEBUG_FUNCPTR (gst_shape_wipe_mask_sink_setcaps));
187 gst_pad_set_getcaps_function (self->mask_sinkpad,
188 GST_DEBUG_FUNCPTR (gst_shape_wipe_mask_sink_getcaps));
189 gst_element_add_pad (GST_ELEMENT (self), self->mask_sinkpad);
191 self->srcpad = gst_pad_new_from_static_template (&src_pad_template, "src");
192 gst_pad_set_event_function (self->srcpad,
193 GST_DEBUG_FUNCPTR (gst_shape_wipe_src_event));
194 gst_pad_set_getcaps_function (self->srcpad,
195 GST_DEBUG_FUNCPTR (gst_shape_wipe_src_getcaps));
196 gst_pad_set_query_function (self->srcpad,
197 GST_DEBUG_FUNCPTR (gst_shape_wipe_src_query));
198 gst_element_add_pad (GST_ELEMENT (self), self->srcpad);
200 self->mask_mutex = g_mutex_new ();
201 self->mask_cond = g_cond_new ();
203 gst_shape_wipe_reset (self);
207 gst_shape_wipe_get_property (GObject * object, guint prop_id,
208 GValue * value, GParamSpec * pspec)
210 GstShapeWipe *self = GST_SHAPE_WIPE (object);
214 g_value_set_float (value, self->mask_position);
217 g_value_set_float (value, self->mask_border);
220 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
226 gst_shape_wipe_set_property (GObject * object, guint prop_id,
227 const GValue * value, GParamSpec * pspec)
229 GstShapeWipe *self = GST_SHAPE_WIPE (object);
233 self->mask_position = g_value_get_float (value);
236 self->mask_border = g_value_get_float (value);
239 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
245 gst_shape_wipe_finalize (GObject * object)
247 GstShapeWipe *self = GST_SHAPE_WIPE (object);
249 gst_shape_wipe_reset (self);
252 g_cond_free (self->mask_cond);
253 self->mask_cond = NULL;
255 if (self->mask_mutex)
256 g_mutex_free (self->mask_mutex);
257 self->mask_mutex = NULL;
259 G_OBJECT_CLASS (parent_class)->finalize (object);
263 gst_shape_wipe_reset (GstShapeWipe * self)
266 gst_buffer_unref (self->mask);
269 g_cond_signal (self->mask_cond);
271 self->width = self->height = 0;
272 self->mask_position = 0.0;
273 self->mask_border = 0.0;
276 gst_segment_init (&self->segment, GST_FORMAT_TIME);
280 gst_shape_wipe_video_sink_bufferalloc (GstPad * pad, guint64 offset, guint size,
281 GstCaps * caps, GstBuffer ** buf)
283 GstShapeWipe *self = GST_SHAPE_WIPE (gst_pad_get_parent (pad));
284 GstFlowReturn ret = GST_FLOW_OK;
286 GST_DEBUG_OBJECT (pad, "Allocating buffer with offset 0x%" G_GINT64_MODIFIER
287 "x and size %u with caps: %" GST_PTR_FORMAT, offset, size, caps);
291 ret = gst_pad_alloc_buffer (self->srcpad, offset, size, caps, buf);
293 gst_object_unref (self);
299 gst_shape_wipe_video_sink_setcaps (GstPad * pad, GstCaps * caps)
301 GstShapeWipe *self = GST_SHAPE_WIPE (gst_pad_get_parent (pad));
306 GST_DEBUG_OBJECT (pad, "Setting caps: %" GST_PTR_FORMAT, caps);
308 s = gst_caps_get_structure (caps, 0);
310 if (!gst_structure_get_int (s, "width", &width) ||
311 !gst_structure_get_int (s, "height", &height)) {
316 if (self->width != width || self->height != height) {
317 g_mutex_lock (self->mask_mutex);
319 self->height = height;
322 gst_buffer_unref (self->mask);
324 g_mutex_unlock (self->mask_mutex);
327 ret = gst_pad_set_caps (self->srcpad, caps);
330 gst_object_unref (self);
336 gst_shape_wipe_video_sink_getcaps (GstPad * pad)
338 GstShapeWipe *self = GST_SHAPE_WIPE (gst_pad_get_parent (pad));
341 if (GST_PAD_CAPS (pad))
342 return gst_caps_copy (GST_PAD_CAPS (pad));
344 tmp = gst_pad_peer_get_caps (self->srcpad);
346 ret = gst_caps_intersect (tmp, gst_pad_get_pad_template_caps (pad));
347 gst_caps_unref (tmp);
349 ret = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
352 tmp = gst_pad_peer_get_caps (pad);
354 GstCaps *intersection;
356 intersection = gst_caps_intersect (tmp, ret);
357 gst_caps_unref (tmp);
358 gst_caps_unref (ret);
362 if (self->height && self->width) {
365 n = gst_caps_get_size (ret);
366 for (i = 0; i < n; i++) {
367 GstStructure *s = gst_caps_get_structure (ret, i);
369 gst_structure_set (s, "width", G_TYPE_INT, self->width, "height",
370 G_TYPE_INT, self->height, NULL);
374 tmp = gst_pad_peer_get_caps (self->mask_sinkpad);
376 GstCaps *intersection, *tmp2;
379 tmp = gst_caps_make_writable (tmp);
381 tmp2 = gst_caps_copy (gst_pad_get_pad_template_caps (self->mask_sinkpad));
383 intersection = gst_caps_intersect (tmp, tmp2);
384 gst_caps_unref (tmp);
385 gst_caps_unref (tmp2);
388 n = gst_caps_get_size (tmp);
390 for (i = 0; i < n; i++) {
391 GstStructure *s = gst_caps_get_structure (tmp, i);
393 gst_structure_remove_fields (s, "bpp", "depth", "endianness", "framerate",
395 gst_structure_set_name (s, "video/x-raw-yuv");
398 intersection = gst_caps_intersect (tmp, ret);
399 gst_caps_unref (tmp);
400 gst_caps_unref (ret);
404 gst_object_unref (self);
406 GST_DEBUG_OBJECT (pad, "Returning caps: %" GST_PTR_FORMAT, ret);
412 gst_shape_wipe_mask_sink_setcaps (GstPad * pad, GstCaps * caps)
414 GstShapeWipe *self = GST_SHAPE_WIPE (gst_pad_get_parent (pad));
417 gint width, height, bpp;
419 GST_DEBUG_OBJECT (pad, "Setting caps: %" GST_PTR_FORMAT, caps);
421 s = gst_caps_get_structure (caps, 0);
423 if (!gst_structure_get_int (s, "width", &width) ||
424 !gst_structure_get_int (s, "height", &height) ||
425 !gst_structure_get_int (s, "bpp", &bpp)) {
430 if ((self->width != width || self->height != height) &&
431 self->width > 0 && self->height > 0) {
432 GST_ERROR_OBJECT (pad, "Mask caps must have the same width/height "
433 "as the video caps");
438 self->height = height;
441 self->mask_bpp = bpp;
444 gst_object_unref (self);
450 gst_shape_wipe_mask_sink_getcaps (GstPad * pad)
452 GstShapeWipe *self = GST_SHAPE_WIPE (gst_pad_get_parent (pad));
456 if (GST_PAD_CAPS (pad))
457 return gst_caps_copy (GST_PAD_CAPS (pad));
459 tmp = gst_pad_peer_get_caps (self->video_sinkpad);
462 gst_caps_intersect (tmp,
463 gst_pad_get_pad_template_caps (self->video_sinkpad));
464 gst_caps_unref (tmp);
466 ret = gst_caps_copy (gst_pad_get_pad_template_caps (self->video_sinkpad));
469 tmp = gst_pad_peer_get_caps (self->srcpad);
471 GstCaps *intersection;
473 intersection = gst_caps_intersect (ret, tmp);
474 gst_caps_unref (ret);
475 gst_caps_unref (tmp);
479 n = gst_caps_get_size (ret);
480 tmp = gst_caps_new_empty ();
481 for (i = 0; i < n; i++) {
482 GstStructure *s = gst_caps_get_structure (ret, i);
485 gst_structure_set_name (s, "video/x-raw-gray");
486 gst_structure_remove_fields (s, "format", "framerate", NULL);
488 if (self->width && self->height)
489 gst_structure_set (s, "width", G_TYPE_INT, self->width, "height",
490 G_TYPE_INT, self->height, NULL);
492 gst_structure_set (s, "framerate", GST_TYPE_FRACTION, 0, 1, NULL);
494 t = gst_structure_copy (s);
496 gst_structure_set (s, "bpp", G_TYPE_INT, 16, "depth", G_TYPE_INT, 16,
497 "endianness", G_TYPE_INT, G_BYTE_ORDER, NULL);
498 gst_structure_set (t, "bpp", G_TYPE_INT, 8, "depth", G_TYPE_INT, 8, NULL);
500 gst_caps_append_structure (tmp, t);
502 gst_caps_merge (ret, tmp);
504 tmp = gst_pad_peer_get_caps (pad);
506 GstCaps *intersection;
508 intersection = gst_caps_intersect (tmp, ret);
509 gst_caps_unref (tmp);
510 gst_caps_unref (ret);
514 gst_object_unref (self);
516 GST_DEBUG_OBJECT (pad, "Returning caps: %" GST_PTR_FORMAT, ret);
522 gst_shape_wipe_src_getcaps (GstPad * pad)
524 GstShapeWipe *self = GST_SHAPE_WIPE (gst_pad_get_parent (pad));
527 if (GST_PAD_CAPS (pad))
528 return gst_caps_copy (GST_PAD_CAPS (pad));
529 else if (GST_PAD_CAPS (self->video_sinkpad))
530 return gst_caps_copy (GST_PAD_CAPS (self->video_sinkpad));
532 tmp = gst_pad_peer_get_caps (self->video_sinkpad);
535 gst_caps_intersect (tmp,
536 gst_pad_get_pad_template_caps (self->video_sinkpad));
537 gst_caps_unref (tmp);
539 ret = gst_caps_copy (gst_pad_get_pad_template_caps (self->video_sinkpad));
542 tmp = gst_pad_peer_get_caps (pad);
544 GstCaps *intersection;
546 intersection = gst_caps_intersect (tmp, ret);
547 gst_caps_unref (tmp);
548 gst_caps_unref (ret);
552 if (self->height && self->width) {
555 n = gst_caps_get_size (ret);
556 for (i = 0; i < n; i++) {
557 GstStructure *s = gst_caps_get_structure (ret, i);
559 gst_structure_set (s, "width", G_TYPE_INT, self->width, "height",
560 G_TYPE_INT, self->height, NULL);
564 tmp = gst_pad_peer_get_caps (self->mask_sinkpad);
566 GstCaps *intersection, *tmp2;
569 tmp = gst_caps_make_writable (tmp);
570 tmp2 = gst_caps_copy (gst_pad_get_pad_template_caps (self->mask_sinkpad));
572 intersection = gst_caps_intersect (tmp, tmp2);
573 gst_caps_unref (tmp);
574 gst_caps_unref (tmp2);
577 n = gst_caps_get_size (tmp);
579 for (i = 0; i < n; i++) {
580 GstStructure *s = gst_caps_get_structure (tmp, i);
582 gst_structure_remove_fields (s, "bpp", "depth", "endianness", "framerate",
584 gst_structure_set_name (s, "video/x-raw-yuv");
587 intersection = gst_caps_intersect (tmp, ret);
588 gst_caps_unref (tmp);
589 gst_caps_unref (ret);
593 gst_object_unref (self);
595 GST_DEBUG_OBJECT (pad, "Returning caps: %" GST_PTR_FORMAT, ret);
601 gst_shape_wipe_video_sink_query (GstPad * pad, GstQuery * query)
603 GstShapeWipe *self = GST_SHAPE_WIPE (gst_pad_get_parent (pad));
605 GstPad *peer = gst_pad_get_peer (self->srcpad);
607 GST_DEBUG_OBJECT (pad, "Handling query of type '%s'",
608 gst_query_type_get_name (GST_QUERY_TYPE (query)));
611 GST_INFO_OBJECT (pad, "No peer yet");
614 ret = gst_pad_query (peer, query);
615 gst_object_unref (peer);
618 gst_object_unref (self);
623 gst_shape_wipe_src_query (GstPad * pad, GstQuery * query)
625 GstShapeWipe *self = GST_SHAPE_WIPE (gst_pad_get_parent (pad));
627 GstPad *peer = gst_pad_get_peer (self->video_sinkpad);
629 GST_DEBUG_OBJECT (pad, "Handling query of type '%s'",
630 gst_query_type_get_name (GST_QUERY_TYPE (query)));
633 GST_INFO_OBJECT (pad, "No peer yet");
636 ret = gst_pad_query (peer, query);
637 gst_object_unref (peer);
640 gst_object_unref (self);
645 gst_shape_wipe_blend_16 (GstShapeWipe * self, GstBuffer * inbuf,
646 GstBuffer * maskbuf, GstBuffer * outbuf)
648 const guint16 *mask = (const guint16 *) GST_BUFFER_DATA (maskbuf);
649 const guint8 *input = (const guint8 *) GST_BUFFER_DATA (inbuf);
650 guint8 *output = (guint8 *) GST_BUFFER_DATA (outbuf);
652 guint mask_increment = GST_ROUND_UP_2 (self->width) - self->width;
653 gfloat position = self->mask_position;
654 gfloat low = position - (self->mask_border / 2.0f);
655 gfloat high = position + (self->mask_border / 2.0f);
667 for (i = 0; i < self->height; i++) {
668 for (j = 0; j < self->width; j++) {
669 gfloat in = *mask / 65536.0f;
672 output[0] = 0x00; /* A */
673 output[1] = 0x00; /* Y */
674 output[2] = 0x80; /* U */
675 output[3] = 0x80; /* V */
676 } else if (in >= high) {
677 output[0] = 0xff; /* A */
678 output[1] = input[1]; /* Y */
679 output[2] = input[2]; /* U */
680 output[3] = input[3]; /* V */
682 gfloat val = 255.0f * ((in - low) / (high - low));
684 output[0] = CLAMP (val, 0, 255); /* A */
685 output[1] = input[1]; /* Y */
686 output[2] = input[2]; /* U */
687 output[3] = input[3]; /* V */
694 mask += mask_increment;
701 gst_shape_wipe_blend_8 (GstShapeWipe * self, GstBuffer * inbuf,
702 GstBuffer * maskbuf, GstBuffer * outbuf)
704 const guint8 *mask = (const guint8 *) GST_BUFFER_DATA (maskbuf);
705 const guint8 *input = (const guint8 *) GST_BUFFER_DATA (inbuf);
706 guint8 *output = (guint8 *) GST_BUFFER_DATA (outbuf);
708 guint mask_increment = GST_ROUND_UP_4 (self->width) - self->width;
709 gfloat position = self->mask_position;
710 gfloat low = position - (self->mask_border / 2.0f);
711 gfloat high = position + (self->mask_border / 2.0f);
723 for (i = 0; i < self->height; i++) {
724 for (j = 0; j < self->width; j++) {
725 gfloat in = *mask / 256.0f;
728 output[0] = 0x00; /* A */
729 output[1] = 0x00; /* Y */
730 output[2] = 0x80; /* U */
731 output[3] = 0x80; /* V */
732 } else if (in >= high) {
733 output[0] = 0xff; /* A */
734 output[1] = input[1]; /* Y */
735 output[2] = input[2]; /* U */
736 output[3] = input[3]; /* V */
738 gfloat val = 255.0f * ((in - low) / (high - low));
740 output[0] = CLAMP (val, 0, 255); /* A */
741 output[1] = input[1]; /* Y */
742 output[2] = input[2]; /* U */
743 output[3] = input[3]; /* V */
750 mask += mask_increment;
757 gst_shape_wipe_video_sink_chain (GstPad * pad, GstBuffer * buffer)
759 GstShapeWipe *self = GST_SHAPE_WIPE (GST_PAD_PARENT (pad));
760 GstFlowReturn ret = GST_FLOW_OK;
761 GstBuffer *mask = NULL, *outbuf = NULL;
762 GstClockTime timestamp;
763 gboolean new_outbuf = FALSE;
765 timestamp = GST_BUFFER_TIMESTAMP (buffer);
767 gst_segment_to_stream_time (&self->segment, GST_FORMAT_TIME, timestamp);
769 if (GST_CLOCK_TIME_IS_VALID (timestamp))
770 gst_object_sync_values (G_OBJECT (self), timestamp);
772 GST_DEBUG_OBJECT (self,
773 "Blending buffer with timestamp %" GST_TIME_FORMAT " at position %lf",
774 GST_TIME_ARGS (timestamp), self->mask_position);
776 g_mutex_lock (self->mask_mutex);
778 g_cond_wait (self->mask_cond, self->mask_mutex);
780 if (self->mask == NULL) {
781 g_mutex_unlock (self->mask_mutex);
782 gst_buffer_unref (buffer);
783 return GST_FLOW_UNEXPECTED;
785 mask = gst_buffer_ref (self->mask);
787 g_mutex_unlock (self->mask_mutex);
789 /* Try to blend inplace, if it's not possible
790 * get a new buffer from downstream.
792 if (!gst_buffer_is_writable (buffer)) {
794 gst_pad_alloc_buffer_and_set_caps (self->srcpad, GST_BUFFER_OFFSET_NONE,
795 GST_BUFFER_SIZE (buffer), GST_PAD_CAPS (self->srcpad), &outbuf);
796 if (G_UNLIKELY (ret != GST_FLOW_OK)) {
797 gst_buffer_unref (buffer);
798 gst_buffer_unref (mask);
806 if (self->mask_bpp == 16)
807 ret = gst_shape_wipe_blend_16 (self, buffer, mask, outbuf);
809 ret = gst_shape_wipe_blend_8 (self, buffer, mask, outbuf);
811 gst_buffer_unref (mask);
813 gst_buffer_unref (buffer);
815 if (ret != GST_FLOW_OK) {
816 gst_buffer_unref (outbuf);
820 ret = gst_pad_push (self->srcpad, outbuf);
825 gst_shape_wipe_mask_sink_chain (GstPad * pad, GstBuffer * buffer)
827 GstShapeWipe *self = GST_SHAPE_WIPE (GST_PAD_PARENT (pad));
828 GstFlowReturn ret = GST_FLOW_OK;
830 g_mutex_lock (self->mask_mutex);
831 GST_DEBUG_OBJECT (self, "Setting new mask buffer: %" GST_PTR_FORMAT, buffer);
833 gst_buffer_replace (&self->mask, buffer);
834 g_cond_signal (self->mask_cond);
835 g_mutex_unlock (self->mask_mutex);
837 gst_buffer_unref (buffer);
842 static GstStateChangeReturn
843 gst_shape_wipe_change_state (GstElement * element, GstStateChange transition)
845 GstShapeWipe *self = GST_SHAPE_WIPE (element);
846 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
848 switch (transition) {
849 case GST_STATE_CHANGE_READY_TO_PAUSED:
854 /* Unblock video sink chain function */
855 if (transition == GST_STATE_CHANGE_PAUSED_TO_READY)
856 g_cond_signal (self->mask_cond);
858 if (GST_ELEMENT_CLASS (parent_class)->change_state)
859 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
861 switch (transition) {
862 case GST_STATE_CHANGE_PAUSED_TO_READY:
863 gst_shape_wipe_reset (self);
873 gst_shape_wipe_video_sink_event (GstPad * pad, GstEvent * event)
875 GstShapeWipe *self = GST_SHAPE_WIPE (gst_pad_get_parent (pad));
878 GST_DEBUG_OBJECT (pad, "Got %s event", GST_EVENT_TYPE_NAME (event));
880 switch (GST_EVENT_TYPE (event)) {
881 case GST_EVENT_NEWSEGMENT:{
884 gint64 start, end, base;
887 gst_event_parse_new_segment (event, &is_update, &rate, &fmt, &start,
889 if (fmt == GST_FORMAT_TIME) {
890 GST_DEBUG_OBJECT (pad,
891 "Got NEWSEGMENT event in GST_FORMAT_TIME, passing on (%"
892 GST_TIME_FORMAT " - %" GST_TIME_FORMAT ")", GST_TIME_ARGS (start),
893 GST_TIME_ARGS (end));
894 gst_segment_set_newsegment (&self->segment, is_update, rate, fmt, start,
897 gst_segment_init (&self->segment, GST_FORMAT_TIME);
902 ret = gst_pad_push_event (self->srcpad, event);
906 gst_object_unref (self);
911 gst_shape_wipe_mask_sink_event (GstPad * pad, GstEvent * event)
913 GST_DEBUG_OBJECT (pad, "Got %s event", GST_EVENT_TYPE_NAME (event));
915 /* Dropping all events here */
916 gst_event_unref (event);
921 gst_shape_wipe_src_event (GstPad * pad, GstEvent * event)
923 GstShapeWipe *self = GST_SHAPE_WIPE (gst_pad_get_parent (pad));
926 switch (GST_EVENT_TYPE (event)) {
928 ret = gst_pad_push_event (self->video_sinkpad, event);
932 gst_object_unref (self);
937 plugin_init (GstPlugin * plugin)
939 GST_DEBUG_CATEGORY_INIT (gst_shape_wipe_debug, "shapewipe", 0,
940 "shapewipe element");
942 gst_controller_init (NULL, NULL);
944 if (!gst_element_register (plugin, "shapewipe", GST_RANK_NONE,
945 GST_TYPE_SHAPE_WIPE))
951 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
954 "Shape Wipe transition filter",
955 plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)