static int opt_duration(slotinfo_t* slotinfo, const char *opt, const char *arg) { slotinfo->duration = parse_time_or_die(opt, arg, 1); return 0; }
int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options) { const OptionDef *po; int bool_val = 1; int *dstcount; void *dst; po = find_option(options, opt); if (!po->name && opt[0] == 'n' && opt[1] == 'o') { /* handle 'no' bool option */ po = find_option(options, opt + 2); if (!(po->name && (po->flags & OPT_BOOL))) goto unknown_opt; bool_val = 0; } if (!po->name) po = find_option(options, "default"); if (!po->name) { unknown_opt: av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'\n", opt); return AVERROR(EINVAL); } if (po->flags & HAS_ARG && !arg) { av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'\n", opt); return AVERROR(EINVAL); } /* new-style options contain an offset into optctx, old-style address of * a global var*/ dst = po->flags & (OPT_OFFSET|OPT_SPEC) ? (uint8_t*)optctx + po->u.off : po->u.dst_ptr; if (po->flags & OPT_SPEC) { SpecifierOpt **so = dst; char *p = strchr(opt, ':'); dstcount = (int*)(so + 1); *so = grow_array(*so, sizeof(**so), dstcount, *dstcount + 1); (*so)[*dstcount - 1].specifier = av_strdup(p ? p + 1 : ""); dst = &(*so)[*dstcount - 1].u; } if (po->flags & OPT_STRING) { char *str; str = av_strdup(arg); *(char**)dst = str; } else if (po->flags & OPT_BOOL) { *(int*)dst = bool_val; } else if (po->flags & OPT_INT) { *(int*)dst = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX); } else if (po->flags & OPT_INT64) { *(int64_t*)dst = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX); } else if (po->flags & OPT_TIME) { *(int64_t*)dst = parse_time_or_die(opt, arg, 1); } else if (po->flags & OPT_FLOAT) { *(float*)dst = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY); } else if (po->flags & OPT_DOUBLE) { *(double*)dst = parse_number_or_die(opt, arg, OPT_DOUBLE, -INFINITY, INFINITY); } else if (po->u.func_arg) { int ret = po->flags & OPT_FUNC2 ? po->u.func2_arg(optctx, opt, arg) : po->u.func_arg(opt, arg); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Failed to set value '%s' for option '%s'\n", arg, opt); return ret; } } if (po->flags & OPT_EXIT) exit_program(0); return !!(po->flags & HAS_ARG); }
static int opt_seek(slotinfo_t* slotinfo, const char *opt, const char *arg) { slotinfo->start_time = parse_time_or_die(opt, arg, 1); return 0; }