From 50c3f8c20a92e37c284d207dded8faf23978416e Mon Sep 17 00:00:00 2001 From: saxon Date: Sun, 15 Jul 2018 18:56:59 +0930 Subject: [PATCH] Writing more universal functions so that they can work on multiple types --- rtmp/rtmp.go | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index e6c3fe88..6e0a159f 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -472,6 +472,7 @@ func sendPacket(r *C.RTMP, pkt *C.RTMPPacket, queue int) int { return 1 } +/* func writeN(r *C.RTMP, buffer unsafe.Pointer, n int) int { ptr := buffer for n > 0 { @@ -513,20 +514,30 @@ func writeN(r *C.RTMP, buffer unsafe.Pointer, n int) int { return n == 0 } +*/ +/* +// TODO: port RTMP_METHOD +func AV_queue(vals **C.RTMP_METHOD, num *int, av *AVal, txn int ) { + var tmp unsafe.Pointer + + if (*num & 0x0f) == 0 { + // TODO: work out what to do with the realloc + *vals = C.realloc(*vals, (*num+16) * C.int(int(unsafe.sizeof(RTMP_METHOD)))) + } + + tmp := C.malloc(av.av_len + 1 ) + memmove(tmp, unsafe.Pointer(av.av_val), int(av.av_len)) + indxPtr(tpm,av.av_len) = '\0' +} +*/ // memmove copies n bytes from "from" to "to". //go:linkname memmove runtime.memmove func memmove(to, from unsafe.Pointer, n uintptr) -// indxPytetr replicates C array indexing using an unsafe pointer for byte data -func indxBytePtr(ptr unsafe.Pointer, indx int) *byte { - return (*byte)(incPtr(ptr,indx)) -} +func indxPtr(ptr unsafe.Pointer, indx, typeSize int) unsafe.Pointer { -// indxPytetr replicates C array indexing using an unsafe pointer for int data -func indxIntPtr( ptr unsafe.Pointer, indx int ) *int { - return (*int)(incPtr(ptr,indx)) } // sliceToPtr get's the address of the first data element and returns as unsafe @@ -547,12 +558,12 @@ func ptrToSlice(data unsafe.Pointer, size int) []byte { } // incPtr attempts to replicate C like pointer arithmatic functionality -func incPtr(ptr unsafe.Pointer, inc int) unsafe.Pointer { +func incPtr(ptr unsafe.Pointer, inc, typeSize int) unsafe.Pointer { return unsafe.Pointer(uintptr(ptr) + uintptr(inc)) } // incPtr attempts to replicate C like pointer arithmatic functionality -func decPtr(ptr unsafe.Pointer, dec int) unsafe.Pointer { +func decPtr(ptr unsafe.Pointer, dec, typeSize int) unsafe.Pointer { return unsafe.Pointer(uintptr(ptr) - uintptr(inc)) }