From 73e2c9977a933393904a896f00ef1113f3d2b798 Mon Sep 17 00:00:00 2001 From: saxon Date: Tue, 14 Aug 2018 16:36:42 +0930 Subject: [PATCH] Identified functions that need porting using todo comments above HandleInvoke in rtmp.go at +1911 onwards --- rtmp/rtmp.go | 137 ++++++++++++++++++++++++++++----------------------- 1 file changed, 74 insertions(+), 63 deletions(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index 1af1c9fc..871a15a8 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -1908,6 +1908,28 @@ func C_HandleClientBW(r *C.RTMP, packet *C.RTMPPacket) { // int HandleInvoke(RTMP* r, const char* body, unsigned int nBodySize); // rtmp.c +2912 +// TODO port AMF_Dump +// TODO port AMFPRop_GetString +// TODO port AMF_GetProp +// TODO port AMFProp_GetNumber +// TODO port RTMP_FindFirstMatchingProperty +// TODO port DecodeTEA +// TODO port SendSecureTokenResponse +// TODO port SendRealseStream +// TODO port SendFCPublish +// TODO port RTMP_SendServerBW +// TODO port RTMP_SendCtrl +// TODO port RTMP_SendCreateStream +// TODO port SendUsherToken +// TODO port SendFCSubscribe +// TODO port SendPublish +// TODO port SendPlaylist +// TODO port SendPlay +// TODO port SendCheckBw +// TODO port SendPong +// TODO port SendCheckBWResult +// TODO port AMFProp_GetObject +// TODO port AV_erase func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 { var obj C.AMFObject var method C.AVal @@ -1929,12 +1951,9 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 { //RTMP_Log(RTMP_LOGERROR, "%s, error decoding invoke packet", __FUNCTION__); return 0 } - // TODO port AMF_Dump + C.AMF_Dump(&obj); - // TODO port AMFPRop_GetString - // TODO port AMF_GetProp C.AMFProp_GetString(C.AMF_GetProp(&obj, NULL, 0), &method); - // TODO port AMFProp_GetNumber txn = C.AMFProp_GetNumber(AMF_GetProp(&obj, NULL, 1)); // TODO use new logger here // RTMP_Log(RTMP_LOGDEBUG, "%s, server invoking <%s>", __FUNCTION__, method.av_val); @@ -1946,7 +1965,6 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 { for i=0; i < r.m_numCalls; i++ { if r.m_methodCalls[i].num == (int)txn { methodInvoked = r.m_methodCalls[i].name; - // TODO port AV_erase C.AV_erase(r.m_methodCalls, &r.m_numCalls, i, FALSE); break; } @@ -1964,147 +1982,140 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 { case C_AVMATCH(&methodInvoked, &av_connect): if r.Link.token.av_len != 0 { var p C.AMFObjectProperty - - // TODO port this func if C.RTMP_FindFirstMatchingProperty(&obj, &av_secureToken, &p){ - // TODO port this func C.DecodeTEA(&r.Link.token, &p.p_vu.p_aval); - // TODO port this func C.SendSecureTokenResponse(r, &p.p_vu.p_aval); } } if (r.Link.protocol & RTMP_FEATURE_WRITE){ - // TODO port this func C.SendReleaseStream(r); - // TODO port this func C.SendFCPublish(r); }else{ - // TODO port this func C.RTMP_SendServerBW(r); - // TODO port this func C.RTMP_SendCtrl(r, 3, 0, 300); } - // TODO port this func C.RTMP_SendCreateStream(r); if (r.Link.protocol & RTMP_FEATURE_WRITE) == 0 { /* Authenticate on Justin.tv legacy servers before sending FCSubscribe */ if r.Link.usherToken.av_len != 0 { - // TODO port this func C.SendUsherToken(r, &r.Link.usherToken); } /* Send the FCSubscribe if live stream or if subscribepath is set */ switch{ case r.Link.subscribepath.av_len: - // TODO port C.SendFCSubscribe(r, &r.Link.subscribepath); case r.Link.lFlags & RTMP_LF_LIV: - SendFCSubscribe(r, &r.Link.playpath); + C.SendFCSubscribe(r, &r.Link.playpath); } } - case AVMATCH(&methodInvoked, &av_createStream): + case C_AVMATCH(&methodInvoked, &av_createStream): r.m_stream_id = (int)AMFProp_GetNumber(AMF_GetProp(&obj, NULL, 3)); if (r.Link.protocol & RTMP_FEATURE_WRITE){ - SendPublish(r); + C.SendPublish(r); } else { if (r.Link.lFlags & RTMP_LF_PLST){ - SendPlaylist(r); + C.SendPlaylist(r); } - SendPlay(r); - RTMP_SendCtrl(r, 3, r.m_stream_id, r.m_nBufferMS); + C.SendPlay(r); + C.RTMP_SendCtrl(r, 3, r.m_stream_id, r.m_nBufferMS); } - case AVMATCH(&methodInvoked, &av_play) || - AVMATCH(&methodInvoked, &av_publish): + case C_AVMATCH(&methodInvoked, &av_play) || + C_AVMATCH(&methodInvoked, &av_publish): r.m_bPlaying = TRUE; } free(methodInvoked.av_val); - case (AVMATCH(&method, &av_onBWDone)): + case (C_AVMATCH(&method, &av_onBWDone)): if (!r.m_nBWCheckCounter){ - SendCheckBW(r); + C.SendCheckBW(r); } - case AVMATCH(&method, &av_onFCSubscribe): + case C_AVMATCH(&method, &av_onFCSubscribe): /* SendOnFCSubscribe(); */ - case AVMATCH(&method, &av_onFCUnsubscribe): + case C_AVMATCH(&method, &av_onFCUnsubscribe): RTMP_Close(r); ret = 1; - case AVMATCH(&method, &av_ping): - SendPong(r, txn); - case AVMATCH(&method, &av__onbwcheck): - SendCheckBWResult(r, txn); - case AVMATCH(&method, &av__onbwdone): + case C_AVMATCH(&method, &av_ping): + C.SendPong(r, txn); + case C_AVMATCH(&method, &av__onbwcheck): + C.SendCheckBWResult(r, txn); + case C_AVMATCH(&method, &av__onbwdone): int i; for (i = 0; i < r.m_numCalls; i++){ - if (AVMATCH(&r.m_methodCalls[i].name, &av__checkbw)){ - AV_erase(r.m_methodCalls, &r.m_numCalls, i, TRUE); + if (C_AVMATCH(&r.m_methodCalls[i].name, &av__checkbw)){ + C.AV_erase(r.m_methodCalls, &r.m_numCalls, i, TRUE); break; } } - case AVMATCH(&method, &av_close): - RTMP_Log(RTMP_LOGERROR, "rtmp server requested close"); + case C_AVMATCH(&method, &av_close): + // TODO use new logger + //RTMP_Log(RTMP_LOGERROR, "rtmp server requested close"); RTMP_Close(r); - case AVMATCH(&method, &av_onStatus): - AMFObject obj2; - AVal code, level; - AMFProp_GetObject(AMF_GetProp(&obj, NULL, 3), &obj2); + case C_AVMATCH(&method, &av_onStatus): + var obj2 C.AMFObject + var code, level C.AVal + C.AMFProp_GetObject(AMF_GetProp(&obj, NULL, 3), &obj2); AMFProp_GetString(AMF_GetProp(&obj2, &av_code, -1), &code); AMFProp_GetString(AMF_GetProp(&obj2, &av_level, -1), &level); - RTMP_Log(RTMP_LOGDEBUG, "%s, onStatus: %s", __FUNCTION__, code.av_val); + // TODO use new logger + // RTMP_Log(RTMP_LOGDEBUG, "%s, onStatus: %s", __FUNCTION__, code.av_val); switch { - case AVMATCH(&code, &av_NetStream_Failed) - || AVMATCH(&code, &av_NetStream_Play_Failed) - || AVMATCH(&code, &av_NetStream_Play_StreamNotFound) - || AVMATCH(&code, &av_NetConnection_Connect_InvalidApp): + case C_AVMATCH(&code, &av_NetStream_Failed) + || C_AVMATCH(&code, &av_NetStream_Play_Failed) + || C_AVMATCH(&code, &av_NetStream_Play_StreamNotFound) + || C_AVMATCH(&code, &av_NetConnection_Connect_InvalidApp): r.m_stream_id = -1; RTMP_Close(r); - RTMP_Log(RTMP_LOGERROR, "Closing connection: %s", code.av_val); - case AVMATCH(&code, &av_NetStream_Play_Start) - || AVMATCH(&code, &av_NetStream_Play_PublishNotify): + // TODO use new logger + // RTMP_Log(RTMP_LOGERROR, "Closing connection: %s", code.av_val); + case C_AVMATCH(&code, &av_NetStream_Play_Start) + || C_AVMATCH(&code, &av_NetStream_Play_PublishNotify): int i; r.m_bPlaying = TRUE; for (i = 0; i < r.m_numCalls; i++){ - if (AVMATCH(&r.m_methodCalls[i].name, &av_play)){ - AV_erase(r.m_methodCalls, &r.m_numCalls, i, TRUE); + if (C_AVMATCH(&r.m_methodCalls[i].name, &av_play)){ + C.AV_erase(r.m_methodCalls, &r.m_numCalls, i, TRUE); break; } } - case AVMATCH(&code, &av_NetStream_Publish_Start): + case C_AVMATCH(&code, &av_NetStream_Publish_Start): int i; r.m_bPlaying = TRUE; for (i = 0; i < r.m_numCalls; i++){ - if (AVMATCH(&r.m_methodCalls[i].name, &av_publish)){ - AV_erase(r.m_methodCalls, &r.m_numCalls, i, TRUE); + if (C_AVMATCH(&r.m_methodCalls[i].name, &av_publish)){ + C.AV_erase(r.m_methodCalls, &r.m_numCalls, i, TRUE); break; } } - case AVMATCH(&code, &av_NetStream_Play_Complete) - || AVMATCH(&code, &av_NetStream_Play_Stop) - || AVMATCH(&code, &av_NetStream_Play_UnpublishNotify): + case C_AVMATCH(&code, &av_NetStream_Play_Complete) + || C_AVMATCH(&code, &av_NetStream_Play_Stop) + || C_AVMATCH(&code, &av_NetStream_Play_UnpublishNotify): RTMP_Close(r); ret = 1; - case AVMATCH(&code, &av_NetStream_Seek_Notify): + case C_AVMATCH(&code, &av_NetStream_Seek_Notify): r.m_read.flags &= ~RTMP_READ_SEEKING; - case AVMATCH(&code, &av_NetStream_Pause_Notify): + case C_AVMATCH(&code, &av_NetStream_Pause_Notify): if (r.m_pausing == 1 || r.m_pausing == 2){ RTMP_SendPause(r, FALSE, r.m_pauseStamp); r.m_pausing = 3; } } - case AVMATCH(&method, &av_playlist_ready): + case C_AVMATCH(&method, &av_playlist_ready): int i; for (i = 0; i < r.m_numCalls; i++){ - if (AVMATCH(&r.m_methodCalls[i].name, &av_set_playlist)){ - AV_erase(r.m_methodCalls, &r.m_numCalls, i, TRUE); + if (C_AVMATCH(&r.m_methodCalls[i].name, &av_set_playlist)){ + C.AV_erase(r.m_methodCalls, &r.m_numCalls, i, TRUE); break; } } default: } leave: - AMF_Reset(&obj); + C.AMF_Reset(&obj); return ret; } + // #define AVMATCH(a1,a2) // amf.h +63 func C_AVMATCH(a1, a2 C.AVal) int32 {