From 825a5f6f29b539f6cca35f148bc63fff6539793c Mon Sep 17 00:00:00 2001 From: saxon Date: Tue, 17 Jul 2018 01:26:52 +0930 Subject: [PATCH] Everything is building now, time to test with youtube --- rtmp/rtmp.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index c7be119c..1523c3d5 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -76,6 +76,10 @@ const ( RTMP_PACKET_TYPE_VIDEO = 0x09 ) +// memmove copies n bytes from "from" to "to". +//go:linkname memmove runtime.memmove +//func memmove(to, from unsafe.Pointer, n uintptr) + // C.AVal is in amf.h // See #define AVC(str) {str, sizeof(str)-1} in amf.h func AVC(str string) C.AVal { @@ -229,8 +233,8 @@ func rtmpWrite(r *C.RTMP, data []byte) int { num = s2 } - memmove(enc,buf,uintptr(num)) - //copy(ptrToSlice(enc, num), ptrToSlice(buf, num)) + //memmove(enc,buf,uintptr(num)) + copy(ptrToSlice(enc, num), ptrToSlice(buf, num)) pkt.m_nBytesRead += C.uint32_t(num) s2 -= num buf = incBytePtr(buf, num) @@ -425,7 +429,9 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int { // RTMP_LogHexString(RTMP_LOGDEBUG2, (uint8_t *)buffer, nChunkSize); if tbuf != nil { - memmove(toff, header, uintptr(nChunkSize + hSize)) + //memmove(toff, header, uintptr(nChunkSize + hSize)) + copy(ptrToSlice(toff, int(nChunkSize+hSize)), ptrToSlice(header, + int(nChunkSize+hSize))) toff = incBytePtr(toff, nChunkSize + hSize) } else { // TODO: port this @@ -515,9 +521,12 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int { r.m_vecChannelsOut = (**C.RTMPPacket)(C.malloc(C.size_t(unsafe.Sizeof(packet)))) } - memmove(incPtr(unsafe.Pointer(r.m_vecChannelsOut),int(packet.m_nChannel), - int(unsafe.Sizeof(packet))),unsafe.Pointer(packet), unsafe.Sizeof(packet)) - + //memmove(incPtr(unsafe.Pointer(r.m_vecChannelsOut),int(packet.m_nChannel), + //int(unsafe.Sizeof(packet))),unsafe.Pointer(packet), unsafe.Sizeof(packet)) + dest := ptrToSlice(incPtr(unsafe.Pointer(r.m_vecChannelsOut),int(packet.m_nChannel), + int(unsafe.Sizeof(packet))),int(unsafe.Sizeof(packet))) + src := ptrToSlice(unsafe.Pointer(packet),int(unsafe.Sizeof(packet))) + copy(dest,src) return 1 } @@ -579,9 +588,7 @@ func avQueue(vals **C.RTMP_METHOD, num *int, av *AVal, txn int ) { } */ -// memmove copies n bytes from "from" to "to". -//go:linkname memmove runtime.memmove -func memmove(to, from unsafe.Pointer, n uintptr) + // indxBytePtr returns a byte at the indx inc give a ptr func indxBytePtr(ptr unsafe.Pointer, inc int) *byte {