From 716a92a72cf5f05dde7a9410444ef419ec4da3e5 Mon Sep 17 00:00:00 2001 From: saxon Date: Sat, 9 Feb 2019 19:31:15 +1030 Subject: [PATCH] stream/rtp/encoder.go: sendLen to sendSize and capturing error from e.Encode() --- stream/rtp/encoder.go | 11 +++++++---- stream/rtp/rtp.go | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/stream/rtp/encoder.go b/stream/rtp/encoder.go index b9453409..9cda9c00 100644 --- a/stream/rtp/encoder.go +++ b/stream/rtp/encoder.go @@ -40,7 +40,7 @@ const ( timestampFreq = 90000 // Hz mtsSize = 188 bufferSize = 1000 - sendLen = 7 * 188 + sendSize = 7 * 188 ) // Encoder implements io writer and provides functionality to wrap data into @@ -72,13 +72,16 @@ func NewEncoder(dst io.Writer, fps int) *Encoder { // so that multiple layers of packetization can occur. func (e *Encoder) Write(data []byte) (int, error) { e.buffer = append(e.buffer, data...) - if len(e.buffer) < sendLen { // sendSize + if len(e.buffer) < sendSize { return len(data), nil } buf := e.buffer for len(buf) != 0 { - l := min(sendLen, len(buf)) // sendSize - e.Encode(buf[:l]) + l := min(sendSize, len(buf)) + err := e.Encode(buf[:l]) + if err != nil { + return len(data), err + } buf = buf[l:] } e.buffer = e.buffer[:0] diff --git a/stream/rtp/rtp.go b/stream/rtp/rtp.go index 47f4a91b..92192294 100644 --- a/stream/rtp/rtp.go +++ b/stream/rtp/rtp.go @@ -35,7 +35,7 @@ package rtp const ( rtpVer = 2 headSize = 3 * 4 // Header size of an rtp packet. - defPayloadSize = sendLen // Default payload size for the rtp packet. + defPayloadSize = sendSize // Default payload size for the rtp packet. defPktSize = headSize + defPayloadSize // Default packet size is header size + payload size. )