Skip to content

Commit 2e635c5

Browse files
committed
modify:wenrtc push stream work now
1 parent 3571bc5 commit 2e635c5

File tree

7 files changed

+296
-19
lines changed

7 files changed

+296
-19
lines changed

XEngine_Source/XEngine_ModuleSession/ModuleSession_Define.h

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,4 +842,80 @@ extern "C" bool ModuleSession_PushStream_AudioCodecSet(LPCXSTR lpszClientAddr, X
842842
意思:是否成功
843843
备注:
844844
*********************************************************************/
845-
extern "C" bool ModuleSession_PushStream_AudioCodecGet(LPCXSTR lpszClientAddr, XNETHANDLE* pxhAudioDecodec, XNETHANDLE* pxhAudioEncodec);
845+
extern "C" bool ModuleSession_PushStream_AudioCodecGet(LPCXSTR lpszClientAddr, XNETHANDLE* pxhAudioDecodec, XNETHANDLE* pxhAudioEncodec);
846+
/********************************************************************
847+
函数名称:ModuleSession_PushStream_RTCConnSet
848+
函数功能:设置RTC连接状态
849+
参数.一:lpszClientAddr
850+
In/Out:In
851+
类型:常量字符指针
852+
可空:N
853+
意思:输入要操作的客户端
854+
参数.二:bConnect
855+
In/Out:In
856+
类型:逻辑型
857+
可空:N
858+
意思:输入连接状态
859+
返回值
860+
类型:逻辑型
861+
意思:是否成功
862+
备注:
863+
*********************************************************************/
864+
extern "C" bool ModuleSession_PushStream_RTCConnSet(LPCXSTR lpszClientAddr, bool bConnect);
865+
/********************************************************************
866+
函数名称:ModuleSession_PushStream_RTCConnGet
867+
函数功能:获取RTC连接状态
868+
参数.一:lpszClientAddr
869+
In/Out:In
870+
类型:常量字符指针
871+
可空:N
872+
意思:输入要操作的客户端
873+
参数.二:pbConnect
874+
In/Out:Out
875+
类型:逻辑型指针
876+
可空:N
877+
意思:输出连接状态
878+
返回值
879+
类型:逻辑型
880+
意思:是否成功
881+
备注:
882+
*********************************************************************/
883+
extern "C" bool ModuleSession_PushStream_RTCConnGet(LPCXSTR lpszClientAddr, bool* pbConnect);
884+
/********************************************************************
885+
函数名称:ModuleSession_PushStream_RTCAddrSet
886+
函数功能:设置RTC的数据通信地址
887+
参数.一:lpszClientUser
888+
In/Out:In
889+
类型:常量字符指针
890+
可空:N
891+
意思:输入要操作的用户
892+
参数.二:lpszClientAddr
893+
In/Out:In
894+
类型:常量字符指针
895+
可空:N
896+
意思:输入绑定的地址
897+
返回值
898+
类型:逻辑型
899+
意思:是否成功
900+
备注:
901+
*********************************************************************/
902+
extern "C" bool ModuleSession_PushStream_RTCAddrSet(LPCXSTR lpszClientUser, LPCXSTR lpszClientAddr);
903+
/********************************************************************
904+
函数名称:ModuleSession_PushStream_RTCAddrGet
905+
函数功能:获取地址绑定的用户
906+
参数.一:lpszClientAddr
907+
In/Out:In
908+
类型:常量字符指针
909+
可空:N
910+
意思:输入要操作的地址
911+
参数.二:ptszClientUser
912+
In/Out:Out
913+
类型:字符指针
914+
可空:N
915+
意思:输出绑定的用户
916+
返回值
917+
类型:逻辑型
918+
意思:是否成功
919+
备注:
920+
*********************************************************************/
921+
extern "C" bool ModuleSession_PushStream_RTCAddrGet(LPCXSTR lpszClientAddr, XCHAR* ptszClientUser);

XEngine_Source/XEngine_ModuleSession/ModuleSession_PushStream/ModuleSession_PushStream.cpp

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,189 @@ bool CModuleSession_PushStream::ModuleSession_PushStream_AudioCodecGet(LPCXSTR l
889889
*pxhAudioEncodec = stl_MapIterator->second->st_AVCodec.xhAudioEncodec;
890890
*pxhAudioDecodec = stl_MapIterator->second->st_AVCodec.xhAudioDecodec;
891891

892+
st_Locker.unlock_shared();
893+
return true;
894+
}
895+
/********************************************************************
896+
函数名称:ModuleSession_PushStream_RTCAddrSet
897+
函数功能:设置RTC的数据通信地址
898+
参数.一:lpszClientUser
899+
In/Out:In
900+
类型:常量字符指针
901+
可空:N
902+
意思:输入要操作的用户
903+
参数.二:lpszClientAddr
904+
In/Out:In
905+
类型:常量字符指针
906+
可空:N
907+
意思:输入绑定的地址
908+
返回值
909+
类型:逻辑型
910+
意思:是否成功
911+
备注:
912+
*********************************************************************/
913+
bool CModuleSession_PushStream::ModuleSession_PushStream_RTCAddrSet(LPCXSTR lpszClientUser, LPCXSTR lpszClientAddr)
914+
{
915+
Session_IsErrorOccur = false;
916+
917+
if (NULL == lpszClientAddr)
918+
{
919+
Session_IsErrorOccur = true;
920+
Session_dwErrorCode = ERROR_STREAMMEDIA_MODULE_SESSION_PARAMENT;
921+
return false;
922+
}
923+
//是否存在
924+
st_Locker.lock_shared();
925+
unordered_map<xstring, PUSHSTREAM_PACKET*>::iterator stl_MapIterator = stl_MapPushStream.find(lpszClientUser);
926+
if (stl_MapIterator == stl_MapPushStream.end())
927+
{
928+
Session_IsErrorOccur = true;
929+
Session_dwErrorCode = ERROR_STREAMMEDIA_MODULE_SESSION_NOTFOUND;
930+
st_Locker.unlock_shared();
931+
return false;
932+
}
933+
_tcsxcpy(stl_MapIterator->second->st_RTCInfo.tszClientAddr, lpszClientAddr);
934+
st_Locker.unlock_shared();
935+
return true;
936+
}
937+
/********************************************************************
938+
函数名称:ModuleSession_PushStream_RTCAddrGet
939+
函数功能:获取地址绑定的用户
940+
参数.一:lpszClientAddr
941+
In/Out:In
942+
类型:常量字符指针
943+
可空:N
944+
意思:输入要操作的地址
945+
参数.二:ptszClientUser
946+
In/Out:Out
947+
类型:字符指针
948+
可空:N
949+
意思:输出绑定的用户
950+
返回值
951+
类型:逻辑型
952+
意思:是否成功
953+
备注:
954+
*********************************************************************/
955+
bool CModuleSession_PushStream::ModuleSession_PushStream_RTCAddrGet(LPCXSTR lpszClientAddr, XCHAR* ptszClientUser)
956+
{
957+
Session_IsErrorOccur = false;
958+
if (NULL == lpszClientAddr)
959+
{
960+
Session_IsErrorOccur = true;
961+
Session_dwErrorCode = ERROR_STREAMMEDIA_MODULE_SESSION_PARAMENT;
962+
return false;
963+
}
964+
//是否存在
965+
st_Locker.lock_shared();
966+
unordered_map<xstring, PUSHSTREAM_PACKET*>::iterator stl_MapIterator = stl_MapPushStream.find(lpszClientAddr);
967+
if (stl_MapIterator == stl_MapPushStream.end())
968+
{
969+
Session_IsErrorOccur = true;
970+
Session_dwErrorCode = ERROR_STREAMMEDIA_MODULE_SESSION_NOTFOUND;
971+
st_Locker.unlock_shared();
972+
return false;
973+
}
974+
_tcsxcpy(ptszClientUser, stl_MapIterator->second->st_RTCInfo.tszClientAddr);
975+
st_Locker.unlock_shared();
976+
return true;
977+
}
978+
/********************************************************************
979+
函数名称:ModuleSession_PushStream_RTCConnSet
980+
函数功能:设置RTC连接状态
981+
参数.一:lpszClientAddr
982+
In/Out:In
983+
类型:常量字符指针
984+
可空:N
985+
意思:输入要操作的客户端
986+
参数.二:bConnect
987+
In/Out:In
988+
类型:逻辑型
989+
可空:N
990+
意思:输入连接状态
991+
返回值
992+
类型:逻辑型
993+
意思:是否成功
994+
备注:
995+
*********************************************************************/
996+
bool CModuleSession_PushStream::ModuleSession_PushStream_RTCConnSet(LPCXSTR lpszClientAddr, bool bConnect)
997+
{
998+
Session_IsErrorOccur = false;
999+
1000+
if (NULL == lpszClientAddr)
1001+
{
1002+
Session_IsErrorOccur = true;
1003+
Session_dwErrorCode = ERROR_STREAMMEDIA_MODULE_SESSION_PARAMENT;
1004+
return false;
1005+
}
1006+
bool bFound = false;
1007+
//是否存在
1008+
st_Locker.lock_shared();
1009+
unordered_map<xstring, PUSHSTREAM_PACKET*>::iterator stl_MapIterator = stl_MapPushStream.find(lpszClientAddr);
1010+
for (; stl_MapIterator != stl_MapPushStream.end(); stl_MapIterator++)
1011+
{
1012+
if (0 == _tcsxnicmp(lpszClientAddr, stl_MapIterator->second->st_RTCInfo.tszClientAddr, _tcsxlen(lpszClientAddr)))
1013+
{
1014+
bFound = true;
1015+
stl_MapIterator->second->st_RTCInfo.bConnect = bConnect;
1016+
break;
1017+
}
1018+
}
1019+
st_Locker.unlock_shared();
1020+
if (!bFound)
1021+
{
1022+
Session_IsErrorOccur = true;
1023+
Session_dwErrorCode = ERROR_STREAMMEDIA_MODULE_SESSION_NOTFOUND;
1024+
return false;
1025+
}
1026+
return true;
1027+
}
1028+
/********************************************************************
1029+
函数名称:ModuleSession_PushStream_RTCConnGet
1030+
函数功能:获取RTC连接状态
1031+
参数.一:lpszClientAddr
1032+
In/Out:In
1033+
类型:常量字符指针
1034+
可空:N
1035+
意思:输入要操作的客户端
1036+
参数.二:pbConnect
1037+
In/Out:Out
1038+
类型:逻辑型指针
1039+
可空:N
1040+
意思:输出连接状态
1041+
返回值
1042+
类型:逻辑型
1043+
意思:是否成功
1044+
备注:
1045+
*********************************************************************/
1046+
bool CModuleSession_PushStream::ModuleSession_PushStream_RTCConnGet(LPCXSTR lpszClientAddr, bool* pbConnect)
1047+
{
1048+
Session_IsErrorOccur = false;
1049+
if (NULL == lpszClientAddr)
1050+
{
1051+
Session_IsErrorOccur = true;
1052+
Session_dwErrorCode = ERROR_STREAMMEDIA_MODULE_SESSION_PARAMENT;
1053+
return false;
1054+
}
1055+
bool bFound = false;
1056+
//是否存在
1057+
st_Locker.lock_shared();
1058+
unordered_map<xstring, PUSHSTREAM_PACKET*>::iterator stl_MapIterator = stl_MapPushStream.begin();
1059+
for (; stl_MapIterator != stl_MapPushStream.end(); stl_MapIterator++)
1060+
{
1061+
if (0 == _tcsxnicmp(lpszClientAddr, stl_MapIterator->second->st_RTCInfo.tszClientAddr, _tcsxlen(lpszClientAddr)))
1062+
{
1063+
bFound = true;
1064+
break;
1065+
}
1066+
}
1067+
if (!bFound)
1068+
{
1069+
Session_IsErrorOccur = true;
1070+
Session_dwErrorCode = ERROR_STREAMMEDIA_MODULE_SESSION_NOTFOUND;
1071+
st_Locker.unlock_shared();
1072+
return false;
1073+
}
1074+
*pbConnect = stl_MapIterator->second->st_RTCInfo.bConnect;
8921075
st_Locker.unlock_shared();
8931076
return true;
8941077
}

XEngine_Source/XEngine_ModuleSession/ModuleSession_PushStream/ModuleSession_PushStream.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ typedef struct
2020
FILE* pSt_File;
2121
}st_HLSFile;
2222
struct
23+
{
24+
XCHAR tszClientAddr[XPATH_MAX];
25+
bool bConnect;
26+
}st_RTCInfo;
27+
struct
2328
{
2429
XNETHANDLE xhAudioDecodec;
2530
XNETHANDLE xhAudioEncodec;
@@ -59,6 +64,11 @@ class CModuleSession_PushStream
5964
public:
6065
bool ModuleSession_PushStream_AudioCodecSet(LPCXSTR lpszClientAddr, XNETHANDLE xhAudioDecodec, XNETHANDLE xhAudioEncodec);
6166
bool ModuleSession_PushStream_AudioCodecGet(LPCXSTR lpszClientAddr, XNETHANDLE* pxhAudioDecodec, XNETHANDLE* pxhAudioEncodec);
67+
public:
68+
bool ModuleSession_PushStream_RTCAddrSet(LPCXSTR lpszClientUser, LPCXSTR lpszClientAddr);
69+
bool ModuleSession_PushStream_RTCAddrGet(LPCXSTR lpszClientAddr, XCHAR* ptszClientUser);
70+
bool ModuleSession_PushStream_RTCConnSet(LPCXSTR lpszClientAddr, bool bConnect);
71+
bool ModuleSession_PushStream_RTCConnGet(LPCXSTR lpszClientAddr, bool* pbConnect);
6272
private:
6373
shared_mutex st_Locker;
6474
private:

XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.def

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,8 @@ EXPORTS
4343
ModuleSession_PushStream_HLSTimeGet
4444

4545
ModuleSession_PushStream_AudioCodecSet
46-
ModuleSession_PushStream_AudioCodecGet
46+
ModuleSession_PushStream_AudioCodecGet
47+
ModuleSession_PushStream_RTCConnSet
48+
ModuleSession_PushStream_RTCConnGet
49+
ModuleSession_PushStream_RTCAddrSet
50+
ModuleSession_PushStream_RTCAddrGet

XEngine_Source/XEngine_ModuleSession/pch.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,20 @@ extern "C" bool ModuleSession_PushStream_AudioCodecSet(LPCXSTR lpszClientAddr, X
183183
extern "C" bool ModuleSession_PushStream_AudioCodecGet(LPCXSTR lpszClientAddr, XNETHANDLE* pxhAudioDecodec, XNETHANDLE* pxhAudioEncodec)
184184
{
185185
return m_PushStream.ModuleSession_PushStream_AudioCodecGet(lpszClientAddr, pxhAudioDecodec, pxhAudioEncodec);
186+
}
187+
extern "C" bool ModuleSession_PushStream_RTCConnSet(LPCXSTR lpszClientAddr, bool bConnect)
188+
{
189+
return m_PushStream.ModuleSession_PushStream_RTCConnSet(lpszClientAddr, bConnect);
190+
}
191+
extern "C" bool ModuleSession_PushStream_RTCConnGet(LPCXSTR lpszClientAddr, bool* pbConnect)
192+
{
193+
return m_PushStream.ModuleSession_PushStream_RTCConnGet(lpszClientAddr, pbConnect);
194+
}
195+
extern "C" bool ModuleSession_PushStream_RTCAddrSet(LPCXSTR lpszClientUser, LPCXSTR lpszClientAddr)
196+
{
197+
return m_PushStream.ModuleSession_PushStream_RTCAddrSet(lpszClientUser, lpszClientAddr);
198+
}
199+
extern "C" bool ModuleSession_PushStream_RTCAddrGet(LPCXSTR lpszClientAddr, XCHAR* ptszClientUser)
200+
{
201+
return m_PushStream.ModuleSession_PushStream_RTCAddrGet(lpszClientAddr, ptszClientUser);
186202
}

XEngine_Source/XEngine_ServiceApp/XEngine_StreamMediaApp/StreamMedia_PullStream/PullStream_ClientWebRtc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ bool PullStream_ClientProtocol_Handle(LPCXSTR lpszClientAddr, XSOCKET hSocket, L
145145
else
146146
{
147147
//RTP
148-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("RTC客户端:%s,请求的RTP协议处理成功"), lpszClientAddr);
148+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("RTC客户端:%s,%d,请求的RTP协议处理成功"), lpszClientAddr, nMsgLen);
149149
}
150150
}
151151
else

