forked from nareix/joy4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodec.go
64 lines (51 loc) · 1.22 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
package codec
import (
"github.com/nareix/joy4/av"
"github.com/nareix/joy4/codec/fake"
"time"
)
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 NewPCMAlawCodecData() av.AudioCodecData {
return PCMUCodecData{
typ: av.PCM_ALAW,
}
}
type SpeexCodecData struct {
fake.CodecData
}
func (self SpeexCodecData) PacketDuration(data []byte) (time.Duration, error) {
// libavcodec/libspeexdec.c
// samples = samplerate/50
// duration = 0.02s
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
}