more sensible calibration signal theshold
[sparrow.git] / gstsparrow.h
blob1a9c4b0f77131468ed952ee7bec564b8cc2a407b
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_PATTERN_L 100
71 #define CALIBRATE_SELF_SIZE 24
74 #define MAX_CALIBRATE_SHAPES 4
76 #define FAKE_OTHER_PROJECTION 0
78 #define WAIT_COUNTDOWN (MAX(CALIBRATE_OFF_MAX_T, CALIBRATE_ON_MAX_T) + 3)
80 #define GST_TYPE_SPARROW \
81 (gst_sparrow_get_type())
82 #define GST_SPARROW(obj) \
83 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_SPARROW,GstSparrow))
84 #define GST_SPARROW_CLASS(klass) \
85 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_SPARROW,GstSparrowClass))
86 #define GST_IS_SPARROW(obj) \
87 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_SPARROW))
88 #define GST_IS_SPARROW_CLASS(klass) \
89 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_SPARROW))
92 #define MAX_CALIBRATION_LAG 16
93 typedef struct lag_times_s {
94 //guint32 hits;
95 guint64 record;
96 } lag_times_t;
98 typedef struct sparrow_format_s {
99 gint32 width;
100 gint32 height;
101 guint32 pixcount;
102 guint32 size;
104 guint32 rshift;
105 guint32 gshift;
106 guint32 bshift;
107 guint32 rmask;
108 guint32 gmask;
109 guint32 bmask;
110 } sparrow_format;
112 enum calibration_shape {
113 NO_SHAPE = 0,
114 VERTICAL_LINE,
115 HORIZONTAL_LINE,
116 FULLSCREEN,
117 RECTANGLE,
120 typedef struct sparrow_shape_s {
121 /*Calibration shape definition -- a rectangle or line.
122 For lines, only one dimension is used.*/
123 enum calibration_shape shape;
124 gint x;
125 gint y;
126 gint w;
127 gint h;
128 } sparrow_shape_t;
130 typedef struct sparrow_calibrate_s {
131 /*calibration state, and shape and pattern definition */
132 gboolean on; /*for calibration pattern */
133 gint wait;
134 guint32 pattern[CALIBRATE_PATTERN_L];
135 guint32 index;
136 guint32 transitions;
137 } sparrow_calibrate_t;
140 typedef struct _GstSparrow GstSparrow;
141 typedef struct _GstSparrowClass GstSparrowClass;
143 typedef enum {
144 SPARROW_INIT,
145 SPARROW_FIND_SELF,
146 SPARROW_WAIT_FOR_GRID,
147 SPARROW_FIND_EDGES,
148 SPARROW_FIND_GRID,
149 SPARROW_PLAY,
150 } sparrow_state;
154 * GstSparrow:
156 * Opaque data structure.
158 struct _GstSparrow
160 GstVideoFilter videofilter;
162 sparrow_format in;
163 sparrow_format out;
164 sparrow_shape_t shapes[MAX_CALIBRATE_SHAPES];
165 sparrow_calibrate_t calibrate;
167 /* properties */
168 gint calibrate_flag; /*whether to calibrate */
170 /* misc */
171 dsfmt_t *dsfmt; /*rng*/
173 /*state */
174 sparrow_state state;
175 sparrow_state next_state;
177 lag_times_t *lag_table;
178 guint64 lag_record;
179 guint32 lag;
181 gint32 countdown; /*intra-state timing*/
183 /*buffer pointers for previous frames */
184 guint8 *in_frame;
185 guint8 *prev_frame;
186 guint8 *work_frame;
187 guint8 *debug_frame;
189 GstBuffer *in_buffer;
190 GstBuffer *prev_buffer;
191 /*don't need work_buffer */
193 IplImage *in_ipl[3];
195 gboolean debug;
197 guint32 rng_seed;
199 guint32 frame_count;
202 struct _GstSparrowClass
204 GstVideoFilterClass parent_class;
207 GType gst_sparrow_get_type(void);
210 GST_DEBUG_CATEGORY_EXTERN (sparrow_debug);
211 #define GST_CAT_DEFAULT sparrow_debug
213 /* GstSparrow signals and args */
214 enum
216 /* FILL ME */
217 LAST_SIGNAL
220 enum
222 PROP_0,
223 PROP_CALIBRATE,
224 PROP_DEBUG,
225 PROP_RNG_SEED
228 #define DEFAULT_PROP_CALIBRATE TRUE
229 #define DEFAULT_PROP_DEBUG FALSE
230 #define DEFAULT_PROP_RNG_SEED -1
236 /* GST_DISABLE_GST_DEBUG is set in gstreamer compilation. If it is set, we
237 need our own debug channel. */
238 #ifdef GST_DISABLE_GST_DEBUG
240 #undef GEST_DEBUG
242 static FILE *_sparrow_bloody_debug_flags = NULL;
243 static void
244 GST_DEBUG(const char *msg, ...){
245 if (! _sparrow_bloody_debug_flags){
246 _sparrow_bloody_debug_flags = fopen("/tmp/sparrow.log", "wb");
247 if (! _sparrow_bloody_debug_flags){
248 exit(1);
251 va_list argp;
252 va_start(argp, msg);
253 vfprintf(_sparrow_bloody_debug_flags, msg, argp);
254 va_end(argp);
255 fflush(_sparrow_bloody_debug_flags);
258 #define GST_ERROR GST_DEBUG
259 #define GST_WARNING GST_DEBUG
260 #define GST_INFO GST_DEBUG
261 #define GST_LOG GST_DEBUG
262 #define GST_FIXME GST_DEBUG
264 #endif
265 #define LOG_LINENO() GST_DEBUG("%-25s line %4d \n", __func__, __LINE__ );
268 G_END_DECLS
269 #endif /* __GST_VIDEO_SPARROW_H__ */