spring clean and reorder in sparrow struct
[sparrow.git] / gstsparrow.h
blob2ec49686bf38507a38df206ce0e274ef2f3d7c10
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
35 #define TIMER_LOG_FILE "/tmp/timer.log"
37 #include "sparrowconfig.h"
38 #include "dSFMT/dSFMT.h"
39 #include "cv.h"
41 #ifndef UNUSED
42 #define UNUSED __attribute__ ((unused))
43 #else
44 #warning UNUSED is set
45 #endif
47 /* the common recommendation for function visibility is to default to 'hidden'
48 and specifically mark the unhidden ('default') ones, but this might muck
49 with gstreamer macros, some of which declare functions, and most sparrow
50 functions are static anyway, so it is simpler to whitelist visibility.
52 http://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fvisibility-2135
54 (actually, it seems like all functions are invisible or static, except the
55 ones that gstreamer makes in macros).
57 #ifndef INVISIBLE
58 #define INVISIBLE __attribute__ ((visibility("hidden")))
59 #else
60 #warning INVISIBLE is set
61 #endif
64 typedef guint32 pix_t;
65 #define PIXSIZE (sizeof(pix_t))
67 #define SPARROW_N_IPL_IN 3
69 #define FAKE_OTHER_PROJECTION 1
71 #define GST_TYPE_SPARROW \
72 (gst_sparrow_get_type())
73 #define GST_SPARROW(obj) \
74 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_SPARROW,GstSparrow))
75 #define GST_SPARROW_CLASS(klass) \
76 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_SPARROW,GstSparrowClass))
77 #define GST_IS_SPARROW(obj) \
78 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_SPARROW))
79 #define GST_IS_SPARROW_CLASS(klass) \
80 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_SPARROW))
84 typedef enum {
85 SPARROW_STATUS_QUO = 0,
86 SPARROW_INIT,
87 SPARROW_FIND_SELF,
88 SPARROW_FIND_SCREEN,
89 SPARROW_FIND_EDGES,
90 SPARROW_PICK_COLOUR,
91 SPARROW_WAIT_FOR_GRID,
92 SPARROW_FIND_GRID,
93 SPARROW_PLAY,
96 SPARROW_NEXT_STATE /*magical last state: alias for next in sequence */
97 } sparrow_state;
99 typedef enum {
100 SPARROW_WHITE = 0,
101 SPARROW_GREEN,
102 SPARROW_MAGENTA,
103 } sparrow_colour;
106 typedef struct sparrow_format_s {
107 gint32 width;
108 gint32 height;
109 guint32 pixcount;
110 guint32 size;
112 guint32 rshift;
113 guint32 gshift;
114 guint32 bshift;
115 guint32 rmask;
116 guint32 gmask;
117 guint32 bmask;
118 guint32 colours[3];
119 } sparrow_format;
122 typedef enum sparrow_axis_s {
123 SPARROW_VERTICAL,
124 SPARROW_HORIZONTAL,
125 } sparrow_axis_t;
128 /* a mesh of these contains the mapping from input to output.
129 stored in a fixed point notation.
131 #define SPARROW_FIXED_POINT 8
133 typedef struct sparrow_map_point_s {
134 int x;
135 int y;
136 int dx;
137 int dy;
138 }sparrow_map_point_t;
140 typedef struct sparrow_map_row_s {
141 int start;
142 int end;
143 sparrow_map_point_t *points;
144 }sparrow_map_row_t;
146 typedef struct sparrow_map_s {
147 sparrow_map_row_t *rows;
148 void *point_mem;
149 }sparrow_map_t;
151 typedef struct sparrow_map_lut_s{
152 guint16 x;
153 guint16 y;
154 } sparrow_map_lut_t;
157 typedef struct _GstSparrow GstSparrow;
158 typedef struct _GstSparrowClass GstSparrowClass;
161 * GstSparrow:
163 * Opaque data structure.
165 struct _GstSparrow
167 GstVideoFilter videofilter;
169 sparrow_format in;
170 sparrow_format out;
172 /*some calibration modes have big unwieldy structs that attach here */
173 void *helper_struct;
175 /* properties / command line options */
176 gboolean debug;
177 gboolean use_timer;
178 gint calibrate_flag; /*whether to calibrate */
179 guint32 rng_seed;
181 /* misc */
182 dsfmt_t *dsfmt; /*rng*/
184 /*state */
185 sparrow_state state;
187 guint32 lag;
189 gint32 countdown; /*intra-state timing*/
191 /*buffer pointers for previous frames */
192 guint8 *in_frame;
193 guint8 *prev_frame;
194 guint8 *work_frame;
195 guint8 *debug_frame;
197 GstBuffer *in_buffer;
198 GstBuffer *prev_buffer;
199 /*don't need work_buffer */
201 IplImage *in_ipl[SPARROW_N_IPL_IN];
203 guint32 colour;
204 guint32 frame_count;
205 struct timeval timer_start;
206 struct timeval timer_stop;
208 guint8 *screenmask;
210 FILE * timer_log;
212 sparrow_map_t map;
213 /*full sized LUT */
214 sparrow_map_lut_t *map_lut;
218 struct _GstSparrowClass
220 GstVideoFilterClass parent_class;
223 GType gst_sparrow_get_type(void);
226 GST_DEBUG_CATEGORY_EXTERN (sparrow_debug);
227 #define GST_CAT_DEFAULT sparrow_debug
229 /* GstSparrow signals and args */
230 enum
232 /* FILL ME */
233 LAST_SIGNAL
236 enum
238 PROP_0,
239 PROP_CALIBRATE,
240 PROP_DEBUG,
241 PROP_TIMER,
242 PROP_RNG_SEED
245 #define DEFAULT_PROP_CALIBRATE TRUE
246 #define DEFAULT_PROP_DEBUG FALSE
247 #define DEFAULT_PROP_TIMER FALSE
248 #define DEFAULT_PROP_RNG_SEED -1
250 /*timing utility code */
251 #define TIME_TRANSFORM 1
253 #define TIMER_START(sparrow) do{ \
254 if (sparrow->timer_log){ \
255 if ((sparrow)->timer_start.tv_sec){ \
256 GST_DEBUG("timer already running!\n"); \
258 else { \
259 gettimeofday(&((sparrow)->timer_start), NULL); \
262 } while (0)
264 static inline void
265 TIMER_STOP(GstSparrow *sparrow)
267 if (sparrow->timer_log){
268 struct timeval *start = &(sparrow->timer_start);
269 struct timeval *stop = &(sparrow->timer_stop);
270 if (start->tv_sec == 0){
271 GST_DEBUG("the timer isn't running!\n");
272 return;
274 gettimeofday(stop, NULL);
275 guint32 t = ((stop->tv_sec - start->tv_sec) * 1000000 +
276 stop->tv_usec - start->tv_usec);
278 #if SPARROW_NOISY_DEBUG
279 GST_DEBUG("took %u microseconds (%0.5f of a frame)\n",
280 t, (double)t * (25.0 / 1000000.0));
281 #endif
283 fprintf(sparrow->timer_log, "%d %6d\n", sparrow->state, t);
284 fflush(sparrow->timer_log);
285 start->tv_sec = 0; /* mark it as unused */
289 /* GST_DISABLE_GST_DEBUG is set in gstreamer compilation. If it is set, we
290 need our own debug channel. */
291 #ifdef GST_DISABLE_GST_DEBUG
293 #undef GST_DEBUG
295 static FILE *_sparrow_bloody_debug_flags = NULL;
296 static void
297 GST_DEBUG(const char *msg, ...){
298 if (! _sparrow_bloody_debug_flags){
299 _sparrow_bloody_debug_flags = fopen("/tmp/sparrow.log", "wb");
300 if (! _sparrow_bloody_debug_flags){
301 exit(1);
304 va_list argp;
305 va_start(argp, msg);
306 vfprintf(_sparrow_bloody_debug_flags, msg, argp);
307 va_end(argp);
308 fflush(_sparrow_bloody_debug_flags);
311 #define GST_ERROR GST_DEBUG
312 #define GST_WARNING GST_DEBUG
313 #define GST_INFO GST_DEBUG
314 #define GST_LOG GST_DEBUG
315 #define GST_FIXME GST_DEBUG
317 #endif
318 #define LOG_LINENO() GST_DEBUG("%-25s line %4d \n", __func__, __LINE__ );
321 G_END_DECLS
322 #endif /* __GST_VIDEO_SPARROW_H__ */