mirror of https://bitbucket.org/ausocean/av.git
rtmp: remove unused functions
This commit is contained in:
parent
ea5c54c85d
commit
0cfabbbad0
122
rtmp/rtmp.go
122
rtmp/rtmp.go
|
@ -79,19 +79,6 @@ func pl2b(b *byte, l int) []byte {
|
|||
return (*[_Gi]byte)(base)[:l]
|
||||
}
|
||||
|
||||
func b2pp(buf []byte) (b, e *byte) {
|
||||
if buf == nil {
|
||||
return nil, nil
|
||||
}
|
||||
if len(buf) == 0 {
|
||||
b = *(**byte)(unsafe.Pointer(&buf))
|
||||
return b, b
|
||||
}
|
||||
b = &buf[0]
|
||||
e = (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(b)) + uintptr(len(buf))))
|
||||
return b, e
|
||||
}
|
||||
|
||||
func bAddr(buf []byte) *byte {
|
||||
if len(buf) == 0 {
|
||||
return nil
|
||||
|
@ -1944,37 +1931,12 @@ func memmove(to, from unsafe.Pointer, n uintptr) {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: write test for this func
|
||||
func memcmp(a, b unsafe.Pointer, size int) int {
|
||||
for i := 0; i < size; i++ {
|
||||
aValue := (*[_Gi]byte)(a)[i]
|
||||
bValue := (*[_Gi]byte)(b)[i]
|
||||
if aValue != bValue {
|
||||
if aValue < bValue {
|
||||
return -1
|
||||
} else {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func memset(ptr *byte, val byte, num int) {
|
||||
for i := 0; i < num; i++ {
|
||||
(*[_Gi]byte)(unsafe.Pointer(ptr))[i] = val
|
||||
}
|
||||
}
|
||||
|
||||
func strLen(str string) int {
|
||||
return len(str)
|
||||
}
|
||||
|
||||
// wrapper for converting byte pointer to unsafe.Pointer
|
||||
func bToUP(b *byte) unsafe.Pointer {
|
||||
return unsafe.Pointer(b)
|
||||
}
|
||||
|
||||
// Creates a new C style string from a go string
|
||||
func goStrToCStr(str string) *byte {
|
||||
l := len(str)
|
||||
|
@ -1987,90 +1949,6 @@ func goStrToCStr(str string) *byte {
|
|||
return &slice[0]
|
||||
}
|
||||
|
||||
// TODO: need a test in rtmp_test.go
|
||||
func cStrToGoStr(cStr *byte) string {
|
||||
return string((*[_Gi]byte)(unsafe.Pointer(cStr))[:strlen(cStr)])
|
||||
}
|
||||
|
||||
// Duplicates a string given as a byte pointer
|
||||
func strdup(str *byte) *byte {
|
||||
length := strlen(str)
|
||||
newMem := make([]byte, length+1)
|
||||
oldMem := (*[_Gi]byte)(unsafe.Pointer(str))[:length+1]
|
||||
copy(newMem, oldMem)
|
||||
return &newMem[0]
|
||||
}
|
||||
|
||||
// Gets the length of the string found at str - length is number of chars
|
||||
// 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 {
|
||||
for i := 0; i < 1000; i++ {
|
||||
if (*[_Gi]byte)(unsafe.Pointer(str))[i] == '\000' {
|
||||
return int32(i)
|
||||
}
|
||||
}
|
||||
return int32(-1)
|
||||
}
|
||||
|
||||
// Returns the pointer where the first occurance of val is located in a string
|
||||
// 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 {
|
||||
for i := 0; i < 1000; i++ {
|
||||
if (*[_Gi]byte)(unsafe.Pointer(str))[i] == val {
|
||||
return &(*[_Gi]byte)(unsafe.Pointer(str))[i]
|
||||
}
|
||||
if (*[_Gi]byte)(unsafe.Pointer(str))[i] == '\000' {
|
||||
break
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: need a test in rtmp_test.go
|
||||
// Porting: http://www.ai.mit.edu/projects/im/cam8/cam8/working/CAMlib/tcl/compat/strstr.c
|
||||
func strstr(str *byte, substring *byte) *byte {
|
||||
var a, b *byte
|
||||
/* First scan quickly through the two strings looking for a
|
||||
* single-character match. When it's found, then compare the
|
||||
* rest of the substring.
|
||||
*/
|
||||
|
||||
b = substring
|
||||
if *b == 0 {
|
||||
return str
|
||||
}
|
||||
|
||||
for *str != 0 {
|
||||
str = (*byte)(incBytePtr(unsafe.Pointer(str), 1))
|
||||
if *str != *b {
|
||||
continue
|
||||
}
|
||||
a = str
|
||||
for {
|
||||
if *b == 0 {
|
||||
return str
|
||||
}
|
||||
tmp1 := a
|
||||
a = (*byte)(incBytePtr(unsafe.Pointer(a), 1))
|
||||
tmp2 := b
|
||||
b = (*byte)(incBytePtr(unsafe.Pointer(b), 1))
|
||||
if *tmp1 != *tmp2 {
|
||||
break
|
||||
}
|
||||
}
|
||||
b = substring
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Creates mem of the size noOfBytes. returns as unsafe pointer
|
||||
func malloc(nOfBytes uintptr) unsafe.Pointer {
|
||||
mem := make([]byte, int(nOfBytes))
|
||||
return unsafe.Pointer(&mem[0])
|
||||
}
|
||||
|
||||
// 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 {
|
||||
|
|
|
@ -53,35 +53,17 @@ var (
|
|||
errMsg = "Obtained: %v, but wanted: %v"
|
||||
)
|
||||
|
||||
// TODO: write test for realloc
|
||||
// TODO: write test for memmove
|
||||
// TODO: write test for allocate
|
||||
|
||||
func TestMemcmp(t *testing.T) {
|
||||
slice1 := []byte("ABCDEFG")
|
||||
slice2 := []byte("ABCDEFG")
|
||||
slice3 := []byte("ABCDJFG")
|
||||
|
||||
if memcmp(unsafe.Pointer(&slice1[0]), unsafe.Pointer(&slice2[0]), 7) != 0 {
|
||||
t.Errorf("Should have got 0!")
|
||||
}
|
||||
|
||||
if memcmp(unsafe.Pointer(&slice1[0]), unsafe.Pointer(&slice3[0]), 7) == 0 {
|
||||
t.Errorf("Should not have got 0!")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMemset(t *testing.T) {
|
||||
size := 10
|
||||
setNum := 5
|
||||
testVal := byte('A')
|
||||
mem := malloc(uintptr(size))
|
||||
memset((*byte)(mem), testVal, setNum)
|
||||
mem := make([]byte, size)
|
||||
memset(&mem[0], testVal, setNum)
|
||||
for i := 0; i < size; i++ {
|
||||
if i > setNum-1 {
|
||||
testVal = byte(0)
|
||||
}
|
||||
if (*[_Gi]byte)(mem)[i] != testVal {
|
||||
if mem[i] != testVal {
|
||||
t.Errorf("mem doesn't match expected values at: %v", i)
|
||||
}
|
||||
}
|
||||
|
@ -102,50 +84,6 @@ func TestGoStrToCStr(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestStrdup(t *testing.T) {
|
||||
goStr := "string\000"
|
||||
bStr := goStrToCStr(goStr)
|
||||
|
||||
testData := []byte{'s', 't', 'r', 'i', 'n', 'g', '\000'}
|
||||
|
||||
newStr := strdup(bStr)
|
||||
|
||||
for i := 0; i < len(goStr); i++ {
|
||||
val := (*[_Gi]byte)(unsafe.Pointer(newStr))[i]
|
||||
testVal := testData[i]
|
||||
if val != testVal {
|
||||
t.Errorf("Wanted: %v, but got: %v", testVal, val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestStrlen(t *testing.T) {
|
||||
goStr := "string\000"
|
||||
bStr := goStrToCStr(goStr)
|
||||
eLength := 6
|
||||
oLength := strlen(bStr)
|
||||
if oLength != int32(eLength) {
|
||||
t.Errorf("Wanted: %v, but got: %v", eLength, oLength)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStrchr(t *testing.T) {
|
||||
goStr := "string\000"
|
||||
bStr := goStrToCStr(goStr)
|
||||
// First try to find something that is in the string
|
||||
ePtr := uintptr(incBytePtr(unsafe.Pointer(bStr), 2))
|
||||
obtainedPtr := uintptr(unsafe.Pointer(strchr(bStr, 'r')))
|
||||
if ePtr != obtainedPtr {
|
||||
t.Errorf("wanted: %v, but got: %v", ePtr, obtainedPtr)
|
||||
}
|
||||
// Now try something that isn't actually in the string
|
||||
obtainedPtr2 := strchr(bStr, 'k')
|
||||
ePtr2 := (*byte)(nil)
|
||||
if ePtr2 != obtainedPtr2 {
|
||||
t.Errorf("wanted: %v, but got: %v", ePtr, obtainedPtr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIncPtr(t *testing.T) {
|
||||
// Test how it deals with bytes
|
||||
bytePtr := unsafe.Pointer(&byteArr[arrStart])
|
||||
|
|
Loading…
Reference in New Issue