mirror of https://bitbucket.org/ausocean/av.git
rtmp: removed case braces in C_HandlInvoke and replaced code not run with panics in case we do get those cases
This commit is contained in:
parent
bd630fd893
commit
8318f34be4
288
rtmp/rtmp.go
288
rtmp/rtmp.go
|
@ -1084,33 +1084,33 @@ func C_SendFCPublish(r *C_RTMP) int32 {
|
||||||
func C_SendFCUnpublish(r *C_RTMP) int32 {
|
func C_SendFCUnpublish(r *C_RTMP) int32 {
|
||||||
// TODO finish porting
|
// TODO finish porting
|
||||||
/*
|
/*
|
||||||
var packet C_RTMPPacket
|
var packet C_RTMPPacket
|
||||||
var pbuf [1024]byte
|
var pbuf [1024]byte
|
||||||
var pend []byte = pbuf[1024:]
|
var pend []byte = pbuf[1024:]
|
||||||
var enc []byte
|
var enc []byte
|
||||||
|
|
||||||
packet.m_nChannel = 0x03
|
packet.m_nChannel = 0x03
|
||||||
packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM
|
packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM
|
||||||
packet.m_packetType = RTMP_PACKET_TYPE_INVOKE
|
packet.m_packetType = RTMP_PACKET_TYPE_INVOKE
|
||||||
packet.m_nTimeStamp = 0
|
packet.m_nTimeStamp = 0
|
||||||
packet.m_nInfoField2 = 0
|
packet.m_nInfoField2 = 0
|
||||||
packet.m_hasAbsTimestamp = 0
|
packet.m_hasAbsTimestamp = 0
|
||||||
packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE
|
packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE
|
||||||
|
|
||||||
// NOTE use of unsafe pointer will be remove here when packet.m_nBody becomes []byte
|
// NOTE use of unsafe pointer will be remove here when packet.m_nBody becomes []byte
|
||||||
enc = []byte(unsafe.Pointer(packet.m_nBody))
|
enc = []byte(unsafe.Pointer(packet.m_nBody))
|
||||||
enc = C_AMF_EncodeString((*byte)(unsafe.Pointer(&enc[0])),
|
enc = C_AMF_EncodeString((*byte)(unsafe.Pointer(&enc[0])),
|
||||||
(*byte)(unsafe.Pointer(&pend[0])), &av_FCUnpublish)
|
(*byte)(unsafe.Pointer(&pend[0])), &av_FCUnpublish)
|
||||||
r.m_numInvokes++
|
r.m_numInvokes++
|
||||||
enc = C_AMF_EncodeNumber(enc, pend, r->m_numInvokes);
|
enc = C_AMF_EncodeNumber(enc, pend, r->m_numInvokes);
|
||||||
*enc++ = AMF_NULL;
|
*enc++ = AMF_NULL;
|
||||||
enc = AMF_EncodeString(enc, pend, &r->Link.playpath);
|
enc = AMF_EncodeString(enc, pend, &r->Link.playpath);
|
||||||
if (!enc)
|
if (!enc)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
packet.m_nBodySize = enc - packet.m_body;
|
packet.m_nBodySize = enc - packet.m_body;
|
||||||
|
|
||||||
return RTMP_SendPacket(r, &packet, FALSE);
|
return RTMP_SendPacket(r, &packet, FALSE);
|
||||||
*/
|
*/
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -1315,10 +1315,9 @@ func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) int32 {
|
||||||
//methodInvoked.av_val);
|
//methodInvoked.av_val);
|
||||||
switch {
|
switch {
|
||||||
case C_AVMATCH(&methodInvoked, &av_connect) != 0:
|
case C_AVMATCH(&methodInvoked, &av_connect) != 0:
|
||||||
{
|
if r.Link.token.av_len != 0 {
|
||||||
/* NOTE This code doesn't run in our use case
|
panic("No support for link token")
|
||||||
TODO port this eventually
|
/*
|
||||||
if r.Link.token.av_len != 0 {
|
|
||||||
log.Println("2.1")
|
log.Println("2.1")
|
||||||
var p C_AMFObjectProperty
|
var p C_AMFObjectProperty
|
||||||
if C.RTMP_FindFirstMatchingProperty(&obj, &av_secureToken, &p) != 0 {
|
if C.RTMP_FindFirstMatchingProperty(&obj, &av_secureToken, &p) != 0 {
|
||||||
|
@ -1326,21 +1325,24 @@ func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) int32 {
|
||||||
C.DecodeTEA(&r.Link.token, &p.p_vu.p_aval)
|
C.DecodeTEA(&r.Link.token, &p.p_vu.p_aval)
|
||||||
C.SendSecureTokenResponse(r, &p.p_vu.p_aval)
|
C.SendSecureTokenResponse(r, &p.p_vu.p_aval)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
if (r.Link.protocol & RTMP_FEATURE_WRITE) != 0 {
|
}
|
||||||
C_SendReleaseStream(r)
|
if (r.Link.protocol & RTMP_FEATURE_WRITE) != 0 {
|
||||||
C_SendFCPublish(r)
|
C_SendReleaseStream(r)
|
||||||
} /* NOTE This code doesn't run in our use case
|
C_SendFCPublish(r)
|
||||||
else {
|
} else {
|
||||||
|
panic("Link protocol has no RTMP_FEATURE_WRITE")
|
||||||
|
/*
|
||||||
log.Println("2.4")
|
log.Println("2.4")
|
||||||
C.RTMP_SendServerBW(r)
|
C.RTMP_SendServerBW(r)
|
||||||
C.RTMP_SendCtrl(r, 3, 0, 300)
|
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 {
|
C_RTMP_SendCreateStream(r)
|
||||||
|
if (r.Link.protocol & RTMP_FEATURE_WRITE) == 0 {
|
||||||
|
panic("Link protocol has no RTMP_FEATURE_WRITE")
|
||||||
|
/*
|
||||||
log.Println("2.5")
|
log.Println("2.5")
|
||||||
// Authenticate on Justin.tv legacy servers before sending FCSubscribe
|
// Authenticate on Justin.tv legacy servers before sending FCSubscribe
|
||||||
if r.Link.usherToken.av_len != 0 {
|
if r.Link.usherToken.av_len != 0 {
|
||||||
|
@ -1360,17 +1362,17 @@ func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) int32 {
|
||||||
C.SendFCSubscribe(r, &r.Link.playpath)
|
C.SendFCSubscribe(r, &r.Link.playpath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
case C_AVMATCH(&methodInvoked, &av_createStream) != 0:
|
|
||||||
{
|
|
||||||
r.m_stream_id = int32(C_AMFProp_GetNumber(C_AMF_GetProp(&obj, nil, 3)))
|
|
||||||
|
|
||||||
if (r.Link.protocol & RTMP_FEATURE_WRITE) != 0 {
|
case C_AVMATCH(&methodInvoked, &av_createStream) != 0:
|
||||||
C_SendPublish(r)
|
r.m_stream_id = int32(C_AMFProp_GetNumber(C_AMF_GetProp(&obj, nil, 3)))
|
||||||
} /* NOTE This code doesn't run in our use case
|
|
||||||
else {
|
if (r.Link.protocol & RTMP_FEATURE_WRITE) != 0 {
|
||||||
|
C_SendPublish(r)
|
||||||
|
} else {
|
||||||
|
panic("Link protocol has no RTMP_FEATURE_WRITE")
|
||||||
|
/*
|
||||||
log.Println("5.2")
|
log.Println("5.2")
|
||||||
if (r.Link.lFlags & RTMP_LF_PLST) != 0 {
|
if (r.Link.lFlags & RTMP_LF_PLST) != 0 {
|
||||||
log.Println("5.3")
|
log.Println("5.3")
|
||||||
|
@ -1378,158 +1380,96 @@ func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) int32 {
|
||||||
}
|
}
|
||||||
C.SendPlay(r)
|
C.SendPlay(r)
|
||||||
C.RTMP_SendCtrl(r, 3, C.uint(r.m_stream_id), C.uint(r.m_nBufferMS))
|
C.RTMP_SendCtrl(r, 3, C.uint(r.m_stream_id), C.uint(r.m_nBufferMS))
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
/*NOTE This code doesn't run in our use case
|
|
||||||
case C_AVMATCH(&methodInvoked, &av_play) != 0 ||
|
case C_AVMATCH(&methodInvoked, &av_play) != 0 ||
|
||||||
C_AVMATCH(&methodInvoked, &av_publish) != 0:
|
C_AVMATCH(&methodInvoked, &av_publish) != 0:
|
||||||
{
|
panic("Unsupported method av_play/av_publish")
|
||||||
log.Println("6")
|
|
||||||
r.m_bPlaying = 1
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
//C.free(unsafe.Pointer(methodInvoked.av_val))
|
//C.free(unsafe.Pointer(methodInvoked.av_val))
|
||||||
}
|
}
|
||||||
case C_AVMATCH(&method, &av_onBWDone) != 0:
|
case C_AVMATCH(&method, &av_onBWDone) != 0:
|
||||||
{
|
if r.m_nBWCheckCounter == 0 {
|
||||||
if r.m_nBWCheckCounter == 0 {
|
C_SendCheckBW(r)
|
||||||
C_SendCheckBW(r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*NOTE This code doesn't run in our use case
|
|
||||||
case C_AVMATCH(&method, &av_onFCSubscribe) != 0:
|
|
||||||
case C_AVMATCH(&method, &av_onFCUnsubscribe) != 0:
|
|
||||||
{
|
|
||||||
log.Println("8")
|
|
||||||
C.RTMP_Close(r)
|
|
||||||
ret = 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case C_AVMATCH(&method, &av_onFCUnsubscribe) != 0 || C_AVMATCH(&method, &av_onFCSubscribe) != 0:
|
||||||
|
panic("Unsupported method av_onFCUnsubscribe/av_onFCSubscribe")
|
||||||
|
|
||||||
case C_AVMATCH(&method, &av_ping) != 0:
|
case C_AVMATCH(&method, &av_ping) != 0:
|
||||||
{
|
panic("Unsupported method av_ping")
|
||||||
log.Println("9")
|
/*
|
||||||
C.SendPong(r, float64(txn))
|
C.SendPong(r, float64(txn))
|
||||||
}
|
*/
|
||||||
case C_AVMATCH(&method, &av__onbwcheck) != 0:
|
case C_AVMATCH(&method, &av__onbwcheck) != 0:
|
||||||
{
|
panic("Unsupported method av_onbwcheck")
|
||||||
|
/*
|
||||||
log.Println("10")
|
log.Println("10")
|
||||||
C.SendCheckBWResult(r, float64(txn))
|
C.SendCheckBWResult(r, float64(txn))
|
||||||
}
|
*/
|
||||||
case C_AVMATCH(&method, &av__onbwdone) != 0:
|
case C_AVMATCH(&method, &av__onbwdone) != 0:
|
||||||
{
|
panic("Unsupported method av_onbwdone")
|
||||||
log.Println("11")
|
|
||||||
|
case C_AVMATCH(&method, &av_close) != 0:
|
||||||
|
panic("Unsupported method av_close")
|
||||||
|
|
||||||
|
case C_AVMATCH(&method, &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)
|
||||||
|
|
||||||
|
// TODO use new logger
|
||||||
|
// RTMP_Log(RTMP_LOGDEBUG, "%s, onStatus: %s", __FUNCTION__, code.av_val);
|
||||||
|
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:
|
||||||
|
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:
|
||||||
|
panic("Unsupported method av_NetStream_Play_Start/av_NetStream_Play_PublishNotify")
|
||||||
|
|
||||||
|
case C_AVMATCH(&code, &av_NetStream_Publish_Start) != 0:
|
||||||
|
|
||||||
var i int32
|
var i int32
|
||||||
|
r.m_bPlaying = 1
|
||||||
for i = 0; i < int32(r.m_numCalls); i++ {
|
for i = 0; i < int32(r.m_numCalls); i++ {
|
||||||
if C_AVMATCH(&(*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i),
|
if C_AVMATCH(&(*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i),
|
||||||
int(unsafe.Sizeof(*r.m_methodCalls))))).name, &av__checkbw) != 0 {
|
int(unsafe.Sizeof(*r.m_methodCalls))))).name, &av_publish) != 0 {
|
||||||
C.AV_erase(r.m_methodCalls, &r.m_numCalls, int32(i), 1)
|
//C.AV_erase(r.m_methodCalls, &r.m_numCalls, int32(i), 1)
|
||||||
|
C_AV_erase(r.m_methodCalls, (*int32)(&r.m_numCalls), int32(i), 1)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
case C_AVMATCH(&method, &av_close) != 0:
|
|
||||||
{
|
|
||||||
log.Println("12")
|
|
||||||
// TODO use new logger
|
|
||||||
//RTMP_Log(RTMP_LOGERROR, "rtmp server requested close");
|
|
||||||
C.RTMP_Close(r)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
case C_AVMATCH(&method, &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)
|
|
||||||
|
|
||||||
// TODO use new logger
|
case C_AVMATCH(&code, &av_NetStream_Play_Complete) != 0 ||
|
||||||
// RTMP_Log(RTMP_LOGDEBUG, "%s, onStatus: %s", __FUNCTION__, code.av_val);
|
C_AVMATCH(&code, &av_NetStream_Play_Stop) != 0 ||
|
||||||
switch {
|
C_AVMATCH(&code, &av_NetStream_Play_UnpublishNotify) != 0:
|
||||||
/*NOTE This code doesn't run in our use case
|
panic("Unsupported method av_NetStream_Play_Complete/av_NetStream_Play_Stop/av_NetStream_Play_UnpublishNotify")
|
||||||
case C_AVMATCH(&code, &av_NetStream_Failed) != 0 ||
|
|
||||||
C_AVMATCH(&code, &av_NetStream_Play_Failed) != 0 ||
|
case C_AVMATCH(&code, &av_NetStream_Seek_Notify) != 0:
|
||||||
C_AVMATCH(&code, &av_NetStream_Play_StreamNotFound) != 0 ||
|
panic("Unsupported method av_netStream_Seek_Notify")
|
||||||
C_AVMATCH(&code, &av_NetConnection_Connect_InvalidApp) != 0:
|
|
||||||
{
|
case C_AVMATCH(&code, &av_NetStream_Pause_Notify) != 0:
|
||||||
log.Println("14")
|
panic("Unsupported method av_NetStream_Pause_Notify")
|
||||||
r.m_stream_id = -1
|
/*
|
||||||
C.RTMP_Close(r)
|
log.Println("19")
|
||||||
// TODO use new logger
|
if r.m_pausing == 1 || r.m_pausing == 2 {
|
||||||
// RTMP_Log(RTMP_LOGERROR, "Closing connection: %s", code.av_val);
|
C.RTMP_SendPause(r, 0, int32(r.m_pauseStamp))
|
||||||
}
|
r.m_pausing = 3
|
||||||
case C_AVMATCH(&code, &av_NetStream_Play_Start) != 0 ||
|
|
||||||
C_AVMATCH(&code, &av_NetStream_Play_PublishNotify) != 0:
|
|
||||||
{
|
|
||||||
log.Println("15")
|
|
||||||
var i int32
|
|
||||||
r.m_bPlaying = 1
|
|
||||||
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, int32(i), 1)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
case C_AVMATCH(&code, &av_NetStream_Publish_Start) != 0:
|
|
||||||
{
|
|
||||||
var i int32
|
|
||||||
r.m_bPlaying = 1
|
|
||||||
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 {
|
|
||||||
//C.AV_erase(r.m_methodCalls, &r.m_numCalls, int32(i), 1)
|
|
||||||
C_AV_erase(r.m_methodCalls, (*int32)(&r.m_numCalls), int32(i), 1)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*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 = uint8(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, int32(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:
|
case C_AVMATCH(&method, &av_playlist_ready) != 0:
|
||||||
{
|
panic("Unsupported method av_playlist_ready")
|
||||||
log.Println("19")
|
|
||||||
var i int32
|
default:
|
||||||
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, int32(i), 1)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
log.Println("20")
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
leave:
|
leave:
|
||||||
C_AMF_Reset(&obj)
|
C_AMF_Reset(&obj)
|
||||||
|
|
Loading…
Reference in New Issue