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"
25 * This class manages the list of currently active output devices.
34 AudioDevice::AudioDevice(DeviceManager *manager, const QByteArray &deviceId, const QByteArray &hw_id)
37 static int counter = 0;
39 // Get name from device
40 if (vlcId == "default") {
41 description = "Default audio device";
49 DeviceManager::DeviceManager(Backend *parent)
56 DeviceManager::~DeviceManager()
58 m_audioDeviceList.clear();
61 bool DeviceManager::canOpenDevice() const
67 * Return a positive device id or -1 if device does not exist.
69 int DeviceManager::deviceId(const QByteArray &nameId) const
71 for (int i = 0 ; i < m_audioDeviceList.size() ; ++i) {
72 if (m_audioDeviceList[i].vlcId == nameId)
73 return m_audioDeviceList[i].id;
79 * Get a human-readable description from a device id.
81 QByteArray DeviceManager::deviceDescription(int i_id) const
83 for (int i = 0 ; i < m_audioDeviceList.size() ; ++i) {
84 if (m_audioDeviceList[i].id == i_id)
85 return m_audioDeviceList[i].description;
91 * Update the current list of active devices.
93 void DeviceManager::updateDeviceList()
95 QList<QByteArray> list, list_hw;
96 list.append("default");
99 // Get the list of available audio outputs
100 libvlc_audio_output_t *p_ao_list = libvlc_audio_output_list_get(
101 vlc_instance, vlc_exception);
102 vlcExceptionRaised();
103 libvlc_audio_output_t *p_start = p_ao_list;
106 list.append(p_ao_list->psz_name);
108 p_ao_list = p_ao_list->p_next;
110 libvlc_audio_output_list_release(p_start);
112 for (int i = 0 ; i < list.size() ; ++i) {
113 QByteArray nameId = list.at(i);
114 QByteArray hwId = list_hw.at(i);
115 if (deviceId(nameId) == -1) {
116 // This is a new device, add it
117 qDebug() << "add aout " << nameId.data();
118 m_audioDeviceList.append(AudioDevice(this, nameId, hwId));
119 emit deviceAdded(deviceId(nameId));
122 if (list.size() < m_audioDeviceList.size()) {
123 // A device was removed
124 for (int i = m_audioDeviceList.size() - 1 ; i >= 0 ; --i) {
125 QByteArray currId = m_audioDeviceList[i].vlcId;
126 bool b_found = false;
127 for (int k = list.size() - 1 ; k >= 0 ; --k) {
128 if (currId == list[k]) {
134 emit deviceRemoved(deviceId(currId));
135 m_audioDeviceList.removeAt(i);
142 * Return a list of hardware id.
144 const QList<AudioDevice> DeviceManager::audioOutputDevices() const
146 return m_audioDeviceList;