[pulseaudio-commits] [SCM] PulseAudio Sound Server branch, master, updated. v0.9.15-test2-89-ged67b07

Lennart Poettering gitmailer-noreply at 0pointer.de
Fri Feb 20 12:40:13 PST 2009


This is an automated email from the git hooks/post-receive script. It was
generated because of a push to the "PulseAudio Sound Server" repository.

The master branch has been updated
      from  6aa110ad4e55bdffebd2f187933ebfcfd5b23e50 (commit)

- Log -----------------------------------------------------------------
ed67b07... simplify some code
9f89907... bluetooth: fix suspend on a2dp (to do on HSP non SCO over PCM)
-----------------------------------------------------------------------

Summary of changes:
 src/modules/bluetooth/module-bluetooth-device.c |   77 +++++++++++++++++++----
 src/pulsecore/rtpoll.c                          |   77 +++++++++++------------
 2 files changed, 101 insertions(+), 53 deletions(-)

-----------------------------------------------------------------------

commit 9f89907bfa671a5d924c3fe1acd1ea433a87fc71
Author: Marc-André Lureau <marc-andre.lureau at nokia.com>
Date:   Tue Feb 17 12:59:34 2009 +0200

    bluetooth: fix suspend on a2dp (to do on HSP non SCO over PCM)
    
     - s/setup_stream_fd/start_stream_fd
    
     - introduce stop_stream_fd to suspend properly the stream_fd (does
       not seem necessary when shuting down)
    
     - move {start,stop}_stream_fd to IO thread, it is also a good idea
       because it takes about 1s to setup.

diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index ac8344f..559d95b 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -653,7 +653,8 @@ static int set_conf(struct userdata *u) {
     return 0;
 }
 
