2 * This file is part of the sigrok-cli project.
4 * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <libsigrokdecode/libsigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */
31 #include <sys/types.h>
35 #include <glib/gstdio.h>
36 #include <libsigrok/libsigrok.h>
37 #include "sigrok-cli.h"
39 #define DEFAULT_OUTPUT_FORMAT "bits:width=64"
41 static struct sr_context *sr_ctx = NULL;
43 static uint64_t limit_samples = 0;
44 static uint64_t limit_frames = 0;
45 static struct sr_output_format *output_format = NULL;
46 static int default_output_format = FALSE;
47 static char *output_format_param = NULL;
49 static GHashTable *pd_ann_visible = NULL;
51 static GByteArray *savebuf;
53 static gboolean opt_version = FALSE;
54 static gint opt_loglevel = SR_LOG_WARN; /* Show errors+warnings per default. */
55 static gboolean opt_scan_devs = FALSE;
56 static gboolean opt_wait_trigger = FALSE;
57 static gchar *opt_input_file = NULL;
58 static gchar *opt_output_file = NULL;
59 static gchar *opt_drv = NULL;
60 static gchar *opt_config = NULL;
61 static gchar *opt_probes = NULL;
62 static gchar *opt_triggers = NULL;
63 static gchar *opt_pds = NULL;
65 static gchar *opt_pd_stack = NULL;
66 static gchar *opt_pd_annotations = NULL;
68 static gchar *opt_input_format = NULL;
69 static gchar *opt_output_format = NULL;
70 static gchar *opt_show = NULL;
71 static gchar *opt_time = NULL;
72 static gchar *opt_samples = NULL;
73 static gchar *opt_frames = NULL;
74 static gchar *opt_continuous = NULL;
75 static gchar *opt_set = NULL;
77 static GOptionEntry optargs[] = {
78 {"version", 'V', 0, G_OPTION_ARG_NONE, &opt_version,
79 "Show version and support list", NULL},
80 {"loglevel", 'l', 0, G_OPTION_ARG_INT, &opt_loglevel,
81 "Set loglevel (5 is most verbose)", NULL},
82 {"driver", 'd', 0, G_OPTION_ARG_STRING, &opt_drv,
83 "The driver to use", NULL},
84 {"config", 'c', 0, G_OPTION_ARG_STRING, &opt_config,
85 "Specify device configuration options", NULL},
86 {"input-file", 'i', 0, G_OPTION_ARG_FILENAME, &opt_input_file,
87 "Load input from file", NULL},
88 {"input-format", 'I', 0, G_OPTION_ARG_STRING, &opt_input_format,
89 "Input format", NULL},
90 {"output-file", 'o', 0, G_OPTION_ARG_FILENAME, &opt_output_file,
91 "Save output to file", NULL},
92 {"output-format", 'O', 0, G_OPTION_ARG_STRING, &opt_output_format,
93 "Output format", NULL},
94 {"probes", 'p', 0, G_OPTION_ARG_STRING, &opt_probes,
95 "Probes to use", NULL},
96 {"triggers", 't', 0, G_OPTION_ARG_STRING, &opt_triggers,
97 "Trigger configuration", NULL},
98 {"wait-trigger", 'w', 0, G_OPTION_ARG_NONE, &opt_wait_trigger,
99 "Wait for trigger", NULL},
101 {"protocol-decoders", 'P', 0, G_OPTION_ARG_STRING, &opt_pds,
102 "Protocol decoders to run", NULL},
103 {"protocol-decoder-stack", 'S', 0, G_OPTION_ARG_STRING, &opt_pd_stack,
104 "Protocol decoder stack", NULL},
105 {"protocol-decoder-annotations", 'A', 0, G_OPTION_ARG_STRING, &opt_pd_annotations,
106 "Protocol decoder annotation(s) to show", NULL},
108 {"scan", 0, 0, G_OPTION_ARG_NONE, &opt_scan_devs,
109 "Scan for devices", NULL},
110 {"show", 0, 0, G_OPTION_ARG_NONE, &opt_show,
111 "Show device detail", NULL},
112 {"time", 0, 0, G_OPTION_ARG_STRING, &opt_time,
113 "How long to sample (ms)", NULL},
114 {"samples", 0, 0, G_OPTION_ARG_STRING, &opt_samples,
115 "Number of samples to acquire", NULL},
116 {"frames", 0, 0, G_OPTION_ARG_STRING, &opt_frames,
117 "Number of frames to acquire", NULL},
118 {"continuous", 0, 0, G_OPTION_ARG_NONE, &opt_continuous,
119 "Sample continuously", NULL},
120 {"set", 0, 0, G_OPTION_ARG_NONE, &opt_set, "Set device options only", NULL},
121 {NULL, 0, 0, 0, NULL, NULL, NULL}
125 /* Convert driver options hash to GSList of struct sr_config. */
126 static GSList *hash_to_hwopt(GHashTable *hash)
128 const struct sr_config_info *srci;
129 struct sr_config *src;
134 keys = g_hash_table_get_keys(hash);
136 for (gl = keys; gl; gl = gl->next) {
138 if (!(srci = sr_config_info_name_get(key))) {
139 g_critical("Unknown option %s", key);
142 src = g_try_malloc(sizeof(struct sr_config));
143 src->key = srci->key;
144 value = g_hash_table_lookup(hash, key);
145 src->data = g_variant_new_string(value);
146 opts = g_slist_append(opts, src);
153 static void free_drvopts(struct sr_config *src)
155 g_variant_unref(src->data);
159 static GSList *device_scan(void)
161 struct sr_dev_driver **drivers, *driver;
163 GSList *drvopts, *devices, *tmpdevs, *l;
168 drvargs = parse_generic_arg(opt_drv, TRUE);
169 drvname = g_strdup(g_hash_table_lookup(drvargs, "sigrok_key"));
170 g_hash_table_remove(drvargs, "sigrok_key");
172 drivers = sr_driver_list();
173 for (i = 0; drivers[i]; i++) {
174 if (strcmp(drivers[i]->name, drvname))
179 g_critical("Driver %s not found.", drvname);
183 if (sr_driver_init(sr_ctx, driver) != SR_OK) {
184 g_critical("Failed to initialize driver.");
188 if (g_hash_table_size(drvargs) > 0) {
189 if (!(drvopts = hash_to_hwopt(drvargs))) {
190 /* Unknown options, already logged. */
191 g_hash_table_destroy(drvargs);
195 g_hash_table_destroy(drvargs);
196 devices = sr_driver_scan(driver, drvopts);
197 g_slist_free_full(drvopts, (GDestroyNotify)free_drvopts);
199 /* No driver specified, let them all scan on their own. */
201 drivers = sr_driver_list();
202 for (i = 0; drivers[i]; i++) {
204 if (sr_driver_init(sr_ctx, driver) != SR_OK) {
205 g_critical("Failed to initialize driver.");
208 tmpdevs = sr_driver_scan(driver, NULL);
209 for (l = tmpdevs; l; l = l->next)
210 devices = g_slist_append(devices, l->data);
211 g_slist_free(tmpdevs);
218 static void show_version(void)
220 struct sr_dev_driver **drivers;
221 struct sr_input_format **inputs;
222 struct sr_output_format **outputs;
225 struct srd_decoder *dec;
229 printf("sigrok-cli %s\n\n", VERSION);
231 printf("Using libsigrok %s (lib version %s).\n",
232 sr_package_version_string_get(), sr_lib_version_string_get());
234 printf("Using libsigrokdecode %s (lib version %s).\n\n",
235 srd_package_version_string_get(), srd_lib_version_string_get());
238 printf("Supported hardware drivers:\n");
239 drivers = sr_driver_list();
240 for (i = 0; drivers[i]; i++) {
241 printf(" %-20s %s\n", drivers[i]->name, drivers[i]->longname);
245 printf("Supported input formats:\n");
246 inputs = sr_input_list();
247 for (i = 0; inputs[i]; i++)
248 printf(" %-20s %s\n", inputs[i]->id, inputs[i]->description);
251 printf("Supported output formats:\n");
252 outputs = sr_output_list();
253 for (i = 0; outputs[i]; i++)
254 printf(" %-20s %s\n", outputs[i]->id, outputs[i]->description);
255 printf(" %-20s %s\n", "sigrok", "Default file output format");
259 if (srd_init(NULL) == SRD_OK) {
260 printf("Supported protocol decoders:\n");
261 srd_decoder_load_all();
262 for (l = srd_decoder_list(); l; l = l->next) {
264 printf(" %-20s %s\n", dec->id, dec->longname);
265 /* Print protocol description upon "-l 3" or higher. */
266 if (opt_loglevel >= SR_LOG_INFO)
267 printf(" %-20s %s\n", "", dec->desc);
275 static void print_dev_line(const struct sr_dev_inst *sdi)
277 struct sr_probe *probe;
282 s = g_string_sized_new(128);
283 g_string_assign(s, sdi->driver->name);
284 if (sr_config_get(sdi->driver, SR_CONF_CONN, &gvar, sdi) == SR_OK) {
285 g_string_append(s, ":conn=");
286 g_string_append(s, g_variant_get_string(gvar, NULL));
287 g_variant_unref(gvar);
289 g_string_append(s, " - ");
290 if (sdi->vendor && sdi->vendor[0])
291 g_string_append_printf(s, "%s ", sdi->vendor);
292 if (sdi->model && sdi->model[0])
293 g_string_append_printf(s, "%s ", sdi->model);
294 if (sdi->version && sdi->version[0])
295 g_string_append_printf(s, "%s ", sdi->version);
297 if (g_slist_length(sdi->probes) == 1) {
298 probe = sdi->probes->data;
299 g_string_append_printf(s, "with 1 probe: %s", probe->name);
301 g_string_append_printf(s, "with %d probes:", g_slist_length(sdi->probes));
302 for (l = sdi->probes; l; l = l->next) {
304 g_string_append_printf(s, " %s", probe->name);
308 g_string_append_printf(s, "\n");
309 printf("%s", s->str);
310 g_string_free(s, TRUE);
314 static void show_dev_list(void)
316 struct sr_dev_inst *sdi;
319 if (!(devices = device_scan()))
322 printf("The following devices were found:\n");
323 for (l = devices; l; l = l->next) {
327 g_slist_free(devices);
331 static void show_dev_detail(void)
333 struct sr_dev_inst *sdi;
334 const struct sr_config_info *srci;
336 GVariant *gvar_opts, *gvar_dict, *gvar_list, *gvar;
337 gsize num_opts, num_elements;
338 const uint64_t *uint64, p, q, low, high;
339 uint64_t cur_low, cur_high;
341 unsigned int num_devices, o, i;
344 const char *charopts, **stropts;
346 if (!(devices = device_scan())) {
347 g_critical("No devices found.");
351 num_devices = g_slist_length(devices);
352 if (num_devices > 1) {
353 g_critical("%d devices found. Use --scan to show them, "
354 "and select one to show.", num_devices);
361 if (sr_dev_open(sdi) != SR_OK) {
362 g_critical("Failed to open device.");
366 if ((sr_config_list(sdi->driver, SR_CONF_SCAN_OPTIONS, &gvar_opts,
368 opts = g_variant_get_fixed_array(gvar_opts, &num_elements,
370 printf("Supported driver options:\n");
371 for (i = 0; i < num_elements; i++) {
372 if (!(srci = sr_config_info_get(opts[i])))
374 printf(" %s\n", srci->id);
376 g_variant_unref(gvar_opts);
379 if ((sr_config_list(sdi->driver, SR_CONF_DEVICE_OPTIONS, &gvar_opts,
381 /* Driver supports no device instance options. */
384 printf("Supported configuration options:\n");
385 opts = g_variant_get_fixed_array(gvar_opts, &num_opts, sizeof(int32_t));
386 for (o = 0; o < num_opts; o++) {
387 if (!(srci = sr_config_info_get(opts[o])))
390 if (srci->key == SR_CONF_TRIGGER_TYPE) {
391 if (sr_config_list(sdi->driver, srci->key, &gvar,
396 charopts = g_variant_get_string(gvar, NULL);
397 printf(" Supported triggers: ");
399 printf("%c ", *charopts);
403 g_variant_unref(gvar);
405 } else if (srci->key == SR_CONF_PATTERN_MODE) {
406 /* Pattern generator modes */
407 printf(" %s", srci->id);
408 if (sr_config_list(sdi->driver, srci->key, &gvar,
410 printf(" - supported patterns:\n");
411 stropts = g_variant_get_strv(gvar, &num_elements);
412 for (i = 0; i < num_elements; i++)
413 printf(" %s\n", stropts[i]);
414 g_variant_unref(gvar);
419 } else if (srci->key == SR_CONF_SAMPLERATE) {
420 /* Supported samplerates */
421 printf(" %s", srci->id);
422 if (sr_config_list(sdi->driver, SR_CONF_SAMPLERATE,
423 &gvar_dict, sdi) != SR_OK) {
427 if ((gvar_list = g_variant_lookup_value(gvar_dict,
428 "samplerates", G_VARIANT_TYPE("at")))) {
429 uint64 = g_variant_get_fixed_array(gvar_list,
430 &num_elements, sizeof(uint64_t));
431 printf(" - supported samplerates:\n");
432 for (i = 0; i < num_elements; i++) {
433 if (!(s = sr_samplerate_string(uint64[i])))
438 g_variant_unref(gvar_list);
439 } else if ((gvar_list = g_variant_lookup_value(gvar_dict,
440 "samplerate-steps", G_VARIANT_TYPE("at")))) {
441 uint64 = g_variant_get_fixed_array(gvar_list,
442 &num_elements, sizeof(uint64_t));
444 if (!(s = sr_samplerate_string(uint64[0])))
449 if (!(s = sr_samplerate_string(uint64[1])))
454 if (!(s = sr_samplerate_string(uint64[2])))
456 printf(" in steps of %s)\n", s);
458 g_variant_unref(gvar_list);
460 g_variant_unref(gvar_dict);
462 } else if (srci->key == SR_CONF_BUFFERSIZE) {
463 /* Supported buffer sizes */
464 printf(" %s", srci->id);
465 if (sr_config_list(sdi->driver, SR_CONF_BUFFERSIZE,
466 &gvar_list, sdi) != SR_OK) {
470 uint64 = g_variant_get_fixed_array(gvar_list,
471 &num_elements, sizeof(uint64_t));
472 printf(" - supported buffer sizes:\n");
473 for (i = 0; i < num_elements; i++)
474 printf(" %"PRIu64"\n", uint64[i]);
475 g_variant_unref(gvar_list);
477 } else if (srci->key == SR_CONF_TIMEBASE) {
478 /* Supported time bases */
479 printf(" %s", srci->id);
480 if (sr_config_list(sdi->driver, SR_CONF_TIMEBASE,
481 &gvar_list, sdi) != SR_OK) {
485 printf(" - supported time bases:\n");
486 num_elements = g_variant_n_children(gvar_list);
487 for (i = 0; i < num_elements; i++) {
488 gvar = g_variant_get_child_value(gvar_list, i);
489 g_variant_get(gvar, "(tt)", &p, &q);
490 s = sr_period_string(p * q);
494 g_variant_unref(gvar_list);
496 } else if (srci->key == SR_CONF_VDIV) {
497 /* Supported volts/div values */
498 printf(" %s", srci->id);
499 if (sr_config_list(sdi->driver, SR_CONF_VDIV,
500 &gvar_list, sdi) != SR_OK) {
504 printf(" - supported volts/div:\n");
505 num_elements = g_variant_n_children(gvar_list);
506 for (i = 0; i < num_elements; i++) {
507 gvar = g_variant_get_child_value(gvar_list, i);
508 g_variant_get(gvar, "(tt)", &p, &q);
509 s = sr_voltage_string(p, q);
513 g_variant_unref(gvar_list);
515 } else if (srci->datatype == SR_T_CHAR) {
516 printf(" %s: ", srci->id);
517 if (sr_config_get(sdi->driver, srci->key,
518 &gvar, sdi) == SR_OK) {
519 tmp_str = g_strdup(g_variant_get_string(gvar, NULL));
520 g_variant_unref(gvar);
524 if (sr_config_list(sdi->driver, srci->key,
525 &gvar, sdi) != SR_OK) {
530 stropts = g_variant_get_strv(gvar, &num_elements);
531 for (i = 0; i < num_elements; i++) {
534 printf("%s", stropts[i]);
535 if (tmp_str && !strcmp(tmp_str, stropts[i]))
536 printf(" (current)");
541 g_variant_unref(gvar);
543 } else if (srci->datatype == SR_T_UINT64_RANGE) {
544 printf(" %s: ", srci->id);
545 if (sr_config_list(sdi->driver, srci->key,
546 &gvar_list, sdi) != SR_OK) {
551 if (sr_config_get(sdi->driver, srci->key, &gvar, sdi) == SR_OK) {
552 g_variant_get(gvar, "(tt)", &cur_low, &cur_high);
553 g_variant_unref(gvar);
559 num_elements = g_variant_n_children(gvar_list);
560 for (i = 0; i < num_elements; i++) {
561 gvar = g_variant_get_child_value(gvar_list, i);
562 g_variant_get(gvar, "(tt)", &low, &high);
563 g_variant_unref(gvar);
566 printf("%"PRIu64"-%"PRIu64, low, high);
567 if (low == cur_low && high == cur_high)
568 printf(" (current)");
571 g_variant_unref(gvar_list);
573 } else if (srci->datatype == SR_T_BOOL) {
574 printf(" %s: ", srci->id);
575 if (sr_config_get(sdi->driver, srci->key,
576 &gvar, sdi) == SR_OK) {
577 if (g_variant_get_boolean(gvar))
578 printf("on (current), off\n");
580 printf("on, off (current)\n");
581 g_variant_unref(gvar);
587 /* Everything else */
588 printf(" %s\n", srci->id);
591 g_variant_unref(gvar_opts);
594 g_slist_free(devices);
599 static void show_pd_detail(void)
602 struct srd_decoder *dec;
603 struct srd_decoder_option *o;
604 char **pdtokens, **pdtok, *optsep, **ann, *val, *doc;
607 pdtokens = g_strsplit(opt_pds, ",", -1);
608 for (pdtok = pdtokens; *pdtok; pdtok++) {
610 if ((optsep = strchr(*pdtok, ':')))
612 if (!(dec = srd_decoder_get_by_id(*pdtok))) {
613 g_critical("Protocol decoder %s not found.", *pdtok);
616 printf("ID: %s\nName: %s\nLong name: %s\nDescription: %s\n",
617 dec->id, dec->name, dec->longname, dec->desc);
618 printf("License: %s\n", dec->license);
619 printf("Annotations:\n");
620 if (dec->annotations) {
621 for (l = dec->annotations; l; l = l->next) {
623 printf("- %s\n %s\n", ann[0], ann[1]);
628 printf("Required probes:\n");
630 for (l = dec->probes; l; l = l->next) {
632 printf("- %s (%s): %s\n",
633 p->name, p->id, p->desc);
638 printf("Optional probes:\n");
639 if (dec->opt_probes) {
640 for (l = dec->opt_probes; l; l = l->next) {
642 printf("- %s (%s): %s\n",
643 p->name, p->id, p->desc);
649 printf("Options:\n");
650 for (l = dec->options; l; l = l->next) {
652 val = g_variant_print(o->def, FALSE);
653 printf("- %s: %s (default %s)\n", o->id, o->desc, val);
657 if ((doc = srd_decoder_doc_get(dec))) {
658 printf("Documentation:\n%s\n",
659 doc[0] == '\n' ? doc + 1 : doc);
664 g_strfreev(pdtokens);
668 static GArray *get_enabled_logic_probes(const struct sr_dev_inst *sdi)
670 struct sr_probe *probe;
674 probes = g_array_new(FALSE, FALSE, sizeof(int));
675 for (l = sdi->probes; l; l = l->next) {
677 if (probe->type != SR_PROBE_LOGIC)
679 if (probe->enabled != TRUE)
681 g_array_append_val(probes, probe->index);
687 static void datafeed_in(const struct sr_dev_inst *sdi,
688 const struct sr_datafeed_packet *packet, void *cb_data)
690 const struct sr_datafeed_meta *meta;
691 const struct sr_datafeed_logic *logic;
692 const struct sr_datafeed_analog *analog;
693 struct sr_config *src;
694 static struct sr_output *o = NULL;
695 static GArray *logic_probelist = NULL;
696 static uint64_t received_samples = 0;
697 static int unitsize = 0;
698 static int triggered = 0;
699 static FILE *outfile = NULL;
702 int sample_size, ret;
703 uint64_t samplerate, output_len, filter_out_len;
704 uint8_t *output_buf, *filter_out;
708 /* If the first packet to come in isn't a header, don't even try. */
709 if (packet->type != SR_DF_HEADER && o == NULL)
713 switch (packet->type) {
715 g_debug("cli: Received SR_DF_HEADER");
716 /* Initialize the output module. */
717 if (!(o = g_try_malloc(sizeof(struct sr_output)))) {
718 g_critical("Output module malloc failed.");
721 o->format = output_format;
722 o->sdi = (struct sr_dev_inst *)sdi;
723 o->param = output_format_param;
724 if (o->format->init) {
725 if (o->format->init(o) != SR_OK) {
726 g_critical("Output format initialization failed.");
731 /* Prepare non-stdout output. */
733 if (opt_output_file) {
734 if (default_output_format) {
735 /* output file is in session format, so we'll
736 * keep a copy of everything as it comes in
737 * and save from there after the session. */
739 savebuf = g_byte_array_new();
741 /* saving to a file in whatever format was set
742 * with --format, so all we need is a filehandle */
743 outfile = g_fopen(opt_output_file, "wb");
747 /* Prepare for logic data. */
748 logic_probelist = get_enabled_logic_probes(sdi);
749 /* How many bytes we need to store the packed samples. */
750 unitsize = (logic_probelist->len + 7) / 8;
754 if (opt_pds && logic_probelist->len) {
755 if (sr_config_get(sdi->driver, SR_CONF_SAMPLERATE,
756 &gvar, sdi) != SR_OK) {
757 g_critical("Unable to initialize protocol "
758 "decoders: no samplerate found.");
761 samplerate = g_variant_get_uint64(gvar);
762 g_variant_unref(gvar);
763 srd_session_start(logic_probelist->len, unitsize, samplerate);
769 g_debug("cli: received SR_DF_META");
770 meta = packet->payload;
771 for (l = meta->config; l; l = l->next) {
774 case SR_CONF_SAMPLERATE:
775 samplerate = g_variant_get_uint64(src->data);
776 g_debug("cli: got samplerate %"PRIu64" Hz", samplerate);
778 case SR_CONF_SAMPLE_INTERVAL:
779 samplerate = g_variant_get_uint64(src->data);
780 g_debug("cli: got sample interval %"PRIu64" ms", samplerate);
783 /* Unknown metadata is not an error. */
790 g_debug("cli: received SR_DF_TRIGGER");
791 if (o->format->event)
792 o->format->event(o, SR_DF_TRIGGER, &output_buf,
798 logic = packet->payload;
799 g_message("cli: received SR_DF_LOGIC, %"PRIu64" bytes", logic->length);
800 sample_size = logic->unitsize;
801 if (logic->length == 0)
804 /* Don't store any samples until triggered. */
805 if (opt_wait_trigger && !triggered)
808 if (limit_samples && received_samples >= limit_samples)
811 ret = sr_filter_probes(sample_size, unitsize, logic_probelist,
812 logic->data, logic->length,
813 &filter_out, &filter_out_len);
817 /* What comes out of the filter is guaranteed to be packed into the
818 * minimum size needed to support the number of samples at this sample
819 * size. however, the driver may have submitted too much -- cut off
820 * the buffer of the last packet according to the sample limit.
822 if (limit_samples && (received_samples + logic->length / sample_size >
823 limit_samples * sample_size))
824 filter_out_len = limit_samples * sample_size - received_samples;
826 if (opt_output_file && default_output_format) {
827 /* Saving to a session file. */
828 g_byte_array_append(savebuf, filter_out, filter_out_len);
832 if (srd_session_send(received_samples, (uint8_t*)filter_out,
833 filter_out_len) != SRD_OK)
838 if (o->format->data && packet->type == o->format->df_type)
839 o->format->data(o, filter_out, filter_out_len,
840 &output_buf, &output_len);
842 fwrite(output_buf, 1, output_len, outfile);
850 received_samples += logic->length / sample_size;
854 analog = packet->payload;
855 g_message("cli: received SR_DF_ANALOG, %d samples", analog->num_samples);
856 if (analog->num_samples == 0)
859 if (limit_samples && received_samples >= limit_samples)
862 if (o->format->data && packet->type == o->format->df_type) {
863 o->format->data(o, (const uint8_t *)analog->data,
864 analog->num_samples * sizeof(float),
865 &output_buf, &output_len);
867 fwrite(output_buf, 1, output_len, outfile);
873 received_samples += analog->num_samples;
876 case SR_DF_FRAME_BEGIN:
877 g_debug("cli: received SR_DF_FRAME_BEGIN");
878 if (o->format->event) {
879 o->format->event(o, SR_DF_FRAME_BEGIN, &output_buf,
882 fwrite(output_buf, 1, output_len, outfile);
889 case SR_DF_FRAME_END:
890 g_debug("cli: received SR_DF_FRAME_END");
891 if (o->format->event) {
892 o->format->event(o, SR_DF_FRAME_END, &output_buf,
895 fwrite(output_buf, 1, output_len, outfile);
906 if (o && o->format->receive) {
907 if (o->format->receive(o, sdi, packet, &out) == SR_OK && out) {
908 fwrite(out->str, 1, out->len, outfile);
910 g_string_free(out, TRUE);
914 /* SR_DF_END needs to be handled after the output module's receive()
915 * is called, so it can properly clean up that module etc. */
916 if (packet->type == SR_DF_END) {
917 g_debug("cli: Received SR_DF_END");
919 if (o->format->event) {
920 o->format->event(o, SR_DF_END, &output_buf, &output_len);
923 fwrite(output_buf, 1, output_len, outfile);
929 if (limit_samples && received_samples < limit_samples)
930 g_warning("Device only sent %" PRIu64 " samples.",
934 g_warning("Device stopped after %" PRIu64 " samples.",
937 g_array_free(logic_probelist, TRUE);
939 if (o->format->cleanup)
940 o->format->cleanup(o);
944 if (outfile && outfile != stdout)
947 if (opt_output_file && default_output_format && savebuf->len) {
948 if (sr_session_save(opt_output_file, sdi, savebuf->data,
949 unitsize, savebuf->len / unitsize) != SR_OK)
950 g_critical("Failed to save session.");
951 g_byte_array_free(savebuf, FALSE);
958 static int opts_to_gvar(struct srd_decoder *dec, GHashTable *hash,
959 GHashTable **options)
961 struct srd_decoder_option *o;
966 char *val_str, *conv;
969 *options = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
970 (GDestroyNotify)g_variant_unref);
972 for (optl = dec->options; optl; optl = optl->next) {
974 if (!(val_str = g_hash_table_lookup(hash, o->id)))
977 if (g_variant_is_of_type(o->def, G_VARIANT_TYPE_STRING)) {
978 gvar = g_variant_new_string(val_str);
979 } else if (g_variant_is_of_type(o->def, G_VARIANT_TYPE_INT64)) {
980 val_int = strtoll(val_str, &conv, 10);
981 if (!conv || conv == val_str) {
982 g_critical("Protocol decoder '%s' option '%s' "
983 "requires a number.", dec->name, o->id);
987 gvar = g_variant_new_int64(val_int);
989 g_critical("Unsupported type for option '%s' (%s)",
990 o->id, g_variant_get_type_string(o->def));
994 g_variant_ref_sink(gvar);
995 g_hash_table_insert(*options, g_strdup(o->id), gvar);
996 g_hash_table_remove(hash, o->id);
1002 static int probes_to_gvar(struct srd_decoder *dec, GHashTable *hash,
1003 GHashTable **probes)
1005 struct srd_probe *p;
1006 GSList *all_probes, *l;
1010 char *val_str, *conv;
1013 *probes = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
1014 (GDestroyNotify)g_variant_unref);
1016 all_probes = g_slist_copy(dec->probes);
1017 all_probes = g_slist_concat(all_probes, dec->opt_probes);
1018 for (l = all_probes; l; l = l->next) {
1020 if (!(val_str = g_hash_table_lookup(hash, p->id)))
1021 /* Not specified. */
1023 val_int = strtoll(val_str, &conv, 10);
1024 if (!conv || conv == val_str) {
1025 g_critical("Protocol decoder '%s' probes '%s' "
1026 "is not a number.", dec->name, p->id);
1030 gvar = g_variant_new_int32(val_int);
1031 g_variant_ref_sink(gvar);
1032 g_hash_table_insert(*probes, g_strdup(p->id), gvar);
1033 g_hash_table_remove(hash, p->id);
1035 g_slist_free(all_probes);
1040 /* Register the given PDs for this session.
1041 * Accepts a string of the form: "spi:sck=3:sdata=4,spi:sck=3:sdata=5"
1042 * That will instantiate two SPI decoders on the clock but different data
1045 static int register_pds(struct sr_dev *dev, const char *pdstring)
1047 struct srd_decoder *dec;
1048 GHashTable *pd_opthash, *options, *probes;
1049 GList *leftover, *l;
1050 struct srd_decoder_inst *di;
1052 char **pdtokens, **pdtok, *pd_name;
1057 pd_ann_visible = g_hash_table_new_full(g_str_hash, g_int_equal,
1060 pd_opthash = options = probes = NULL;
1061 pdtokens = g_strsplit(pdstring, ",", 0);
1062 for (pdtok = pdtokens; *pdtok; pdtok++) {
1063 if (!(pd_opthash = parse_generic_arg(*pdtok, TRUE))) {
1064 g_critical("Invalid protocol decoder option '%s'.", *pdtok);
1068 pd_name = g_strdup(g_hash_table_lookup(pd_opthash, "sigrok_key"));
1069 g_hash_table_remove(pd_opthash, "sigrok_key");
1070 if (srd_decoder_load(pd_name) != SRD_OK) {
1071 g_critical("Failed to load protocol decoder %s.", pd_name);
1075 dec = srd_decoder_get_by_id(pd_name);
1077 /* Convert decoder option and probe values to GVariant. */
1078 if (!opts_to_gvar(dec, pd_opthash, &options)) {
1082 if (!probes_to_gvar(dec, pd_opthash, &probes)) {
1086 if (g_hash_table_size(pd_opthash) > 0) {
1087 leftover = g_hash_table_get_keys(pd_opthash);
1088 for (l = leftover; l; l = l->next)
1089 g_critical("Unknown option or probe '%s'", (char *)l->data);
1090 g_list_free(leftover);
1094 if (!(di = srd_inst_new(pd_name, options))) {
1095 g_critical("Failed to instantiate protocol decoder %s.", pd_name);
1100 /* If no annotation list was specified, add them all in now.
1101 * This will be pared down later to leave only the last PD
1104 if (!opt_pd_annotations)
1105 g_hash_table_insert(pd_ann_visible,
1106 g_strdup(di->inst_id), NULL);
1108 /* Remap the probes if needed. */
1109 if (srd_inst_probe_set_all(di, probes) != SRD_OK) {
1115 g_strfreev(pdtokens);
1117 g_hash_table_destroy(pd_opthash);
1119 g_hash_table_destroy(options);
1121 g_hash_table_destroy(probes);
1128 int setup_pd_stack(void)
1130 struct srd_decoder_inst *di_from, *di_to;
1134 /* Set up the protocol decoder stack. */
1135 pds = g_strsplit(opt_pds, ",", 0);
1136 if (g_strv_length(pds) > 1) {
1138 /* A stack setup was specified, use that. */
1140 pds = g_strsplit(opt_pd_stack, ",", 0);
1141 if (g_strv_length(pds) < 2) {
1143 g_critical("Specify at least two protocol decoders to stack.");
1148 /* First PD goes at the bottom of the stack. */
1149 ids = g_strsplit(pds[0], ":", 0);
1150 if (!(di_from = srd_inst_find_by_id(ids[0]))) {
1152 g_critical("Cannot stack protocol decoder '%s': "
1153 "instance not found.", pds[0]);
1158 /* Every subsequent PD goes on top. */
1159 for (i = 1; pds[i]; i++) {
1160 ids = g_strsplit(pds[i], ":", 0);
1161 if (!(di_to = srd_inst_find_by_id(ids[0]))) {
1163 g_critical("Cannot stack protocol decoder '%s': "
1164 "instance not found.", pds[i]);
1168 if ((ret = srd_inst_stack(di_from, di_to)) != SRD_OK)
1171 /* Don't show annotation from this PD. Only the last PD in
1172 * the stack will be left on the annotation list (unless
1173 * the annotation list was specifically provided).
1175 if (!opt_pd_annotations)
1176 g_hash_table_remove(pd_ann_visible,
1187 int setup_pd_annotations(void)
1190 struct srd_decoder *dec;
1192 char **pds, **pdtok, **keyval, **ann_descr;
1194 /* Set up custom list of PDs and annotations to show. */
1195 if (opt_pd_annotations) {
1196 pds = g_strsplit(opt_pd_annotations, ",", 0);
1197 for (pdtok = pds; *pdtok && **pdtok; pdtok++) {
1199 keyval = g_strsplit(*pdtok, "=", 0);
1200 if (!(dec = srd_decoder_get_by_id(keyval[0]))) {
1201 g_critical("Protocol decoder '%s' not found.", keyval[0]);
1204 if (!dec->annotations) {
1205 g_critical("Protocol decoder '%s' has no annotations.", keyval[0]);
1208 if (g_strv_length(keyval) == 2) {
1209 for (l = dec->annotations; l; l = l->next, ann++) {
1210 ann_descr = l->data;
1211 if (!canon_cmp(ann_descr[0], keyval[1]))
1216 g_critical("Annotation '%s' not found "
1217 "for protocol decoder '%s'.", keyval[1], keyval[0]);
1221 g_debug("cli: showing protocol decoder annotation %d from '%s'", ann, keyval[0]);
1222 g_hash_table_insert(pd_ann_visible, g_strdup(keyval[0]), GINT_TO_POINTER(ann));
1231 void show_pd_annotations(struct srd_proto_data *pdata, void *cb_data)
1235 gpointer ann_format;
1237 /* 'cb_data' is not used in this specific callback. */
1240 if (!pd_ann_visible)
1243 if (!g_hash_table_lookup_extended(pd_ann_visible, pdata->pdo->di->inst_id,
1245 /* Not in the list of PDs whose annotations we're showing. */
1248 if (pdata->ann_format != GPOINTER_TO_INT(ann_format))
1249 /* We don't want this particular format from the PD. */
1252 annotations = pdata->data;
1253 if (opt_loglevel > SR_LOG_WARN)
1254 printf("%"PRIu64"-%"PRIu64" ", pdata->start_sample, pdata->end_sample);
1255 printf("%s: ", pdata->pdo->proto_id);
1256 for (i = 0; annotations[i]; i++)
1257 printf("\"%s\" ", annotations[i]);
1263 int setup_output_format(void)
1265 GHashTable *fmtargs;
1266 GHashTableIter iter;
1267 gpointer key, value;
1268 struct sr_output_format **outputs;
1272 if (opt_output_format && !strcmp(opt_output_format, "sigrok")) {
1273 /* Doesn't really exist as an output module - this is
1274 * the session save mode. */
1275 g_free(opt_output_format);
1276 opt_output_format = NULL;
1279 if (!opt_output_format) {
1280 opt_output_format = DEFAULT_OUTPUT_FORMAT;
1281 /* we'll need to remember this so when saving to a file
1282 * later, sigrok session format will be used.
1284 default_output_format = TRUE;
1287 fmtargs = parse_generic_arg(opt_output_format, TRUE);
1288 fmtspec = g_hash_table_lookup(fmtargs, "sigrok_key");
1290 g_critical("Invalid output format.");
1293 outputs = sr_output_list();
1294 for (i = 0; outputs[i]; i++) {
1295 if (strcmp(outputs[i]->id, fmtspec))
1297 g_hash_table_remove(fmtargs, "sigrok_key");
1298 output_format = outputs[i];
1299 g_hash_table_iter_init(&iter, fmtargs);
1300 while (g_hash_table_iter_next(&iter, &key, &value)) {
1301 /* only supporting one parameter per output module
1302 * for now, and only its value */
1303 output_format_param = g_strdup(value);
1308 if (!output_format) {
1309 g_critical("Invalid output format %s.", opt_output_format);
1312 g_hash_table_destroy(fmtargs);
1317 static int select_probes(struct sr_dev_inst *sdi)
1319 struct sr_probe *probe;
1320 GSList *selected_probes, *l;
1325 if (!(selected_probes = parse_probestring(sdi, opt_probes)))
1328 for (l = sdi->probes; l; l = l->next) {
1330 if (g_slist_find(selected_probes, probe))
1331 probe->enabled = TRUE;
1333 probe->enabled = FALSE;
1335 g_slist_free(selected_probes);
1341 * Return the input file format which the CLI tool should use.
1343 * If the user specified -I / --input-format, use that one. Otherwise, try to
1344 * autodetect the format as good as possible. Failing that, return NULL.
1346 * @param filename The filename of the input file. Must not be NULL.
1347 * @param opt The -I / --input-file option the user specified (or NULL).
1349 * @return A pointer to the 'struct sr_input_format' that should be used,
1350 * or NULL if no input format was selected or auto-detected.
1352 static struct sr_input_format *determine_input_file_format(
1353 const char *filename, const char *opt)
1356 struct sr_input_format **inputs;
1358 /* If there are no input formats, return NULL right away. */
1359 inputs = sr_input_list();
1361 g_critical("No supported input formats available.");
1365 /* If the user specified -I / --input-format, use that one. */
1367 for (i = 0; inputs[i]; i++) {
1368 if (strcasecmp(inputs[i]->id, opt))
1370 g_debug("Using user-specified input file format '%s'.",
1375 /* The user specified an unknown input format, return NULL. */
1376 g_critical("Error: specified input file format '%s' is "
1381 /* Otherwise, try to find an input module that can handle this file. */
1382 for (i = 0; inputs[i]; i++) {
1383 if (inputs[i]->format_match(filename))
1387 /* Return NULL if no input module wanted to touch this. */
1389 g_critical("Error: no matching input module found.");
1393 g_debug("cli: Autodetected '%s' input format for file '%s'.",
1394 inputs[i]->id, filename);
1399 static void load_input_file_format(void)
1401 GHashTable *fmtargs = NULL;
1403 struct sr_input *in;
1404 struct sr_input_format *input_format;
1405 char *fmtspec = NULL;
1407 if (opt_input_format) {
1408 fmtargs = parse_generic_arg(opt_input_format, TRUE);
1409 fmtspec = g_hash_table_lookup(fmtargs, "sigrok_key");
1412 if (!(input_format = determine_input_file_format(opt_input_file,
1414 /* The exact cause was already logged. */
1419 g_hash_table_remove(fmtargs, "sigrok_key");
1421 if (stat(opt_input_file, &st) == -1) {
1422 g_critical("Failed to load %s: %s", opt_input_file,
1427 /* Initialize the input module. */
1428 if (!(in = g_try_malloc(sizeof(struct sr_input)))) {
1429 g_critical("Failed to allocate input module.");
1432 in->format = input_format;
1433 in->param = fmtargs;
1434 if (in->format->init) {
1435 if (in->format->init(in, opt_input_file) != SR_OK) {
1436 g_critical("Input format init failed.");
1441 if (select_probes(in->sdi) > 0)
1445 sr_session_datafeed_callback_add(datafeed_in, NULL);
1446 if (sr_session_dev_add(in->sdi) != SR_OK) {
1447 g_critical("Failed to use device.");
1448 sr_session_destroy();
1452 input_format->loadfile(in, opt_input_file);
1454 sr_session_destroy();
1457 g_hash_table_destroy(fmtargs);
1460 static void load_input_file(void)
1463 if (sr_session_load(opt_input_file) == SR_OK) {
1464 /* sigrok session file */
1465 sr_session_datafeed_callback_add(datafeed_in, NULL);
1471 /* fall back on input modules */
1472 load_input_file_format();
1476 static int set_dev_options(struct sr_dev_inst *sdi, GHashTable *args)
1478 const struct sr_config_info *srci;
1479 GHashTableIter iter;
1480 gpointer key, value;
1483 uint64_t tmp_u64, p, q, low, high;
1485 GVariant *val, *rational[2], *range[2];
1487 g_hash_table_iter_init(&iter, args);
1488 while (g_hash_table_iter_next(&iter, &key, &value)) {
1489 if (!(srci = sr_config_info_name_get(key))) {
1490 g_critical("Unknown device option '%s'.", (char *) key);
1494 if ((value == NULL) &&
1495 (srci->datatype != SR_T_BOOL)) {
1496 g_critical("Option '%s' needs a value.", (char *)key);
1500 switch (srci->datatype) {
1502 ret = sr_parse_sizestring(value, &tmp_u64);
1505 val = g_variant_new_uint64(tmp_u64);
1508 val = g_variant_new_string(value);
1514 tmp_bool = sr_parse_boolstring(value);
1515 val = g_variant_new_boolean(tmp_bool);
1518 tmp_double = strtof(value, NULL);
1519 val = g_variant_new_double(tmp_double);
1521 case SR_T_RATIONAL_PERIOD:
1522 if ((ret = sr_parse_period(value, &p, &q)) != SR_OK)
1524 rational[0] = g_variant_new_uint64(p);
1525 rational[1] = g_variant_new_uint64(q);
1526 val = g_variant_new_tuple(rational, 2);
1528 case SR_T_RATIONAL_VOLT:
1529 if ((ret = sr_parse_voltage(value, &p, &q)) != SR_OK)
1531 rational[0] = g_variant_new_uint64(p);
1532 rational[1] = g_variant_new_uint64(q);
1533 val = g_variant_new_tuple(rational, 2);
1535 case SR_T_UINT64_RANGE:
1536 if (sscanf(value, "%"PRIu64"-%"PRIu64, &low, &high) != 2) {
1540 range[0] = g_variant_new_uint64(low);
1541 range[1] = g_variant_new_uint64(high);
1542 val = g_variant_new_tuple(range, 2);
1549 ret = sr_config_set(sdi, srci->key, val);
1551 g_critical("Failed to set device option '%s'.", (char *)key);
1559 static void set_options(void)
1561 struct sr_dev_inst *sdi;
1563 GHashTable *devargs;
1566 g_critical("No setting specified.");
1570 if (!(devargs = parse_generic_arg(opt_config, FALSE)))
1573 if (!(devices = device_scan())) {
1574 g_critical("No devices found.");
1577 sdi = devices->data;
1579 if (sr_dev_open(sdi) != SR_OK) {
1580 g_critical("Failed to open device.");
1584 set_dev_options(sdi, devargs);
1587 g_slist_free(devices);
1588 g_hash_table_destroy(devargs);
1592 static int set_limit_time(const struct sr_dev_inst *sdi)
1596 uint64_t samplerate;
1598 if (!(time_msec = sr_parse_timestring(opt_time))) {
1599 g_critical("Invalid time '%s'", opt_time);
1603 if (sr_dev_has_option(sdi, SR_CONF_LIMIT_MSEC)) {
1604 gvar = g_variant_new_uint64(time_msec);
1605 if (sr_config_set(sdi, SR_CONF_LIMIT_MSEC, gvar) != SR_OK) {
1606 g_critical("Failed to configure time limit.");
1609 } else if (sr_dev_has_option(sdi, SR_CONF_SAMPLERATE)) {
1610 /* Convert to samples based on the samplerate. */
1611 sr_config_get(sdi->driver, SR_CONF_SAMPLERATE, &gvar, sdi);
1612 samplerate = g_variant_get_uint64(gvar);
1613 g_variant_unref(gvar);
1614 limit_samples = (samplerate) * time_msec / (uint64_t)1000;
1615 if (limit_samples == 0) {
1616 g_critical("Not enough time at this samplerate.");
1619 gvar = g_variant_new_uint64(limit_samples);
1620 if (sr_config_set(sdi, SR_CONF_LIMIT_SAMPLES, gvar) != SR_OK) {
1621 g_critical("Failed to configure time-based sample limit.");
1625 g_critical("This device does not support time limits.");
1632 static void run_session(void)
1635 GHashTable *devargs;
1637 struct sr_dev_inst *sdi;
1641 devices = device_scan();
1643 g_critical("No devices found.");
1646 if (g_slist_length(devices) > 1) {
1647 g_critical("sigrok-cli only supports one device for capturing.");
1650 sdi = devices->data;
1653 sr_session_datafeed_callback_add(datafeed_in, NULL);
1655 if (sr_dev_open(sdi) != SR_OK) {
1656 g_critical("Failed to open device.");
1660 if (sr_session_dev_add(sdi) != SR_OK) {
1661 g_critical("Failed to add device to session.");
1662 sr_session_destroy();
1667 if ((devargs = parse_generic_arg(opt_config, FALSE))) {
1668 if (set_dev_options(sdi, devargs) != SR_OK)
1670 g_hash_table_destroy(devargs);
1674 if (select_probes(sdi) != SR_OK) {
1675 g_critical("Failed to set probes.");
1676 sr_session_destroy();
1681 if (!(triggerlist = sr_parse_triggerstring(sdi, opt_triggers))) {
1682 sr_session_destroy();
1685 max_probes = g_slist_length(sdi->probes);
1686 for (i = 0; i < max_probes; i++) {
1687 if (triggerlist[i]) {
1688 sr_dev_trigger_set(sdi, i, triggerlist[i]);
1689 g_free(triggerlist[i]);
1692 g_free(triggerlist);
1695 if (opt_continuous) {
1696 if (!sr_dev_has_option(sdi, SR_CONF_CONTINUOUS)) {
1697 g_critical("This device does not support continuous sampling.");
1698 sr_session_destroy();
1704 if (set_limit_time(sdi) != SR_OK) {
1705 sr_session_destroy();
1711 if ((sr_parse_sizestring(opt_samples, &limit_samples) != SR_OK)) {
1712 g_critical("Invalid sample limit '%s'.", opt_samples);
1713 sr_session_destroy();
1716 gvar = g_variant_new_uint64(limit_samples);
1717 if (sr_config_set(sdi, SR_CONF_LIMIT_SAMPLES, gvar) != SR_OK) {
1718 g_critical("Failed to configure sample limit.");
1719 sr_session_destroy();
1725 if ((sr_parse_sizestring(opt_frames, &limit_frames) != SR_OK)) {
1726 g_critical("Invalid sample limit '%s'.", opt_samples);
1727 sr_session_destroy();
1730 gvar = g_variant_new_uint64(limit_frames);
1731 if (sr_config_set(sdi, SR_CONF_LIMIT_FRAMES, gvar) != SR_OK) {
1732 g_critical("Failed to configure frame limit.");
1733 sr_session_destroy();
1738 if (sr_session_start() != SR_OK) {
1739 g_critical("Failed to start session.");
1740 sr_session_destroy();
1752 sr_session_datafeed_callback_remove_all();
1753 sr_session_destroy();
1754 g_slist_free(devices);
1758 static void logger(const gchar *log_domain, GLogLevelFlags log_level,
1759 const gchar *message, gpointer cb_data)
1765 * All messages, warnings, errors etc. go to stderr (not stdout) in
1766 * order to not mess up the CLI tool data output, e.g. VCD output.
1768 if (log_level & (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING)
1769 || opt_loglevel > SR_LOG_WARN) {
1770 fprintf(stderr, "%s\n", message);
1775 int main(int argc, char **argv)
1777 GOptionContext *context;
1782 g_log_set_default_handler(logger, NULL);
1784 context = g_option_context_new(NULL);
1785 g_option_context_add_main_entries(context, optargs, NULL);
1789 if (!g_option_context_parse(context, &argc, &argv, &error)) {
1790 g_critical("%s", error->message);
1794 /* Set the loglevel (amount of messages to output) for libsigrok. */
1795 if (sr_log_loglevel_set(opt_loglevel) != SR_OK)
1798 if (sr_init(&sr_ctx) != SR_OK)
1802 /* Set the loglevel (amount of messages to output) for libsigrokdecode. */
1803 if (srd_log_loglevel_set(opt_loglevel) != SRD_OK)
1807 if (srd_init(NULL) != SRD_OK)
1809 if (register_pds(NULL, opt_pds) != 0)
1811 if (srd_pd_output_callback_add(SRD_OUTPUT_ANN,
1812 show_pd_annotations, NULL) != SRD_OK)
1814 if (setup_pd_stack() != 0)
1816 if (setup_pd_annotations() != 0)
1821 if (setup_output_format() != 0)
1826 else if (opt_scan_devs)
1829 else if (opt_pds && opt_show)
1834 else if (opt_input_file)
1838 else if (opt_samples || opt_time || opt_frames || opt_continuous)
1841 help = g_option_context_get_help(context, TRUE, NULL);
1857 g_option_context_free(context);