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);
// amf.c +318
func C_AMFProp_SetName(prop *C_AMFObjectProperty, name *C_AVal) {
prop.p_name = *name
func C_AMFProp_SetName(prop *C_AMFObjectProperty, name string) {
prop.p_name = name
}
// double AMFProp_GetNumber(AMFObjectProperty* prop);
@ -332,20 +332,18 @@ func C_AMF_PropEncode(p *C_AMFObjectProperty, pBuffer *byte, pBufEnd *byte) *byt
return nil
}
if p.p_type != AMF_NULL && int(uintptr(unsafe.Pointer(pBuffer)))+
int(p.p_name.av_len)+2+1 >= int(
uintptr(unsafe.Pointer(pBufEnd))) {
buflen := int(uintptr(unsafe.Pointer(pBufEnd)) - uintptr(unsafe.Pointer(pBuffer)))
if p.p_type != AMF_NULL && len(p.p_name)+2+1 >= buflen {
return nil
}
if p.p_type != AMF_NULL && p.p_name.av_len != 0 {
(*[_Gi]byte)(unsafe.Pointer(pBuffer))[0] = byte(p.p_name.av_len >> 8)
if p.p_type != AMF_NULL && len(p.p_name) != 0 {
(*[_Gi]byte)(unsafe.Pointer(pBuffer))[0] = byte(len(p.p_name) >> 8)
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))
memmove(unsafe.Pointer(pBuffer), unsafe.Pointer(p.p_name.av_val),
uintptr(p.p_name.av_len))
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), int(p.p_name.av_len)))
copy((*[_Gi]byte)(unsafe.Pointer(pBuffer))[:], p.p_name)
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), len(p.p_name)))
}
switch p.p_type {
@ -356,8 +354,8 @@ func C_AMF_PropEncode(p *C_AMFObjectProperty, pBuffer *byte, pBufEnd *byte) *byt
case AMF_STRING:
pBuffer = C_AMF_EncodeString(pBuffer, pBufEnd, p.p_vu.p_aval)
case AMF_NULL:
if uintptr(incBytePtr(unsafe.Pointer(pBuffer), 1)) >= uintptr(unsafe.Pointer(
pBufEnd)) {
buflen = int(uintptr(unsafe.Pointer(pBufEnd)) - uintptr(unsafe.Pointer(pBuffer)))
if 1 >= buflen {
return nil
}
*(*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 nRes int32
prop.p_name.av_len = 0
prop.p_name.av_val = nil
prop.p_name = ""
if nSize == 0 || pBuffer == nil {
// TODO use new logger here
@ -478,7 +475,7 @@ func C_AMFProp_Decode(prop *C_AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa
return -1
}
prop.p_name = AVC(C_AMF_DecodeString(pBuffer))
prop.p_name = C_AMF_DecodeString(pBuffer)
nSize -= int32(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);
// 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 < int32(obj.o_num) {
return &(*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props),
int(nIndex), int(unsafe.Sizeof(*obj.o_props)))))
//return &obj.o_props[nIndex]
}
} else {
var n int32
for n = 0; n < int32(obj.o_num); n++ {
if C_AVMATCH(&(*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props),
int(n), int(unsafe.Sizeof(*obj.o_props))))).p_name, name) != 0 {
for n := int32(0); n < obj.o_num; n++ {
p_name := (*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props),
int(n), int(unsafe.Sizeof(*obj.o_props))))).p_name
if p_name == name {
return &(*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props),
int(n), int(unsafe.Sizeof(*obj.o_props)))))
}

View File

@ -114,7 +114,7 @@ type P_vu struct {
// typedef struct AMFObjectProperty
// amf.h +79
type C_AMFObjectProperty struct {
p_name C_AVal
p_name string
p_type C_AMFDataType
p_vu P_vu
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
//C.AMF_Dump(&obj)
//C.AMFProp_GetString(C_AMF_GetProp(&obj, nil, 0), &method)
method := C_AMFProp_GetString(C_AMF_GetProp(&obj, nil, 0))
txn = float64(C_AMFProp_GetNumber(C_AMF_GetProp(&obj, nil, 1)))
method := C_AMFProp_GetString(C_AMF_GetProp(&obj, "", 0))
txn = float64(C_AMFProp_GetNumber(C_AMF_GetProp(&obj, "", 1)))
// TODO use new logger here
// RTMP_Log(RTMP_LOGDEBUG, "%s, server invoking <%s>", __FUNCTION__, method.av_val);
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:
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 {
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:
var obj2 C_AMFObject
C_AMFProp_GetObject(C_AMF_GetProp(&obj, nil, 3), &obj2)
code := C_AMFProp_GetString(C_AMF_GetProp(&obj2, &av_code, -1))
C_AMFProp_GetObject(C_AMF_GetProp(&obj, "", 3), &obj2)
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
// TODO use new logger