mirror of
https://github.com/alsa-project/alsa-utils
synced 2024-11-14 05:25:43 +01:00
axfer: add an option to suppress event waiting
In aplay, '--test-nowait' is used to suppress calls of snd_pcm_wait() when I/O operations return -EAGAIN or process truncated number of data frames. This seems to be for debugging purpose. In this program, this option is equivalent to suppress event waiting. This commit adds support for this option. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
b5d2fadfb1
commit
0e3a1d9e0b
4 changed files with 37 additions and 12 deletions
|
@ -81,10 +81,12 @@ static int irq_mmap_process_frames(struct libasound_state *state,
|
||||||
snd_pcm_sframes_t consumed_count;
|
snd_pcm_sframes_t consumed_count;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
// Wait for hardware IRQ when no avail space in buffer.
|
if (state->use_waiter) {
|
||||||
err = snd_pcm_wait(state->handle, -1);
|
// Wait for hardware IRQ when no avail space in buffer.
|
||||||
if (err < 0)
|
err = snd_pcm_wait(state->handle, -1);
|
||||||
return err;
|
if (err < 0)
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
// Sync cache in user space to data in kernel space to calculate avail
|
// Sync cache in user space to data in kernel space to calculate avail
|
||||||
// frames according to the latest positions on PCM buffer.
|
// frames according to the latest positions on PCM buffer.
|
||||||
|
|
|
@ -133,10 +133,12 @@ static int r_process_frames_nonblocking(struct libasound_state *state,
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for hardware IRQ when no available space.
|
if (state->use_waiter) {
|
||||||
err = snd_pcm_wait(state->handle, -1);
|
// Wait for hardware IRQ when no available space.
|
||||||
if (err < 0)
|
err = snd_pcm_wait(state->handle, -1);
|
||||||
goto error;
|
if (err < 0)
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
// Check available space on the buffer.
|
// Check available space on the buffer.
|
||||||
avail = snd_pcm_avail(state->handle);
|
avail = snd_pcm_avail(state->handle);
|
||||||
|
@ -286,10 +288,12 @@ static int w_process_frames_nonblocking(struct libasound_state *state,
|
||||||
unsigned int avail_count;
|
unsigned int avail_count;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
// Wait for hardware IRQ when no left space.
|
if (state->use_waiter) {
|
||||||
err = snd_pcm_wait(state->handle, -1);
|
// Wait for hardware IRQ when no left space.
|
||||||
if (err < 0)
|
err = snd_pcm_wait(state->handle, -1);
|
||||||
goto error;
|
if (err < 0)
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
// Check available space on the buffer.
|
// Check available space on the buffer.
|
||||||
avail = snd_pcm_avail(state->handle);
|
avail = snd_pcm_avail(state->handle);
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
enum no_short_opts {
|
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_FATAL_ERRORS = 200,
|
OPT_FATAL_ERRORS = 200,
|
||||||
|
OPT_TEST_NOWAIT,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define S_OPTS "D:NM"
|
#define S_OPTS "D:NM"
|
||||||
|
@ -21,6 +22,7 @@ static const struct option l_opts[] = {
|
||||||
{"mmap", 0, 0, 'M'},
|
{"mmap", 0, 0, 'M'},
|
||||||
// For debugging.
|
// For debugging.
|
||||||
{"fatal-errors", 0, 0, OPT_FATAL_ERRORS},
|
{"fatal-errors", 0, 0, OPT_FATAL_ERRORS},
|
||||||
|
{"test-nowait", 0, 0, OPT_TEST_NOWAIT},
|
||||||
};
|
};
|
||||||
|
|
||||||
static int xfer_libasound_init(struct xfer_context *xfer,
|
static int xfer_libasound_init(struct xfer_context *xfer,
|
||||||
|
@ -54,6 +56,8 @@ static int xfer_libasound_parse_opt(struct xfer_context *xfer, int key,
|
||||||
state->mmap = true;
|
state->mmap = true;
|
||||||
else if (key == OPT_FATAL_ERRORS)
|
else if (key == OPT_FATAL_ERRORS)
|
||||||
state->finish_at_xrun = true;
|
state->finish_at_xrun = true;
|
||||||
|
else if (key == OPT_TEST_NOWAIT)
|
||||||
|
state->test_nowait = true;
|
||||||
else
|
else
|
||||||
err = -ENXIO;
|
err = -ENXIO;
|
||||||
|
|
||||||
|
@ -80,6 +84,15 @@ int xfer_libasound_validate_opts(struct xfer_context *xfer)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (state->test_nowait) {
|
||||||
|
if (!state->nonblock && !state->mmap) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"An option for nowait test should be used with "
|
||||||
|
"nonblock or mmap options.\n");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,6 +137,9 @@ static int open_handle(struct xfer_context *xfer)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((state->nonblock || state->mmap) && !state->test_nowait)
|
||||||
|
state->use_waiter = true;
|
||||||
|
|
||||||
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)
|
||||||
return err;
|
return err;
|
||||||
|
|
|
@ -33,6 +33,9 @@ struct libasound_state {
|
||||||
bool finish_at_xrun:1;
|
bool finish_at_xrun:1;
|
||||||
bool nonblock:1;
|
bool nonblock:1;
|
||||||
bool mmap:1;
|
bool mmap:1;
|
||||||
|
bool test_nowait:1;
|
||||||
|
|
||||||
|
bool use_waiter:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
// For internal use in 'libasound' module.
|
// For internal use in 'libasound' module.
|
||||||
|
|
Loading…
Reference in a new issue