Think I've cleaned it up a bit more, about to build

This commit is contained in:
saxon 2018-07-12 00:31:17 +09:30
parent 030b3f6fca
commit 929bdb32f9
1 changed files with 8 additions and 14 deletions

View File

@ -107,11 +107,6 @@ func byteSliceToCArr(buf []byte) *C.char {
return (*C.char)(unsafe.Pointer(&buf[0]))
}
func cPtrInc(a *C.char, inc C.uint) *C.char {
return (*C.char)(unsafe.Pointer( uintptr(unsafe.Pointer(a)) +
( unsafe.Sizeof(C.char(0x00)) * (uintptr(inc)) ) ))
}
func (s *session) rtmpWrite(r *C.RTMP, buf []byte) int {
var pkt *C.RTMPPacket = &r.m_write
size := len(buf)
@ -164,19 +159,19 @@ func (s *session) rtmpWrite(r *C.RTMP, buf []byte) int {
return 0
}
enc := C.GoBytes(unsafe.Pointer(pkt.m_body),C.int(pkt.m_nBodySize))
pend := enc[int(pkt.m_nBodySize):]
enc := unsafe.Pointer(pkt.m_body)
pend += enc + pkt.m_nBodySize
pend := unsafe.Pointer(uintptr(enc) + uintptr(pkt.m_nBodySize))
if pkt.m_packetType == C.RTMP_PACKET_TYPE_INFO {
enc = C.AMF_EncodeString(enc, pend, &av_setDataFrame )
enc = C.AMF_EncodeString((*C.char)(enc), (*C.char)(pend), &av_setDataFrame )
// C-code: pkt.m_nBytesRead enc - pkt.m_body
pkt.m_nBytesRead = (C.uint)((uintptr(unsafe.Pointer(enc)) -
uintptr(unsafe.Pointer(pkt.m_body)))/unsafe.Sizeof(C.char(0x00)))
pkt.m_nBytesRead = (C.uint)(uintptr(enc)-uintptr(unsafe.Pointer(pkt.m_body)))
}
} else {
//C-code: enc = pkt.m_body + pkt.m_nBytesRead
enc = cPtrInc(pkt.m_body,pkt.m_nBytesRead)
enc = unsafe.Pointer(uinptr(pkt.m_body) + uintptr(pkt.m_nBytesRead))
}
num = int(pkt.m_nBodySize - pkt.m_nBytesRead)
@ -184,9 +179,8 @@ func (s *session) rtmpWrite(r *C.RTMP, buf []byte) int {
if num > s2 {
num = s2
}
// C.memcpy(enc, buf, num)
// Need to create byte slice from c array enc
encSlice := C.GoBytes(unsafe.Pointer(enc),C.int(num))
encSlice := C.GoBytes(enc,C.int(num))
copy(encSlice,buf)
pkt.m_nBytesRead += C.uint(num)