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 /* number of frames of time-buffer. It should be as a configurable paramater */
52 /* This number also must be 2^n just for the speed. */
61 #define gst_quarktv_parent_class parent_class
62 G_DEFINE_TYPE (GstQuarkTV, gst_quarktv, GST_TYPE_VIDEO_FILTER);
64 static void gst_quarktv_planetable_clear (GstQuarkTV * filter);
66 static GstStaticPadTemplate gst_quarktv_src_template =
67 GST_STATIC_PAD_TEMPLATE ("src",
70 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ xRGB, xBGR, BGRx, RGBx }"))
73 static GstStaticPadTemplate gst_quarktv_sink_template =
74 GST_STATIC_PAD_TEMPLATE ("sink",
77 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ xRGB, xBGR, BGRx, RGBx }"))
81 gst_quarktv_set_info (GstVideoFilter * vfilter, GstCaps * incaps,
82 GstVideoInfo * in_info, GstCaps * outcaps, GstVideoInfo * out_info)
84 GstQuarkTV *filter = GST_QUARKTV (vfilter);
87 width = GST_VIDEO_INFO_WIDTH (in_info);
88 height = GST_VIDEO_INFO_HEIGHT (in_info);
90 gst_quarktv_planetable_clear (filter);
91 filter->area = width * height;
97 gst_quarktv_transform_frame (GstVideoFilter * vfilter, GstVideoFrame * in_frame,
98 GstVideoFrame * out_frame)
100 GstQuarkTV *filter = GST_QUARKTV (vfilter);
103 GstClockTime timestamp;
104 GstBuffer **planetable;
105 gint planes, current_plane;
107 timestamp = GST_BUFFER_TIMESTAMP (in_frame->buffer);
109 gst_segment_to_stream_time (&GST_BASE_TRANSFORM (vfilter)->segment,
110 GST_FORMAT_TIME, timestamp);
112 GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT,
113 GST_TIME_ARGS (timestamp));
115 if (GST_CLOCK_TIME_IS_VALID (timestamp))
116 gst_object_sync_values (GST_OBJECT (filter), timestamp);
118 if (G_UNLIKELY (filter->planetable == NULL))
119 return GST_FLOW_WRONG_STATE;
121 src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
122 dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
124 GST_OBJECT_LOCK (filter);
126 planetable = filter->planetable;
127 planes = filter->planes;
128 current_plane = filter->current_plane;
130 if (planetable[current_plane])
131 gst_buffer_unref (planetable[current_plane]);
132 planetable[current_plane] = gst_buffer_ref (in_frame->buffer);
138 /* pick a random buffer */
139 rand = planetable[(current_plane + (fastrand () >> 24)) % planes];
141 /* Copy the pixel from the random buffer to dest, FIXME, slow */
143 gst_buffer_extract (rand, area * 4, &dest[area], 4);
145 dest[area] = src[area];
148 filter->current_plane--;
149 if (filter->current_plane < 0)
150 filter->current_plane = planes - 1;
151 GST_OBJECT_UNLOCK (filter);
157 gst_quarktv_planetable_clear (GstQuarkTV * filter)
161 if (filter->planetable == NULL)
164 for (i = 0; i < filter->planes; i++) {
165 if (GST_IS_BUFFER (filter->planetable[i])) {
166 gst_buffer_unref (filter->planetable[i]);
168 filter->planetable[i] = NULL;
173 gst_quarktv_start (GstBaseTransform * trans)
175 GstQuarkTV *filter = GST_QUARKTV (trans);
177 if (filter->planetable) {
178 gst_quarktv_planetable_clear (filter);
179 g_free (filter->planetable);
182 (GstBuffer **) g_malloc0 (filter->planes * sizeof (GstBuffer *));
188 gst_quarktv_finalize (GObject * object)
190 GstQuarkTV *filter = GST_QUARKTV (object);
192 if (filter->planetable) {
193 gst_quarktv_planetable_clear (filter);
194 g_free (filter->planetable);
195 filter->planetable = NULL;
198 G_OBJECT_CLASS (parent_class)->finalize (object);
202 gst_quarktv_set_property (GObject * object, guint prop_id, const GValue * value,
205 GstQuarkTV *filter = GST_QUARKTV (object);
207 GST_OBJECT_LOCK (filter);
211 gint new_n_planes = g_value_get_int (value);
212 GstBuffer **new_planetable;
215 /* If the number of planes changed, copy across any existing planes */
216 if (new_n_planes != filter->planes) {
218 (GstBuffer **) g_malloc0 (new_n_planes * sizeof (GstBuffer *));
220 if (filter->planetable) {
221 for (i = 0; (i < new_n_planes) && (i < filter->planes); i++) {
222 new_planetable[i] = filter->planetable[i];
224 for (; i < filter->planes; i++) {
225 if (filter->planetable[i])
226 gst_buffer_unref (filter->planetable[i]);
228 g_free (filter->planetable);
231 filter->planetable = new_planetable;
232 filter->planes = new_n_planes;
233 filter->current_plane = filter->planes - 1;
238 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
241 GST_OBJECT_UNLOCK (filter);
245 gst_quarktv_get_property (GObject * object, guint prop_id, GValue * value,
248 GstQuarkTV *filter = GST_QUARKTV (object);
252 g_value_set_int (value, filter->planes);
255 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
261 gst_quarktv_class_init (GstQuarkTVClass * klass)
263 GObjectClass *gobject_class = (GObjectClass *) klass;
264 GstElementClass *gstelement_class = (GstElementClass *) klass;
265 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
266 GstVideoFilterClass *vfilter_class = (GstVideoFilterClass *) klass;
268 gobject_class->set_property = gst_quarktv_set_property;
269 gobject_class->get_property = gst_quarktv_get_property;
271 gobject_class->finalize = gst_quarktv_finalize;
273 g_object_class_install_property (gobject_class, PROP_PLANES,
274 g_param_spec_int ("planes", "Planes",
275 "Number of planes", 0, 64, PLANES,
276 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
278 gst_element_class_set_details_simple (gstelement_class, "QuarkTV effect",
279 "Filter/Effect/Video",
280 "Motion dissolver", "FUKUCHI, Kentarou <fukuchi@users.sourceforge.net>");
282 gst_element_class_add_pad_template (gstelement_class,
283 gst_static_pad_template_get (&gst_quarktv_sink_template));
284 gst_element_class_add_pad_template (gstelement_class,
285 gst_static_pad_template_get (&gst_quarktv_src_template));
287 trans_class->start = GST_DEBUG_FUNCPTR (gst_quarktv_start);
289 vfilter_class->set_info = GST_DEBUG_FUNCPTR (gst_quarktv_set_info);
290 vfilter_class->transform_frame =
291 GST_DEBUG_FUNCPTR (gst_quarktv_transform_frame);
295 gst_quarktv_init (GstQuarkTV * filter)
297 filter->planes = PLANES;
298 filter->current_plane = filter->planes - 1;