stream/rtp/encoder.go: sendLen to sendSize and capturing error from e.Encode()

This commit is contained in:
saxon 2019-02-09 19:31:15 +10:30
parent 01513fbb3f
commit 716a92a72c
2 changed files with 8 additions and 5 deletions

View File

@ -40,7 +40,7 @@ const (
timestampFreq = 90000 // Hz timestampFreq = 90000 // Hz
mtsSize = 188 mtsSize = 188
bufferSize = 1000 bufferSize = 1000
sendLen = 7 * 188 sendSize = 7 * 188
) )
// Encoder implements io writer and provides functionality to wrap data into // 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. // so that multiple layers of packetization can occur.
func (e *Encoder) Write(data []byte) (int, error) { func (e *Encoder) Write(data []byte) (int, error) {
e.buffer = append(e.buffer, data...) e.buffer = append(e.buffer, data...)
if len(e.buffer) < sendLen { // sendSize if len(e.buffer) < sendSize {
return len(data), nil return len(data), nil
} }
buf := e.buffer buf := e.buffer
for len(buf) != 0 { for len(buf) != 0 {
l := min(sendLen, len(buf)) // sendSize l := min(sendSize, len(buf))
e.Encode(buf[:l]) err := e.Encode(buf[:l])
if err != nil {
return len(data), err
}
buf = buf[l:] buf = buf[l:]
} }
e.buffer = e.buffer[:0] e.buffer = e.buffer[:0]

View File

@ -35,7 +35,7 @@ package rtp
const ( const (
rtpVer = 2 rtpVer = 2
headSize = 3 * 4 // Header size of an rtp packet. 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. defPktSize = headSize + defPayloadSize // Default packet size is header size + payload size.
) )