2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2009> Sebastian Dröge <sebastian.droege@collabora.co.uk>
6 * Copyright (C) 2001-2002 FUKUCHI Kentarou
8 * QuarkTV - motion disolver.
10 * EffecTV is free software. This library is free software;
11 * you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the
23 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA.
28 * SECTION:element-quarktv
30 * QuarkTV disolves moving objects. It picks up pixels from
31 * the last frames randomly.
34 * <title>Example launch line</title>
36 * gst-launch -v videotestsrc ! quarktv ! videoconvert ! autovideosink
37 * ]| This pipeline shows the effect of quarktv on a test stream.
49 #include "gsteffectv.h"
51 #include <gst/controller/gstcontroller.h>
53 /* number of frames of time-buffer. It should be as a configurable paramater */
54 /* This number also must be 2^n just for the speed. */
63 #define gst_quarktv_parent_class parent_class
64 G_DEFINE_TYPE (GstQuarkTV, gst_quarktv, GST_TYPE_VIDEO_FILTER);
66 static void gst_quarktv_planetable_clear (GstQuarkTV * filter);
68 static GstStaticPadTemplate gst_quarktv_src_template =
69 GST_STATIC_PAD_TEMPLATE ("src",
72 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ xRGB, xBGR, BGRx, RGBx }"))
75 static GstStaticPadTemplate gst_quarktv_sink_template =
76 GST_STATIC_PAD_TEMPLATE ("sink",
79 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ xRGB, xBGR, BGRx, RGBx }"))
83 gst_quarktv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
86 GstQuarkTV *filter = GST_QUARKTV (btrans);
90 if (!gst_video_info_from_caps (&info, incaps))
95 width = GST_VIDEO_INFO_WIDTH (&info);
96 height = GST_VIDEO_INFO_HEIGHT (&info);
98 gst_quarktv_planetable_clear (filter);
99 filter->area = width * height;
106 GST_DEBUG_OBJECT (filter, "invalid caps received");
112 gst_quarktv_transform (GstBaseTransform * trans, GstBuffer * in,
115 GstQuarkTV *filter = GST_QUARKTV (trans);
116 gint area, width, height, sstride, dstride;
118 GstClockTime timestamp;
119 GstBuffer **planetable;
120 gint planes, current_plane;
121 GstVideoFrame in_frame, out_frame;
123 timestamp = GST_BUFFER_TIMESTAMP (in);
125 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME, timestamp);
127 GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT,
128 GST_TIME_ARGS (timestamp));
130 if (GST_CLOCK_TIME_IS_VALID (timestamp))
131 gst_object_sync_values (G_OBJECT (filter), timestamp);
133 if (G_UNLIKELY (filter->planetable == NULL))
134 return GST_FLOW_WRONG_STATE;
136 if (!gst_video_frame_map (&in_frame, &filter->info, in, GST_MAP_READ))
139 if (!gst_video_frame_map (&out_frame, &filter->info, out, GST_MAP_WRITE))
142 src = GST_VIDEO_FRAME_PLANE_DATA (&in_frame, 0);
143 sstride = GST_VIDEO_FRAME_PLANE_STRIDE (&in_frame, 0);
144 dest = GST_VIDEO_FRAME_PLANE_DATA (&out_frame, 0);
145 dstride = GST_VIDEO_FRAME_PLANE_STRIDE (&out_frame, 0);
147 width = GST_VIDEO_FRAME_WIDTH (&in_frame);
148 height = GST_VIDEO_FRAME_HEIGHT (&in_frame);
150 GST_OBJECT_LOCK (filter);
152 planetable = filter->planetable;
153 planes = filter->planes;
154 current_plane = filter->current_plane;
156 if (planetable[current_plane])
157 gst_buffer_unref (planetable[current_plane]);
158 planetable[current_plane] = gst_buffer_ref (in);
164 /* pick a random buffer */
165 rand = planetable[(current_plane + (fastrand () >> 24)) % planes];
167 /* Copy the pixel from the random buffer to dest, FIXME, slow */
169 gst_buffer_extract (rand, area * 4, &dest[area], 4);
171 dest[area] = src[area];
174 filter->current_plane--;
175 if (filter->current_plane < 0)
176 filter->current_plane = planes - 1;
177 GST_OBJECT_UNLOCK (filter);
179 gst_video_frame_unmap (&in_frame);
180 gst_video_frame_unmap (&out_frame);
187 GST_DEBUG_OBJECT (filter, "invalid input frame");
188 return GST_FLOW_ERROR;
192 GST_DEBUG_OBJECT (filter, "invalid output frame");
193 gst_video_frame_unmap (&in_frame);
194 return GST_FLOW_ERROR;
199 gst_quarktv_planetable_clear (GstQuarkTV * filter)
203 if (filter->planetable == NULL)
206 for (i = 0; i < filter->planes; i++) {
207 if (GST_IS_BUFFER (filter->planetable[i])) {
208 gst_buffer_unref (filter->planetable[i]);
210 filter->planetable[i] = NULL;
215 gst_quarktv_start (GstBaseTransform * trans)
217 GstQuarkTV *filter = GST_QUARKTV (trans);
219 if (filter->planetable) {
220 gst_quarktv_planetable_clear (filter);
221 g_free (filter->planetable);
224 (GstBuffer **) g_malloc0 (filter->planes * sizeof (GstBuffer *));
230 gst_quarktv_finalize (GObject * object)
232 GstQuarkTV *filter = GST_QUARKTV (object);
234 if (filter->planetable) {
235 gst_quarktv_planetable_clear (filter);
236 g_free (filter->planetable);
237 filter->planetable = NULL;
240 G_OBJECT_CLASS (parent_class)->finalize (object);
244 gst_quarktv_set_property (GObject * object, guint prop_id, const GValue * value,
247 GstQuarkTV *filter = GST_QUARKTV (object);
249 GST_OBJECT_LOCK (filter);
253 gint new_n_planes = g_value_get_int (value);
254 GstBuffer **new_planetable;
257 /* If the number of planes changed, copy across any existing planes */
258 if (new_n_planes != filter->planes) {
260 (GstBuffer **) g_malloc0 (new_n_planes * sizeof (GstBuffer *));
262 if (filter->planetable) {
263 for (i = 0; (i < new_n_planes) && (i < filter->planes); i++) {
264 new_planetable[i] = filter->planetable[i];
266 for (; i < filter->planes; i++) {
267 if (filter->planetable[i])
268 gst_buffer_unref (filter->planetable[i]);
270 g_free (filter->planetable);
273 filter->planetable = new_planetable;
274 filter->planes = new_n_planes;
275 filter->current_plane = filter->planes - 1;
280 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
283 GST_OBJECT_UNLOCK (filter);
287 gst_quarktv_get_property (GObject * object, guint prop_id, GValue * value,
290 GstQuarkTV *filter = GST_QUARKTV (object);
294 g_value_set_int (value, filter->planes);
297 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
303 gst_quarktv_class_init (GstQuarkTVClass * klass)
305 GObjectClass *gobject_class = (GObjectClass *) klass;
306 GstElementClass *gstelement_class = (GstElementClass *) klass;
307 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
309 gobject_class->set_property = gst_quarktv_set_property;
310 gobject_class->get_property = gst_quarktv_get_property;
312 gobject_class->finalize = gst_quarktv_finalize;
314 g_object_class_install_property (gobject_class, PROP_PLANES,
315 g_param_spec_int ("planes", "Planes",
316 "Number of planes", 0, 64, PLANES,
317 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
319 gst_element_class_set_details_simple (gstelement_class, "QuarkTV effect",
320 "Filter/Effect/Video",
321 "Motion dissolver", "FUKUCHI, Kentarou <fukuchi@users.sourceforge.net>");
323 gst_element_class_add_pad_template (gstelement_class,
324 gst_static_pad_template_get (&gst_quarktv_sink_template));
325 gst_element_class_add_pad_template (gstelement_class,
326 gst_static_pad_template_get (&gst_quarktv_src_template));
328 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_quarktv_set_caps);
329 trans_class->transform = GST_DEBUG_FUNCPTR (gst_quarktv_transform);
330 trans_class->start = GST_DEBUG_FUNCPTR (gst_quarktv_start);
334 gst_quarktv_init (GstQuarkTV * filter)
336 filter->planes = PLANES;
337 filter->current_plane = filter->planes - 1;
339 gst_pad_use_fixed_caps (GST_BASE_TRANSFORM_SRC_PAD (filter));
340 gst_pad_use_fixed_caps (GST_BASE_TRANSFORM_SINK_PAD (filter));