mirror of
https://github.com/alsa-project/alsa-utils
synced 2024-09-20 01:59:57 +02:00
axfer: code refactoring for a helper function to wait for avail buffer space
This commit applies code refactoring for waiting PCM event queued per period of PCM buffer in copying operation for IRQ-based scheduling model. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
a07eb8e235
commit
498ca99461
1 changed files with 28 additions and 26 deletions
|
@ -19,6 +19,32 @@ struct rw_closure {
|
||||||
struct frame_cache cache;
|
struct frame_cache cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int wait_for_avail(struct libasound_state *state)
|
||||||
|
{
|
||||||
|
unsigned short revents;
|
||||||
|
unsigned short event;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
// Wait for hardware IRQ when no available space.
|
||||||
|
err = xfer_libasound_wait_event(state, -1, &revents);
|
||||||
|
if (err < 0)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
// TODO: error reporting.
|
||||||
|
if (revents & POLLERR)
|
||||||
|
return -EIO;
|
||||||
|
|
||||||
|
if (snd_pcm_stream(state->handle) == SND_PCM_STREAM_CAPTURE)
|
||||||
|
event = POLLIN;
|
||||||
|
else
|
||||||
|
event = POLLOUT;
|
||||||
|
|
||||||
|
if (!(revents & event))
|
||||||
|
return -EAGAIN;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int read_frames(struct libasound_state *state, unsigned int *frame_count,
|
static int read_frames(struct libasound_state *state, unsigned int *frame_count,
|
||||||
unsigned int avail_count, struct mapper_context *mapper,
|
unsigned int avail_count, struct mapper_context *mapper,
|
||||||
struct container_context *cntrs)
|
struct container_context *cntrs)
|
||||||
|
@ -134,21 +160,9 @@ static int r_process_frames_nonblocking(struct libasound_state *state,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state->use_waiter) {
|
if (state->use_waiter) {
|
||||||
unsigned short revents;
|
err = wait_for_avail(state);
|
||||||
|
|
||||||
// Wait for hardware IRQ when no available space.
|
|
||||||
err = xfer_libasound_wait_event(state, -1, &revents);
|
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto error;
|
goto error;
|
||||||
if (revents & POLLERR) {
|
|
||||||
// TODO: error reporting.
|
|
||||||
err = -EIO;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
if (!(revents & POLLIN)) {
|
|
||||||
err = -EAGAIN;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check available space on the buffer.
|
// Check available space on the buffer.
|
||||||
|
@ -300,21 +314,9 @@ static int w_process_frames_nonblocking(struct libasound_state *state,
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (state->use_waiter) {
|
if (state->use_waiter) {
|
||||||
unsigned short revents;
|
err = wait_for_avail(state);
|
||||||
|
|
||||||
// Wait for hardware IRQ when no left space.
|
|
||||||
err = xfer_libasound_wait_event(state, -1, &revents);
|
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto error;
|
goto error;
|
||||||
if (revents & POLLERR) {
|
|
||||||
// TODO: error reporting.
|
|
||||||
err = -EIO;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
if (!(revents & POLLOUT)) {
|
|
||||||
err = -EAGAIN;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check available space on the buffer.
|
// Check available space on the buffer.
|
||||||
|
|
Loading…
Reference in a new issue