From 8583a3bc4e9af2a1be06c82422a7cac1470341ce Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Sat, 12 Mar 2005 03:10:09 +0000 Subject: if no audioOutput specified, we no attempt to detect if there exists a usable oss or alsa device git-svn-id: https://svn.musicpd.org/mpd/trunk@3057 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/audioOutput.c | 108 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 70 insertions(+), 38 deletions(-) (limited to 'src/audioOutput.c') diff --git a/src/audioOutput.c b/src/audioOutput.c index 1186dbe0d..632d1b8dc 100644 --- a/src/audioOutput.c +++ b/src/audioOutput.c @@ -48,55 +48,87 @@ AudioOutput * newAudioOutput(ConfigParam * param) { char * name = NULL; char * format = NULL; char * type = NULL; - BlockParam * bp; - - getBlockParam(AUDIO_OUTPUT_NAME, name, 1); - getBlockParam(AUDIO_OUTPUT_TYPE, type, 1); - - if(findInList(audioOutputPluginList, type, &data)) { - AudioOutputPlugin * plugin = (AudioOutputPlugin *) data; - ret = malloc(sizeof(AudioOutput)); - ret->name = strdup(name); - ret->type = strdup(type); - ret->finishDriverFunc = plugin->finishDriverFunc; - ret->openDeviceFunc = plugin->openDeviceFunc; - ret->playFunc = plugin->playFunc; - ret->dropBufferedAudioFunc = plugin->dropBufferedAudioFunc; - ret->closeDeviceFunc = plugin->closeDeviceFunc; - ret->sendMetdataFunc = plugin->sendMetdataFunc; - ret->open = 0; - - ret->convertAudioFormat = 0; - ret->sameInAndOutFormats = 0; - ret->convBuffer = NULL; - ret->convBufferLen = 0; - - memset(&ret->inAudioFormat, 0, sizeof(AudioFormat)); - memset(&ret->outAudioFormat, 0, sizeof(AudioFormat)); - memset(&ret->reqAudioFormat, 0, sizeof(AudioFormat)); - - getBlockParam(AUDIO_OUTPUT_FORMAT, format, 0); + BlockParam * bp = NULL; + AudioOutputPlugin * plugin = NULL; + + if(param) { + getBlockParam(AUDIO_OUTPUT_NAME, name, 1); + getBlockParam(AUDIO_OUTPUT_TYPE, type, 1); + + if(!findInList(audioOutputPluginList, type, &data)) { + ERROR("couldn't find audio output plugin for type " + "\"%s\" at line %i\n", type, + param->line); + exit(EXIT_FAILURE); + } + plugin = (AudioOutputPlugin *) data; + if(format) { ret->convertAudioFormat = 1; if(0 != parseAudioConfig(&ret->reqAudioFormat, format)) { - ERROR("error parsing format at line %i\n", + ERROR("error parsing format at line %i\n", bp->line); - exit(EXIT_FAILURE); - } + exit(EXIT_FAILURE); + } + } + } + else { + ListNode * node = audioOutputPluginList->firstNode; + + WARNING("No \"%s\" defined in config file\n", + CONF_AUDIO_OUTPUT); + WARNING("Attempt to detect audio output device\n"); + + while(node) { + plugin = (AudioOutputPlugin *) node->data; + if(plugin->testDefaultDeviceFunc) { + WARNING("Attempting to detect a %s audio " + "device\n", plugin->name); + if(plugin->testDefaultDeviceFunc() == 0) { + WARNING("Successfully detected a %s " + "audio device\n", + plugin->name); + break; + } + } + node = node->nextNode; } - if(plugin->initDriverFunc(ret, param) != 0) { - free(ret); - ret = NULL; + if(!node) { + WARNING("Unable to detect an audio device\n"); + return NULL; } + + name = "default detected output"; + type = plugin->name; } - else { - ERROR("couldn't find audio output plugin for type \"%s\" at " - "line %i\n", type, param->line); - exit(EXIT_FAILURE); + + ret = malloc(sizeof(AudioOutput)); + ret->name = strdup(name); + ret->type = strdup(type); + ret->finishDriverFunc = plugin->finishDriverFunc; + ret->openDeviceFunc = plugin->openDeviceFunc; + ret->playFunc = plugin->playFunc; + ret->dropBufferedAudioFunc = plugin->dropBufferedAudioFunc; + ret->closeDeviceFunc = plugin->closeDeviceFunc; + ret->sendMetdataFunc = plugin->sendMetdataFunc; + ret->open = 0; + + ret->convertAudioFormat = 0; + ret->sameInAndOutFormats = 0; + ret->convBuffer = NULL; + ret->convBufferLen = 0; + + memset(&ret->inAudioFormat, 0, sizeof(AudioFormat)); + memset(&ret->outAudioFormat, 0, sizeof(AudioFormat)); + memset(&ret->reqAudioFormat, 0, sizeof(AudioFormat)); + + if(plugin->initDriverFunc(ret, param) != 0) { + free(ret); + ret = NULL; } return ret; -- cgit v1.2.3