Merge pull request #2554 from metalefty/v0.9-cherry-pick
[v0.9] cherry-pick sound related improvements
This commit is contained in:
commit
00d9b29fcc
@ -88,6 +88,27 @@ static struct xr_wave_format_ex **g_client_formats = NULL;
|
||||
|
||||
static int g_current_format = 0; /* index in g_client_formats */
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/*
|
||||
* This can be called from sound.c because it includes audin.h.
|
||||
*/
|
||||
|
||||
const char *
|
||||
audin_wave_format_tag_to_str(int tag)
|
||||
{
|
||||
return
|
||||
(tag == WAVE_FORMAT_PCM) ? "WAVE_FORMAT_PCM" :
|
||||
(tag == WAVE_FORMAT_ADPCM) ? "WAVE_FORMAT_ADPCM" :
|
||||
(tag == WAVE_FORMAT_ALAW) ? "WAVE_FORMAT_ALAW" :
|
||||
(tag == WAVE_FORMAT_MULAW) ? "WAVE_FORMAT_MULAW" :
|
||||
(tag == WAVE_FORMAT_MULAW) ? "WAVE_FORMAT_MULAW" :
|
||||
(tag == WAVE_FORMAT_MPEGLAYER3) ? "WAVE_FORMAT_MPEGLAYER3" :
|
||||
(tag == WAVE_FORMAT_OPUS) ? "WAVE_FORMAT_OPUS" :
|
||||
(tag == WAVE_FORMAT_AAC) ? "WAVE_FORMAT_AAC" :
|
||||
"UNKNOWN";
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
static int
|
||||
cleanup_client_formats(void)
|
||||
@ -261,9 +282,17 @@ audin_process_formats(int chan_id, struct stream *s)
|
||||
in_uint16_le(s, wf->nBlockAlign);
|
||||
in_uint16_le(s, wf->wBitsPerSample);
|
||||
in_uint16_le(s, wf->cbSize);
|
||||
LOG_DEVEL(LOG_LEVEL_INFO, "audin_process_formats: recved format wFormatTag 0x%4.4x "
|
||||
"nChannels %d nSamplesPerSec %d",
|
||||
wf->wFormatTag, wf->nChannels, wf->nSamplesPerSec);
|
||||
|
||||
LOG(LOG_LEVEL_INFO, "audin_process_formats:");
|
||||
LOG(LOG_LEVEL_INFO, " wFormatNo %d", index);
|
||||
LOG(LOG_LEVEL_INFO, " wFormatTag %s", audin_wave_format_tag_to_str(wf->wFormatTag));
|
||||
LOG(LOG_LEVEL_INFO, " nChannels %d", wf->nChannels);
|
||||
LOG(LOG_LEVEL_INFO, " nSamplesPerSec %d", wf->nSamplesPerSec);
|
||||
LOG(LOG_LEVEL_INFO, " nAvgBytesPerSec %d", wf->nAvgBytesPerSec);
|
||||
LOG(LOG_LEVEL_INFO, " nBlockAlign %d", wf->nBlockAlign);
|
||||
LOG(LOG_LEVEL_INFO, " wBitsPerSample %d", wf->wBitsPerSample);
|
||||
LOG(LOG_LEVEL_INFO, " cbSize %d", wf->cbSize);
|
||||
|
||||
if (wf->cbSize > 0)
|
||||
{
|
||||
if (!s_check_rem(s, wf->cbSize))
|
||||
|
||||
@ -22,6 +22,8 @@
|
||||
#ifndef _AUDIN_H_
|
||||
#define _AUDIN_H_
|
||||
|
||||
const char *
|
||||
audin_wave_format_tag_to_str(int tag);
|
||||
int
|
||||
audin_init(void);
|
||||
int
|
||||
|
||||
@ -369,14 +369,15 @@ sound_process_output_format(int aindex, int wFormatTag, int nChannels,
|
||||
int nBlockAlign, int wBitsPerSample,
|
||||
int cbSize, char *data)
|
||||
{
|
||||
LOG_DEVEL(LOG_LEVEL_INFO, "sound_process_output_format:");
|
||||
LOG_DEVEL(LOG_LEVEL_INFO, " wFormatTag %d", wFormatTag);
|
||||
LOG_DEVEL(LOG_LEVEL_INFO, " nChannels %d", nChannels);
|
||||
LOG_DEVEL(LOG_LEVEL_INFO, " nSamplesPerSec %d", nSamplesPerSec);
|
||||
LOG_DEVEL(LOG_LEVEL_INFO, " nAvgBytesPerSec %d", nAvgBytesPerSec);
|
||||
LOG_DEVEL(LOG_LEVEL_INFO, " nBlockAlign %d", nBlockAlign);
|
||||
LOG_DEVEL(LOG_LEVEL_INFO, " wBitsPerSample %d", wBitsPerSample);
|
||||
LOG_DEVEL(LOG_LEVEL_INFO, " cbSize %d", cbSize);
|
||||
LOG(LOG_LEVEL_INFO, "sound_process_output_format:");
|
||||
LOG(LOG_LEVEL_INFO, " wFormatNo %d", aindex);
|
||||
LOG(LOG_LEVEL_INFO, " wFormatTag %s", audin_wave_format_tag_to_str(wFormatTag));
|
||||
LOG(LOG_LEVEL_INFO, " nChannels %d", nChannels);
|
||||
LOG(LOG_LEVEL_INFO, " nSamplesPerSec %d", nSamplesPerSec);
|
||||
LOG(LOG_LEVEL_INFO, " nAvgBytesPerSec %d", nAvgBytesPerSec);
|
||||
LOG(LOG_LEVEL_INFO, " nBlockAlign %d", nBlockAlign);
|
||||
LOG(LOG_LEVEL_INFO, " wBitsPerSample %d", wBitsPerSample);
|
||||
LOG(LOG_LEVEL_INFO, " cbSize %d", cbSize);
|
||||
|
||||
LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, "", data, cbSize);
|
||||
|
||||
@ -898,6 +899,8 @@ sound_send_wave_data_chunk(char *data, int data_bytes)
|
||||
format_index = g_current_client_format_index;
|
||||
data_bytes = sound_wave_compress(data, data_bytes, &format_index);
|
||||
|
||||
LOG(LOG_LEVEL_TRACE, "sound_send_wave_data_chunk: wFormatNo %d", format_index);
|
||||
|
||||
/* part one of 2 PDU wave info */
|
||||
|
||||
LOG_DEVEL(LOG_LEVEL_DEBUG, "sound_send_wave_data_chunk: sending %d bytes", data_bytes);
|
||||
@ -1057,7 +1060,7 @@ sound_process_wave_confirm(struct stream *s, int size)
|
||||
in_uint8(s, cConfirmedBlockNo);
|
||||
time_diff = time - g_sent_time[cConfirmedBlockNo & 0xff];
|
||||
|
||||
LOG(LOG_LEVEL_DEBUG, "sound_process_wave_confirm: wTimeStamp %d, "
|
||||
LOG(LOG_LEVEL_TRACE, "sound_process_wave_confirm: wTimeStamp %d, "
|
||||
"cConfirmedBlockNo %d time diff %d",
|
||||
wTimeStamp, cConfirmedBlockNo, time_diff);
|
||||
|
||||
@ -1089,12 +1092,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:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user