]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
allow calculation of nominal source frame rates even when the connection is error...
authorMike Brady <mikebrady@eircom.net>
Tue, 2 Apr 2019 14:37:38 +0000 (15:37 +0100)
committerMike Brady <mikebrady@eircom.net>
Tue, 2 Apr 2019 14:37:38 +0000 (15:37 +0100)
audio_alsa.c
player.c
player.h
rtp.c

index ebeff90774ce554f81a43d17a9ccb48f79a38248..d990495941ba3181d2cf9ef6a89642fe1b69d388 100644 (file)
@@ -1191,7 +1191,7 @@ int delay_and_status(snd_pcm_state_t *state, snd_pcm_sframes_t *delay, enum yndk
 
       if (update_timestamp_ns == 0) {
         ret = snd_pcm_delay    (alsa_handle,delay);
-        measurement_data_is_valid = 0; // can't really check frame rates
+        measurement_data_is_valid = 0; // frame rates are likely to be very unreliable if it can't set the update_timestamp, so don't publish them.
       } else {
         *delay = snd_pcm_status_get_delay(alsa_snd_pcm_status);
 
index 9d3b007b70cae293454f60c2fc630147ac962e4f..546b474e492a7da14a6f979e6f3490ed235574a9 100644 (file)
--- a/player.c
+++ b/player.c
@@ -209,7 +209,6 @@ static inline seq_t seq_sum(seq_t a, seq_t b) {
 void reset_input_flow_metrics(rtsp_conn_info *conn) {
   conn->play_number_after_flush = 0;
   conn->packet_count_since_flush = 0;
-  conn->packet_stream_established = 0;
   conn->input_frame_rate_starting_point_is_valid = 0;
   conn->initial_reference_time = 0;
   conn->initial_reference_timestamp = 0;
@@ -892,8 +891,7 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) {
                   curframe->given_timestamp; // we will keep buffering until we are
                                              // supposed to start playing this
               have_sent_prefiller_silence = 0;
-              conn->packet_stream_established = 1;
-
 // debug(1, "First packet timestamp is %" PRId64 ".", conn->first_packet_timestamp);
 
 // say we have started playing here
index daff62366ebfb477350ad93e6915b4ddb611b538..cb197e4a8f2211d8e095be4ebac638d400e64d17 100644 (file)
--- a/player.h
+++ b/player.h
@@ -202,9 +202,6 @@ typedef struct {
   uint32_t reference_timestamp;
   uint64_t remote_reference_timestamp_time;
 
-  int packet_stream_established; // true if a stream of packets is flowing, made true by a first
-                                 // packet, false by a flush
-
   // used as the initials values for calculating the rate at which the source thinks it's sending
   // frames
   uint32_t initial_reference_timestamp;
diff --git a/rtp.c b/rtp.c
index 35a74ecd223be55ed788bccd53a4c48d771c3eaf..94de81c2356de4401b8a68e3ad44091e6a3b203b 100644 (file)
--- a/rtp.c
+++ b/rtp.c
@@ -381,28 +381,26 @@ void *rtp_control_receiver(void *arg) {
 
             debug_mutex_lock(&conn->reference_time_mutex, 1000, 0);
 
-            if (conn->packet_stream_established) {
-              if (conn->initial_reference_time == 0) {
-                conn->initial_reference_time = remote_time_of_sync;
-                conn->initial_reference_timestamp = sync_rtp_timestamp;
+            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 a 32-bit
+                                                // numerator and 64-bit denominator
+                                                // 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.
               } 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 a 32-bit
-                                                  // numerator and 64-bit denominator
-                                                  // 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.
-                } else {
-                  conn->remote_frame_rate = 0.0; // use as a flag.
-                }
+                conn->remote_frame_rate = 0.0; // use as a flag.
               }
             }
 
@@ -1088,8 +1086,7 @@ int sanitised_source_rate_information(uint32_t *frames, uint64_t *time, rtsp_con
   *frames = fs;
   uint64_t one_fp = (uint64_t)(0x100000000); // one second in fp form
   *time = one_fp;
-  if ((conn->packet_stream_established) && (conn->initial_reference_time) &&
-      (conn->initial_reference_timestamp)) {
+  if ((conn->initial_reference_time) && (conn->initial_reference_timestamp)) {
     //    uint32_t local_frames = conn->reference_timestamp - conn->initial_reference_timestamp;
     uint32_t local_frames =
         modulo_32_offset(conn->initial_reference_timestamp, conn->reference_timestamp);