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
|
clock time.Duration
|
||||||
frameInterval time.Duration
|
frameInterval time.Duration
|
||||||
ptsOffset time.Duration
|
ptsOffset time.Duration
|
||||||
tsSpace [PktLen]byte
|
tsSpace [PktSize]byte
|
||||||
pesSpace [pes.MaxPesLen]byte
|
pesSpace [pes.MaxPesLen]byte
|
||||||
|
|
||||||
psiCount int
|
psiCount int
|
||||||
|
@ -159,7 +159,7 @@ func (e *Encoder) Encode(nalu []byte) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
e.psiCount--
|
e.psiCount--
|
||||||
_, err := e.dst.Write(pkt.Bytes(e.tsSpace[:PktLen]))
|
_, err := e.dst.Write(pkt.Bytes(e.tsSpace[:PktSize]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ func (e *Encoder) writePSI() error {
|
||||||
AFC: hasPayload,
|
AFC: hasPayload,
|
||||||
Payload: patTable,
|
Payload: patTable,
|
||||||
}
|
}
|
||||||
_, err := e.dst.Write(patPkt.Bytes(e.tsSpace[:PktLen]))
|
_, err := e.dst.Write(patPkt.Bytes(e.tsSpace[:PktSize]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -204,7 +204,7 @@ func (e *Encoder) writePSI() error {
|
||||||
AFC: hasPayload,
|
AFC: hasPayload,
|
||||||
Payload: pmtTable,
|
Payload: pmtTable,
|
||||||
}
|
}
|
||||||
_, err = e.dst.Write(pmtPkt.Bytes(e.tsSpace[:PktLen]))
|
_, err = e.dst.Write(pmtPkt.Bytes(e.tsSpace[:PktSize]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PktLen = 188
|
PktSize = 188
|
||||||
PayloadLen = 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) < PktLen {
|
if len(d) < PktSize {
|
||||||
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 += PktLen {
|
for i := 0; i < len(d); i += PktSize {
|
||||||
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+PktLen]
|
p = d[i+4 : i+PktSize]
|
||||||
return
|
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
|
// FillPayload takes a channel and fills the packets Payload field until the
|
||||||
// channel is empty or we've the packet reaches capacity
|
// channel is empty or we've the packet reaches capacity
|
||||||
func (p *Packet) FillPayload(data []byte) int {
|
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)
|
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)
|
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
|
// 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) != PktLen {
|
if buf == nil || cap(buf) != PktSize {
|
||||||
buf = make([]byte, 0, PktLen)
|
buf = make([]byte, 0, PktSize)
|
||||||
}
|
}
|
||||||
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 -
|
||||||
|
|
Loading…
Reference in New Issue