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);
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 dest = GST_VIDEO_FRAME_PLANE_DATA (&out_frame, 0);
145 GST_OBJECT_LOCK (filter);
147 planetable = filter->planetable;
148 planes = filter->planes;
149 current_plane = filter->current_plane;
151 if (planetable[current_plane])
152 gst_buffer_unref (planetable[current_plane]);
153 planetable[current_plane] = gst_buffer_ref (in);
159 /* pick a random buffer */
160 rand = planetable[(current_plane + (fastrand () >> 24)) % planes];
162 /* Copy the pixel from the random buffer to dest, FIXME, slow */
164 gst_buffer_extract (rand, area * 4, &dest[area], 4);
166 dest[area] = src[area];
169 filter->current_plane--;
170 if (filter->current_plane < 0)
171 filter->current_plane = planes - 1;
172 GST_OBJECT_UNLOCK (filter);
174 gst_video_frame_unmap (&in_frame);
175 gst_video_frame_unmap (&out_frame);
182 GST_DEBUG_OBJECT (filter, "invalid input frame");
183 return GST_FLOW_ERROR;
187 GST_DEBUG_OBJECT (filter, "invalid output frame");
188 gst_video_frame_unmap (&in_frame);
189 return GST_FLOW_ERROR;
194 gst_quarktv_planetable_clear (GstQuarkTV * filter)
198 if (filter->planetable == NULL)
201 for (i = 0; i < filter->planes; i++) {
202 if (GST_IS_BUFFER (filter->planetable[i])) {
203 gst_buffer_unref (filter->planetable[i]);
205 filter->planetable[i] = NULL;
210 gst_quarktv_start (GstBaseTransform * trans)
212 GstQuarkTV *filter = GST_QUARKTV (trans);
214 if (filter->planetable) {
215 gst_quarktv_planetable_clear (filter);
216 g_free (filter->planetable);
219 (GstBuffer **) g_malloc0 (filter->planes * sizeof (GstBuffer *));
225 gst_quarktv_finalize (GObject * object)
227 GstQuarkTV *filter = GST_QUARKTV (object);
229 if (filter->planetable) {
230 gst_quarktv_planetable_clear (filter);
231 g_free (filter->planetable);
232 filter->planetable = NULL;
235 G_OBJECT_CLASS (parent_class)->finalize (object);
239 gst_quarktv_set_property (GObject * object, guint prop_id, const GValue * value,
242 GstQuarkTV *filter = GST_QUARKTV (object);
244 GST_OBJECT_LOCK (filter);
248 gint new_n_planes = g_value_get_int (value);
249 GstBuffer **new_planetable;
252 /* If the number of planes changed, copy across any existing planes */
253 if (new_n_planes != filter->planes) {
255 (GstBuffer **) g_malloc0 (new_n_planes * sizeof (GstBuffer *));
257 if (filter->planetable) {
258 for (i = 0; (i < new_n_planes) && (i < filter->planes); i++) {
259 new_planetable[i] = filter->planetable[i];
261 for (; i < filter->planes; i++) {
262 if (filter->planetable[i])
263 gst_buffer_unref (filter->planetable[i]);
265 g_free (filter->planetable);
268 filter->planetable = new_planetable;
269 filter->planes = new_n_planes;
270 filter->current_plane = filter->planes - 1;
275 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
278 GST_OBJECT_UNLOCK (filter);
282 gst_quarktv_get_property (GObject * object, guint prop_id, GValue * value,
285 GstQuarkTV *filter = GST_QUARKTV (object);
289 g_value_set_int (value, filter->planes);
292 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
298 gst_quarktv_class_init (GstQuarkTVClass * klass)
300 GObjectClass *gobject_class = (GObjectClass *) klass;
301 GstElementClass *gstelement_class = (GstElementClass *) klass;
302 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
304 gobject_class->set_property = gst_quarktv_set_property;
305 gobject_class->get_property = gst_quarktv_get_property;
307 gobject_class->finalize = gst_quarktv_finalize;
309 g_object_class_install_property (gobject_class, PROP_PLANES,
310 g_param_spec_int ("planes", "Planes",
311 "Number of planes", 0, 64, PLANES,
312 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
314 gst_element_class_set_details_simple (gstelement_class, "QuarkTV effect",
315 "Filter/Effect/Video",
316 "Motion dissolver", "FUKUCHI, Kentarou <fukuchi@users.sourceforge.net>");
318 gst_element_class_add_pad_template (gstelement_class,
319 gst_static_pad_template_get (&gst_quarktv_sink_template));
320 gst_element_class_add_pad_template (gstelement_class,
321 gst_static_pad_template_get (&gst_quarktv_src_template));
323 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_quarktv_set_caps);
324 trans_class->transform = GST_DEBUG_FUNCPTR (gst_quarktv_transform);
325 trans_class->start = GST_DEBUG_FUNCPTR (gst_quarktv_start);
329 gst_quarktv_init (GstQuarkTV * filter)
331 filter->planes = PLANES;
332 filter->current_plane = filter->planes - 1;
334 gst_pad_use_fixed_caps (GST_BASE_TRANSFORM_SRC_PAD (filter));
335 gst_pad_use_fixed_caps (GST_BASE_TRANSFORM_SINK_PAD (filter));