rtmp: tried removing some unsafe pointers in C_RTMP_Write - ended up breaking it. Youtube tells me it's starting but it now goes live

This commit is contained in:
saxon 2018-09-01 23:23:07 +09:30
parent c494da9a1d
commit 287c3d32ac
1 changed files with 30 additions and 20 deletions

View File

@ -2109,10 +2109,10 @@ func C_RTMPSockBuf_Send(sb *C_RTMPSockBuf, buf *byte, l int32) int32 {
// int RTMP_Write(RTMP* r, const char* buf, int size); // int RTMP_Write(RTMP* r, const char* buf, int size);
// rtmp.c +5095 // rtmp.c +5095
func C_RTMP_Write(r *C_RTMP, data []byte) int { func C_RTMP_Write(r *C_RTMP, data []byte) int {
buf := sliceToPtr(data) buf := data
// TODO: port RTMPPacket // TODO: port RTMPPacket
var pkt = &r.m_write var pkt = &r.m_write
var pend, enc unsafe.Pointer var pend, enc []byte
size := len(data) size := len(data)
s2 := size s2 := size
var ret, num int var ret, num int
@ -2127,19 +2127,21 @@ func C_RTMP_Write(r *C_RTMP, data []byte) int {
return 0 return 0
} }
if (*[_Gi]byte)(buf)[0] == 'F' && (*[_Gi]byte)(buf)[1] == 'L' && (*[_Gi]byte)(buf)[2] == 'V' { if buf[0] == 'F' && buf[1] == 'L' && buf[2] == 'V' {
buf = unsafe.Pointer(uintptr(buf) + uintptr(13)) //buf = unsafe.Pointer(uintptr(buf) + uintptr(13))
buf = buf[13:]
s2 -= 13 s2 -= 13
} }
pkt.m_packetType = uint8((*[_Gi]byte)(buf)[0]) pkt.m_packetType = uint8(buf[0])
buf = incBytePtr(buf, 1) buf = buf[1:]
pkt.m_nBodySize = uint32(C_AMF_DecodeInt24((*byte)(buf))) pkt.m_nBodySize = uint32(C_AMF_DecodeInt24(&buf[0]))
buf = incBytePtr(buf, 3) //buf = incBytePtr(buf, 3)
pkt.m_nTimeStamp = uint32(C_AMF_DecodeInt24((*byte)(buf))) buf = buf[3:]
buf = incBytePtr(buf, 3) pkt.m_nTimeStamp = uint32(C_AMF_DecodeInt24(&buf[0]))
pkt.m_nTimeStamp |= uint32((*[_Gi]byte)(buf)[0]) << 24 buf = buf[3:]
buf = incBytePtr(buf, 4) pkt.m_nTimeStamp |= uint32(buf[0]) << 24
buf = buf[4:]
s2 -= 11 s2 -= 11
if ((pkt.m_packetType == RTMP_PACKET_TYPE_AUDIO || if ((pkt.m_packetType == RTMP_PACKET_TYPE_AUDIO ||
@ -2160,27 +2162,34 @@ func C_RTMP_Write(r *C_RTMP, data []byte) int {
return 0 return 0
} }
enc = unsafe.Pointer(pkt.m_body) enc = (*[_Gi]byte)(unsafe.Pointer(pkt.m_body))[:pkt.m_nBodySize]
pend = incBytePtr(enc, int(pkt.m_nBodySize)) //pend = incBytePtr(enc, int(pkt.m_nBodySize))
pend = enc[pkt.m_nBodySize:]
if pkt.m_packetType == RTMP_PACKET_TYPE_INFO { if pkt.m_packetType == RTMP_PACKET_TYPE_INFO {
enc = unsafe.Pointer(C_AMF_EncodeString((*byte)(enc), (*byte)(pend), &setDataFrame)) enc = (*[_Gi]byte)(unsafe.Pointer(C_AMF_EncodeString((*byte)(unsafe.Pointer(&enc[0])),
pkt.m_nBytesRead = uint32(math.Abs(float64(uintptr(enc) - (*byte)(unsafe.Pointer(&pend[0])), &setDataFrame)))[:pkt.m_nBodySize]
// TODO: work out what to do with this
pkt.m_nBytesRead = uint32(math.Abs(float64(uintptr(unsafe.Pointer(&enc[0])) -
uintptr(unsafe.Pointer(pkt.m_body))))) uintptr(unsafe.Pointer(pkt.m_body)))))
} }
} else { } else {
enc = incBytePtr(unsafe.Pointer(pkt.m_body), int(pkt.m_nBytesRead)) enc = ((*[_Gi]byte)(unsafe.Pointer(pkt.m_body))[:pkt.m_nBodySize])[pkt.m_nBytesRead:]
//enc = incBytePtr(unsafe.Pointer(pkt.m_body), int(pkt.m_nBytesRead))
} }
num = int(pkt.m_nBodySize - pkt.m_nBytesRead) num = int(pkt.m_nBodySize - pkt.m_nBytesRead)
if num > s2 { if num > s2 {
num = s2 num = s2
} }
memmove(enc, buf, uintptr(num)) copy(enc[:num], buf[:num])
//memmove(enc, buf, uintptr(num))
pkt.m_nBytesRead += uint32(num) pkt.m_nBytesRead += uint32(num)
s2 -= num s2 -= num
buf = incBytePtr(buf, num) //buf = incBytePtr(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
ret = C_RTMP_SendPacket(r, pkt, 0) ret = C_RTMP_SendPacket(r, pkt, 0)
@ -2191,7 +2200,8 @@ func C_RTMP_Write(r *C_RTMP, data []byte) int {
if ret == 0 { if ret == 0 {
return -1 return -1
} }
buf = incBytePtr(buf, 4) buf = buf[4:]
//buf = incBytePtr(buf, 4)
s2 -= 4 s2 -= 4
if s2 < 0 { if s2 < 0 {
break break