Lines Matching defs:xfer
3 // xfer-options.c - a parser of commandline options for xfer.
9 #include "xfer.h"
48 " --xfer-type=BACKEND backend type (libasound, libffado)\n"
52 static int allocate_paths(struct xfer_context *xfer, char *const *paths,
63 xfer->paths = calloc(count, sizeof(xfer->paths[0]));
64 if (xfer->paths == NULL)
66 xfer->path_count = count;
69 xfer->paths[0] = strdup("-");
70 if (xfer->paths[0] == NULL)
74 xfer->paths[i] = strndup(paths[i], PATH_MAX);
75 if (xfer->paths[i] == NULL)
83 static int verify_cntr_format(struct xfer_context *xfer)
99 if (strcasecmp(xfer->cntr_format_literal, entry->literal))
102 xfer->cntr_format = entry->cntr_format;
107 xfer->cntr_format_literal);
113 static int verify_sample_format(struct xfer_context *xfer)
128 xfer->sample_format = snd_pcm_format_value(xfer->sample_format_literal);
129 if (xfer->sample_format != SND_PCM_FORMAT_UNKNOWN)
134 if (strcmp(entry->literal, xfer->sample_format_literal))
137 if (xfer->frames_per_second > 0 &&
138 xfer->frames_per_second != entry->frames_per_second) {
146 if (xfer->samples_per_frame > 0 &&
147 xfer->samples_per_frame != entry->samples_per_frame) {
155 xfer->frames_per_second = entry->frames_per_second;
156 xfer->samples_per_frame = entry->samples_per_frame;
157 if (xfer->cntr_format == CONTAINER_FORMAT_AU)
158 xfer->sample_format = entry->be_format;
160 xfer->sample_format = entry->le_format;
166 xfer->sample_format_literal);
171 static int validate_options(struct xfer_context *xfer)
176 if (xfer->cntr_format_literal == NULL) {
177 if (xfer->direction == SND_PCM_STREAM_CAPTURE) {
179 if (xfer->path_count == 1 &&
180 !strcmp(xfer->paths[0], "-")) {
181 xfer->cntr_format = CONTAINER_FORMAT_RAW;
184 xfer->cntr_format = container_format_from_path(
185 xfer->paths[0]);
190 err = verify_cntr_format(xfer);
195 if (xfer->multiple_cntrs) {
196 if (!strcmp(xfer->paths[0], "-")) {
207 if (xfer->direction == SND_PCM_STREAM_PLAYBACK) {
209 if (xfer->path_count == 1) {
219 if (xfer->path_count > 1) {
227 xfer->sample_format = SND_PCM_FORMAT_UNKNOWN;
228 if (xfer->sample_format_literal) {
229 err = verify_sample_format(xfer);
234 val = xfer->frames_per_second;
235 if (xfer->frames_per_second == 0)
236 xfer->frames_per_second = 8000;
237 if (xfer->frames_per_second < 1000)
238 xfer->frames_per_second *= 1000;
239 if (xfer->frames_per_second < 2000 ||
240 xfer->frames_per_second > 192000) {
245 if (xfer->samples_per_frame > 0) {
246 if (xfer->samples_per_frame < 1 ||
247 xfer->samples_per_frame > 256) {
249 xfer->samples_per_frame);
257 int xfer_options_parse_args(struct xfer_context *xfer,
266 {"xfer-type", 1, 0, OPT_XFER_TYPE},
331 xfer->help = true;
333 ++xfer->verbose;
335 xfer->quiet = true;
337 xfer->duration_seconds = arg_parse_decimal_num(optarg, &err);
339 xfer->duration_frames = arg_parse_decimal_num(optarg, &err);
341 xfer->sample_format_literal = arg_duplicate_string(optarg, &err);
343 xfer->samples_per_frame = arg_parse_decimal_num(optarg, &err);
345 xfer->frames_per_second = arg_parse_decimal_num(optarg, &err);
347 xfer->cntr_format_literal = arg_duplicate_string(optarg, &err);
349 xfer->multiple_cntrs = true;
351 xfer->dump_hw_params = true;
368 err = xfer->ops->parse_opt(xfer, key, optarg);
377 if (xfer->help) {
379 if (xfer->ops->help) {
382 xfer_label_from_type(xfer->type));
383 xfer->ops->help(xfer);
388 err = allocate_paths(xfer, argv + optind, argc - optind);
392 return validate_options(xfer);
395 void xfer_options_calculate_duration(struct xfer_context *xfer,
400 if (xfer->duration_seconds > 0) {
401 frame_count = (uint64_t)xfer->duration_seconds * (uint64_t)xfer->frames_per_second;
406 if (xfer->duration_frames > 0) {
407 frame_count = xfer->duration_frames;
421 static int generate_path_with_suffix(struct xfer_context *xfer,
430 if (xfer->path_count > 1)
431 len += (unsigned int)log10(xfer->path_count) + 2;
433 xfer->paths[index] = malloc(len);
434 if (xfer->paths[index] == NULL)
437 if (xfer->path_count == 1) {
438 snprintf(xfer->paths[index], len, single_format, template,
441 snprintf(xfer->paths[index], len, multiple_format, template,
448 static int generate_path_without_suffix(struct xfer_context *xfer,
458 if (xfer->path_count > 1)
459 len += (unsigned int)log10(xfer->path_count) + 2;
461 xfer->paths[index] = malloc(len);
462 if (xfer->paths[index] == NULL)
465 if (xfer->path_count == 1) {
466 snprintf(xfer->paths[index], len, single_format, template);
468 snprintf(xfer->paths[index], len, multiple_format, template,
475 static int generate_path(struct xfer_context *xfer, char *template,
478 int (*generator)(struct xfer_context *xfer, const char *template,
495 return generator(xfer, template, index, suffix);
498 static int create_paths(struct xfer_context *xfer, unsigned int path_count)
506 assert(xfer->path_count == 1);
507 assert(xfer->paths);
508 assert(xfer->paths[0]);
509 assert(xfer->paths[0][0] != '\0');
512 template = xfer->paths[0];
513 free(xfer->paths);
514 xfer->paths = NULL;
517 xfer->paths = calloc(path_count, sizeof(*xfer->paths));
518 if (xfer->paths == NULL) {
522 xfer->path_count = path_count;
524 suffix = container_suffix_from_format(xfer->cntr_format);
526 for (i = 0; i < xfer->path_count; ++i) {
535 err = generate_path(xfer, template, i, suffix);
545 static int fixup_paths(struct xfer_context *xfer)
552 suffix = container_suffix_from_format(xfer->cntr_format);
554 for (i = 0; i < xfer->path_count; ++i) {
557 if (!strcmp(xfer->paths[i], allowed_duplication[j]))
563 template = xfer->paths[i];
564 xfer->paths[i] = NULL;
565 err = generate_path(xfer, template, i, suffix);
574 int xfer_options_fixup_paths(struct xfer_context *xfer)
579 if (xfer->path_count == 1) {
581 if (!strcmp(xfer->paths[0], "-"))
583 if (!xfer->multiple_cntrs)
584 err = fixup_paths(xfer);
586 err = create_paths(xfer, xfer->samples_per_frame);
588 if (!xfer->multiple_cntrs)
590 if (xfer->path_count != xfer->samples_per_frame)
593 err = fixup_paths(xfer);
599 for (i = 0; i < xfer->path_count - 1; ++i) {
602 if (!strcmp(xfer->paths[i], allowed_duplication[j]))
608 for (j = i + 1; j < xfer->path_count; ++j) {
609 if (!strcmp(xfer->paths[i], xfer->paths[j])) {
616 if (j < xfer->path_count)
620 if (xfer->verbose > 1)
622 if (err < 0 || xfer->verbose > 1) {
623 for (i = 0; i < xfer->path_count; ++i)
624 fprintf(stderr, " %d: %s\n", i, xfer->paths[i]);