-
Notifications
You must be signed in to change notification settings - Fork 1
/
codec.go
100 lines (80 loc) · 1.95 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
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
package codec
import (
"time"
"github.com/zhangm168/vdk/av"
"github.com/zhangm168/vdk/codec/fake"
)
type OpusCodecData struct {
typ av.CodecType
SampleRate_ int
ChannelLayout_ av.ChannelLayout
}
func (self OpusCodecData) Type() av.CodecType {
return self.typ
}
func (self OpusCodecData) SampleRate() int {
return self.SampleRate_
}
func (self OpusCodecData) ChannelLayout() av.ChannelLayout {
return self.ChannelLayout_
}
func (self OpusCodecData) PacketDuration(data []byte) (time.Duration, error) {
return time.Duration(20) * time.Millisecond, nil
}
func (self OpusCodecData) SampleFormat() av.SampleFormat {
return av.FLT
}
type PCMUCodecData struct {
typ av.CodecType
}
func (self PCMUCodecData) Type() av.CodecType {
return self.typ
}
func (self PCMUCodecData) SampleRate() int {
return 8000
}
func (self PCMUCodecData) ChannelLayout() av.ChannelLayout {
return av.CH_MONO
}
func (self PCMUCodecData) SampleFormat() av.SampleFormat {
return av.S16
}
func (self PCMUCodecData) PacketDuration(data []byte) (time.Duration, error) {
return time.Duration(len(data)) * time.Second / time.Duration(8000), nil
}
func NewPCMMulawCodecData() av.AudioCodecData {
return PCMUCodecData{
typ: av.PCM_MULAW,
}
}
func NewPCMCodecData() av.AudioCodecData {
return PCMUCodecData{
typ: av.PCM,
}
}
func NewPCMAlawCodecData() av.AudioCodecData {
return PCMUCodecData{
typ: av.PCM_ALAW,
}
}
func NewOpusCodecData(sr int, cc av.ChannelLayout) av.AudioCodecData {
return OpusCodecData{
typ: av.OPUS,
SampleRate_: sr,
ChannelLayout_: cc,
}
}
type SpeexCodecData struct {
fake.CodecData
}
func (self SpeexCodecData) PacketDuration(data []byte) (time.Duration, error) {
return time.Millisecond * 20, nil
}
func NewSpeexCodecData(sr int, cl av.ChannelLayout) SpeexCodecData {
codec := SpeexCodecData{}
codec.CodecType_ = av.SPEEX
codec.SampleFormat_ = av.S16
codec.SampleRate_ = sr
codec.ChannelLayout_ = cl
return codec
}