Files

65 lines
1.2 KiB
Go
Raw Permalink Normal View History

2016-06-08 14:41:32 +08:00
package codec
import (
2016-07-01 21:45:15 +08:00
"github.com/nareix/joy4/av"
2016-07-13 15:11:11 +08:00
"github.com/nareix/joy4/codec/fake"
2016-06-22 17:58:19 +08:00
"time"
2016-06-08 14:41:32 +08:00
)
2016-06-22 17:58:19 +08:00
type PCMUCodecData struct {
typ av.CodecType
2016-06-08 14:41:32 +08:00
}
2016-06-22 17:58:19 +08:00
func (self PCMUCodecData) Type() av.CodecType {
return self.typ
2016-06-08 14:41:32 +08:00
}
2016-06-22 17:58:19 +08:00
func (self PCMUCodecData) SampleRate() int {
return 8000
2016-06-08 14:41:32 +08:00
}
2016-06-22 17:58:19 +08:00
func (self PCMUCodecData) ChannelLayout() av.ChannelLayout {
return av.CH_MONO
2016-06-08 14:41:32 +08:00
}
2016-06-22 17:58:19 +08:00
func (self PCMUCodecData) SampleFormat() av.SampleFormat {
return av.S16
2016-06-08 14:41:32 +08:00
}
2016-06-22 17:58:19 +08:00
func (self PCMUCodecData) PacketDuration(data []byte) (time.Duration, error) {
return time.Duration(len(data)) * time.Second / time.Duration(8000), nil
2016-06-08 14:41:32 +08:00
}
func NewPCMMulawCodecData() av.AudioCodecData {
2016-06-22 17:58:19 +08:00
return PCMUCodecData{
typ: av.PCM_MULAW,
2016-06-08 14:41:32 +08:00
}
}
2016-06-11 23:32:15 +08:00
func NewPCMAlawCodecData() av.AudioCodecData {
2016-06-22 17:58:19 +08:00
return PCMUCodecData{
typ: av.PCM_ALAW,
2016-06-11 23:32:15 +08:00
}
}
2016-07-13 15:11:11 +08:00
type SpeexCodecData struct {
fake.CodecData
2016-06-29 17:34:37 +08:00
}
2016-07-13 15:11:11 +08:00
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
2016-06-29 17:34:37 +08:00
}