You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
joy4/codec/codec.go

71 lines
1.3 KiB
Go

4 years ago
package codec
import (
"time"
1 year ago
"git.icomsys.co.kr/ljhwan026/joy4/av"
"git.icomsys.co.kr/ljhwan026/joy4/codec/fake"
4 years ago
)
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,
}
}
func NewG729CodecData() av.AudioCodecData {
return PCMUCodecData{
typ: av.G729,
}
}
4 years ago
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
}