From 0d7d4458047f58409728c1d120fd708d0932c0d8 Mon Sep 17 00:00:00 2001 From: saxon Date: Fri, 27 Jul 2018 14:44:02 +0930 Subject: [PATCH] Got rid of build errors, just need to test --- rtmp/rtmp.go | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index 334f2bcf..9f0b33e0 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -863,23 +863,23 @@ func sendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int { if r.Link.protocol&RTMP_FEATURE_WRITE == 0 { // TODO: port this - enc = C.AMF_EncodeNamedBoolean(enc, pend, &av_fpad, 0) + enc = amfEncodeNamedBoolean(enc, pend, &av_fpad, 0) if enc == nil { return 0 } - enc = C.AMF_EncodeNamedNumber(enc, pend, &av_capabilities, 15.0) + enc = amfEncodeNamedNumber(enc, pend, &av_capabilities, 15.0) if enc == nil { return 0 } - enc = C.AMF_EncodeNamedNumber(enc, pend, &av_audioCodecs, r.m_fAudioCodecs) + enc = amfEncodeNamedNumber(enc, pend, &av_audioCodecs, float64(r.m_fAudioCodecs)) if enc == nil { return 0 } - enc = C.AMF_EncodeNamedNumber(enc, pend, &av_videoCodecs, r.m_fVideoCodecs) + enc = amfEncodeNamedNumber(enc, pend, &av_videoCodecs, float64(r.m_fVideoCodecs)) if enc == nil { return 0 } - enc = C.AMF_EncodeNamedNumber(enc, pend, &av_videoFunction, 1.0) + enc = amfEncodeNamedNumber(enc, pend, &av_videoFunction, 1.0) if enc == nil { return 0 } @@ -892,7 +892,7 @@ func sendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int { } if r.m_fEncoding != 0.0 || r.m_bSendEncoding != 0 { - enc = C.AMF_EncodeNamedNumber(enc, pend, &av_objectEncoding, r.m_fEncoding) + enc = amfEncodeNamedNumber(enc, pend, &av_objectEncoding, float64(r.m_fEncoding)) if enc == nil { return 0 } @@ -913,8 +913,7 @@ func sendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int { /* add auth string */ if r.Link.auth.av_len != 0 { // TODO: port this - enc = (*byte)(unsafe.Pointer(C.AMF_EncodeBoolean((*C.char)(unsafe.Pointer(enc)), (*C.char)( - unsafe.Pointer(pend)), r.Link.lFlags&RTMP_LF_AUTH))) + enc = amfEncodeBoolean(enc, pend, int(r.Link.lFlags&RTMP_LF_AUTH)) if enc == nil { return 0 } @@ -1430,37 +1429,46 @@ func amfEncodeNamedNumber(output *byte, outend *byte, strName *C.AVal, dVal floa return amfEncodeNumber(output, outend, dVal) } -func amfEncodeNamedBoolean(output *byte, outend *byte, strName *AVal, bVal int) *byte { +func amfEncodeNamedBoolean(output *byte, outend *byte, strName *C.AVal, bVal int) *byte { if int(uintptr(unsafe.Pointer(output)))+2+int(strName.av_len) > int(uintptr(unsafe.Pointer(outend))) { return nil } output = amfEncodeInt16(output, outend, int16(strName.av_len)) memmove(unsafe.Pointer(output), unsafe.Pointer(outend), uintptr(strName.av_len)) output = (*byte)(incBytePtr(unsafe.Pointer(output), int(strName.av_len))) + return amfEncodeBoolean(output, outend, bVal) +} - return amfEncodeBoolean(output, outend, dVal) +func amfEncodeBoolean(output *byte, outend *byte, bVal int) *byte { + if int(uintptr(unsafe.Pointer(output)))+2 > int(uintptr(unsafe.Pointer(outend))) { + return nil + } + *(*byte)(unsafe.Pointer(output)) = C.AMF_BOOLEAN + output = (*byte)(incBytePtr(unsafe.Pointer(output), 1)) + val := byte(0x01) + if bVal == 0 { + val = byte(0x00) + } + *(*byte)(unsafe.Pointer(output)) = val + return output } func amfEncodeNumber(output *byte, outend *byte, dVal float64) *byte { if int(uintptr(unsafe.Pointer(output)))+1+8 > int(uintptr(unsafe.Pointer(outend))) { return nil } - // TODO: port this - *(*byte)(unsafe.Pointer(enc)) = C.AMF_NUMBER + *(*byte)(unsafe.Pointer(output)) = C.AMF_NUMBER output = (*byte)(incBytePtr(unsafe.Pointer(output), 1)) - // NOTE: here we are assuming little endian for both byte order and float // word order var ci, co *uint8 ci = (*uint8)(unsafe.Pointer(&dVal)) co = (*uint8)(unsafe.Pointer(output)) - for i := 0; i < 8; i++ { *indxBytePtr(unsafe.Pointer(co), i) = *indxBytePtr(unsafe.Pointer(ci), 7-i) } - - return (*Byte)(incBytePtr(unsafe.Pointer(output), 8)) + return (*byte)(incBytePtr(unsafe.Pointer(output), 8)) } func amfEncodeNamedString(output *byte, outend *byte, strName *C.AVal, strValue *C.AVal) *byte {