Convert README to README.rst for Github co-hosting
[sparrow.git] / gtk-app.h
blobfe00d39f745ea37957ff782cdbfc2cfa1683f89b
1 #define WIDTH 800
2 #define HEIGHT 600
3 //#define FPS 20
5 #define QUOTE_(x) #x
6 #define QUOTE(x) QUOTE_(x)
8 static gboolean option_fake = FALSE;
9 static gboolean option_fullscreen = FALSE;
10 static gint option_debug = -1;
11 static gint option_timer = -1;
12 static gint option_screens = 1;
13 static gint option_fps = 20;
14 static guint option_first_screen = 0;
15 static guint option_serial = 0;
16 static char **option_reload = NULL;
17 static char **option_save = NULL;
18 static char *option_avi = NULL;
21 #define MAX_SCREENS 2
23 static GOptionEntry entries[] =
25 { "fake-source", 0, 0, G_OPTION_ARG_NONE, &option_fake,
26 "use videotestsrc, not v4l2src (mostly won't work)", NULL },
27 { "full-screen", 'f', 0, G_OPTION_ARG_NONE, &option_fullscreen, "run full screen", NULL },
28 { "fps", 'p', 0, G_OPTION_ARG_INT, &option_fps,
29 "speed (Frames per second, multiple of 5 <= 30)", "FPS" },
30 { "screens", 's', 0, G_OPTION_ARG_INT, &option_screens, "Use this many screens, (max "
31 QUOTE(MAX_SCREENS) ")", "S" },
32 { "first-screen", 0, 0, G_OPTION_ARG_INT, &option_first_screen, "Start with this screen", "S" },
33 { "debug", 'd', 0, G_OPTION_ARG_INT, &option_debug, "Save screen's debug images in /tmp", "SCREEN" },
34 { "timer", 't', 0, G_OPTION_ARG_INT, &option_timer, "Log frame times in /tmp/timer.log", "SCREEN" },
35 { "serial-calibration", 'c', 0, G_OPTION_ARG_NONE, &option_serial,
36 "calibrate projections one at a time, not together", NULL },
37 { "reload", 'r', 0, G_OPTION_ARG_FILENAME_ARRAY, &option_reload,
38 "load calibration data from FILE (one per screen)", "FILE" },
39 { "save", 'S', 0, G_OPTION_ARG_FILENAME_ARRAY, &option_save,
40 "save calibration data to FILE (one per screen)", "FILE" },
41 { "avi", 'a', 0, G_OPTION_ARG_FILENAME, &option_avi,
42 "save mjpeg video to FILE", "FILE" },
43 { NULL, 0, 0, 0, NULL, NULL, NULL }
47 typedef struct windows_s {
48 int realised;
49 int requested;
50 GstElement *sinks[MAX_SCREENS];
51 XID xwindows[MAX_SCREENS];
52 GtkWidget *gtk_windows[MAX_SCREENS];
53 } windows_t;
56 #define COMMON_CAPS \
57 "framerate", GST_TYPE_FRACTION, option_fps, 1, \
58 "width", G_TYPE_INT, WIDTH, \
59 "height", G_TYPE_INT, HEIGHT, \
60 NULL
64 static void
65 mjpeg_branch(GstPipeline *pipeline, GstElement *tee)
67 /* ! jpegenc ! avimux ! filesink location=mjpeg.avi */
68 GstElement *queue = gst_element_factory_make("queue", NULL);
69 GstElement *jpegenc = gst_element_factory_make("jpegenc", NULL);
70 GstElement *avimux = gst_element_factory_make("avimux", NULL);
71 GstElement *filesink = gst_element_factory_make("filesink", NULL);
72 GstElement *cs = gst_element_factory_make("ffmpegcolorspace", NULL);
73 g_object_set(G_OBJECT(filesink),
74 "location", option_avi,
75 NULL);
76 gst_bin_add_many(GST_BIN(pipeline),
77 queue,
78 cs,
79 jpegenc,
80 avimux,
81 filesink,
82 NULL);
83 gst_element_link_many(tee,
84 queue,
85 cs,
86 jpegenc,
87 avimux,
88 filesink,
89 NULL);
92 static void
93 post_tee_pipeline(GstPipeline *pipeline, GstElement *tee, GstElement *sink,
94 int rngseed, int colour, int timer, int debug, char *save, char *reload){
95 GstElement *queue = gst_element_factory_make("queue", NULL);
96 GstElement *sparrow = gst_element_factory_make("sparrow", NULL);
97 GstElement *caps_posteriori = gst_element_factory_make("capsfilter", NULL);
98 GstElement *cs_posteriori = gst_element_factory_make("ffmpegcolorspace", NULL);
100 g_object_set(G_OBJECT(caps_posteriori), "caps",
101 gst_caps_new_simple ("video/x-raw-rgb",
102 COMMON_CAPS), NULL);
104 g_object_set(G_OBJECT(sparrow),
105 "timer", timer,
106 "debug", debug,
107 "rngseed", rngseed,
108 "colour", colour,
109 "serial", option_serial,
110 NULL);
111 if (reload){
112 g_object_set(G_OBJECT(sparrow),
113 "reload", reload,
114 NULL);
116 if (save){
117 g_object_set(G_OBJECT(sparrow),
118 "save", save,
119 NULL);
122 gst_bin_add_many (GST_BIN(pipeline),
123 queue,
124 sparrow,
125 caps_posteriori,
126 cs_posteriori,
127 sink,
128 NULL);
130 gst_element_link_many(tee,
131 queue,
132 sparrow,
133 caps_posteriori,
134 cs_posteriori,
135 sink,
136 NULL);
139 static GstElement *
140 pre_tee_pipeline(GstPipeline *pipeline){
141 if (pipeline == NULL){
142 pipeline = GST_PIPELINE(gst_pipeline_new("sparrow_pipeline"));
144 char * src_name = (option_fake) ? "videotestsrc" : "v4l2src";
145 GstElement *src = gst_element_factory_make(src_name, NULL);
146 GstElement *caps_priori = gst_element_factory_make("capsfilter", NULL);
147 GstElement *cs_priori = gst_element_factory_make("ffmpegcolorspace", NULL);
148 GstElement *caps_interiori = gst_element_factory_make("capsfilter", NULL);
149 GstElement *tee = gst_element_factory_make ("tee", NULL);
151 g_object_set(G_OBJECT(caps_priori), "caps",
152 gst_caps_new_simple ("video/x-raw-yuv",
153 "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC('Y', 'U', 'Y', '2'),
154 COMMON_CAPS), NULL);
156 g_object_set(G_OBJECT(caps_interiori), "caps",
157 gst_caps_new_simple ("video/x-raw-rgb",
158 COMMON_CAPS), NULL);
160 gst_bin_add_many(GST_BIN(pipeline),
161 src,
162 caps_priori,
163 cs_priori,
164 //caps_interiori,
165 tee,
166 NULL);
168 gst_element_link_many(src,
169 caps_priori,
170 cs_priori,
171 //caps_interiori,
172 tee,
173 NULL);
174 return tee;
178 static void hide_mouse(GtkWidget *widget){
179 GdkWindow *w = GDK_WINDOW(widget->window);
180 GdkDisplay *display = gdk_display_get_default();
181 GdkCursor *cursor = gdk_cursor_new_for_display(display, GDK_BLANK_CURSOR);
182 gdk_window_set_cursor(w, cursor);
183 gdk_cursor_unref (cursor);