[pulseaudio-discuss] [PATCH v6 12/37] raop: Better playback resume handling

Hajime Fujita crisp.fujita at gmail.com
Sun Jan 31 20:16:09 PST 2016


From: Martin Blanchard <tchaik at gmx.com>

When playback stops, a FLUSH command is send to the server and the sink
goes to IDLE. If playback resumes quickly, sink goes back to RUNNING
(without being SUSPENDED) and the sink should just start streaming again.
This patch implements this behaviour.
---
 src/modules/raop/module-raop-sink.c |  8 ++++++--
 src/modules/raop/raop_client.c      | 26 +++++++++++++++++++++++---
 src/modules/raop/raop_client.h      |  1 +
 3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/src/modules/raop/module-raop-sink.c b/src/modules/raop/module-raop-sink.c
index 8deb139..1e83e97 100644
--- a/src/modules/raop/module-raop-sink.c
+++ b/src/modules/raop/module-raop-sink.c
@@ -332,10 +332,14 @@ static int udp_sink_process_msg(pa_msgobject *o, int code, void *data, int64_t o
 
                     pa_smoother_resume(u->smoother, pa_rtclock_now(), true);
 
-                    if (!pa_raop_client_udp_can_stream(u->raop)) {
-                        /* Connecting will trigger a RECORD */
+                    if (!pa_raop_client_udp_is_alive(u->raop)) {
+                        /* Connecting will trigger a RECORD and start steaming */
                         pa_raop_client_connect(u->raop);
+                    } else if (!pa_raop_client_udp_can_stream(u->raop)) {
+                        /* RECORD alredy sent, simply start streaming */
+                        pa_raop_client_udp_stream(u->raop);
                     }
+
                     udp_start_wakeup_clock(u);
 
                     break;
diff --git a/src/modules/raop/raop_client.c b/src/modules/raop/raop_client.c
index 11c871d..e6e3737 100644
--- a/src/modules/raop/raop_client.c
+++ b/src/modules/raop/raop_client.c
@@ -934,8 +934,6 @@ static void udp_rtsp_cb(pa_rtsp_client *rtsp, pa_rtsp_state state, pa_headerlist
 
             pa_log_debug("RAOP: RECORD");
 
-            c->is_recording = true;
-
             alt = pa_xstrdup(pa_headerlist_gets(headers, "Audio-Latency"));
             /* Generate a random synchronization source identifier from this session. */
             pa_random(&rand, sizeof(rand));
@@ -947,6 +945,8 @@ static void udp_rtsp_cb(pa_rtsp_client *rtsp, pa_rtsp_state state, pa_headerlist
             c->udp_first_packet = true;
             c->udp_sync_count = 0;
 
+            c->is_recording = true;
+
             c->udp_record_callback(c->udp_setup_userdata);
 
             pa_xfree(alt);
@@ -1150,11 +1150,12 @@ int pa_raop_client_connect(pa_raop_client *c) {
 
 int pa_raop_client_flush(pa_raop_client *c) {
     int rv = 0;
+
     pa_assert(c);
 
     if (c->rtsp != NULL) {
         rv = pa_rtsp_flush(c->rtsp, c->seq, c->rtptime);
-        c->udp_sync_count = -1;
+        c->udp_sync_count = 0;
     }
 
     return rv;
@@ -1193,6 +1194,25 @@ int pa_raop_client_udp_can_stream(pa_raop_client *c) {
     return rv;
 }
 
+int pa_raop_client_udp_stream(pa_raop_client *c) {
+    int rv = 0;
+
+    pa_assert(c);
+
+    if (c->rtsp != NULL && c->udp_stream_fd > 0) {
+        if (!c->is_recording) {
+            c->udp_first_packet = true;
+            c->udp_sync_count = 0;
+
+            c->is_recording = true;
+         }
+
+        rv = 1;
+    }
+
+    return rv;
+}
+
 int pa_raop_client_udp_handle_timing_packet(pa_raop_client *c, const uint8_t packet[], ssize_t size) {
     const uint32_t * data = NULL;
     uint8_t payload = 0;
diff --git a/src/modules/raop/raop_client.h b/src/modules/raop/raop_client.h
index 6ab6d32..d49c146 100644
--- a/src/modules/raop/raop_client.h
+++ b/src/modules/raop/raop_client.h
@@ -43,6 +43,7 @@ int pa_raop_client_teardown(pa_raop_client *c);
 
 int pa_raop_client_udp_is_alive(pa_raop_client *c);
 int pa_raop_client_udp_can_stream(pa_raop_client *c);
+int pa_raop_client_udp_stream(pa_raop_client *c);
 
 void pa_raop_client_set_encryption(pa_raop_client *c, int encryption);
 pa_volume_t pa_raop_client_adjust_volume(pa_raop_client *c, pa_volume_t volume);
-- 
2.5.0



More information about the pulseaudio-discuss mailing list