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"
|
"unsafe"
|
||||||
_"fmt"
|
_"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -130,7 +131,7 @@ func (s *session) Write(data []byte) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func rtmpWrite(r *C.RTMP, data []byte) int {
|
func rtmpWrite(r *C.RTMP, data []byte) int {
|
||||||
buf := unsafe.Pointer(&data[0])
|
buf := sliceToPtr(data)
|
||||||
var pkt = &r.m_write
|
var pkt = &r.m_write
|
||||||
var pend, enc unsafe.Pointer
|
var pend, enc unsafe.Pointer
|
||||||
size := len(data)
|
size := len(data)
|
||||||
|
@ -198,9 +199,7 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
|
||||||
if num > s2 {
|
if num > s2 {
|
||||||
num = s2
|
num = s2
|
||||||
}
|
}
|
||||||
// TODO: Can only remove this mem copy onc I port the RTMPPacket struct and
|
copy(ptrToSlice(enc,num),ptrToSlice(buf,num))
|
||||||
// AllocatPacket
|
|
||||||
C.memcpy(enc,buf,C.ulong(num))
|
|
||||||
pkt.m_nBytesRead += C.uint(num)
|
pkt.m_nBytesRead += C.uint(num)
|
||||||
s2 -= num
|
s2 -= num
|
||||||
buf = incPtr(buf,num)
|
buf = incPtr(buf,num)
|
||||||
|
@ -221,12 +220,23 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
|
||||||
return size + s2
|
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 {
|
func incPtr(ptr unsafe.Pointer, inc int) unsafe.Pointer {
|
||||||
return unsafe.Pointer(uintptr(ptr) + uintptr(inc))
|
return unsafe.Pointer(uintptr(ptr) + uintptr(inc))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
func sendPacket(r *C.RTMP, pkt *C.RTMPPacket, queue int) int {
|
func sendPacket(r *C.RTMP, pkt *C.RTMPPacket, queue int) int {
|
||||||
const prevPacket *C.RTMPPacket
|
const prevPacket *C.RTMPPacket
|
||||||
|
|
Loading…
Reference in New Issue