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 g_object_class_install_property (gobject_class
, PROP_SERIAL
,
159 g_param_spec_boolean("serial", "Serial calibration",
160 "Calibrate the projectors one after another, rather than both at once",
161 DEFAULT_PROP_SERIAL
, G_PARAM_READWRITE
));
163 trans_class
->set_caps
= GST_DEBUG_FUNCPTR (gst_sparrow_set_caps
);
164 trans_class
->transform
= GST_DEBUG_FUNCPTR (gst_sparrow_transform
);
165 GST_INFO("gst class init\n");
169 gst_sparrow_init (GstSparrow
* sparrow
, GstSparrowClass
* g_class
)
171 GST_INFO("gst sparrow init\n");
172 /*disallow resizing */
173 gst_pad_use_fixed_caps(GST_BASE_TRANSFORM_SRC_PAD(sparrow
));
177 set_string_prop(const GValue
*value
, const char **target
){
178 const char *s
= g_value_dup_string(value
);
179 size_t len
= strlen(s
);
186 gst_sparrow_set_property (GObject
* object
, guint prop_id
, const GValue
* value
,
191 g_return_if_fail (GST_IS_SPARROW (object
));
192 sparrow
= GST_SPARROW (object
);
194 GST_DEBUG("gst_sparrow_set_property\n");
198 sparrow
->debug
= g_value_get_boolean(value
);
199 GST_DEBUG("debug_value is %d\n", sparrow
->debug
);
202 sparrow
->use_timer
= g_value_get_boolean(value
);
203 GST_DEBUG("timer_value is %d\n", sparrow
->use_timer
);
206 sparrow
->rng_seed
= g_value_get_uint(value
);
207 GST_DEBUG("rng seed is %d\n", sparrow
->rng_seed
);
210 val
= g_value_get_uint(value
);
211 if (val
< SPARROW_LAST_COLOUR
){
212 sparrow
->colour
= val
;
214 GST_DEBUG("colour is %d\n", sparrow
->colour
);
215 if(sparrow
->colour
== SPARROW_GREEN
)
217 else if(sparrow
->colour
== SPARROW_MAGENTA
)
218 GST_DEBUG("magenta!");
220 GST_DEBUG("UNKNOWN COLOUR");
223 set_string_prop(value
, &sparrow
->reload
);
224 GST_DEBUG("reload is %s\n", sparrow
->reload
);
227 set_string_prop(value
, &sparrow
->save
);
228 GST_DEBUG("save is %s\n", sparrow
->save
);
231 sparrow
->serial
= g_value_get_boolean(value
);
232 GST_DEBUG("serial is %d\n", sparrow
->serial
);
235 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
242 gst_sparrow_get_property (GObject
* object
, guint prop_id
, GValue
* value
,
247 g_return_if_fail (GST_IS_SPARROW (object
));
248 sparrow
= GST_SPARROW (object
);
252 g_value_set_boolean(value
, sparrow
->debug
);
255 g_value_set_boolean(value
, sparrow
->use_timer
);
258 g_value_set_uint(value
, sparrow
->rng_seed
);
261 g_value_set_uint(value
, sparrow
->colour
);
264 g_value_set_string(value
, sparrow
->reload
);
267 g_value_set_string(value
, sparrow
->save
);
270 g_value_set_boolean(value
, sparrow
->serial
);
273 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
281 gst_sparrow_set_caps (GstBaseTransform
* base
, GstCaps
* incaps
, GstCaps
* outcaps
)
283 GST_INFO("set_caps\n");
284 GstSparrow
*sparrow
= GST_SPARROW(base
);
286 GST_DEBUG_OBJECT (sparrow
,
287 "set_caps: \nin %" GST_PTR_FORMAT
" \nout %" GST_PTR_FORMAT
, incaps
, outcaps
);
289 /* set_caps gets called after set_property, so it is a good place for hooks
290 that depend on properties and that need to be run before everything
293 return sparrow_init(sparrow
, incaps
, outcaps
);
299 gst_sparrow_transform (GstBaseTransform
* base
, GstBuffer
*inbuf
, GstBuffer
*outbuf
)
301 GstSparrow
*sparrow
= GST_SPARROW(base
);
302 guint insize
= GST_BUFFER_SIZE(inbuf
);
303 guint outsize
= GST_BUFFER_SIZE(outbuf
);
305 if (insize
!= sparrow
->in
.size
|| outsize
!= sparrow
->out
.size
)
308 sparrow_transform(sparrow
, inbuf
, outbuf
);
314 GST_ELEMENT_ERROR (sparrow
, STREAM
, FORMAT
,
315 (NULL
), ("Invalid buffer size(s)\nIN: size %d, expected %d\nOUT: size %d, expected %d",
316 insize
, sparrow
->in
.size
, outsize
, sparrow
->out
.size
));
317 return GST_FLOW_ERROR
;
323 plugin_init (GstPlugin
* plugin
)
325 GST_DEBUG_CATEGORY_INIT (sparrow_debug
, "sparrow", 0, "sparrow");
326 GST_INFO("gst plugin init\n");
328 return gst_element_register (plugin
, "sparrow", GST_RANK_NONE
, GST_TYPE_SPARROW
);
331 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR
,
334 "Add sparrows to video streams",
335 plugin_init
, VERSION
, GST_LICENSE
, GST_PACKAGE_NAME
, GST_PACKAGE_ORIGIN
);