rtmp: remove C_Aval from C_AMFObjectProperty

This commit is contained in:
Dan Kortschak 2018-09-06 16:30:39 +09:30
parent c4800034a6
commit fed9d366c6
3 changed files with 25 additions and 29 deletions

View File

@ -296,8 +296,8 @@ func C_AMF_EncodeNamedBoolean(output *byte, outend *byte, key string, val bool)
// void AMFProp_SetName(AMFObjectProperty *prop, AVal *name); // void AMFProp_SetName(AMFObjectProperty *prop, AVal *name);
// amf.c +318 // amf.c +318
func C_AMFProp_SetName(prop *C_AMFObjectProperty, name *C_AVal) { func C_AMFProp_SetName(prop *C_AMFObjectProperty, name string) {
prop.p_name = *name prop.p_name = name
} }
// double AMFProp_GetNumber(AMFObjectProperty* prop); // double AMFProp_GetNumber(AMFObjectProperty* prop);
@ -332,20 +332,18 @@ func C_AMF_PropEncode(p *C_AMFObjectProperty, pBuffer *byte, pBufEnd *byte) *byt
return nil return nil
} }
if p.p_type != AMF_NULL && int(uintptr(unsafe.Pointer(pBuffer)))+ buflen := int(uintptr(unsafe.Pointer(pBufEnd)) - uintptr(unsafe.Pointer(pBuffer)))
int(p.p_name.av_len)+2+1 >= int( if p.p_type != AMF_NULL && len(p.p_name)+2+1 >= buflen {
uintptr(unsafe.Pointer(pBufEnd))) {
return nil return nil
} }
if p.p_type != AMF_NULL && p.p_name.av_len != 0 { if p.p_type != AMF_NULL && len(p.p_name) != 0 {
(*[_Gi]byte)(unsafe.Pointer(pBuffer))[0] = byte(p.p_name.av_len >> 8) (*[_Gi]byte)(unsafe.Pointer(pBuffer))[0] = byte(len(p.p_name) >> 8)
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1)) pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1))
(*[_Gi]byte)(unsafe.Pointer(pBuffer))[0] = byte(p.p_name.av_len & 0xff) (*[_Gi]byte)(unsafe.Pointer(pBuffer))[0] = byte(len(p.p_name) & 0xff)
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1)) pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1))
memmove(unsafe.Pointer(pBuffer), unsafe.Pointer(p.p_name.av_val), copy((*[_Gi]byte)(unsafe.Pointer(pBuffer))[:], p.p_name)
uintptr(p.p_name.av_len)) pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), len(p.p_name)))
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), int(p.p_name.av_len)))
} }
switch p.p_type { switch p.p_type {
@ -356,8 +354,8 @@ func C_AMF_PropEncode(p *C_AMFObjectProperty, pBuffer *byte, pBufEnd *byte) *byt
case AMF_STRING: case AMF_STRING:
pBuffer = C_AMF_EncodeString(pBuffer, pBufEnd, p.p_vu.p_aval) pBuffer = C_AMF_EncodeString(pBuffer, pBufEnd, p.p_vu.p_aval)
case AMF_NULL: case AMF_NULL:
if uintptr(incBytePtr(unsafe.Pointer(pBuffer), 1)) >= uintptr(unsafe.Pointer( buflen = int(uintptr(unsafe.Pointer(pBufEnd)) - uintptr(unsafe.Pointer(pBuffer)))
pBufEnd)) { if 1 >= buflen {
return nil return nil
} }
*(*byte)(unsafe.Pointer(pBuffer)) = AMF_NULL *(*byte)(unsafe.Pointer(pBuffer)) = AMF_NULL
@ -454,8 +452,7 @@ func C_AMFProp_Decode(prop *C_AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa
var nOriginalSize int32 = nSize var nOriginalSize int32 = nSize
var nRes int32 var nRes int32
prop.p_name.av_len = 0 prop.p_name = ""
prop.p_name.av_val = nil
if nSize == 0 || pBuffer == nil { if nSize == 0 || pBuffer == nil {
// TODO use new logger here // TODO use new logger here
@ -478,7 +475,7 @@ func C_AMFProp_Decode(prop *C_AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa
return -1 return -1
} }
prop.p_name = AVC(C_AMF_DecodeString(pBuffer)) prop.p_name = C_AMF_DecodeString(pBuffer)
nSize -= int32(2 + nNameSize) nSize -= int32(2 + nNameSize)
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), int(2+nNameSize))) pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), int(2+nNameSize)))
} }
@ -788,18 +785,17 @@ func C_AMF_AddProp(obj *C_AMFObject, prop *C_AMFObjectProperty) {
// AMFObjectProperty* AMF_GetProp(AMFObject *obj, const AVal* name, int nIndex); // AMFObjectProperty* AMF_GetProp(AMFObject *obj, const AVal* name, int nIndex);
// amf.c + 1249 // amf.c + 1249
func C_AMF_GetProp(obj *C_AMFObject, name *C_AVal, nIndex int32) *C_AMFObjectProperty { func C_AMF_GetProp(obj *C_AMFObject, name string, nIndex int32) *C_AMFObjectProperty {
if nIndex >= 0 { if nIndex >= 0 {
if nIndex < int32(obj.o_num) { if nIndex < int32(obj.o_num) {
return &(*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props), return &(*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props),
int(nIndex), int(unsafe.Sizeof(*obj.o_props))))) int(nIndex), int(unsafe.Sizeof(*obj.o_props)))))
//return &obj.o_props[nIndex]
} }
} else { } else {
var n int32 for n := int32(0); n < obj.o_num; n++ {
for n = 0; n < int32(obj.o_num); n++ { p_name := (*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props),
if C_AVMATCH(&(*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props), int(n), int(unsafe.Sizeof(*obj.o_props))))).p_name
int(n), int(unsafe.Sizeof(*obj.o_props))))).p_name, name) != 0 { if p_name == name {
return &(*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props), return &(*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props),
int(n), int(unsafe.Sizeof(*obj.o_props))))) int(n), int(unsafe.Sizeof(*obj.o_props)))))
} }

