Change pa_sink_render to pa_sink_render_into_full and remove some unnecessary checks on the rt thread

This commit is contained in:
João Paulo Rechi Vita 2008-08-14 20:59:28 -03:00 committed by Lennart Poettering
parent 2e51b93026
commit 435eb0711b

View file

@ -87,6 +87,7 @@ struct userdata {
pa_smoother *smoother;
pa_memchunk memchunk;
pa_mempool *mempool;
const char *name;
const char *addr;
@ -572,78 +573,72 @@ static void thread_func(void *userdata) {
for (;;) {
int ret;
if (PA_SINK_IS_OPENED(u->sink->thread_info.state))
if (u->sink->thread_info.rewind_requested)
pa_sink_process_rewind(u->sink, 0);
if (u->rtpoll_item) {
struct pollfd *pollfd;
if (PA_SINK_IS_OPENED(u->sink->thread_info.state)) {
if (u->sink->thread_info.rewind_requested) {
pa_log("rewind_requested");
pa_sink_process_rewind(u->sink, 0);
pa_log("rewind_finished");
}
}
pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
/* Render some data and write it to the fifo */
if (PA_SINK_IS_OPENED(u->sink->thread_info.state) && pollfd->revents) {
pa_usec_t usec;
int64_t n;
pa_log("Render some data and write it to the fifo");
for (;;) {
ssize_t l;
void *p;
if (u->memchunk.length <= 0)
pa_sink_render(u->sink, u->block_size, &u->memchunk);
u->memchunk.memblock = pa_memblock_new(u->mempool, u->block_size);
pa_log("memblock allocated");
u->memchunk.length = pa_memblock_get_length(u->memchunk.memblock);
pa_log("memchunk length");
pa_sink_render_into_full(u->sink, &u->memchunk);
pa_log("rendered");
pa_assert(u->memchunk.length > 0);
p = pa_memblock_acquire(u->memchunk.memblock);
l = pa_write(u->stream_fd, (uint8_t*) p + u->memchunk.index, u->memchunk.length, &write_type);
pa_log("memblock acquired");
l = pa_write(u->stream_fd, (uint8_t*) p, u->memchunk.length, &write_type);
pa_log("memblock written");
pa_memblock_release(u->memchunk.memblock);
pa_log("memblock released");
pa_assert(l != 0);
if (l < 0) {
pa_log("l = %d < 0", l);
if (errno == EINTR)
continue;
else if (errno == EAGAIN) {
/* OK, we filled all socket buffers up
* now. */
else if (errno == EAGAIN)
goto filled_up;
} else {
else {
pa_log("Failed to write data to FIFO: %s", pa_cstrerror(errno));
goto fail;
}
} else {
pa_log("l = %d >= 0", l);
u->offset += l;
u->memchunk.index += l;
u->memchunk.length -= l;
if (u->memchunk.length <= 0) {
pa_memblock_unref(u->memchunk.memblock);
pa_log("memblock unrefered");
pa_memchunk_reset(&u->memchunk);
}
pa_log("memchunk reseted");
pollfd->revents = 0;
if (u->memchunk.length > 0)
/* OK, we wrote less that we asked for,
* hence we can assume that the socket
* buffers are full now */
goto filled_up;
}
}
filled_up:
/* At this spot we know that the socket buffers are
* fully filled up. This is the best time to estimate
* the playback position of the server */
pa_log("filled_up");
/* At this spot we know that the socket buffers are fully filled up.
* This is the best time to estimate the playback position of the server */
n = u->offset;
//#ifdef SIOCOUTQ
@ -655,40 +650,38 @@ static void thread_func(void *userdata) {
//#endif
usec = pa_bytes_to_usec(n, &u->sink->sample_spec);
if (usec > u->latency)
usec -= u->latency;
else
usec = 0;
pa_smoother_put(u->smoother, pa_rtclock_usec(), usec);
}
/* Hmm, nothing to do. Let's sleep */
pa_log("let's sleep");
pollfd->events = PA_SINK_IS_OPENED(u->sink->thread_info.state) ? POLLOUT : 0;
if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0) {
pa_log("ret < 0");
goto fail;
}
pa_log("waking up");
if (ret == 0) {
pa_log("ret == 0");
goto finish;
}
if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0)
goto fail;
if (ret == 0)
goto finish;
if (u->rtpoll_item) {
struct pollfd* pollfd;
pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
if (pollfd->revents & ~POLLOUT) {
pa_log("FIFO shutdown.");
goto fail;
}
}
}
fail:
/* If this was no regular exit from the loop we have to continue
* processing messages until we received PA_MESSAGE_SHUTDOWN */
/* If this was no regular exit from the loop we have to continue processing messages until we receive PA_MESSAGE_SHUTDOWN */
pa_log("fail");
pa_asyncmsgq_post(u->thread_mq.outq, PA_MSGOBJECT(u->core), PA_CORE_MESSAGE_UNLOAD_MODULE, u->module, 0, NULL, NULL);
pa_asyncmsgq_wait_for(u->thread_mq.inq, PA_MESSAGE_SHUTDOWN);
@ -714,6 +707,7 @@ int pa__init(pa_module* m) {
u->offset = 0;
u->latency = 0;
u->smoother = pa_smoother_new(PA_USEC_PER_SEC, PA_USEC_PER_SEC*2, TRUE, 10);
u->mempool = pa_mempool_new(FALSE);
pa_memchunk_reset(&u->memchunk);
u->rtpoll = pa_rtpoll_new();
pa_thread_mq_init(&u->thread_mq, u->core->mainloop, u->rtpoll);