From 438cf8470b3ebac3ca2207657899f7dbaf879c7e Mon Sep 17 00:00:00 2001 From: saxon Date: Sat, 14 Jul 2018 14:30:58 +0930 Subject: [PATCH] Created incPtr function for ptr increment --- rtmp/rtmp.go | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index 7f6242f0..77042fa4 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -147,21 +147,21 @@ func rtmpWrite(r *C.RTMP, data []byte) int { return 0 } buf0 := *(*byte)(buf) - buf1 := *(*byte)(unsafe.Pointer(uintptr(buf) + uintptr(1))) - buf2 := *(*byte)(unsafe.Pointer(uintptr(buf) + uintptr(2))) + buf1 := *(*byte)(incPtr(buf,1)) + buf2 := *(*byte)(incPtr(buf,2)) if buf0 == 'F' && buf1 == 'L' && buf2 == 'V' { buf = unsafe.Pointer(uintptr(buf) + uintptr(13)) s2 -= 13 } pkt.m_packetType = C.uchar(*(*byte)(buf)) - buf = unsafe.Pointer(uintptr(buf) + uintptr(1)) + buf = incPtr(buf,1) pkt.m_nBodySize = C.AMF_DecodeInt24((*C.char)(buf)) - buf = unsafe.Pointer(uintptr(buf) + uintptr(3)) + buf = incPtr(buf,3) pkt.m_nTimeStamp = C.AMF_DecodeInt24((*C.char)(buf)) - buf = unsafe.Pointer(uintptr(buf) + uintptr(3)) + buf = incPtr(buf,3) pkt.m_nTimeStamp |= C.uint(*((*byte)(buf))) << 24 - buf = unsafe.Pointer(uintptr(buf) + uintptr(4)) + buf = incPtr(buf,4) s2 -= 11 if ((pkt.m_packetType == RTMP_PACKET_TYPE_AUDIO || @@ -183,8 +183,7 @@ func rtmpWrite(r *C.RTMP, data []byte) int { } enc = unsafe.Pointer(pkt.m_body) - pend = unsafe.Pointer(uintptr(enc) + - uintptr(pkt.m_nBodySize)) + pend = incPtr(enc,int(pkt.m_nBodySize)) if pkt.m_packetType == RTMP_PACKET_TYPE_INFO { enc = unsafe.Pointer(C.AMF_EncodeString((*C.char)(enc), (*C.char)(pend), &setDataFrame)) @@ -193,25 +192,18 @@ func rtmpWrite(r *C.RTMP, data []byte) int { } } else { - enc = unsafe.Pointer(uintptr(unsafe.Pointer(pkt.m_body)) + - uintptr(pkt.m_nBytesRead)) + enc = incPtr(unsafe.Pointer(pkt.m_body),int(pkt.m_nBytesRead)) } num = int(pkt.m_nBodySize - pkt.m_nBytesRead) if num > s2 { num = s2 } - /* - // this will be a mem cpy func - for i := 0; i < num; i++ { - *(*byte)(enc) = *(*byte)(buf) - } - */ // TODO: Can only remove this mem copy onc I port the RTMPPacket struct and // AllocatPacket C.memcpy(enc,buf,C.ulong(num)) pkt.m_nBytesRead += C.uint(num) s2 -= num - buf = unsafe.Pointer(uintptr(buf) + uintptr(num)) + buf = incPtr(buf,num) if pkt.m_nBytesRead == pkt.m_nBodySize { ret = int(C.RTMP_SendPacket(r, pkt, 0)) C.RTMPPacket_Free(pkt) @@ -219,7 +211,7 @@ func rtmpWrite(r *C.RTMP, data []byte) int { if ret == 0 { return -1 } - buf = unsafe.Pointer(uintptr(buf) + uintptr(4)) + buf = incPtr(buf,4) s2 -= 4 if s2 < 0 { break @@ -229,11 +221,11 @@ func rtmpWrite(r *C.RTMP, data []byte) int { return size + s2 } -/* + func incPtr(ptr unsafe.Pointer, inc int) unsafe.Pointer { - return unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(4)) + return unsafe.Pointer(uintptr(ptr) + uintptr(inc)) } -*/ + /* func sendPacket(r *C.RTMP, pkt *C.RTMPPacket, queue int) int {