diff options
author | Matthew Gregan <[email protected]> | 2011-09-22 16:03:39 +1200 |
---|---|---|
committer | Matthew Gregan <[email protected]> | 2011-09-22 16:03:39 +1200 |
commit | 22cfd70139808f659d123296c43c58c478b90ac9 (patch) | |
tree | e1f2f2b60cb3614c603fe6d79baf2c2e4f399f2c /src | |
parent | 572c7651db5a5133f607aca741e61ee2489c2a32 (diff) | |
download | cubeb-22cfd70139808f659d123296c43c58c478b90ac9.tar.gz cubeb-22cfd70139808f659d123296c43c58c478b90ac9.zip |
start refactoring alsa code.
Diffstat (limited to 'src')
-rw-r--r-- | src/cubeb_alsa.c | 100 |
1 files changed, 54 insertions, 46 deletions
diff --git a/src/cubeb_alsa.c b/src/cubeb_alsa.c index 6077ec5..9526d81 100644 --- a/src/cubeb_alsa.c +++ b/src/cubeb_alsa.c @@ -150,6 +150,59 @@ cubeb_unregister_active_stream(cubeb * ctx, cubeb_stream * stm) rebuild_pfds(ctx); } +static void +cubeb_process_stream(cubeb_stream * stm) +{ + long got; + snd_pcm_sframes_t avail; + void * p; + + avail = snd_pcm_avail_update(stm->pcm); + if (avail == -EPIPE) { + snd_pcm_recover(stm->pcm, avail, 1); + avail = snd_pcm_avail_update(stm->pcm); + } + p = calloc(1, snd_pcm_frames_to_bytes(stm->pcm, avail)); + assert(p); + got = stm->data_callback(stm, stm->user_ptr, p, avail); + if (got < 0) { + assert(0); /* XXX handle this case */ + } + if (got > 0) { + snd_pcm_sframes_t wrote = snd_pcm_writei(stm->pcm, p, got); + stm->write_position += wrote; + } + if (got != avail) { + struct cubeb_msg msg; +#if 0 + snd_pcm_state_t state = snd_pcm_state(stm->pcm); + r = snd_pcm_drain(stm->pcm); + assert(r == 0 || r == -EAGAIN); +#endif + + /* XXX write out a period of data to ensure real data is flushed to speakers */ + + /* XXX only fire this once */ + stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_DRAINED); + +#if 1 + /* XXX can't rebuild pfds until we've finished processing the current list */ + stm->state = CUBEB_STREAM_STATE_DEACTIVATING; + + msg.type = CUBEB_MSG_DEL_STREAM; + msg.data = stm; + cubeb_send_msg(stm->context, &msg); +#else + /* disable fds for poll */ + /* XXX this will be undone upon next rebuild, so need to flag this somehow */ + for (i = 0; i < stm->n_descriptors; ++i) { + tmppfds[i].fd = -1; + } +#endif + } + free(p); +} + static void * cubeb_run_thread(void * context) { @@ -185,52 +238,7 @@ cubeb_run_thread(void * context) } if (revents & POLLOUT) { - long got; - snd_pcm_sframes_t avail = snd_pcm_avail_update(stm->pcm); - void * p; - if (avail == -EPIPE) { - snd_pcm_recover(stm->pcm, avail, 1); - avail = snd_pcm_avail_update(stm->pcm); - } - p = calloc(1, snd_pcm_frames_to_bytes(stm->pcm, avail)); - assert(p); - got = stm->data_callback(stm, stm->user_ptr, p, avail); - if (got < 0) { - assert(0); /* XXX handle this case */ - } - if (got > 0) { - snd_pcm_sframes_t wrote = snd_pcm_writei(stm->pcm, p, got); - stm->write_position += wrote; - } - if (got != avail) { - struct cubeb_msg msg; -#if 0 - snd_pcm_state_t state = snd_pcm_state(stm->pcm); - r = snd_pcm_drain(stm->pcm); - assert(r == 0 || r == -EAGAIN); -#endif - - /* XXX write out a period of data to ensure real data is flushed to speakers */ - - /* XXX only fire this once */ - stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_DRAINED); - -#if 1 - /* XXX can't rebuild pfds until we've finished processing the current list */ - stm->state = CUBEB_STREAM_STATE_DEACTIVATING; - - msg.type = CUBEB_MSG_DEL_STREAM; - msg.data = stm; - cubeb_send_msg(stm->context, &msg); -#else - /* disable fds for poll */ - /* XXX this will be undone upon next rebuild, so need to flag this somehow */ - for (i = 0; i < stm->n_descriptors; ++i) { - tmppfds[i].fd = -1; - } -#endif - } - free(p); + cubeb_process_stream(stm); } tmppfds += stm->n_descriptors; |