sound: fix noise between two playbacks for mp3/aac (#2519)

* sound: fix noise between two playbacks for mp3/aac
* fix sound stuttered on skip operation of vlc
This commit is contained in:
Hiero32 2023-02-09 10:09:04 +09:00 committed by GitHub
parent 4b4989b6a7
commit 1ffe7890d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 0 deletions

View File

@ -1089,12 +1089,41 @@ sound_process_wave_confirm(struct stream *s, int size)
static int
process_pcm_message(int id, int size, struct stream *s)
{
static int sending_silence = 0;
static int silence_start_time = 0;
switch (id)
{
case 0:
if ((g_client_does_fdk_aac || g_client_does_mp3lame) && sending_silence)
{
if ((g_time3() - silence_start_time) < 1000)
{
/* do not send data within 1000mS after SNDC_CLOSE is sent. to avoid stutter */
return 0;
}
sending_silence = 0;
}
return sound_send_wave_data(s->p, size);
break;
case 1:
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 */
char *buf = (char *) g_malloc(g_bbuf_size, 0);
if (buf != NULL)
{
silence_start_time = g_time3();
sending_silence = 1;
for (int i = 0; i < send_silence_times; i++)
{
g_memset(buf, 0, g_bbuf_size);
sound_send_wave_data_chunk(buf, g_bbuf_size);
}
free(buf);
g_time_diff = 0;
}
}
return sound_send_close();
break;
default: