mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-02 09:01:46 -05:00
Move render and write to the fd to a separate function
This commit is contained in:
parent
88a21e9677
commit
d1cc632278
1 changed files with 90 additions and 81 deletions
|
|
@ -673,39 +673,15 @@ finish:
|
|||
pa_log_debug("SCO thread shutting down");
|
||||
}
|
||||
|
||||
static void a2dp_thread_func(void *userdata) {
|
||||
struct userdata *u = userdata;
|
||||
|
||||
pa_assert(u);
|
||||
|
||||
pa_log_debug("A2DP Thread starting up");
|
||||
|
||||
pa_thread_mq_install(&u->thread_mq);
|
||||
pa_rtpoll_install(u->rtpoll);
|
||||
|
||||
pa_smoother_set_time_offset(u->smoother, pa_rtclock_usec());
|
||||
|
||||
for (;;) {
|
||||
int ret;
|
||||
struct pollfd *pollfd;
|
||||
|
||||
if (PA_SINK_IS_OPENED(u->sink->thread_info.state)) {
|
||||
if (u->sink->thread_info.rewind_requested) {
|
||||
pa_sink_process_rewind(u->sink, 0);
|
||||
}
|
||||
}
|
||||
|
||||
pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
|
||||
|
||||
if (PA_SINK_IS_OPENED(u->sink->thread_info.state) && pollfd->revents) {
|
||||
pa_usec_t usec;
|
||||
int64_t n;
|
||||
static int a2dp_process_render(struct userdata *u) {
|
||||
ssize_t l;
|
||||
int write_type = 0, written;
|
||||
struct bt_a2dp *a2dp = &u->a2dp;
|
||||
struct rtp_header *header = (void *) a2dp->buffer;
|
||||
struct rtp_payload *payload = (void *) (a2dp->buffer + sizeof(*header));
|
||||
|
||||
pa_assert(u);
|
||||
|
||||
do {
|
||||
/* Render some data */
|
||||
int frame_size, encoded;
|
||||
|
|
@ -728,7 +704,7 @@ static void a2dp_thread_func(void *userdata) {
|
|||
pa_log_debug("SBC: encoded: %d; written: %d", encoded, written);
|
||||
if (encoded <= 0) {
|
||||
pa_log_error("SBC encoding error (%d)", encoded);
|
||||
goto fail;
|
||||
return -1;
|
||||
}
|
||||
pa_memblock_release(u->memchunk.memblock);
|
||||
pa_memblock_unref(u->memchunk.memblock);
|
||||
|
|
@ -760,7 +736,7 @@ avdtp_write:
|
|||
if (l < 0) {
|
||||
if (errno == EINTR) {
|
||||
pa_log_debug("EINTR");
|
||||
continue;
|
||||
goto avdtp_write;
|
||||
}
|
||||
else if (errno == EAGAIN) {
|
||||
pa_log_debug("EAGAIN");
|
||||
|
|
@ -768,12 +744,11 @@ avdtp_write:
|
|||
}
|
||||
else {
|
||||
pa_log_error("Failed to write data to FIFO: %s", pa_cstrerror(errno));
|
||||
goto fail;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
u->offset += a2dp->codesize*a2dp->frame_count;
|
||||
pollfd->revents = 0;
|
||||
|
||||
/* Reset buffer of data to send */
|
||||
a2dp->count = sizeof(struct rtp_header) + sizeof(struct rtp_payload);
|
||||
|
|
@ -781,6 +756,40 @@ avdtp_write:
|
|||
a2dp->samples = 0;
|
||||
a2dp->seq_num++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void a2dp_thread_func(void *userdata) {
|
||||
struct userdata *u = userdata;
|
||||
|
||||
pa_assert(u);
|
||||
|
||||
pa_log_debug("A2DP Thread starting up");
|
||||
|
||||
pa_thread_mq_install(&u->thread_mq);
|
||||
pa_rtpoll_install(u->rtpoll);
|
||||
|
||||
pa_smoother_set_time_offset(u->smoother, pa_rtclock_usec());
|
||||
|
||||
for (;;) {
|
||||
int ret;
|
||||
struct pollfd *pollfd;
|
||||
int64_t n;
|
||||
pa_usec_t usec;
|
||||
|
||||
if (PA_SINK_IS_OPENED(u->sink->thread_info.state)) {
|
||||
if (u->sink->thread_info.rewind_requested) {
|
||||
pa_sink_process_rewind(u->sink, 0);
|
||||
}
|
||||
}
|
||||
|
||||
pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
|
||||
|
||||
if (PA_SINK_IS_OPENED(u->sink->thread_info.state) && pollfd->revents) {
|
||||
if (a2dp_process_render(u) < 0)
|
||||
goto fail;
|
||||
pollfd->revents = 0;
|
||||
|
||||
/* feed the time smoother */
|
||||
n = u->offset;
|
||||
#ifdef SIOCOUTQ
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue