rtmp: make string decoding a returning function

This commit is contained in:
Dan Kortschak 2018-09-06 12:46:07 +09:30
parent a626a740ea
commit 019a1f1c90
2 changed files with 13 additions and 16 deletions

View File

@ -91,26 +91,24 @@ func C_AMF_DecodeInt32(data *byte) uint32 {
// void AMF_DecodeString(const char* data, C_AVal* bv);
// amf.c +68
func C_AMF_DecodeString(data *byte, bv *C_AVal) {
dataPtr := unsafe.Pointer(data)
//bv.av_len = int32(C.AMF_DecodeInt16((*byte)(dataPtr)))
bv.av_len = int32(C_AMF_DecodeInt16((*byte)(dataPtr)))
if bv.av_len > 0 {
bv.av_val = (*byte)(incBytePtr(dataPtr, 2))
} else {
bv.av_val = nil
func C_AMF_DecodeString(data *byte) C_AVal {
var bv C_AVal
bv.av_len = int32(C_AMF_DecodeInt16(data))
if bv.av_len != 0 {
bv.av_val = (*byte)(incBytePtr(unsafe.Pointer(data), 2))
}
return bv
}
// void AMF_DecodeLongString(const char *data, AVal *bv);
// amf.c +75
func C_AMF_DecodeLongString(data *byte, bv *C_AVal) {
func C_AMF_DecodeLongString(data *byte) C_AVal {
var bv C_AVal
bv.av_len = int32(C_AMF_DecodeInt32(data))
if bv.av_len > 0 {
if bv.av_len != 0 {
bv.av_val = (*byte)(incBytePtr(unsafe.Pointer(data), 4))
} else {
bv.av_val = nil
}
return bv
}
// double AMF_DecodeNumber(const char* data);
@ -491,7 +489,7 @@ func C_AMFProp_Decode(prop *C_AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa
return -1
}
C_AMF_DecodeString(pBuffer, &prop.p_name)
prop.p_name = C_AMF_DecodeString(pBuffer)
nSize -= int32(2 + nNameSize)
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), int(2+nNameSize)))
}
@ -522,7 +520,7 @@ func C_AMFProp_Decode(prop *C_AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa
if int64(nSize) < int64(nStringSize)+2 {
return -1
}
C_AMF_DecodeString(pBuffer, &prop.p_vu.p_aval)
prop.p_vu.p_aval = C_AMF_DecodeString(pBuffer)
nSize -= int32(2 + nStringSize)
case AMF_OBJECT:

View File

@ -1858,10 +1858,9 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
// TODO: port the const
if packet.m_packetType == RTMP_PACKET_TYPE_INVOKE {
// TODO: port C_AVal
var method C_AVal
var ptr unsafe.Pointer
ptr = incBytePtr(unsafe.Pointer(packet.m_body), 1)
C_AMF_DecodeString((*byte)(ptr), &method)
method := C_AMF_DecodeString((*byte)(ptr))
if debugMode {
log.Printf("Invoking %v", method.av_val)