summaryrefslogtreecommitdiffstats
path: root/src/PulseAudioQt/device.h
blob: 450ae6b71e5f7adff5f6577f5c8d572a75901f8b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
    SPDX-FileCopyrightText: 2014-2015 Harald Sitter <sitter@kde.org>

    SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/

#ifndef PA_DEVICE_H
#define PA_DEVICE_H

#include <QString>

#include "port.h"
#include "volumeobject.h"

namespace PulseAudioQt
{
class Port;
class DevicePrivate;

/**
 * A PulseAudio device. Can be either a Sink or Source.
 */
class PULSEAUDIOQT_EXPORT Device : public VolumeObject
{
    Q_OBJECT
    Q_PROPERTY(State state READ state NOTIFY stateChanged)
    Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
    Q_PROPERTY(QString formFactor READ formFactor NOTIFY formFactorChanged)
    Q_PROPERTY(quint32 cardIndex READ cardIndex NOTIFY cardIndexChanged)
    Q_PROPERTY(QList<Port *> ports READ ports NOTIFY portsChanged)
    Q_PROPERTY(quint32 activePortIndex READ activePortIndex WRITE setActivePortIndex NOTIFY activePortIndexChanged)
    Q_PROPERTY(bool default READ isDefault WRITE setDefault NOTIFY defaultChanged)

public:
    enum State {
        /** This state is used when the server does not support sink/source state introspection. */
        InvalidState = 0,
        /** Running, sink/source is playing/recording and used by at least one non-corked sink-input/source-output.  */
        RunningState,
        /** When idle, the sink/source is playing/recording but there is no non-corked sink-input/source-output attached to it. */
        IdleState,
        /** When suspended, actual sink/source access can be closed, for instance. */
        SuspendedState,
        UnknownState,
    };
    Q_ENUM(State);

    ~Device();

    /**
     * The state of this device.
     */
    State state() const;

    /**
     * A human readable description of this device.
     */
    QString description() const;

    /**
     * The device's form factor.
     * One of "internal", "speaker", "handset", "tv", "webcam", "microphone", "headset", "headphone", "hands-free", "car", "hifi", "computer", "portable".
     * This is based on PA_PROP_DEVICE_FORM_FACTOR.
     */
    QString formFactor() const;

    /**
     * Index of the card that owns this device.
     */
    quint32 cardIndex() const;

    /**
     * The ports associated with this device.
     */
    QList<Port *> ports() const;

    /**
     * The currently active port, by index.
     */
    quint32 activePortIndex() const;

    /**
     * Set the currently active port, by index.
     */
    virtual void setActivePortIndex(quint32 port_index) = 0;

    /**
     * Whether this is the default device.
     */
    virtual bool isDefault() const = 0;

    /**
     * Set whether this is the default device.
     */
    virtual void setDefault(bool enable) = 0;

Q_SIGNALS:
    void stateChanged();
    void descriptionChanged();
    void formFactorChanged();
    void cardIndexChanged();
    void portsChanged();
    void activePortIndexChanged();
    void defaultChanged();

protected:
    /** @private */
    explicit Device(QObject *parent);
    /** @private */
    DevicePrivate *d;

private:
    friend class SinkPrivate;
    friend class SourcePrivate;
};

} // PulseAudioQt

#endif // DEVICE_H