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_caps (GstBaseTransform * btrans, GstCaps * incaps,
84 GstQuarkTV *filter = GST_QUARKTV (btrans);
88 if (!gst_video_info_from_caps (&info, incaps))
93 width = GST_VIDEO_INFO_WIDTH (&info);
94 height = GST_VIDEO_INFO_HEIGHT (&info);
96 gst_quarktv_planetable_clear (filter);
97 filter->area = width * height;
104 GST_DEBUG_OBJECT (filter, "invalid caps received");
110 gst_quarktv_transform (GstBaseTransform * trans, GstBuffer * in,
113 GstQuarkTV *filter = GST_QUARKTV (trans);
116 GstClockTime timestamp;
117 GstBuffer **planetable;
118 gint planes, current_plane;
119 GstVideoFrame in_frame, out_frame;
121 timestamp = GST_BUFFER_TIMESTAMP (in);
123 gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME, timestamp);
125 GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT,
126 GST_TIME_ARGS (timestamp));
128 if (GST_CLOCK_TIME_IS_VALID (timestamp))
129 gst_object_sync_values (GST_OBJECT (filter), timestamp);
131 if (G_UNLIKELY (filter->planetable == NULL))
132 return GST_FLOW_WRONG_STATE;
134 if (!gst_video_frame_map (&in_frame, &filter->info, in, GST_MAP_READ))
137 if (!gst_video_frame_map (&out_frame, &filter->info, out, GST_MAP_WRITE))
140 src = GST_VIDEO_FRAME_PLANE_DATA (&in_frame, 0);
141 dest = GST_VIDEO_FRAME_PLANE_DATA (&out_frame, 0);
143 GST_OBJECT_LOCK (filter);
145 planetable = filter->planetable;
146 planes = filter->planes;
147 current_plane = filter->current_plane;
149 if (planetable[current_plane])
150 gst_buffer_unref (planetable[current_plane]);
151 planetable[current_plane] = gst_buffer_ref (in);
157 /* pick a random buffer */
158 rand = planetable[(current_plane + (fastrand () >> 24)) % planes];
160 /* Copy the pixel from the random buffer to dest, FIXME, slow */
162 gst_buffer_extract (rand, area * 4, &dest[area], 4);
164 dest[area] = src[area];
167 filter->current_plane--;
168 if (filter->current_plane < 0)
169 filter->current_plane = planes - 1;
170 GST_OBJECT_UNLOCK (filter);
172 gst_video_frame_unmap (&in_frame);
173 gst_video_frame_unmap (&out_frame);
180 GST_DEBUG_OBJECT (filter, "invalid input frame");
181 return GST_FLOW_ERROR;
185 GST_DEBUG_OBJECT (filter, "invalid output frame");
186 gst_video_frame_unmap (&in_frame);
187 return GST_FLOW_ERROR;
192 gst_quarktv_planetable_clear (GstQuarkTV * filter)
196 if (filter->planetable == NULL)
199 for (i = 0; i < filter->planes; i++) {
200 if (GST_IS_BUFFER (filter->planetable[i])) {
201 gst_buffer_unref (filter->planetable[i]);
203 filter->planetable[i] = NULL;
208 gst_quarktv_start (GstBaseTransform * trans)
210 GstQuarkTV *filter = GST_QUARKTV (trans);
212 if (filter->planetable) {
213 gst_quarktv_planetable_clear (filter);
214 g_free (filter->planetable);
217 (GstBuffer **) g_malloc0 (filter->planes * sizeof (GstBuffer *));
223 gst_quarktv_finalize (GObject * object)
225 GstQuarkTV *filter = GST_QUARKTV (object);
227 if (filter->planetable) {
228 gst_quarktv_planetable_clear (filter);
229 g_free (filter->planetable);
230 filter->planetable = NULL;
233 G_OBJECT_CLASS (parent_class)->finalize (object);
237 gst_quarktv_set_property (GObject * object, guint prop_id, const GValue * value,
240 GstQuarkTV *filter = GST_QUARKTV (object);
242 GST_OBJECT_LOCK (filter);
246 gint new_n_planes = g_value_get_int (value);
247 GstBuffer **new_planetable;
250 /* If the number of planes changed, copy across any existing planes */
251 if (new_n_planes != filter->planes) {
253 (GstBuffer **) g_malloc0 (new_n_planes * sizeof (GstBuffer *));
255 if (filter->planetable) {
256 for (i = 0; (i < new_n_planes) && (i < filter->planes); i++) {
257 new_planetable[i] = filter->planetable[i];
259 for (; i < filter->planes; i++) {
260 if (filter->planetable[i])
261 gst_buffer_unref (filter->planetable[i]);
263 g_free (filter->planetable);
266 filter->planetable = new_planetable;
267 filter->planes = new_n_planes;
268 filter->current_plane = filter->planes - 1;
273 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
276 GST_OBJECT_UNLOCK (filter);
280 gst_quarktv_get_property (GObject * object, guint prop_id, GValue * value,
283 GstQuarkTV *filter = GST_QUARKTV (object);
287 g_value_set_int (value, filter->planes);
290 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
296 gst_quarktv_class_init (GstQuarkTVClass * klass)
298 GObjectClass *gobject_class = (GObjectClass *) klass;
299 GstElementClass *gstelement_class = (GstElementClass *) klass;
300 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
302 gobject_class->set_property = gst_quarktv_set_property;
303 gobject_class->get_property = gst_quarktv_get_property;
305 gobject_class->finalize = gst_quarktv_finalize;
307 g_object_class_install_property (gobject_class, PROP_PLANES,
308 g_param_spec_int ("planes", "Planes",
309 "Number of planes", 0, 64, PLANES,
310 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
312 gst_element_class_set_details_simple (gstelement_class, "QuarkTV effect",
313 "Filter/Effect/Video",
314 "Motion dissolver", "FUKUCHI, Kentarou <fukuchi@users.sourceforge.net>");
316 gst_element_class_add_pad_template (gstelement_class,
317 gst_static_pad_template_get (&gst_quarktv_sink_template));
318 gst_element_class_add_pad_template (gstelement_class,
319 gst_static_pad_template_get (&gst_quarktv_src_template));
321 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_quarktv_set_caps);
322 trans_class->transform = GST_DEBUG_FUNCPTR (gst_quarktv_transform);
323 trans_class->start = GST_DEBUG_FUNCPTR (gst_quarktv_start);
327 gst_quarktv_init (GstQuarkTV * filter)
329 filter->planes = PLANES;
330 filter->current_plane = filter->planes - 1;
332 gst_pad_use_fixed_caps (GST_BASE_TRANSFORM_SRC_PAD (filter));
333 gst_pad_use_fixed_caps (GST_BASE_TRANSFORM_SINK_PAD (filter));