mirror of https://bitbucket.org/ausocean/av.git
rtmp: make C_AMFObject hold a []C_AMFObjectProperty
This commit is contained in:
parent
52f34e4a85
commit
b8742e9927
75
rtmp/amf.go
75
rtmp/amf.go
|
@ -553,9 +553,8 @@ func C_AMF_Encode(obj *C_AMFObject, pBuffer *byte, pBufEnd *byte) *byte {
|
|||
*pBuffer = AMF_OBJECT
|
||||
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1))
|
||||
|
||||
for i := 0; i < int(obj.o_num); i++ {
|
||||
res := C_AMF_PropEncode((*C_AMFObjectProperty)(incPtr(unsafe.Pointer(
|
||||
obj.o_props), i, int(unsafe.Sizeof(*obj.o_props)))), pBuffer, pBufEnd)
|
||||
for i := 0; i < len(obj.o_props); i++ {
|
||||
res := C_AMF_PropEncode(&obj.o_props[i], pBuffer, pBufEnd)
|
||||
if res == nil {
|
||||
log.Println("C_AMF_Encode: failed to encode property in index")
|
||||
break
|
||||
|
@ -583,11 +582,10 @@ func C_AMF_EncodeEcmaArray(obj *C_AMFObject, pBuffer *byte, pBufEnd *byte) *byte
|
|||
*pBuffer = AMF_ECMA_ARRAY
|
||||
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1))
|
||||
|
||||
pBuffer = C_AMF_EncodeInt32(pp2b(pBuffer, pBufEnd), obj.o_num)
|
||||
pBuffer = C_AMF_EncodeInt32(pp2b(pBuffer, pBufEnd), int32(len(obj.o_props)))
|
||||
|
||||
for i := 0; i < int(obj.o_num); i++ {
|
||||
res := C_AMF_PropEncode((*C_AMFObjectProperty)(incPtr(unsafe.Pointer(
|
||||
obj.o_props), i, int(unsafe.Sizeof(*obj.o_props)))), pBuffer, pBufEnd)
|
||||
for i := 0; i < len(obj.o_props); i++ {
|
||||
res := C_AMF_PropEncode(&obj.o_props[i], pBuffer, pBufEnd)
|
||||
if res == nil {
|
||||
log.Println("C_AMF_EncodeEcmaArray: failed to encode property!")
|
||||
break
|
||||
|
@ -615,13 +613,12 @@ func C_AMF_EncodeArray(obj *C_AMFObject, pBuffer *byte, pBufEnd *byte) *byte {
|
|||
*pBuffer = AMF_STRICT_ARRAY
|
||||
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1))
|
||||
|
||||
pBuffer = C_AMF_EncodeInt32(pp2b(pBuffer, pBufEnd), obj.o_num)
|
||||
pBuffer = C_AMF_EncodeInt32(pp2b(pBuffer, pBufEnd), int32(len(obj.o_props)))
|
||||
|
||||
for i := 0; i < int(obj.o_num); i++ {
|
||||
res := C_AMF_PropEncode((*C_AMFObjectProperty)(incPtr(unsafe.Pointer(
|
||||
obj.o_props), i, int(unsafe.Sizeof(*obj.o_props)))), pBuffer, pBufEnd)
|
||||
for i := 0; i < len(obj.o_props); i++ {
|
||||
res := C_AMF_PropEncode(&obj.o_props[i], pBuffer, pBufEnd)
|
||||
if res == nil {
|
||||
log.Println("C_AMF_EncodeEcmaArray: failed to encode property!")
|
||||
log.Println("C_AMF_EncodeArray: failed to encode property!")
|
||||
break
|
||||
} else {
|
||||
pBuffer = res
|
||||
|
@ -637,8 +634,7 @@ func C_AMF_DecodeArray(obj *C_AMFObject, pBuffer *byte, nSize, nArrayLen, bDecod
|
|||
nOriginalSize := nSize
|
||||
var bError int32 = 0
|
||||
|
||||
obj.o_num = 0
|
||||
obj.o_props = nil
|
||||
obj.o_props = obj.o_props[:0]
|
||||
for nArrayLen > 0 {
|
||||
var prop C_AMFObjectProperty
|
||||
var nRes int32
|
||||
|
@ -655,7 +651,7 @@ func C_AMF_DecodeArray(obj *C_AMFObject, pBuffer *byte, nSize, nArrayLen, bDecod
|
|||
} else {
|
||||
nSize -= nRes
|
||||
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), int(nRes)))
|
||||
C_AMF_AddProp(obj, &prop)
|
||||
obj.o_props = append(obj.o_props, prop)
|
||||
}
|
||||
}
|
||||
if bError != 0 {
|
||||
|
@ -671,9 +667,7 @@ func C_AMF_Decode(obj *C_AMFObject, pBuffer *byte, nSize, bDecodeName int32) int
|
|||
nOriginalSize := nSize
|
||||
var bError int32
|
||||
|
||||
obj.o_num = 0
|
||||
obj.o_props = nil
|
||||
|
||||
obj.o_props = obj.o_props[:0]
|
||||
for nSize > 0 {
|
||||
var prop C_AMFObjectProperty
|
||||
var nRes int32
|
||||
|
@ -705,7 +699,7 @@ func C_AMF_Decode(obj *C_AMFObject, pBuffer *byte, nSize, bDecodeName int32) int
|
|||
break
|
||||
}
|
||||
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), int(nRes)))
|
||||
C_AMF_AddProp(obj, &prop)
|
||||
obj.o_props = append(obj.o_props, prop)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -716,36 +710,17 @@ func C_AMF_Decode(obj *C_AMFObject, pBuffer *byte, nSize, bDecodeName int32) int
|
|||
return nOriginalSize - nSize
|
||||
}
|
||||
|
||||
// void AMF_AddProp(AMFObject* obj, const AMFObjectProperty* prop);
|
||||
// amf.c + 1234
|
||||
func C_AMF_AddProp(obj *C_AMFObject, prop *C_AMFObjectProperty) {
|
||||
if (obj.o_num & 0x0f) == 0 {
|
||||
//obj.o_props = (*C_AMFObjectProperty)(realloc(unsafe.Pointer(obj.o_props),
|
||||
//uint32(int(obj.o_num+16)*int(unsafe.Sizeof(*obj.o_props)))))
|
||||
obj.o_props = (*C_AMFObjectProperty)(C.realloc(unsafe.Pointer(obj.o_props),
|
||||
C.size_t(int(obj.o_num+16)*int(unsafe.Sizeof(*obj.o_props)))))
|
||||
}
|
||||
memmove(unsafe.Pointer(&(*(*C_AMFObjectProperty)(incPtr(
|
||||
unsafe.Pointer(obj.o_props), int(obj.o_num), int(unsafe.Sizeof(*obj.o_props)))))),
|
||||
unsafe.Pointer(prop), unsafe.Sizeof(*obj.o_props))
|
||||
obj.o_num++
|
||||
}
|
||||
|
||||
// AMFObjectProperty* AMF_GetProp(AMFObject *obj, const AVal* name, int nIndex);
|
||||
// amf.c + 1249
|
||||
func C_AMF_GetProp(obj *C_AMFObject, name string, nIndex int32) *C_AMFObjectProperty {
|
||||
if nIndex >= 0 {
|
||||
if nIndex < obj.o_num {
|
||||
return &(*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props),
|
||||
int(nIndex), int(unsafe.Sizeof(*obj.o_props)))))
|
||||
func C_AMF_GetProp(obj *C_AMFObject, name string, idx int32) *C_AMFObjectProperty {
|
||||
if idx >= 0 {
|
||||
if idx < int32(len(obj.o_props)) {
|
||||
return &obj.o_props[idx]
|
||||
}
|
||||
} else {
|
||||
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)))))
|
||||
for i, p := range obj.o_props {
|
||||
if p.p_name == name {
|
||||
return &obj.o_props[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -755,14 +730,10 @@ func C_AMF_GetProp(obj *C_AMFObject, name string, nIndex int32) *C_AMFObjectProp
|
|||
// void AMF_Reset(AMFObject* obj);
|
||||
// amf.c +1282
|
||||
func C_AMF_Reset(obj *C_AMFObject) {
|
||||
var n int32
|
||||
for n = 0; n < obj.o_num; n++ {
|
||||
C_AMFProp_Reset(&(*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props),
|
||||
int(n), int(unsafe.Sizeof(*obj.o_props))))))
|
||||
for i := range obj.o_props {
|
||||
C_AMFProp_Reset(&obj.o_props[i])
|
||||
}
|
||||
//C.free(unsafe.Pointer(obj.o_props))
|
||||
obj.o_props = nil
|
||||
obj.o_num = 0
|
||||
obj.o_props = obj.o_props[:0]
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -60,8 +60,7 @@ type C_AMFDataType int32
|
|||
// typedef struct AMF_Object
|
||||
// amf.h +67
|
||||
type C_AMFObject struct {
|
||||
o_num int32
|
||||
o_props *C_AMFObjectProperty
|
||||
o_props []C_AMFObjectProperty
|
||||
}
|
||||
|
||||
// typedef struct P_vu
|
||||
|
|
|
@ -770,17 +770,12 @@ func C_SendConnectPacket(r *C_RTMP, cp *C_RTMPPacket) (ok bool) {
|
|||
}
|
||||
}
|
||||
|
||||
if r.Link.extras.o_num != 0 {
|
||||
for i := 0; i < int(r.Link.extras.o_num); i++ {
|
||||
enc = C_AMF_PropEncode((*C_AMFObjectProperty)(incPtr(unsafe.Pointer(
|
||||
&r.Link.extras.o_props), int(unsafe.Sizeof(r.Link.extras.o_props)), i)),
|
||||
enc, pend)
|
||||
|
||||
for i := range r.Link.extras.o_props {
|
||||
enc = C_AMF_PropEncode(&r.Link.extras.o_props[i], enc, pend)
|
||||
if enc == nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
packet.m_nBodySize = uint32(uintptr(decBytePtr(unsafe.Pointer(enc),
|
||||
int(uintptr(unsafe.Pointer(packet.m_body))))))
|
||||
|
|
Loading…
Reference in New Issue