1 /* This file is part of the KDE project.
3 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
5 This library is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 2.1 or 3 of the License.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this library. If not, see <http://www.gnu.org/licenses/>.
18 #include "devicemanager.h"
20 //#include "videowidget.h"
21 //#include "widgetrenderer.h"
22 #include "vlcloader.h"
24 #ifdef PHONON_PULSESUPPORT
25 # include <phonon/pulsesupport.h>
29 * This class manages the list of currently active output devices.
38 AudioDevice::AudioDevice(DeviceManager *manager, const QByteArray &deviceId, const QByteArray &hw_id)
41 static int counter = 0;
43 // Get name from device
44 if (vlcId == "default") {
45 description = "Default audio device";
53 DeviceManager::DeviceManager(Backend *parent)
60 DeviceManager::~DeviceManager()
62 m_audioDeviceList.clear();
65 bool DeviceManager::canOpenDevice() const
71 * Return a positive device id or -1 if device does not exist.
73 int DeviceManager::deviceId(const QByteArray &nameId) const
75 for (int i = 0 ; i < m_audioDeviceList.size() ; ++i) {
76 if (m_audioDeviceList[i].vlcId == nameId)
77 return m_audioDeviceList[i].id;
83 * Get a human-readable description from a device id.
85 QByteArray DeviceManager::deviceDescription(int i_id) const
87 for (int i = 0 ; i < m_audioDeviceList.size() ; ++i) {
88 if (m_audioDeviceList[i].id == i_id)
89 return m_audioDeviceList[i].description;
95 * Update the current list of active devices.
97 void DeviceManager::updateDeviceList()
99 QList<QByteArray> list, list_hw;
100 list.append("default");
103 // Get the list of available audio outputs
104 libvlc_audio_output_t *p_ao_list = libvlc_audio_output_list_get(
105 vlc_instance, vlc_exception);
106 vlcExceptionRaised();
107 libvlc_audio_output_t *p_start = p_ao_list;
109 bool checkpulse = false;
110 #ifdef PHONON_PULSESUPPORT
111 PulseSupport *pulse = PulseSupport::getInstance();
112 checkpulse = pulse->isActive();
114 bool haspulse = false;
116 if (checkpulse && 0 == strcmp(p_ao_list->psz_name, "pulse")) {
120 list.append(p_ao_list->psz_name);
122 p_ao_list = p_ao_list->p_next;
124 libvlc_audio_output_list_release(p_start);
127 #ifdef PHONON_PULSESUPPORT
130 pulse->enable(false);
133 for (int i = 0 ; i < list.size() ; ++i) {
134 QByteArray nameId = list.at(i);
135 QByteArray hwId = list_hw.at(i);
136 if (deviceId(nameId) == -1) {
137 // This is a new device, add it
138 qDebug() << "add aout " << nameId.data();
139 m_audioDeviceList.append(AudioDevice(this, nameId, hwId));
140 emit deviceAdded(deviceId(nameId));
143 if (list.size() < m_audioDeviceList.size()) {
144 // A device was removed
145 for (int i = m_audioDeviceList.size() - 1 ; i >= 0 ; --i) {
146 QByteArray currId = m_audioDeviceList[i].vlcId;
147 bool b_found = false;
148 for (int k = list.size() - 1 ; k >= 0 ; --k) {
149 if (currId == list[k]) {
155 emit deviceRemoved(deviceId(currId));
156 m_audioDeviceList.removeAt(i);
163 * Return a list of hardware id.
165 const QList<AudioDevice> DeviceManager::audioOutputDevices() const
167 return m_audioDeviceList;