rtmp: make C_AMF_Decode take a []byte

Also remove never-executed and incorrect error retry logic.
This commit is contained in:
Dan Kortschak 2018-09-16 09:40:43 +09:30
parent e649a94612
commit 61798fd4a6
2 changed files with 14 additions and 37 deletions

View File

@ -406,7 +406,7 @@ func C_AMFProp_Decode(prop *C_AMFObjectProperty, data []byte, bDecodeName int32)
data = data[2+nStringSize:]
case AMF_OBJECT:
nRes := C_AMF_Decode(&prop.p_vu.p_object, bAddr(data), int32(len(data)), 1)
nRes := C_AMF_Decode(&prop.p_vu.p_object, data, 1)
if nRes == -1 {
return -1
}
@ -430,7 +430,7 @@ func C_AMFProp_Decode(prop *C_AMFObjectProperty, data []byte, bDecodeName int32)
case AMF_ECMA_ARRAY:
// next comes the rest, mixed array has a final 0x000009 mark and names, so its an object
data = data[4:]
nRes = C_AMF_Decode(&prop.p_vu.p_object, bAddr(data), int32(len(data)), 1)
nRes = C_AMF_Decode(&prop.p_vu.p_object, data, 1)
if nRes == -1 {
return -1
}
@ -559,51 +559,28 @@ func C_AMF_EncodeArray(obj *C_AMFObject, dst []byte) []byte {
// int AMF_Decode(AMFObject *obj, const char* pBuffer, int nSize, int bDecodeName);
// amf.c +1180
func C_AMF_Decode(obj *C_AMFObject, pBuffer *byte, nSize, bDecodeName int32) int32 {
nOriginalSize := nSize
var bError int32
func C_AMF_Decode(obj *C_AMFObject, data []byte, bDecodeName int32) int32 {
nOriginalSize := len(data)
obj.o_props = obj.o_props[:0]
for nSize > 0 {
var prop C_AMFObjectProperty
var nRes int32
if nSize >= 3 && C_AMF_DecodeInt24((*[_Gi]byte)(unsafe.Pointer(pBuffer))[:3]) == AMF_OBJECT_END {
nSize -= 3
bError = 0
for len(data) != 0 {
if len(data) >= 3 && C_AMF_DecodeInt24(data[:3]) == AMF_OBJECT_END {
data = data[3:]
break
}
if bError != 0 {
// TODO use new logger here
log.Println("AMF_Decode: decoding error, ignoring bytes until next known pattern!")
nSize--
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1))
continue
}
// TODO port AMFProp_Decode
nRes = C_AMFProp_Decode(&prop, pl2b(pBuffer, int(nSize)), bDecodeName)
var prop C_AMFObjectProperty
nRes := C_AMFProp_Decode(&prop, data, bDecodeName)
// nRes = int32(C.AMFProp_Decode(&prop, (*byte)(unsafe.Pointer(pBuffer)),
// int32(nSize), int32(bDecodeName)))
if nRes == -1 {
bError = 1
break
} else {
nSize -= nRes
if nSize < 0 {
bError = 1
break
}
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), int(nRes)))
obj.o_props = append(obj.o_props, prop)
return -1
}
data = data[nRes:]
obj.o_props = append(obj.o_props, prop)
}
if bError != 0 {
return -1
}
return nOriginalSize - nSize
return int32(nOriginalSize - len(data))
}
// AMFObjectProperty* AMF_GetProp(AMFObject *obj, const AVal* name, int nIndex);

View File

@ -1059,7 +1059,7 @@ func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) (ok bool) {
return false
}
var obj C_AMFObject
nRes := C_AMF_Decode(&obj, body, int32(nBodySize), 0)
nRes := C_AMF_Decode(&obj, pl2b(body, int(nBodySize)), 0)
if nRes < 0 {
// TODO use new logger here
//RTMP_Log(RTMP_LOGERROR, "%s, error decoding invoke packet", __FUNCTION__);