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 = AMF_OBJECT
|
||||||
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1))
|
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1))
|
||||||
|
|
||||||
for i := 0; i < int(obj.o_num); i++ {
|
for i := 0; i < len(obj.o_props); i++ {
|
||||||
res := C_AMF_PropEncode((*C_AMFObjectProperty)(incPtr(unsafe.Pointer(
|
res := C_AMF_PropEncode(&obj.o_props[i], pBuffer, pBufEnd)
|
||||||
obj.o_props), i, int(unsafe.Sizeof(*obj.o_props)))), pBuffer, pBufEnd)
|
|
||||||
if res == nil {
|
if res == nil {
|
||||||
log.Println("C_AMF_Encode: failed to encode property in index")
|
log.Println("C_AMF_Encode: failed to encode property in index")
|
||||||
break
|
break
|
||||||
|
@ -583,11 +582,10 @@ func C_AMF_EncodeEcmaArray(obj *C_AMFObject, pBuffer *byte, pBufEnd *byte) *byte
|
||||||
*pBuffer = AMF_ECMA_ARRAY
|
*pBuffer = AMF_ECMA_ARRAY
|
||||||
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1))
|
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++ {
|
for i := 0; i < len(obj.o_props); i++ {
|
||||||
res := C_AMF_PropEncode((*C_AMFObjectProperty)(incPtr(unsafe.Pointer(
|
res := C_AMF_PropEncode(&obj.o_props[i], pBuffer, pBufEnd)
|
||||||
obj.o_props), i, int(unsafe.Sizeof(*obj.o_props)))), pBuffer, pBufEnd)
|
|
||||||
if res == nil {
|
if res == nil {
|
||||||
log.Println("C_AMF_EncodeEcmaArray: failed to encode property!")
|
log.Println("C_AMF_EncodeEcmaArray: failed to encode property!")
|
||||||
break
|
break
|
||||||
|
@ -615,13 +613,12 @@ func C_AMF_EncodeArray(obj *C_AMFObject, pBuffer *byte, pBufEnd *byte) *byte {
|
||||||
*pBuffer = AMF_STRICT_ARRAY
|
*pBuffer = AMF_STRICT_ARRAY
|
||||||
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1))
|
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++ {
|
for i := 0; i < len(obj.o_props); i++ {
|
||||||
res := C_AMF_PropEncode((*C_AMFObjectProperty)(incPtr(unsafe.Pointer(
|
res := C_AMF_PropEncode(&obj.o_props[i], pBuffer, pBufEnd)
|
||||||
obj.o_props), i, int(unsafe.Sizeof(*obj.o_props)))), pBuffer, pBufEnd)
|
|
||||||
if res == nil {
|
if res == nil {
|
||||||
log.Println("C_AMF_EncodeEcmaArray: failed to encode property!")
|
log.Println("C_AMF_EncodeArray: failed to encode property!")
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
pBuffer = res
|
pBuffer = res
|
||||||
|
@ -637,8 +634,7 @@ func C_AMF_DecodeArray(obj *C_AMFObject, pBuffer *byte, nSize, nArrayLen, bDecod
|
||||||
nOriginalSize := nSize
|
nOriginalSize := nSize
|
||||||
var bError int32 = 0
|
var bError int32 = 0
|
||||||
|
|
||||||
obj.o_num = 0
|
obj.o_props = obj.o_props[:0]
|
||||||
obj.o_props = nil
|
|
||||||
for nArrayLen > 0 {
|
for nArrayLen > 0 {
|
||||||
var prop C_AMFObjectProperty
|
var prop C_AMFObjectProperty
|
||||||
var nRes int32
|
var nRes int32
|
||||||
|
@ -655,7 +651,7 @@ func C_AMF_DecodeArray(obj *C_AMFObject, pBuffer *byte, nSize, nArrayLen, bDecod
|
||||||
} else {
|
} else {
|
||||||
nSize -= nRes
|
nSize -= nRes
|
||||||
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), int(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 {
|
if bError != 0 {
|
||||||
|
@ -671,9 +667,7 @@ func C_AMF_Decode(obj *C_AMFObject, pBuffer *byte, nSize, bDecodeName int32) int
|
||||||
nOriginalSize := nSize
|
nOriginalSize := nSize
|
||||||
var bError int32
|
var bError int32
|
||||||
|
|
||||||
obj.o_num = 0
|
obj.o_props = obj.o_props[:0]
|
||||||
obj.o_props = nil
|
|
||||||
|
|
||||||
for nSize > 0 {
|
for nSize > 0 {
|
||||||
var prop C_AMFObjectProperty
|
var prop C_AMFObjectProperty
|
||||||
var nRes int32
|
var nRes int32
|
||||||
|
@ -705,7 +699,7 @@ func C_AMF_Decode(obj *C_AMFObject, pBuffer *byte, nSize, bDecodeName int32) int
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), int(nRes)))
|
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
|
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);
|
// AMFObjectProperty* AMF_GetProp(AMFObject *obj, const AVal* name, int nIndex);
|
||||||
// amf.c + 1249
|
// amf.c + 1249
|
||||||
func C_AMF_GetProp(obj *C_AMFObject, name string, nIndex int32) *C_AMFObjectProperty {
|
func C_AMF_GetProp(obj *C_AMFObject, name string, idx int32) *C_AMFObjectProperty {
|
||||||
if nIndex >= 0 {
|
if idx >= 0 {
|
||||||
if nIndex < obj.o_num {
|
if idx < int32(len(obj.o_props)) {
|
||||||
return &(*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props),
|
return &obj.o_props[idx]
|
||||||
int(nIndex), int(unsafe.Sizeof(*obj.o_props)))))
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for n := int32(0); n < obj.o_num; n++ {
|
for i, p := range obj.o_props {
|
||||||
p_name := (*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props),
|
if p.p_name == name {
|
||||||
int(n), int(unsafe.Sizeof(*obj.o_props))))).p_name
|
return &obj.o_props[i]
|
||||||
if p_name == name {
|
|
||||||
return &(*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props),
|
|
||||||
int(n), int(unsafe.Sizeof(*obj.o_props)))))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -755,14 +730,10 @@ func C_AMF_GetProp(obj *C_AMFObject, name string, nIndex int32) *C_AMFObjectProp
|
||||||
// void AMF_Reset(AMFObject* obj);
|
// void AMF_Reset(AMFObject* obj);
|
||||||
// amf.c +1282
|
// amf.c +1282
|
||||||
func C_AMF_Reset(obj *C_AMFObject) {
|
func C_AMF_Reset(obj *C_AMFObject) {
|
||||||
var n int32
|
for i := range obj.o_props {
|
||||||
for n = 0; n < obj.o_num; n++ {
|
C_AMFProp_Reset(&obj.o_props[i])
|
||||||
C_AMFProp_Reset(&(*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props),
|
|
||||||
int(n), int(unsafe.Sizeof(*obj.o_props))))))
|
|
||||||
}
|
}
|
||||||
//C.free(unsafe.Pointer(obj.o_props))
|
obj.o_props = obj.o_props[:0]
|
||||||
obj.o_props = nil
|
|
||||||
obj.o_num = 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -60,8 +60,7 @@ type C_AMFDataType int32
|
||||||
// typedef struct AMF_Object
|
// typedef struct AMF_Object
|
||||||
// amf.h +67
|
// amf.h +67
|
||||||
type C_AMFObject struct {
|
type C_AMFObject struct {
|
||||||
o_num int32
|
o_props []C_AMFObjectProperty
|
||||||
o_props *C_AMFObjectProperty
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// typedef struct P_vu
|
// typedef struct P_vu
|
||||||
|
|
13
rtmp/rtmp.go
13
rtmp/rtmp.go
|
@ -770,15 +770,10 @@ func C_SendConnectPacket(r *C_RTMP, cp *C_RTMPPacket) (ok bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Link.extras.o_num != 0 {
|
for i := range r.Link.extras.o_props {
|
||||||
for i := 0; i < int(r.Link.extras.o_num); i++ {
|
enc = C_AMF_PropEncode(&r.Link.extras.o_props[i], enc, pend)
|
||||||
enc = C_AMF_PropEncode((*C_AMFObjectProperty)(incPtr(unsafe.Pointer(
|
if enc == nil {
|
||||||
&r.Link.extras.o_props), int(unsafe.Sizeof(r.Link.extras.o_props)), i)),
|
return false
|
||||||
enc, pend)
|
|
||||||
|
|
||||||
if enc == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue