From 9fe9ae3bc0c292e75f90667e3645882a178d1b00 Mon Sep 17 00:00:00 2001 From: Hiero32 <112747353+Hiero32@users.noreply.github.com> Date: Sat, 25 Mar 2023 20:20:42 +0900 Subject: [PATCH] Support to set parameters from sesman.ini. --- docs/man/sesman.ini.5.in | 18 ++++++++++++++++++ sesman/chansrv/chansrv_config.c | 18 ++++++++++++++++++ sesman/chansrv/chansrv_config.h | 6 ++++++ sesman/chansrv/sound.c | 14 +++++++++++--- sesman/sesman.ini.in | 10 ++++++++++ 5 files changed, 63 insertions(+), 3 deletions(-) diff --git a/docs/man/sesman.ini.5.in b/docs/man/sesman.ini.5.in index 2a9db919..e632c138 100644 --- a/docs/man/sesman.ini.5.in +++ b/docs/man/sesman.ini.5.in @@ -359,6 +359,24 @@ GNOME 3 versions later than 3.29.92. Do not use this for any other reason. This setting will be removed in a later version of xrdp, when GNOME 3 is no longer supported. +.TP +\fBSoundNumSilentFramesAAC\fR=\fInumber\fR +Sets the \fInumber\fR of silent frames which are sent to client before close +message is sent, when AAC is selected. If set to 0, no silent frame is sent. +If not specified, defaults to \fI4\fR. + +.TP +\fBSoundNumSilentFramesMP3\fR=\fInumber\fR +Sets the \fInumber\fR of silent frames which are sent to client before close +message is sent, when MP3 is selected. If set to 0, no silent frame is sent. +If not specified, defaults to \fI2\fR. + +.TP +\fBSoundMsecDoNotSend\fR=\fInumber\fR +Sets the duration(msec). Sound data is not send to client during \fInumber\fR +millisecond(s) after close message is sent, when AAC/MP3 is selected. +If set to 0, all the data is sent. If not specified, defaults to \fI1000\fR. + .SH "SESSIONS VARIABLES" All entries in the \fB[SessionVariables]\fR section are set as environment variables in the user's session. diff --git a/sesman/chansrv/chansrv_config.c b/sesman/chansrv/chansrv_config.c index dd902d99..2fba79ae 100644 --- a/sesman/chansrv/chansrv_config.c +++ b/sesman/chansrv/chansrv_config.c @@ -41,6 +41,9 @@ #define DEFAULT_FUSE_MOUNT_NAME "xrdp-client" #define DEFAULT_FILE_UMASK 077 #define DEFAULT_USE_NAUTILUS3_FLIST_FORMAT 0 +#define DEFAULT_NUM_SILENT_FRAMES_AAC 4 +#define DEFAULT_NUM_SILENT_FRAMES_MP3 2 +#define DEFAULT_MSEC_DO_NOT_SEND 1000 /** * Type used for passing a logging function about */ @@ -182,6 +185,18 @@ read_config_chansrv(log_func_t logmsg, { cfg->use_nautilus3_flist_format = g_text2bool(value); } + else if (g_strcasecmp(name, "SoundNumSilentFramesAAC") == 0) + { + cfg->num_silent_frames_aac = strtoul(value, NULL, 0); + } + else if (g_strcasecmp(name, "SoundNumSilentFramesMP3") == 0) + { + cfg->num_silent_frames_mp3 = strtoul(value, NULL, 0); + } + else if (g_strcasecmp(name, "SoundMsecDoNotSend") == 0) + { + cfg->msec_do_not_send = strtoul(value, NULL, 0); + } } return error; @@ -213,6 +228,9 @@ new_config(void) cfg->fuse_mount_name = fuse_mount_name; cfg->file_umask = DEFAULT_FILE_UMASK; cfg->use_nautilus3_flist_format = DEFAULT_USE_NAUTILUS3_FLIST_FORMAT; + cfg->num_silent_frames_aac = DEFAULT_NUM_SILENT_FRAMES_AAC; + cfg->num_silent_frames_mp3 = DEFAULT_NUM_SILENT_FRAMES_MP3; + cfg->msec_do_not_send = DEFAULT_MSEC_DO_NOT_SEND; } return cfg; diff --git a/sesman/chansrv/chansrv_config.h b/sesman/chansrv/chansrv_config.h index f328256e..7a5fbe4c 100644 --- a/sesman/chansrv/chansrv_config.h +++ b/sesman/chansrv/chansrv_config.h @@ -38,6 +38,12 @@ struct config_chansrv /** Whether to use nautilus3-compatible file lists for the clipboard */ int use_nautilus3_flist_format; + + /** Number of silent frames to send before SNDC_CLOSE is sent, setting from sesman.ini */ + unsigned int num_silent_frames_aac; + unsigned int num_silent_frames_mp3; + /** Do net send sound data afer SNDC_CLOSE is sent. unit is millisecond, setting from sesman.ini */ + unsigned int msec_do_not_send; }; diff --git a/sesman/chansrv/sound.c b/sesman/chansrv/sound.c index 5790263e..c7680b32 100644 --- a/sesman/chansrv/sound.c +++ b/sesman/chansrv/sound.c @@ -34,6 +34,7 @@ #include "xrdp_constants.h" #include "xrdp_sockets.h" #include "chansrv_common.h" +#include "chansrv_config.h" #include "list.h" #include "audin.h" @@ -60,6 +61,7 @@ static lame_global_flags *g_lame_encoder = 0; extern int g_rdpsnd_chan_id; /* in chansrv.c */ extern int g_display_num; /* in chansrv.c */ +extern struct config_chansrv *g_cfg; /* in chansrv.c */ /* audio out: sound_server -> xrdp -> NeutrinoRDP */ static struct trans *g_audio_l_trans_out = 0; /* listener */ @@ -1099,9 +1101,9 @@ process_pcm_message(int id, int size, struct stream *s) case 0: if ((g_client_does_fdk_aac || g_client_does_mp3lame) && sending_silence) { - if ((g_time3() - silence_start_time) < 1000) + if ((g_time3() - silence_start_time) < (int)g_cfg->msec_do_not_send) { - /* do not send data within 1000mS after SNDC_CLOSE is sent. to avoid stutter */ + /* do not send data within msec_do_not_send msec after SNDC_CLOSE is sent, to avoid stutter. setting from sesman.ini */ return 0; } sending_silence = 0; @@ -1112,7 +1114,7 @@ process_pcm_message(int id, int size, struct stream *s) if ((g_client_does_fdk_aac || g_client_does_mp3lame) && sending_silence == 0) { /* workaround for mstsc.exe. send silence data before send close */ - int send_silence_times = g_client_does_fdk_aac ? 4 : 2; /* This value comes by trial and error */ + int send_silence_times = g_client_does_fdk_aac ? g_cfg->num_silent_frames_aac : g_cfg->num_silent_frames_mp3; /* setting from sesman.ini */ char *buf = (char *) g_malloc(g_bbuf_size, 0); if (buf != NULL) { @@ -1291,6 +1293,12 @@ sound_init(void) } list_clear(g_ack_time_diff); +#if defined(XRDP_FDK_AAC) || defined(XRDP_MP3LAME) + LOG(LOG_LEVEL_INFO, "num_silent_frames_aac: %d", g_cfg->num_silent_frames_aac); + LOG(LOG_LEVEL_INFO, "num_silent_frames_mp3: %d", g_cfg->num_silent_frames_mp3); + LOG(LOG_LEVEL_INFO, "msec_do_not_send: %d", g_cfg->msec_do_not_send); +#endif + return 0; } diff --git a/sesman/sesman.ini.in b/sesman/sesman.ini.in index 746c49a5..e14ff02b 100644 --- a/sesman/sesman.ini.in +++ b/sesman/sesman.ini.in @@ -152,6 +152,16 @@ FileUmask=077 ; and up, and you wish to cut-paste files between Nautilus and Windows. Do ; not use this setting for GNOME 4, or other file managers #UseNautilus3FlistFormat=true +; sound redirection +; workaround for Microsoft mstsc.exe to suppress noise. +; SoundNumSilentFramesAAC | SoundNumSilentFramesMP3 silent frames are sent before SNDC_CLOSE is sent. +; during SoundMsecDoNotSend mS after SNDC_CLOSE is sent, sound data is not send. +; depending on the environment, it might be necessary to increase values. +; Defaults: SoundNumSilentFramesAAC=4, SoundNumSilentFramesMP3=2, SoundMsecDoNotSend=1000 +; If set to 0, this workaround is not applied. +#SoundNumSilentFramesAAC=4 +#SoundNumSilentFramesMP3=2 +#SoundMsecDoNotSend=1000 [ChansrvLogging] ; Note: one log file is created per display and the LogFile config value