don't save every play frame by default
[sparrow.git] / gstsparrow.h
blobe795d7a169640a98014d94f18b130d11a596258f
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 16
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 rmask;
121 guint32 gmask;
122 guint32 bmask;
123 guint32 colours[3];
124 } sparrow_format;
127 typedef enum sparrow_axis_s {
128 SPARROW_HORIZONTAL,
129 SPARROW_VERTICAL,
130 } sparrow_axis_t;
133 /* a mesh of these contains the mapping from input to output.
134 stored in a fixed point notation.
136 #define SPARROW_FIXED_POINT 10
137 #define SPARROW_MAP_LUT_SHIFT 1
138 #define SPARROW_FP_2_LUT (SPARROW_FIXED_POINT - SPARROW_MAP_LUT_SHIFT)
140 typedef struct sparrow_map_path_s {
141 int dx;
142 int dy;
143 int n;
144 }sparrow_map_path_t;
147 typedef struct sparrow_map_row_s {
148 int start;
149 int end;
150 int in_x;
151 int in_y;
152 sparrow_map_path_t *points;
153 }sparrow_map_row_t;
155 typedef struct sparrow_map_s {
156 sparrow_map_row_t *rows;
157 void *point_mem;
158 }sparrow_map_t;
160 typedef struct sparrow_map_lut_s{
161 guint16 x;
162 guint16 y;
163 } sparrow_map_lut_t;
165 typedef struct sparrow_frame_s {
166 guint offset;
167 guint jpeg_size;
168 guint8 summary[48];
169 int successors[8];
170 } sparrow_frame_t;
172 typedef struct sparrow_shared_s {
173 guint8 *jpeg_blob;
174 size_t blob_size;
175 sparrow_frame_t *index;
176 guint image_count;
177 } sparrow_shared_t;
180 typedef struct _GstSparrow GstSparrow;
181 typedef struct _GstSparrowClass GstSparrowClass;
184 * GstSparrow:
186 * Opaque data structure.
188 struct _GstSparrow
190 GstVideoFilter videofilter;
191 sparrow_shared_t *shared; /* images, shared between the vaious instances */
192 sparrow_format in;
193 sparrow_format out;
195 /*some calibration modes have big unwieldy structs that attach here */
196 void *helper_struct;
198 /* properties / command line options */
199 gboolean debug;
200 gboolean use_timer;
201 guint32 rng_seed;
203 /* misc */
204 dsfmt_t *dsfmt; /*rng*/
206 /*state */
207 sparrow_state state;
208 gint32 countdown; /*intra-state timing*/
210 guint8 *debug_frame; /* for constructing debug images */
211 GstBuffer *in_buffer;
213 guint32 colour;
214 guint32 frame_count;
216 const char *reload;
217 const char *save;
219 /*debug timer */
220 struct timeval timer_start;
221 struct timeval timer_stop;
222 FILE * timer_log;
224 /*calibration results */
225 guint32 lag;
226 guint8 *screenmask;
227 sparrow_map_t map;
228 /*full sized LUT */
229 sparrow_map_lut_t *map_lut;
230 /*for jpeg decompression*/
231 struct jpeg_decompress_struct *cinfo;
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_DEBUG,
257 PROP_TIMER,
258 PROP_RNG_SEED,
259 PROP_COLOUR,
260 PROP_RELOAD,
261 PROP_SAVE
264 #define DEFAULT_PROP_CALIBRATE TRUE
265 #define DEFAULT_PROP_DEBUG FALSE
266 #define DEFAULT_PROP_TIMER FALSE
267 #define DEFAULT_PROP_RNG_SEED -1
268 #define DEFAULT_PROP_COLOUR SPARROW_GREEN
269 #define DEFAULT_PROP_RELOAD ""
270 #define DEFAULT_PROP_SAVE ""
272 #define QUOTE_(x) #x
273 #define QUOTE(x) QUOTE_(x)
275 /*timing utility code */
276 #define TIME_TRANSFORM 1
278 #define TIMER_START(sparrow) do{ \
279 if (sparrow->timer_log){ \
280 if ((sparrow)->timer_start.tv_sec){ \
281 GST_DEBUG("timer already running!\n"); \
283 else { \
284 gettimeofday(&((sparrow)->timer_start), NULL); \
287 } while (0)
289 static inline void
290 TIMER_STOP(GstSparrow *sparrow)
292 if (sparrow->timer_log){
293 struct timeval *start = &(sparrow->timer_start);
294 struct timeval *stop = &(sparrow->timer_stop);
295 if (start->tv_sec == 0){
296 GST_DEBUG("the timer isn't running!\n");
297 return;
299 gettimeofday(stop, NULL);
300 guint32 t = ((stop->tv_sec - start->tv_sec) * 1000000 +
301 stop->tv_usec - start->tv_usec);
303 #if SPARROW_NOISY_DEBUG
304 GST_DEBUG("took %u microseconds (%0.5f of a frame)\n",
305 t, (double)t * (25.0 / 1000000.0));
306 #endif
308 fprintf(sparrow->timer_log, "%d %6d\n", sparrow->state, t);
309 fflush(sparrow->timer_log);
310 start->tv_sec = 0; /* mark it as unused */
314 /* GST_DISABLE_GST_DEBUG is set in gstreamer compilation. If it is set, we
315 need our own debug channel. */
316 #ifdef GST_DISABLE_GST_DEBUG
318 #undef GST_DEBUG
320 static FILE *_sparrow_bloody_debug_flags = NULL;
321 static void
322 GST_DEBUG(const char *msg, ...){
323 if (! _sparrow_bloody_debug_flags){
324 _sparrow_bloody_debug_flags = fopen("/tmp/sparrow.log", "wb");
325 if (! _sparrow_bloody_debug_flags){
326 exit(1);
329 va_list argp;
330 va_start(argp, msg);
331 vfprintf(_sparrow_bloody_debug_flags, msg, argp);
332 va_end(argp);
333 fflush(_sparrow_bloody_debug_flags);
336 #define GST_ERROR GST_DEBUG
337 #define GST_WARNING GST_DEBUG
338 #define GST_INFO GST_DEBUG
339 #define GST_LOG GST_DEBUG
340 #define GST_FIXME GST_DEBUG
342 #endif
343 #define LOG_LINENO() GST_DEBUG("%-25s line %4d \n", __func__, __LINE__ );
346 G_END_DECLS
347 #endif /* __GST_VIDEO_SPARROW_H__ */