1/*
2 Copyright (C) 2007-2008 Tanguy Krotoff <tkrotoff@gmail.com>
3 Copyright (C) 2008 Lukas Durfina <lukas.durfina@gmail.com>
4 Copyright (C) 2009 Fathi Boudra <fabo@kde.org>
5 Copyright (C) 2013 Harald Sitter <sitter@kde.org>
6
7 This library 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 2.1 of the License, or (at your option) any later version.
11
12 This library 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 library. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#ifndef PHONON_VLC_AUDIOOUTPUT_H
22#define PHONON_VLC_AUDIOOUTPUT_H
23
24#include <QtCore/QObject>
25
26#include <phonon/audiooutputinterface.h>
27
28#include "sinknode.h"
29
30namespace Phonon {
31namespace VLC {
32
33/** \brief AudioOutput implementation for Phonon-VLC
34 *
35 * This class is a SinkNode that implements the AudioOutputInterface from Phonon. It
36 * supports setting the volume and the audio output device.
37 *
38 * There are signals for the change of the volume or for when an audio device failed.
39 *
40 * See the Phonon::AudioOutputInterface documentation for details.
41 *
42 * \see AudioDataOutput
43 */
44class AudioOutput : public QObject, public SinkNode, public AudioOutputInterface
45{
46 Q_OBJECT
47 Q_INTERFACES(Phonon::AudioOutputInterface)
48
49public:
50 /**
51 * Creates an AudioOutput with the given backend object. The volume is set to 1.0
52 *
53 * \param p_back Parent backend
54 * \param p_parent A parent object
55 */
56 explicit AudioOutput(QObject *parent);
57 ~AudioOutput() override;
58
59 /** \reimp */
60 void handleConnectToMediaObject(MediaObject *mediaObject) override;
61 /** \reimp */
62 void handleAddToMedia(Media *media) override;
63
64 /**
65 * \return The current volume for this audio output.
66 */
67 qreal volume() const override;
68
69 /**
70 * Sets the volume of the audio output. See the Phonon::AudioOutputInterface::setVolume() documentation
71 * for details.
72 */
73 void setVolume(qreal volume) override;
74
75 /**
76 * \return The index of the current audio output device from the list obtained from the backend object.
77 */
78 int outputDevice() const override;
79
80 /**
81 * Sets the current output device for this audio output. The validity of the device index
82 * is verified before attempting to change the device.
83 *
84 * \param device The index of the device, obtained from the backend's audio device list
85 * \return \c true if succeeded, or no change was made
86 * \return \c false if failed
87 */
88 bool setOutputDevice(int) override;
89
90 /**
91 * Sets the current output device for this audio output.
92 *
93 * \param device The device to set; it should be valid and contain an usable deviceAccessList property
94 * \return \c true if succeeded, or no change was made
95 * \return \c false if failed
96 */
97 bool setOutputDevice(const AudioOutputDevice &newDevice) override;
98 void setStreamUuid(QString uuid) override;
99 void setMuted(bool mute) override;
100
101 virtual void setCategory(Phonon::Category category);
102
103Q_SIGNALS:
104 void volumeChanged(qreal volume);
105 void audioDeviceFailed();
106 void mutedChanged(bool mute);
107
108private Q_SLOTS:
109 /**
110 * Sets the volume to m_volume.
111 */
112 void applyVolume();
113
114 void onMutedChanged(bool mute);
115 void onVolumeChanged(float volume);
116
117private:
118 /**
119 * We can only really set the output device once we have a libvlc_media_player, which comes
120 * from our SinkNode.
121 */
122 void setOutputDeviceImplementation();
123
124 qreal m_volume;
125 // Set after first setVolume to indicate volume was set manually.
126 bool m_explicitVolume;
127 bool m_muted;
128 AudioOutputDevice m_device;
129 QString m_streamUuid;
130 Category m_category;
131};
132
133} // namespace VLC
134} // namespace Phonon
135
136#endif // PHONON_VLC_AUDIOOUTPUT_H
137

source code of phonon-vlc/src/audio/audiooutput.h