diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index 90954404..e650d1dc 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -321,7 +321,7 @@ func (s *session) Open() error { func startSession(rtmp *C.RTMP, u string, timeout uint32) (*C.RTMP, error) { url := C.CString(u) connect_timeout := C.int(timeout) - rtmp = C.RTMP_Alloc() + rtmp = rtmpAlloc() C.RTMP_Init(rtmp) rtmp.Link.timeout = connect_timeout if C.RTMP_SetupURL(rtmp, url) == 0 { @@ -347,11 +347,11 @@ func startSession(rtmp *C.RTMP, u string, timeout uint32) (*C.RTMP, error) { return rtmp, nil } -/* func rtmpAlloc() *C.RTMP { - return C.calloc + var r C.RTMP + return (*C.RTMP)(allocate(unsafe.Sizeof(r))) } -*/ + // Close terminates the rtmp connection func (s *session) Close() error { if s.rtmp == nil { @@ -911,6 +911,11 @@ func avQueue(vals **C.RTMP_METHOD, num *int, av *C.AVal, txn int) { int(unsafe.Sizeof(rtmpMethodPtr))))).name.av_val = (*C.char)(tmp) } +func allocate(nOfBytes uintptr) unsafe.Pointer { + mem := make([]byte, int(nOfBytes)) + return unsafe.Pointer(&mem[0]) +} + // indxBytePtr returns a byte at the indx inc give a ptr func indxBytePtr(ptr unsafe.Pointer, inc int) *byte { return (*byte)(incPtr(ptr, inc, byteSize))