rtmp: make C_AMF_Encode take a []byte

This commit is contained in:
Dan Kortschak 2018-09-15 10:42:16 +09:30
parent e0311dae58
commit d38cd89bc3
1 changed files with 9 additions and 8 deletions

View File

@ -321,8 +321,7 @@ func C_AMF_PropEncode(p *C_AMFObjectProperty, dst []byte) *byte {
dst[0] = AMF_NULL dst[0] = AMF_NULL
pBuffer = &dst[1] pBuffer = &dst[1]
case AMF_OBJECT: case AMF_OBJECT:
b, e := b2pp(dst) pBuffer = C_AMF_Encode(&p.p_vu.p_object, dst)
pBuffer = C_AMF_Encode(&p.p_vu.p_object, b, e)
case AMF_ECMA_ARRAY: case AMF_ECMA_ARRAY:
b, e := b2pp(dst) b, e := b2pp(dst)
pBuffer = C_AMF_EncodeEcmaArray(&p.p_vu.p_object, b, e) 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); // char* AMF_Encode(AMFObject* obj, char* pBuffer, char* pBufEnd);
// amf.c +891 // amf.c +891
func C_AMF_Encode(obj *C_AMFObject, pBuffer *byte, pBufEnd *byte) *byte { func C_AMF_Encode(obj *C_AMFObject, dst []byte) *byte {
if uintptr(unsafe.Pointer(pBuffer))+uintptr(4) >= uintptr(unsafe.Pointer(pBufEnd)) { if len(dst) < 5 {
return nil return nil
} }
*pBuffer = AMF_OBJECT dst[0] = AMF_OBJECT
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1)) dst = dst[1:]
pBuffer, pBufEnd := b2pp(dst)
for i := 0; i < len(obj.o_props); i++ { for i := 0; i < len(obj.o_props); i++ {
res := C_AMF_PropEncode(&obj.o_props[i], pp2b(pBuffer, pBufEnd)) res := C_AMF_PropEncode(&obj.o_props[i], pp2b(pBuffer, pBufEnd))
if res == nil { if res == nil {
@ -571,12 +571,13 @@ func C_AMF_Encode(obj *C_AMFObject, pBuffer *byte, pBufEnd *byte) *byte {
pBuffer = res pBuffer = res
} }
} }
dst = pp2b(pBuffer, pBufEnd)
if uintptr(incBytePtr(unsafe.Pointer(pBuffer), 3)) >= uintptr(unsafe.Pointer(pBufEnd)) { if len(dst) < 4 {
return nil return nil
} }
pBuffer = C_AMF_EncodeInt24(pp2b(pBuffer, pBufEnd), int32(AMF_OBJECT_END)) pBuffer = C_AMF_EncodeInt24(dst, AMF_OBJECT_END)
return pBuffer return pBuffer
} }