channels/rdpsnd: added more ALSA debug output

This commit is contained in:
Marc-André Moreau 2013-02-24 22:32:48 -05:00
parent 71a205a21e
commit c22e5181c1

View File

@ -104,28 +104,27 @@ int rdpsnd_alsa_set_hw_params(rdpsndAlsaPlugin* alsa)
status = snd_pcm_hw_params_set_format(alsa->pcm_handle, hw_params, alsa->format);
SND_PCM_CHECK("snd_pcm_hw_params_set_format", status);
/* Set sample rate */
status = snd_pcm_hw_params_set_rate_near(alsa->pcm_handle, hw_params, &alsa->actual_rate, NULL);
SND_PCM_CHECK("snd_pcm_hw_params_set_rate_near", status);
/* Set number of channels */
status = snd_pcm_hw_params_set_channels(alsa->pcm_handle, hw_params, alsa->actual_channels);
SND_PCM_CHECK("snd_pcm_hw_params_set_channels", status);
status = snd_pcm_hw_params_set_channels_near(alsa->pcm_handle, hw_params, &alsa->actual_channels);
SND_PCM_CHECK("snd_pcm_hw_params_set_channels_near", status);
/* Set sample rate */
status = snd_pcm_hw_params_set_rate(alsa->pcm_handle, hw_params, alsa->actual_rate, 0);
SND_PCM_CHECK("snd_pcm_hw_params_set_rate", status);
status = snd_pcm_hw_params_set_rate_near(alsa->pcm_handle, hw_params, &alsa->actual_rate, NULL);
SND_PCM_CHECK("snd_pcm_hw_params_set_rate_near", status);
/* Get maximum buffer size */
status = snd_pcm_hw_params_get_buffer_size_max(hw_params, &alsa->buffer_size);
SND_PCM_CHECK("snd_pcm_hw_params_get_buffer_size_max", status);
/* Set buffer size */
//status = snd_pcm_hw_params_set_buffer_size(alsa->pcm_handle, hw_params, alsa->buffer_size);
//SND_PCM_CHECK("snd_pcm_hw_params_set_buffer_size", status);
status = snd_pcm_hw_params_set_buffer_size_near(alsa->pcm_handle, hw_params, &alsa->buffer_size);
SND_PCM_CHECK("snd_pcm_hw_params_set_buffer_size_near", status);
/* Set period time */
/* Get period size */
status = snd_pcm_hw_params_get_period_size_min(hw_params, &alsa->period_size, NULL);
SND_PCM_CHECK("snd_pcm_hw_params_get_period_size_min", status);
/* Set period size */
status = snd_pcm_hw_params_set_period_size_near(alsa->pcm_handle, hw_params, &alsa->period_size, NULL);
SND_PCM_CHECK("snd_pcm_hw_params_set_period_size_near", status);
@ -142,10 +141,7 @@ int rdpsnd_alsa_set_sw_params(rdpsndAlsaPlugin* alsa)
int status;
snd_pcm_sw_params_t* sw_params;
if (alsa->latency == 0)
alsa->start_threshold = 0;
else
alsa->start_threshold = alsa->buffer_size / 2;
alsa->start_threshold = alsa->period_size;
status = snd_pcm_sw_params_malloc(&sw_params);
SND_PCM_CHECK("snd_pcm_sw_params_malloc", status);
@ -156,6 +152,9 @@ int rdpsnd_alsa_set_sw_params(rdpsndAlsaPlugin* alsa)
status = snd_pcm_sw_params_set_start_threshold(alsa->pcm_handle, sw_params, alsa->start_threshold);
SND_PCM_CHECK("snd_pcm_sw_params_set_start_threshold", status);
status = snd_pcm_sw_params_set_avail_min(alsa->pcm_handle, sw_params, alsa->buffer_size / 2);
SND_PCM_CHECK("snd_pcm_sw_params_set_avail_min", status);
status = snd_pcm_sw_params(alsa->pcm_handle, sw_params);
SND_PCM_CHECK("snd_pcm_sw_params", status);
@ -167,6 +166,20 @@ int rdpsnd_alsa_set_sw_params(rdpsndAlsaPlugin* alsa)
return 0;
}
int rdpsnd_alsa_validate_params(rdpsndAlsaPlugin* alsa)
{
int status;
snd_pcm_uframes_t buffer_size;
snd_pcm_uframes_t period_size;
status = snd_pcm_get_params(alsa->pcm_handle, &buffer_size, &period_size);
SND_PCM_CHECK("snd_pcm_get_params", status);
printf("Parameters: BufferSize: %d PeriodSize: %d\n", buffer_size, period_size);
return 0;
}
static int rdpsnd_alsa_set_params(rdpsndAlsaPlugin* alsa)
{
/**
@ -190,23 +203,14 @@ static int rdpsnd_alsa_set_params(rdpsndAlsaPlugin* alsa)
snd_pcm_drop(alsa->pcm_handle);
if (alsa->latency < 0)
alsa->buffer_size = alsa->actual_rate * 4 / 10; /* Default to 400ms buffer */
else
alsa->buffer_size = alsa->latency * alsa->actual_rate * 2 / 1000; /* Double of the latency */
if (alsa->buffer_size < alsa->actual_rate / 2)
alsa->buffer_size = alsa->actual_rate / 2; /* Minimum 0.5-second buffer */
printf("ALSA #1: BufferSize: %d Latency: %d Rate: %d Channels: %d\n",
alsa->buffer_size, alsa->latency, alsa->actual_rate, alsa->actual_channels);
if (rdpsnd_alsa_set_hw_params(alsa) < 0)
return -1;
if (rdpsnd_alsa_set_sw_params(alsa) < 0)
return -1;
rdpsnd_alsa_validate_params(alsa);
return 0;
}
@ -455,7 +459,7 @@ static void* rdpsnd_alsa_schedule_thread(void* arg)
wInitialTime = GetTickCount();
wFixedLatency = 250;
wFixedLatency = 340;
wAverageLatency = wFixedLatency / 2;
wAverageSleepLatency = wFixedLatency / 2;
@ -479,14 +483,10 @@ static void* rdpsnd_alsa_schedule_thread(void* arg)
}
else if (message.id == 1)
{
UINT16 wAudioLength;
waveInfo = (RDPSND_WAVE_INFO*) message.wParam;
data = waveInfo->data;
length = waveInfo->length;
frames = length / frame_size;
wAudioLength = frames / (alsa->actual_rate / 1000);
}
offset = 0;
@ -496,12 +496,23 @@ static void* rdpsnd_alsa_schedule_thread(void* arg)
{
available_input = (length - offset) / frame_size;
if (available_output < 1)
while (available_output < (alsa->buffer_size / 4))
{
snd_pcm_wait(alsa->pcm_handle, -1);
available_output = snd_pcm_avail_update(alsa->pcm_handle);
}
if (available_output > alsa->buffer_size)
{
int gap_ms;
int gap_frames;
gap_frames = available_output - alsa->buffer_size;
gap_ms = gap_frames / (alsa->actual_rate / 1000);
printf("Buffer Underrun Gap: %d ms\n", gap_ms);
}
status = snd_pcm_writei(alsa->pcm_handle, &data[offset],
(available_input < available_output) ? available_input : available_output);
@ -553,6 +564,8 @@ static void* rdpsnd_alsa_schedule_thread(void* arg)
else
wSleepLatency = 0;
wSleepLatency = 0;
wAverageSleepLatency = (wAverageSleepLatency + wSleepLatency) / 2;
Sleep(wSleepLatency);