mod_portaudio: fix shared stream output device validation/initialization that caused segfault and portaudio errors

This commit is contained in:
Moises Silva 2011-05-18 20:55:51 -04:00
parent 690b3b5b72
commit 792149f32a
1 changed files with 13 additions and 7 deletions

View File

@ -2293,7 +2293,8 @@ PaError open_shared_audio_stream(shared_audio_stream_t *shstream, const PaStream
{ {
PaError err; PaError err;
if (inputParameters->device != -1) { if (inputParameters->device != -1) {
err = OpenAudioStream(&shstream->stream, inputParameters, outputParameters, shstream->sample_rate, err = OpenAudioStream(&shstream->stream, inputParameters->device != -1 ? inputParameters : NULL,
outputParameters->device != -1 ? outputParameters : NULL, shstream->sample_rate,
paClipOff, STREAM_SAMPLES_PER_PACKET(shstream), globals.dual_streams); paClipOff, STREAM_SAMPLES_PER_PACKET(shstream), globals.dual_streams);
} else { } else {
err = OpenAudioStream(&shstream->stream, NULL, outputParameters, shstream->sample_rate, err = OpenAudioStream(&shstream->stream, NULL, outputParameters, shstream->sample_rate,
@ -2319,20 +2320,25 @@ static int create_shared_audio_stream(shared_audio_stream_t *shstream)
inputParameters.hostApiSpecificStreamInfo = NULL; inputParameters.hostApiSpecificStreamInfo = NULL;
} }
outputParameters.device = shstream->outdev; outputParameters.device = shstream->outdev;
if (shstream->outdev != -1) {
outputParameters.channelCount = shstream->channels; outputParameters.channelCount = shstream->channels;
outputParameters.sampleFormat = SAMPLE_TYPE; outputParameters.sampleFormat = SAMPLE_TYPE;
outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency; outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency;
outputParameters.hostApiSpecificStreamInfo = NULL; outputParameters.hostApiSpecificStreamInfo = NULL;
}
err = open_shared_audio_stream(shstream, &inputParameters, &outputParameters); err = open_shared_audio_stream(shstream, &inputParameters, &outputParameters);
if (err != paNoError) { if (err != paNoError) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening audio device retrying\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Error opening audio device retrying (indev = %d, outdev = %d, error = %s)\n",
inputParameters.device, outputParameters.device, Pa_GetErrorText(err));
switch_yield(1000000); switch_yield(1000000);
err = open_shared_audio_stream(shstream, &inputParameters, &outputParameters); err = open_shared_audio_stream(shstream, &inputParameters, &outputParameters);
} }
if (err != paNoError) { if (err != paNoError) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open audio device\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open audio device (indev = %d, outdev = %d, error = %s)\n",
inputParameters.device, outputParameters.device, Pa_GetErrorText(err));
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_ERROR_AUDIO_DEV) == SWITCH_STATUS_SUCCESS) { if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_ERROR_AUDIO_DEV) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Reason", Pa_GetErrorText(err)); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Reason", Pa_GetErrorText(err));
switch_event_fire(&event); switch_event_fire(&event);