From: Mike Brady Date: Tue, 2 Apr 2019 11:24:02 +0000 (+0100) Subject: change how the initials size of the silence sent to the dac is calculated, to make... X-Git-Tag: 3.3rc4~31^2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c687dadd14038e608ceea794a9ac69348988f6df;p=thirdparty%2Fshairport-sync.git change how the initials size of the silence sent to the dac is calculated, to make it pretty large --- diff --git a/audio_alsa.c b/audio_alsa.c index 8bb54584..4be06ee0 100644 --- a/audio_alsa.c +++ b/audio_alsa.c @@ -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 { diff --git a/player.c b/player.c index 63316684..a41c66f2 100644 --- 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;