add PacketDuration

This commit is contained in:
nareix 2016-06-22 17:58:19 +08:00
parent 323db22c7e
commit a1c38b0cd0
3 changed files with 25 additions and 47 deletions

View File

@ -3,6 +3,7 @@ package aacparser
import ( import (
"github.com/nareix/bits" "github.com/nareix/bits"
"github.com/nareix/av" "github.com/nareix/av"
"time"
"fmt" "fmt"
"bytes" "bytes"
"io" "io"
@ -333,15 +334,7 @@ type CodecData struct {
Config MPEG4AudioConfig Config MPEG4AudioConfig
} }
func (self CodecData) IsVideo() bool { func (self CodecData) Type() av.CodecType {
return false
}
func (self CodecData) IsAudio() bool {
return true
}
func (self CodecData) Type() int {
return av.AAC return av.AAC
} }
@ -361,6 +354,11 @@ func (self CodecData) SampleFormat() av.SampleFormat {
return av.FLTP return av.FLTP
} }
func (self CodecData) PacketDuration(data []byte) (dur time.Duration, err error) {
dur = time.Duration(1024) * time.Second / time.Duration(self.Config.SampleRate)
return
}
func (self CodecData) MakeADTSHeader(samples int, payloadLength int) []byte { func (self CodecData) MakeADTSHeader(samples int, payloadLength int) []byte {
return MakeADTSHeader(self.Config, samples, payloadLength) return MakeADTSHeader(self.Config, samples, payloadLength)
} }

View File

@ -2,54 +2,42 @@ package codec
import ( import (
"github.com/nareix/av" "github.com/nareix/av"
"time"
) )
type AudioCodecData struct { type PCMUCodecData struct {
CodecType int typ av.CodecType
CodecSampleRate int
CodecChannelLayout av.ChannelLayout
CodecSampleFormat av.SampleFormat
} }
func (self AudioCodecData) Type() int { func (self PCMUCodecData) Type() av.CodecType {
return self.CodecType return self.typ
} }
func (self AudioCodecData) IsAudio() bool { func (self PCMUCodecData) SampleRate() int {
return true return 8000
} }
func (self AudioCodecData) IsVideo() bool { func (self PCMUCodecData) ChannelLayout() av.ChannelLayout {
return false return av.CH_MONO
} }
func (self AudioCodecData) SampleRate() int { func (self PCMUCodecData) SampleFormat() av.SampleFormat {
return self.CodecSampleRate return av.S16
} }
func (self AudioCodecData) ChannelLayout() av.ChannelLayout { func (self PCMUCodecData) PacketDuration(data []byte) (time.Duration, error) {
return self.CodecChannelLayout return time.Duration(len(data)) * time.Second / time.Duration(8000), nil
}
func (self AudioCodecData) SampleFormat() av.SampleFormat {
return self.CodecSampleFormat
} }
func NewPCMMulawCodecData() av.AudioCodecData { func NewPCMMulawCodecData() av.AudioCodecData {
return AudioCodecData{ return PCMUCodecData{
CodecType: av.PCM_MULAW, typ: av.PCM_MULAW,
CodecSampleFormat: av.S16,
CodecChannelLayout: av.CH_MONO,
CodecSampleRate: 8000,
} }
} }
func NewPCMAlawCodecData() av.AudioCodecData { func NewPCMAlawCodecData() av.AudioCodecData {
return AudioCodecData{ return PCMUCodecData{
CodecType: av.PCM_ALAW, typ: av.PCM_ALAW,
CodecSampleFormat: av.S16,
CodecChannelLayout: av.CH_MONO,
CodecSampleRate: 8000,
} }
} }

View File

@ -543,14 +543,10 @@ type CodecData struct {
SPSInfo SPSInfo SPSInfo SPSInfo
} }
func (self CodecData) Type() int { func (self CodecData) Type() av.CodecType {
return av.H264 return av.H264
} }
func (self CodecData) IsVideo() bool {
return true
}
func (self CodecData) AVCDecoderConfRecordBytes() []byte { func (self CodecData) AVCDecoderConfRecordBytes() []byte {
return self.Record return self.Record
} }
@ -563,10 +559,6 @@ func (self CodecData) PPS() []byte {
return self.RecordInfo.PPS[0] return self.RecordInfo.PPS[0]
} }
func (self CodecData) IsAudio() bool {
return false
}
func (self CodecData) Width() int { func (self CodecData) Width() int {
return int(self.SPSInfo.Width) return int(self.SPSInfo.Width)
} }