]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Add source rate calculation based on source frame and timing information, calculated...
authorMike Brady <mikebrady@eircom.net>
Mon, 13 Aug 2018 13:44:22 +0000 (14:44 +0100)
committerMike Brady <mikebrady@eircom.net>
Mon, 13 Aug 2018 13:44:22 +0000 (14:44 +0100)
player.c
player.h
rtp.c

index f2e1a7fdc1eff2c0bebc2a2ab23142df74c88160..0d867069ebe32251a1a0fa824c998e8ed798a64f 100644 (file)
--- a/player.c
+++ b/player.c
@@ -1785,9 +1785,10 @@ void *player_thread_func(void *arg) {
                "min DAC queue size, "
                "min buffer occupancy, "
                "max buffer occupancy, "
-               "input frames per second, "
+               "source frames per second, "
+               "average input frames per second, "
                "output frames per second, "
-               "drift client vs local clock in ppm");
+               "client:local clock drift in ppm");
       } else {
         inform("sync error in milliseconds, "
                "total packets, "
@@ -2414,7 +2415,8 @@ void *player_thread_func(void *arg) {
                          "%*lli," /* min DAC queue size */
                          "%*d,"   /* min buffer occupancy */
                          "%*d,"   /* max buffer occupancy */
-                         "%*.2f," /* input frame rate */
+                         "%*.2f," /* remote frame rate */
+                         "%*.2f," /* actual (average) input frame rate */
                          "%*.2f," /* output frame rate */
                          "%*.2f," /* output frame rate */
                          "%*d",   /* sample count */
@@ -2426,7 +2428,12 @@ void *player_thread_func(void *arg) {
                          12, play_number, 7, conn->missing_packets, 7, conn->late_packets, 7,
                          conn->too_late_packets, 7, conn->resend_requests, 7,
                          minimum_dac_queue_size, 5, minimum_buffer_occupancy, 5,
-                         maximum_buffer_occupancy, 11, conn->input_frame_rate, 11, conn->frame_rate ,  10, (1.0-conn->local_to_remote_time_gradient)*1000000, 6, conn->local_to_remote_time_gradient_sample_count);
+                         maximum_buffer_occupancy,
+                         11, conn->remote_frame_rate,
+                         11, conn->input_frame_rate,
+                         11, conn->frame_rate ,
+                         10, (1.0-conn->local_to_remote_time_gradient)*1000000,
+                         6, conn->local_to_remote_time_gradient_sample_count);
                 } else {
                   inform("%*.2f," /* Sync error in milliseconds */
                          "%*d,"   /* total packets */
index a7d961a580cc01ea4000748394928d8ad9ca273d..783c51657f4b43aed396e6696a3b26dc077cc680 100644 (file)
--- a/player.h
+++ b/player.h
@@ -191,6 +191,11 @@ typedef struct {
   uint64_t remote_reference_timestamp_time;  
 
   
+  // used as the initials values for calculating the rate at which the source thinks it's sending frames
+  int64_t initial_reference_timestamp;
+  uint64_t initial_reference_time;
+  double remote_frame_rate;
+
   // the ratio of the following should give us the operating rate, nominally 44,100
   int64_t reference_to_previous_frame_difference;
   uint64_t reference_to_previous_time_difference;
diff --git a/rtp.c b/rtp.c
index 96bb0fcf8bd0f0a109a8207ad7dc4eb111460ffd..6747724f01a6f536918a0dd4d9252d495efd900e 100644 (file)
--- a/rtp.c
+++ b/rtp.c
@@ -356,6 +356,17 @@ void *rtp_control_receiver(void *arg) {
             }
 
             debug_mutex_lock(&conn->reference_time_mutex, 1000, 1);
+            
+            if (conn->initial_reference_time==0) {
+              conn->initial_reference_time = remote_time_of_sync;
+              conn->initial_reference_timestamp = sync_rtp_timestamp;
+            } else {
+              uint64_t remote_frame_time_interval = conn->remote_reference_timestamp_time - conn->initial_reference_time; // here, this should never be zero
+              if (remote_frame_time_interval) {
+                conn->remote_frame_rate = (1.0 * (conn->reference_timestamp - conn->initial_reference_timestamp)) / remote_frame_time_interval; // an IEEE double calculation with two 64-bit integers
+                conn->remote_frame_rate = conn->remote_frame_rate * (uint64_t)0x100000000; // this should just change the [binary] exponent in the IEEE FP representation; the mantissa should be unaffected.
+              }            
+            }
 
             // this is for debugging
             uint64_t old_remote_reference_time = conn->remote_reference_timestamp_time;