Created allocate func

This commit is contained in:
saxon 2018-07-19 17:24:37 +09:30
parent 283fb1e3ab
commit b8c54118c9
1 changed files with 9 additions and 4 deletions

View File

@ -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))