joy4/codec/codec.go
nareix 021f28e76c Add 'codec/' from commit 'cef54937c5de3d17c5b4d14a489d4c445d613ef8'
git-subtree-dir: codec
git-subtree-mainline: 8b0ee7d5c264e0de454a9d23a5644b04ce8f2864
git-subtree-split: cef54937c5de3d17c5b4d14a489d4c445d613ef8
2016-07-01 21:37:19 +08:00

52 lines
927 B
Go

package codec
import (
"github.com/nareix/av"
"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,
}
}
func NewNellyMoserCodecData() av.AudioCodecData {
return PCMUCodecData{typ: av.NELLYMOSER}
}
func NewSpeexCodecData() av.AudioCodecData {
return PCMUCodecData{typ: av.SPEEX}
}