remove unused shapes code
[sparrow.git] / gstsparrow.h
blob8ae590dc57908c24e94ea5464f9b4d2c0b7a50ed
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>
29 #include <sys/time.h>
31 G_BEGIN_DECLS
33 #define SPARROW_PPM_DEBUG 1
36 #include "sparrowconfig.h"
37 #include "dSFMT/dSFMT.h"
38 #include "cv.h"
40 #ifndef UNUSED
41 #define UNUSED __attribute__ ((unused))
42 #else
43 #warning UNUSED is set
44 #endif
46 /* the common recommendation is to default to 'hidden' and specifically mark
47 the unhidden ('default') ones, but this might muck with gstreamer macros,
48 some of which declare functions, and most sparrow functions are static
49 anyway, so it is simpler to whitelist visibility.
51 http://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fvisibility-2135
53 (actually, it seems like all functions are invisible or static, except the
54 ones that gstreamer makes in macros).
56 #ifndef INVISIBLE
57 #define INVISIBLE __attribute__ ((visibility("hidden")))
58 #else
59 #warning INVISIBLE is set
60 #endif
63 typedef guint32 pix_t;
64 #define PIXSIZE (sizeof(pix_t))
67 #define CALIBRATE_ON_MIN_T 2
68 #define CALIBRATE_ON_MAX_T 7
69 #define CALIBRATE_OFF_MIN_T 2
70 #define CALIBRATE_OFF_MAX_T 9
71 #define CALIBRATE_SELF_SIZE 24
73 #define CALIBRATE_MAX_VOTE_ERROR 5
74 #define CALIBRATE_MAX_BEST_ERROR 2
75 #define CALIBRATE_INITIAL_WAIT 72
76 #define CALIBRATE_RETRY_WAIT 16
78 #define CALIBRATE_SIGNAL_THRESHOLD 200
80 #define SPARROW_N_IPL_IN 3
82 #define MAX_CALIBRATE_SHAPES 4
84 #define FAKE_OTHER_PROJECTION 1
86 #define WAIT_COUNTDOWN (MAX(CALIBRATE_OFF_MAX_T, CALIBRATE_ON_MAX_T) + 3)
88 #define GST_TYPE_SPARROW \
89 (gst_sparrow_get_type())
90 #define GST_SPARROW(obj) \
91 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_SPARROW,GstSparrow))
92 #define GST_SPARROW_CLASS(klass) \
93 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_SPARROW,GstSparrowClass))
94 #define GST_IS_SPARROW(obj) \
95 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_SPARROW))
96 #define GST_IS_SPARROW_CLASS(klass) \
97 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_SPARROW))
101 typedef enum {
102 SPARROW_STATUS_QUO = 0,
103 SPARROW_INIT,
104 SPARROW_FIND_SELF,
105 SPARROW_FIND_SCREEN,
106 SPARROW_FIND_EDGES,
107 SPARROW_PICK_COLOUR,
108 SPARROW_WAIT_FOR_GRID,
109 SPARROW_FIND_GRID,
110 SPARROW_PLAY,
113 SPARROW_NEXT_STATE /*magical last state: alias for next in sequence */
114 } sparrow_state;
116 typedef enum {
117 SPARROW_WHITE = 0,
118 SPARROW_GREEN,
119 SPARROW_MAGENTA
120 } sparrow_colour;
122 #define MAX_CALIBRATION_LAG 12
123 typedef struct lag_times_s {
124 //guint32 hits;
125 guint64 record;
126 } lag_times_t;
128 typedef struct sparrow_format_s {
129 gint32 width;
130 gint32 height;
131 guint32 pixcount;
132 guint32 size;
134 guint32 rshift;
135 guint32 gshift;
136 guint32 bshift;
137 guint32 rmask;
138 guint32 gmask;
139 guint32 bmask;
140 guint32 colours[3];
141 } sparrow_format;
143 enum calibration_shape {
144 NO_SHAPE = 0,
145 VERTICAL_LINE,
146 HORIZONTAL_LINE,
147 FULLSCREEN,
148 RECTANGLE,
151 typedef struct sparrow_shape_s {
152 /*Calibration shape definition -- a rectangle.*/
153 enum calibration_shape shape;
154 gint x;
155 gint y;
156 gint w;
157 gint h;
158 } sparrow_shape_t;
160 typedef struct sparrow_calibrate_s {
161 /*calibration state, and shape and pattern definition */
162 gboolean on; /*for calibration pattern */
163 gint wait;
164 guint32 transitions;
165 guint32 incolour;
166 guint32 outcolour;
167 } sparrow_calibrate_t;
169 typedef struct sparrow_find_screen_s {
170 IplImage *green;
171 IplImage *working;
172 IplImage *mask;
173 } sparrow_find_screen_t;
176 typedef struct _GstSparrow GstSparrow;
177 typedef struct _GstSparrowClass GstSparrowClass;
180 * GstSparrow:
182 * Opaque data structure.
184 struct _GstSparrow
186 GstVideoFilter videofilter;
188 sparrow_format in;
189 sparrow_format out;
190 sparrow_shape_t shapes[MAX_CALIBRATE_SHAPES];
191 int n_shapes;
193 sparrow_calibrate_t calibrate;
195 /* properties */
196 gint calibrate_flag; /*whether to calibrate */
198 /* misc */
199 dsfmt_t *dsfmt; /*rng*/
201 /*state */
202 sparrow_state state;
204 lag_times_t *lag_table;
205 guint64 lag_record;
206 guint32 lag;
208 gint32 countdown; /*intra-state timing*/
210 /*buffer pointers for previous frames */
211 guint8 *in_frame;
212 guint8 *prev_frame;
213 guint8 *work_frame;
214 guint8 *debug_frame;
216 GstBuffer *in_buffer;
217 GstBuffer *prev_buffer;
218 /*don't need work_buffer */
220 IplImage *in_ipl[SPARROW_N_IPL_IN];
222 gboolean debug;
224 guint32 rng_seed;
226 guint32 frame_count;
227 struct timeval timer_start;
228 struct timeval timer_stop;
229 sparrow_find_screen_t findscreen;
231 guint8 *screenmask;
232 IplImage *screenmask_ipl;
235 struct _GstSparrowClass
237 GstVideoFilterClass parent_class;
240 GType gst_sparrow_get_type(void);
243 GST_DEBUG_CATEGORY_EXTERN (sparrow_debug);
244 #define GST_CAT_DEFAULT sparrow_debug
246 /* GstSparrow signals and args */
247 enum
249 /* FILL ME */
250 LAST_SIGNAL
253 enum
255 PROP_0,
256 PROP_CALIBRATE,
257 PROP_DEBUG,
258 PROP_RNG_SEED
261 #define DEFAULT_PROP_CALIBRATE TRUE
262 #define DEFAULT_PROP_DEBUG FALSE
263 #define DEFAULT_PROP_RNG_SEED -1
265 /*timing utility code */
267 #define TIMER_START(sparrow) (((sparrow)->timer_start.time_t) ? \
268 (GST_DEBUG("timer already running!\n")) : \
269 (gettimeofday(&((sparrow)->tv1), NULL))
271 static inline void
272 TIMER_STOP(GstSparrow *sparrow)
274 struct timeval *start = &(sparrow->timer_start);
275 struct timeval *stop = &(sparrow->timer_stop);
276 if (start->tv_sec == 0){
277 GST_DEBUG("the timer isn't running!\n");
278 return;
280 gettimeofday(stop, NULL);
281 guint32 t = ((stop->tv_sec - start->tv_sec) * 1000000 +
282 stop->tv_usec - start->tv_usec);
283 GST_DEBUG("took %u microseconds (%0.5f of a frame)\n",
284 t, (double)t * (25.0 / 1000000.0));
285 start->tv_sec = 0; /* mark it as unused */
288 /* GST_DISABLE_GST_DEBUG is set in gstreamer compilation. If it is set, we
289 need our own debug channel. */
290 #ifdef GST_DISABLE_GST_DEBUG
292 #undef GST_DEBUG
294 static FILE *_sparrow_bloody_debug_flags = NULL;
295 static void
296 GST_DEBUG(const char *msg, ...){
297 if (! _sparrow_bloody_debug_flags){
298 _sparrow_bloody_debug_flags = fopen("/tmp/sparrow.log", "wb");
299 if (! _sparrow_bloody_debug_flags){
300 exit(1);
303 va_list argp;
304 va_start(argp, msg);
305 vfprintf(_sparrow_bloody_debug_flags, msg, argp);
306 va_end(argp);
307 fflush(_sparrow_bloody_debug_flags);
310 #define GST_ERROR GST_DEBUG
311 #define GST_WARNING GST_DEBUG
312 #define GST_INFO GST_DEBUG
313 #define GST_LOG GST_DEBUG
314 #define GST_FIXME GST_DEBUG
316 #endif
317 #define LOG_LINENO() GST_DEBUG("%-25s line %4d \n", __func__, __LINE__ );
320 G_END_DECLS
321 #endif /* __GST_VIDEO_SPARROW_H__ */