]> git.sesse.net Git - vlc/blob - bindings/phonon/vlc/audiooutput.cpp
Phonon Backend using VLC
[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 namespace Phonon
32 {
33 namespace VLC {
34
35 AudioOutput::AudioOutput(Backend *p_back, QObject * p_parent)
36         : SinkNode(p_parent),
37         f_volume(1.0),
38         p_backend(p_back)
39 {
40     p_media_object = 0;
41 }
42
43 AudioOutput::~AudioOutput()
44 {
45 }
46
47 qreal AudioOutput::volume() const
48 {
49     return f_volume;
50 }
51
52 void AudioOutput::setVolume(qreal volume)
53 {
54     if (vlc_instance) {
55         libvlc_audio_set_volume(vlc_instance, (int)(f_volume * 100), vlc_exception);
56         vlcExceptionRaised();
57         f_volume = volume;
58         emit volumeChanged(f_volume);
59     }
60 }
61
62 int AudioOutput::outputDevice() const
63 {
64     return i_device;
65 }
66
67 bool AudioOutput::setOutputDevice(int device)
68 {
69     if (i_device == device)
70         return true;
71
72     const QList<AudioDevice> deviceList = p_backend->deviceManager()->audioOutputDevices();
73     if (device >= 0 && device < deviceList.size()) {
74
75         i_device = device;
76         const QByteArray deviceName = deviceList.at(device).vlcId;
77         libvlc_audio_output_set(vlc_instance, (char *) deviceList.at(device).vlcId.data());
78         qDebug() << "set aout " << deviceList.at(device).vlcId.data();
79 //         if (deviceName == DEFAULT_ID) {
80 //             libvlc_audio_device_set(p_vlc_instance, DEFAULT, vlc_exception);
81 //             vlcExceptionRaised();
82 //         } else if (deviceName.startsWith(ALSA_ID)) {
83 //             qDebug() << "setting ALSA " << deviceList.at(device).hwId.data();
84 //             libvlc_audio_device_set(p_vlc_instance, ALSA, vlc_exception);
85 //             vlcExceptionRaised();
86 //             libvlc_audio_alsa_device_set(p_vlc_instance,
87 //                                          deviceList.at(device).hwId,
88 //                                          vlc_exception);
89 //             vlcExceptionRaised();
90     }
91
92     return true;
93 }
94
95 #if (PHONON_VERSION >= PHONON_VERSION_CHECK(4, 2, 0))
96 bool AudioOutput::setOutputDevice(const Phonon::AudioOutputDevice & device)
97 {
98     return true;
99 }
100 #endif
101
102 }
103 } // Namespace Phonon::VLC