Git commit 93e263b1b6c0110dcf467da3841fc279eb3dca72 by Andreas Hartmetz. Committed on 01/08/2011 at 00:24. Pushed by ahartmetz into branch 'master'. Hopefully start fixing device selection in non-PA mode. ...by enumerating actual devices, not sound systems. Restructure the code for better readability in the process. M +45 -34 src/devicemanager.cpp http://commits.kde.org/phonon-vlc/93e263b1b6c0110dcf467da3841fc279eb3dca72 diff --git a/src/devicemanager.cpp b/src/devicemanager.cpp index c4f55a5..0f3b34e 100644 --- a/src/devicemanager.cpp +++ b/src/devicemanager.cpp @@ -140,57 +140,68 @@ void DeviceManager::updateDeviceSublist(const QList &newDevices, QLi } } +static QList vlcAudioOutBackends() +{ + QList ret; + + libvlc_audio_output_t *firstAudioOut = libvlc_audio_output_list_get(libvlc); + if (!firstAudioOut) { + error() << "libVLC:" << LibVLC::errorMessage(); + return ret; + } + for (libvlc_audio_output_t *audioOut = firstAudioOut; audioOut; audioOut = audioOut->p_next) { + ret.append(QByteArray(audioOut->psz_name)); + } + libvlc_audio_output_list_release(firstAudioOut); + + return ret; +} + void DeviceManager::updateDeviceList() { // Lists for audio output devices QList audioOutputDeviceList; + audioOutputDeviceList.append(DeviceInfo("default")); - audioOutputDeviceList.last().capabilities = DeviceInfo::AudioOutput; + DeviceInfo &defaultAudioOutputDevice = audioOutputDeviceList.first(); + defaultAudioOutputDevice.capabilities = DeviceInfo::AudioOutput; if (!LibVLC::self || !libvlc) return; - bool checkpulse = false; + QList audioOutBackends = vlcAudioOutBackends(); + #ifdef PHONON_PULSESUPPORT PulseSupport *pulse = PulseSupport::getInstance(); - checkpulse = pulse->isActive(); + if (pulse && pulse->isActive()) { + if (audioOutBackends.contains("pulse")) { + defaultAudioOutputDevice.isAdvanced = false; + defaultAudioOutputDevice.accessList.append(DeviceAccess("pulse", "default")); + return; + } else { + pulse->enable(false); + } + } #endif - bool haspulse = false; - // Get the list of available audio outputs - libvlc_audio_output_t *audioOutput = libvlc_audio_output_list_get(libvlc); - if (!audioOutput) - error() << "libVLC:" << LibVLC::errorMessage(); + QList knownSoundSystems; + knownSoundSystems << "alsa" << "oss"; + foreach (const QByteArray &soundSystem, knownSoundSystems) { + if (audioOutBackends.contains(soundSystem)) { + const int deviceCount = libvlc_audio_output_device_count(libvlc, soundSystem); - libvlc_audio_output_t *start = audioOutput; - while (audioOutput) { -#ifdef __GNUC__ -#warning this only iters on aouts, not actual devices -#endif - if (checkpulse && qstrcmp(audioOutput->psz_name, "pulse") == 0) { - audioOutputDeviceList.last().isAdvanced = false; - audioOutputDeviceList.last().accessList.append(DeviceAccess("pulse", "default")); - haspulse = true; + for (int i = 0; i < deviceCount; i++) { + const char *idName = libvlc_audio_output_device_id(libvlc, soundSystem, i); + const char *longName = libvlc_audio_output_device_longname(libvlc, soundSystem, i); + + DeviceInfo device(idName, longName, false); + device.accessList.append(DeviceAccess(idName, QString())); + device.capabilities = DeviceInfo::AudioOutput; + audioOutputDeviceList.append(device); + } break; } - - DeviceInfo device(audioOutput->psz_name, - audioOutput->psz_description, - true); - device.accessList.append(DeviceAccess(audioOutput->psz_name, QString())); - device.capabilities = DeviceInfo::AudioOutput; - audioOutputDeviceList.append(device); - - audioOutput = audioOutput->p_next; - } - libvlc_audio_output_list_release(start); - -#ifdef PHONON_PULSESUPPORT - if (haspulse) { - return; } - pulse->enable(false); -#endif updateDeviceSublist(audioOutputDeviceList, m_audioOutputDeviceList); }