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 ! ffmpegcolorspace ! autovideosink
37 * ]| This pipeline shows the effect of quarktv on a test stream.
49 #include "gsteffectv.h"
51 #include <gst/controller/gstcontroller.h>
52 #include <gst/video/video.h>
54 /* number of frames of time-buffer. It should be as a configurable paramater */
55 /* This number also must be 2^n just for the speed. */
64 GST_BOILERPLATE (GstQuarkTV, gst_quarktv, GstVideoFilter,
65 GST_TYPE_VIDEO_FILTER);
67 static void gst_quarktv_planetable_clear (GstQuarkTV * filter);
69 static GstStaticPadTemplate gst_quarktv_src_template =
70 GST_STATIC_PAD_TEMPLATE ("src",
73 GST_STATIC_CAPS (GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_xBGR ";"
74 GST_VIDEO_CAPS_BGRx "; " GST_VIDEO_CAPS_RGBx)
77 static GstStaticPadTemplate gst_quarktv_sink_template =
78 GST_STATIC_PAD_TEMPLATE ("sink",
81 GST_STATIC_CAPS (GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_xBGR ";"
82 GST_VIDEO_CAPS_BGRx "; " GST_VIDEO_CAPS_RGBx)
86 gst_quarktv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
89 GstQuarkTV *filter = GST_QUARKTV (btrans);
90 GstStructure *structure;
93 structure = gst_caps_get_structure (incaps, 0);
95 GST_OBJECT_LOCK (filter);
96 if (gst_structure_get_int (structure, "width", &filter->width) &&
97 gst_structure_get_int (structure, "height", &filter->height)) {
98 gst_quarktv_planetable_clear (filter);
99 filter->area = filter->width * filter->height;
102 GST_OBJECT_UNLOCK (filter);
108 gst_quarktv_transform (GstBaseTransform * trans, GstBuffer * in,
111 GstQuarkTV *filter = GST_QUARKTV (trans);
114 GstFlowReturn ret = GST_FLOW_OK;
115 GstClockTime timestamp;
116 GstBuffer **planetable;
117 gint planes, current_plane;
119 timestamp = GST_BUFFER_TIMESTAMP (in);
121 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME, timestamp);
123 GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT,
124 GST_TIME_ARGS (timestamp));
126 if (GST_CLOCK_TIME_IS_VALID (timestamp))
127 gst_object_sync_values (G_OBJECT (filter), timestamp);
129 if (G_UNLIKELY (filter->planetable == NULL))
130 return GST_FLOW_WRONG_STATE;
132 GST_OBJECT_LOCK (filter);
134 src = (guint32 *) GST_BUFFER_DATA (in);
135 dest = (guint32 *) GST_BUFFER_DATA (out);
136 planetable = filter->planetable;
137 planes = filter->planes;
138 current_plane = filter->current_plane;
140 if (planetable[current_plane])
141 gst_buffer_unref (planetable[current_plane]);
142 planetable[current_plane] = gst_buffer_ref (in);
148 /* pick a random buffer */
149 rand = planetable[(current_plane + (fastrand () >> 24)) % planes];
151 /* Copy the pixel from the random buffer to dest */
153 (rand ? ((guint32 *) GST_BUFFER_DATA (rand))[area] : src[area]);
156 filter->current_plane--;
157 if (filter->current_plane < 0)
158 filter->current_plane = planes - 1;
159 GST_OBJECT_UNLOCK (filter);
165 gst_quarktv_planetable_clear (GstQuarkTV * filter)
169 if (filter->planetable == NULL)
172 for (i = 0; i < filter->planes; i++) {
173 if (GST_IS_BUFFER (filter->planetable[i])) {
174 gst_buffer_unref (filter->planetable[i]);
176 filter->planetable[i] = NULL;
181 gst_quarktv_start (GstBaseTransform * trans)
183 GstQuarkTV *filter = GST_QUARKTV (trans);
185 if (filter->planetable) {
186 gst_quarktv_planetable_clear (filter);
187 g_free (filter->planetable);
190 (GstBuffer **) g_malloc0 (filter->planes * sizeof (GstBuffer *));
196 gst_quarktv_finalize (GObject * object)
198 GstQuarkTV *filter = GST_QUARKTV (object);
200 if (filter->planetable) {
201 gst_quarktv_planetable_clear (filter);
202 g_free (filter->planetable);
203 filter->planetable = NULL;
206 G_OBJECT_CLASS (parent_class)->finalize (object);
210 gst_quarktv_set_property (GObject * object, guint prop_id, const GValue * value,
213 GstQuarkTV *filter = GST_QUARKTV (object);
215 GST_OBJECT_LOCK (filter);
219 gint new_n_planes = g_value_get_int (value);
220 GstBuffer **new_planetable;
223 /* If the number of planes changed, copy across any existing planes */
224 if (new_n_planes != filter->planes) {
226 (GstBuffer **) g_malloc0 (new_n_planes * sizeof (GstBuffer *));
228 if (filter->planetable) {
229 for (i = 0; (i < new_n_planes) && (i < filter->planes); i++) {
230 new_planetable[i] = filter->planetable[i];
232 for (; i < filter->planes; i++) {
233 if (filter->planetable[i])
234 gst_buffer_unref (filter->planetable[i]);
236 g_free (filter->planetable);
239 filter->planetable = new_planetable;
240 filter->planes = new_n_planes;
241 filter->current_plane = filter->planes - 1;
246 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
249 GST_OBJECT_UNLOCK (filter);
253 gst_quarktv_get_property (GObject * object, guint prop_id, GValue * value,
256 GstQuarkTV *filter = GST_QUARKTV (object);
260 g_value_set_int (value, filter->planes);
263 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
269 gst_quarktv_base_init (gpointer g_class)
271 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
273 gst_element_class_set_details_simple (element_class, "QuarkTV effect",
274 "Filter/Effect/Video",
275 "Motion dissolver", "FUKUCHI, Kentarou <fukuchi@users.sourceforge.net>");
277 gst_element_class_add_pad_template (element_class,
278 gst_static_pad_template_get (&gst_quarktv_sink_template));
279 gst_element_class_add_pad_template (element_class,
280 gst_static_pad_template_get (&gst_quarktv_src_template));
284 gst_quarktv_class_init (GstQuarkTVClass * klass)
286 GObjectClass *gobject_class = (GObjectClass *) klass;
287 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
289 gobject_class->set_property = gst_quarktv_set_property;
290 gobject_class->get_property = gst_quarktv_get_property;
292 gobject_class->finalize = gst_quarktv_finalize;
294 g_object_class_install_property (gobject_class, PROP_PLANES,
295 g_param_spec_int ("planes", "Planes",
296 "Number of planes", 0, 64, PLANES,
297 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
299 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_quarktv_set_caps);
300 trans_class->transform = GST_DEBUG_FUNCPTR (gst_quarktv_transform);
301 trans_class->start = GST_DEBUG_FUNCPTR (gst_quarktv_start);
305 gst_quarktv_init (GstQuarkTV * filter, GstQuarkTVClass * klass)
307 filter->planes = PLANES;
308 filter->current_plane = filter->planes - 1;
310 gst_pad_use_fixed_caps (GST_BASE_TRANSFORM_SRC_PAD (filter));
311 gst_pad_use_fixed_caps (GST_BASE_TRANSFORM_SINK_PAD (filter));