XEngine_Source/XEngine_ServiceApp/XEngine_StreamMediaApp/StreamMedia_PushStream/PushStream_ClientWebRtc.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ bool PushStream_ClientProtocol_Handle(LPCXSTR lpszClientAddr, XSOCKET hSocket, L
3232
nSDLen = 2048;
3333
bool bConnect = false;
3434

35-
if (!ModuleSession_PullStream_RTCConnGet(lpszClientAddr, &bConnect))
35+
if (!ModuleSession_PushStream_RTCConnGet(lpszClientAddr, &bConnect))
3636
{
3737
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("RTC客户端:%s,请求的DTLS协议处理失败,地址不存在"), lpszClientAddr);
3838
return false;
@@ -58,18 +58,7 @@ bool PushStream_ClientProtocol_Handle(LPCXSTR lpszClientAddr, XSOCKET hSocket, L
5858

5959
XCHAR tszSMSName[128] = {};
6060
XCHAR tszSMSAddr[128] = {};
61-
if (!ModuleSession_PullStream_RTCSmsGet(lpszClientAddr, tszSMSName))
62-
{
63-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("RTC客户端:%s,握手成功,处理SMS地址失败,诶有找到"), lpszClientAddr);
64-
return false;
65-
}
66-
if (!ModuleSession_PushStream_FindStream(tszSMSName, tszSMSAddr))
67-
{
68-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("RTC客户端:%s,握手成功,处理SMS地址失败,诶有找到"), lpszClientAddr);
69-
return false;
70-
}
71-
ModuleSession_PullStream_RTCConnSet(lpszClientAddr, true);
72-
ModuleSession_PushStream_ClientInsert(tszSMSAddr, lpszClientAddr, ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_PULL_RTC);
61+
ModuleSession_PushStream_RTCConnSet(lpszClientAddr, true);
7362
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("RTC客户端:%s,请求的DTLS握手协议处理成功,绑定的地址:%s,绑定的名称:%s"), lpszClientAddr, tszSMSAddr, tszSMSName);
7463
}
7564
else
@@ -110,8 +99,8 @@ bool PushStream_ClientProtocol_Handle(LPCXSTR lpszClientAddr, XSOCKET hSocket, L
11099
nSDLen = nRVLen;
111100
NatProtocol_StunNat_Packet(tszSDBuffer, &nSDLen, (LPCXSTR)st_NatClient.byTokenStr, RFCCOMPONENTS_NATCLIENT_PROTOCOL_STUN_CLASS_RESPONSE, RFCCOMPONENTS_NATCLIENT_PROTOCOL_STUN_ATTR_MAPPED_ADDRESS, tszRVBuffer, true, st_ServiceConfig.st_XPull.st_PullWebRtc.tszICEPass, true);
112101
//更新绑定的地址
113-
ModuleSession_PullStream_RTCAddrSet(tszUserStr, lpszClientAddr);
114102
SocketOpt_HeartBeat_ActiveAddrEx(xhRTCWhipHeart, tszUserStr); //激活一次心跳
103+
ModuleSession_PushStream_RTCAddrSet(tszUserStr, lpszClientAddr);
115104
XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_PUSH_RTC);
116105
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("RTC客户端:%s,请求的STUN协议处理成功,请求的用户:%s"), lpszClientAddr, tszUserStr);
117106
}
@@ -355,11 +344,10 @@ bool PushStream_ClientWhip_Handle(RFCCOMPONENTS_HTTP_REQPARAM* pSt_HTTPParam, LP
355344

356345
ModuleSession_PushStream_Create(tszUserStr, tszSMSAddr, ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_PULL_RTC);
357346
ModuleSession_PushStream_SetAVInfo(tszUserStr, &st_AVInfo);
358-
ModuleSession_PullStream_RTCSet(tszUserStr, tszTokenStr, tszICEUser, tszICEPass, tszHMacStr);
359347
SocketOpt_HeartBeat_InsertAddrEx(xhRTCWhipHeart, tszUserStr); //需要加入心跳,不然没法知道超时
360348

361349
st_HDRParam.nHttpCode = 201;
362-
_xstprintf(st_HDRParam.tszMimeType, _X("sdp"));
350+
_xstprintf(st_HDRParam.tszMimeType, _X("application/sdp"));
363351
HttpProtocol_Server_SendMsgEx(xhHttpPacket, tszSDBuffer, &nSDLen, &st_HDRParam, tszRVBuffer, nRVLen, tszHDRStr);
364352
XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_HTTP);
365353
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("WEBRTC:%s,Whip协议推流请求成功"), lpszClientAddr);

0 commit comments

Comments
 (0)