Simplified code (identified code that doesn't run in our use case - reducing no of funcs to port

This commit is contained in:
saxon 2018-08-14 22:51:25 +09:30
parent 4723a46c91
commit 9266fc79d7
1 changed files with 86 additions and 70 deletions

View File

@ -1941,27 +1941,16 @@ func C_HandleClientBW(r *C.RTMP, packet *C.RTMPPacket) {
// 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
// TODO port AMF_GetProp
// TODO port AMF_Decode
// TODO port AV_erase
// TODO port SendReleaseStream
// TODO port SendFCPublish
// TODO port RTMP_SendCreateStream
// TODO port SendPublish
// TODO port SendCheckBW
// TODO port AMF_Reset
func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 {
var obj C.AMFObject
var method C.AVal
@ -2001,6 +1990,7 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) 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 {
log.Println("1.1")
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, &r.m_numCalls, C.int(i), 0)
@ -2008,6 +1998,7 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 {
}
}
if methodInvoked.av_val == nil {
log.Println("1.2")
// TODO use new logger here
//RTMP_Log(RTMP_LOGDEBUG, "%s, received result id %f without matching request",
//__FUNCTION__, txn);
@ -2020,28 +2011,39 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 {
case C_AVMATCH(&methodInvoked, &av_connect) != 0:
{
log.Println("2")
/* NOTE This code doesn't run in our use case
TODO port this eventually
if r.Link.token.av_len != 0 {
log.Println("2.1")
var p C.AMFObjectProperty
if C.RTMP_FindFirstMatchingProperty(&obj, &av_secureToken, &p) != 0 {
log.Println("2.2")
C.DecodeTEA(&r.Link.token, &p.p_vu.p_aval)
C.SendSecureTokenResponse(r, &p.p_vu.p_aval)
}
}
*/
if (r.Link.protocol & RTMP_FEATURE_WRITE) != 0 {
log.Println("2.3")
C.SendReleaseStream(r)
C.SendFCPublish(r)
} else {
} /* NOTE This code doesn't run in our use case
else {
log.Println("2.4")
C.RTMP_SendServerBW(r)
C.RTMP_SendCtrl(r, 3, 0, 300)
}
*/
C.RTMP_SendCreateStream(r)
/* NOTE This code doesn't run in our use case
if (r.Link.protocol & RTMP_FEATURE_WRITE) == 0 {
/* Authenticate on Justin.tv legacy servers before sending FCSubscribe */
log.Println("2.5")
// Authenticate on Justin.tv legacy servers before sending FCSubscribe
if r.Link.usherToken.av_len != 0 {
log.Println("2.6")
C.SendUsherToken(r, &r.Link.usherToken)
}
/* Send the FCSubscribe if live stream or if subscribepath is set */
// Send the FCSubscribe if live stream or if subscribepath is set
switch {
case r.Link.subscribepath.av_len != 0:
{
@ -2055,6 +2057,7 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 {
}
}
}
*/
}
case C_AVMATCH(&methodInvoked, &av_createStream) != 0:
{
@ -2062,21 +2065,28 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 {
r.m_stream_id = C.int(C.AMFProp_GetNumber(C.AMF_GetProp(&obj, nil, 3)))
if (r.Link.protocol & RTMP_FEATURE_WRITE) != 0 {
log.Println("5.1")
C.SendPublish(r)
} else {
} /* NOTE This code doesn't run in our use case
else {
log.Println("5.2")
if (r.Link.lFlags & RTMP_LF_PLST) != 0 {
log.Println("5.3")
C.SendPlaylist(r)
}
C.SendPlay(r)
C.RTMP_SendCtrl(r, 3, C.uint(r.m_stream_id), C.uint(r.m_nBufferMS))
}
*/
}
case C_AVMATCH(&methodInvoked, &av_play) != 0 ||
C_AVMATCH(&methodInvoked, &av_publish) != 0:
{
log.Println("6")
r.m_bPlaying = 1
}
/*NOTE This code doesn't run in our use case
case C_AVMATCH(&methodInvoked, &av_play) != 0 ||
C_AVMATCH(&methodInvoked, &av_publish) != 0:
{
log.Println("6")
r.m_bPlaying = 1
}
*/
}
C.free(unsafe.Pointer(methodInvoked.av_val))
}
@ -2084,11 +2094,12 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 {
{
log.Println("7")
if r.m_nBWCheckCounter == 0 {
log.Println("7.1")
C.SendCheckBW(r)
}
}
/*NOTE This code doesn't run in our use case
case C_AVMATCH(&method, &av_onFCSubscribe) != 0:
/* SendOnFCSubscribe(); */
case C_AVMATCH(&method, &av_onFCUnsubscribe) != 0:
{
log.Println("8")
@ -2124,22 +2135,20 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 {
//RTMP_Log(RTMP_LOGERROR, "rtmp server requested close");
C.RTMP_Close(r)
}
*/
case C_AVMATCH(&method, &av_onStatus) != 0:
{
log.Println("13")
var obj2 C.AMFObject
log.Println("13.1")
var code, level C.AVal
log.Println("13.2")
C.AMFProp_GetObject(C.AMF_GetProp(&obj, nil, 3), &obj2)
log.Println("13.3")
C.AMFProp_GetString(C.AMF_GetProp(&obj2, &av_code, -1), &code)
log.Println("13.4")
C.AMFProp_GetString(C.AMF_GetProp(&obj2, &av_level, -1), &level)
// TODO use new logger
// RTMP_Log(RTMP_LOGDEBUG, "%s, onStatus: %s", __FUNCTION__, code.av_val);
switch {
/*NOTE This code doesn't run in our use case
case C_AVMATCH(&code, &av_NetStream_Failed) != 0 ||
C_AVMATCH(&code, &av_NetStream_Play_Failed) != 0 ||
C_AVMATCH(&code, &av_NetStream_Play_StreamNotFound) != 0 ||
@ -2160,11 +2169,13 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 {
for i = 0; i < int32(r.m_numCalls); i++ {
if C_AVMATCH(&(*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i),
int(unsafe.Sizeof(*r.m_methodCalls))))).name, &av_play) != 0 {
log.Println("15.1")
C.AV_erase(r.m_methodCalls, &r.m_numCalls, C.int(i), 1)
break
}
}
}
*/
case C_AVMATCH(&code, &av_NetStream_Publish_Start) != 0:
{
log.Println("16")
@ -2173,49 +2184,54 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 {
for i = 0; i < int32(r.m_numCalls); i++ {
if C_AVMATCH(&(*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i),
int(unsafe.Sizeof(*r.m_methodCalls))))).name, &av_publish) != 0 {
log.Println("16.1")
C.AV_erase(r.m_methodCalls, &r.m_numCalls, C.int(i), 1)
break
}
}
}
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:
{
log.Println("17")
C.RTMP_Close(r)
ret = 1
}
case C_AVMATCH(&code, &av_NetStream_Seek_Notify) != 0:
{
log.Println("18")
// NOTE ~ has been replace by ^ - is this correct ?
r.m_read.flags = C.uint8_t(int8(r.m_read.flags) & ^RTMP_READ_SEEKING)
}
case C_AVMATCH(&code, &av_NetStream_Pause_Notify) != 0:
{
log.Println("19")
if r.m_pausing == 1 || r.m_pausing == 2 {
C.RTMP_SendPause(r, 0, C.int(r.m_pauseStamp))
r.m_pausing = 3
/*NOTE This code doesn't run in our use case
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:
{
log.Println("17")
C.RTMP_Close(r)
ret = 1
}
case C_AVMATCH(&code, &av_NetStream_Seek_Notify) != 0:
{
log.Println("18")
// NOTE ~ has been replace by ^ - is this correct ?
r.m_read.flags = C.uint8_t(int8(r.m_read.flags) & ^RTMP_READ_SEEKING)
}
case C_AVMATCH(&code, &av_NetStream_Pause_Notify) != 0:
{
log.Println("19")
if r.m_pausing == 1 || r.m_pausing == 2 {
C.RTMP_SendPause(r, 0, C.int(r.m_pauseStamp))
r.m_pausing = 3
}
}
*/
}
}
/*NOTE This code doesn't run in our use case
case C_AVMATCH(&method, &av_playlist_ready) != 0:
{
log.Println("19")
var i int32
for i = 0; i < int32(r.m_numCalls); i++ {
if C_AVMATCH(&(*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i),
int(unsafe.Sizeof(*r.m_methodCalls))))).name, &av_set_playlist) != 0 {
C.AV_erase(r.m_methodCalls, &r.m_numCalls, C.int(i), 1)
break
}
}
}
}
case C_AVMATCH(&method, &av_playlist_ready) != 0:
{
log.Println("19")
var i int32
for i = 0; i < int32(r.m_numCalls); i++ {
if C_AVMATCH(&(*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i),
int(unsafe.Sizeof(*r.m_methodCalls))))).name, &av_set_playlist) != 0 {
C.AV_erase(r.m_methodCalls, &r.m_numCalls, C.int(i), 1)
break
}
}
}
default:
log.Println("20")
default:
log.Println("20")
*/
}
leave:
C.AMF_Reset(&obj)