mirror of https://bitbucket.org/ausocean/av.git
Finished writing out the sendPacket function, now time to try and compile
This commit is contained in:
parent
12f02fb261
commit
384fa23e5b
76
rtmp/rtmp.go
76
rtmp/rtmp.go
|
@ -155,12 +155,12 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
if indxPtr(buf,0) == 'F' && indxPtr(buf,1) == 'L' && indxPtr(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(indxPtr(buf,0))
|
||||
pkt.m_packetType = C.uchar(indxBytePtr(buf,0))
|
||||
buf = incPtr(buf, 1)
|
||||
// TODO: port this
|
||||
pkt.m_nBodySize = C.AMF_DecodeInt24((*C.char)(buf))
|
||||
|
@ -168,7 +168,7 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
|
|||
// TODO: replace with ported version
|
||||
pkt.m_nTimeStamp = C.AMF_DecodeInt24((*C.char)(buf))
|
||||
buf = incPtr(buf, 3)
|
||||
pkt.m_nTimeStamp |= C.uint(indxPtr(buf,0)) << 24
|
||||
pkt.m_nTimeStamp |= C.uint(indxBytePtr(buf,0)) << 24
|
||||
buf = incPtr(buf, 4)
|
||||
s2 -= 11
|
||||
|
||||
|
@ -232,9 +232,14 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
|
|||
return size + s2
|
||||
}
|
||||
|
||||
// indxPtr replicates C array indexing using an unsafe pointer
|
||||
func indxPtr(ptr unsafe.Pointer, inc int) byte {
|
||||
return *(*byte)(incPtr(ptr,inc))
|
||||
// indxPytetr replicates C array indexing using an unsafe pointer for byte data
|
||||
func indxBytePtr(ptr unsafe.Pointer, indx int) *byte {
|
||||
return (*byte)(incPtr(ptr,indx))
|
||||
}
|
||||
|
||||
// indxPytetr replicates C array indexing using an unsafe pointer for int data
|
||||
func indxIntPtr( ptr unsafe.Pointer, indx int ) *int {
|
||||
return (*int)(incPtr(ptr,indx))
|
||||
}
|
||||
|
||||
// sliceToPtr get's the address of the first data element and returns as unsafe
|
||||
|
@ -326,7 +331,7 @@ func sendPacket(r *C.RTMP, pkt *C.RTMPPacket, queue int) int {
|
|||
hend = packet.m_body
|
||||
} else {
|
||||
header = incPtr(hbuf,6)
|
||||
// TODO: be cautious about this size of - make sure it works how you think it
|
||||
// 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)))
|
||||
}
|
||||
|
@ -444,15 +449,68 @@ func sendPacket(r *C.RTMP, pkt *C.RTMPPacket, queue int) int {
|
|||
hSize += 4
|
||||
}
|
||||
|
||||
*(*byte)(header) = (0xc0 | c)
|
||||
*(*byte)(header) = byte(0xc0 | c)
|
||||
|
||||
if cSize != 0 {
|
||||
tmp := int(packet.m_nChannel) - 64
|
||||
indxBytePtr(header,1) = byte(tmp & 0xff)
|
||||
|
||||
if cSize == 2 {
|
||||
indxBytePtr(header,2) = byte(tmp >> 8)
|
||||
}
|
||||
}
|
||||
if t >= 0xffffff {
|
||||
extendedTimestamp := incPtr(header,1+cSize)
|
||||
// TODO: port this
|
||||
C.AMF_EncodeInt32((*C.char)(extendedTimestamp),
|
||||
(*C.char)(incPtr(extendedTimestamp,4)), t)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if tbuf != 0 {
|
||||
// TODO: port C.writeN
|
||||
wrote := int(C.WriteN(r, (*C.char)(tbuf), (*C.char)(decPtr(toff,tbuf))))
|
||||
C.free((*C.char)(tbuf))
|
||||
tbuf = nil
|
||||
|
||||
if wrote == 0 {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
// We invoked a remote method
|
||||
// TODO: port the const
|
||||
if packet.m_packetType == C.RTMP_PACKET_TYPE_INVOKE {
|
||||
// TODO: port C.AVal
|
||||
var C.AVal method
|
||||
var ptr unsafe.Pointer
|
||||
ptr = incPtr(unsafe.Pointer(packet.m_body),1)
|
||||
// TODO: port this
|
||||
C.AMF_DecodeString((*C.char)(ptr), &method)
|
||||
|
||||
if debugMode {
|
||||
log.Printf("Invoking %v", method.av_val)
|
||||
}
|
||||
// keep it in call queue till result arrives
|
||||
if queue != 0 {
|
||||
var txn int
|
||||
ptr = incPtr(ptr, 3 + int(method.av_len))
|
||||
// TODO: port this
|
||||
txn = int(C.AMF_DecodeNumber((*C.char)(ptr)))
|
||||
// TODO: port this
|
||||
C.AV_queue(&r.m_methodCalls, &r.m_numCalls, &method, C.int(txn))
|
||||
}
|
||||
}
|
||||
|
||||
if indxPtr(unsafe.Pointer(r.m_vecChannelsOut),packet.m_nChannel) == 0 {
|
||||
(*C.char)(indxPtr(r.m_vecChannelsOut)) = C.malloc(unsafe.Sizof(C.RTMPPacket))
|
||||
}
|
||||
|
||||
memmove(indxPtr(unsafe.Pointer(r.m_vecChannelsOut),packet.m_nChannel),
|
||||
unsafe.Pointer(packet), unsafe.Sizeof(C.RTMPPakcet))
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue