]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Only allow sync packets after flush or resume to set latency and set an initial defau...
authorMike Brady <mikebrady@eircom.net>
Wed, 10 Jan 2018 13:02:52 +0000 (13:02 +0000)
committerMike Brady <mikebrady@eircom.net>
Wed, 10 Jan 2018 13:02:52 +0000 (13:02 +0000)
player.c
rtp.c

index f37be4b9cdadf55ee5abfe9f020303729eb71a07..27520753524dae600f4716f30a1dfcb9c933319d 100644 (file)
--- a/player.c
+++ b/player.c
@@ -1374,6 +1374,11 @@ static void *player_thread_func(void *arg) {
   conn->first_packet_timestamp = 0;
   conn->flush_requested = 0;
   // conn->fix_volume = 0x10000;
+  
+  if (conn->latency==0) {
+    debug(1,"No latency has (yet) been specified. Setting 99225 (2.25 seconds) frames as a default.");
+    conn->latency = 99225;
+  }
 
   int rc = pthread_mutex_init(&conn->ab_mutex, NULL);
   if (rc)
diff --git a/rtp.c b/rtp.c
index 7fc1a0352ed31fa04ae30ae58faeeabbefd65224..2a24abc3e1fd299386845166babd7bb48b907b4f 100644 (file)
--- a/rtp.c
+++ b/rtp.c
@@ -182,7 +182,7 @@ void *rtp_control_receiver(void *arg) {
   uint8_t packet[2048], *pktp;
   struct timespec tn;
   uint64_t remote_time_of_sync, local_time_now, remote_time_now;
-  int64_t sync_rtp_timestamp, rtp_timestamp_less_latency;
+  int64_t sync_rtp_timestamp;
   ssize_t nread;
   while (conn->please_stop == 0) {
     fd_set readfds;
@@ -223,7 +223,6 @@ void *rtp_control_receiver(void *arg) {
 
         // debug(1,"Remote Sync Time: %0llx.",remote_time_of_sync);
 
-        rtp_timestamp_less_latency = monotonic_timestamp(ntohl(*((uint32_t *)&packet[4])), conn);
         sync_rtp_timestamp = monotonic_timestamp(ntohl(*((uint32_t *)&packet[16])), conn);
         
         if (config.userSuppliedLatency) {
@@ -231,7 +230,8 @@ void *rtp_control_receiver(void *arg) {
             debug(1,"Using the user-supplied latency: %lld.",config.userSuppliedLatency);           
           }
           conn->latency = config.userSuppliedLatency;
-        } else {
+        } else if (packet[0] & 0x10) { // only set latency if it's a packet just after a flush or resume
+          int64_t rtp_timestamp_less_latency = monotonic_timestamp(ntohl(*((uint32_t *)&packet[4])), conn);
           int64_t la =
               sync_rtp_timestamp - rtp_timestamp_less_latency + config.fixedLatencyOffset;
           if ((conn->maximum_latency) && (conn->maximum_latency<la))