File indexing completed on 2024-04-14 14:55:42

0001 /*
0002     SPDX-FileCopyrightText: 2014-2015 Harald Sitter <sitter@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef PA_DEVICE_H
0008 #define PA_DEVICE_H
0009 
0010 #include <QString>
0011 #include <QVariantMap>
0012 
0013 #include "port.h"
0014 #include "volumeobject.h"
0015 
0016 namespace PulseAudioQt
0017 {
0018 class Port;
0019 class DevicePrivate;
0020 
0021 /**
0022  * A PulseAudio device. Can be either a Sink or Source.
0023  */
0024 class PULSEAUDIOQT_EXPORT Device : public VolumeObject
0025 {
0026     Q_OBJECT
0027     Q_PROPERTY(State state READ state NOTIFY stateChanged)
0028     Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
0029     Q_PROPERTY(QString formFactor READ formFactor NOTIFY formFactorChanged)
0030     Q_PROPERTY(quint32 cardIndex READ cardIndex NOTIFY cardIndexChanged)
0031     Q_PROPERTY(QList<Port *> ports READ ports NOTIFY portsChanged)
0032     Q_PROPERTY(quint32 activePortIndex READ activePortIndex WRITE setActivePortIndex NOTIFY activePortIndexChanged)
0033     Q_PROPERTY(bool default READ isDefault WRITE setDefault NOTIFY defaultChanged)
0034     Q_PROPERTY(qint64 baseVolume READ baseVolume NOTIFY baseVolumeChanged)
0035     Q_PROPERTY(QVariantMap pulseProperties READ pulseProperties NOTIFY pulsePropertiesChanged)
0036 
0037 public:
0038     enum State {
0039         /** This state is used when the server does not support sink/source state introspection. */
0040         InvalidState = 0,
0041         /** Running, sink/source is playing/recording and used by at least one non-corked sink-input/source-output.  */
0042         RunningState,
0043         /** When idle, the sink/source is playing/recording but there is no non-corked sink-input/source-output attached to it. */
0044         IdleState,
0045         /** When suspended, actual sink/source access can be closed, for instance. */
0046         SuspendedState,
0047         UnknownState,
0048     };
0049     Q_ENUM(State);
0050 
0051     ~Device();
0052 
0053     /**
0054      * The state of this device.
0055      */
0056     State state() const;
0057 
0058     /**
0059      * A human readable description of this device.
0060      */
0061     QString description() const;
0062 
0063     /**
0064      * The device's form factor.
0065      * One of "internal", "speaker", "handset", "tv", "webcam", "microphone", "headset", "headphone", "hands-free", "car", "hifi", "computer", "portable".
0066      * This is based on PA_PROP_DEVICE_FORM_FACTOR.
0067      */
0068     QString formFactor() const;
0069 
0070     /**
0071      * Index of the card that owns this device.
0072      */
0073     quint32 cardIndex() const;
0074 
0075     /**
0076      * The ports associated with this device.
0077      */
0078     QList<Port *> ports() const;
0079 
0080     /**
0081      * The currently active port, by index.
0082      */
0083     quint32 activePortIndex() const;
0084 
0085     /**
0086      * Set the currently active port, by index.
0087      */
0088     virtual void setActivePortIndex(quint32 port_index) = 0;
0089 
0090     /**
0091      * Whether this is the default device.
0092      */
0093     virtual bool isDefault() const = 0;
0094 
0095     /**
0096      * Set whether this is the default device.
0097      */
0098     virtual void setDefault(bool enable) = 0;
0099 
0100     /**
0101      * The base volume of this device, generally useful as a good default volume.
0102      */
0103     qint64 baseVolume() const;
0104 
0105     /**
0106      * @return QVariantMap the pulseaudio properties of this device (e.g. media.class, device.api, ...)
0107      */
0108     [[nodiscard]] QVariantMap pulseProperties() const;
0109 
0110     /**
0111      * @brief Switch all streams onto this Device
0112      * Iterates through all relevant streams for the Device type and assigns them to this Device.
0113      * For example for a Sink device all SinkInputs known to the daemon will be explicitly switched
0114      * onto this Sink. Useful for mass-rerouting of streams from different devices onto a specific target device.
0115      */
0116     virtual Q_INVOKABLE void switchStreams() = 0;
0117 
0118 Q_SIGNALS:
0119     void stateChanged();
0120     void descriptionChanged();
0121     void formFactorChanged();
0122     void cardIndexChanged();
0123     void portsChanged();
0124     void activePortIndexChanged();
0125     void defaultChanged();
0126     void baseVolumeChanged();
0127     void pulsePropertiesChanged();
0128 
0129 protected:
0130     /** @private */
0131     explicit Device(QObject *parent);
0132     /** @private */
0133     DevicePrivate *d;
0134 
0135 private:
0136     friend class SinkPrivate;
0137     friend class SourcePrivate;
0138 };
0139 
0140 } // PulseAudioQt
0141 
0142 #endif // DEVICE_H