mirror of https://bitbucket.org/ausocean/av.git
Writing more universal functions so that they can work on multiple types
This commit is contained in:
parent
abd5cc27de
commit
50c3f8c20a
29
rtmp/rtmp.go
29
rtmp/rtmp.go
|
@ -472,6 +472,7 @@ func sendPacket(r *C.RTMP, pkt *C.RTMPPacket, queue int) int {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
func writeN(r *C.RTMP, buffer unsafe.Pointer, n int) int {
|
func writeN(r *C.RTMP, buffer unsafe.Pointer, n int) int {
|
||||||
ptr := buffer
|
ptr := buffer
|
||||||
for n > 0 {
|
for n > 0 {
|
||||||
|
@ -513,20 +514,30 @@ func writeN(r *C.RTMP, buffer unsafe.Pointer, n int) int {
|
||||||
|
|
||||||
return n == 0
|
return n == 0
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
// TODO: port RTMP_METHOD
|
||||||
|
func AV_queue(vals **C.RTMP_METHOD, num *int, av *AVal, txn int ) {
|
||||||
|
var tmp unsafe.Pointer
|
||||||
|
|
||||||
|
if (*num & 0x0f) == 0 {
|
||||||
|
// TODO: work out what to do with the realloc
|
||||||
|
*vals = C.realloc(*vals, (*num+16) * C.int(int(unsafe.sizeof(RTMP_METHOD))))
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp := C.malloc(av.av_len + 1 )
|
||||||
|
memmove(tmp, unsafe.Pointer(av.av_val), int(av.av_len))
|
||||||
|
indxPtr(tpm,av.av_len) = '\0'
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// memmove copies n bytes from "from" to "to".
|
// memmove copies n bytes from "from" to "to".
|
||||||
//go:linkname memmove runtime.memmove
|
//go:linkname memmove runtime.memmove
|
||||||
func memmove(to, from unsafe.Pointer, n uintptr)
|
func memmove(to, from unsafe.Pointer, n uintptr)
|
||||||
|
|
||||||
// indxPytetr replicates C array indexing using an unsafe pointer for byte data
|
func indxPtr(ptr unsafe.Pointer, indx, typeSize int) unsafe.Pointer {
|
||||||
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
|
// sliceToPtr get's the address of the first data element and returns as unsafe
|
||||||
|
@ -547,12 +558,12 @@ func ptrToSlice(data unsafe.Pointer, size int) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
// incPtr attempts to replicate C like pointer arithmatic functionality
|
// incPtr attempts to replicate C like pointer arithmatic functionality
|
||||||
func incPtr(ptr unsafe.Pointer, inc int) unsafe.Pointer {
|
func incPtr(ptr unsafe.Pointer, inc, typeSize int) unsafe.Pointer {
|
||||||
return unsafe.Pointer(uintptr(ptr) + uintptr(inc))
|
return unsafe.Pointer(uintptr(ptr) + uintptr(inc))
|
||||||
}
|
}
|
||||||
|
|
||||||
// incPtr attempts to replicate C like pointer arithmatic functionality
|
// incPtr attempts to replicate C like pointer arithmatic functionality
|
||||||
func decPtr(ptr unsafe.Pointer, dec int) unsafe.Pointer {
|
func decPtr(ptr unsafe.Pointer, dec, typeSize int) unsafe.Pointer {
|
||||||
return unsafe.Pointer(uintptr(ptr) - uintptr(inc))
|
return unsafe.Pointer(uintptr(ptr) - uintptr(inc))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue