From 24968c83b37b102935f256c1d5b1e90cc733a68e Mon Sep 17 00:00:00 2001 From: saxon Date: Sun, 2 Sep 2018 11:32:11 +0930 Subject: [PATCH] rtmp: removed use of s2 and replaced with len(buf) --- rtmp/rtmp.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index d76fdef7..83d151a8 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -2113,12 +2113,11 @@ func C_RTMP_Write(r *C_RTMP, buf []byte) int { var pkt = &r.m_write var pend, enc []byte size := len(buf) - s2 := size var ret, num int pkt.m_nChannel = 0x04 pkt.m_nInfoField2 = int32(r.m_stream_id) - for s2 != 0 { + for len(buf) != 0 { if pkt.m_nBytesRead == 0 { if size < minDataSize { log.Printf("size: %d\n", size) @@ -2128,7 +2127,6 @@ func C_RTMP_Write(r *C_RTMP, buf []byte) int { if buf[0] == 'F' && buf[1] == 'L' && buf[2] == 'V' { buf = buf[13:] - s2 -= 13 } pkt.m_packetType = uint8(buf[0]) @@ -2139,7 +2137,6 @@ func C_RTMP_Write(r *C_RTMP, buf []byte) int { buf = buf[3:] pkt.m_nTimeStamp |= uint32(buf[0]) << 24 buf = buf[4:] - s2 -= 11 if ((pkt.m_packetType == RTMP_PACKET_TYPE_AUDIO || pkt.m_packetType == RTMP_PACKET_TYPE_VIDEO) && @@ -2175,13 +2172,12 @@ func C_RTMP_Write(r *C_RTMP, buf []byte) int { enc = ((*[_Gi]byte)(unsafe.Pointer(pkt.m_body))[:pkt.m_nBodySize])[pkt.m_nBytesRead:] } num = int(pkt.m_nBodySize - pkt.m_nBytesRead) - if num > s2 { - num = s2 + if num > len(buf) { + num = len(buf) } copy(enc[:num], buf[:num]) pkt.m_nBytesRead += uint32(num) - s2 -= num buf = buf[num:] if pkt.m_nBytesRead == pkt.m_nBodySize { // TODO: Port this @@ -2194,13 +2190,12 @@ func C_RTMP_Write(r *C_RTMP, buf []byte) int { return -1 } buf = buf[4:] - s2 -= 4 - if s2 < 0 { + if len(buf) < 0 { break } } } - return size + s2 + return size + len(buf) } /*