From 287c3d32ac4220b3ef350a0ad7af8fde6854baa3 Mon Sep 17 00:00:00 2001 From: saxon Date: Sat, 1 Sep 2018 23:23:07 +0930 Subject: [PATCH] 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 --- rtmp/rtmp.go | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index 05f90d3b..28dc8542 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -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); // rtmp.c +5095 func C_RTMP_Write(r *C_RTMP, data []byte) int { - buf := sliceToPtr(data) + buf := data // TODO: port RTMPPacket var pkt = &r.m_write - var pend, enc unsafe.Pointer + var pend, enc []byte size := len(data) s2 := size var ret, num int @@ -2127,19 +2127,21 @@ func C_RTMP_Write(r *C_RTMP, data []byte) int { return 0 } - if (*[_Gi]byte)(buf)[0] == 'F' && (*[_Gi]byte)(buf)[1] == 'L' && (*[_Gi]byte)(buf)[2] == 'V' { - buf = unsafe.Pointer(uintptr(buf) + uintptr(13)) + if buf[0] == 'F' && buf[1] == 'L' && buf[2] == 'V' { + //buf = unsafe.Pointer(uintptr(buf) + uintptr(13)) + buf = buf[13:] s2 -= 13 } - pkt.m_packetType = uint8((*[_Gi]byte)(buf)[0]) - buf = incBytePtr(buf, 1) - pkt.m_nBodySize = uint32(C_AMF_DecodeInt24((*byte)(buf))) - buf = incBytePtr(buf, 3) - pkt.m_nTimeStamp = uint32(C_AMF_DecodeInt24((*byte)(buf))) - buf = incBytePtr(buf, 3) - pkt.m_nTimeStamp |= uint32((*[_Gi]byte)(buf)[0]) << 24 - buf = incBytePtr(buf, 4) + pkt.m_packetType = uint8(buf[0]) + buf = buf[1:] + pkt.m_nBodySize = uint32(C_AMF_DecodeInt24(&buf[0])) + //buf = incBytePtr(buf, 3) + buf = buf[3:] + pkt.m_nTimeStamp = uint32(C_AMF_DecodeInt24(&buf[0])) + buf = buf[3:] + pkt.m_nTimeStamp |= uint32(buf[0]) << 24 + buf = buf[4:] s2 -= 11 if ((pkt.m_packetType == RTMP_PACKET_TYPE_AUDIO || @@ -2160,27 +2162,34 @@ func C_RTMP_Write(r *C_RTMP, data []byte) int { return 0 } - enc = unsafe.Pointer(pkt.m_body) - pend = incBytePtr(enc, int(pkt.m_nBodySize)) + enc = (*[_Gi]byte)(unsafe.Pointer(pkt.m_body))[:pkt.m_nBodySize] + //pend = incBytePtr(enc, int(pkt.m_nBodySize)) + pend = enc[pkt.m_nBodySize:] if pkt.m_packetType == RTMP_PACKET_TYPE_INFO { - enc = unsafe.Pointer(C_AMF_EncodeString((*byte)(enc), (*byte)(pend), &setDataFrame)) - pkt.m_nBytesRead = uint32(math.Abs(float64(uintptr(enc) - + enc = (*[_Gi]byte)(unsafe.Pointer(C_AMF_EncodeString((*byte)(unsafe.Pointer(&enc[0])), + (*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))))) } } 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) if num > s2 { num = s2 } - memmove(enc, buf, uintptr(num)) + copy(enc[:num], buf[:num]) + //memmove(enc, buf, uintptr(num)) pkt.m_nBytesRead += uint32(num) s2 -= num - buf = incBytePtr(buf, num) + //buf = incBytePtr(buf, num) + buf = buf[num:] if pkt.m_nBytesRead == pkt.m_nBodySize { // TODO: Port this ret = C_RTMP_SendPacket(r, pkt, 0) @@ -2191,7 +2200,8 @@ func C_RTMP_Write(r *C_RTMP, data []byte) int { if ret == 0 { return -1 } - buf = incBytePtr(buf, 4) + buf = buf[4:] + //buf = incBytePtr(buf, 4) s2 -= 4 if s2 < 0 { break