]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
change how the initials size of the silence sent to the dac is calculated, to make...
authorMike Brady <mikebrady@eircom.net>
Tue, 2 Apr 2019 11:24:02 +0000 (12:24 +0100)
committerMike Brady <mikebrady@eircom.net>
Tue, 2 Apr 2019 11:24:02 +0000 (12:24 +0100)
audio_alsa.c
player.c

index 8bb54584a1188f655d66044c0ee4aa1b56bbada5..4be06ee0e57ad2c0ed3bd5c14720fb90359b33bd 100644 (file)
@@ -65,6 +65,7 @@ static void parameters(audio_parameters *info);
 int mute(int do_mute); // returns true if it actually is allowed to use the mute
 static double set_volume;
 static int output_method_signalled = 0; // for reporting whether it's using mmap or not
+int delay_type_notifier = -1; // used for reporting the type of delay
 
 audio_output audio_alsa = {
     .name = "alsa",
@@ -1173,7 +1174,7 @@ int delay_and_status(snd_pcm_state_t *state, snd_pcm_sframes_t *delay, enum yndk
           *using_update_timestamps = YNDK_YES;
       }
       
-/*
+
       if (update_timestamp_ns == 0) {
         if (delay_type_notifier != 1) {
           inform("Note: this output device does not provide timed delay updates via snd_pcm_status_get_*_htstamp(). Is it a virtual rather than a real device? Disable_standby is not available.");
@@ -1185,8 +1186,7 @@ int delay_and_status(snd_pcm_state_t *state, snd_pcm_sframes_t *delay, enum yndk
           delay_type_notifier = 0;
         }
       }
-*/
-               
+       
       if (update_timestamp_ns == 0) {
         ret = snd_pcm_delay    (alsa_handle,delay);
       } else {
@@ -1352,16 +1352,16 @@ int do_play(void *buf, int samples) {
           }
         }
       } else {
-
-        debug(1, "alsa: error %d writing %d samples to alsa device.", ret, samples);
         frame_index = 0;
         measurement_data_is_valid = 0;
         if (ret == -EPIPE) { /* underrun */
+          debug(1, "alsa: underrun while writing %d samples to alsa device.", samples);
           ret = snd_pcm_recover(alsa_handle, ret, debuglev > 0 ? 1 : 0);
           if (ret < 0) {
             warn("alsa: can't recover from SND_PCM_STATE_XRUN: %s.", snd_strerror(ret));
           }
         } else if (ret == -ESTRPIPE) { /* suspended */
+          debug(1, "alsa: suspended while writing %d samples to alsa device.", samples);
           while ((ret = snd_pcm_resume(alsa_handle)) == -EAGAIN) {
             sleep(1); /* wait until the suspend flag is released */
             if (ret < 0) {
@@ -1371,7 +1371,12 @@ int do_play(void *buf, int samples) {
                    snd_strerror(ret));
             }
           }
+        } else {
+          char errorstring[1024];
+          strerror_r(-ret, (char *)errorstring, sizeof(errorstring));
+          debug(1, "alsa: error %d (\"%s\") writing %d samples to alsa device.", ret, (char *)errorstring, samples);
         }
+
       }
     }
   } else {
index 633166846c80f752b6bb541cda03043c7fecff64..a41c66f20b19994b2cea0d3dc70e994edb6d3130 100644 (file)
--- a/player.c
+++ b/player.c
@@ -961,6 +961,20 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) {
                                 conn);
 
             conn->first_packet_time_to_play = should_be_time;
+            
+            // we want the frames of silence sent at the start to be fairly large in case the output
+            // device's minimum buffer size is large. But they can't be greater than the silent lead_in time
+            // which is either the agreed latency or the silent lead-in time specified by the setting
+            // In fact, if should be some fraction of them, to allow for adjustment.
+            
+            int64_t max_dac_delay = conn->latency;
+            if (config.audio_backend_silent_lead_in_time >= 0)
+              max_dac_delay =
+                (int64_t)(config.audio_backend_silent_lead_in_time * conn->input_rate);
+            
+            max_dac_delay = max_dac_delay / 4;
+            
+            // debug(1,"max_dac_delay is %" PRIu64 " frames.", max_dac_delay);           
 
             // now, the size of the initial silence must be affected by the lead-in time.
             // it must be somewhat less than the lead-in time so that dynamic adjustments can be
@@ -968,7 +982,7 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) {
             // to compensate for delays due to paging, etc.
             // The suggestion is that it should be at least 100 ms less than the lead-in time.
 
-            int64_t max_dac_delay = config.output_rate / 10; // so the lead-in time must be greater
+            // int64_t max_dac_delay = config.output_rate / 3; // so the lead-in time must be greater
                                                              // than this, say 0.2 sec, to allow for
                                                              // dynamic adjustment
             int64_t filler_size = max_dac_delay;