mirror of https://bitbucket.org/ausocean/av.git
Building without error, just need to test
This commit is contained in:
parent
e0f07b9bca
commit
cf8568bf40
71
rtmp/rtmp.go
71
rtmp/rtmp.go
|
@ -406,12 +406,8 @@ func rtmpInit(r *C.RTMP) {
|
|||
}
|
||||
|
||||
func rtmpSetupUrl(r *C.RTMP, u string) int32 {
|
||||
length := len(u)
|
||||
url := goStrToCStr(u)
|
||||
|
||||
var opt, arg AVal
|
||||
var p1, p2 *byte
|
||||
ptr := strchr(url, byte(' '))
|
||||
var ret, len int32
|
||||
var port uint32
|
||||
port = 0
|
||||
|
@ -431,13 +427,14 @@ func rtmpSetupUrl(r *C.RTMP, u string) int32 {
|
|||
r.Link.tcUrl.av_val = (*C.char)(unsafe.Pointer(url))
|
||||
if r.Link.app.av_len != 0 {
|
||||
if int(uintptr(unsafe.Pointer(r.Link.app.av_val))) <
|
||||
int(uintptr(incBytePtr(unsafe.Pointer(url), len))) {
|
||||
int(uintptr(incBytePtr(unsafe.Pointer(url), int(len)))) {
|
||||
|
||||
r.Link.tcUrl.av_len = r.Link.app.av_len +
|
||||
int(uintptr(decBytePtr(r.Link.app.av_val, int(uintptr(unsafe.Pointer(url))))))
|
||||
r.Link.tcUrl.av_len = C.int(int(r.Link.app.av_len) +
|
||||
int(uintptr(decBytePtr(unsafe.Pointer(r.Link.app.av_val),
|
||||
int(uintptr(unsafe.Pointer(url)))))))
|
||||
} else {
|
||||
len = r.Link.hostname.av_len + r.Link.app.av_len +
|
||||
int(unsafe.Sizeof("rtmpte://:65535/"))
|
||||
len = int32(r.Link.hostname.av_len) + int32(r.Link.app.av_len) +
|
||||
int32(unsafe.Sizeof("rtmpte://:65535/"))
|
||||
|
||||
r.Link.tcUrl.av_val = (*C.char)(allocate(uintptr(len)))
|
||||
hostname := string(ptrToSlice(unsafe.Pointer(r.Link.hostname.av_val),
|
||||
|
@ -449,15 +446,15 @@ func rtmpSetupUrl(r *C.RTMP, u string) int32 {
|
|||
fString := fmt.Sprintf("%v://%v:%v/%v",
|
||||
RTMPProtocolStringsLower[r.Link.protocol], hostname, r.Link.port, app)
|
||||
|
||||
r.Link.tcUrl.av_val = (*C.char)(goStrToCStr(fString))
|
||||
r.Link.tcUrl.av_len = len(RTMPProtocolStringsLower[r.Link.protocol]) +
|
||||
len(string("://")) + len(hostname) + len(string(":")) +
|
||||
len(strconv.Itoa(int(r.Link.port))) + len(string("/")) + len(app)
|
||||
r.Link.tcUrl.av_val = (*C.char)(bToUP(goStrToCStr(fString)))
|
||||
r.Link.tcUrl.av_len = C.int(strLen(RTMPProtocolStringsLower[r.Link.protocol]) +
|
||||
strLen(string("://")) + strLen(hostname) + strLen(string(":")) +
|
||||
strLen(strconv.Itoa(int(r.Link.port))) + strLen(string("/")) + strLen(app))
|
||||
|
||||
r.Link.lFlags |= RTMP_LF_FTCU
|
||||
}
|
||||
} else {
|
||||
r.Link.tcUrl.av_len = strlen(url)
|
||||
r.Link.tcUrl.av_len = C.int(strlen(url))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -465,9 +462,9 @@ func rtmpSetupUrl(r *C.RTMP, u string) int32 {
|
|||
|
||||
if r.Link.port == 0 {
|
||||
switch {
|
||||
case r.Link.Protocol & RRTMP_FEATURE_SSL:
|
||||
case (r.Link.protocol & RTMP_FEATURE_SSL) != 0:
|
||||
r.Link.port = 433
|
||||
case r.Link.protocol & RTMP_FEATURE_HTTP:
|
||||
case (r.Link.protocol & RTMP_FEATURE_HTTP) != 0:
|
||||
r.Link.port = 80
|
||||
default:
|
||||
r.Link.port = 1935
|
||||
|
@ -476,14 +473,18 @@ func rtmpSetupUrl(r *C.RTMP, u string) int32 {
|
|||
return 1
|
||||
}
|
||||
|
||||
func strLen(str string) int {
|
||||
return len(str)
|
||||
}
|
||||
|
||||
/*
|
||||
func socksSetup(r *RTMP, sockshost *AVal) {
|
||||
if sockshost.av_len != 0 {
|
||||
socksport := strchr((*byte)(unsafe.Pointer(sockshost.av_val)), ':')
|
||||
hostname := strdup((*byte)(sockshost.av_val))
|
||||
hostname := strdup((*byte)(unsafe.Pointer(sockshost.av_val)))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
func endSession(rtmp *C.RTMP) uint32 {
|
||||
if rtmp == nil {
|
||||
return 3
|
||||
|
@ -1081,15 +1082,16 @@ func avQueue(vals **C.RTMP_METHOD, num *int, av *C.AVal, txn int) {
|
|||
}
|
||||
|
||||
// wrapper for converting byte pointer to unsafe.Pointer
|
||||
func uBP(b *byte) unsafe.Pointer {
|
||||
func bToUP(b *byte) unsafe.Pointer {
|
||||
return unsafe.Pointer(b)
|
||||
}
|
||||
|
||||
// wrapper for converting slice to unsafe.pointer
|
||||
func uBSP(b []byte) unsafe.Pointer {
|
||||
func sToUP(b []byte) unsafe.Pointer {
|
||||
return unsafe.Pointer(&b[0])
|
||||
}
|
||||
|
||||
// Creates a new C string from a go string
|
||||
func goStrToCStr(str string) *byte {
|
||||
l := len(str)
|
||||
slice := make([]byte, l+1)
|
||||
|
@ -1098,22 +1100,38 @@ func goStrToCStr(str string) *byte {
|
|||
slice[i] = *indxBytePtr(ptr, i)
|
||||
}
|
||||
slice[l] = '\000'
|
||||
return slice
|
||||
return &slice[0]
|
||||
}
|
||||
|
||||
// Duplicates a string given as a byte pointer
|
||||
func strdup(str *byte) *byte {
|
||||
length := strlen(str)
|
||||
newMem := make([]byte, length+1)
|
||||
oldMem := ptrToSlice(unsafe.Pointer(str), int(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; true; i++ {
|
||||
var ptr *byte
|
||||
for i := 0; i < 1000; i++ {
|
||||
ptr = indxBytePtr(unsafe.Pointer(str), i)
|
||||
if *ptr == '\000' {
|
||||
return i
|
||||
return int32(i)
|
||||
}
|
||||
}
|
||||
return 0
|
||||
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 {
|
||||
var ptr *byte
|
||||
for i := 0; true; i++ {
|
||||
for i := 0; i < 1000; i++ {
|
||||
ptr = indxBytePtr(unsafe.Pointer(str), i)
|
||||
if *ptr == val {
|
||||
return ptr
|
||||
|
@ -1125,6 +1143,7 @@ func strchr(str *byte, val byte) *byte {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Creates mem of the size noOfBytes. returns as unsafe pointer
|
||||
func allocate(nOfBytes uintptr) unsafe.Pointer {
|
||||
mem := make([]byte, int(nOfBytes))
|
||||
return unsafe.Pointer(&mem[0])
|
||||
|
|
Loading…
Reference in New Issue