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 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)
}
/*