-
Notifications
You must be signed in to change notification settings - Fork 0
/
codec.go
75 lines (62 loc) · 1.57 KB
/
codec.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
69
70
71
72
73
74
75
package codec
import (
"time"
"github.com/Youngju-Heo/gomedia/core/media/av"
"github.com/Youngju-Heo/gomedia/core/media/codec/fake"
)
// PCMUCodecData struct
type PCMUCodecData struct {
typ av.CodecType
}
// Type func
func (codecData PCMUCodecData) Type() av.CodecType {
return codecData.typ
}
// SampleRate func
func (codecData PCMUCodecData) SampleRate() int {
return 8000
}
// ChannelLayout func
func (codecData PCMUCodecData) ChannelLayout() av.ChannelLayout {
return av.ChMono
}
// SampleFormat func
func (codecData PCMUCodecData) SampleFormat() av.SampleFormat {
return av.S16
}
// PacketDuration func
func (codecData PCMUCodecData) PacketDuration(data []byte) (time.Duration, error) {
return time.Duration(len(data)) * time.Second / time.Duration(8000), nil
}
// NewPCMMulawCodecData func
func NewPCMMulawCodecData() av.AudioCodecData {
return PCMUCodecData{
typ: av.PCMU,
}
}
// NewPCMAlawCodecData func
func NewPCMAlawCodecData() av.AudioCodecData {
return PCMUCodecData{
typ: av.PCMA,
}
}
// SpeexCodecData struct
type SpeexCodecData struct {
fake.CodecData
}
// PacketDuration func
func (codecData SpeexCodecData) PacketDuration(data []byte) (time.Duration, error) {
// libavcodec/libspeexdec.c
// samples = samplerate/50
// duration = 0.02s
return time.Millisecond * 20, nil
}
// // NewSpeexCodecData func
// func NewSpeexCodecData(sr int, cl av.ChannelLayout) SpeexCodecData {
// codec := SpeexCodecData{}
// codec.CodecTypeItem = av.SPEEX
// codec.SampleFormatItem = av.S16
// codec.SampleRateItem = sr
// codec.ChannelLayoutItem = cl
// return codec
// }