mirror of https://bitbucket.org/ausocean/av.git
Finished dealing with bugs, but now I have a really ugly error that gives no indication to where abouts
This commit is contained in:
parent
376a694cd9
commit
d73dea687a
114
rtmp/rtmp.go
114
rtmp/rtmp.go
|
@ -41,6 +41,7 @@ int write_frame(RTMP* rtmp, char* data, uint data_length);
|
|||
int end_session(RTMP* rtmp);
|
||||
void AV_queue(RTMP_METHOD **vals, int *num, AVal *av, int txn);
|
||||
int WriteN(RTMP *r, const char *buffer, int n);
|
||||
int EncodeInt32LE(char *output, int nVal);
|
||||
*/
|
||||
import "C"
|
||||
|
||||
|
@ -175,12 +176,12 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
if indxBytePtr(buf,0) == 'F' && indxBytePtr(buf,1) == 'L' && indxBytePtr(buf,2) == 'V' {
|
||||
if *indxBytePtr(buf,0) == 'F' && *indxBytePtr(buf,1) == 'L' && *indxBytePtr(buf,2) == 'V' {
|
||||
buf = unsafe.Pointer(uintptr(buf) + uintptr(13))
|
||||
s2 -= 13
|
||||
}
|
||||
|
||||
pkt.m_packetType = C.uchar(indxBytePtr(buf,0))
|
||||
pkt.m_packetType = C.uchar(*indxBytePtr(buf,0))
|
||||
buf = incBytePtr(buf, 1)
|
||||
// TODO: port this
|
||||
pkt.m_nBodySize = C.AMF_DecodeInt24((*C.char)(buf))
|
||||
|
@ -188,7 +189,7 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
|
|||
// TODO: replace with ported version
|
||||
pkt.m_nTimeStamp = C.AMF_DecodeInt24((*C.char)(buf))
|
||||
buf = incBytePtr(buf, 3)
|
||||
pkt.m_nTimeStamp |= C.uint(indxBytePtr(buf,0)) << 24
|
||||
pkt.m_nTimeStamp |= C.uint(*indxBytePtr(buf,0)) << 24
|
||||
buf = incBytePtr(buf, 4)
|
||||
s2 -= 11
|
||||
|
||||
|
@ -314,13 +315,13 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
|
|||
t = int32(int(packet.m_nTimeStamp) - last)
|
||||
|
||||
if packet.m_body != nil {
|
||||
header = decPtr(unsafe.Pointer(packet.m_body), nSize,
|
||||
hend = packet.m_body
|
||||
header = decBytePtr(unsafe.Pointer(packet.m_body), nSize)
|
||||
hend = unsafe.Pointer(packet.m_body)
|
||||
} else {
|
||||
header = incPtr(hbuf,6)
|
||||
header = incBytePtr(hbuf,6)
|
||||
// TODO: be cautious about this sizeof - make sure it works how you think it
|
||||
// does. C code used sizeof(hbuf) where hbuf is a *char
|
||||
hend = incPtr(hbuf,unsafe.Sizeof((*byte)(hbuf)))
|
||||
hend = incBytePtr(hbuf,C.RTMP_MAX_HEADER_SIZE)
|
||||
}
|
||||
|
||||
switch {
|
||||
|
@ -331,9 +332,14 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
|
|||
}
|
||||
|
||||
if cSize != 0 {
|
||||
header = decPtr(header,4)
|
||||
hSize = incPtr(hSize,4)
|
||||
log.Printf("Larger timsetamp than 24-bit: 0x%x", t)
|
||||
header = decBytePtr(header,4)
|
||||
hSize += cSize
|
||||
}
|
||||
|
||||
if t >= 0xffffff {
|
||||
header = decBytePtr(header,4)
|
||||
hSize += 4
|
||||
log.Printf("Larger timestamp than 24-bit: 0x%v", t)
|
||||
}
|
||||
|
||||
hptr = header
|
||||
|
@ -347,33 +353,44 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
|
|||
c |= byte(1)
|
||||
}
|
||||
|
||||
*(*byte)(hptr) = c
|
||||
hptr = incBytePtr(hptr,1)
|
||||
|
||||
if cSize != 0 {
|
||||
tmp := packet.m_nChannel - 64
|
||||
*(*byte)(hptr) = byte(tmp & 0xff)
|
||||
hptr = incBytePtr(hptr,1)
|
||||
|
||||
if cSize == 2 {
|
||||
*(*byte)(hptr) = byte(tmp >> 8)
|
||||
hptr = incPtr(hptr,1)
|
||||
hptr = incBytePtr(hptr,1)
|
||||
}
|
||||
}
|
||||
|
||||
if nSize > 1 {
|
||||
res := t
|
||||
if t > 0xffffff {
|
||||
res = 0xffffff
|
||||
}
|
||||
hptr = unsafe.Pointer(AMF_EncodeInt24((*C.char)(hptr),(*C.char)(hend), res))
|
||||
hptr = unsafe.Pointer(C.AMF_EncodeInt24((*C.char)(hptr),(*C.char)(hend), C.int(res)))
|
||||
}
|
||||
|
||||
if nSize > 4 {
|
||||
*(*byte)(hptr) = byte(packet.m_packetType)
|
||||
hptr = unsafe.Pointer(AMF_EncodeInt24((*C.char)(hptr), (*C.char)(hend),
|
||||
packet.m_nbodySize))
|
||||
hptr = unsafe.Pointer(C.AMF_EncodeInt24((*C.char)(hptr), (*C.char)(hend),
|
||||
C.int(packet.m_nBodySize)))
|
||||
}
|
||||
|
||||
if nSize > 8 {
|
||||
hptr = incPtr(hptr, int(EncodeInt32LE((*C.char)(hptr), packet.m_nInfoField2)))
|
||||
hptr = incBytePtr(hptr, int(C.EncodeInt32LE((*C.char)(hptr), packet.m_nInfoField2)))
|
||||
}
|
||||
|
||||
if t >= 0xffffff {
|
||||
hptr = unsafe.Pointer(AMF_EncodeInt32((*C.char)(hptr), (*C.char)(hend), t))
|
||||
hptr = unsafe.Pointer(C.AMF_EncodeInt32((*C.char)(hptr), (*C.char)(hend), C.int(t)))
|
||||
}
|
||||
|
||||
nSize = int(packet.m_nBodySize)
|
||||
buffer = unsafe.Pointer(m_body)
|
||||
buffer = unsafe.Pointer(packet.m_body)
|
||||
nChunkSize = int(r.m_outChunkSize)
|
||||
|
||||
if debugMode {
|
||||
|
@ -382,14 +399,14 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
|
|||
|
||||
// send all chunks in one HTTP request
|
||||
// TODO: port RTMP_FEATURE_HTTP
|
||||
if r.Link.protocol & C.RTMP_FEATURE_HTTP {
|
||||
if int(r.Link.protocol & C.RTMP_FEATURE_HTTP) != 0 {
|
||||
chunks := (nSize+nChunkSize-1)/nChunkSize
|
||||
if chunks > 1 {
|
||||
tlen = chunks *(cSize+1) +nSize +hSize
|
||||
// TODO: figure out how to do this in go
|
||||
tbuf = C.malloc(tlen)
|
||||
tbuf = C.malloc(C.ulong(tlen))
|
||||
|
||||
if tbuf == 0 {
|
||||
if tbuf == nil {
|
||||
return 0
|
||||
}
|
||||
toff = tbuf
|
||||
|
@ -407,11 +424,11 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
|
|||
// RTMP_LogHexString(RTMP_LOGDEBUG2, (uint8_t *)buffer, nChunkSize);
|
||||
|
||||
if tbuf != nil {
|
||||
memmove(toff, header, nChunksize + hSize)
|
||||
toff = incPtr(toff, nChunkSize + hSize)
|
||||
memmove(toff, header, uintptr(nChunkSize + hSize))
|
||||
toff = incBytePtr(toff, nChunkSize + hSize)
|
||||
} else {
|
||||
// TODO: port this
|
||||
wrote = C.WriteN(r, (*C.char)(header), C.int(nChunkSize+hSize))
|
||||
wrote = int(C.WriteN(r, (*C.char)(header), C.int(nChunkSize+hSize)))
|
||||
|
||||
if wrote == 0 {
|
||||
return 0
|
||||
|
@ -419,20 +436,20 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
|
|||
}
|
||||
|
||||
nSize -= nChunkSize
|
||||
buffer = incPtr(buffer,nChunkSize)
|
||||
buffer = incBytePtr(buffer,nChunkSize)
|
||||
hSize = 0
|
||||
|
||||
if nSize > 0 {
|
||||
header = decPtr(buffer, 1)
|
||||
header = decBytePtr(buffer, 1)
|
||||
hSize = 1
|
||||
|
||||
if cSize != 0 {
|
||||
header = decPtr(header,1)
|
||||
header = decBytePtr(header,1)
|
||||
hSize += cSize
|
||||
}
|
||||
|
||||
if t >= 0xffffff {
|
||||
header = decPtr(header,4)
|
||||
header = decBytePtr(header,4)
|
||||
hSize += 4
|
||||
}
|
||||
|
||||
|
@ -440,25 +457,26 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
|
|||
|
||||
if cSize != 0 {
|
||||
tmp := int(packet.m_nChannel) - 64
|
||||
indxBytePtr(header,1) = byte(tmp & 0xff)
|
||||
*indxBytePtr(header,1) = byte(tmp & 0xff)
|
||||
|
||||
if cSize == 2 {
|
||||
indxBytePtr(header,2) = byte(tmp >> 8)
|
||||
*indxBytePtr(header,2) = byte(tmp >> 8)
|
||||
}
|
||||
}
|
||||
if t >= 0xffffff {
|
||||
extendedTimestamp := incPtr(header,1+cSize)
|
||||
extendedTimestamp := incBytePtr(header,1+cSize)
|
||||
// TODO: port this
|
||||
C.AMF_EncodeInt32((*C.char)(extendedTimestamp),
|
||||
(*C.char)(incPtr(extendedTimestamp,4)), t)
|
||||
(*C.char)(incBytePtr(extendedTimestamp,4)), C.int(t))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if tbuf != 0 {
|
||||
if tbuf != nil {
|
||||
// TODO: port C.writeN
|
||||
wrote := int(C.WriteN(r, (*C.char)(tbuf), (*C.char)(decPtr(toff,tbuf))))
|
||||
C.free((*C.char)(tbuf))
|
||||
wrote := int(C.WriteN(r, (*C.char)(tbuf), C.int(uintptr(decBytePtr(toff,
|
||||
int(uintptr(unsafe.Pointer(tbuf))))))))
|
||||
C.free(tbuf)
|
||||
tbuf = nil
|
||||
|
||||
if wrote == 0 {
|
||||
|
@ -472,7 +490,7 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
|
|||
// TODO: port C.AVal
|
||||
var method C.AVal
|
||||
var ptr unsafe.Pointer
|
||||
ptr = incPtr(unsafe.Pointer(packet.m_body),1)
|
||||
ptr = incBytePtr(unsafe.Pointer(packet.m_body),1)
|
||||
// TODO: port this
|
||||
C.AMF_DecodeString((*C.char)(ptr), &method)
|
||||
|
||||
|
@ -482,7 +500,7 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
|
|||
// keep it in call queue till result arrives
|
||||
if queue != 0 {
|
||||
var txn int
|
||||
ptr = incPtr(ptr, 3 + int(method.av_len))
|
||||
ptr = incBytePtr(ptr, 3 + int(method.av_len))
|
||||
// TODO: port this
|
||||
txn = int(C.AMF_DecodeNumber((*C.char)(ptr)))
|
||||
// TODO: port this
|
||||
|
@ -490,12 +508,14 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
|
|||
}
|
||||
}
|
||||
|
||||
if indxPtr(unsafe.Pointer(r.m_vecChannelsOut),packet.m_nChannel) == 0 {
|
||||
(*C.char)(indxPtr(r.m_vecChannelsOut)) = C.malloc(unsafe.Sizof(C.RTMPPacket))
|
||||
if unsafe.Pointer((*C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsOut),
|
||||
int(packet.m_nChannel), int(unsafe.Sizeof(packet))))) == nil {
|
||||
|
||||
r.m_vecChannelsOut = (**C.RTMPPacket)(C.malloc(C.ulong(unsafe.Sizeof(packet))))
|
||||
}
|
||||
|
||||
memmove(indxPtr(unsafe.Pointer(r.m_vecChannelsOut),packet.m_nChannel),
|
||||
unsafe.Pointer(packet), unsafe.Sizeof(C.RTMPPacket))
|
||||
memmove(incPtr(unsafe.Pointer(r.m_vecChannelsOut),int(packet.m_nChannel),
|
||||
int(unsafe.Sizeof(packet))),unsafe.Pointer(packet), unsafe.Sizeof(packet))
|
||||
|
||||
return 1
|
||||
}
|
||||
|
@ -563,18 +583,18 @@ func avQueue(vals **C.RTMP_METHOD, num *int, av *AVal, txn int ) {
|
|||
func memmove(to, from unsafe.Pointer, n uintptr)
|
||||
|
||||
// indxBytePtr returns a byte at the indx inc give a ptr
|
||||
func indxBytePtr(ptr unsafe.Pointer, inc int) byte {
|
||||
return *(*byte)(incPtr(ptr, inc, byteSize))
|
||||
func indxBytePtr(ptr unsafe.Pointer, inc int) *byte {
|
||||
return (*byte)(incPtr(ptr, inc, byteSize))
|
||||
}
|
||||
|
||||
// indxInt32Ptr returns an int32 at the indx inc given a ptr
|
||||
func indxInt32Ptr(ptr unsafe.Pointer, inc int) int32 {
|
||||
return *(*int32)(incPtr(ptr, inc, int32Size))
|
||||
func indxInt32Ptr(ptr unsafe.Pointer, inc int) *int32 {
|
||||
return (*int32)(incPtr(ptr, inc, int32Size))
|
||||
}
|
||||
|
||||
// indxInt64Ptr returns an int64 at the indx inc given a ptr
|
||||
func indxInt64Ptr(ptr unsafe.Pointer, inc int) int64 {
|
||||
return *(*int64)(incPtr(ptr, inc, int64Size))
|
||||
func indxInt64Ptr(ptr unsafe.Pointer, inc int) *int64 {
|
||||
return (*int64)(incPtr(ptr, inc, int64Size))
|
||||
}
|
||||
|
||||
// incBytePtr returns an unsafe.Pointer to a byte that is inc positive positions
|
||||
|
@ -620,7 +640,7 @@ func decInt32Ptr(ptr unsafe.Pointer, dec int) unsafe.Pointer {
|
|||
// decBytePtr returns an unsafe.Pointer to a int64 that is dec negative positions
|
||||
// from ptr
|
||||
func decInt64Ptr(ptr unsafe.Pointer, dec int) unsafe.Pointer {
|
||||
return decPTr(ptr,dec,int64Size)
|
||||
return decPtr(ptr,dec,int64Size)
|
||||
}
|
||||
|
||||
// sliceToPtr get's the address of the first data element and returns as unsafe
|
||||
|
|
Loading…
Reference in New Issue