-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDevice.h
78 lines (63 loc) · 1.29 KB
/
Device.h
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
#ifndef AUDIOFFT_DEVICE_H
#define AUDIOFFT_DEVICE_H
#include <string>
#include <pulse/pulseaudio.h>
#include <list>
#include <vector>
#include "Engine.h"
enum DeviceType {
SOURCE,
SINK
};
enum DeviceState {
DEVICE_INVALID_STATE,
DEVICE_RUNNING,
DEVICE_IDLE,
DEVICE_SUSPENDED
};
class Device {
public:
Device();
unsigned int index;
DeviceType type;
std::string name;
std::string desc;
DeviceState state;
pa_cvolume volume;
pa_volume_t volume_avg;
int volume_percentage;
bool muted;
explicit Device(const pa_source_info* i);
explicit Device(const pa_sink_info* i);
private:
void setVolume(const pa_cvolume* v);
};
static std::vector<Device> used;
typedef enum PulseAudioContextState {
INIT,
READY,
FINISHED
}PulseAudioContextState;
static void stateCallback(pa_context* c, void* userdata) {
auto* state = static_cast<PulseAudioContextState *>(userdata);
switch (pa_context_get_state(c)) {
case PA_CONTEXT_TERMINATED:
*state = FINISHED;
break;
case PA_CONTEXT_READY:
*state = READY;
break;
default:
break;
}
}
static void sourceListCallback(pa_context* c, const pa_source_info* i, int eol, void* raw) {
if (eol != 0) {
return;
}
Device s(i);
if (i != nullptr && i -> monitor_of_sink != PA_INVALID_INDEX) {
used.emplace_back(s);
}
}
#endif //AUDIOFFT_DEVICE_H