rtmp: removed use of s2 and replaced with len(buf)

This commit is contained in:
saxon 2018-09-02 11:32:11 +09:30
parent 390c882792
commit 24968c83b3
1 changed files with 5 additions and 10 deletions

View File

@ -2113,12 +2113,11 @@ func C_RTMP_Write(r *C_RTMP, buf []byte) int {
var pkt = &r.m_write var pkt = &r.m_write
var pend, enc []byte var pend, enc []byte
size := len(buf) size := len(buf)
s2 := size
var ret, num int var ret, num int
pkt.m_nChannel = 0x04 pkt.m_nChannel = 0x04
pkt.m_nInfoField2 = int32(r.m_stream_id) pkt.m_nInfoField2 = int32(r.m_stream_id)
for s2 != 0 { for len(buf) != 0 {
if pkt.m_nBytesRead == 0 { if pkt.m_nBytesRead == 0 {
if size < minDataSize { if size < minDataSize {
log.Printf("size: %d\n", size) 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' { if buf[0] == 'F' && buf[1] == 'L' && buf[2] == 'V' {
buf = buf[13:] buf = buf[13:]
s2 -= 13
} }
pkt.m_packetType = uint8(buf[0]) pkt.m_packetType = uint8(buf[0])
@ -2139,7 +2137,6 @@ func C_RTMP_Write(r *C_RTMP, buf []byte) int {
buf = buf[3:] buf = buf[3:]
pkt.m_nTimeStamp |= uint32(buf[0]) << 24 pkt.m_nTimeStamp |= uint32(buf[0]) << 24
buf = buf[4:] buf = buf[4:]
s2 -= 11
if ((pkt.m_packetType == RTMP_PACKET_TYPE_AUDIO || if ((pkt.m_packetType == RTMP_PACKET_TYPE_AUDIO ||
pkt.m_packetType == RTMP_PACKET_TYPE_VIDEO) && 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:] enc = ((*[_Gi]byte)(unsafe.Pointer(pkt.m_body))[:pkt.m_nBodySize])[pkt.m_nBytesRead:]
} }
num = int(pkt.m_nBodySize - pkt.m_nBytesRead) num = int(pkt.m_nBodySize - pkt.m_nBytesRead)
if num > s2 { if num > len(buf) {
num = s2 num = len(buf)
} }
copy(enc[:num], buf[:num]) copy(enc[:num], buf[:num])
pkt.m_nBytesRead += uint32(num) pkt.m_nBytesRead += uint32(num)
s2 -= num
buf = buf[num:] buf = buf[num:]
if pkt.m_nBytesRead == pkt.m_nBodySize { if pkt.m_nBytesRead == pkt.m_nBodySize {
// TODO: Port this // TODO: Port this
@ -2194,13 +2190,12 @@ func C_RTMP_Write(r *C_RTMP, buf []byte) int {
return -1 return -1
} }
buf = buf[4:] buf = buf[4:]
s2 -= 4 if len(buf) < 0 {
if s2 < 0 {
break break
} }
} }
} }
return size + s2 return size + len(buf)
} }
/* /*