various clean-ups around new coord_t
[sparrow.git] / gstsparrow.h
blobc61759fffa05b44878e2a0be4ba3d3255b2e00d8
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
32 #define GST_TYPE_SPARROW \
33 (gst_sparrow_get_type())
34 #define GST_SPARROW(obj) \
35 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_SPARROW,GstSparrow))
36 #define GST_SPARROW_CLASS(klass) \
37 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_SPARROW,GstSparrowClass))
38 #define GST_IS_SPARROW(obj) \
39 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_SPARROW))
40 #define GST_IS_SPARROW_CLASS(klass) \
41 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_SPARROW))
43 /*XXX could be run time option */
44 #define USE_FULL_LUT 1
46 #define SPARROW_PPM_DEBUG 1
48 #define TIMER_LOG_FILE "/tmp/timer.log"
50 #include "sparrowconfig.h"
51 #include "dSFMT/dSFMT.h"
52 #include "cv.h"
54 #ifndef UNUSED
55 #define UNUSED __attribute__ ((unused))
56 #else
57 #warning UNUSED is set
58 #endif
60 /* the common recommendation for function visibility is to default to 'hidden'
61 and specifically mark the unhidden ('default') ones, but this might muck
62 with gstreamer macros, some of which declare functions, and most sparrow
63 functions are static anyway, so it is simpler to whitelist visibility.
65 http://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fvisibility-2135
67 (actually, it seems like all functions are invisible or static, except the
68 ones that gstreamer makes in macros).
70 #ifndef INVISIBLE
71 #define INVISIBLE __attribute__ ((visibility("hidden")))
72 #else
73 #warning INVISIBLE is set
74 #endif
77 typedef guint32 pix_t;
78 #define PIXSIZE (sizeof(pix_t))
80 #define SPARROW_N_IPL_IN 3
82 //#define FAKE_OTHER_PROJECTION 1
85 #define LINE_PERIOD 32
86 #define H_LINE_OFFSET (LINE_PERIOD / 2)
87 #define V_LINE_OFFSET (LINE_PERIOD / 2)
90 typedef enum {
91 SPARROW_STATUS_QUO = 0,
92 SPARROW_INIT,
93 SPARROW_FIND_SELF,
94 SPARROW_FIND_SCREEN,
95 SPARROW_FIND_EDGES,
96 SPARROW_PLAY,
99 SPARROW_NEXT_STATE /*magical last state: alias for next in sequence */
100 } sparrow_state;
102 typedef enum {
103 SPARROW_WHITE = 0,
104 SPARROW_GREEN,
105 SPARROW_MAGENTA,
107 SPARROW_LAST_COLOUR
108 } sparrow_colour;
111 typedef struct sparrow_format_s {
112 gint32 width;
113 gint32 height;
114 guint32 pixcount;
115 guint32 size;
117 guint32 rshift;
118 guint32 gshift;
119 guint32 bshift;
120 guint32 rbyte;
121 guint32 gbyte;
122 guint32 bbyte;
123 guint32 rmask;
124 guint32 gmask;
125 guint32 bmask;
126 guint32 colours[3];
127 } sparrow_format;
130 typedef enum sparrow_axis_s {
131 SPARROW_HORIZONTAL,
132 SPARROW_VERTICAL,
133 } sparrow_axis_t;
136 typedef struct sparrow_map_path_s {
137 int dx;
138 int dy;
139 int n;
140 }sparrow_map_path_t;
143 typedef struct sparrow_map_lut_s{
144 guint16 x;
145 guint16 y;
146 } sparrow_map_lut_t;
148 typedef struct sparrow_frame_s {
149 gint32 offset;
150 guint32 jpeg_size;
151 guint8 summary[48];
152 gint32 successors[8];
153 } sparrow_frame_t;
155 typedef struct sparrow_shared_s {
156 guint8 *jpeg_blob;
157 guint32 blob_size;
158 sparrow_frame_t *index;
159 guint32 image_count;
160 } sparrow_shared_t;
163 typedef struct _GstSparrow GstSparrow;
164 typedef struct _GstSparrowClass GstSparrowClass;
167 * GstSparrow:
169 * Opaque data structure.
171 struct _GstSparrow
173 GstVideoFilter videofilter;
174 sparrow_shared_t *shared; /* images, shared between the vaious instances */
175 sparrow_format in;
176 sparrow_format out;
178 /*some calibration modes have big unwieldy structs that attach here */
179 void *helper_struct;
181 /* properties / command line options */
182 gboolean debug;
183 gboolean use_timer;
184 guint32 rng_seed;
186 /* misc */
187 dsfmt_t *dsfmt; /*rng*/
189 /*state */
190 sparrow_state state;
191 gint32 countdown; /*intra-state timing*/
193 guint8 *debug_frame; /* for constructing debug images */
194 GstBuffer *in_buffer;
196 guint32 colour;
197 guint32 frame_count;
199 const char *reload;
200 const char *save;
202 /*debug timer */
203 struct timeval timer_start;
204 struct timeval timer_stop;
205 FILE * timer_log;
207 /*calibration results */
208 guint32 lag;
209 guint8 *screenmask;
210 /*full sized LUT */
211 sparrow_map_lut_t *map_lut;
212 /*for jpeg decompression*/
213 struct jpeg_decompress_struct *cinfo;
217 struct _GstSparrowClass
219 GstVideoFilterClass parent_class;
222 GType gst_sparrow_get_type(void);
225 GST_DEBUG_CATEGORY_EXTERN (sparrow_debug);
226 #define GST_CAT_DEFAULT sparrow_debug
228 /* GstSparrow signals and args */
229 enum
231 /* FILL ME */
232 LAST_SIGNAL
235 enum
237 PROP_0,
238 PROP_DEBUG,
239 PROP_TIMER,
240 PROP_RNG_SEED,
241 PROP_COLOUR,
242 PROP_RELOAD,
243 PROP_SAVE
246 #define DEFAULT_PROP_CALIBRATE TRUE
247 #define DEFAULT_PROP_DEBUG FALSE
248 #define DEFAULT_PROP_TIMER FALSE
249 #define DEFAULT_PROP_RNG_SEED -1
250 #define DEFAULT_PROP_COLOUR SPARROW_GREEN
251 #define DEFAULT_PROP_RELOAD ""
252 #define DEFAULT_PROP_SAVE ""
254 #define QUOTE_(x) #x
255 #define QUOTE(x) QUOTE_(x)
257 /*timing utility code */
258 #define TIME_TRANSFORM 1
260 #define TIMER_START(sparrow) do{ \
261 if (sparrow->timer_log){ \
262 if ((sparrow)->timer_start.tv_sec){ \
263 GST_DEBUG("timer already running!\n"); \
265 else { \
266 gettimeofday(&((sparrow)->timer_start), NULL); \
269 } while (0)
271 static inline void
272 TIMER_STOP(GstSparrow *sparrow)
274 if (sparrow->timer_log){
275 struct timeval *start = &(sparrow->timer_start);
276 struct timeval *stop = &(sparrow->timer_stop);
277 if (start->tv_sec == 0){
278 GST_DEBUG("the timer isn't running!\n");
279 return;
281 gettimeofday(stop, NULL);
282 guint32 t = ((stop->tv_sec - start->tv_sec) * 1000000 +
283 stop->tv_usec - start->tv_usec);
285 #if SPARROW_NOISY_DEBUG
286 GST_DEBUG("took %u microseconds (%0.5f of a frame)\n",
287 t, (double)t * (25.0 / 1000000.0));
288 #endif
290 fprintf(sparrow->timer_log, "%d %6d\n", sparrow->state, t);
291 fflush(sparrow->timer_log);
292 start->tv_sec = 0; /* mark it as unused */
296 /* GST_DISABLE_GST_DEBUG is set in gstreamer compilation. If it is set, we
297 need our own debug channel. */
298 #ifdef GST_DISABLE_GST_DEBUG
300 #undef GST_DEBUG
302 static FILE *_sparrow_bloody_debug_flags = NULL;
303 static void
304 GST_DEBUG(const char *msg, ...){
305 if (! _sparrow_bloody_debug_flags){
306 _sparrow_bloody_debug_flags = fopen("/tmp/sparrow.log", "wb");
307 if (! _sparrow_bloody_debug_flags){
308 exit(1);
311 va_list argp;
312 va_start(argp, msg);
313 vfprintf(_sparrow_bloody_debug_flags, msg, argp);
314 va_end(argp);
315 fflush(_sparrow_bloody_debug_flags);
318 #define GST_ERROR GST_DEBUG
319 #define GST_WARNING GST_DEBUG
320 #define GST_INFO GST_DEBUG
321 #define GST_LOG GST_DEBUG
322 #define GST_FIXME GST_DEBUG
324 #endif
325 #define LOG_LINENO() GST_DEBUG("%-25s line %4d \n", __func__, __LINE__ );
328 G_END_DECLS
329 #endif /* __GST_VIDEO_SPARROW_H__ */