diff --git a/rtmp/amf.go b/rtmp/amf.go index 5471328f..d6bbb3e4 100644 --- a/rtmp/amf.go +++ b/rtmp/amf.go @@ -321,8 +321,7 @@ func C_AMF_PropEncode(p *C_AMFObjectProperty, dst []byte) *byte { dst[0] = AMF_NULL pBuffer = &dst[1] case AMF_OBJECT: - b, e := b2pp(dst) - pBuffer = C_AMF_Encode(&p.p_vu.p_object, b, e) + pBuffer = C_AMF_Encode(&p.p_vu.p_object, dst) case AMF_ECMA_ARRAY: b, e := b2pp(dst) pBuffer = C_AMF_EncodeEcmaArray(&p.p_vu.p_object, b, e) @@ -554,14 +553,15 @@ 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, pBuffer *byte, pBufEnd *byte) *byte { - if uintptr(unsafe.Pointer(pBuffer))+uintptr(4) >= uintptr(unsafe.Pointer(pBufEnd)) { +func C_AMF_Encode(obj *C_AMFObject, dst []byte) *byte { + if len(dst) < 5 { return nil } - *pBuffer = AMF_OBJECT - pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1)) + 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 { @@ -571,12 +571,13 @@ func C_AMF_Encode(obj *C_AMFObject, pBuffer *byte, pBufEnd *byte) *byte { pBuffer = res } } + dst = pp2b(pBuffer, pBufEnd) - if uintptr(incBytePtr(unsafe.Pointer(pBuffer), 3)) >= uintptr(unsafe.Pointer(pBufEnd)) { + if len(dst) < 4 { return nil } - pBuffer = C_AMF_EncodeInt24(pp2b(pBuffer, pBufEnd), int32(AMF_OBJECT_END)) + pBuffer = C_AMF_EncodeInt24(dst, AMF_OBJECT_END) return pBuffer }