]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Move a play session's latency into the play session's data structure, duh.
authorMike Brady <mikebrady@eircom.net>
Tue, 9 Jan 2018 20:54:03 +0000 (20:54 +0000)
committerMike Brady <mikebrady@eircom.net>
Tue, 9 Jan 2018 20:54:03 +0000 (20:54 +0000)
common.h
player.c
player.h
rtp.c
shairport.c

index aa4633b87fd7b4dfbd59a228df92ba3e450fa48e..5c16358b7c21c6dbd2dc201ab03d880a3291f641 100644 (file)
--- a/common.h
+++ b/common.h
@@ -121,7 +121,6 @@ typedef struct {
   char *mdns_name;
   mdns_backend *mdns;
   int buffer_start_fill;
-  int64_t latency;
   int64_t userSuppliedLatency; // overrides all other latencies -- use with caution
   int64_t fixedLatencyOffset;  // add this to all automatic latencies supplied to get the actual total latency
                                // the total latency will be limited to the min and max-latency values, if supplied
index 736fcd07b4cd701501a65edad1b0da394f29834e..f37be4b9cdadf55ee5abfe9f020303729eb71a07 100644 (file)
--- a/player.c
+++ b/player.c
@@ -862,7 +862,7 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) {
               // debug(1, "Output sample ratio is %d", conn->output_sample_ratio);
 
               int64_t delta = (conn->first_packet_timestamp - reference_timestamp) +
-                              config.latency * conn->output_sample_ratio +
+                              conn->latency * conn->output_sample_ratio +
                               (int64_t)(config.audio_backend_latency_offset * config.output_rate);
 
               if (delta >= 0) {
@@ -888,7 +888,7 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) {
           if (conn->first_packet_time_to_play != 0) {
             // recalculate conn->first_packet_time_to_play -- the latency might change
             int64_t delta = (conn->first_packet_timestamp - reference_timestamp) +
-                            config.latency * conn->output_sample_ratio +
+                            conn->latency * conn->output_sample_ratio +
                             (int64_t)(config.audio_backend_latency_offset * config.output_rate);
 
             if (delta >= 0) {
@@ -1088,7 +1088,7 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) {
         int64_t packet_timestamp = curframe->timestamp; // types okay
         int64_t delta = packet_timestamp - reference_timestamp;
         int64_t offset =
-            config.latency * conn->output_sample_ratio +
+            conn->latency * conn->output_sample_ratio +
             (int64_t)(config.audio_backend_latency_offset * config.output_rate) -
             config.audio_backend_buffer_desired_length *
                 config.output_rate; // all arguments are int32_t, so expression promotion okay
@@ -1463,7 +1463,7 @@ static void *player_thread_func(void *arg) {
   // check that there are enough buffers to accommodate the desired latency and the latency offset
 
   int maximum_latency =
-      config.latency + (int)(config.audio_backend_latency_offset * config.output_rate);
+      conn->latency + (int)(config.audio_backend_latency_offset * config.output_rate);
   if ((maximum_latency + (352 - 1)) / 352 + 10 > BUFFER_FRAMES)
     die("Not enough buffers available for a total latency of %d frames. A maximum of %d 352-frame "
         "packets may be accommodated.",
@@ -1841,7 +1841,7 @@ static void *player_thread_func(void *arg) {
             // if negative, the packet will be early -- the delay is less than expected.
 
             sync_error =
-                delay - (config.latency * conn->output_sample_ratio +
+                delay - (conn->latency * conn->output_sample_ratio +
                          (int64_t)(config.audio_backend_latency_offset *
                                    config.output_rate)); // int64_t from int64_t - int32_t, so okay
 
index 2b0a47c7b44e6ef503cff69c22a479522b7c42a6..6310dec79c46a9fb7ddd4c46cacfcf57ad8b9c1a 100644 (file)
--- a/player.h
+++ b/player.h
@@ -63,6 +63,7 @@ typedef struct {
 
 typedef struct {
   int connection_number;           // for debug ID purposes, nothing else...
+  int64_t latency; // the actual latency used for this play session
   int64_t minimum_latency; // set if an a=min-latency: line appears in the ANNOUNCE message; zero otherwise
   int64_t maximum_latency; // set if an a=max-latency: line appears in the ANNOUNCE message; zero otherwise
   
diff --git a/rtp.c b/rtp.c
index c24940ca6f9ad1050763164673a944f8220f821c..7fc1a0352ed31fa04ae30ae58faeeabbefd65224 100644 (file)
--- a/rtp.c
+++ b/rtp.c
@@ -1,7 +1,7 @@
 /*
  * Apple RTP protocol handler. This file is part of Shairport.
  * Copyright (c) James Laird 2013
- * Copyright (c) Mike Brady 2014 -- 2017
+ * Copyright (c) Mike Brady 2014 -- 2018
  * All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person
@@ -225,12 +225,12 @@ void *rtp_control_receiver(void *arg) {
 
         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) {
-          if (config.userSuppliedLatency != config.latency) {
+          if (config.userSuppliedLatency != conn->latency) {
             debug(1,"Using the user-supplied latency: %lld.",config.userSuppliedLatency);           
           }
-          config.latency = config.userSuppliedLatency;
+          conn->latency = config.userSuppliedLatency;
         } else {
           int64_t la =
               sync_rtp_timestamp - rtp_timestamp_less_latency + config.fixedLatencyOffset;
@@ -239,8 +239,8 @@ void *rtp_control_receiver(void *arg) {
           if ((conn->minimum_latency) && (conn->minimum_latency>la))
             la = conn->minimum_latency;    
                   
-          if (la != config.latency) {
-            config.latency = la;
+          if (la != conn->latency) {
+            conn->latency = la;
             debug(1,"New latency: %lld, sync latency: %lld, minimum latency: %lld, maximum latency: %lld, fixed offset: %lld.",
               la,sync_rtp_timestamp - rtp_timestamp_less_latency,conn->minimum_latency,conn->maximum_latency,config.fixedLatencyOffset);
           }
@@ -255,6 +255,7 @@ void *rtp_control_receiver(void *arg) {
           // it's as if the first sync after a flush or resume is the timing of the next packet
           // after the one whose RTP is given. Weird.
         }
+
         pthread_mutex_lock(&conn->reference_time_mutex);
         conn->remote_reference_timestamp_time = remote_time_of_sync;
         conn->reference_timestamp_time =
index e14830eb38385cb1c7a8580dc5cedccada5520ba..ee459fddcdffd3251c80bb8841a6617dfb6a7ca7 100644 (file)
@@ -1108,10 +1108,8 @@ int main(int argc, char **argv) {
   strcat(configuration_file_path, ".conf");
   config.configfile = configuration_file_path;
 
-  config.statistics_requested = 0; // don't print stats in the log
-  config.latency = -1; // -1 means not set. 88200 works well. This is also reset in rtsp.c when play
-                       // is about to start
-  config.userSuppliedLatency = 0; // zero means none supplied
+  //config.statistics_requested = 0; // don't print stats in the log
+  //config.userSuppliedLatency = 0; // zero means none supplied
   config.resyncthreshold = 0.05;  // 50 ms
   config.timeout = 120; // this number of seconds to wait for [more] audio before switching to idle.
   config.tolerance =