axfer: add an option for waiter type

This commit is an integration to add an option for users to choose waiter
type. Users give the type to value to '--waiter-type' ('-w') option to
choose it. Currently, 'snd_pcm_wait()' is just supported as a default.
This alsa-lib API is implemented with a call of poll(2).

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Sakamoto 2018-11-13 15:41:41 +09:00 committed by Takashi Iwai
parent cd211d8c22
commit 0e1b59cb4f
2 changed files with 26 additions and 1 deletions

View file

@ -13,6 +13,7 @@ enum no_short_opts {
// 200 or later belong to non us-ascii character set. // 200 or later belong to non us-ascii character set.
OPT_PERIOD_SIZE = 200, OPT_PERIOD_SIZE = 200,
OPT_BUFFER_SIZE, OPT_BUFFER_SIZE,
OPT_WAITER_TYPE,
OPT_DISABLE_RESAMPLE, OPT_DISABLE_RESAMPLE,
OPT_DISABLE_CHANNELS, OPT_DISABLE_CHANNELS,
OPT_DISABLE_FORMAT, OPT_DISABLE_FORMAT,
@ -33,6 +34,7 @@ static const struct option l_opts[] = {
{"avail-min", 1, 0, 'A'}, {"avail-min", 1, 0, 'A'},
{"start-delay", 1, 0, 'R'}, {"start-delay", 1, 0, 'R'},
{"stop-delay", 1, 0, 'T'}, {"stop-delay", 1, 0, 'T'},
{"waiter-type", 1, 0, OPT_WAITER_TYPE},
// For plugins in alsa-lib. // For plugins in alsa-lib.
{"disable-resample", 0, 0, OPT_DISABLE_RESAMPLE}, {"disable-resample", 0, 0, OPT_DISABLE_RESAMPLE},
{"disable-channels", 0, 0, OPT_DISABLE_CHANNELS}, {"disable-channels", 0, 0, OPT_DISABLE_CHANNELS},
@ -86,6 +88,8 @@ static int xfer_libasound_parse_opt(struct xfer_context *xfer, int key,
state->msec_for_start_threshold = arg_parse_decimal_num(optarg, &err); state->msec_for_start_threshold = arg_parse_decimal_num(optarg, &err);
else if (key == 'T') else if (key == 'T')
state->msec_for_stop_threshold = arg_parse_decimal_num(optarg, &err); state->msec_for_stop_threshold = arg_parse_decimal_num(optarg, &err);
else if (key == OPT_WAITER_TYPE)
state->waiter_type_literal = arg_duplicate_string(optarg, &err);
else if (key == OPT_DISABLE_RESAMPLE) else if (key == OPT_DISABLE_RESAMPLE)
state->no_auto_resample = true; state->no_auto_resample = true;
else if (key == OPT_DISABLE_CHANNELS) else if (key == OPT_DISABLE_CHANNELS)
@ -147,6 +151,25 @@ int xfer_libasound_validate_opts(struct xfer_context *xfer)
} }
} }
if (state->waiter_type_literal != NULL) {
if (state->test_nowait) {
fprintf(stderr,
"An option for waiter type should not be "
"used with nowait test option.\n");
return -EINVAL;
}
if (!state->nonblock && !state->mmap) {
fprintf(stderr,
"An option for waiter type should be used "
"with nonblock or mmap options.\n");
return -EINVAL;
}
state->waiter_type =
waiter_type_from_label(state->waiter_type_literal);
} else {
state->waiter_type = WAITER_TYPE_DEFAULT;
}
return err; return err;
} }
@ -201,7 +224,6 @@ static int open_handle(struct xfer_context *xfer)
if ((state->nonblock || state->mmap) && !state->test_nowait) if ((state->nonblock || state->mmap) && !state->test_nowait)
state->use_waiter = true; state->use_waiter = true;
state->waiter_type = WAITER_TYPE_DEFAULT;
err = snd_pcm_hw_params_any(state->handle, state->hw_params); err = snd_pcm_hw_params_any(state->handle, state->hw_params);
if (err < 0) if (err < 0)
@ -751,7 +773,9 @@ static void xfer_libasound_destroy(struct xfer_context *xfer)
struct libasound_state *state = xfer->private_data; struct libasound_state *state = xfer->private_data;
free(state->node_literal); free(state->node_literal);
free(state->waiter_type_literal);
state->node_literal = NULL; state->node_literal = NULL;
state->waiter_type_literal = NULL;
if (state->hw_params) if (state->hw_params)
snd_pcm_hw_params_free(state->hw_params); snd_pcm_hw_params_free(state->hw_params);

View file

@ -30,6 +30,7 @@ struct libasound_state {
bool verbose; bool verbose;
char *node_literal; char *node_literal;
char *waiter_type_literal;
unsigned int msec_per_period; unsigned int msec_per_period;
unsigned int msec_per_buffer; unsigned int msec_per_buffer;