Skip to content

Commit eec3872

Browse files
committed
added:srtp core code file
1 parent 308267d commit eec3872

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#include "pch.h"
2+
#include "ModuleHelp_SRTPCore.h"
3+
/********************************************************************
4+
// Created: 2024/03/15 14:42:49
5+
// File Name: D:\XEngine_StreamMedia\XEngine_Source\XEngine_ModuleHelp\ModuleHelp_SRtp\ModuleHelp_SRTPCore.cpp
6+
// File Path: D:\XEngine_StreamMedia\XEngine_Source\XEngine_ModuleHelp\ModuleHelp_SRtp
7+
// File Base: ModuleHelp_SRTPCore
8+
// File Ext: cpp
9+
// Project: XEngine(网络通信引擎)
10+
// Author: qyt
11+
// Purpose: SRTP协议帮助处理模块
12+
// History:
13+
*********************************************************************/
14+
CModuleHelp_SRTPCore::CModuleHelp_SRTPCore()
15+
{
16+
}
17+
CModuleHelp_SRTPCore::~CModuleHelp_SRTPCore()
18+
{
19+
}
20+
//////////////////////////////////////////////////////////////////////////
21+
// 公有函数
22+
//////////////////////////////////////////////////////////////////////////
23+
/********************************************************************
24+
函数名称:ModuleHelp_SRTPCore_Init
25+
函数功能:启动SRT
26+
参数.一:nPort
27+
In/Out:In
28+
类型:整数型
29+
可空:N
30+
意思:输入要绑定的端口
31+
返回值
32+
类型:逻辑型
33+
意思:是否成功
34+
备注:
35+
*********************************************************************/
36+
bool CModuleHelp_SRTPCore::ModuleHelp_SRTPCore_Init()
37+
{
38+
ModuleHelp_IsErrorOccur = false;
39+
40+
#if 1 == _XENGINE_STREAMMEDIA_BUILDSWITCH_RTC
41+
srtp_init();
42+
#endif
43+
return true;
44+
}
45+
bool CModuleHelp_SRTPCore::ModuleHelp_SRTPCore_Destory()
46+
{
47+
ModuleHelp_IsErrorOccur = false;
48+
49+
#if 1 == _XENGINE_STREAMMEDIA_BUILDSWITCH_RTC
50+
srtp_shutdown();
51+
#endif
52+
return true;
53+
}
54+
bool CModuleHelp_SRTPCore::ModuleHelp_SRTPCore_Create(LPCXSTR lpszSendKey, LPCXSTR lpszRecvKey)
55+
{
56+
ModuleHelp_IsErrorOccur = false;
57+
58+
#if 1 == _XENGINE_STREAMMEDIA_BUILDSWITCH_RTC
59+
SRTPCORE_CLIENTINFO st_SRTPCore = {};
60+
srtp_policy_t st_SRTPPolicy = {};
61+
62+
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&st_SRTPPolicy.rtp);
63+
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&st_SRTPPolicy.rtcp);
64+
65+
st_SRTPPolicy.ssrc.value = 0;
66+
st_SRTPPolicy.window_size = 8192;
67+
st_SRTPPolicy.allow_repeat_tx = 1;
68+
st_SRTPPolicy.next = NULL;
69+
70+
//初始化接受上下文
71+
st_SRTPPolicy.ssrc.type = ssrc_any_inbound;
72+
st_SRTPPolicy.key = (unsigned char*)lpszRecvKey;
73+
74+
srtp_err_status_t r0 = srtp_err_status_ok;
75+
if ((r0 = srtp_create(&st_SRTPCore.pSt_SRTPRecvCtx, &st_SRTPPolicy)) != srtp_err_status_ok)
76+
{
77+
78+
}
79+
80+
st_SRTPPolicy.ssrc.type = ssrc_any_outbound;
81+
st_SRTPPolicy.key = (unsigned char*)lpszSendKey;
82+
83+
if ((r0 = srtp_create(&st_SRTPCore.pSt_SRTPSendCtx, &st_SRTPPolicy)) != srtp_err_status_ok)
84+
{
85+
86+
}
87+
#endif
88+
return true;
89+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
/********************************************************************
3+
// Created: 2024/03/15 14:42:30
4+
// File Name: D:\XEngine_StreamMedia\XEngine_Source\XEngine_ModuleHelp\ModuleHelp_SRtp\ModuleHelp_SRTPCore.h
5+
// File Path: D:\XEngine_StreamMedia\XEngine_Source\XEngine_ModuleHelp\ModuleHelp_SRtp
6+
// File Base: ModuleHelp_SRTPCore
7+
// File Ext: h
8+
// Project: XEngine(网络通信引擎)
9+
// Author: qyt
10+
// Purpose: SRTP协议帮助处理模块
11+
// History:
12+
*********************************************************************/
13+
14+
typedef struct
15+
{
16+
srtp_t pSt_SRTPSendCtx;
17+
srtp_t pSt_SRTPRecvCtx;
18+
}SRTPCORE_CLIENTINFO;
19+
20+
class CModuleHelp_SRTPCore
21+
{
22+
public:
23+
CModuleHelp_SRTPCore();
24+
~CModuleHelp_SRTPCore();
25+
public:
26+
bool ModuleHelp_SRTPCore_Init();
27+
bool ModuleHelp_SRTPCore_Destory();
28+
bool ModuleHelp_SRTPCore_Create(LPCXSTR lpszSendKey, LPCXSTR lpszRecvKey);
29+
protected:
30+
private:
31+
};

0 commit comments

Comments
 (0)