View File

@ -114,7 +114,7 @@ type P_vu struct {
// typedef struct AMFObjectProperty // typedef struct AMFObjectProperty
// amf.h +79 // amf.h +79
type C_AMFObjectProperty struct { type C_AMFObjectProperty struct {
p_name C_AVal p_name string
p_type C_AMFDataType p_type C_AMFDataType
p_vu P_vu p_vu P_vu
p_UTCoffset int16 p_UTCoffset int16

View File

@ -1174,8 +1174,8 @@ func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) (ok bool) {
// NOTE we don't really need this ?? still functions without it // NOTE we don't really need this ?? still functions without it
//C.AMF_Dump(&obj) //C.AMF_Dump(&obj)
//C.AMFProp_GetString(C_AMF_GetProp(&obj, nil, 0), &method) //C.AMFProp_GetString(C_AMF_GetProp(&obj, nil, 0), &method)
method := C_AMFProp_GetString(C_AMF_GetProp(&obj, nil, 0)) method := C_AMFProp_GetString(C_AMF_GetProp(&obj, "", 0))
txn = float64(C_AMFProp_GetNumber(C_AMF_GetProp(&obj, nil, 1))) txn = float64(C_AMFProp_GetNumber(C_AMF_GetProp(&obj, "", 1)))
// TODO use new logger here // TODO use new logger here
// RTMP_Log(RTMP_LOGDEBUG, "%s, server invoking <%s>", __FUNCTION__, method.av_val); // RTMP_Log(RTMP_LOGDEBUG, "%s, server invoking <%s>", __FUNCTION__, method.av_val);
avmethod := AVC(method) avmethod := AVC(method)
@ -1221,7 +1221,7 @@ func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) (ok bool) {
} }
case C_AVMATCH(&methodInvoked, &av_createStream) != 0: case C_AVMATCH(&methodInvoked, &av_createStream) != 0:
r.m_stream_id = int32(C_AMFProp_GetNumber(C_AMF_GetProp(&obj, nil, 3))) r.m_stream_id = int32(C_AMFProp_GetNumber(C_AMF_GetProp(&obj, "", 3)))
if (r.Link.protocol & RTMP_FEATURE_WRITE) != 0 { if (r.Link.protocol & RTMP_FEATURE_WRITE) != 0 {
C_SendPublish(r) C_SendPublish(r)
@ -1257,10 +1257,10 @@ func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) (ok bool) {
case C_AVMATCH(&avmethod, &av_onStatus) != 0: case C_AVMATCH(&avmethod, &av_onStatus) != 0:
var obj2 C_AMFObject var obj2 C_AMFObject
C_AMFProp_GetObject(C_AMF_GetProp(&obj, nil, 3), &obj2) C_AMFProp_GetObject(C_AMF_GetProp(&obj, "", 3), &obj2)
code := C_AMFProp_GetString(C_AMF_GetProp(&obj2, &av_code, -1)) code := C_AMFProp_GetString(C_AMF_GetProp(&obj2, CAV(&av_code), -1))
level := C_AMFProp_GetString(C_AMF_GetProp(&obj2, &av_level, -1)) // Not used. level := C_AMFProp_GetString(C_AMF_GetProp(&obj2, CAV(&av_level), -1)) // Not used.
_ = level _ = level
// TODO use new logger // TODO use new logger