rtmp: fixed broken cases, removed braces from cases, added panic to unsupported types in AMFPRop_Decode

This commit is contained in:
saxon 2018-08-25 17:37:36 +09:30
parent ecb3f3f4c2
commit 36dfa31c48
1 changed files with 100 additions and 130 deletions

View File

@ -79,6 +79,9 @@ func C_AMF_DecodeInt16(data *byte) uint16 {
// unsigned int AMF_DecodeInt24(const char* data);
// amf.c +50
func C_AMF_DecodeInt24(data *byte) uint32 {
c := (*[3]byte)(unsafe.Pointer(data))
return (uint32(c[0]) << 16) | (uint32(c[1]) << 8) | uint32(c[2])
/*
// TODO Understand logic and simplify
c := (*uint8)(unsafe.Pointer(data))
dst := uint32(int32(*c) << 16)
@ -87,6 +90,7 @@ func C_AMF_DecodeInt24(data *byte) uint32 {
dst |= uint32(int32(*((*uint8)(unsafe.Pointer(uintptr(unsafe.Pointer(c)) +
(uintptr)(int32(2))*unsafe.Sizeof(*c))))))
return dst
*/
}
// unsigned int AMF_DeocdeInt32(const char* data);
@ -519,16 +523,15 @@ func C_AMFProp_Decode(prop *C_AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa
switch prop.p_type {
case AMF_NUMBER:
log.Println("1")
if nSize < 8 {
return -1
}
prop.p_vu.p_number = float64(C_AMF_DecodeNumber(pBuffer))
nSize -= 8
/*
case AMF_BOOLEAN:
log.Println("2")
panic("AMF_BOOLEAN not supported")
/*
if nSize < 1 {
return -1
}
@ -536,8 +539,6 @@ func C_AMFProp_Decode(prop *C_AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa
nSize--
*/
case AMF_STRING:
{
log.Println("3")
var nStringSize = C_AMF_DecodeInt16(pBuffer)
if int64(nSize) < int64(nStringSize)+2 {
@ -545,48 +546,32 @@ func C_AMFProp_Decode(prop *C_AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa
}
C_AMF_DecodeString(pBuffer, &prop.p_vu.p_aval)
nSize -= int32(2 + nStringSize)
}
case AMF_OBJECT:
{
log.Println("4")
var nRes int32 = int32(C_AMF_Decode(&prop.p_vu.p_object, pBuffer, nSize, 1))
if nRes == -1 {
return -1
}
nSize -= nRes
}
case AMF_MOVIECLIP:
{
log.Println("5")
// TODO use new logger here
log.Println("AMFProp_Decode: MAF_MOVIECLIP reserved!")
//RTMP_Log(RTMP_LOGERROR, "AMF_MOVIECLIP reserved!");
return -1
}
case AMF_NULL:
log.Println("6")
case AMF_UNDEFINED:
log.Println("7")
case AMF_UNSUPPORTED:
log.Println("8")
case AMF_NULL, AMF_UNDEFINED, AMF_UNSUPPORTED:
prop.p_type = AMF_NULL
case AMF_REFERENCE:
{
log.Println("9")
// TODO use new logger here
log.Println("AMFProp_Decode: AMF_REFERENCE not supported!")
//RTMP_Log(RTMP_LOGERROR, "AMF_REFERENCE not supported!");
return -1
}
case AMF_ECMA_ARRAY:
{
log.Println("10")
nSize -= 4
// next comes the rest, mixed array has a final 0x000009 mark and names, so its an object
@ -596,17 +581,14 @@ func C_AMFProp_Decode(prop *C_AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa
return -1
}
nSize -= nRes
}
case AMF_OBJECT_END:
{
log.Println("11")
return -1
}
/*
case AMF_STRICT_ARRAY:
{
log.Println("12")
panic("AMF_STRICT_ARRAY not supported")
/*
nArrayLen := int32(C_AMF_DecodeInt32(pBuffer))
nSize -= 4
@ -615,12 +597,12 @@ func C_AMFProp_Decode(prop *C_AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa
return -1
}
nSize -= nRes
}
*/
/*
case AMF_DATE:
{
log.Println("13")
panic("AMF_DATE not supported")
/*
// TODO use new logger here
//RTMP_Log(RTMP_LOGDEBUG, "AMF_DATE");
@ -633,14 +615,10 @@ func C_AMFProp_Decode(prop *C_AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa
nSize -= 10
}
*/
case AMF_LONG_STRING:
log.Println("14")
case AMF_LONG_STRING, AMF_XML_DOC:
panic("AMF_LONG_STRING, AMF_XML_DOC not supported")
/*
case AMF_XML_DOC:
{
log.Println("15")
var nStringSize uint32 = C_AMF_DecodeInt32(pBuffer)
if int64(nSize) < int64(nStringSize)+4 {
return -1
@ -650,28 +628,22 @@ func C_AMFProp_Decode(prop *C_AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa
if prop.p_type == AMF_LONG_STRING {
prop.p_type = AMF_STRING
}
}
*/
case AMF_RECORDSET:
{
log.Println("16")
// TODO use new logger here
log.Println("AMFProp_Decode: AMF_RECORDSET reserved!")
//RTMP_Log(RTMP_LOGERROR, "AMF_RECORDSET reserved!");
return -1
}
case AMF_TYPED_OBJECT:
{
log.Println("17")
// TODO use new logger here
// RTMP_Log(RTMP_LOGERROR, "AMF_TYPED_OBJECT not supported!")
return -1
}
/*
case AMF_AVMPLUS:
{
panic("AMF_AVMPLUS not supported")
/*
log.Println("18")
nRes := int32(C.AMF3_Decode(&prop.p_vu.p_object, (*byte)(unsafe.Pointer(pBuffer)), int32(nSize), 1))
if nRes == -1 {
@ -679,10 +651,8 @@ func C_AMFProp_Decode(prop *C_AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa
}
nSize -= nRes
prop.p_type = AMF_OBJECT
}
*/
default:
log.Println("19")
// TODO use new logger here
//RTMP_Log(RTMP_LOGDEBUG, "%s - unknown datatype 0x%02x, @%p", __FUNCTION__,
//prop.p_type, pBuffer - 1);