retmp: simplify big switch

This commit is contained in:
Dan Kortschak 2018-09-06 18:03:55 +09:30
parent 97127030b3
commit 569cc100fa
1 changed files with 70 additions and 78 deletions

View File

@ -1178,84 +1178,82 @@ func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) (ok bool) {
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)
switch {
case C_AVMATCH(&avmethod, &av__result) != 0:
{
var methodInvoked C_AVal
var i int32
for i = 0; i < int32(r.m_numCalls); i++ {
if float64((*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i),
int(unsafe.Sizeof(*r.m_methodCalls))))).num) == txn {
methodInvoked = (*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls),
int(i), int(unsafe.Sizeof(*r.m_methodCalls))))).name
C_AV_erase(r.m_methodCalls, (*int32)(&r.m_numCalls), int32(i), 0)
break
}
switch method {
case CAV(&av__result):
var methodInvoked C_AVal
for i := int32(0); i < r.m_numCalls; i++ {
if float64((*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i),
int(unsafe.Sizeof(*r.m_methodCalls))))).num) == txn {
methodInvoked = (*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls),
int(i), int(unsafe.Sizeof(*r.m_methodCalls))))).name
C_AV_erase(r.m_methodCalls, (*int32)(&r.m_numCalls), int32(i), 0)
break
}
if methodInvoked.av_val == nil {
// TODO use new logger here
//RTMP_Log(RTMP_LOGDEBUG, "%s, received result id %f without matching request",
//__FUNCTION__, txn);
goto leave
}
// TODO use new logger here
//RTMP_Log(RTMP_LOGDEBUG, "%s, received result for method call <%s>", __FUNCTION__,
//methodInvoked.av_val);
switch {
case C_AVMATCH(&methodInvoked, &av_connect) != 0:
if r.Link.token.av_len != 0 {
panic("No support for link token")
}
if (r.Link.protocol & RTMP_FEATURE_WRITE) != 0 {
C_SendReleaseStream(r)
C_SendFCPublish(r)
} else {
panic("Link protocol has no RTMP_FEATURE_WRITE")
}
C_RTMP_SendCreateStream(r)
if (r.Link.protocol & RTMP_FEATURE_WRITE) == 0 {
panic("Link protocol has no RTMP_FEATURE_WRITE")
}
case C_AVMATCH(&methodInvoked, &av_createStream) != 0:
r.m_stream_id = int32(C_AMFProp_GetNumber(C_AMF_GetProp(&obj, "", 3)))
if (r.Link.protocol & RTMP_FEATURE_WRITE) != 0 {
C_SendPublish(r)
} else {
panic("Link protocol has no RTMP_FEATURE_WRITE")
}
case C_AVMATCH(&methodInvoked, &av_play) != 0 ||
C_AVMATCH(&methodInvoked, &av_publish) != 0:
panic("Unsupported method av_play/av_publish")
}
//C.free(unsafe.Pointer(methodInvoked.av_val))
}
case C_AVMATCH(&avmethod, &av_onBWDone) != 0:
if methodInvoked.av_val == nil {
// TODO use new logger here
//RTMP_Log(RTMP_LOGDEBUG, "%s, received result id %f without matching request",
//__FUNCTION__, txn);
goto leave
}
// TODO use new logger here
//RTMP_Log(RTMP_LOGDEBUG, "%s, received result for method call <%s>", __FUNCTION__,
//methodInvoked.av_val);
switch {
case C_AVMATCH(&methodInvoked, &av_connect) != 0:
if r.Link.token.av_len != 0 {
panic("No support for link token")
}
if (r.Link.protocol & RTMP_FEATURE_WRITE) != 0 {
C_SendReleaseStream(r)
C_SendFCPublish(r)
} else {
panic("Link protocol has no RTMP_FEATURE_WRITE")
}
C_RTMP_SendCreateStream(r)
if (r.Link.protocol & RTMP_FEATURE_WRITE) == 0 {
panic("Link protocol has no RTMP_FEATURE_WRITE")
}
case C_AVMATCH(&methodInvoked, &av_createStream) != 0:
r.m_stream_id = int32(C_AMFProp_GetNumber(C_AMF_GetProp(&obj, "", 3)))
if r.Link.protocol&RTMP_FEATURE_WRITE != 0 {
C_SendPublish(r)
} else {
panic("Link protocol has no RTMP_FEATURE_WRITE")
}
case C_AVMATCH(&methodInvoked, &av_play) != 0 ||
C_AVMATCH(&methodInvoked, &av_publish) != 0:
panic("Unsupported method av_play/av_publish")
}
//C.free(unsafe.Pointer(methodInvoked.av_val))
case CAV(&av_onBWDone):
if r.m_nBWCheckCounter == 0 {
C_SendCheckBW(r)
}
case C_AVMATCH(&avmethod, &av_onFCUnsubscribe) != 0 || C_AVMATCH(&avmethod, &av_onFCSubscribe) != 0:
case CAV(&av_onFCUnsubscribe), CAV(&av_onFCSubscribe):
panic("Unsupported method av_onFCUnsubscribe/av_onFCSubscribe")
case C_AVMATCH(&avmethod, &av_ping) != 0:
case CAV(&av_ping):
panic("Unsupported method av_ping")
case C_AVMATCH(&avmethod, &av__onbwcheck) != 0:
case CAV(&av__onbwcheck):
panic("Unsupported method av_onbwcheck")
case C_AVMATCH(&avmethod, &av__onbwdone) != 0:
case CAV(&av__onbwdone):
panic("Unsupported method av_onbwdone")
case C_AVMATCH(&avmethod, &av_close) != 0:
case CAV(&av_close):
panic("Unsupported method av_close")
case C_AVMATCH(&avmethod, &av_onStatus) != 0:
case CAV(&av_onStatus):
var obj2 C_AMFObject
C_AMFProp_GetObject(C_AMF_GetProp(&obj, "", 3), &obj2)
code := C_AMFProp_GetString(C_AMF_GetProp(&obj2, CAV(&av_code), -1))
@ -1265,20 +1263,16 @@ func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) (ok bool) {
// TODO use new logger
// RTMP_Log(RTMP_LOGDEBUG, "%s, onStatus: %s", __FUNCTION__, code.av_val);
avcode := AVC(code)
switch {
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:
switch code {
case CAV(&av_NetStream_Failed), CAV(&av_NetStream_Play_Failed),
CAV(&av_NetStream_Play_StreamNotFound), CAV(&av_NetConnection_Connect_InvalidApp):
panic("Unsupported method av_NetStream/av_NetStream_Play_Failed/av_netSTream_Play_StreamNotFound/av_netConnection_Connect_invalidApp")
case C_AVMATCH(&avcode, &av_NetStream_Play_Start) != 0 ||
C_AVMATCH(&avcode, &av_NetStream_Play_PublishNotify) != 0:
case CAV(&av_NetStream_Play_Start), CAV(&av_NetStream_Play_PublishNotify):
panic("Unsupported method av_NetStream_Play_Start/av_NetStream_Play_PublishNotify")
case C_AVMATCH(&avcode, &av_NetStream_Publish_Start) != 0:
case CAV(&av_NetStream_Publish_Start):
var i int32
r.m_bPlaying = true
for i = 0; i < int32(r.m_numCalls); i++ {
@ -1289,19 +1283,17 @@ func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) (ok bool) {
}
}
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:
case CAV(&av_NetStream_Play_Complete), CAV(&av_NetStream_Play_Stop), CAV(&av_NetStream_Play_UnpublishNotify):
panic("Unsupported method av_NetStream_Play_Complete/av_NetStream_Play_Stop/av_NetStream_Play_UnpublishNotify")
case C_AVMATCH(&avcode, &av_NetStream_Seek_Notify) != 0:
case CAV(&av_NetStream_Seek_Notify):
panic("Unsupported method av_netStream_Seek_Notify")
case C_AVMATCH(&avcode, &av_NetStream_Pause_Notify) != 0:
case CAV(&av_NetStream_Pause_Notify):
panic("Unsupported method av_NetStream_Pause_Notify")
}
case C_AVMATCH(&avmethod, &av_playlist_ready) != 0:
case CAV(&av_playlist_ready):
panic("Unsupported method av_playlist_ready")
default: