stream/mts/encoder.go: writing psi at start of stream

This commit is contained in:
saxon 2019-01-23 15:50:25 +10:30
parent 1ec23badcc
commit df146cfb17
1 changed files with 7 additions and 7 deletions

View File

@ -233,6 +233,12 @@ const (
// generate handles the incoming data and generates equivalent mpegts packets - // generate handles the incoming data and generates equivalent mpegts packets -
// sending them to the output channel. // sending them to the output channel.
func (e *Encoder) Encode(nalu []byte) error { func (e *Encoder) Encode(nalu []byte) error {
if e.psiCount <= 0 {
err := e.writePSI()
if err != nil {
return err
}
}
// Prepare PES data. // Prepare PES data.
pesPkt := pes.Packet{ pesPkt := pes.Packet{
StreamID: streamID, StreamID: streamID,
@ -262,14 +268,8 @@ func (e *Encoder) Encode(nalu []byte) error {
pkt.PCR = e.pcr() pkt.PCR = e.pcr()
pusi = false pusi = false
} }
if e.psiCount <= 0 {
err := e.writePSI()
if err != nil {
return err
}
}
e.psiCount--
_, err := e.dst.Write(pkt.Bytes(e.tsSpace[:PacketSize])) _, err := e.dst.Write(pkt.Bytes(e.tsSpace[:PacketSize]))
e.psiCount--
if err != nil { if err != nil {
return err return err
} }