/
options.go
62 lines (54 loc) · 1.75 KB
/
options.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
package pbWriter
import (
"github.com/dh1tw/remoteAudio/audiocodec"
)
// Option is the type for a function option
type Option func(*Options)
// Options is the data structure holding the optional values. The
// values are typically set by calling the functional options.
type Options struct {
DeviceName string
Encoder audiocodec.Encoder
Channels int
FramesPerBuffer int
UserID string
ToWireCb func([]byte)
}
// Channels is a functional option to set the amount of channels to be used
// with the audio device. Typically this is either Mono (1) or Stereo (2).
// Make sure that your audio device supports the specified amount of channels.
func Channels(chs int) Option {
return func(args *Options) {
args.Channels = chs
}
}
// FramesPerBuffer is a functional option which sets the amount of sample frames
// our audio device will request / provide when executing the callback.
// Example: A buffer with 960 frames at 48000kHz / stereo contains
// 1920 samples and results in 20ms Audio.
func FramesPerBuffer(s int) Option {
return func(args *Options) {
args.FramesPerBuffer = s
}
}
// Encoder is a functional option to set a specific decoder. By default,
// the opus decoder is used.
func Encoder(enc audiocodec.Encoder) Option {
return func(args *Options) {
args.Encoder = enc
}
}
// UserID is a functional option to set the UserID. All serialized protobufs
// contain the UserID to mark their origin.
func UserID(s string) Option {
return func(args *Options) {
args.UserID = s
}
}
// ToWireCb is a functional option to set the callback which will be executed
// when data has been serialized and is ready to be send to the network.
func ToWireCb(cb func([]byte)) Option {
return func(args *Options) {
args.ToWireCb = cb
}
}