From 929bdb32f9a4a4b696a5084d3ae6de3a21c1f124 Mon Sep 17 00:00:00 2001 From: saxon Date: Thu, 12 Jul 2018 00:31:17 +0930 Subject: [PATCH] Think I've cleaned it up a bit more, about to build --- rtmp/rtmp.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index d6f02786..c7518bff 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -107,11 +107,6 @@ func byteSliceToCArr(buf []byte) *C.char { return (*C.char)(unsafe.Pointer(&buf[0])) } -func cPtrInc(a *C.char, inc C.uint) *C.char { - return (*C.char)(unsafe.Pointer( uintptr(unsafe.Pointer(a)) + - ( unsafe.Sizeof(C.char(0x00)) * (uintptr(inc)) ) )) -} - func (s *session) rtmpWrite(r *C.RTMP, buf []byte) int { var pkt *C.RTMPPacket = &r.m_write size := len(buf) @@ -164,19 +159,19 @@ func (s *session) rtmpWrite(r *C.RTMP, buf []byte) int { return 0 } - enc := C.GoBytes(unsafe.Pointer(pkt.m_body),C.int(pkt.m_nBodySize)) - pend := enc[int(pkt.m_nBodySize):] + enc := unsafe.Pointer(pkt.m_body) + pend += enc + pkt.m_nBodySize + pend := unsafe.Pointer(uintptr(enc) + uintptr(pkt.m_nBodySize)) if pkt.m_packetType == C.RTMP_PACKET_TYPE_INFO { - enc = C.AMF_EncodeString(enc, pend, &av_setDataFrame ) + enc = C.AMF_EncodeString((*C.char)(enc), (*C.char)(pend), &av_setDataFrame ) // C-code: pkt.m_nBytesRead enc - pkt.m_body - pkt.m_nBytesRead = (C.uint)((uintptr(unsafe.Pointer(enc)) - - uintptr(unsafe.Pointer(pkt.m_body)))/unsafe.Sizeof(C.char(0x00))) + pkt.m_nBytesRead = (C.uint)(uintptr(enc)-uintptr(unsafe.Pointer(pkt.m_body))) } } else { //C-code: enc = pkt.m_body + pkt.m_nBytesRead - enc = cPtrInc(pkt.m_body,pkt.m_nBytesRead) + enc = unsafe.Pointer(uinptr(pkt.m_body) + uintptr(pkt.m_nBytesRead)) } num = int(pkt.m_nBodySize - pkt.m_nBytesRead) @@ -184,9 +179,8 @@ func (s *session) rtmpWrite(r *C.RTMP, buf []byte) int { if num > s2 { num = s2 } - // C.memcpy(enc, buf, num) - // Need to create byte slice from c array enc - encSlice := C.GoBytes(unsafe.Pointer(enc),C.int(num)) + + encSlice := C.GoBytes(enc,C.int(num)) copy(encSlice,buf) pkt.m_nBytesRead += C.uint(num)