]> git.sesse.net Git - vlc/blob - bindings/phonon/vlc/audiooutput.cpp
Add some locking.
[vlc] / bindings / phonon / vlc / audiooutput.cpp
1 /*****************************************************************************
2  * VLC backend for the Phonon library                                        *
3  * Copyright (C) 2007-2008 Tanguy Krotoff <tkrotoff@gmail.com>               *
4  * Copyright (C) 2008 Lukas Durfina <lukas.durfina@gmail.com>                *
5  * Copyright (C) 2009 Fathi Boudra <fabo@kde.org>                            *
6  *                                                                           *
7  * This program is free software; you can redistribute it and/or             *
8  * modify it under the terms of the GNU Lesser General Public                *
9  * License as published by the Free Software Foundation; either              *
10  * version 3 of the License, or (at your option) any later version.          *
11  *                                                                           *
12  * This program is distributed in the hope that it will be useful,           *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
15  * Lesser General Public License for more details.                           *
16  *                                                                           *
17  * You should have received a copy of the GNU Lesser General Public          *
18  * License along with this package; if not, write to the Free Software       *
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA *
20  *****************************************************************************/
21
22 #include "audiooutput.h"
23 #include "devicemanager.h"
24 #include "backend.h"
25
26 #include "mediaobject.h"
27 #include "vlcmediaobject.h"
28
29 #include "vlcloader.h"
30
31 #ifdef PHONON_PULSESUPPORT
32 #  include <phonon/pulsesupport.h>
33 #endif
34
35 namespace Phonon
36 {
37 namespace VLC {
38
39 AudioOutput::AudioOutput(Backend *p_back, QObject * p_parent)
40         : SinkNode(p_parent),
41         f_volume(1.0),
42         i_device(0),
43         p_backend(p_back)
44 {
45     p_media_object = 0;
46 }
47
48 AudioOutput::~AudioOutput()
49 {
50 }
51
52 qreal AudioOutput::volume() const
53 {
54     return f_volume;
55 }
56
57 void AudioOutput::setVolume(qreal volume)
58 {
59     if (vlc_instance) {
60         libvlc_audio_set_volume(vlc_instance, (int)(f_volume * 100), vlc_exception);
61         vlcExceptionRaised();
62         f_volume = volume;
63         emit volumeChanged(f_volume);
64     }
65 }
66
67 int AudioOutput::outputDevice() const
68 {
69     return i_device;
70 }
71
72 bool AudioOutput::setOutputDevice(int device)
73 {
74     if (i_device == device)
75         return true;
76
77 #ifdef PHONON_PULSESUPPORT
78     if (PulseSupport::getInstance()->isActive()) {
79         i_device = device;
80         libvlc_audio_output_set(vlc_instance, "pulse");
81         qDebug() << "set aout " << "pulse";
82         return true;
83     }
84 #endif
85
86     const QList<AudioDevice> deviceList = p_backend->deviceManager()->audioOutputDevices();
87     if (device >= 0 && device < deviceList.size()) {
88
89         i_device = device;
90         const QByteArray deviceName = deviceList.at(device).vlcId;
91         libvlc_audio_output_set(vlc_instance, (char *) deviceList.at(device).vlcId.data());
92         qDebug() << "set aout " << deviceList.at(device).vlcId.data();
93 //         if (deviceName == DEFAULT_ID) {
94 //             libvlc_audio_device_set(p_vlc_instance, DEFAULT, vlc_exception);
95 //             vlcExceptionRaised();
96 //         } else if (deviceName.startsWith(ALSA_ID)) {
97 //             qDebug() << "setting ALSA " << deviceList.at(device).hwId.data();
98 //             libvlc_audio_device_set(p_vlc_instance, ALSA, vlc_exception);
99 //             vlcExceptionRaised();
100 //             libvlc_audio_alsa_device_set(p_vlc_instance,
101 //                                          deviceList.at(device).hwId,
102 //                                          vlc_exception);
103 //             vlcExceptionRaised();
104     }
105
106     return true;
107 }
108
109 #if (PHONON_VERSION >= PHONON_VERSION_CHECK(4, 2, 0))
110 bool AudioOutput::setOutputDevice(const Phonon::AudioOutputDevice & device)
111 {
112     return true;
113 }
114 #endif
115
116 }
117 } // Namespace Phonon::VLC