relate initial silence buffer size to the ilent leadin time available

This commit is contained in:
Mike Brady
2019-04-02 12:52:36 +01:00
2 changed files with 23 additions and 16 deletions
+9 -7
View File
@@ -65,7 +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_notified = -1; // for controlling the reporting of whether the output device can do precison delays (alsa->pulsaudio devices can't)
int delay_type_notified = -1; // for controlling the reporting of whether the output device can do precison delays (e.g. alsa->pulsaudio virtual devices can't)
audio_output audio_alsa = {
.name = "alsa",
@@ -1174,9 +1174,6 @@ 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)
debug(1,"update timestamp is zero!");
// user information
if (update_timestamp_ns == 0) {
if (delay_type_notified != 1) {
@@ -1190,7 +1187,7 @@ int delay_and_status(snd_pcm_state_t *state, snd_pcm_sframes_t *delay, enum yndk
delay_type_notified = 0;
}
}
if (update_timestamp_ns == 0) {
ret = snd_pcm_delay (alsa_handle,delay);
} else {
@@ -1356,16 +1353,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) {
@@ -1375,7 +1372,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 {
+14 -9
View File
@@ -961,16 +961,21 @@ 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
// made
// 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 / 5; // 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;
if (local_time_now > conn->first_packet_time_to_play) {