summaryrefslogtreecommitdiffstats
path: root/bridge/mumble/codec.go
blob: 1306e4082829545607e3854e8747136f02f4f038 (plain) (blame)
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
package bmumble

import (
	"fmt"

	"layeh.com/gumble/gumble"
)

// This is a dummy implementation of a Gumble audio codec which claims
// to implement Opus, but does not actually do anything.  This serves
// as a workaround until https://github.com/layeh/gumble/pull/61 is
// merged.
// See https://github.com/42wim/matterbridge/issues/1750 for details.

const (
	audioCodecIDOpus = 4
)

func registerNullCodecAsOpus() {
	codec := &NullCodec{
		encoder: &NullAudioEncoder{},
		decoder: &NullAudioDecoder{},
	}
	gumble.RegisterAudioCodec(audioCodecIDOpus, codec)
}

type NullCodec struct {
	encoder *NullAudioEncoder
	decoder *NullAudioDecoder
}

func (c *NullCodec) ID() int {
	return audioCodecIDOpus
}

func (c *NullCodec) NewEncoder() gumble.AudioEncoder {
	e := &NullAudioEncoder{}
	return e
}

func (c *NullCodec) NewDecoder() gumble.AudioDecoder {
	d := &NullAudioDecoder{}
	return d
}

type NullAudioEncoder struct{}

func (e *NullAudioEncoder) ID() int {
	return audioCodecIDOpus
}

func (e *NullAudioEncoder) Encode(pcm []int16, mframeSize, maxDataBytes int) ([]byte, error) {
	return nil, fmt.Errorf("not implemented")
}

func (e *NullAudioEncoder) Reset() {
}

type NullAudioDecoder struct{}

func (d *NullAudioDecoder) ID() int {
	return audioCodecIDOpus
}

func (d *NullAudioDecoder) Decode(data []byte, frameSize int) ([]int16, error) {
	return nil, fmt.Errorf("not implemented")
}

func (d *NullAudioDecoder) Reset() {
}