From a1a8289a7f6abeff6b5a6e93036c4cfcd9de3c2e Mon Sep 17 00:00:00 2001 From: saxon Date: Tue, 31 Jul 2018 07:30:34 +0930 Subject: [PATCH] Ported amfEncodeEcmaArray - need to test --- rtmp/rtmp.go | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index ef1c68b7..e64990cb 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -1171,7 +1171,7 @@ func amfEncode(obj *C.AMFObject, pBuffer *byte, pBufEnd *byte) *byte { return nil } - *(*byte)(unsafe.Pointer(pBuffer)) = AMF_OBJECT + *pBuffer = AMF_OBJECT pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1)) for i := 0; i < int(obj.o_num); i++ { @@ -1194,6 +1194,36 @@ func amfEncode(obj *C.AMFObject, pBuffer *byte, pBufEnd *byte) *byte { return pBuffer } +func amfEncodeEcmaArray(obj *AMFObject, pBuffer *byte, pBufEnd *byte) *byte { + if int(uintptr(unsafe.Pointer(pBuffer)))+4 >= int(uintptr(unsafe.Pointer(pBufEnd))) { + return nil + } + + *pBuffer = AMF_ECMA_ARRAY + pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1)) + + pBuffer = amfEncodeInt32(pBuffer, pBufEnd, int32(obj.o_num)) + + for i := 0; i < int(obj.o_num); i++ { + res := amfPropEncode((*C.AMFObjectProperty)(incPtr(unsafe.Pointer( + obj.o_props), i, int(unsafe.Sizeof(*obj.o_props)))), pBuffer, pBufEnd) + if res == nil { + log.Println("amfEncodeEcmaArray: failed to encode property!") + break + } else { + pBuffer = res + } + } + + if int(uintptr(unsafe.Pointer(pBuffer)))+3 >= int(uintptr(unsafe.Pointer(pBufEnd))) { + return nil + } + + pBuffer = amfEncodeInt24(pBuffer, pBufEnd, AMF_OBJECT_END) + + return pBuffer +} + func rtmpConnectStream(r *C.RTMP, seekTime int32) int { var packet C.RTMPPacket memset((*byte)(unsafe.Pointer(&packet)), 0, int(unsafe.Sizeof(packet)))