From 5c413b14dd589b5d4f8e7f3ec088743988cc9e99 Mon Sep 17 00:00:00 2001 From: Paul Kocialkowski Date: Sat, 13 Oct 2012 10:50:09 +0200 Subject: Init check: check that mixer was correctly started Signed-off-by: Paul Kocialkowski --- audio_hw.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/audio_hw.c b/audio_hw.c index 403f6cd..954c6ea 100644 --- a/audio_hw.c +++ b/audio_hw.c @@ -53,12 +53,19 @@ static uint32_t audio_hw_get_supported_devices(const struct audio_hw_device *dev static int audio_hw_init_check(const struct audio_hw_device *dev) { + struct tinyalsa_audio_device *tinyalsa_audio_device; + LOGD("%s(%p)", __func__, dev); - if(dev != NULL) - return 0; - else - return -EINVAL; + if(dev == NULL) + return -1; + + tinyalsa_audio_device = (struct tinyalsa_audio_device *) dev; + + if(tinyalsa_audio_device->mixer == NULL) + return -1; + + return 0; } static int audio_hw_set_voice_volume(struct audio_hw_device *dev, float volume) @@ -194,14 +201,15 @@ int audio_hw_open(const hw_module_t *module, const char *name, dev->dump = audio_hw_dump; - tinyalsa_mixer_open(&tinyalsa_mixer, TINYALSA_MIXER_CONFIG_FILE); - if(tinyalsa_mixer == NULL) { + rc = tinyalsa_mixer_open(&tinyalsa_mixer, TINYALSA_MIXER_CONFIG_FILE); + if(rc < 0 || tinyalsa_mixer == NULL) { LOGE("Failed to open mixer!"); - } else { - rc = tinyalsa_mixer_set_route(tinyalsa_mixer, AUDIO_DEVICE_OUT_DEFAULT, AUDIO_MODE_NORMAL); - if(rc < 0) { - LOGE("Failed to set default mixer route"); - } + goto error_device; + } + + rc = tinyalsa_mixer_set_route(tinyalsa_mixer, AUDIO_DEVICE_OUT_DEFAULT, AUDIO_MODE_NORMAL); + if(rc < 0) { + LOGE("Failed to set default mixer route"); } tinyalsa_audio_device->mixer = tinyalsa_mixer; @@ -209,6 +217,12 @@ int audio_hw_open(const hw_module_t *module, const char *name, *device = &(dev->common); return 0; + +error_device: + *device = NULL; + free(tinyalsa_audio_device); + + return -1; } struct hw_module_methods_t audio_hw_module_methods = { -- cgit v1.1