Added --param low-latency-audio

Currently modifies these values these values:
* audio pbuf delay - 32 ms -> 5 ms
* ALSA playback - minimal value
* ALSA audio buffer (internal in UG module) - 20 ms -> 5 ms
* audio mixer, internal audio buffer - 50 ms -> 5 ms
This commit is contained in:
Martin Pulec
2017-02-17 11:15:15 +01:00
parent 8676bed5f5
commit ded740065c
4 changed files with 21 additions and 4 deletions

View File

@@ -668,6 +668,10 @@ static void *audio_receiver_thread(void *arg)
}
struct audio_decoder *dec_state;
dec_state = (struct audio_decoder *) calloc(1, sizeof(struct audio_decoder));
if (get_commandline_param("low-latency-audio")) {
pbuf_set_playout_delay(cp->playout_buffer, 0.005);
}
assert(dec_state != NULL);
cp->decoder_state = dec_state;
dec_state->enabled = true;

View File

@@ -449,8 +449,18 @@ static int audio_play_alsa_reconfigure(void *state, struct audio_desc desc)
maxval = atoi(maxval_str);
}
rc = snd_pcm_hw_params_set_buffer_time_minmax(s->handle, params, &minval, &mindir,
&maxval, &maxdir);
if (get_commandline_param("low-latency-audio")) {
unsigned int val;
int dir;
rc = snd_pcm_hw_params_set_buffer_time_first(s->handle, params,
&val, &dir);
if (rc == 0) {
log_msg(LOG_LEVEL_INFO, "[ALSA play.] Buffer len set to: %c%u\n", dir < 0 ? '-' : dir == 0 ? '=' : '+', val);
}
} else {
rc = snd_pcm_hw_params_set_buffer_time_minmax(s->handle, params, &minval, &mindir,
&maxval, &maxdir);
}
if (rc < 0) {
log_msg(LOG_LEVEL_WARNING, MOD_NAME "Warning - unable to set buffer to its size: %s\n",
snd_strerror(rc));
@@ -490,7 +500,7 @@ static int audio_play_alsa_reconfigure(void *state, struct audio_desc desc)
jitter_buffer_reset(s->buf);
#else
audio_buffer_destroy(s->buf);
s->buf = audio_buffer_init(s->desc.sample_rate, s->desc.bps, s->desc.ch_count, 20);
s->buf = audio_buffer_init(s->desc.sample_rate, s->desc.bps, s->desc.ch_count, get_commandline_param("low-latency-audio") ? 20 : 5);
#endif
s->timestamp = 0;
pthread_create(&s->thread_id, NULL, worker, s);

View File

@@ -124,7 +124,7 @@ static void mixer_dummy_rtp_callback(struct rtp *session [[gnu::unused]], rtp_ev
struct am_participant {
am_participant(struct socket_udp_local *l, struct sockaddr_storage *ss, string const & audio_codec) {
assert(l != nullptr && ss != nullptr);
m_buffer = audio_buffer_init(SAMPLE_RATE, BPS, CHANNELS, 50);
m_buffer = audio_buffer_init(SAMPLE_RATE, BPS, CHANNELS, get_commandline_param("low-latency-audio") ? 50 : 5);
assert(m_buffer != NULL);
struct sockaddr *sa = (struct sockaddr *) ss;
assert(ss->ss_family == AF_INET || ss->ss_family == AF_INET6);

View File

@@ -328,6 +328,9 @@ void print_param_doc()
}
}
// some common parameters used within multiple modules
ADD_TO_PARAM_DOC(low_latency_audio, "* low-latency-audio\n"
" Try to reduce audio latency at the expense of worse reliability\n");
ADD_TO_PARAM_DOC(ldgm_device, "* window-title=<title>\n"
" Use alternative window title (SDL/GL only)\n");