mirror of https://bitbucket.org/ausocean/av.git
Merge branch 'master' into rtmp-unsafe-cleanup
This commit is contained in:
commit
e861420e69
|
@ -120,7 +120,7 @@ func C_RTMP_ParseURL(url *byte, protocol *int32, host *C_AVal, port *uint32,
|
||||||
|
|
||||||
if hostlen < 256 {
|
if hostlen < 256 {
|
||||||
host.av_val = (*byte)(unsafe.Pointer(p))
|
host.av_val = (*byte)(unsafe.Pointer(p))
|
||||||
host.av_len = int32(hostlen)
|
host.av_len = hostlen
|
||||||
// TODO: use new logger with this
|
// TODO: use new logger with this
|
||||||
//RTMP_Log(RTMP_LOGDEBUG, "Parsed host : %.*s", hostlen, host.av_val);
|
//RTMP_Log(RTMP_LOGDEBUG, "Parsed host : %.*s", hostlen, host.av_val);
|
||||||
} else {
|
} else {
|
||||||
|
@ -204,7 +204,7 @@ func C_RTMP_ParseURL(url *byte, protocol *int32, host *C_AVal, port *uint32,
|
||||||
}
|
}
|
||||||
|
|
||||||
app.av_val = (*byte)(unsafe.Pointer(p))
|
app.av_val = (*byte)(unsafe.Pointer(p))
|
||||||
app.av_len = int32(applen)
|
app.av_len = applen
|
||||||
// TODO: use new logging here
|
// TODO: use new logging here
|
||||||
// RTMP_Log(RTMP_LOGDEBUG, "Parsed app : %.*s", applen, p);
|
// RTMP_Log(RTMP_LOGDEBUG, "Parsed app : %.*s", applen, p);
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ func C_RTMP_ParsePlaypath(in, out *C_AVal) {
|
||||||
ppstart := (*byte)(unsafe.Pointer(playpath))
|
ppstart := (*byte)(unsafe.Pointer(playpath))
|
||||||
var streamname, destptr, p *byte
|
var streamname, destptr, p *byte
|
||||||
|
|
||||||
pplen := int32(in.av_len)
|
pplen := in.av_len
|
||||||
|
|
||||||
out.av_val = nil
|
out.av_val = nil
|
||||||
out.av_len = 0
|
out.av_len = 0
|
||||||
|
@ -248,7 +248,7 @@ func C_RTMP_ParsePlaypath(in, out *C_AVal) {
|
||||||
temp = strstr((*byte)(unsafe.Pointer(ppstart)), goStrToCStr("slist="))
|
temp = strstr((*byte)(unsafe.Pointer(ppstart)), goStrToCStr("slist="))
|
||||||
if *ppstart == '?' && temp != nil {
|
if *ppstart == '?' && temp != nil {
|
||||||
ppstart = (*byte)(incBytePtr(unsafe.Pointer(temp), 6))
|
ppstart = (*byte)(incBytePtr(unsafe.Pointer(temp), 6))
|
||||||
pplen = int32(strlen(ppstart))
|
pplen = strlen(ppstart)
|
||||||
|
|
||||||
temp = strchr(ppstart, '&')
|
temp = strchr(ppstart, '&')
|
||||||
|
|
||||||
|
@ -305,7 +305,7 @@ func C_RTMP_ParsePlaypath(in, out *C_AVal) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p = (*byte)(ppstart)
|
p = ppstart
|
||||||
for pplen > 0 {
|
for pplen > 0 {
|
||||||
if subExt != 0 && p == ext {
|
if subExt != 0 && p == ext {
|
||||||
p = (*byte)(incBytePtr(unsafe.Pointer(p), 4))
|
p = (*byte)(incBytePtr(unsafe.Pointer(p), 4))
|
||||||
|
|
30
rtmp/rtmp.go
30
rtmp/rtmp.go
|
@ -275,14 +275,14 @@ func C_SocksSetup(r *C_RTMP, sockshost *C_AVal) {
|
||||||
hostname := strdup((*byte)(unsafe.Pointer(sockshost.av_val)))
|
hostname := strdup((*byte)(unsafe.Pointer(sockshost.av_val)))
|
||||||
|
|
||||||
if unsafe.Pointer(socksport) != nil {
|
if unsafe.Pointer(socksport) != nil {
|
||||||
(*[_Gi]byte)(unsafe.Pointer(hostname))[int(uintptr(decBytePtr(unsafe.Pointer(socksport),
|
(*[_Gi]byte)(unsafe.Pointer(hostname))[uintptr(decBytePtr(unsafe.Pointer(socksport),
|
||||||
int(uintptr(unsafe.Pointer(sockshost.av_val))))))] = '\000'
|
int(uintptr(unsafe.Pointer(sockshost.av_val)))))] = '\000'
|
||||||
r.Link.sockshost.av_val = (*byte)(unsafe.Pointer(hostname))
|
r.Link.sockshost.av_val = (*byte)(unsafe.Pointer(hostname))
|
||||||
r.Link.sockshost.av_len = int32(strlen(hostname))
|
r.Link.sockshost.av_len = int32(strlen(hostname))
|
||||||
|
|
||||||
value, err := strconv.Atoi(string((*[_Gi]byte)(unsafe.Pointer(uintptr(
|
value, err := strconv.Atoi(string((*[_Gi]byte)(unsafe.Pointer(uintptr(
|
||||||
unsafe.Pointer(socksport)) + uintptr(1)))[:int(strlen((*byte)(unsafe.Pointer(
|
unsafe.Pointer(socksport)) + uintptr(1)))[:strlen((*byte)(unsafe.Pointer(
|
||||||
uintptr(unsafe.Pointer(socksport))+uintptr(1)))))+1]))
|
uintptr(unsafe.Pointer(socksport))+uintptr(1))))+1]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("C_SocksSetup: bad string conversion!")
|
log.Println("C_SocksSetup: bad string conversion!")
|
||||||
}
|
}
|
||||||
|
@ -336,9 +336,9 @@ func C_RTMP_SetupURL(r *C_RTMP, u string) int32 {
|
||||||
int32(len("rtmpte://:65535/\x00"))
|
int32(len("rtmpte://:65535/\x00"))
|
||||||
|
|
||||||
r.Link.tcUrl.av_val = (*byte)(malloc(uintptr(uintptr(length))))
|
r.Link.tcUrl.av_val = (*byte)(malloc(uintptr(uintptr(length))))
|
||||||
hostname := string((*[_Gi]byte)(unsafe.Pointer(r.Link.hostname.av_val))[:int(r.Link.hostname.av_len)])
|
hostname := string((*[_Gi]byte)(unsafe.Pointer(r.Link.hostname.av_val))[:r.Link.hostname.av_len])
|
||||||
|
|
||||||
app := string((*[_Gi]byte)(unsafe.Pointer(r.Link.app.av_val))[:int(r.Link.app.av_len)])
|
app := string((*[_Gi]byte)(unsafe.Pointer(r.Link.app.av_val))[:r.Link.app.av_len])
|
||||||
|
|
||||||
fString := fmt.Sprintf("%v://%v:%v/%v",
|
fString := fmt.Sprintf("%v://%v:%v/%v",
|
||||||
RTMPProtocolStringsLower[r.Link.protocol], hostname, r.Link.port, app)
|
RTMPProtocolStringsLower[r.Link.protocol], hostname, r.Link.port, app)
|
||||||
|
@ -1187,7 +1187,7 @@ func C_AV_queue(vals **C_RTMP_METHOD, num *int32, av *C_AVal, txn int32) {
|
||||||
tmp := malloc(uintptr(av.av_len + 1))
|
tmp := malloc(uintptr(av.av_len + 1))
|
||||||
//tmp := allocate(uintptr(av.av_len + 1))
|
//tmp := allocate(uintptr(av.av_len + 1))
|
||||||
memmove(tmp, unsafe.Pointer(av.av_val), uintptr(av.av_len))
|
memmove(tmp, unsafe.Pointer(av.av_val), uintptr(av.av_len))
|
||||||
(*[_Gi]byte)(tmp)[int(av.av_len)] = '\000'
|
(*[_Gi]byte)(tmp)[av.av_len] = '\000'
|
||||||
|
|
||||||
(*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(*vals), int(*num),
|
(*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(*vals), int(*num),
|
||||||
int(unsafe.Sizeof(*(*vals)))))).num = int32(txn)
|
int(unsafe.Sizeof(*(*vals)))))).num = int32(txn)
|
||||||
|
@ -1879,7 +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((*[_Gi]byte)(toff)[:int(nChunkSize+hSize)], (*[_Gi]byte)(header)[:int(nChunkSize+hSize)])
|
copy((*[_Gi]byte)(toff)[:nChunkSize+hSize], (*[_Gi]byte)(header)[:nChunkSize+hSize])
|
||||||
toff = incBytePtr(toff, nChunkSize+hSize)
|
toff = incBytePtr(toff, nChunkSize+hSize)
|
||||||
} else {
|
} else {
|
||||||
// TODO: port this
|
// TODO: port this
|
||||||
|
@ -1912,7 +1912,7 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) int {
|
||||||
|
|
||||||
if cSize != 0 {
|
if cSize != 0 {
|
||||||
tmp := int(packet.m_nChannel) - 64
|
tmp := int(packet.m_nChannel) - 64
|
||||||
(*[_Gi]byte)(header)[1] = byte(tmp & 0xff)
|
(*[_Gi]byte)(header)[1] = byte(tmp)
|
||||||
|
|
||||||
if cSize == 2 {
|
if cSize == 2 {
|
||||||
(*[_Gi]byte)(header)[2] = byte(tmp >> 8)
|
(*[_Gi]byte)(header)[2] = byte(tmp >> 8)
|
||||||
|
@ -2219,7 +2219,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((*[_Gi]byte)(to)[:int(n)], (*[_Gi]byte)(from)[:int(n)])
|
copy((*[_Gi]byte)(to)[:n], (*[_Gi]byte)(from)[:n])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2239,9 +2239,9 @@ func memcmp(a, b unsafe.Pointer, size int) int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func memset(ptr *byte, val int, num int) {
|
func memset(ptr *byte, val byte, num int) {
|
||||||
for i := 0; i < num; i++ {
|
for i := 0; i < num; i++ {
|
||||||
(*[_Gi]byte)(unsafe.Pointer(ptr))[int(i)] = byte(val)
|
(*[_Gi]byte)(unsafe.Pointer(ptr))[i] = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2268,14 +2268,14 @@ func goStrToCStr(str string) *byte {
|
||||||
|
|
||||||
// TODO: need a test in rtmp_test.go
|
// TODO: need a test in rtmp_test.go
|
||||||
func cStrToGoStr(cStr *byte) string {
|
func cStrToGoStr(cStr *byte) string {
|
||||||
return string((*[_Gi]byte)(unsafe.Pointer(cStr))[:int(strlen(cStr))])
|
return string((*[_Gi]byte)(unsafe.Pointer(cStr))[:strlen(cStr)])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Duplicates a string given as a byte pointer
|
// Duplicates a string given as a byte pointer
|
||||||
func strdup(str *byte) *byte {
|
func strdup(str *byte) *byte {
|
||||||
length := strlen(str)
|
length := strlen(str)
|
||||||
newMem := make([]byte, length+1)
|
newMem := make([]byte, length+1)
|
||||||
oldMem := (*[_Gi]byte)(unsafe.Pointer(str))[:int(length+1)]
|
oldMem := (*[_Gi]byte)(unsafe.Pointer(str))[:length+1]
|
||||||
copy(newMem, oldMem)
|
copy(newMem, oldMem)
|
||||||
return &newMem[0]
|
return &newMem[0]
|
||||||
}
|
}
|
||||||
|
@ -2352,7 +2352,7 @@ func malloc(nOfBytes uintptr) unsafe.Pointer {
|
||||||
|
|
||||||
func calloc(val byte, noOfBytes uintptr) unsafe.Pointer {
|
func calloc(val byte, noOfBytes uintptr) unsafe.Pointer {
|
||||||
mem := malloc(noOfBytes)
|
mem := malloc(noOfBytes)
|
||||||
memset((*byte)(mem), int(val), int(noOfBytes))
|
memset((*byte)(mem), val, int(noOfBytes))
|
||||||
return mem
|
return mem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ func TestMemset(t *testing.T) {
|
||||||
if i > setNum-1 {
|
if i > setNum-1 {
|
||||||
testVal = byte(0)
|
testVal = byte(0)
|
||||||
}
|
}
|
||||||
if *indxBytePtr(mem, i) != testVal {
|
if (*[_Gi]byte)(mem)[i] != testVal {
|
||||||
t.Errorf("mem doesn't match expected values at: %v", i)
|
t.Errorf("mem doesn't match expected values at: %v", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ func TestGoStrToCStr(t *testing.T) {
|
||||||
testData := []byte{'s', 't', 'r', 'i', 'n', 'g', '\000'}
|
testData := []byte{'s', 't', 'r', 'i', 'n', 'g', '\000'}
|
||||||
|
|
||||||
for i := 0; i < len(goStr); i++ {
|
for i := 0; i < len(goStr); i++ {
|
||||||
val := *indxBytePtr(unsafe.Pointer(bStr), i)
|
val := (*[_Gi]byte)(unsafe.Pointer(bStr))[i]
|
||||||
testVal := testData[i]
|
testVal := testData[i]
|
||||||
if val != testVal {
|
if val != testVal {
|
||||||
t.Errorf("Wanted: %v, but got: %v", testVal, val)
|
t.Errorf("Wanted: %v, but got: %v", testVal, val)
|
||||||
|
@ -111,7 +111,7 @@ func TestStrdup(t *testing.T) {
|
||||||
newStr := strdup(bStr)
|
newStr := strdup(bStr)
|
||||||
|
|
||||||
for i := 0; i < len(goStr); i++ {
|
for i := 0; i < len(goStr); i++ {
|
||||||
val := *indxBytePtr(unsafe.Pointer(newStr), i)
|
val := (*[_Gi]byte)(unsafe.Pointer(newStr))[i]
|
||||||
testVal := testData[i]
|
testVal := testData[i]
|
||||||
if val != testVal {
|
if val != testVal {
|
||||||
t.Errorf("Wanted: %v, but got: %v", testVal, val)
|
t.Errorf("Wanted: %v, but got: %v", testVal, val)
|
||||||
|
@ -191,12 +191,3 @@ func TestDecPtr(t *testing.T) {
|
||||||
t.Errorf(errMsg, valueInt64, int64Arr[inc])
|
t.Errorf(errMsg, valueInt64, int64Arr[inc])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIndxBytePtr(t *testing.T) {
|
|
||||||
// Test how it deals with bytes
|
|
||||||
bytePtr := unsafe.Pointer(&byteArr[arrStart])
|
|
||||||
valueByte := indxBytePtr(bytePtr, inc)
|
|
||||||
if *valueByte != byteArr[inc] {
|
|
||||||
t.Errorf(errMsg, valueByte, byteArr[inc])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue