From 019a569d42ad9edb531a102e5cd65e83e8eabbf2 Mon Sep 17 00:00:00 2001 From: Vic Lee Date: Tue, 21 Jun 2016 14:05:29 +0800 Subject: [PATCH] rdpsnd/server: decrease audio latency and make it configurable. --- channels/rdpsnd/server/rdpsnd_main.c | 21 +++++++++++---------- include/freerdp/server/rdpsnd.h | 3 +++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/channels/rdpsnd/server/rdpsnd_main.c b/channels/rdpsnd/server/rdpsnd_main.c index 7a93ecd9e..a1d1a2522 100644 --- a/channels/rdpsnd/server/rdpsnd_main.c +++ b/channels/rdpsnd/server/rdpsnd_main.c @@ -337,25 +337,26 @@ static UINT rdpsnd_server_select_format(RdpsndServerContext* context, int client goto out; } + if (context->latency <= 0) + context->latency = 50; + context->priv->out_frames = context->src_format.nSamplesPerSec * context->latency / 1000; + if (context->priv->out_frames < 1) + context->priv->out_frames = 1; switch(format->wFormatTag) { case WAVE_FORMAT_DVI_ADPCM: bs = (format->nBlockAlign - 4 * format->nChannels) * 4; - context->priv->out_frames = (format->nBlockAlign * 4 * format->nChannels * 2 / bs + 1) * bs / (format->nChannels * 2); + context->priv->out_frames -= context->priv->out_frames % bs; + if (context->priv->out_frames < bs) + context->priv->out_frames = bs; break; case WAVE_FORMAT_ADPCM: bs = (format->nBlockAlign - 7 * format->nChannels) * 2 / format->nChannels + 2; - context->priv->out_frames = bs * 4; + context->priv->out_frames -= context->priv->out_frames % bs; + if (context->priv->out_frames < bs) + context->priv->out_frames = bs; break; - default: - context->priv->out_frames = 0x4000 / context->priv->src_bytes_per_frame; - break; - } - - if (format->nSamplesPerSec != context->src_format.nSamplesPerSec) - { - context->priv->out_frames = (context->priv->out_frames * context->src_format.nSamplesPerSec + format->nSamplesPerSec - 100) / format->nSamplesPerSec; } context->priv->out_pending_frames = 0; diff --git a/include/freerdp/server/rdpsnd.h b/include/freerdp/server/rdpsnd.h index 701bca69f..463469ddd 100644 --- a/include/freerdp/server/rdpsnd.h +++ b/include/freerdp/server/rdpsnd.h @@ -61,6 +61,9 @@ struct _rdpsnd_server_context /* Server source PCM audio format. Set by server. */ AUDIO_FORMAT src_format; + /* Server audio latency, or buffer size, in milli-seconds. Set by server. */ + int latency; + /* Client supported formats. */ AUDIO_FORMAT* client_formats; int num_client_formats;