From c4800034a60f59f3e34a3d82239d1335c3fb3b60 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Thu, 6 Sep 2018 16:10:15 +0930 Subject: [PATCH] rtmp: remove C_AVal from P_vu --- rtmp/amf.go | 14 +++++------- rtmp/amf_headers.go | 2 +- rtmp/rtmp.go | 55 +++++++++++++++++++++++---------------------- 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/rtmp/amf.go b/rtmp/amf.go index eb363535..72af2f80 100644 --- a/rtmp/amf.go +++ b/rtmp/amf.go @@ -308,12 +308,11 @@ func C_AMFProp_GetNumber(prop *C_AMFObjectProperty) float64 { // void AMFProp_GetString(AMFObjectProperty* prop, AVal* str); // amf.c +341 -func C_AMFProp_GetString(prop *C_AMFObjectProperty, str *C_AVal) { +func C_AMFProp_GetString(prop *C_AMFObjectProperty) string { if prop.p_type == AMF_STRING { - *str = prop.p_vu.p_aval - } else { - *str = AV_empty + return prop.p_vu.p_aval } + return "" } // void AMFProp_GetObject(AMFObjectProperty *prop, AMFObject *obj); @@ -355,7 +354,7 @@ func C_AMF_PropEncode(p *C_AMFObjectProperty, pBuffer *byte, pBufEnd *byte) *byt case AMF_BOOLEAN: pBuffer = C_AMF_EncodeBoolean(pBuffer, pBufEnd, p.p_vu.p_number != 0) case AMF_STRING: - pBuffer = C_AMF_EncodeString(pBuffer, pBufEnd, CAV(&p.p_vu.p_aval)) + 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)) { @@ -510,7 +509,7 @@ func C_AMFProp_Decode(prop *C_AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa if int64(nSize) < int64(nStringSize)+2 { return -1 } - prop.p_vu.p_aval = AVC(C_AMF_DecodeString(pBuffer)) + prop.p_vu.p_aval = C_AMF_DecodeString(pBuffer) nSize -= int32(2 + nStringSize) case AMF_OBJECT: @@ -593,8 +592,7 @@ func C_AMFProp_Reset(prop *C_AMFObjectProperty) { prop.p_type == AMF_STRICT_ARRAY { C_AMF_Reset(&prop.p_vu.p_object) } else { - prop.p_vu.p_aval.av_len = 0 - prop.p_vu.p_aval.av_val = nil + prop.p_vu.p_aval = "" } prop.p_type = AMF_INVALID } diff --git a/rtmp/amf_headers.go b/rtmp/amf_headers.go index 27eb90f1..6827c29e 100644 --- a/rtmp/amf_headers.go +++ b/rtmp/amf_headers.go @@ -107,7 +107,7 @@ type C_AMFObject struct { // amf.h +73 type P_vu struct { p_number float64 - p_aval C_AVal + p_aval string p_object C_AMFObject } diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index deb3d1e5..f7214f99 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -1155,7 +1155,6 @@ func C_AV_queue(vals **C_RTMP_METHOD, num *int32, av string, txn int32) { // rtmp.c +2912 func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) (ok bool) { var obj C_AMFObject - var method C_AVal var txn float64 var nRes int32 @@ -1175,13 +1174,13 @@ 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) - 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))) // TODO use new logger here // RTMP_Log(RTMP_LOGDEBUG, "%s, server invoking <%s>", __FUNCTION__, method.av_val); - + avmethod := AVC(method) switch { - case C_AVMATCH(&method, &av__result) != 0: + case C_AVMATCH(&avmethod, &av__result) != 0: { var methodInvoked C_AVal var i int32 @@ -1236,47 +1235,49 @@ func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) (ok bool) { } //C.free(unsafe.Pointer(methodInvoked.av_val)) } - case C_AVMATCH(&method, &av_onBWDone) != 0: + case C_AVMATCH(&avmethod, &av_onBWDone) != 0: if r.m_nBWCheckCounter == 0 { C_SendCheckBW(r) } - case C_AVMATCH(&method, &av_onFCUnsubscribe) != 0 || C_AVMATCH(&method, &av_onFCSubscribe) != 0: + case C_AVMATCH(&avmethod, &av_onFCUnsubscribe) != 0 || C_AVMATCH(&avmethod, &av_onFCSubscribe) != 0: panic("Unsupported method av_onFCUnsubscribe/av_onFCSubscribe") - case C_AVMATCH(&method, &av_ping) != 0: + case C_AVMATCH(&avmethod, &av_ping) != 0: panic("Unsupported method av_ping") - case C_AVMATCH(&method, &av__onbwcheck) != 0: + case C_AVMATCH(&avmethod, &av__onbwcheck) != 0: panic("Unsupported method av_onbwcheck") - case C_AVMATCH(&method, &av__onbwdone) != 0: + case C_AVMATCH(&avmethod, &av__onbwdone) != 0: panic("Unsupported method av_onbwdone") - case C_AVMATCH(&method, &av_close) != 0: + case C_AVMATCH(&avmethod, &av_close) != 0: panic("Unsupported method av_close") - case C_AVMATCH(&method, &av_onStatus) != 0: + case C_AVMATCH(&avmethod, &av_onStatus) != 0: var obj2 C_AMFObject - var code, level C_AVal C_AMFProp_GetObject(C_AMF_GetProp(&obj, nil, 3), &obj2) - C_AMFProp_GetString(C_AMF_GetProp(&obj2, &av_code, -1), &code) - C_AMFProp_GetString(C_AMF_GetProp(&obj2, &av_level, -1), &level) + code := C_AMFProp_GetString(C_AMF_GetProp(&obj2, &av_code, -1)) + + level := C_AMFProp_GetString(C_AMF_GetProp(&obj2, &av_level, -1)) // Not used. + _ = level // TODO use new logger // RTMP_Log(RTMP_LOGDEBUG, "%s, onStatus: %s", __FUNCTION__, code.av_val); + avcode := AVC(code) switch { - case C_AVMATCH(&code, &av_NetStream_Failed) != 0 || - C_AVMATCH(&code, &av_NetStream_Play_Failed) != 0 || - C_AVMATCH(&code, &av_NetStream_Play_StreamNotFound) != 0 || - C_AVMATCH(&code, &av_NetConnection_Connect_InvalidApp) != 0: + case C_AVMATCH(&avcode, &av_NetStream_Failed) != 0 || + C_AVMATCH(&avcode, &av_NetStream_Play_Failed) != 0 || + C_AVMATCH(&avcode, &av_NetStream_Play_StreamNotFound) != 0 || + C_AVMATCH(&avcode, &av_NetConnection_Connect_InvalidApp) != 0: panic("Unsupported method av_NetStream/av_NetStream_Play_Failed/av_netSTream_Play_StreamNotFound/av_netConnection_Connect_invalidApp") - case C_AVMATCH(&code, &av_NetStream_Play_Start) != 0 || - C_AVMATCH(&code, &av_NetStream_Play_PublishNotify) != 0: + case C_AVMATCH(&avcode, &av_NetStream_Play_Start) != 0 || + C_AVMATCH(&avcode, &av_NetStream_Play_PublishNotify) != 0: panic("Unsupported method av_NetStream_Play_Start/av_NetStream_Play_PublishNotify") - case C_AVMATCH(&code, &av_NetStream_Publish_Start) != 0: + case C_AVMATCH(&avcode, &av_NetStream_Publish_Start) != 0: var i int32 r.m_bPlaying = true @@ -1288,19 +1289,19 @@ func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) (ok bool) { } } - case C_AVMATCH(&code, &av_NetStream_Play_Complete) != 0 || - C_AVMATCH(&code, &av_NetStream_Play_Stop) != 0 || - C_AVMATCH(&code, &av_NetStream_Play_UnpublishNotify) != 0: + case C_AVMATCH(&avcode, &av_NetStream_Play_Complete) != 0 || + C_AVMATCH(&avcode, &av_NetStream_Play_Stop) != 0 || + C_AVMATCH(&avcode, &av_NetStream_Play_UnpublishNotify) != 0: panic("Unsupported method av_NetStream_Play_Complete/av_NetStream_Play_Stop/av_NetStream_Play_UnpublishNotify") - case C_AVMATCH(&code, &av_NetStream_Seek_Notify) != 0: + case C_AVMATCH(&avcode, &av_NetStream_Seek_Notify) != 0: panic("Unsupported method av_netStream_Seek_Notify") - case C_AVMATCH(&code, &av_NetStream_Pause_Notify) != 0: + case C_AVMATCH(&avcode, &av_NetStream_Pause_Notify) != 0: panic("Unsupported method av_NetStream_Pause_Notify") } - case C_AVMATCH(&method, &av_playlist_ready) != 0: + case C_AVMATCH(&avmethod, &av_playlist_ready) != 0: panic("Unsupported method av_playlist_ready") default: