mirror of https://bitbucket.org/ausocean/av.git
mts: replaced usage of Len with Size for PktSize and PayloadSize etc
This commit is contained in:
parent
24bc974b01
commit
52b8f7bf54
|
@ -85,7 +85,7 @@ type Encoder struct {
|
|||
clock time.Duration
|
||||
frameInterval time.Duration
|
||||
ptsOffset time.Duration
|
||||
tsSpace [PktLen]byte
|
||||
tsSpace [PktSize]byte
|
||||
pesSpace [pes.MaxPesLen]byte
|
||||
|
||||
psiCount int
|
||||
|
@ -159,7 +159,7 @@ func (e *Encoder) Encode(nalu []byte) error {
|
|||
}
|
||||
}
|
||||
e.psiCount--
|
||||
_, err := e.dst.Write(pkt.Bytes(e.tsSpace[:PktLen]))
|
||||
_, err := e.dst.Write(pkt.Bytes(e.tsSpace[:PktSize]))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ func (e *Encoder) writePSI() error {
|
|||
AFC: hasPayload,
|
||||
Payload: patTable,
|
||||
}
|
||||
_, err := e.dst.Write(patPkt.Bytes(e.tsSpace[:PktLen]))
|
||||
_, err := e.dst.Write(patPkt.Bytes(e.tsSpace[:PktSize]))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ func (e *Encoder) writePSI() error {
|
|||
AFC: hasPayload,
|
||||
Payload: pmtTable,
|
||||
}
|
||||
_, err = e.dst.Write(pmtPkt.Bytes(e.tsSpace[:PktLen]))
|
||||
_, err = e.dst.Write(pmtPkt.Bytes(e.tsSpace[:PktSize]))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
PktLen = 188
|
||||
PayloadLen = 176
|
||||
PktSize = 188
|
||||
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
|
||||
// is found, then it is returned, otherwise nil and an error is returned.
|
||||
func FindPMT(d []byte) (p []byte, err error) {
|
||||
if len(d) < PktLen {
|
||||
if len(d) < PktSize {
|
||||
return nil, errors.New("Mmpegts data not of valid length")
|
||||
}
|
||||
for i := 0; i < len(d); i += PktLen {
|
||||
for i := 0; i < len(d); i += PktSize {
|
||||
pid := (uint16(d[i+1]&0x1f) << 8) | uint16(d[i+2])
|
||||
if pid == pmtPid {
|
||||
p = d[i+4 : i+PktLen]
|
||||
p = d[i+4 : i+PktSize]
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -146,9 +146,9 @@ func FindPMT(d []byte) (p []byte, err error) {
|
|||
// FillPayload takes a channel and fills the packets Payload field until the
|
||||
// channel is empty or we've the packet reaches capacity
|
||||
func (p *Packet) FillPayload(data []byte) int {
|
||||
currentPktLength := 6 + asInt(p.PCRF)*6 + asInt(p.OPCRF)*6 +
|
||||
currentPktSizegth := 6 + asInt(p.PCRF)*6 + asInt(p.OPCRF)*6 +
|
||||
asInt(p.SPF)*1 + asInt(p.TPDF)*1 + len(p.TPD)
|
||||
p.Payload = make([]byte, PayloadLen-currentPktLength)
|
||||
p.Payload = make([]byte, PayloadSize-currentPktSizegth)
|
||||
return copy(p.Payload, data)
|
||||
}
|
||||
|
||||
|
@ -169,8 +169,8 @@ func asByte(b bool) byte {
|
|||
// ToByteSlice interprets the fields of the ts packet instance and outputs a
|
||||
// corresponding byte slice
|
||||
func (p *Packet) Bytes(buf []byte) []byte {
|
||||
if buf == nil || cap(buf) != PktLen {
|
||||
buf = make([]byte, 0, PktLen)
|
||||
if buf == nil || cap(buf) != PktSize {
|
||||
buf = make([]byte, 0, PktSize)
|
||||
}
|
||||
buf = buf[:0]
|
||||
stuffingLength := 182 - len(p.Payload) - len(p.TPD) - asInt(p.PCRF)*6 -
|
||||
|
|
Loading…
Reference in New Issue