diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index a5ec7d49..438e2806 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -66,6 +66,18 @@ const ( RTMP_PACKET_TYPE_VIDEO = 0x09 ) +// C.AVal is in amf.h +// See #define AVC(str) {str, sizeof(str)-1} in amf.h +func AVC(str string) C.AVal { + var aval C.AVal + aval.av_val = C.CString(str) + aval.av_len = C.int(len(str)) + return aval +} + +// av_setDataFrame is a static const global in rtmp.c +var setDataFrame = AVC("@setDataFrame") + // Session provides an interface for sending flv tags over rtmp. type Session interface { Open() error @@ -90,18 +102,6 @@ func NewSession(url string, connectTimeout uint) Session { } } -// C.AVal is in amf.h -// See #define AVC(str) {str, sizeof(str)-1} in amf.h -func AVC(str string) C.AVal { - var aval C.AVal - aval.av_val = C.CString(str) - aval.av_len = C.int(len(str)) - return aval -} - -// av_setDataFrame is a static const global in rtmp.c -var setDataFrame = AVC("@setDataFrame") - // Open establishes an rtmp connection with the url passed into the // constructor func (s *session) Open() error { @@ -131,10 +131,6 @@ func (s *session) Write(data []byte) (int, error) { return len(data), nil } -// memmove copies n bytes from "from" to "to". -//go:linkname memmove runtime.memmove -func memmove(to, from unsafe.Pointer, n uintptr) - // rtmpWrite writes data to the current rtmp connection encapsulated by r func rtmpWrite(r *C.RTMP, data []byte) int { buf := sliceToPtr(data) @@ -232,43 +228,6 @@ func rtmpWrite(r *C.RTMP, data []byte) int { return size + s2 } -// 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)) -} - -// 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 -// 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)) - shDest.Data = uintptr(data) - shDest.Len = size - shDest.Cap = size - 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)) -} - -// incPtr attempts to replicate C like pointer arithmatic functionality -func decPtr(ptr unsafe.Pointer, dec int) unsafe.Pointer { - return unsafe.Pointer(uintptr(ptr) - uintptr(inc)) -} - func sendPacket(r *C.RTMP, pkt *C.RTMPPacket, queue int) int { const prevPacket *C.RTMPPacket last := 0 @@ -513,6 +472,46 @@ func sendPacket(r *C.RTMP, pkt *C.RTMPPacket, queue int) int { return 1 } +// 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)) +} + +// 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 +// 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)) + shDest.Data = uintptr(data) + shDest.Len = size + shDest.Cap = size + 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)) +} + +// incPtr attempts to replicate C like pointer arithmatic functionality +func decPtr(ptr unsafe.Pointer, dec int) unsafe.Pointer { + return unsafe.Pointer(uintptr(ptr) - uintptr(inc)) +} // Close terminates the rtmp connection func (s *session) Close() error {