2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2003> David Schleef <ds@schleef.org>
4 * Copyright (C) <2010> Douglas Bagnall <douglas@halo.gen.nz>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
24 * SECTION:element-sparrow
26 * Performs sparrow correction on a video stream.
29 * <title>Example launch line</title>
31 * gst-launch videotestsrc ! ffmpegcolorspace ! sparrow ! ximagesink
37 #include "gstsparrow.h"
38 #include <gst/video/gstvideofilter.h>
39 #include <gst/video/video.h>
40 GST_DEBUG_CATEGORY (sparrow_debug
);
45 /* static_functions */
46 static void gst_sparrow_base_init(gpointer g_class
);
47 static void gst_sparrow_class_init(GstSparrowClass
*g_class
);
48 static void gst_sparrow_init(GstSparrow
*sparrow
, GstSparrowClass
*g_class
);
49 static void gst_sparrow_set_property(GObject
*object
, guint prop_id
, const GValue
*value
, GParamSpec
*pspec
);
50 static void gst_sparrow_get_property(GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
);
51 static gboolean
gst_sparrow_set_caps(GstBaseTransform
*base
, GstCaps
*incaps
, GstCaps
*outcaps
);
52 static GstFlowReturn
gst_sparrow_transform(GstBaseTransform
*base
, GstBuffer
*inbuf
, GstBuffer
*outbuf
);
53 static gboolean
plugin_init(GstPlugin
*plugin
);
56 //#include <sparrow.c>
60 /* the capabilities of the inputs and outputs.
62 * Use RGB, not YUV, because inverting video is trivial in RGB, not so in YUV
64 static GstStaticPadTemplate sink_factory
= GST_STATIC_PAD_TEMPLATE ("sink",
68 GST_VIDEO_CAPS_xBGR
"; " GST_VIDEO_CAPS_xRGB
"; "
69 GST_VIDEO_CAPS_BGRx
"; " GST_VIDEO_CAPS_RGBx
)
72 static GstStaticPadTemplate src_factory
= GST_STATIC_PAD_TEMPLATE ("src",
76 GST_VIDEO_CAPS_xBGR
"; " GST_VIDEO_CAPS_xRGB
"; "
77 GST_VIDEO_CAPS_BGRx
"; " GST_VIDEO_CAPS_RGBx
)
81 GST_BOILERPLATE (GstSparrow
, gst_sparrow
, GstVideoFilter
, GST_TYPE_VIDEO_FILTER
);
83 /* plugin_init - registers plugin (once)
84 XXX_base_init - for the gobject class (once)
85 XXX_class_init - for global state (once)
86 XXX_init - for each plugin instance
90 gst_sparrow_base_init (gpointer g_class
)
92 GstElementClass
*element_class
= GST_ELEMENT_CLASS (g_class
);
94 gst_element_class_set_details_simple (element_class
, "Video sparrow correction",
95 "Filter/Effect/Video",
96 "Adds sparrows to a video stream",
97 "Douglas Bagnall <douglas@halo.gen.nz>");
99 gst_element_class_add_pad_template (element_class
,
100 gst_static_pad_template_get (&sink_factory
));
101 gst_element_class_add_pad_template (element_class
,
102 gst_static_pad_template_get (&src_factory
));
104 GST_INFO("gst base init\n");
110 gst_sparrow_finalize (GObject
* obj
){
111 GST_DEBUG("in gst_sparrow_finalize!\n");
112 GstSparrow
*sparrow
= GST_SPARROW(obj
);
113 sparrow_finalise(sparrow
);
117 gst_sparrow_class_init (GstSparrowClass
* g_class
)
119 GObjectClass
*gobject_class
;
120 GstBaseTransformClass
*trans_class
;
122 gobject_class
= G_OBJECT_CLASS (g_class
);
123 trans_class
= GST_BASE_TRANSFORM_CLASS (g_class
);
125 gobject_class
->set_property
= gst_sparrow_set_property
;
126 gobject_class
->get_property
= gst_sparrow_get_property
;
127 gobject_class
->finalize
= GST_DEBUG_FUNCPTR (gst_sparrow_finalize
);
129 g_object_class_install_property (gobject_class
, PROP_DEBUG
,
130 g_param_spec_boolean ("debug", "Debug", "save PPM files of internal state [off]",
132 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
));
134 g_object_class_install_property (gobject_class
, PROP_TIMER
,
135 g_param_spec_boolean ("timer", "Timer", "Time each transform [off]",
137 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
));
139 g_object_class_install_property (gobject_class
, PROP_RNG_SEED
,
140 g_param_spec_uint ("rngseed", "RNGSeed", "Seed for the random number generator [-1, meaning auto]",
141 0, (guint32
)-1, (guint32
)DEFAULT_PROP_RNG_SEED
,
142 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
));
144 g_object_class_install_property (gobject_class
, PROP_COLOUR
,
145 g_param_spec_uint ("colour", "Colour", "Colour for calibration (" QUOTE(SPARROW_GREEN
)
146 " for green, " QUOTE(SPARROW_MAGENTA
) "for magenta) [" QUOTE(DEFAULT_PROP_COLOUR
) "]",
147 0, SPARROW_LAST_COLOUR
- 1, (guint32
)DEFAULT_PROP_COLOUR
,
148 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
));
150 g_object_class_install_property (gobject_class
, PROP_RELOAD
,
151 g_param_spec_string ("reload", "Reload", "reload calibration from this file, don't calibrate [None]",
152 DEFAULT_PROP_RELOAD
, G_PARAM_READWRITE
));
154 g_object_class_install_property (gobject_class
, PROP_SAVE
,
155 g_param_spec_string ("save", "Save", "save calibration details to this file [None]",
156 DEFAULT_PROP_SAVE
, G_PARAM_READWRITE
));
158 trans_class
->set_caps
= GST_DEBUG_FUNCPTR (gst_sparrow_set_caps
);
159 trans_class
->transform
= GST_DEBUG_FUNCPTR (gst_sparrow_transform
);
160 GST_INFO("gst class init\n");
164 gst_sparrow_init (GstSparrow
* sparrow
, GstSparrowClass
* g_class
)
166 GST_INFO("gst sparrow init\n");
167 /*disallow resizing */
168 gst_pad_use_fixed_caps(GST_BASE_TRANSFORM_SRC_PAD(sparrow
));
172 set_string_prop(const GValue
*value
, const char **target
){
173 const char *s
= g_value_dup_string(value
);
174 size_t len
= strlen(s
);
181 gst_sparrow_set_property (GObject
* object
, guint prop_id
, const GValue
* value
,
186 g_return_if_fail (GST_IS_SPARROW (object
));
187 sparrow
= GST_SPARROW (object
);
189 GST_DEBUG("gst_sparrow_set_property\n");
193 sparrow
->debug
= g_value_get_boolean(value
);
194 GST_DEBUG("debug_value is %d\n", sparrow
->debug
);
197 sparrow
->use_timer
= g_value_get_boolean(value
);
198 GST_DEBUG("timer_value is %d\n", sparrow
->use_timer
);
201 sparrow
->rng_seed
= g_value_get_uint(value
);
202 GST_DEBUG("rng seed is %d\n", sparrow
->rng_seed
);
205 sparrow
->colour
= g_value_get_uint(value
);
206 GST_DEBUG("colour is %d\n", sparrow
->rng_seed
);
209 set_string_prop(value
, &sparrow
->reload
);
210 GST_DEBUG("reload is %s\n", sparrow
->reload
);
213 set_string_prop(value
, &sparrow
->save
);
214 GST_DEBUG("save is %s\n", sparrow
->save
);
217 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
224 gst_sparrow_get_property (GObject
* object
, guint prop_id
, GValue
* value
,
229 g_return_if_fail (GST_IS_SPARROW (object
));
230 sparrow
= GST_SPARROW (object
);
234 g_value_set_boolean(value
, sparrow
->debug
);
237 g_value_set_boolean(value
, sparrow
->use_timer
);
240 g_value_set_uint(value
, sparrow
->rng_seed
);
243 g_value_set_uint(value
, sparrow
->colour
);
246 g_value_set_string(value
, sparrow
->reload
);
249 g_value_set_string(value
, sparrow
->save
);
252 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
260 gst_sparrow_set_caps (GstBaseTransform
* base
, GstCaps
* incaps
, GstCaps
* outcaps
)
262 GST_INFO("set_caps\n");
263 GstSparrow
*sparrow
= GST_SPARROW(base
);
265 GST_DEBUG_OBJECT (sparrow
,
266 "set_caps: \nin %" GST_PTR_FORMAT
" \nout %" GST_PTR_FORMAT
, incaps
, outcaps
);
268 /* set_caps gets called after set_property, so it is a good place for hooks
269 that depend on properties and that need to be run before everything
272 return sparrow_init(sparrow
, incaps
, outcaps
);
278 gst_sparrow_transform (GstBaseTransform
* base
, GstBuffer
* inbuf
,
281 GstSparrow
*sparrow
= GST_SPARROW(base
);
282 guint8
*indata
= GST_BUFFER_DATA(inbuf
);
283 guint8
*outdata
= GST_BUFFER_DATA(outbuf
);
284 guint insize
= GST_BUFFER_SIZE(inbuf
);
285 guint outsize
= GST_BUFFER_SIZE(outbuf
);
287 if (insize
!= sparrow
->in
.size
|| outsize
!= sparrow
->out
.size
)
290 sparrow_transform(sparrow
, indata
, outdata
);
296 GST_ELEMENT_ERROR (sparrow
, STREAM
, FORMAT
,
297 (NULL
), ("Invalid buffer size(s)\nIN: size %d, expected %d\nOUT: size %d, expected %d",
298 insize
, sparrow
->in
.size
, outsize
, sparrow
->out
.size
));
299 return GST_FLOW_ERROR
;
305 plugin_init (GstPlugin
* plugin
)
307 GST_DEBUG_CATEGORY_INIT (sparrow_debug
, "sparrow", 0, "sparrow");
308 GST_INFO("gst plugin init\n");
310 return gst_element_register (plugin
, "sparrow", GST_RANK_NONE
, GST_TYPE_SPARROW
);
313 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR
,
316 "Add sparrows to video streams",
317 plugin_init
, VERSION
, GST_LICENSE
, GST_PACKAGE_NAME
, GST_PACKAGE_ORIGIN
);