diff --git a/revid/mtsSender_test.go b/revid/mtsSender_test.go index 5a8f5fa0..3eb65dae 100644 --- a/revid/mtsSender_test.go +++ b/revid/mtsSender_test.go @@ -116,7 +116,7 @@ func TestSegment(t *testing.T) { for i := 0; i < noOfPacketsToWrite; i++ { // Insert a payload so that we check that the segmentation works correctly // in this regard. Packet number will be used. - encoder.Encode([]byte{byte(i)}) + encoder.Write([]byte{byte(i)}) rb.Flush() for { @@ -203,7 +203,7 @@ func TestSendFailDiscontinuity(t *testing.T) { const noOfPacketsToWrite = 100 for i := 0; i < noOfPacketsToWrite; i++ { // Our payload will just be packet number. - encoder.Encode([]byte{byte(i)}) + encoder.Write([]byte{byte(i)}) rb.Flush() for { diff --git a/revid/revid.go b/revid/revid.go index 087cbbfa..38c4d7a3 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -453,7 +453,7 @@ loop: // Loop over encoders and hand bytes over to each one. for _, enc := range r.encoder { - err := enc.Encode(bytes) + _, err := enc.Write(bytes) if err != nil { r.err <- err } diff --git a/stream/encoding.go b/stream/encoding.go index 26f0e19b..493f6b83 100644 --- a/stream/encoding.go +++ b/stream/encoding.go @@ -30,7 +30,7 @@ package stream import "io" type Encoder interface { - Encode([]byte) error + Write([]byte) (int, error) } // NopEncoder returns an @@ -42,7 +42,7 @@ type noop struct { dst io.Writer } -func (e noop) Encode(p []byte) error { - _, err := e.dst.Write(p) - return err +func (e noop) Write(p []byte) (int, error) { + n, err := e.dst.Write(p) + return n, err } diff --git a/stream/flv/encoder.go b/stream/flv/encoder.go index 46d0eacb..a340b182 100644 --- a/stream/flv/encoder.go +++ b/stream/flv/encoder.go @@ -189,7 +189,7 @@ func (s *frameScanner) readByte() (b byte, ok bool) { // generate takes in raw video data from the input chan and packetises it into // flv tags, which are then passed to the output channel. -func (e *Encoder) Encode(frame []byte) error { +func (e *Encoder) Write(frame []byte) (int, error) { var frameType byte var packetType byte if e.start.IsZero() { @@ -198,9 +198,9 @@ func (e *Encoder) Encode(frame []byte) error { // See https://download.macromedia.com/f4v/video_file_format_spec_v10_1.pdf // section E.3. var zero [4]byte - _, err := e.dst.Write(zero[:]) + n, err := e.dst.Write(zero[:]) if err != nil { - return err + return n, err } } timeStamp := e.getNextTimestamp() @@ -229,9 +229,9 @@ func (e *Encoder) Encode(frame []byte) error { Data: frame, PrevTagSize: uint32(videoHeaderSize + len(frame)), } - _, err := e.dst.Write(tag.Bytes()) + n, err := e.dst.Write(tag.Bytes()) if err != nil { - return err + return n, err } } // Do we even have some audio to send off ? @@ -250,9 +250,9 @@ func (e *Encoder) Encode(frame []byte) error { Data: dummyAudioTag1Data, PrevTagSize: uint32(audioSize), } - _, err := e.dst.Write(tag.Bytes()) + n, err := e.dst.Write(tag.Bytes()) if err != nil { - return err + return n, err } tag = AudioTag{ @@ -267,11 +267,11 @@ func (e *Encoder) Encode(frame []byte) error { Data: dummyAudioTag2Data, PrevTagSize: uint32(22), } - _, err = e.dst.Write(tag.Bytes()) + n, err = e.dst.Write(tag.Bytes()) if err != nil { - return err + return n, err } } - return nil + return len(frame), nil } diff --git a/stream/mts/encoder.go b/stream/mts/encoder.go index b1e098a4..ca534985 100644 --- a/stream/mts/encoder.go +++ b/stream/mts/encoder.go @@ -180,13 +180,13 @@ func (e *Encoder) TimeBasedPsi(b bool, sendCount int) { // generate handles the incoming data and generates equivalent mpegts packets - // sending them to the output channel. -func (e *Encoder) Encode(nalu []byte) error { +func (e *Encoder) Write(nalu []byte) (int, error) { now := time.Now() if (e.timeBasedPsi && (now.Sub(e.psiLastTime) > psiInterval)) || (!e.timeBasedPsi && (e.pktCount >= e.psiSendCount)) { e.pktCount = 0 err := e.writePSI() if err != nil { - return err + return 0, err } e.psiLastTime = now } @@ -220,16 +220,16 @@ func (e *Encoder) Encode(nalu []byte) error { pkt.PCR = e.pcr() pusi = false } - _, err := e.dst.Write(pkt.Bytes(e.tsSpace[:PacketSize])) + n, err := e.dst.Write(pkt.Bytes(e.tsSpace[:PacketSize])) if err != nil { - return err + return n, err } e.pktCount++ } e.tick() - return nil + return len(nalu), nil } // writePSI creates mpegts with pat and pmt tables - with pmt table having updated