Skip to content

Commit 76418b8

Browse files
committed
modify:rtc stun protocol supported
1 parent c99e267 commit 76418b8

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

XEngine_Source/XEngine_ServiceApp/XEngine_StreamMediaApp/StreamMedia_PullStream/PullStream_ClientWebRtc.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,44 @@
1010
// Purpose: WEBRTC拉流服务
1111
// History:
1212
*********************************************************************/
13+
bool PullStream_ClientStun_Handle(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen)
14+
{
15+
int nAttrCount = 0;
16+
RFCCOMPONENTS_NATATTR** ppSt_ListAttr;
17+
RFCCOMPONENTS_NATSTUN st_NatClient = {};
18+
19+
if (!NatProtocol_StunNat_Parse(lpszMsgBuffer, nMsgLen, &st_NatClient, &ppSt_ListAttr, &nAttrCount))
20+
{
21+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("STUN客户端:%s,请求的STUN协议不正确,解析失败,错误:%lX"), lpszClientAddr, NatProtocol_GetLastError());
22+
return false;
23+
}
24+
XCHAR tszUserStr[128] = {};
25+
for (int i = 0; i < nAttrCount; i++)
26+
{
27+
if (RFCCOMPONENTS_NATCLIENT_PROTOCOL_STUN_ATTR_USERNAME == ppSt_ListAttr[i]->wAttr)
28+
{
29+
memcpy(tszUserStr, ppSt_ListAttr[i]->tszMsgBuffer, ppSt_ListAttr[i]->wLen);
30+
}
31+
}
32+
int nTMPLen = 0;
33+
int nMSGLen = 0;
34+
int nIPPort = 0;
35+
XCHAR tszTMPBuffer[1024] = {};
36+
XCHAR tszMSGBuffer[1024] = {};
37+
XCHAR tszIPAddr[128] = {};
38+
39+
_tcsxcpy(tszIPAddr, lpszClientAddr);
40+
41+
BaseLib_OperatorIPAddr_SegAddr(tszIPAddr, &nIPPort);
42+
43+
NatProtocol_StunNat_BuildAttr(tszTMPBuffer, &nTMPLen, RFCCOMPONENTS_NATCLIENT_PROTOCOL_STUN_ATTR_USERNAME, tszUserStr, _tcsxlen(tszUserStr));
44+
NatProtocol_StunNat_BuildMapAddress(tszTMPBuffer + nTMPLen, &nTMPLen, tszIPAddr, nIPPort, true);
45+
//NatProtocol_StunNat_BuildMSGIntegrity(tszMSGBuffer, &nMSGLen, tszTMPBuffer, nTMPLen, );
46+
NatProtocol_StunNat_Packet(tszMSGBuffer, &nMSGLen, (LPCXSTR)st_NatClient.byTokenStr, RFCCOMPONENTS_NATCLIENT_PROTOCOL_STUN_CLASS_FLAGS, RFCCOMPONENTS_NATCLIENT_PROTOCOL_STUN_ATTR_MAPPED_ADDRESS);
47+
48+
BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ListAttr, nAttrCount);
49+
return true;
50+
}
1351
bool PullStream_ClientWebRtc_Handle(RFCCOMPONENTS_HTTP_REQPARAM* pSt_HTTPParam, LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen)
1452
{
1553
int nRVLen = 0;

XEngine_Source/XEngine_ServiceApp/XEngine_StreamMediaApp/StreamMedia_PullStream/PullStream_ClientWebRtc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
// Purpose: WEBRTC拉流服务
1111
// History:
1212
*********************************************************************/
13+
bool PullStream_ClientStun_Handle(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen);
1314
bool PullStream_ClientWebRtc_Handle(RFCCOMPONENTS_HTTP_REQPARAM* pSt_HTTPParam, LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen);

XEngine_Source/XEngine_ServiceApp/XEngine_StreamMediaApp/XEngine_Hdr.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ using namespace std;
3838
#include <XEngine_Include/XEngine_HelpComponents/Packets_Error.h>
3939
#include <XEngine_Include/XEngine_RfcComponents/HttpProtocol_Define.h>
4040
#include <XEngine_Include/XEngine_RfcComponents/HttpProtocol_Error.h>
41+
#include <XEngine_Include/XEngine_RfcComponents/NatProtocol_Define.h>
42+
#include <XEngine_Include/XEngine_RfcComponents/NatProtocol_Error.h>
4143
#include <XEngine_Include/XEngine_StreamMedia/SDPProtocol_Define.h>
4244
#include <XEngine_Include/XEngine_StreamMedia/SDPProtocol_Error.h>
4345
#include <XEngine_Include/XEngine_StreamMedia/FLVProtocol_Define.h>
@@ -169,6 +171,7 @@ extern FILE* pSt_AFile;
169171
#pragma comment(lib,"XEngine_HelpComponents/HelpComponents_XLog.lib")
170172
#pragma comment(lib,"XEngine_HelpComponents/HelpComponents_Packets")
171173
#pragma comment(lib,"XEngine_RfcComponents/RfcComponents_HttpProtocol.lib")
174+
#pragma comment(lib,"XEngine_RfcComponents/RfcComponents_NatProtocol.lib")
172175
#pragma comment(lib,"XEngine_StreamMedia/StreamMedia_SDPProtocol.lib")
173176
#pragma comment(lib,"XEngine_StreamMedia/StreamMedia_FLVProtocol.lib")
174177
#pragma comment(lib,"XEngine_StreamMedia/StreamMedia_RTMPProtocol.lib")

XEngine_Source/XEngine_ServiceApp/XEngine_StreamMediaApp/XEngine_Network.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ void CALLBACK Network_Callback_AudioRTCPRecv(LPCXSTR lpszClientAddr, XSOCKET hSo
161161
//WEBRTC
162162
void CALLBACK Network_Callback_STUNRecv(LPCXSTR lpszClientAddr, XSOCKET hSocket, LPCXSTR lpszRecvMsg, int nMsgLen, XPVOID lParam)
163163
{
164+
PullStream_ClientStun_Handle(lpszClientAddr, lpszRecvMsg, nMsgLen);
164165
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_DEBUG, _X("STUN客户端:%s,发送数据大小:%d 给服务器"), lpszClientAddr, nMsgLen);
165166
}
166167
//////////////////////////////////////////////////////////////////////////网络IO关闭操作

0 commit comments

Comments
 (0)