mirror of https://bitbucket.org/ausocean/av.git
mts: improved some const naming
This commit is contained in:
parent
e386f06adf
commit
3a872d46c8
|
@ -86,7 +86,7 @@ type Encoder struct {
|
||||||
clock time.Duration
|
clock time.Duration
|
||||||
frameInterval time.Duration
|
frameInterval time.Duration
|
||||||
ptsOffset time.Duration
|
ptsOffset time.Duration
|
||||||
tsSpace [mpegTsSize]byte
|
tsSpace [PktLen]byte
|
||||||
pesSpace [pes.MaxPesSize]byte
|
pesSpace [pes.MaxPesSize]byte
|
||||||
|
|
||||||
psiCount int
|
psiCount int
|
||||||
|
@ -160,7 +160,7 @@ func (e *Encoder) Encode(nalu []byte) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
e.psiCount--
|
e.psiCount--
|
||||||
_, err := e.dst.Write(pkt.Bytes(e.tsSpace[:mpegTsSize]))
|
_, err := e.dst.Write(pkt.Bytes(e.tsSpace[:PktLen]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ func (e *Encoder) writePSI() error {
|
||||||
AFC: hasPayload,
|
AFC: hasPayload,
|
||||||
Payload: addPadding(patTable),
|
Payload: addPadding(patTable),
|
||||||
}
|
}
|
||||||
_, err := e.dst.Write(patPkt.Bytes(e.tsSpace[:mpegTsSize]))
|
_, err := e.dst.Write(patPkt.Bytes(e.tsSpace[:PktLen]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -205,7 +205,7 @@ func (e *Encoder) writePSI() error {
|
||||||
AFC: hasPayload,
|
AFC: hasPayload,
|
||||||
Payload: addPadding(pmtTable),
|
Payload: addPadding(pmtTable),
|
||||||
}
|
}
|
||||||
_, err = e.dst.Write(pmtPkt.Bytes(e.tsSpace[:mpegTsSize]))
|
_, err = e.dst.Write(pmtPkt.Bytes(e.tsSpace[:PktLen]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
mpegTsSize = 188
|
PktLen = 188
|
||||||
mpegtsPayloadSize = 176
|
PayloadLen = 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) < mpegTsSize {
|
if len(d) < PktLen {
|
||||||
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 += mpegTsSize {
|
for i := 0; i < len(d); i += PktLen {
|
||||||
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+mpegTsSize]
|
p = d[i+4 : i+PktLen]
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ func FindPMT(d []byte) (p []byte, err error) {
|
||||||
func (p *Packet) FillPayload(data []byte) int {
|
func (p *Packet) FillPayload(data []byte) int {
|
||||||
currentPktLength := 6 + asInt(p.PCRF)*6 + asInt(p.OPCRF)*6 +
|
currentPktLength := 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, mpegtsPayloadSize-currentPktLength)
|
p.Payload = make([]byte, PayloadLen-currentPktLength)
|
||||||
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) != mpegTsSize {
|
if buf == nil || cap(buf) != PktLen {
|
||||||
buf = make([]byte, 0, mpegTsSize)
|
buf = make([]byte, 0, PktLen)
|
||||||
}
|
}
|
||||||
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