-
Notifications
You must be signed in to change notification settings - Fork 24
/
sink.go
68 lines (58 loc) · 1.63 KB
/
sink.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
package pulse
import "github.com/jfreymuth/pulse/proto"
// A Sink is an output device.
type Sink struct {
info proto.GetSinkInfoReply
}
// ListSinks returns a list of all available output devices.
func (c *Client) ListSinks() ([]*Sink, error) {
var reply proto.GetSinkInfoListReply
err := c.c.Request(&proto.GetSinkInfoList{}, &reply)
if err != nil {
return nil, err
}
sinks := make([]*Sink, len(reply))
for i := range sinks {
sinks[i] = &Sink{info: *reply[i]}
}
return sinks, nil
}
// DefaultSink returns the default output device.
func (c *Client) DefaultSink() (*Sink, error) {
var sink Sink
err := c.c.Request(&proto.GetSinkInfo{SinkIndex: proto.Undefined}, &sink.info)
if err != nil {
return nil, err
}
return &sink, nil
}
// SinkByID looks up a sink id.
func (c *Client) SinkByID(name string) (*Sink, error) {
var sink Sink
err := c.c.Request(&proto.GetSinkInfo{SinkIndex: proto.Undefined, SinkName: name}, &sink.info)
if err != nil {
return nil, err
}
return &sink, nil
}
// ID returns the sink name. Sink names are unique identifiers, but not necessarily human-readable.
func (s *Sink) ID() string {
return s.info.SinkName
}
// Name is a human-readable name describing the sink.
func (s *Sink) Name() string {
return s.info.Device
}
// Channels returns the default channel map.
func (s *Sink) Channels() proto.ChannelMap {
return s.info.ChannelMap
}
// SampleRate returns the default sample rate.
func (s *Sink) SampleRate() int {
return int(s.info.Rate)
}
// SinkIndex returns the sink index.
// This should only be used together with (*Cient).RawRequest.
func (s *Sink) SinkIndex() uint32 {
return s.info.SinkIndex
}