mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-04 13:29:59 -05:00
Change pa_sink_render to pa_sink_render_into_full and remove some unnecessary checks on the rt thread
This commit is contained in:
parent
2e51b93026
commit
435eb0711b
1 changed files with 97 additions and 103 deletions
|
|
@ -87,6 +87,7 @@ struct userdata {
|
||||||
pa_smoother *smoother;
|
pa_smoother *smoother;
|
||||||
|
|
||||||
pa_memchunk memchunk;
|
pa_memchunk memchunk;
|
||||||
|
pa_mempool *mempool;
|
||||||
|
|
||||||
const char *name;
|
const char *name;
|
||||||
const char *addr;
|
const char *addr;
|
||||||
|
|
@ -572,78 +573,72 @@ static void thread_func(void *userdata) {
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int ret;
|
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;
|
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);
|
pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
|
||||||
|
|
||||||
/* Render some data and write it to the fifo */
|
/* Render some data and write it to the fifo */
|
||||||
if (PA_SINK_IS_OPENED(u->sink->thread_info.state) && pollfd->revents) {
|
if (PA_SINK_IS_OPENED(u->sink->thread_info.state) && pollfd->revents) {
|
||||||
pa_usec_t usec;
|
pa_usec_t usec;
|
||||||
int64_t n;
|
int64_t n;
|
||||||
|
pa_log("Render some data and write it to the fifo");
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ssize_t l;
|
ssize_t l;
|
||||||
void *p;
|
void *p;
|
||||||
|
|
||||||
if (u->memchunk.length <= 0)
|
u->memchunk.memblock = pa_memblock_new(u->mempool, u->block_size);
|
||||||
pa_sink_render(u->sink, u->block_size, &u->memchunk);
|
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);
|
pa_assert(u->memchunk.length > 0);
|
||||||
|
|
||||||
p = pa_memblock_acquire(u->memchunk.memblock);
|
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_memblock_release(u->memchunk.memblock);
|
||||||
|
pa_log("memblock released");
|
||||||
|
|
||||||
pa_assert(l != 0);
|
pa_assert(l != 0);
|
||||||
|
|
||||||
if (l < 0) {
|
if (l < 0) {
|
||||||
|
pa_log("l = %d < 0", l);
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
else if (errno == EAGAIN) {
|
else if (errno == EAGAIN)
|
||||||
|
|
||||||
/* OK, we filled all socket buffers up
|
|
||||||
* now. */
|
|
||||||
goto filled_up;
|
goto filled_up;
|
||||||
|
else {
|
||||||
} else {
|
|
||||||
pa_log("Failed to write data to FIFO: %s", pa_cstrerror(errno));
|
pa_log("Failed to write data to FIFO: %s", pa_cstrerror(errno));
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
pa_log("l = %d >= 0", l);
|
||||||
u->offset += l;
|
u->offset += l;
|
||||||
|
|
||||||
u->memchunk.index += l;
|
|
||||||
u->memchunk.length -= l;
|
|
||||||
|
|
||||||
if (u->memchunk.length <= 0) {
|
|
||||||
pa_memblock_unref(u->memchunk.memblock);
|
pa_memblock_unref(u->memchunk.memblock);
|
||||||
|
pa_log("memblock unrefered");
|
||||||
pa_memchunk_reset(&u->memchunk);
|
pa_memchunk_reset(&u->memchunk);
|
||||||
}
|
pa_log("memchunk reseted");
|
||||||
|
|
||||||
pollfd->revents = 0;
|
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:
|
filled_up:
|
||||||
|
|
||||||
/* At this spot we know that the socket buffers are
|
pa_log("filled_up");
|
||||||
* fully filled up. This is the best time to estimate
|
/* At this spot we know that the socket buffers are fully filled up.
|
||||||
* the playback position of the server */
|
* This is the best time to estimate the playback position of the server */
|
||||||
|
|
||||||
n = u->offset;
|
n = u->offset;
|
||||||
|
|
||||||
//#ifdef SIOCOUTQ
|
//#ifdef SIOCOUTQ
|
||||||
|
|
@ -655,40 +650,38 @@ static void thread_func(void *userdata) {
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
usec = pa_bytes_to_usec(n, &u->sink->sample_spec);
|
usec = pa_bytes_to_usec(n, &u->sink->sample_spec);
|
||||||
|
|
||||||
if (usec > u->latency)
|
if (usec > u->latency)
|
||||||
usec -= u->latency;
|
usec -= u->latency;
|
||||||
else
|
else
|
||||||
usec = 0;
|
usec = 0;
|
||||||
|
|
||||||
pa_smoother_put(u->smoother, pa_rtclock_usec(), usec);
|
pa_smoother_put(u->smoother, pa_rtclock_usec(), usec);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Hmm, nothing to do. Let's sleep */
|
/* 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;
|
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);
|
pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
|
||||||
|
|
||||||
if (pollfd->revents & ~POLLOUT) {
|
if (pollfd->revents & ~POLLOUT) {
|
||||||
pa_log("FIFO shutdown.");
|
pa_log("FIFO shutdown.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
/* If this was no regular exit from the loop we have to continue
|
/* If this was no regular exit from the loop we have to continue processing messages until we receive PA_MESSAGE_SHUTDOWN */
|
||||||
* processing messages until we received 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_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);
|
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->offset = 0;
|
||||||
u->latency = 0;
|
u->latency = 0;
|
||||||
u->smoother = pa_smoother_new(PA_USEC_PER_SEC, PA_USEC_PER_SEC*2, TRUE, 10);
|
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);
|
pa_memchunk_reset(&u->memchunk);
|
||||||
u->rtpoll = pa_rtpoll_new();
|
u->rtpoll = pa_rtpoll_new();
|
||||||
pa_thread_mq_init(&u->thread_mq, u->core->mainloop, u->rtpoll);
|
pa_thread_mq_init(&u->thread_mq, u->core->mainloop, u->rtpoll);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue