• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * Copyright (C) <2009> Sebastian Dröge <sebastian.droege@collabora.co.uk>
3  *
4  * EffecTV - Realtime Digital Video Effector
5  * Copyright (C) 2001-2006 FUKUCHI Kentaro
6  *
7  * StreakTV - afterimage effector.
8  * Copyright (C) 2001-2002 FUKUCHI Kentaro
9  *
10  * This combines the StreakTV and BaltanTV effects, which are
11  * very similar. BaltanTV is used if the feedback property is set
12  * to TRUE, otherwise StreakTV is used.
13  *
14  * EffecTV is free software. This library is free software;
15  * you can redistribute it and/or
16  * modify it under the terms of the GNU Library General Public
17  * License as published by the Free Software Foundation; either
18  * version 2 of the License, or (at your option) any later version.
19  *
20  * This library is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23  * Library General Public License for more details.
24  *
25  * You should have received a copy of the GNU Library General Public
26  * License along with this library; if not, write to the
27  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
28  * Boston, MA 02110-1301, USA.
29  */
30 
31 /**
32  * SECTION:element-streaktv
33  * @title: streaktv
34  *
35  * StreakTV makes after images of moving objects.
36  *
37  * ## Example launch line
38  * |[
39  * gst-launch-1.0 -v videotestsrc ! streaktv ! videoconvert ! autovideosink
40  * ]| This pipeline shows the effect of streaktv on a test stream.
41  *
42  */
43 
44 #ifdef HAVE_CONFIG_H
45 #include "config.h"
46 #endif
47 
48 #include <math.h>
49 #include <string.h>
50 
51 #include "gststreak.h"
52 #include "gsteffectv.h"
53 
54 #define DEFAULT_FEEDBACK FALSE
55 
56 enum
57 {
58   PROP_0,
59   PROP_FEEDBACK
60 };
61 
62 #define gst_streaktv_parent_class parent_class
63 G_DEFINE_TYPE (GstStreakTV, gst_streaktv, GST_TYPE_VIDEO_FILTER);
64 GST_ELEMENT_REGISTER_DEFINE (streaktv, "streaktv", GST_RANK_NONE,
65     GST_TYPE_STREAKTV);
66 
67 static GstStaticPadTemplate gst_streaktv_src_template =
68 GST_STATIC_PAD_TEMPLATE ("src",
69     GST_PAD_SRC,
70     GST_PAD_ALWAYS,
71     GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ BGRx, RGBx, xBGR, xRGB }"))
72     );
73 
74 static GstStaticPadTemplate gst_streaktv_sink_template =
75 GST_STATIC_PAD_TEMPLATE ("sink",
76     GST_PAD_SINK,
77     GST_PAD_ALWAYS,
78     GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ BGRx, RGBx, xBGR, xRGB }"))
79     );
80 
81 
82 static GstFlowReturn
gst_streaktv_transform_frame(GstVideoFilter * vfilter,GstVideoFrame * in_frame,GstVideoFrame * out_frame)83 gst_streaktv_transform_frame (GstVideoFilter * vfilter,
84     GstVideoFrame * in_frame, GstVideoFrame * out_frame)
85 {
86   GstStreakTV *filter = GST_STREAKTV (vfilter);
87   guint32 *src, *dest;
88   gint i, cf;
89   gint video_area, width, height;
90   guint32 **planetable = filter->planetable;
91   gint plane = filter->plane;
92   guint stride_mask, stride_shift, stride;
93 
94   src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
95   dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
96 
97   width = GST_VIDEO_FRAME_WIDTH (in_frame);
98   height = GST_VIDEO_FRAME_HEIGHT (in_frame);
99 
100   video_area = width * height;
101 
102   GST_OBJECT_LOCK (filter);
103   if (filter->feedback) {
104     stride_mask = 0xfcfcfcfc;
105     stride = 8;
106     stride_shift = 2;
107   } else {
108     stride_mask = 0xf8f8f8f8;
109     stride = 4;
110     stride_shift = 3;
111   }
112 
113   for (i = 0; i < video_area; i++) {
114     planetable[plane][i] = (src[i] & stride_mask) >> stride_shift;
115   }
116 
117   cf = plane & (stride - 1);
118   if (filter->feedback) {
119     for (i = 0; i < video_area; i++) {
120       dest[i] = planetable[cf][i]
121           + planetable[cf + stride][i]
122           + planetable[cf + stride * 2][i]
123           + planetable[cf + stride * 3][i];
124       planetable[plane][i] = (dest[i] & stride_mask) >> stride_shift;
125     }
126   } else {
127     for (i = 0; i < video_area; i++) {
128       dest[i] = planetable[cf][i]
129           + planetable[cf + stride][i]
130           + planetable[cf + stride * 2][i]
131           + planetable[cf + stride * 3][i]
132           + planetable[cf + stride * 4][i]
133           + planetable[cf + stride * 5][i]
134           + planetable[cf + stride * 6][i]
135           + planetable[cf + stride * 7][i];
136     }
137   }
138 
139   plane++;
140   filter->plane = plane & (PLANES - 1);
141   GST_OBJECT_UNLOCK (filter);
142 
143   return GST_FLOW_OK;
144 }
145 
146 static gboolean
gst_streaktv_set_info(GstVideoFilter * vfilter,GstCaps * incaps,GstVideoInfo * in_info,GstCaps * outcaps,GstVideoInfo * out_info)147 gst_streaktv_set_info (GstVideoFilter * vfilter, GstCaps * incaps,
148     GstVideoInfo * in_info, GstCaps * outcaps, GstVideoInfo * out_info)
149 {
150   GstStreakTV *filter = GST_STREAKTV (vfilter);
151   gint i, width, height;
152 
153   width = GST_VIDEO_INFO_WIDTH (in_info);
154   height = GST_VIDEO_INFO_HEIGHT (in_info);
155 
156   g_free (filter->planebuffer);
157 
158   filter->planebuffer = g_new0 (guint32, width * height * 4 * PLANES);
159 
160   for (i = 0; i < PLANES; i++)
161     filter->planetable[i] = &filter->planebuffer[width * height * i];
162 
163   return TRUE;
164 }
165 
166 static gboolean
gst_streaktv_start(GstBaseTransform * trans)167 gst_streaktv_start (GstBaseTransform * trans)
168 {
169   GstStreakTV *filter = GST_STREAKTV (trans);
170 
171   filter->plane = 0;
172 
173   return TRUE;
174 }
175 
176 static void
gst_streaktv_finalize(GObject * object)177 gst_streaktv_finalize (GObject * object)
178 {
179   GstStreakTV *filter = GST_STREAKTV (object);
180 
181   if (filter->planebuffer) {
182     g_free (filter->planebuffer);
183     filter->planebuffer = NULL;
184   }
185 
186   G_OBJECT_CLASS (parent_class)->finalize (object);
187 }
188 
189 static void
gst_streaktv_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)190 gst_streaktv_set_property (GObject * object, guint prop_id,
191     const GValue * value, GParamSpec * pspec)
192 {
193   GstStreakTV *filter = GST_STREAKTV (object);
194 
195   switch (prop_id) {
196     case PROP_FEEDBACK:
197       if (G_UNLIKELY (GST_STATE (filter) >= GST_STATE_PAUSED)) {
198         g_warning ("Changing the \"feedback\" property only allowed "
199             "in state < PLAYING");
200         return;
201       }
202 
203       filter->feedback = g_value_get_boolean (value);
204       break;
205     default:
206       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
207       break;
208   }
209 }
210 
211 static void
gst_streaktv_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)212 gst_streaktv_get_property (GObject * object, guint prop_id, GValue * value,
213     GParamSpec * pspec)
214 {
215   GstStreakTV *filter = GST_STREAKTV (object);
216 
217   switch (prop_id) {
218     case PROP_FEEDBACK:
219       g_value_set_boolean (value, filter->feedback);
220       break;
221     default:
222       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
223       break;
224   }
225 }
226 
227 static void
gst_streaktv_class_init(GstStreakTVClass * klass)228 gst_streaktv_class_init (GstStreakTVClass * klass)
229 {
230   GObjectClass *gobject_class = (GObjectClass *) klass;
231   GstElementClass *gstelement_class = (GstElementClass *) klass;
232   GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
233   GstVideoFilterClass *vfilter_class = (GstVideoFilterClass *) klass;
234 
235   gobject_class->set_property = gst_streaktv_set_property;
236   gobject_class->get_property = gst_streaktv_get_property;
237 
238   gobject_class->finalize = gst_streaktv_finalize;
239 
240   g_object_class_install_property (gobject_class, PROP_FEEDBACK,
241       g_param_spec_boolean ("feedback", "Feedback",
242           "Feedback", DEFAULT_FEEDBACK,
243           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
244 
245   gst_element_class_set_static_metadata (gstelement_class, "StreakTV effect",
246       "Filter/Effect/Video",
247       "StreakTV makes after images of moving objects",
248       "FUKUCHI, Kentarou <fukuchi@users.sourceforge.net>, "
249       "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
250 
251   gst_element_class_add_static_pad_template (gstelement_class,
252       &gst_streaktv_sink_template);
253   gst_element_class_add_static_pad_template (gstelement_class,
254       &gst_streaktv_src_template);
255 
256   trans_class->start = GST_DEBUG_FUNCPTR (gst_streaktv_start);
257 
258   vfilter_class->set_info = GST_DEBUG_FUNCPTR (gst_streaktv_set_info);
259   vfilter_class->transform_frame =
260       GST_DEBUG_FUNCPTR (gst_streaktv_transform_frame);
261 }
262 
263 static void
gst_streaktv_init(GstStreakTV * filter)264 gst_streaktv_init (GstStreakTV * filter)
265 {
266   filter->feedback = DEFAULT_FEEDBACK;
267 }
268