From abd5cc27de371c7c12cbf6af561ee317a52a3718 Mon Sep 17 00:00:00 2001 From: saxon Date: Sun, 15 Jul 2018 17:18:24 +0930 Subject: [PATCH] Wrote WriteN - still need to test --- rtmp/rtmp.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index 438e2806..e6c3fe88 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -229,7 +229,7 @@ func rtmpWrite(r *C.RTMP, data []byte) int { } func sendPacket(r *C.RTMP, pkt *C.RTMPPacket, queue int) int { - const prevPacket *C.RTMPPacket + var prevPacket *C.RTMPPacket last := 0 var nSize, hSize, cSize, nChunkSize, tlen int var header, hptr, hend, buffer, tbuf, toff unsafe.Pointer @@ -319,7 +319,7 @@ func sendPacket(r *C.RTMP, pkt *C.RTMPPacket, queue int) int { c |= byte(1) } - hptr* = tmp >> 8 + *(*byte)(hptr) = byte(tmp >> 8) hptr = incPtr(hptr,1) if nSize > 1 { @@ -442,7 +442,7 @@ func sendPacket(r *C.RTMP, pkt *C.RTMPPacket, queue int) int { // TODO: port the const if packet.m_packetType == C.RTMP_PACKET_TYPE_INVOKE { // TODO: port C.AVal - var C.AVal method + var method C.AVal var ptr unsafe.Pointer ptr = incPtr(unsafe.Pointer(packet.m_body),1) // TODO: port this @@ -467,11 +467,54 @@ func sendPacket(r *C.RTMP, pkt *C.RTMPPacket, queue int) int { } memmove(indxPtr(unsafe.Pointer(r.m_vecChannelsOut),packet.m_nChannel), - unsafe.Pointer(packet), unsafe.Sizeof(C.RTMPPakcet)) + unsafe.Pointer(packet), unsafe.Sizeof(C.RTMPPacket)) return 1 } +func writeN(r *C.RTMP, buffer unsafe.Pointer, n int) int { + ptr := buffer + for n > 0 { + var nBytes int + + if r.Link.protocol & C.RTMP_FEATURE_HTTP { + // TODO: port HTTP_POST + nbytes = int(C.HTTP_POST(r, C.RTMPT_SEND, (*C.char)(ptr), C.int(n)) + } else { + // TODO: port this if necessary + nBytes = RTMPSockBuf_Send(&r.m_sb, (*C.char)(ptr), C.int(n)) + } + + if nBytes < 0 { + // TODO: port this + sockerr := int(C.GetSockError()) + + if debugMode { + log.Printf("WriteN, RTMP send error %v (%v bytes)",sockerr, n) + } + + if sockerr == C.EINTR && RTMP_ctrlC == 0 { + continue + } + + // TODO: port this + C.RTMP_Close(r) + n = 1 + break + } + + if nBytes == 0 { + break + } + + n -= nBytes + ptr = incPtr(ptr, nBytes) + } + + return n == 0 +} + + // memmove copies n bytes from "from" to "to". //go:linkname memmove runtime.memmove func memmove(to, from unsafe.Pointer, n uintptr)