-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontrols_common.go
More file actions
183 lines (164 loc) · 4.17 KB
/
controls_common.go
File metadata and controls
183 lines (164 loc) · 4.17 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package gopus
// ExpertFrameDuration mirrors libopus OPUS_SET/GET_EXPERT_FRAME_DURATION values.
type ExpertFrameDuration int
const (
ExpertFrameDurationArg ExpertFrameDuration = 5000
ExpertFrameDuration2_5Ms ExpertFrameDuration = 5001
ExpertFrameDuration5Ms ExpertFrameDuration = 5002
ExpertFrameDuration10Ms ExpertFrameDuration = 5003
ExpertFrameDuration20Ms ExpertFrameDuration = 5004
ExpertFrameDuration40Ms ExpertFrameDuration = 5005
ExpertFrameDuration60Ms ExpertFrameDuration = 5006
ExpertFrameDuration80Ms ExpertFrameDuration = 5007
ExpertFrameDuration100Ms ExpertFrameDuration = 5008
ExpertFrameDuration120Ms ExpertFrameDuration = 5009
)
func validApplication(application Application) bool {
switch application {
case ApplicationVoIP, ApplicationAudio, ApplicationLowDelay, ApplicationRestrictedSilk, ApplicationRestrictedCelt:
return true
default:
return false
}
}
func validateBitrate(bitrate, max int) error {
if bitrate < 6000 || bitrate > max {
return ErrInvalidBitrate
}
return nil
}
func validateComplexity(complexity int) error {
if complexity < 0 || complexity > 10 {
return ErrInvalidComplexity
}
return nil
}
func validateBitrateMode(mode BitrateMode) error {
switch mode {
case BitrateModeVBR, BitrateModeCVBR, BitrateModeCBR:
return nil
default:
return ErrInvalidBitrateMode
}
}
func validSignal(signal Signal) bool {
switch signal {
case SignalAuto, SignalVoice, SignalMusic:
return true
default:
return false
}
}
func validateSignal(signal Signal) error {
if !validSignal(signal) {
return ErrInvalidSignal
}
return nil
}
func validBandwidth(bandwidth Bandwidth) bool {
switch bandwidth {
case BandwidthNarrowband, BandwidthMediumband, BandwidthWideband, BandwidthSuperwideband, BandwidthFullband:
return true
default:
return false
}
}
func validateBandwidth(bandwidth Bandwidth) error {
if !validBandwidth(bandwidth) {
return ErrInvalidBandwidth
}
return nil
}
func validateForceChannels(channels int) error {
if channels != -1 && channels != 1 && channels != 2 {
return ErrInvalidForceChannels
}
return nil
}
func validatePacketLoss(lossPercent int) error {
if lossPercent < 0 || lossPercent > 100 {
return ErrInvalidPacketLoss
}
return nil
}
func validateLSBDepth(depth int) error {
if depth < 8 || depth > 24 {
return ErrInvalidLSBDepth
}
return nil
}
func validFrameSize(samples int) bool {
switch samples {
case 120, 240, 480, 960, 1920, 2880, 3840, 4800, 5760:
return true
default:
return false
}
}
func validateFrameSize(samples int, application Application) error {
if !validFrameSize(samples) {
return ErrInvalidFrameSize
}
if application == ApplicationRestrictedSilk && samples < 480 {
return ErrInvalidFrameSize
}
return nil
}
func validExpertFrameDuration(duration ExpertFrameDuration) bool {
switch duration {
case ExpertFrameDurationArg,
ExpertFrameDuration2_5Ms,
ExpertFrameDuration5Ms,
ExpertFrameDuration10Ms,
ExpertFrameDuration20Ms,
ExpertFrameDuration40Ms,
ExpertFrameDuration60Ms,
ExpertFrameDuration80Ms,
ExpertFrameDuration100Ms,
ExpertFrameDuration120Ms:
return true
default:
return false
}
}
func expertFrameDurationFrameSize(duration ExpertFrameDuration) int {
switch duration {
case ExpertFrameDuration2_5Ms:
return 120
case ExpertFrameDuration5Ms:
return 240
case ExpertFrameDuration10Ms:
return 480
case ExpertFrameDuration20Ms:
return 960
case ExpertFrameDuration40Ms:
return 1920
case ExpertFrameDuration60Ms:
return 2880
case ExpertFrameDuration80Ms:
return 3840
case ExpertFrameDuration100Ms:
return 4800
case ExpertFrameDuration120Ms:
return 5760
default:
return 0
}
}
func setExpertFrameDuration(duration ExpertFrameDuration, current *ExpertFrameDuration, setFrameSize func(int) error) error {
if !validExpertFrameDuration(duration) {
return ErrInvalidArgument
}
*current = duration
if duration == ExpertFrameDurationArg {
return nil
}
return setFrameSize(expertFrameDurationFrameSize(duration))
}
func lookaheadSamples(sampleRate int, application Application) int {
base := sampleRate / 400
if application == ApplicationLowDelay || application == ApplicationRestrictedCelt {
return base
}
return base + sampleRate/250
}