- gc->audio_format_num = -1; /* default: grab any audio format */
- for (i = 1; i < argc; i++) {
- const char *arg = argv[i];
- if (arg[0] != '-')
- break;
- if (!strcmp(arg, "--")) {
- i++;
- break;
- }
- if (!strncmp(arg, "-n=", 3)) {
- ret = para_atoi32(arg + 3, &gc->filter_num);
- if (ret < 0)
- return ret;
- if (gc->filter_num < 0)
- return -E_BAD_GC_FILTER_NUM;
- if (gc->filter_num >= max_num_filters())
- return -E_BAD_GC_FILTER_NUM;
- continue;
- }
- if (!strncmp(arg, "-m", 2)) {
- if (*(arg + 3))
- return -E_GC_SYNTAX;
- switch(*(arg + 2)) {
- case 's':
- gc->mode = GM_SLOPPY;
- continue;
- case 'a':
- gc->mode = GM_AGGRESSIVE;
- continue;
- case 'p':
- gc->mode = GM_PEDANTIC;
- continue;
- default:
- return -E_GC_SYNTAX;
- }
- }
- if (!strcmp(arg, "-i")) {
- gc->flags |= GF_INPUT_GRAB;
- continue;
- }
- if (!strcmp(arg, "-o")) {
- gc->flags |= GF_ONE_SHOT;
- continue;
- }
- if (!strncmp(arg, "-f=", 3)) {
- ret = get_audio_format_num(arg + 3);
- if (ret < 0)
- return ret;
- gc->audio_format_num = ret;
- continue;
- }
- return -E_GC_SYNTAX;
+static int gc_post_select(__a_unused struct sched *s, void *context)
+{
+ struct grab_client *gc = context;
+ struct btr_node *btrn = gc->btrn;
+ int ret;
+ size_t sz;
+ char *buf;
+
+ ret = btr_node_status(btrn, 0, BTR_NT_LEAF);
+ if (ret == 0)
+ return 0;
+ if (ret < 0)
+ goto err;
+ sz = btr_next_buffer(btrn, &buf);
+ assert(sz != 0);
+ ret = gc_write(gc, buf, sz);
+ if (ret < 0)
+ goto err;
+ if (ret > 0)
+ btr_consume(btrn, ret);
+ return 0;
+err:
+ gc_close(gc, ret);
+ return ret;
+}
+
+static int gc_check_args(struct lls_parse_result *lpr, struct grab_client *gc)
+{
+ const struct lls_opt_result *r;
+
+ r = lls_opt_result(LSG_AUDIOD_CMD_GRAB_OPT_MODE, lpr);
+ if (lls_opt_given(r) > 0) {
+ const char *arg = lls_string_val(0, r);
+ if (strcmp(arg, "s") == 0)
+ gc->mode = GM_SLOPPY;
+ else if (strcmp(arg, "a") == 0)
+ gc->mode = GM_AGGRESSIVE;
+ else if (strcmp(arg, "p") == 0)
+ gc->mode = GM_PEDANTIC;
+ else
+ return -E_GC_SYNTAX;
+ }
+
+ r = lls_opt_result(LSG_AUDIOD_CMD_GRAB_OPT_ONE_SHOT, lpr);
+ if (lls_opt_given(r) > 0)
+ gc->flags |= GF_ONE_SHOT;
+
+ r = lls_opt_result(LSG_AUDIOD_CMD_GRAB_OPT_PARENT, lpr);
+ if (lls_opt_given(r) > 0) {
+ const char *arg = lls_string_val(0, r);
+ gc->parent = para_strdup(arg);
+ }
+
+ r = lls_opt_result(LSG_AUDIOD_CMD_GRAB_OPT_NAME, lpr);
+ if (lls_opt_given(r) > 0) {
+ const char *arg = lls_string_val(0, r);
+ gc->name = para_strdup(arg);