From 4415d2c0894717701cddaaea6d63aff00bd97cc3 Mon Sep 17 00:00:00 2001 From: saxon Date: Wed, 11 Jul 2018 14:22:17 +0930 Subject: [PATCH] Finished making major change to how I increment pointers --- rtmp/rtmp.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index 15796e65..b1f26e69 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -109,6 +109,11 @@ 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 var pend, enc []byte @@ -165,8 +170,7 @@ func (s *session) rtmpWrite(r *C.RTMP, buf []byte) int { // Note this is pointer arithmatic enc = pkt.m_body // pend = enc + pkt.m_nBodySize - pend = (*C.char)(unsafe.Pointer( uintptr(unsafe.Pointer(enc)) + - ( unsafe.Sizeof(C.char(0x00)) * (uintptr(pkt.m_nBodySize)) ) )) + pend = cPtrInc(enc,pkt.m_nBodySize) if pkt.m_packetType == C.RTMP_PACKET_TYPE_INFO { enc = C.AMF_EncodeString(enc, pend, &av_setDataFrame ) @@ -177,8 +181,7 @@ func (s *session) rtmpWrite(r *C.RTMP, buf []byte) int { } } else { //C-code: enc = pkt.m_body + pkt.m_nBytesRead - enc = (*C.char)(unsafe.Pointer( uintptr(unsafe.Pointer(pkt.m_body)) + - ( unsafe.Sizeof(C.char(0x00)) * (uintptr(pkt.m_nBytesRead)) ) )) + enc = cPtrInc(pkt.m_body,pkt.m_nBytesRead) } num = int(pkt.m_nBodySize - pkt.m_nBytesRead)