From 04bd966c890e9da1c67f3046f15f22deb7e646ff Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Sat, 15 Sep 2018 11:25:07 +0930 Subject: [PATCH] rtmp: make encoders return []byte --- rtmp/amf.go | 97 +++++++++++++++++++++++----------------------------- rtmp/rtmp.go | 87 +++++++++++++++++++++++----------------------- 2 files changed, 85 insertions(+), 99 deletions(-) diff --git a/rtmp/amf.go b/rtmp/amf.go index f6075907..8b6126eb 100644 --- a/rtmp/amf.go +++ b/rtmp/amf.go @@ -77,6 +77,13 @@ func b2pp(buf []byte) (b, e *byte) { return b, e } +func bAddr(buf []byte) *byte { + if len(buf) == 0 { + return nil + } + return &buf[0] +} + // unsigned short AMF_DecodeInt16(const char* data); // amf.c +41 func C_AMF_DecodeInt16(data []byte) uint16 { @@ -123,7 +130,7 @@ func C_AMF_DecodeBoolean(data []byte) bool { // char* AMF_EncodeInt24(char* output, char* outend, int nVal); // amf.c +149 -func C_AMF_EncodeInt24(dst []byte, val int32) *byte { +func C_AMF_EncodeInt24(dst []byte, val int32) []byte { if len(dst) < 3 { return nil } @@ -134,12 +141,12 @@ func C_AMF_EncodeInt24(dst []byte, val int32) *byte { if len(dst) == 3 { return nil } - return &dst[3:][0] + return dst[3:] } // char* AMF_EncodeInt32(char* output, char* outend, int nVal); // amf.c +160 -func C_AMF_EncodeInt32(dst []byte, val int32) *byte { +func C_AMF_EncodeInt32(dst []byte, val int32) []byte { if len(dst) < 4 { return nil } @@ -147,12 +154,12 @@ func C_AMF_EncodeInt32(dst []byte, val int32) *byte { if len(dst) == 4 { return nil } - return &dst[4:][0] + return dst[4:] } // char* AMF_EncodeString(char* output, char* outend, const C_AVal* bv); // amf.c +173 -func C_AMF_EncodeString(dst []byte, val string) *byte { +func C_AMF_EncodeString(dst []byte, val string) []byte { const typeSize = 1 if len(val) < 65536 && len(val)+typeSize+binary.Size(int16(0)) > len(dst) { return nil @@ -170,7 +177,7 @@ func C_AMF_EncodeString(dst []byte, val string) *byte { if len(dst) == len(val) { return nil } - return &dst[len(val):][0] + return dst[len(val):] } dst[0] = AMF_LONG_STRING dst = dst[1:] @@ -180,24 +187,24 @@ func C_AMF_EncodeString(dst []byte, val string) *byte { if len(dst) == len(val) { return nil } - return &dst[len(val):][0] + return dst[len(val):] } // char* AMF_EncodeNumber(char* output, char* outend, double dVal); // amf.c +199 -func C_AMF_EncodeNumber(dst []byte, val float64) *byte { +func C_AMF_EncodeNumber(dst []byte, val float64) []byte { if len(dst) < 9 { return nil } dst[0] = AMF_NUMBER dst = dst[1:] binary.BigEndian.PutUint64(dst, math.Float64bits(val)) - return &dst[8:][0] + return dst[8:] } // char* AMF_EncodeBoolean(char* output, char* outend, int bVal); // amf.c +260 -func C_AMF_EncodeBoolean(dst []byte, val bool) *byte { +func C_AMF_EncodeBoolean(dst []byte, val bool) []byte { if len(dst) < 2 { return nil } @@ -208,13 +215,13 @@ func C_AMF_EncodeBoolean(dst []byte, val bool) *byte { if len(dst) == 2 { return nil } - return &dst[2:][0] + return dst[2:] } // char* AMF_EncodeNamedString(char* output, char* outend, const C_AVal* strName, const C_AVal* strValue); // amf.c +273 -func C_AMF_EncodeNamedString(dst []byte, key, val string) *byte { +func C_AMF_EncodeNamedString(dst []byte, key, val string) []byte { if 2+len(key) > len(dst) { return nil } @@ -229,7 +236,7 @@ func C_AMF_EncodeNamedString(dst []byte, key, val string) *byte { // char* AMF_EncodeNamedNumber(char* output, char* outend, const C_AVal* strName, double dVal); // amf.c +286 -func C_AMF_EncodeNamedNumber(dst []byte, key string, val float64) *byte { +func C_AMF_EncodeNamedNumber(dst []byte, key string, val float64) []byte { if 2+len(key) > len(dst) { return nil } @@ -244,7 +251,7 @@ func C_AMF_EncodeNamedNumber(dst []byte, key string, val float64) *byte { // char* AMF_EncodeNamedBoolean(char* output, char* outend, const C_AVal* strname, int bVal); // amf.c +299 -func C_AMF_EncodeNamedBoolean(dst []byte, key string, val bool) *byte { +func C_AMF_EncodeNamedBoolean(dst []byte, key string, val bool) []byte { if 2+len(key) > len(dst) { return nil } @@ -290,7 +297,7 @@ func C_AMFProp_GetObject(prop *C_AMFObjectProperty, obj *C_AMFObject) { // char* AMFPropEncode(AMFOBjectProperty* prop, char* pBufer, char* pBufEnd); // amf.c +366 -func C_AMF_PropEncode(p *C_AMFObjectProperty, dst []byte) *byte { +func C_AMF_PropEncode(p *C_AMFObjectProperty, dst []byte) []byte { if p.p_type == AMF_INVALID { return nil } @@ -306,31 +313,30 @@ func C_AMF_PropEncode(p *C_AMFObjectProperty, dst []byte) *byte { dst = dst[len(p.p_name):] } - var pBuffer *byte switch p.p_type { case AMF_NUMBER: - pBuffer = C_AMF_EncodeNumber(dst, p.p_vu.p_number) + dst = C_AMF_EncodeNumber(dst, p.p_vu.p_number) case AMF_BOOLEAN: - pBuffer = C_AMF_EncodeBoolean(dst, p.p_vu.p_number != 0) + dst = C_AMF_EncodeBoolean(dst, p.p_vu.p_number != 0) case AMF_STRING: - pBuffer = C_AMF_EncodeString(dst, p.p_vu.p_aval) + dst = C_AMF_EncodeString(dst, p.p_vu.p_aval) case AMF_NULL: if len(dst) < 2 { return nil } dst[0] = AMF_NULL - pBuffer = &dst[1] + dst = dst[1:] case AMF_OBJECT: - pBuffer = C_AMF_Encode(&p.p_vu.p_object, dst) + dst = C_AMF_Encode(&p.p_vu.p_object, dst) case AMF_ECMA_ARRAY: - pBuffer = C_AMF_EncodeEcmaArray(&p.p_vu.p_object, dst) + dst = C_AMF_EncodeEcmaArray(&p.p_vu.p_object, dst) case AMF_STRICT_ARRAY: - pBuffer = C_AMF_EncodeArray(&p.p_vu.p_object, dst) + dst = C_AMF_EncodeArray(&p.p_vu.p_object, dst) default: log.Println("C_AMF_PropEncode: invalid type!") - pBuffer = nil + dst = nil } - return pBuffer + return dst } // int AMF3ReadInteger(const char *data, int32_t *valp); @@ -551,7 +557,7 @@ func C_AMFProp_Reset(prop *C_AMFObjectProperty) { // char* AMF_Encode(AMFObject* obj, char* pBuffer, char* pBufEnd); // amf.c +891 -func C_AMF_Encode(obj *C_AMFObject, dst []byte) *byte { +func C_AMF_Encode(obj *C_AMFObject, dst []byte) []byte { if len(dst) < 5 { return nil } @@ -559,30 +565,23 @@ func C_AMF_Encode(obj *C_AMFObject, dst []byte) *byte { dst[0] = AMF_OBJECT dst = dst[1:] - pBuffer, pBufEnd := b2pp(dst) for i := 0; i < len(obj.o_props); i++ { - res := C_AMF_PropEncode(&obj.o_props[i], pp2b(pBuffer, pBufEnd)) - if res == nil { + dst = C_AMF_PropEncode(&obj.o_props[i], dst) + if dst == nil { log.Println("C_AMF_Encode: failed to encode property in index") break - } else { - pBuffer = res } } - dst = pp2b(pBuffer, pBufEnd) if len(dst) < 4 { return nil } - - pBuffer = C_AMF_EncodeInt24(dst, AMF_OBJECT_END) - - return pBuffer + return C_AMF_EncodeInt24(dst, AMF_OBJECT_END) } // char* AMF_EncodeEcmaArray(AMFObject* obj, char* pBuffer, char* pBufEnd); // amf.c +924 -func C_AMF_EncodeEcmaArray(obj *C_AMFObject, dst []byte) *byte { +func C_AMF_EncodeEcmaArray(obj *C_AMFObject, dst []byte) []byte { if len(dst) < 5 { return nil } @@ -592,30 +591,23 @@ func C_AMF_EncodeEcmaArray(obj *C_AMFObject, dst []byte) *byte { binary.BigEndian.PutUint32(dst[:4], uint32(len(obj.o_props))) dst = dst[4:] - pBuffer, pBufEnd := b2pp(dst) for i := 0; i < len(obj.o_props); i++ { - res := C_AMF_PropEncode(&obj.o_props[i], pp2b(pBuffer, pBufEnd)) - if res == nil { + dst = C_AMF_PropEncode(&obj.o_props[i], dst) + if dst == nil { log.Println("C_AMF_EncodeEcmaArray: failed to encode property!") break - } else { - pBuffer = res } } - dst = pp2b(pBuffer, pBufEnd) if len(dst) < 4 { return nil } - - pBuffer = C_AMF_EncodeInt24(dst, AMF_OBJECT_END) - - return pBuffer + return C_AMF_EncodeInt24(dst, AMF_OBJECT_END) } // char* AMF_EncodeArray(AMFObject* obj, char* pBuffer, char* pBufEnd); // amf.c +959 -func C_AMF_EncodeArray(obj *C_AMFObject, dst []byte) *byte { +func C_AMF_EncodeArray(obj *C_AMFObject, dst []byte) []byte { if len(dst) < 5 { return nil } @@ -625,18 +617,15 @@ func C_AMF_EncodeArray(obj *C_AMFObject, dst []byte) *byte { binary.BigEndian.PutUint32(dst[:4], uint32(len(obj.o_props))) dst = dst[4:] - pBuffer, pBufEnd := b2pp(dst) for i := 0; i < len(obj.o_props); i++ { - res := C_AMF_PropEncode(&obj.o_props[i], pp2b(pBuffer, pBufEnd)) - if res == nil { + dst = C_AMF_PropEncode(&obj.o_props[i], dst) + if dst == nil { log.Println("C_AMF_EncodeArray: failed to encode property!") break - } else { - pBuffer = res } } - return pBuffer + return dst } // int AMF_DecodeArray(AMFObject *obj, const char *pBuffer, int nSize, int nArrayLen, int bDecodeName); diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index ccc7f2b8..20196521 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -670,69 +670,69 @@ func C_SendConnectPacket(r *C_RTMP, cp *C_RTMPPacket) (ok bool) { enc = (*byte)(unsafe.Pointer(packet.m_body)) - enc = C_AMF_EncodeString(pp2b(enc, pend), av_connect) + enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), av_connect)) r.m_numInvokes += 1 - enc = C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes)) + enc = bAddr(C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))) (*[_Gi]byte)(unsafe.Pointer(enc))[0] = AMF_OBJECT enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1)) - enc = C_AMF_EncodeNamedString(pp2b(enc, pend), av_app, r.Link.app) + enc = bAddr(C_AMF_EncodeNamedString(pp2b(enc, pend), av_app, r.Link.app)) if enc == nil { return false } if r.Link.protocol&RTMP_FEATURE_WRITE != 0 { - enc = C_AMF_EncodeNamedString(pp2b(enc, pend), av_type, av_nonprivate) + enc = bAddr(C_AMF_EncodeNamedString(pp2b(enc, pend), av_type, av_nonprivate)) if enc == nil { return false } } if r.Link.flashVer != "" { - enc = C_AMF_EncodeNamedString(pp2b(enc, pend), av_flashVer, r.Link.flashVer) + enc = bAddr(C_AMF_EncodeNamedString(pp2b(enc, pend), av_flashVer, r.Link.flashVer)) if enc == nil { return false } } if r.Link.swfUrl != "" { - enc = C_AMF_EncodeNamedString(pp2b(enc, pend), av_swfUrl, r.Link.swfUrl) + enc = bAddr(C_AMF_EncodeNamedString(pp2b(enc, pend), av_swfUrl, r.Link.swfUrl)) if enc == nil { return false } } if r.Link.tcUrl != "" { - enc = C_AMF_EncodeNamedString(pp2b(enc, pend), av_tcUrl, r.Link.tcUrl) + enc = bAddr(C_AMF_EncodeNamedString(pp2b(enc, pend), av_tcUrl, r.Link.tcUrl)) if enc == nil { return false } } if r.Link.protocol&RTMP_FEATURE_WRITE == 0 { - enc = C_AMF_EncodeNamedBoolean(pp2b(enc, pend), av_fpad, false) + enc = bAddr(C_AMF_EncodeNamedBoolean(pp2b(enc, pend), av_fpad, false)) if enc == nil { return false } - enc = C_AMF_EncodeNamedNumber(pp2b(enc, pend), av_capabilities, 15) + enc = bAddr(C_AMF_EncodeNamedNumber(pp2b(enc, pend), av_capabilities, 15)) if enc == nil { return false } - enc = C_AMF_EncodeNamedNumber(pp2b(enc, pend), av_audioCodecs, r.m_fAudioCodecs) + enc = bAddr(C_AMF_EncodeNamedNumber(pp2b(enc, pend), av_audioCodecs, r.m_fAudioCodecs)) if enc == nil { return false } - enc = C_AMF_EncodeNamedNumber(pp2b(enc, pend), av_videoCodecs, r.m_fVideoCodecs) + enc = bAddr(C_AMF_EncodeNamedNumber(pp2b(enc, pend), av_videoCodecs, r.m_fVideoCodecs)) if enc == nil { return false } - enc = C_AMF_EncodeNamedNumber(pp2b(enc, pend), av_videoFunction, 1) + enc = bAddr(C_AMF_EncodeNamedNumber(pp2b(enc, pend), av_videoFunction, 1)) if enc == nil { return false } if r.Link.pageUrl != "" { - enc = C_AMF_EncodeNamedString(pp2b(enc, pend), av_pageUrl, r.Link.pageUrl) + enc = bAddr(C_AMF_EncodeNamedString(pp2b(enc, pend), av_pageUrl, r.Link.pageUrl)) if enc == nil { return false } @@ -740,7 +740,7 @@ func C_SendConnectPacket(r *C_RTMP, cp *C_RTMPPacket) (ok bool) { } if r.m_fEncoding != 0.0 || r.m_bSendEncoding { - enc = C_AMF_EncodeNamedNumber(pp2b(enc, pend), av_objectEncoding, r.m_fEncoding) + enc = bAddr(C_AMF_EncodeNamedNumber(pp2b(enc, pend), av_objectEncoding, r.m_fEncoding)) if enc == nil { return false } @@ -760,18 +760,18 @@ func C_SendConnectPacket(r *C_RTMP, cp *C_RTMPPacket) (ok bool) { /* add auth string */ if r.Link.auth != "" { - enc = C_AMF_EncodeBoolean(pp2b(enc, pend), r.Link.lFlags&RTMP_LF_AUTH != 0) + enc = bAddr(C_AMF_EncodeBoolean(pp2b(enc, pend), r.Link.lFlags&RTMP_LF_AUTH != 0)) if enc == nil { return false } - enc = C_AMF_EncodeString(pp2b(enc, pend), r.Link.auth) + enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), r.Link.auth)) if enc == nil { return false } } for i := range r.Link.extras.o_props { - enc = C_AMF_PropEncode(&r.Link.extras.o_props[i], pp2b(enc, pend)) + enc = bAddr(C_AMF_PropEncode(&r.Link.extras.o_props[i], pp2b(enc, pend))) if enc == nil { return false } @@ -801,9 +801,9 @@ func C_RTMP_SendCreateStream(r *C_RTMP) (ok bool) { packet.m_body = &pbuf[RTMP_MAX_HEADER_SIZE] enc = (*byte)(unsafe.Pointer(packet.m_body)) - enc = C_AMF_EncodeString(pp2b(enc, pend), av_createStream) + enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), av_createStream)) r.m_numInvokes++ - enc = C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes)) + enc = bAddr(C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))) *enc = AMF_NULL enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1)) @@ -831,12 +831,12 @@ func C_SendReleaseStream(r *C_RTMP) (ok bool) { packet.m_body = &pbuf[RTMP_MAX_HEADER_SIZE] enc = (*byte)(unsafe.Pointer(packet.m_body)) - enc = C_AMF_EncodeString(pp2b(enc, pend), av_releaseStream) + enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), av_releaseStream)) r.m_numInvokes++ - enc = C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes)) + enc = bAddr(C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))) *enc = AMF_NULL enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1)) - enc = C_AMF_EncodeString(pp2b(enc, pend), r.Link.playpath) + enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), r.Link.playpath)) if enc == nil { return false } @@ -864,12 +864,12 @@ func C_SendFCPublish(r *C_RTMP) (ok bool) { packet.m_body = &pbuf[RTMP_MAX_HEADER_SIZE] enc = (*byte)(unsafe.Pointer(packet.m_body)) - enc = C_AMF_EncodeString(pp2b(enc, pend), av_FCPublish) + enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), av_FCPublish)) r.m_numInvokes++ - enc = C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes)) + enc = bAddr(C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))) *enc = AMF_NULL enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1)) - enc = C_AMF_EncodeString(pp2b(enc, pend), r.Link.playpath) + enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), r.Link.playpath)) if enc == nil { return false } @@ -897,12 +897,12 @@ func C_SendFCUnpublish(r *C_RTMP) (ok bool) { packet.m_body = &pbuf[RTMP_MAX_HEADER_SIZE] enc = (*byte)(unsafe.Pointer(packet.m_body)) - enc = C_AMF_EncodeString(pp2b(enc, pend), av_FCUnpublish) + enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), av_FCUnpublish)) r.m_numInvokes++ - enc = C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes)) + enc = bAddr(C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))) *enc = AMF_NULL enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1)) - enc = C_AMF_EncodeString(pp2b(enc, pend), r.Link.playpath) + enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), r.Link.playpath)) if enc == nil { return false @@ -932,18 +932,18 @@ func C_SendPublish(r *C_RTMP) (ok bool) { packet.m_body = &pbuf[RTMP_MAX_HEADER_SIZE] enc = (*byte)(unsafe.Pointer(packet.m_body)) - enc = C_AMF_EncodeString(pp2b(enc, pend), av_publish) + enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), av_publish)) r.m_numInvokes++ - enc = C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes)) + enc = bAddr(C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))) *enc = AMF_NULL enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1)) - enc = C_AMF_EncodeString(pp2b(enc, pend), r.Link.playpath) + enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), r.Link.playpath)) if enc == nil { return false } - enc = C_AMF_EncodeString(pp2b(enc, pend), av_live) + enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), av_live)) if enc == nil { return false } @@ -972,12 +972,12 @@ func C_SendDeleteStream(r *C_RTMP, dStreamId float64) (ok bool) { packet.m_body = &pbuf[RTMP_MAX_HEADER_SIZE] enc = (*byte)(unsafe.Pointer(packet.m_body)) - enc = C_AMF_EncodeString(pp2b(enc, pend), av_deleteStream) + enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), av_deleteStream)) r.m_numInvokes++ - enc = C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes)) + enc = bAddr(C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))) *enc = AMF_NULL enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1)) - enc = C_AMF_EncodeNumber(pp2b(enc, pend), dStreamId) + enc = bAddr(C_AMF_EncodeNumber(pp2b(enc, pend), dStreamId)) packet.m_nBodySize = uint32(uintptr(unsafe.Pointer(enc)) - uintptr( unsafe.Pointer(packet.m_body))) @@ -1028,9 +1028,9 @@ func C_SendCheckBW(r *C_RTMP) (ok bool) { packet.m_body = &pbuf[RTMP_MAX_HEADER_SIZE] enc = (*byte)(unsafe.Pointer(packet.m_body)) - enc = C_AMF_EncodeString(pp2b(enc, pend), av__checkbw) + enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), av__checkbw)) r.m_numInvokes++ - enc = C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes)) + enc = bAddr(C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))) *enc = AMF_NULL enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1)) @@ -1593,11 +1593,11 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) { if t > 0xffffff { res = 0xffffff } - hptr = unsafe.Pointer(C_AMF_EncodeInt24(pp2b((*byte)(hptr), (*byte)(hend)), int32(res))) + hptr = unsafe.Pointer(bAddr(C_AMF_EncodeInt24(pp2b((*byte)(hptr), (*byte)(hend)), int32(res)))) } if nSize > 4 { - hptr = unsafe.Pointer(C_AMF_EncodeInt24(pp2b((*byte)(hptr), (*byte)(hend)), (int32(packet.m_nBodySize)))) + hptr = unsafe.Pointer(bAddr(C_AMF_EncodeInt24(pp2b((*byte)(hptr), (*byte)(hend)), (int32(packet.m_nBodySize))))) *(*byte)(hptr) = packet.m_packetType hptr = incBytePtr(hptr, 1) } @@ -1607,7 +1607,7 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) { } if t >= 0xffffff { - hptr = unsafe.Pointer(C_AMF_EncodeInt32(pp2b((*byte)(hptr), (*byte)(hend)), (int32)(t))) + hptr = unsafe.Pointer(bAddr(C_AMF_EncodeInt32(pp2b((*byte)(hptr), (*byte)(hend)), (int32)(t)))) } nSize = int(packet.m_nBodySize) @@ -1818,7 +1818,7 @@ func C_RTMPSockBuf_Close(sb *C_RTMPSockBuf) int32 { func C_RTMP_Write(r *C_RTMP, buf []byte) int { // TODO: port RTMPPacket var pkt = &r.m_write - var pend, enc []byte + var enc []byte size := len(buf) var num int @@ -1864,11 +1864,8 @@ func C_RTMP_Write(r *C_RTMP, buf []byte) int { } enc = (*[_Gi]byte)(unsafe.Pointer(pkt.m_body))[:pkt.m_nBodySize] - pend = enc[pkt.m_nBodySize:] - if pkt.m_packetType == RTMP_PACKET_TYPE_INFO { - enc = (*[_Gi]byte)(unsafe.Pointer(C_AMF_EncodeString(pp2b((*byte)(unsafe.Pointer(&enc[0])), - (*byte)(unsafe.Pointer(&pend[0]))), setDataFrame)))[:pkt.m_nBodySize] + enc = C_AMF_EncodeString(enc, setDataFrame) // TODO: work out what to do with this pkt.m_nBytesRead = uint32(float64(uintptr(unsafe.Pointer(&enc[0])) -