-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsource.go
109 lines (104 loc) · 2.4 KB
/
source.go
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
package pulseaudio
import "io"
//Source contains information about a source in pulseaudio, e.g. a microphone
type Source struct {
Index uint32
Name string
Description string
SampleSpec sampleSpec
ChannelMap channelMap
ModuleIndex uint32
Cvolume cvolume
Muted bool
MonitorSourceIndex uint32
MonitorSourceName string
Latency uint64
Driver string
Flags uint32
PropList map[string]string
RequestedLatency uint64
BaseVolume uint32
SinkState uint32
NVolumeSteps uint32
CardIndex uint32
Ports []sinkPort
ActivePortName string
Formats []formatInfo
}
//ReadFrom deserialized a PA source packet
func (s *Source) ReadFrom(r io.Reader) (int64, error) {
var portCount uint32
err := bread(r,
uint32Tag, &s.Index,
stringTag, &s.Name,
stringTag, &s.Description,
&s.SampleSpec,
&s.ChannelMap,
uint32Tag, &s.ModuleIndex,
&s.Cvolume,
&s.Muted,
uint32Tag, &s.MonitorSourceIndex,
stringTag, &s.MonitorSourceName,
usecTag, &s.Latency,
stringTag, &s.Driver,
uint32Tag, &s.Flags,
&s.PropList,
usecTag, &s.RequestedLatency,
volumeTag, &s.BaseVolume,
uint32Tag, &s.SinkState,
uint32Tag, &s.NVolumeSteps,
uint32Tag, &s.CardIndex,
uint32Tag, &portCount)
if err != nil {
return 0, err
}
s.Ports = make([]sinkPort, portCount)
for i := uint32(0); i < portCount; i++ {
err = bread(r, &s.Ports[i])
if err != nil {
return 0, err
}
}
if portCount == 0 {
err = bread(r, stringNullTag)
if err != nil {
return 0, err
}
} else {
err = bread(r, stringTag, &s.ActivePortName)
if err != nil {
return 0, err
}
}
var formatCount uint8
err = bread(r,
uint8Tag, &formatCount)
if err != nil {
return 0, err
}
s.Formats = make([]formatInfo, formatCount)
for i := uint8(0); i < formatCount; i++ {
err = bread(r, &s.Formats[i])
if err != nil {
return 0, err
}
}
return 0, nil
}
// Sources queries pulseaudio for a list of all it's sources and returns an array of them
func (c *Client) Sources() ([]Source, error) {
b, err := c.request(commandGetSourceInfoList)
if err != nil {
return nil, err
}
var sources []Source
for b.Len() > 0 {
var source Source
err = bread(b, &source)
if err != nil {
return nil, err
}
sources = append(sources, source)
}
return sources, nil
}