add dummy init/mode functions, and fix silly error
[sparrow.git] / gstsparrow.h
blob04b6ca5d2a77dc16d391cb0a6d3d39030f6d7ab6
1 /* GStreamer
2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2003> David Schleef <ds@schleef.org>
4 * Copyright (C) <2003> Arwed v. Merkatz <v.merkatz@gmx.net>
5 * Copyright (C) <2006> Mark Nauwelaerts <manauw@skynet.be>
6 * Copyright (C) <2010> Douglas Bagnall <douglas@halo.gen.nz>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 #ifndef __GST_VIDEO_SPARROW_H__
26 #define __GST_VIDEO_SPARROW_H__
28 #include <gst/video/gstvideofilter.h>
30 G_BEGIN_DECLS
32 #define SPARROW_PPM_DEBUG 1
35 #include "sparrowconfig.h"
36 #include "dSFMT/dSFMT.h"
37 #include "cv.h"
39 #ifndef UNUSED
40 #define UNUSED __attribute__ ((unused))
41 #else
42 #warning UNUSED is set
43 #endif
45 /* the common recommendation is to default to 'hidden' and specifically mark
46 the unhidden ('default') ones, but this might muck with gstreamer macros,
47 some of which declare functions, and most sparrow functions are static
48 anyway, so it is simpler to whitelist visibility.
50 http://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fvisibility-2135
52 (actually, it seems like all functions are invisible or static, except the
53 ones that gstreamer makes in macros).
55 #ifndef INVISIBLE
56 #define INVISIBLE __attribute__ ((visibility("hidden")))
57 #else
58 #warning INVISIBLE is set
59 #endif
62 typedef guint32 pix_t;
63 #define PIXSIZE (sizeof(pix_t))
66 #define CALIBRATE_ON_MIN_T 2
67 #define CALIBRATE_ON_MAX_T 7
68 #define CALIBRATE_OFF_MIN_T 2
69 #define CALIBRATE_OFF_MAX_T 9
70 #define CALIBRATE_SELF_SIZE 24
72 #define CALIBRATE_MAX_VOTE_ERROR 5
73 #define CALIBRATE_MAX_BEST_ERROR 2
74 #define CALIBRATE_INITIAL_WAIT 72
75 #define CALIBRATE_RETRY_WAIT 16
77 #define CALIBRATE_SIGNAL_THRESHOLD 200
80 #define MAX_CALIBRATE_SHAPES 4
82 #define FAKE_OTHER_PROJECTION 1
84 #define WAIT_COUNTDOWN (MAX(CALIBRATE_OFF_MAX_T, CALIBRATE_ON_MAX_T) + 3)
86 #define GST_TYPE_SPARROW \
87 (gst_sparrow_get_type())
88 #define GST_SPARROW(obj) \
89 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_SPARROW,GstSparrow))
90 #define GST_SPARROW_CLASS(klass) \
91 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_SPARROW,GstSparrowClass))
92 #define GST_IS_SPARROW(obj) \
93 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_SPARROW))
94 #define GST_IS_SPARROW_CLASS(klass) \
95 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_SPARROW))
99 typedef enum {
100 SPARROW_STATUS_QUO = 0,
101 SPARROW_INIT,
102 SPARROW_FIND_SELF,
103 SPARROW_FIND_SCREEN,
104 SPARROW_FIND_EDGES,
105 SPARROW_PICK_COLOUR,
106 SPARROW_WAIT_FOR_GRID,
107 SPARROW_FIND_GRID,
108 SPARROW_PLAY,
111 SPARROW_NEXT_STATE /*magical last state: alias for next in sequence */
112 } sparrow_state;
114 typedef enum {
115 SPARROW_WHITE = 0,
116 SPARROW_GREEN,
117 SPARROW_MAGENTA
118 } sparrow_colour;
120 #define MAX_CALIBRATION_LAG 12
121 typedef struct lag_times_s {
122 //guint32 hits;
123 guint64 record;
124 } lag_times_t;
126 typedef struct sparrow_format_s {
127 gint32 width;
128 gint32 height;
129 guint32 pixcount;
130 guint32 size;
132 guint32 rshift;
133 guint32 gshift;
134 guint32 bshift;
135 guint32 rmask;
136 guint32 gmask;
137 guint32 bmask;
138 guint32 colours[3];
139 } sparrow_format;
141 enum calibration_shape {
142 NO_SHAPE = 0,
143 VERTICAL_LINE,
144 HORIZONTAL_LINE,
145 FULLSCREEN,
146 RECTANGLE,
149 typedef struct sparrow_shape_s {
150 /*Calibration shape definition -- a rectangle or line.
151 For lines, only one dimension is used.*/
152 enum calibration_shape shape;
153 gint x;
154 gint y;
155 gint w;
156 gint h;
157 } sparrow_shape_t;
159 typedef struct sparrow_calibrate_s {
160 /*calibration state, and shape and pattern definition */
161 gboolean on; /*for calibration pattern */
162 gint wait;
163 guint32 transitions;
164 guint32 incolour;
165 guint32 outcolour;
166 } sparrow_calibrate_t;
169 typedef struct _GstSparrow GstSparrow;
170 typedef struct _GstSparrowClass GstSparrowClass;
173 * GstSparrow:
175 * Opaque data structure.
177 struct _GstSparrow
179 GstVideoFilter videofilter;
181 sparrow_format in;
182 sparrow_format out;
183 sparrow_shape_t shapes[MAX_CALIBRATE_SHAPES];
184 int n_shapes;
186 sparrow_calibrate_t calibrate;
188 /* properties */
189 gint calibrate_flag; /*whether to calibrate */
191 /* misc */
192 dsfmt_t *dsfmt; /*rng*/
194 /*state */
195 sparrow_state state;
197 lag_times_t *lag_table;
198 guint64 lag_record;
199 guint32 lag;
201 gint32 countdown; /*intra-state timing*/
203 /*buffer pointers for previous frames */
204 guint8 *in_frame;
205 guint8 *prev_frame;
206 guint8 *work_frame;
207 guint8 *debug_frame;
209 GstBuffer *in_buffer;
210 GstBuffer *prev_buffer;
211 /*don't need work_buffer */
213 IplImage *in_ipl[3];
215 gboolean debug;
217 guint32 rng_seed;
219 guint32 frame_count;
222 struct _GstSparrowClass
224 GstVideoFilterClass parent_class;
227 GType gst_sparrow_get_type(void);
230 GST_DEBUG_CATEGORY_EXTERN (sparrow_debug);
231 #define GST_CAT_DEFAULT sparrow_debug
233 /* GstSparrow signals and args */
234 enum
236 /* FILL ME */
237 LAST_SIGNAL
240 enum
242 PROP_0,
243 PROP_CALIBRATE,
244 PROP_DEBUG,
245 PROP_RNG_SEED
248 #define DEFAULT_PROP_CALIBRATE TRUE
249 #define DEFAULT_PROP_DEBUG FALSE
250 #define DEFAULT_PROP_RNG_SEED -1
256 /* GST_DISABLE_GST_DEBUG is set in gstreamer compilation. If it is set, we
257 need our own debug channel. */
258 #ifdef GST_DISABLE_GST_DEBUG
260 #undef GST_DEBUG
262 static FILE *_sparrow_bloody_debug_flags = NULL;
263 static void
264 GST_DEBUG(const char *msg, ...){
265 if (! _sparrow_bloody_debug_flags){
266 _sparrow_bloody_debug_flags = fopen("/tmp/sparrow.log", "wb");
267 if (! _sparrow_bloody_debug_flags){
268 exit(1);
271 va_list argp;
272 va_start(argp, msg);
273 vfprintf(_sparrow_bloody_debug_flags, msg, argp);
274 va_end(argp);
275 fflush(_sparrow_bloody_debug_flags);
278 #define GST_ERROR GST_DEBUG
279 #define GST_WARNING GST_DEBUG
280 #define GST_INFO GST_DEBUG
281 #define GST_LOG GST_DEBUG
282 #define GST_FIXME GST_DEBUG
284 #endif
285 #define LOG_LINENO() GST_DEBUG("%-25s line %4d \n", __func__, __LINE__ );
288 G_END_DECLS
289 #endif /* __GST_VIDEO_SPARROW_H__ */