From f24c4df73ff25bf69e1bc2165fd3273c0c50cb8d Mon Sep 17 00:00:00 2001 From: f-jjth Date: Mon, 19 Aug 2013 14:36:13 +0200 Subject: [PATCH] Improve OpenAL driver for IAXClient Abort OpenAL initialization if input device are not found in this way we don't create and merge new OpenAL context with SGSoundMgr Close OpenAL context and input device when FG is stopped --- utils/iaxclient/lib/audio_openal.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/utils/iaxclient/lib/audio_openal.c b/utils/iaxclient/lib/audio_openal.c index fbc9c4b02..30d821239 100644 --- a/utils/iaxclient/lib/audio_openal.c +++ b/utils/iaxclient/lib/audio_openal.c @@ -248,6 +248,12 @@ int openal_mic_boost_set(struct iaxc_audio_driver *d, int enable) int openal_destroy(struct iaxc_audio_driver *d) { + struct openal_priv_data* priv = (struct openal_priv_data*)(d->priv); + + alcCaptureStop(priv->in_dev); + alcCaptureCloseDevice(priv->in_dev); + alDeleteSources(1, &priv->source); + return 0; } @@ -256,11 +262,19 @@ int openal_initialize(struct iaxc_audio_driver *d, int sample_rate) struct openal_priv_data* priv = malloc(sizeof(struct openal_priv_data)); int err = alGetError(); d->priv = priv; - + + // First we are looking for input device + priv->in_dev = alcCaptureOpenDevice(NULL, 8000, AL_FORMAT_MONO16, 800); + if (!priv->in_dev) return openal_error("alcCaptureOpenDevice", alGetError()); + + alcCaptureStart(priv->in_dev); + if ((err = alGetError())) return openal_error("alcCaptureStart", err); + + // Then we look for output device priv->out_ctx = alcGetCurrentContext(); if( priv->out_ctx == NULL ) { // FGCom standalone only - ALCdevice* out_dev = alcOpenDevice(0); + ALCdevice* out_dev = alcOpenDevice(NULL); if (out_dev == 0) return openal_error("alcOpenDevice", alGetError()); priv->out_ctx = alcCreateContext(out_dev, 0); @@ -285,12 +299,6 @@ int openal_initialize(struct iaxc_audio_driver *d, int sample_rate) alGenSources(1, &priv->source); if ((err = alGetError())) return openal_error("alGenSources", err); - priv->in_dev = alcCaptureOpenDevice(0, 8000, AL_FORMAT_MONO16, 800); - if (!priv->in_dev) return openal_error("alcCaptureOpenDevice", 0); - - alcCaptureStart(priv->in_dev); - if ((err = alGetError())) return openal_error("alcCaptureStart", err); - d->initialize = openal_initialize; d->destroy = openal_destroy; d->select_devices = openal_select_devices;