From a2620e003b87c000a3e3ea4a6bfb5d9b37ae679d Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Fri, 14 Sep 2018 21:28:19 +0930 Subject: [PATCH] rtmp: make C_EncodeInt32LE take a []byte dst --- rtmp/rtmp.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index f1139869..30fdada1 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -47,6 +47,7 @@ import "C" import ( "bytes" + "encoding/binary" "errors" "fmt" "log" @@ -1242,14 +1243,8 @@ func C_DecodeInt32LE(data []byte) int32 { // int EncodeInt32LE(char* output, int nVal); // rtmp.c +3537 -func C_EncodeInt32LE(output *byte, nVal int32) int32 { - *output = byte(nVal) - nVal >>= 8 - (*[_Gi]byte)(unsafe.Pointer(output))[1] = byte(nVal) - nVal >>= 8 - (*[_Gi]byte)(unsafe.Pointer(output))[2] = byte(nVal) - nVal >>= 8 - (*[_Gi]byte)(unsafe.Pointer(output))[3] = byte(nVal) +func C_EncodeInt32LE(dst []byte, v int32) int32 { + binary.LittleEndian.PutUint32(dst, uint32(v)) return 4 } @@ -1613,8 +1608,7 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) { } if nSize > 8 { - // TODO: port this - hptr = incBytePtr(hptr, int(C_EncodeInt32LE((*byte)(hptr), packet.m_nInfoField2))) + hptr = incBytePtr(hptr, int(C_EncodeInt32LE((*[_Gi]byte)(hptr)[:4], packet.m_nInfoField2))) } if t >= 0xffffff {