mirror of https://bitbucket.org/ausocean/av.git
Got rid of C.memcpy
This commit is contained in:
parent
438cf8470b
commit
965641be16
20
rtmp/rtmp.go
20
rtmp/rtmp.go
|
@ -49,6 +49,7 @@ import (
|
|||
"unsafe"
|
||||
_"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -130,7 +131,7 @@ func (s *session) Write(data []byte) (int, error) {
|
|||
}
|
||||
|
||||
func rtmpWrite(r *C.RTMP, data []byte) int {
|
||||
buf := unsafe.Pointer(&data[0])
|
||||
buf := sliceToPtr(data)
|
||||
var pkt = &r.m_write
|
||||
var pend, enc unsafe.Pointer
|
||||
size := len(data)
|
||||
|
@ -198,9 +199,7 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
|
|||
if num > s2 {
|
||||
num = s2
|
||||
}
|
||||
// TODO: Can only remove this mem copy onc I port the RTMPPacket struct and
|
||||
// AllocatPacket
|
||||
C.memcpy(enc,buf,C.ulong(num))
|
||||
copy(ptrToSlice(enc,num),ptrToSlice(buf,num))
|
||||
pkt.m_nBytesRead += C.uint(num)
|
||||
s2 -= num
|
||||
buf = incPtr(buf,num)
|
||||
|
@ -221,12 +220,23 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
|
|||
return size + s2
|
||||
}
|
||||
|
||||
func sliceToPtr(data []byte) unsafe.Pointer {
|
||||
return unsafe.Pointer(&data[0])
|
||||
}
|
||||
|
||||
func ptrToSlice(data unsafe.Pointer, size int) []byte {
|
||||
var ret []byte
|
||||
shDest := (*reflect.SliceHeader)(unsafe.Pointer(&ret))
|
||||
shDest.Data = uintptr(data)
|
||||
shDest.Len = size
|
||||
shDest.Cap = size
|
||||
return ret
|
||||
}
|
||||
|
||||
func incPtr(ptr unsafe.Pointer, inc int) unsafe.Pointer {
|
||||
return unsafe.Pointer(uintptr(ptr) + uintptr(inc))
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
func sendPacket(r *C.RTMP, pkt *C.RTMPPacket, queue int) int {
|
||||
const prevPacket *C.RTMPPacket
|
||||
|
|
Loading…
Reference in New Issue