From a9b5c7a26fc6e89a1da46f14d114b8978a8eaf8c Mon Sep 17 00:00:00 2001 From: saxon Date: Sat, 14 Jul 2018 15:21:01 +0930 Subject: [PATCH] Added some commenting above functions --- rtmp/rtmp.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index ae8c2ec6..637ac311 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -130,6 +130,7 @@ func (s *session) Write(data []byte) (int, error) { return len(data), nil } +// rtmpWrite writes data to the current rtmp connection encapsulated by r func rtmpWrite(r *C.RTMP, data []byte) int { buf := sliceToPtr(data) // TODO: port RTMPPacket @@ -224,14 +225,19 @@ func rtmpWrite(r *C.RTMP, data []byte) int { return size + s2 } +// indxPtr replicates C array indexing using an unsafe pointer func indxPtr(ptr unsafe.Pointer, inc int) byte { return *(*byte)(incPtr(ptr,inc)) } +// sliceToPtr get's the address of the first data element and returns as unsafe +// pointer func sliceToPtr(data []byte) unsafe.Pointer { return unsafe.Pointer(&data[0]) } +// ptrToSlice returns a slice given unsafe pointer and size - no allocation and +// copying is required - same data is used. func ptrToSlice(data unsafe.Pointer, size int) []byte { var ret []byte shDest := (*reflect.SliceHeader)(unsafe.Pointer(&ret)) @@ -241,6 +247,7 @@ func ptrToSlice(data unsafe.Pointer, size int) []byte { return ret } +// incPtr attempts to replicate C like pointer arithmatic functionality func incPtr(ptr unsafe.Pointer, inc int) unsafe.Pointer { return unsafe.Pointer(uintptr(ptr) + uintptr(inc)) } @@ -290,7 +297,3 @@ func (e Err) Error() string { } return "rtmp: " + strconv.Itoa(int(e)) } - -func byteSliceToCArr(buf []byte) *C.char { - return (*C.char)(unsafe.Pointer(&buf[0])) -}