File indexing completed on 2025-02-16 07:33:46
0001 /* 0002 Copyright (C) 2007-2008 Tanguy Krotoff <tkrotoff@gmail.com> 0003 Copyright (C) 2008 Lukas Durfina <lukas.durfina@gmail.com> 0004 Copyright (C) 2009 Fathi Boudra <fabo@kde.org> 0005 Copyright (C) 2013 Harald Sitter <sitter@kde.org> 0006 0007 This library is free software; you can redistribute it and/or 0008 modify it under the terms of the GNU Lesser General Public 0009 License as published by the Free Software Foundation; either 0010 version 2.1 of the License, or (at your option) any later version. 0011 0012 This library is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 Lesser General Public License for more details. 0016 0017 You should have received a copy of the GNU Lesser General Public 0018 License along with this library. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 0021 #ifndef PHONON_VLC_AUDIOOUTPUT_H 0022 #define PHONON_VLC_AUDIOOUTPUT_H 0023 0024 #include <QtCore/QObject> 0025 0026 #include <phonon/audiooutputinterface.h> 0027 0028 #include "sinknode.h" 0029 0030 namespace Phonon { 0031 namespace VLC { 0032 0033 /** \brief AudioOutput implementation for Phonon-VLC 0034 * 0035 * This class is a SinkNode that implements the AudioOutputInterface from Phonon. It 0036 * supports setting the volume and the audio output device. 0037 * 0038 * There are signals for the change of the volume or for when an audio device failed. 0039 * 0040 * See the Phonon::AudioOutputInterface documentation for details. 0041 * 0042 * \see AudioDataOutput 0043 */ 0044 class AudioOutput : public QObject, public SinkNode, public AudioOutputInterface 0045 { 0046 Q_OBJECT 0047 Q_INTERFACES(Phonon::AudioOutputInterface) 0048 0049 public: 0050 /** 0051 * Creates an AudioOutput with the given backend object. The volume is set to 1.0 0052 * 0053 * \param p_back Parent backend 0054 * \param p_parent A parent object 0055 */ 0056 explicit AudioOutput(QObject *parent); 0057 ~AudioOutput() override; 0058 0059 /** \reimp */ 0060 void handleConnectToMediaObject(MediaObject *mediaObject) override; 0061 /** \reimp */ 0062 void handleAddToMedia(Media *media) override; 0063 0064 /** 0065 * \return The current volume for this audio output. 0066 */ 0067 qreal volume() const override; 0068 0069 /** 0070 * Sets the volume of the audio output. See the Phonon::AudioOutputInterface::setVolume() documentation 0071 * for details. 0072 */ 0073 void setVolume(qreal volume) override; 0074 0075 /** 0076 * \return The index of the current audio output device from the list obtained from the backend object. 0077 */ 0078 int outputDevice() const override; 0079 0080 /** 0081 * Sets the current output device for this audio output. The validity of the device index 0082 * is verified before attempting to change the device. 0083 * 0084 * \param device The index of the device, obtained from the backend's audio device list 0085 * \return \c true if succeeded, or no change was made 0086 * \return \c false if failed 0087 */ 0088 bool setOutputDevice(int) override; 0089 0090 /** 0091 * Sets the current output device for this audio output. 0092 * 0093 * \param device The device to set; it should be valid and contain an usable deviceAccessList property 0094 * \return \c true if succeeded, or no change was made 0095 * \return \c false if failed 0096 */ 0097 bool setOutputDevice(const AudioOutputDevice &newDevice) override; 0098 void setStreamUuid(QString uuid) override; 0099 void setMuted(bool mute) override; 0100 0101 virtual void setCategory(Phonon::Category category); 0102 0103 Q_SIGNALS: 0104 void volumeChanged(qreal volume); 0105 void audioDeviceFailed(); 0106 void mutedChanged(bool mute); 0107 0108 private Q_SLOTS: 0109 /** 0110 * Sets the volume to m_volume. 0111 */ 0112 void applyVolume(); 0113 0114 void onMutedChanged(bool mute); 0115 void onVolumeChanged(float volume); 0116 0117 private: 0118 /** 0119 * We can only really set the output device once we have a libvlc_media_player, which comes 0120 * from our SinkNode. 0121 */ 0122 void setOutputDeviceImplementation(); 0123 0124 qreal m_volume; 0125 // Set after first setVolume to indicate volume was set manually. 0126 bool m_explicitVolume; 0127 bool m_muted; 0128 AudioOutputDevice m_device; 0129 QString m_streamUuid; 0130 Category m_category; 0131 }; 0132 0133 } // namespace VLC 0134 } // namespace Phonon 0135 0136 #endif // PHONON_VLC_AUDIOOUTPUT_H