mirror of https://bitbucket.org/ausocean/av.git
rtmp: simplify slice conversion
Second pass: gofmt -w -r 'ptrToSlice(p,i)->(*[_Gi]byte)(p)[:i]' {rtmp,parseurl,amf}.go
This commit is contained in:
parent
52c6b1f60a
commit
e235da36a1
17
rtmp/rtmp.go
17
rtmp/rtmp.go
|
@ -50,7 +50,6 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"reflect"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
@ -1880,8 +1879,7 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) int {
|
||||||
|
|
||||||
if tbuf != nil {
|
if tbuf != nil {
|
||||||
//memmove(toff, header, uintptr(nChunkSize + hSize))
|
//memmove(toff, header, uintptr(nChunkSize + hSize))
|
||||||
copy(ptrToSlice(toff, int(nChunkSize+hSize)), ptrToSlice(header,
|
copy((*[_Gi]byte)(toff)[:int(nChunkSize+hSize)], (*[_Gi]byte)(header)[:int(nChunkSize+hSize)])
|
||||||
int(nChunkSize+hSize)))
|
|
||||||
toff = incBytePtr(toff, nChunkSize+hSize)
|
toff = incBytePtr(toff, nChunkSize+hSize)
|
||||||
} else {
|
} else {
|
||||||
// TODO: port this
|
// TODO: port this
|
||||||
|
@ -2212,7 +2210,7 @@ func realloc(ptr unsafe.Pointer, newSize uint32) unsafe.Pointer {
|
||||||
|
|
||||||
func memmove(to, from unsafe.Pointer, n uintptr) {
|
func memmove(to, from unsafe.Pointer, n uintptr) {
|
||||||
if to != nil && from != nil && n != 0 {
|
if to != nil && from != nil && n != 0 {
|
||||||
copy(ptrToSlice(to, int(n)), ptrToSlice(from, int(n)))
|
copy((*[_Gi]byte)(to)[:int(n)], (*[_Gi]byte)(from)[:int(n)])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2389,17 +2387,6 @@ func sliceToPtr(data []byte) unsafe.Pointer {
|
||||||
return unsafe.Pointer(&data[0])
|
return unsafe.Pointer(&data[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
// ptrToSlice returns a slice given unsafe pointer and size - no allocation and
|
|
||||||
// copying is required - same data is used.
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
var rtmpErrs = [...]string{
|
var rtmpErrs = [...]string{
|
||||||
1: "rtmp: not connected",
|
1: "rtmp: not connected",
|
||||||
2: "rtmp: write error",
|
2: "rtmp: write error",
|
||||||
|
|
Loading…
Reference in New Issue