mirror of https://bitbucket.org/ausocean/av.git
Using C memory functions until I can use go ones using linkname stuff or get mine right such that they work
This commit is contained in:
parent
357bf4c87b
commit
4847728ddf
27
rtmp/rtmp.go
27
rtmp/rtmp.go
|
@ -450,6 +450,7 @@ func startSession(rtmp *C.RTMP, u string, timeout uint32) (*C.RTMP, error) {
|
|||
|
||||
func rtmpAlloc() *C.RTMP {
|
||||
var r C.RTMP
|
||||
//return (*C.RTMP)(C.malloc(C.size_t(unsafe.Sizeof(r))))
|
||||
return (*C.RTMP)(allocate(unsafe.Sizeof(r)))
|
||||
}
|
||||
|
||||
|
@ -1270,13 +1271,13 @@ func rtmpSendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
|
|||
|
||||
if packet.m_nChannel >= r.m_channelsAllocatedOut {
|
||||
n := int(packet.m_nChannel + 10)
|
||||
//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)))
|
||||
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))
|
||||
C.free(unsafe.Pointer(r.m_vecChannelsOut))
|
||||
r.m_vecChannelsOut = nil
|
||||
r.m_channelsAllocatedOut = 0
|
||||
return 0
|
||||
|
@ -1286,9 +1287,10 @@ func rtmpSendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
|
|||
C.memset(incPtr(unsafe.Pointer(r.m_vecChannelsOut), int(r.m_channelsAllocatedOut),
|
||||
int(unsafe.Sizeof(packet))), 0, C.size_t(unsafe.Sizeof(packet)*
|
||||
uintptr(n-int(r.m_channelsAllocatedOut))))
|
||||
|
||||
//memset((*byte)(incPtr(unsafe.Pointer(r.m_vecChannelsOut), int(
|
||||
//r.m_channelsAllocatedOut), int(unsafe.Sizeof(packet))), 0, int(
|
||||
//unsafe.Sizeof(packet)*uintptr(n-int(r.m_channelsAllocatedOut)))))
|
||||
// r.m_channelsAllocatedOut), int(unsafe.Sizeof(packet)))), 0, int(
|
||||
// unsafe.Sizeof(packet)*uintptr(n-int(r.m_channelsAllocatedOut))))
|
||||
r.m_channelsAllocatedOut = C.int(n)
|
||||
}
|
||||
prevPacket = *(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsOut),
|
||||
|
@ -1577,9 +1579,12 @@ 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)(realloc(unsafe.Pointer(*vals), int((*num+16)*
|
||||
int(unsafe.Sizeof(*(*vals))))))
|
||||
//*vals = (*C.RTMP_METHOD)(realloc(unsafe.Pointer(*vals), int((*num+16)*
|
||||
//int(unsafe.Sizeof(*(*vals))))))
|
||||
*vals = (*C.RTMP_METHOD)(C.realloc(unsafe.Pointer(*vals), C.size_t((*num+16)*int(
|
||||
unsafe.Sizeof(*(*vals))))))
|
||||
}
|
||||
//tmp := 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'
|
||||
|
@ -1805,9 +1810,9 @@ func memcmp(a, b unsafe.Pointer, size int) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
func memset(ptr *byte, val byte, num int) {
|
||||
func memset(ptr *byte, val int, num int) {
|
||||
for i := 0; i < num; i++ {
|
||||
*indxBytePtr(unsafe.Pointer(ptr), int(i)) = val
|
||||
*indxBytePtr(unsafe.Pointer(ptr), int(i)) = byte(uint8(val))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue