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., 51 Franklin St, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
28 * SECTION:element-quarktv
31 * QuarkTV disolves moving objects. It picks up pixels from
32 * the last frames randomly.
34 * ## Example launch line
36 * gst-launch-1.0 -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 parameter */
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);
63 GST_ELEMENT_REGISTER_DEFINE (quarktv, "quarktv", GST_RANK_NONE,
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_info (GstVideoFilter * vfilter, GstCaps * incaps,
84 GstVideoInfo * in_info, GstCaps * outcaps, GstVideoInfo * out_info)
86 GstQuarkTV *filter = GST_QUARKTV (vfilter);
89 width = GST_VIDEO_INFO_WIDTH (in_info);
90 height = GST_VIDEO_INFO_HEIGHT (in_info);
92 gst_quarktv_planetable_clear (filter);
93 filter->area = width * height;
99 gst_quarktv_transform_frame (GstVideoFilter * vfilter, GstVideoFrame * in_frame,
100 GstVideoFrame * out_frame)
102 GstQuarkTV *filter = GST_QUARKTV (vfilter);
105 GstClockTime timestamp;
106 GstBuffer **planetable;
107 gint planes, current_plane;
109 timestamp = GST_BUFFER_TIMESTAMP (in_frame->buffer);
111 gst_segment_to_stream_time (&GST_BASE_TRANSFORM (vfilter)->segment,
112 GST_FORMAT_TIME, timestamp);
114 GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT,
115 GST_TIME_ARGS (timestamp));
117 if (GST_CLOCK_TIME_IS_VALID (timestamp))
118 gst_object_sync_values (GST_OBJECT (filter), timestamp);
120 if (G_UNLIKELY (filter->planetable == NULL))
121 return GST_FLOW_FLUSHING;
123 src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
124 dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
126 GST_OBJECT_LOCK (filter);
128 planetable = filter->planetable;
129 planes = filter->planes;
130 current_plane = filter->current_plane;
132 if (planetable[current_plane])
133 gst_buffer_unref (planetable[current_plane]);
134 planetable[current_plane] = gst_buffer_ref (in_frame->buffer);
140 /* pick a random buffer */
141 rand = planetable[(current_plane + (fastrand () >> 24)) % planes];
143 /* Copy the pixel from the random buffer to dest, FIXME, slow */
145 gst_buffer_extract (rand, area * 4, &dest[area], 4);
147 dest[area] = src[area];
150 filter->current_plane--;
151 if (filter->current_plane < 0)
152 filter->current_plane = planes - 1;
153 GST_OBJECT_UNLOCK (filter);
159 gst_quarktv_planetable_clear (GstQuarkTV * filter)
163 if (filter->planetable == NULL)
166 for (i = 0; i < filter->planes; i++) {
167 if (GST_IS_BUFFER (filter->planetable[i])) {
168 gst_buffer_unref (filter->planetable[i]);
170 filter->planetable[i] = NULL;
175 gst_quarktv_start (GstBaseTransform * trans)
177 GstQuarkTV *filter = GST_QUARKTV (trans);
179 if (filter->planetable) {
180 gst_quarktv_planetable_clear (filter);
181 g_free (filter->planetable);
184 (GstBuffer **) g_malloc0 (filter->planes * sizeof (GstBuffer *));
190 gst_quarktv_finalize (GObject * object)
192 GstQuarkTV *filter = GST_QUARKTV (object);
194 if (filter->planetable) {
195 gst_quarktv_planetable_clear (filter);
196 g_free (filter->planetable);
197 filter->planetable = NULL;
200 G_OBJECT_CLASS (parent_class)->finalize (object);
204 gst_quarktv_set_property (GObject * object, guint prop_id, const GValue * value,
207 GstQuarkTV *filter = GST_QUARKTV (object);
209 GST_OBJECT_LOCK (filter);
213 gint new_n_planes = g_value_get_int (value);
214 GstBuffer **new_planetable;
217 /* If the number of planes changed, copy across any existing planes */
218 if (new_n_planes != filter->planes) {
220 (GstBuffer **) g_malloc0 (new_n_planes * sizeof (GstBuffer *));
222 if (filter->planetable) {
223 for (i = 0; (i < new_n_planes) && (i < filter->planes); i++) {
224 new_planetable[i] = filter->planetable[i];
226 for (; i < filter->planes; i++) {
227 if (filter->planetable[i])
228 gst_buffer_unref (filter->planetable[i]);
230 g_free (filter->planetable);
233 filter->planetable = new_planetable;
234 filter->planes = new_n_planes;
235 filter->current_plane = filter->planes - 1;
240 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
243 GST_OBJECT_UNLOCK (filter);
247 gst_quarktv_get_property (GObject * object, guint prop_id, GValue * value,
250 GstQuarkTV *filter = GST_QUARKTV (object);
254 g_value_set_int (value, filter->planes);
257 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
263 gst_quarktv_class_init (GstQuarkTVClass * klass)
265 GObjectClass *gobject_class = (GObjectClass *) klass;
266 GstElementClass *gstelement_class = (GstElementClass *) klass;
267 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
268 GstVideoFilterClass *vfilter_class = (GstVideoFilterClass *) klass;
270 gobject_class->set_property = gst_quarktv_set_property;
271 gobject_class->get_property = gst_quarktv_get_property;
273 gobject_class->finalize = gst_quarktv_finalize;
275 g_object_class_install_property (gobject_class, PROP_PLANES,
276 g_param_spec_int ("planes", "Planes",
277 "Number of planes", 1, 64, PLANES,
278 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
280 gst_element_class_set_static_metadata (gstelement_class, "QuarkTV effect",
281 "Filter/Effect/Video",
282 "Motion dissolver", "FUKUCHI, Kentarou <fukuchi@users.sourceforge.net>");
284 gst_element_class_add_static_pad_template (gstelement_class,
285 &gst_quarktv_sink_template);
286 gst_element_class_add_static_pad_template (gstelement_class,
287 &gst_quarktv_src_template);
289 trans_class->start = GST_DEBUG_FUNCPTR (gst_quarktv_start);
291 vfilter_class->set_info = GST_DEBUG_FUNCPTR (gst_quarktv_set_info);
292 vfilter_class->transform_frame =
293 GST_DEBUG_FUNCPTR (gst_quarktv_transform_frame);
297 gst_quarktv_init (GstQuarkTV * filter)
299 filter->planes = PLANES;
300 filter->current_plane = filter->planes - 1;