From df146cfb17f06951c2fc4318d967ab83ffb2ba3f Mon Sep 17 00:00:00 2001 From: saxon Date: Wed, 23 Jan 2019 15:50:25 +1030 Subject: [PATCH] stream/mts/encoder.go: writing psi at start of stream --- stream/mts/encoder.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/stream/mts/encoder.go b/stream/mts/encoder.go index decc8558..60393285 100644 --- a/stream/mts/encoder.go +++ b/stream/mts/encoder.go @@ -233,6 +233,12 @@ const ( // generate handles the incoming data and generates equivalent mpegts packets - // sending them to the output channel. func (e *Encoder) Encode(nalu []byte) error { + if e.psiCount <= 0 { + err := e.writePSI() + if err != nil { + return err + } + } // Prepare PES data. pesPkt := pes.Packet{ StreamID: streamID, @@ -262,14 +268,8 @@ func (e *Encoder) Encode(nalu []byte) error { pkt.PCR = e.pcr() 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])) + e.psiCount-- if err != nil { return err }