-static int setup_stream_fd(struct userdata *u) {
+/* from IO thread */
+static int start_stream_fd(struct userdata *u) {
     union {
         bt_audio_msg_header_t rsp;
         struct bt_start_stream_req start_req;
@@ -662,8 +663,11 @@ static int setup_stream_fd(struct userdata *u) {
         bt_audio_error_t error;
         uint8_t buf[BT_SUGGESTED_BUFFER_SIZE];
     } msg;
+    struct pollfd *pollfd;
 
     pa_assert(u);
+    pa_assert(u->rtpoll);
+    pa_assert(!u->rtpoll_item);
     pa_assert(u->stream_fd < 0);
 
     memset(msg.buf, 0, BT_SUGGESTED_BUFFER_SIZE);
@@ -691,6 +695,47 @@ static int setup_stream_fd(struct userdata *u) {
     pa_make_fd_nonblock(u->stream_fd);
     pa_make_socket_low_delay(u->stream_fd);
 
+    u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 1);
+    pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
+    pollfd->fd = u->stream_fd;
+    pollfd->events = pollfd->revents = 0;
+
+    return 0;
+}
+
+/* from IO thread */
+static int stop_stream_fd(struct userdata *u) {
+    union {
+        bt_audio_msg_header_t rsp;
+        struct bt_stop_stream_req start_req;
+        struct bt_stop_stream_rsp start_rsp;
+        bt_audio_error_t error;
+        uint8_t buf[BT_SUGGESTED_BUFFER_SIZE];
+    } msg;
+
+    pa_assert(u);
+    pa_assert(u->rtpoll);
+    pa_assert(u->rtpoll_item);
+    pa_assert(u->stream_fd >= 0);
+
+    /* FIXME: HSP, only when sink&source suspended */
+    pa_rtpoll_item_free(u->rtpoll_item);
+    u->rtpoll_item = NULL;
+
+    memset(msg.buf, 0, BT_SUGGESTED_BUFFER_SIZE);
+    msg.start_req.h.type = BT_REQUEST;
+    msg.start_req.h.name = BT_STOP_STREAM;
+    msg.start_req.h.length = sizeof(msg.start_req);
+
+    if (service_send(u, &msg.start_req.h) < 0)
+        return -1;
+
+    if (service_expect(u, &msg.rsp, sizeof(msg), BT_STOP_STREAM, sizeof(msg.start_rsp)) < 0)
+        return -1;
+
+    pa_close(u->stream_fd);
+    u->stream_fd = -1;
+
     return 0;
 }
 
@@ -707,12 +752,19 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
 
                 case PA_SINK_SUSPENDED:
                     pa_assert(PA_SINK_IS_OPENED(u->sink->thread_info.state));
+
+                    stop_stream_fd(u); /* FIXME: return value */
+
                     break;
 
                 case PA_SINK_IDLE:
                 case PA_SINK_RUNNING:
-                    if (!PA_SINK_IS_OPENED(u->sink->thread_info.state))
-                        u->started_at = pa_rtclock_usec();
+                    if (PA_SINK_IS_OPENED(u->sink->thread_info.state))
+                        break;
+
+                    if (u->rtpoll_item == NULL)
+                        start_stream_fd(u); /* FIXME: return value */
+                    u->started_at = pa_rtclock_usec();
 
                     break;
 
@@ -994,6 +1046,9 @@ static void thread_func(void *userdata) {
     if (u->core->realtime_scheduling)
         pa_make_realtime(u->core->realtime_priority);
 
+    if (start_stream_fd(u) < 0)
+        goto fail;
+
     pa_thread_mq_install(&u->thread_mq);
     pa_rtpoll_install(u->rtpoll);
 
@@ -1074,12 +1129,18 @@ static void thread_func(void *userdata) {
         pollfd->events = (short) (((u->sink && PA_SINK_IS_OPENED(u->sink->thread_info.state) && !writable) ? POLLOUT : 0) |
                                   (u->source && PA_SOURCE_IS_OPENED(u->source->thread_info.state) ? POLLIN : 0));
 
+    poll_run:
         if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0)
             goto fail;
 
         if (ret == 0)
             goto finish;
 
+        if (!u->rtpoll_item) {
+            pa_rtpoll_set_timer_disabled(u->rtpoll);
+            goto poll_run;
+        }
+
         pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
 
         if (pollfd->revents & ~(POLLOUT|POLLIN)) {
@@ -1463,9 +1524,6 @@ static int setup_bt(struct userdata *u) {
         return 0;
     }
 
-    if (setup_stream_fd(u) < 0)
-        return -1;
-
     pa_log_debug("Got the stream socket");
 
     return 0;
@@ -1533,8 +1591,6 @@ static void stop_thread(struct userdata *u) {
 }
 
 static int start_thread(struct userdata *u) {
-    struct pollfd *pollfd;
-
     pa_assert(u);
     pa_assert(!u->thread);
     pa_assert(!u->rtpoll);
@@ -1549,11 +1605,6 @@ static int start_thread(struct userdata *u) {
     u->rtpoll = pa_rtpoll_new();
     pa_thread_mq_init(&u->thread_mq, u->core->mainloop, u->rtpoll);
 
-    u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 1);
-    pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
-    pollfd->fd = u->stream_fd;
-    pollfd->events = pollfd->revents = 0;
-
     if (!(u->thread = pa_thread_new(thread_func, u))) {
         pa_log_error("Failed to create IO thread");
         stop_thread(u);

commit ed67b07c4189e33223f1fb981a519a1af2992ebc
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Feb 20 21:39:46 2009 +0100

    simplify some code

diff --git a/src/pulsecore/rtpoll.c b/src/pulsecore/rtpoll.c
index 01dfd62..aa8ca32 100644
--- a/src/pulsecore/rtpoll.c
+++ b/src/pulsecore/rtpoll.c
@@ -478,59 +478,56 @@ static void update_timer(pa_rtpoll *p) {
 #ifdef HAVE_PPOLL
 
 #ifdef __linux__
-    if (!p->dont_use_ppoll) {
+    if (p->dont_use_ppoll)
+        return;
 #endif
 
-        if (p->timer == (timer_t) -1) {
-            struct sigevent se;
-
-            memset(&se, 0, sizeof(se));
-            se.sigev_notify = SIGEV_SIGNAL;
-            se.sigev_signo = p->rtsig;
+    if (p->timer == (timer_t) -1) {
+        struct sigevent se;
 
-            if (timer_create(CLOCK_MONOTONIC, &se, &p->timer) < 0)
-                if (timer_create(CLOCK_REALTIME, &se, &p->timer) < 0) {
-                    pa_log_warn("Failed to allocate POSIX timer: %s", pa_cstrerror(errno));
-                    p->timer = (timer_t) -1;
-                }
-        }
+        memset(&se, 0, sizeof(se));
+        se.sigev_notify = SIGEV_SIGNAL;
+        se.sigev_signo = p->rtsig;
 
-        if (p->timer != (timer_t) -1) {
-            struct itimerspec its;
-            struct timespec ts = { .tv_sec = 0, .tv_nsec = 0 };
-            sigset_t ss;
+        if (timer_create(CLOCK_MONOTONIC, &se, &p->timer) < 0)
+            if (timer_create(CLOCK_REALTIME, &se, &p->timer) < 0) {
+                pa_log_warn("Failed to allocate POSIX timer: %s", pa_cstrerror(errno));
+                p->timer = (timer_t) -1;
+            }
+    }
 
-            if (p->timer_armed) {
-                /* First disarm timer */
-                memset(&its, 0, sizeof(its));
-                pa_assert_se(timer_settime(p->timer, TIMER_ABSTIME, &its, NULL) == 0);
+    if (p->timer != (timer_t) -1) {
+        struct itimerspec its;
+        struct timespec ts = { .tv_sec = 0, .tv_nsec = 0 };
+        sigset_t ss;
 
-                /* Remove a signal that might be waiting in the signal q */
-                pa_assert_se(sigemptyset(&ss) == 0);
-                pa_assert_se(sigaddset(&ss, p->rtsig) == 0);
-                sigtimedwait(&ss, NULL, &ts);
-            }
+        if (p->timer_armed) {
+            /* First disarm timer */
+            memset(&its, 0, sizeof(its));
+            pa_assert_se(timer_settime(p->timer, TIMER_ABSTIME, &its, NULL) == 0);
 
-            /* And install the new timer */
-            if (p->timer_enabled) {
-                memset(&its, 0, sizeof(its));
+            /* Remove a signal that might be waiting in the signal q */
+            pa_assert_se(sigemptyset(&ss) == 0);
+            pa_assert_se(sigaddset(&ss, p->rtsig) == 0);
+            sigtimedwait(&ss, NULL, &ts);
+        }
 
-                its.it_value.tv_sec = p->next_elapse.tv_sec;
-                its.it_value.tv_nsec = p->next_elapse.tv_usec*1000;
+        /* And install the new timer */
+        if (p->timer_enabled) {
+            memset(&its, 0, sizeof(its));
 
-                /* Make sure that 0,0 is not understood as
-                 * "disarming" */
-                if (its.it_value.tv_sec == 0 && its.it_value.tv_nsec == 0)
-                    its.it_value.tv_nsec = 1;
-                pa_assert_se(timer_settime(p->timer, TIMER_ABSTIME, &its, NULL) == 0);
-            }
+            its.it_value.tv_sec = p->next_elapse.tv_sec;
+            its.it_value.tv_nsec = p->next_elapse.tv_usec*1000;
 
-            p->timer_armed = p->timer_enabled;
+            /* Make sure that 0,0 is not understood as
+             * "disarming" */
+            if (its.it_value.tv_sec == 0 && its.it_value.tv_nsec == 0)
+                its.it_value.tv_nsec = 1;
+            pa_assert_se(timer_settime(p->timer, TIMER_ABSTIME, &its, NULL) == 0);
         }
 
-#ifdef __linux__
+        p->timer_armed = p->timer_enabled;
     }
-#endif
 
 #endif
 }

-- 
hooks/post-receive
PulseAudio Sound Server



More information about the pulseaudio-commits mailing list