mts: PktSize to PacketSize

This commit is contained in:
saxon 2019-01-12 17:36:35 +10:30
parent 010abcfd0c
commit 46f5ffd6f2
2 changed files with 10 additions and 10 deletions

View File

@ -196,7 +196,7 @@ type Encoder struct {
clock time.Duration clock time.Duration
frameInterval time.Duration frameInterval time.Duration
ptsOffset time.Duration ptsOffset time.Duration
tsSpace [PktSize]byte tsSpace [PacketSize]byte
pesSpace [pes.MaxPesSize]byte pesSpace [pes.MaxPesSize]byte
psiCount int psiCount int
@ -269,7 +269,7 @@ func (e *Encoder) Encode(nalu []byte) error {
} }
} }
e.psiCount-- e.psiCount--
_, err := e.dst.Write(pkt.Bytes(e.tsSpace[:PktSize])) _, err := e.dst.Write(pkt.Bytes(e.tsSpace[:PacketSize]))
if err != nil { if err != nil {
return err return err
} }
@ -291,7 +291,7 @@ func (e *Encoder) writePSI() error {
AFC: hasPayload, AFC: hasPayload,
Payload: patTable, Payload: patTable,
} }
_, err := e.dst.Write(patPkt.Bytes(e.tsSpace[:PktSize])) _, err := e.dst.Write(patPkt.Bytes(e.tsSpace[:PacketSize]))
if err != nil { if err != nil {
return err return err
} }
@ -314,7 +314,7 @@ func (e *Encoder) writePSI() error {
AFC: hasPayload, AFC: hasPayload,
Payload: pmtTable, Payload: pmtTable,
} }
_, err = e.dst.Write(pmtPkt.Bytes(e.tsSpace[:PktSize])) _, err = e.dst.Write(pmtPkt.Bytes(e.tsSpace[:PacketSize]))
if err != nil { if err != nil {
return err return err
} }

View File

@ -33,7 +33,7 @@ import (
) )
const ( const (
PktSize = 188 PacketSize = 188
PayloadSize = 176 PayloadSize = 176
) )
@ -130,13 +130,13 @@ type Packet struct {
// FindPMT will take a clip of mpegts and try to find a PMT table - if one // FindPMT will take a clip of mpegts and try to find a PMT table - if one
// is found, then it is returned, otherwise nil and an error is returned. // is found, then it is returned, otherwise nil and an error is returned.
func FindPMT(d []byte) (p []byte, err error) { func FindPMT(d []byte) (p []byte, err error) {
if len(d) < PktSize { if len(d) < PacketSize {
return nil, errors.New("Mmpegts data not of valid length") return nil, errors.New("Mmpegts data not of valid length")
} }
for i := 0; i < len(d); i += PktSize { for i := 0; i < len(d); i += PacketSize {
pid := (uint16(d[i+1]&0x1f) << 8) | uint16(d[i+2]) pid := (uint16(d[i+1]&0x1f) << 8) | uint16(d[i+2])
if pid == pmtPid { if pid == pmtPid {
p = d[i+4 : i+PktSize] p = d[i+4 : i+PacketSize]
return return
} }
} }
@ -169,8 +169,8 @@ func asByte(b bool) byte {
// ToByteSlice interprets the fields of the ts packet instance and outputs a // ToByteSlice interprets the fields of the ts packet instance and outputs a
// corresponding byte slice // corresponding byte slice
func (p *Packet) Bytes(buf []byte) []byte { func (p *Packet) Bytes(buf []byte) []byte {
if buf == nil || cap(buf) != PktSize { if buf == nil || cap(buf) != PacketSize {
buf = make([]byte, 0, PktSize) buf = make([]byte, 0, PacketSize)
} }
buf = buf[:0] buf = buf[:0]
stuffingLength := 182 - len(p.Payload) - len(p.TPD) - asInt(p.PCRF)*6 - stuffingLength := 182 - len(p.Payload) - len(p.TPD) - asInt(p.PCRF)*6 -