forked from dchote/gumble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
audiocodec.go
55 lines (46 loc) · 1.21 KB
/
audiocodec.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
package gumble // import "github.com/5pm-HDH/gumble/gumble"
import (
"sync"
)
const (
audioCodecIDOpus = 4
)
var (
audioCodecsLock sync.Mutex
audioCodecs [8]AudioCodec
)
// RegisterAudioCodec registers an audio codec that can be used for encoding
// and decoding outgoing and incoming audio data. The function panics if the
// ID is invalid.
func RegisterAudioCodec(id int, codec AudioCodec) {
audioCodecsLock.Lock()
defer audioCodecsLock.Unlock()
if id < 0 || id >= len(audioCodecs) {
panic("id out of range")
}
audioCodecs[id] = codec
}
func getAudioCodec(id int) AudioCodec {
audioCodecsLock.Lock()
defer audioCodecsLock.Unlock()
return audioCodecs[id]
}
// AudioCodec can create a encoder and a decoder for outgoing and incoming
// data.
type AudioCodec interface {
ID() int
NewEncoder() AudioEncoder
NewDecoder() AudioDecoder
}
// AudioEncoder encodes a chunk of PCM audio samples to a certain type.
type AudioEncoder interface {
ID() int
Encode(pcm []int16, mframeSize, maxDataBytes int) ([]byte, error)
Reset()
}
// AudioDecoder decodes an encoded byte slice to a chunk of PCM audio samples.
type AudioDecoder interface {
ID() int
Decode(data []byte, frameSize int) ([]int16, error)
Reset()
}