From 29f7d24623e9efc78282186d901a2d4848c6208f Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Wed, 19 Sep 2018 14:57:13 +0930 Subject: [PATCH] rtmp: clean up C_HandShake --- rtmp/rtmp.go | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index c8f0aa98..b66369cf 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -1391,30 +1391,25 @@ func C_RTMP_ReadPacket(r *C_RTMP, packet *C_RTMPPacket) (ok bool) { // int HandShake(RTMP* r, int FP9HandShake); // rtmp.c +3744 func C_HandShake(r *C_RTMP, FP9HandShake int32) (ok bool) { - var uptime, suptime uint32 - var typ [1]byte - //clientbuf := make([]byte, RTMP_SIG_SIZE+1) var clientbuf [RTMP_SIG_SIZE + 1]byte - clientsig := (*byte)(incBytePtr(unsafe.Pointer(&clientbuf[0]), 1)) - //serversig := make([]byte, RTMP_SIG_SIZE) + clientsig := clientbuf[1:] + var serversig [RTMP_SIG_SIZE]byte clientbuf[0] = 0x03 // not encrypted - // TODO: port rtmp_getTime - uptime = inet.Htonl(uint32(C_RTMP_GetTime())) - memmove(unsafe.Pointer(clientsig), unsafe.Pointer(&uptime), 4) - - memset((*byte)(sliceToPtr((*[_Gi]byte)(unsafe.Pointer(clientsig))[4:])), 0, 4) + binary.BigEndian.PutUint32(clientsig, uint32(C_RTMP_GetTime())) + copy(clientsig[4:8], []byte{0, 0, 0, 0}) for i := 8; i < RTMP_SIG_SIZE; i++ { - (*[_Gi]byte)(unsafe.Pointer(clientsig))[i] = byte(rand.Intn(256)) + clientsig[i] = byte(rand.Intn(256)) } - if !C_WriteN(r, pl2b(&clientbuf[0], RTMP_SIG_SIZE+1)) { + if !C_WriteN(r, clientbuf[:]) { return false } + var typ [1]byte if C_ReadN(r, typ[:]) != 1 { return false } @@ -1431,11 +1426,14 @@ func C_HandShake(r *C_RTMP, FP9HandShake int32) (ok bool) { } // decode server response - memmove(unsafe.Pointer(&suptime), unsafe.Pointer(&serversig[0]), 4) - suptime = inet.Ntohl(suptime) + suptime := binary.BigEndian.Uint32(serversig[:4]) + _ = suptime + // RTMP_Log(RTMP_LOGDEBUG, "%s: Server Uptime : %d", __FUNCTION__, suptime) + // RTMP_Log(RTMP_LOGDEBUG, "%s: FMS Version : %d.%d.%d.%d", __FUNCTION__, + // serversig[4], serversig[5], serversig[6], serversig[7]) // 2nd part of handshake - if !C_WriteN(r, pl2b(&serversig[0], RTMP_SIG_SIZE)) { + if !C_WriteN(r, serversig[:]) { return false }