diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index fdf39148..fb6564fc 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -148,10 +148,6 @@ const ( int64Size = 8 ) -func memmove(to, from unsafe.Pointer, n uintptr) { - copy(ptrToSlice(to, int(n)), ptrToSlice(from, int(n))) -} - // av_setDataFrame is a static const global in rtmp.c var ( setDataFrame = AVC("@setDataFrame") @@ -1104,8 +1100,8 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int { log.Println("Resize") n := int(packet.m_nChannel + 10) // TODO: port this - packets = C.realloc(unsafe.Pointer(r.m_vecChannelsOut), - C.size_t(unsafe.Sizeof(packet)*uintptr(n))) + packets = realloc(unsafe.Pointer(r.m_vecChannelsOut), + int(unsafe.Sizeof(packet)*uintptr(n))) if uintptr(packets) == uintptr(0) { C.free(unsafe.Pointer(r.m_vecChannelsOut)) @@ -1241,7 +1237,7 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int { if chunks > 1 { tlen = chunks*(cSize+1) + nSize + hSize // TODO: figure out how to do this in go - tbuf = C.malloc(C.size_t(tlen)) + tbuf = allocate(uintptr(tlen)) if tbuf == nil { return 0 @@ -1345,7 +1341,7 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int { *(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsOut), int(packet.m_nChannel), int(unsafe.Sizeof(packet)))) = - (*C.RTMPPacket)(C.malloc(C.size_t(unsafe.Sizeof(*packet)))) + (*C.RTMPPacket)(allocate(unsafe.Sizeof(*packet))) } memmove(unsafe.Pointer(*(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsOut), @@ -1404,10 +1400,10 @@ func sockBufSend(sb *C.RTMPSockBuf, buf *byte, l int32) int32 { func avQueue(vals **C.RTMP_METHOD, num *int, av *C.AVal, txn int) { if (*num & 0x0f) == 0 { // TODO: work out what to do with the realloc - *vals = (*C.RTMP_METHOD)(C.realloc(unsafe.Pointer(*vals), C.size_t((*num+16)* + *vals = (*C.RTMP_METHOD)(realloc(unsafe.Pointer(*vals), int((*num+16)* int(unsafe.Sizeof(*(*vals)))))) } - tmp := unsafe.Pointer(C.malloc(C.size_t(av.av_len + 1))) + tmp := allocate(uintptr(av.av_len + 1)) memmove(tmp, unsafe.Pointer(av.av_val), uintptr(av.av_len)) *indxBytePtr(tmp, int(av.av_len)) = '\000' @@ -1417,6 +1413,7 @@ func avQueue(vals **C.RTMP_METHOD, num *int, av *C.AVal, txn int) { int(unsafe.Sizeof(*(*vals)))))).name.av_len = av.av_len (*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(*vals), *num, int(unsafe.Sizeof(*(*vals)))))).name.av_val = (*C.char)(tmp) + *num++ } func amfEncodeNamedNumber(output *byte, outend *byte, strName *C.AVal, dVal float64) *byte { @@ -1603,6 +1600,16 @@ func amfEncodeInt32(output *byte, outend *byte, nVal int32) *byte { return (*byte)(incBytePtr(outputPtr, 4)) } +func realloc(ptr unsafe.Pointer, size int) unsafe.Pointer { + dest := allocate(uintptr(size)) + memmove(dest, ptr, uintptr(size)) + return dest +} + +func memmove(to, from unsafe.Pointer, n uintptr) { + copy(ptrToSlice(to, int(n)), ptrToSlice(from, int(n))) +} + // TODO: write test for this func func memcmp(a, b unsafe.Pointer, size int) int { for i := 0; i < size; i++ {