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 (
"github.com/nareix/bits"
"github.com/nareix/av"
"time"
"fmt"
"bytes"
"io"
@ -333,15 +334,7 @@ type CodecData struct {
Config MPEG4AudioConfig
}
func (self CodecData) IsVideo() bool {
return false
}
func (self CodecData) IsAudio() bool {
return true
}
func (self CodecData) Type() int {
func (self CodecData) Type() av.CodecType {
return av.AAC
}
@ -361,6 +354,11 @@ func (self CodecData) SampleFormat() av.SampleFormat {
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 {
return MakeADTSHeader(self.Config, samples, payloadLength)
}

View File

@ -2,54 +2,42 @@ package codec
import (
"github.com/nareix/av"
"time"
)
type AudioCodecData struct {
CodecType int
CodecSampleRate int
CodecChannelLayout av.ChannelLayout
CodecSampleFormat av.SampleFormat
type PCMUCodecData struct {
typ av.CodecType
}
func (self AudioCodecData) Type() int {
return self.CodecType
func (self PCMUCodecData) Type() av.CodecType {
return self.typ
}
func (self AudioCodecData) IsAudio() bool {
return true
func (self PCMUCodecData) SampleRate() int {
return 8000
}
func (self AudioCodecData) IsVideo() bool {
return false
func (self PCMUCodecData) ChannelLayout() av.ChannelLayout {
return av.CH_MONO
}
func (self AudioCodecData) SampleRate() int {
return self.CodecSampleRate
func (self PCMUCodecData) SampleFormat() av.SampleFormat {
return av.S16
}
func (self AudioCodecData) ChannelLayout() av.ChannelLayout {
return self.CodecChannelLayout
}
func (self AudioCodecData) SampleFormat() av.SampleFormat {
return self.CodecSampleFormat
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 AudioCodecData{
CodecType: av.PCM_MULAW,
CodecSampleFormat: av.S16,
CodecChannelLayout: av.CH_MONO,
CodecSampleRate: 8000,
return PCMUCodecData{
typ: av.PCM_MULAW,
}
}
func NewPCMAlawCodecData() av.AudioCodecData {
return AudioCodecData{
CodecType: av.PCM_ALAW,
CodecSampleFormat: av.S16,
CodecChannelLayout: av.CH_MONO,
CodecSampleRate: 8000,
return PCMUCodecData{
typ: av.PCM_ALAW,
}
}

View File

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