mirror of https://bitbucket.org/ausocean/av.git
Getting seg fault
This commit is contained in:
parent
0d7d445804
commit
5cca4d45a5
35
rtmp/rtmp.go
35
rtmp/rtmp.go
|
@ -379,7 +379,6 @@ func (s *session) Write(data []byte) (int, error) {
|
||||||
if rtmpIsConnected(s.rtmp) == 0 {
|
if rtmpIsConnected(s.rtmp) == 0 {
|
||||||
return 0, Err(1)
|
return 0, Err(1)
|
||||||
}
|
}
|
||||||
//if C.RTMP_Write(s.rtmp,(*C.char)(unsafe.Pointer(&data[0])),C.int(len(data))) == 0 {
|
|
||||||
if rtmpWrite(s.rtmp, data) == 0 {
|
if rtmpWrite(s.rtmp, data) == 0 {
|
||||||
return 0, Err(2)
|
return 0, Err(2)
|
||||||
}
|
}
|
||||||
|
@ -449,6 +448,7 @@ func rtmpSetupUrl(r *C.RTMP, u string) int32 {
|
||||||
port = 0
|
port = 0
|
||||||
|
|
||||||
len = strlen(url)
|
len = strlen(url)
|
||||||
|
// TODO: port this
|
||||||
ret = int32(C.RTMP_ParseURL((*C.char)(unsafe.Pointer(url)), &r.Link.protocol, &r.Link.hostname,
|
ret = int32(C.RTMP_ParseURL((*C.char)(unsafe.Pointer(url)), &r.Link.protocol, &r.Link.hostname,
|
||||||
(*C.uint)(&port), &r.Link.playpath0, &r.Link.app))
|
(*C.uint)(&port), &r.Link.playpath0, &r.Link.app))
|
||||||
|
|
||||||
|
@ -944,6 +944,7 @@ func sendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int {
|
||||||
|
|
||||||
func rtmpConnectStream(r *C.RTMP, seekTime int32) int {
|
func rtmpConnectStream(r *C.RTMP, seekTime int32) int {
|
||||||
var packet C.RTMPPacket
|
var packet C.RTMPPacket
|
||||||
|
memset((*byte)(unsafe.Pointer(&packet)), 0, int(unsafe.Sizeof(packet)))
|
||||||
|
|
||||||
if seekTime > 0 {
|
if seekTime > 0 {
|
||||||
r.Link.seekTime = C.int(seekTime)
|
r.Link.seekTime = C.int(seekTime)
|
||||||
|
@ -1306,7 +1307,6 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
if tbuf != nil {
|
if tbuf != nil {
|
||||||
// TODO: port C.writeN
|
|
||||||
wrote := int(writeN(r, tbuf, int(uintptr(decBytePtr(toff,
|
wrote := int(writeN(r, tbuf, int(uintptr(decBytePtr(toff,
|
||||||
int(uintptr(unsafe.Pointer(tbuf))))))))
|
int(uintptr(unsafe.Pointer(tbuf))))))))
|
||||||
C.free(tbuf)
|
C.free(tbuf)
|
||||||
|
@ -1333,10 +1333,10 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
|
||||||
if queue != 0 {
|
if queue != 0 {
|
||||||
var txn int
|
var txn int
|
||||||
ptr = incBytePtr(ptr, 3+int(method.av_len))
|
ptr = incBytePtr(ptr, 3+int(method.av_len))
|
||||||
|
txn = int(amfDecodeNumber((*byte)(ptr)))
|
||||||
// TODO: port this
|
// TODO: port this
|
||||||
txn = int(C.AMF_DecodeNumber((*C.char)(ptr)))
|
avQueue(&r.m_methodCalls, (*int)(unsafe.Pointer(&r.m_numCalls)), &method,
|
||||||
// TODO: port this
|
int(txn))
|
||||||
C.AV_queue(&r.m_methodCalls, &r.m_numCalls, &method, C.int(txn))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1402,21 +1402,21 @@ func sockBufSend(sb *C.RTMPSockBuf, buf *byte, l int32) int32 {
|
||||||
|
|
||||||
// TODO: port RTMP_METHOD
|
// TODO: port RTMP_METHOD
|
||||||
func avQueue(vals **C.RTMP_METHOD, num *int, av *C.AVal, txn int) {
|
func avQueue(vals **C.RTMP_METHOD, num *int, av *C.AVal, txn int) {
|
||||||
var rtmpMethodPtr *C.RTMP_METHOD
|
|
||||||
if (*num & 0x0f) == 0 {
|
if (*num & 0x0f) == 0 {
|
||||||
// TODO: work out what to do with the realloc
|
// TODO: work out what to do with the realloc
|
||||||
*vals = (*C.RTMP_METHOD)(C.realloc(unsafe.Pointer(*vals), C.size_t((*num+16)*int(unsafe.Sizeof(*(*vals))))))
|
*vals = (*C.RTMP_METHOD)(C.realloc(unsafe.Pointer(*vals), C.size_t((*num+16)*
|
||||||
|
int(unsafe.Sizeof(*(*vals))))))
|
||||||
}
|
}
|
||||||
tmp := unsafe.Pointer(C.malloc(C.size_t(av.av_len + 1)))
|
tmp := unsafe.Pointer(C.malloc(C.size_t(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))
|
||||||
//C.memcpy(tmp, unsafe.Pointer(av.av_val), C.size_t(av.av_len))
|
*indxBytePtr(tmp, int(av.av_len)) = '\000'
|
||||||
*indxBytePtr(tmp, int(av.av_len)) = *(*byte)(unsafe.Pointer(C.CString("")))
|
|
||||||
(*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(*vals), *num,
|
(*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(*vals), *num,
|
||||||
int(unsafe.Sizeof(rtmpMethodPtr))))).num = C.int(txn)
|
int(unsafe.Sizeof(*(*vals)))))).num = C.int(txn)
|
||||||
(*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(*vals), *num,
|
(*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(*vals), *num,
|
||||||
int(unsafe.Sizeof(rtmpMethodPtr))))).name.av_len = av.av_len
|
int(unsafe.Sizeof(*(*vals)))))).name.av_len = av.av_len
|
||||||
(*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(*vals), *num,
|
(*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(*vals), *num,
|
||||||
int(unsafe.Sizeof(rtmpMethodPtr))))).name.av_val = (*C.char)(tmp)
|
int(unsafe.Sizeof(*(*vals)))))).name.av_val = (*C.char)(tmp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func amfEncodeNamedNumber(output *byte, outend *byte, strName *C.AVal, dVal float64) *byte {
|
func amfEncodeNamedNumber(output *byte, outend *byte, strName *C.AVal, dVal float64) *byte {
|
||||||
|
@ -1471,6 +1471,17 @@ func amfEncodeNumber(output *byte, outend *byte, dVal float64) *byte {
|
||||||
return (*byte)(incBytePtr(unsafe.Pointer(output), 8))
|
return (*byte)(incBytePtr(unsafe.Pointer(output), 8))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func amfDecodeNumber(data *byte) float64 {
|
||||||
|
var dVal float64
|
||||||
|
var ci, co *uint8
|
||||||
|
ci = (*uint8)(unsafe.Pointer(data))
|
||||||
|
co = (*uint8)(unsafe.Pointer(&dVal))
|
||||||
|
for i := 0; i < 8; i++ {
|
||||||
|
*indxBytePtr(unsafe.Pointer(co), i) = *indxBytePtr(unsafe.Pointer(ci), 7-i)
|
||||||
|
}
|
||||||
|
return dVal
|
||||||
|
}
|
||||||
|
|
||||||
func amfEncodeNamedString(output *byte, outend *byte, strName *C.AVal, strValue *C.AVal) *byte {
|
func amfEncodeNamedString(output *byte, outend *byte, strName *C.AVal, strValue *C.AVal) *byte {
|
||||||
if int(uintptr(unsafe.Pointer(output)))+2+int(strName.av_len) > int(uintptr(unsafe.Pointer(outend))) {
|
if int(uintptr(unsafe.Pointer(output)))+2+int(strName.av_len) > int(uintptr(unsafe.Pointer(outend))) {
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue