rtmp: remove indxBytePtr

Manual clean up.
This commit is contained in:
Dan Kortschak 2018-08-31 12:01:34 +09:30
parent e235da36a1
commit c494da9a1d
3 changed files with 9 additions and 19 deletions

View File

@ -439,7 +439,7 @@ func C_AMF3ReadString(data *byte, str *C_AVal) int32 {
// assert elided - we will get a panic if it's nil.
len := C_AMF3ReadInteger(data, &ref)
data = indxBytePtr(unsafe.Pointer(data), int(len))
data = (*byte)(sliceToPtr((*[_Gi]byte)(unsafe.Pointer(data))[len:]))
if ref&0x1 == 0 {
/* reference: 0xxx */
@ -453,7 +453,7 @@ func C_AMF3ReadString(data *byte, str *C_AVal) int32 {
return len
} else {
nSize := (ref >> 1)
str.av_val = (*byte)(unsafe.Pointer(data))
str.av_val = data
str.av_len = int32(nSize)
return len + nSize
}

View File

@ -263,8 +263,7 @@ func C_RTMP_ParsePlaypath(in, out *C_AVal) {
if q != nil {
ext = (*byte)(decBytePtr(unsafe.Pointer(q), 4))
} else {
ext = (*byte)(indxBytePtr(unsafe.Pointer(ppstart), int(uintptr(pplen)-
uintptr(4))))
ext = (*byte)(sliceToPtr((*[_Gi]byte)(unsafe.Pointer(ppstart))[uintptr(pplen)-4:]))
}
switch {
case strings.Compare(cStrToGoStr(ext)[:4], ".f4v") == 0 ||

View File

@ -1662,7 +1662,7 @@ func C_HandShake(r *C_RTMP, FP9HandShake int32) int {
uptime = inet.Htonl(uint32(C_RTMP_GetTime()))
memmove(unsafe.Pointer(clientsig), unsafe.Pointer(&uptime), 4)
memset(indxBytePtr(unsafe.Pointer(clientsig), 4), 0, 4)
memset((*byte)(sliceToPtr((*[_Gi]byte)(unsafe.Pointer(clientsig))[4:])), 0, 4)
for i := 8; i < RTMP_SIG_SIZE; i++ {
(*[_Gi]byte)(unsafe.Pointer(clientsig))[i] = byte(rand.Intn(256))
@ -2232,7 +2232,7 @@ func memcmp(a, b unsafe.Pointer, size int) int {
func memset(ptr *byte, val int, num int) {
for i := 0; i < num; i++ {
(*[_Gi]byte)(unsafe.Pointer(ptr))[int(i)] = byte(uint8(val))
(*[_Gi]byte)(unsafe.Pointer(ptr))[int(i)] = byte(val)
}
}
@ -2275,10 +2275,8 @@ func strdup(str *byte) *byte {
// between start and terminating null char. Returns -1 if a null char is not
// found before a count of 1000
func strlen(str *byte) int32 {
var ptr *byte
for i := 0; i < 1000; i++ {
ptr = indxBytePtr(unsafe.Pointer(str), i)
if *ptr == '\000' {
if (*[_Gi]byte)(unsafe.Pointer(str))[i] == '\000' {
return int32(i)
}
}
@ -2289,13 +2287,11 @@ func strlen(str *byte) int32 {
// which is terminated by a null char. Returns nil if null char is not found
// before a count of 10000
func strchr(str *byte, val byte) *byte {
var ptr *byte
for i := 0; i < 1000; i++ {
ptr = indxBytePtr(unsafe.Pointer(str), i)
if *ptr == val {
return ptr
if (*[_Gi]byte)(unsafe.Pointer(str))[i] == val {
return &(*[_Gi]byte)(unsafe.Pointer(str))[i]
}
if *ptr == '\000' {
if (*[_Gi]byte)(unsafe.Pointer(str))[i] == '\000' {
break
}
}
@ -2351,11 +2347,6 @@ func calloc(val byte, noOfBytes uintptr) unsafe.Pointer {
return mem
}
// indxBytePtr returns a byte at the indx inc give a ptr
func indxBytePtr(ptr unsafe.Pointer, inc int) *byte {
return (*byte)(incPtr(ptr, inc, 1))
}
// incBytePtr returns an unsafe.Pointer to a byte that is inc positive positions
// from the passed ptr
func incBytePtr(ptr unsafe.Pointer, inc int) unsafe.Pointer {