-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
311 lines (284 loc) · 11.9 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/* Limrendir
*
* This hastily written code was largely inspired, when not copy-pasted, from Aravis Viewer by Emmanuel Pacaud.
*
* This software is free; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
#include <limrendir.h>
#include <arvdebugprivate.h>
#include <arvgvstreamprivate.h>
#include <gtk/gtk.h>
#include <gst/gst.h>
#include <arv.h>
#include <stdlib.h>
#include <libintl.h>
#include <logroutines.h>
#if GST_GL_HAVE_WINDOW_X11 && defined (GDK_WINDOWING_X11)
#include <gst/gl/x11/gstgldisplay_x11.h>
#endif
static char *arv_viewer_option_debug_domains = NULL;
static char *arv_option_register_cache = NULL;
static char *arv_option_range_check = NULL;
static gboolean arv_viewer_option_auto_socket_buffer = TRUE; // Auto socket buffer
static gboolean arv_viewer_option_no_packet_resend = FALSE;
static unsigned int arv_viewer_option_initial_packet_timeout = ARV_GV_STREAM_INITIAL_PACKET_TIMEOUT_US_DEFAULT / 1000;
static unsigned int arv_viewer_option_packet_timeout = ARV_GV_STREAM_PACKET_TIMEOUT_US_DEFAULT / 1000;
static unsigned int arv_viewer_option_frame_retention = ARV_GV_STREAM_FRAME_RETENTION_US_DEFAULT / 1000;
static char *arv_option_uv_usb_mode = NULL;
static const GOptionEntry arv_viewer_option_entries[] =
{
{
"auto-buffer-size", 'a', 0, G_OPTION_ARG_NONE,
&arv_viewer_option_auto_socket_buffer, "Auto socket buffer size", NULL
},
{
"no-packet-resend", 'r', 0, G_OPTION_ARG_NONE,
&arv_viewer_option_no_packet_resend, "No packet resend", NULL
},
{
"initial-packet-timeout", 'l', 0, G_OPTION_ARG_INT,
&arv_viewer_option_initial_packet_timeout, "Initial packet timeout (ms)", NULL
},
{
"packet-timeout", 'p', 0, G_OPTION_ARG_INT,
&arv_viewer_option_packet_timeout, "Packet timeout (ms)", NULL
},
{
"frame-retention", 'm', 0, G_OPTION_ARG_INT,
&arv_viewer_option_frame_retention, "Frame retention (ms)", NULL
},
{
"register-cache", '\0', 0, G_OPTION_ARG_STRING,
&arv_option_register_cache, "Register cache policy",
"{disable|enable|debug}"
},
{
"range-check", '\0', 0, G_OPTION_ARG_STRING,
&arv_option_range_check, "Range check policy",
"{disable|enable}"
},
{
"usb-mode", 's', 0, G_OPTION_ARG_STRING,
&arv_option_uv_usb_mode, "USB device I/O mode",
"{sync|async}"
},
{
"aravis-debug", 'd', 0, G_OPTION_ARG_STRING,
&arv_viewer_option_debug_domains, NULL,
"{<category>[:<level>][,...]|help}"
},
{ NULL }
};
const double gc_option_frequency_default = -1;
const double gc_option_exposure_time_us_default = -1;
const double gc_option_gain_default = -1;
const int gc_option_horizontal_binning_default = -1;
const int gc_option_vertical_binning_default = -1;
const int gc_option_width_default = -1;
const int gc_option_height_default = -1;
const int gc_option_x_offset_default = -1;
const int gc_option_y_offset_default = -1;
char *arv_option_camera_name = NULL;
double arv_option_frequency = gc_option_frequency_default;
double arv_option_exposure_time_us = gc_option_exposure_time_us_default;
double arv_option_gain = gc_option_gain_default;
int arv_option_horizontal_binning = gc_option_horizontal_binning_default;
int arv_option_vertical_binning = gc_option_vertical_binning_default;
int arv_option_width = gc_option_width_default;
int arv_option_height = gc_option_height_default;
int arv_option_x_offset = gc_option_x_offset_default;
int arv_option_y_offset = gc_option_y_offset_default;
static const GOptionEntry gevCapture_option_entries[] =
{
{
"camera-name", 'c', 0, G_OPTION_ARG_STRING,
&arv_option_camera_name, "Camera name", "string"
},
{
"frequency", 'f', 0, G_OPTION_ARG_DOUBLE,
&arv_option_frequency, "Acquisition frequency (Hz)", "double"
},
{
"exposure", 'e', 0, G_OPTION_ARG_DOUBLE,
&arv_option_exposure_time_us, "Exposure time (us)", "double"
},
{
"gain", 'g', 0, G_OPTION_ARG_DOUBLE,
&arv_option_gain, "Gain (dB)", "double"
},
{
"x-offset", 'x', 0, G_OPTION_ARG_INT,
&arv_option_x_offset, "X-offset", "int"
},
{
"y-offset", 'y', 0, G_OPTION_ARG_INT,
&arv_option_y_offset, "Y-offset", "int"
},
{
"width", 'w', 0, G_OPTION_ARG_INT,
&arv_option_width, "Width", "int"
},
{
"height", 'h', 0, G_OPTION_ARG_INT,
&arv_option_height, "Height", "int"
},
{
"h-binning", '\0', 0, G_OPTION_ARG_INT,
&arv_option_horizontal_binning, "Horizontal binning", "int"
},
{
"v-binning", '\0', 0, G_OPTION_ARG_INT,
&arv_option_vertical_binning, "Vertical binning", "int"
},
{ NULL}
};
static gboolean lrd_option_gevcapture_mode = FALSE;
static char *lrd_option_dataset_name = NULL;
static int lrd_option_log_level = LOG_INFO;
static gboolean lrd_option_create_fake_camera = FALSE;
static const GOptionEntry limrendir_option_entries[] =
{
{
"gevcapture", 'o', 0, G_OPTION_ARG_NONE,
&lrd_option_gevcapture_mode, "GevCapture legacymode", NULL
},
{
"dataset-name", 'n', 0, G_OPTION_ARG_STRING,
&lrd_option_dataset_name, "Output dataset name", "s"
},
{
"log-level", '\0', 0, G_OPTION_ARG_INT,
&lrd_option_log_level, "Logging level", "0-4 (error, warn, info, debug, trace)"
},
{
"fake-camera", '\0', 0, G_OPTION_ARG_NONE,
&lrd_option_create_fake_camera, "Creates a fake camera", NULL
},
{ NULL }
};
int main (int argc, char **argv)
{
LrdViewer *viewer;
GtkIconTheme *icon_theme;
int status;
GOptionContext *context;
GError *error = NULL;
ArvRegisterCachePolicy register_cache_policy;
ArvRangeCheckPolicy range_check_policy;
ArvUvUsbMode usb_mode;
#if GST_GL_HAVE_WINDOW_X11 && defined(GDK_WINDOWING_X11)
XInitThreads ();
#endif
// ??? No idea what this is
// bindtextdomain (ARAVIS_GETTEXT, ARAVIS_LOCALE_DIR);
// bind_textdomain_codeset (ARAVIS_GETTEXT, "UTF-8");
// textdomain (ARAVIS_GETTEXT);
gtk_init (&argc, &argv);
gst_init (&argc, &argv);
context = g_option_context_new (NULL);
g_option_context_add_main_entries (context, limrendir_option_entries, NULL);
g_option_context_add_main_entries (context, gevCapture_option_entries, NULL);
g_option_context_add_main_entries (context, arv_viewer_option_entries, NULL);
g_option_context_add_group (context, gtk_get_option_group (TRUE));
g_option_context_add_group (context, gst_init_get_option_group ());
if (!g_option_context_parse (context, &argc, &argv, &error)) {
g_option_context_free (context);
g_print ("Option parsing failed: %s\n", error->message);
g_error_free (error);
return EXIT_FAILURE;
}
g_option_context_free (context);
icon_theme = gtk_icon_theme_get_default ();
gtk_icon_theme_add_resource_path (icon_theme, "/org/aravis/viewer/icons/gnome/");
// Log level
if (lrd_option_log_level < LOG_ERROR) {
lrd_option_log_level = LOG_ERROR;
} else if (lrd_option_log_level > LOG_TRACE) {
lrd_option_log_level = LOG_TRACE;
}
log_initialize(lrd_option_log_level);
if (arv_option_register_cache == NULL)
register_cache_policy = ARV_REGISTER_CACHE_POLICY_DEFAULT;
else if (g_strcmp0 (arv_option_register_cache, "disable") == 0)
register_cache_policy = ARV_REGISTER_CACHE_POLICY_DISABLE;
else if (g_strcmp0 (arv_option_register_cache, "enable") == 0)
register_cache_policy = ARV_REGISTER_CACHE_POLICY_ENABLE;
else if (g_strcmp0 (arv_option_register_cache, "debug") == 0)
register_cache_policy = ARV_REGISTER_CACHE_POLICY_DEBUG;
else {
printf ("Invalid register cache policy\n");
return EXIT_FAILURE;
}
if (arv_option_range_check == NULL)
range_check_policy = ARV_RANGE_CHECK_POLICY_DEFAULT;
else if (g_strcmp0 (arv_option_range_check, "disable") == 0)
range_check_policy = ARV_RANGE_CHECK_POLICY_DISABLE;
else if (g_strcmp0 (arv_option_range_check, "enable") == 0)
range_check_policy = ARV_RANGE_CHECK_POLICY_ENABLE;
else if (g_strcmp0 (arv_option_range_check, "debug") == 0)
range_check_policy = ARV_RANGE_CHECK_POLICY_DEBUG;
else {
printf ("Invalid range check policy\n");
return EXIT_FAILURE;
}
if (arv_option_uv_usb_mode == NULL)
usb_mode = ARV_UV_USB_MODE_DEFAULT;
else if (g_strcmp0 (arv_option_uv_usb_mode, "sync") == 0)
usb_mode = ARV_UV_USB_MODE_SYNC;
else if (g_strcmp0 (arv_option_uv_usb_mode, "async") == 0)
usb_mode = ARV_UV_USB_MODE_ASYNC;
else {
printf ("Invalid USB device I/O mode\n");
return EXIT_FAILURE;
}
if (!arv_debug_enable (arv_viewer_option_debug_domains)) {
if (g_strcmp0 (arv_viewer_option_debug_domains, "help") != 0)
printf ("Invalid debug selection\n");
else
arv_debug_print_infos ();
return EXIT_FAILURE;
}
viewer = trn_viewer_new();
if (!ARV_IS_VIEWER (viewer))
return EXIT_FAILURE;
log_debug("Settings arv-viewer options");
arv_viewer_set_options (viewer,
arv_viewer_option_auto_socket_buffer,
!arv_viewer_option_no_packet_resend,
arv_viewer_option_initial_packet_timeout,
arv_viewer_option_packet_timeout,
arv_viewer_option_frame_retention,
register_cache_policy,
range_check_policy,
usb_mode);
log_debug("Settings gevCapture options");
gevCapture_set_options (viewer,
arv_option_camera_name,
arv_option_frequency,
arv_option_exposure_time_us,
arv_option_gain,
arv_option_horizontal_binning,
arv_option_vertical_binning ,
arv_option_width,
arv_option_height,
arv_option_x_offset,
arv_option_y_offset);
log_debug("Settings limrendir options");
limrendir_set_options(viewer,
lrd_option_gevcapture_mode,
lrd_option_dataset_name,
lrd_option_create_fake_camera);
log_trace("Application run");
status = g_application_run (G_APPLICATION (viewer), argc, argv);
g_object_unref (viewer);
log_terminate();
return status;
}