From f7c9719d5b39e4faaa20bf890dafce21c9eb1026 Mon Sep 17 00:00:00 2001 From: saxon Date: Wed, 18 Jul 2018 12:02:02 +0930 Subject: [PATCH] Move amfEncodeString under rtmpWrite --- rtmp/rtmp.go | 57 ++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index ed4e0b2c..31c89b41 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -172,32 +172,6 @@ func (s *session) Write(data []byte) (int, error) { return len(data), nil } -func afmEncodeString(output *byte, outend *byte, bv *C.AVal) *byte { - outputPtr := unsafe.Pointer(output) - outendPtr := unsafe.Pointer(outend) - if (bv.av_len < 65536 && uintptr(incBytePtr(outputPtr, 1+2+int(bv.av_len))) > uintptr(outendPtr)) || uintptr(incBytePtr(outputPtr, 1+4+int(bv.av_len))) > uintptr(outendPtr) { - return nil - } - - if bv.av_len < 65536 { - *(*C.char)(outputPtr) = C.AMF_STRING - incBytePtr(outputPtr, 1) - - // TODO Encode Int16 - outputPtr = unsafe.Pointer(C.AMF_EncodeInt16((*C.char)(outputPtr), (*C.char)(outendPtr), (C.short)(bv.av_len))) - } else { - *(*C.char)(outputPtr) = C.AMF_LONG_STRING - incBytePtr(outputPtr, 1) - - // TODO Encode Int16 - outputPtr = unsafe.Pointer(C.AMF_EncodeInt32((*C.char)(outputPtr), (*C.char)(outendPtr), bv.av_len)) - } - C.memcpy(unsafe.Pointer(outputPtr), unsafe.Pointer(bv.av_val), (C.ulong)(bv.av_len)) - incBytePtr(outputPtr, int(bv.av_len)) - - return (*byte)(outputPtr) -} - // rtmpWrite writes data to the current rtmp connection encapsulated by r func rtmpWrite(r *C.RTMP, data []byte) int { buf := sliceToPtr(data) @@ -295,6 +269,33 @@ func rtmpWrite(r *C.RTMP, data []byte) int { return size + s2 } +func afmEncodeString(output *byte, outend *byte, bv *C.AVal) *byte { + outputPtr := unsafe.Pointer(output) + outendPtr := unsafe.Pointer(outend) + if (bv.av_len < 65536 && uintptr(incBytePtr(outputPtr, 1+2+int(bv.av_len))) > uintptr(outendPtr)) || uintptr(incBytePtr(outputPtr, 1+4+int(bv.av_len))) > uintptr(outendPtr) { + return nil + } + + if bv.av_len < 65536 { + *(*C.char)(outputPtr) = C.AMF_STRING + incBytePtr(outputPtr, 1) + + // TODO Encode Int16 + outputPtr = unsafe.Pointer(C.AMF_EncodeInt16((*C.char)(outputPtr), (*C.char)(outendPtr), (C.short)(bv.av_len))) + } else { + *(*C.char)(outputPtr) = C.AMF_LONG_STRING + incBytePtr(outputPtr, 1) + + // TODO Encode Int16 + outputPtr = unsafe.Pointer(C.AMF_EncodeInt32((*C.char)(outputPtr), (*C.char)(outendPtr), bv.av_len)) + } + C.memcpy(unsafe.Pointer(outputPtr), unsafe.Pointer(bv.av_val), (C.ulong)(bv.av_len)) + incBytePtr(outputPtr, int(bv.av_len)) + + return (*byte)(outputPtr) +} + + // send packet version 1 - less C stuff func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int { var prevPacket *C.RTMPPacket @@ -604,7 +605,7 @@ func writeN(r *C.RTMP, buffer unsafe.Pointer, n int) int { return 0 } -/* + // TODO: port RTMP_METHOD func avQueue(vals **C.RTMP_METHOD, num *int, av *C.AVal, txn int ) { var rtmpMethodPtr *C.RTMP_METHOD @@ -622,7 +623,7 @@ func avQueue(vals **C.RTMP_METHOD, num *int, av *C.AVal, txn int ) { (*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(*vals),*num, int(unsafe.Sizeof(rtmpMethodPtr))))).name.av_val = (*C.char)(tmp) } -*/ + // indxBytePtr returns a byte at the indx inc give a ptr func indxBytePtr(ptr unsafe.Pointer, inc int) *byte {