Skip to content

Commit 6966a89

Browse files
committed
added:pre pull stream support for xstream ts srt
1 parent ad979eb commit 6966a89

File tree

6 files changed

+65
-25
lines changed

6 files changed

+65
-25
lines changed

XEngine_Release/XEngine_Config/XEngine_Config.json

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,45 @@
2828
},
2929
"XPull": {
3030
"XStream": {
31-
"bEnable": true
31+
"bEnable": true,
32+
"bPrePull": true
3233
},
3334
"RTMP": {
34-
"bEnable": true
35+
"bEnable": true,
36+
"bPrePull": false
3537
},
3638
"FLV": {
37-
"bEnable": true
39+
"bEnable": true,
40+
"bPrePull": false
3841
},
3942
"RTSP": {
4043
"bEnable": true,
44+
"bPrePull": true,
4145
"nVRTPPort": 56001,
4246
"nVRTCPPort": 56002,
4347
"nARTPPort": 56003,
4448
"nARTCPPort": 56004
4549
},
4650
"RTC": {
47-
"bEnable": true,
51+
"bEnable": false,
52+
"bPrePull": false,
4853
"tszICEUser": "xengine",
4954
"tszICEPass": "3321308h8i6vt3769r6638l1409d50jz",
5055
"tszCertStr": "./XEngine_Key/server.crt",
5156
"tszKeyStr": "./XEngine_Key/server.key",
5257
"tszDerStr": "./XEngine_Key/server.der"
5358
},
5459
"SRT": {
55-
"bEnable": true
60+
"bEnable": true,
61+
"bPrePull": true
5662
},
5763
"TS": {
58-
"bEnable": true
64+
"bEnable": true,
65+
"bPrePull": true
5966
},
6067
"HLS": {
6168
"bEnable": false,
69+
"bPrePull": true,
6270
"bClear": false,
6371
"nTime": 15,
6472
"tszHLSPath": "./XEngine_File"
@@ -71,7 +79,7 @@
7179
"LogLeave": 17
7280
},
7381
"XReport":{
74-
"bEnable":true,
82+
"bEnable":false,
7583
"tszServiceName":"XEngine_StreamMedia",
7684
"tszAPIUrl":"http://app.xyry.org:5501/api?function=machine"
7785
}

XEngine_Source/XEngine_BuildSwitch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
// Purpose: 编译开关选项
1111
// History:
1212
*********************************************************************/
13-
#define _XENGINE_STREAMMEDIA_BUILDSWITCH_SRT 1 //SRT协议编译开关选项
13+
#define _XENGINE_STREAMMEDIA_BUILDSWITCH_SRT 0 //SRT协议编译开关选项
1414
#define _XENGINE_STREAMMEDIA_BUILDSWITCH_RTC 1 //WEBRTC协议编译开关选项

XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,33 +58,40 @@ typedef struct tag_XEngine_ServiceConfig
5858
struct
5959
{
6060
bool bEnable;
61+
bool bPrePull;
6162
}st_PullXStream;
6263
struct
6364
{
6465
bool bEnable;
66+
bool bPrePull;
6567
}st_PullRtmp;
6668
struct
6769
{
6870
bool bEnable;
71+
bool bPrePull;
6972
}st_PullFlv;
7073
struct
7174
{
7275
XCHAR tszHLSPath[MAX_PATH];
7376
int nTime;
7477
bool bEnable;
78+
bool bPrePull;
7579
bool bClear;
7680
}st_PullHls;
7781
struct
7882
{
7983
bool bEnable;
84+
bool bPrePull;
8085
}st_PullSrt;
8186
struct
8287
{
8388
bool bEnable;
89+
bool bPrePull;
8490
}st_PullTs;
8591
struct
8692
{
8793
bool bEnable;
94+
bool bPrePull;
8895
int nVRTPPort;
8996
int nVRTCPPort;
9097
int nARTPPort;
@@ -98,6 +105,7 @@ typedef struct tag_XEngine_ServiceConfig
98105
XCHAR tszKeyStr[MAX_PATH];
99106
XCHAR tszDerStr[MAX_PATH];
100107
bool bEnable;
108+
bool bPrePull;
101109
}st_PullWebRtc;
102110
}st_XPull;
103111
struct

XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,25 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE
139139
Json::Value st_PullTs = st_Pull["TS"];
140140

141141
pSt_ServerConfig->st_XPull.st_PullXStream.bEnable = st_PullXStream["bEnable"].asBool();
142+
pSt_ServerConfig->st_XPull.st_PullXStream.bPrePull = st_PullXStream["bPrePull"].asBool();
143+
142144
pSt_ServerConfig->st_XPull.st_PullRtmp.bEnable = st_PullRtmp["bEnable"].asBool();
145+
pSt_ServerConfig->st_XPull.st_PullRtmp.bPrePull = st_PullRtmp["bPrePull"].asBool();
146+
143147
pSt_ServerConfig->st_XPull.st_PullFlv.bEnable = st_PullFlv["bEnable"].asBool();
148+
pSt_ServerConfig->st_XPull.st_PullFlv.bPrePull = st_PullFlv["bPrePull"].asBool();
149+
144150
pSt_ServerConfig->st_XPull.st_PullHls.bEnable = st_PullHls["bEnable"].asBool();
145-
pSt_ServerConfig->st_XPull.st_PullWebRtc.bEnable = st_PullWebRtc["bEnable"].asBool();
151+
pSt_ServerConfig->st_XPull.st_PullHls.bPrePull = st_PullHls["bPrePull"].asBool();
152+
146153
pSt_ServerConfig->st_XPull.st_PullSrt.bEnable = st_PullSrt["bEnable"].asBool();
154+
pSt_ServerConfig->st_XPull.st_PullSrt.bPrePull = st_PullSrt["bPrePull"].asBool();
155+
147156
pSt_ServerConfig->st_XPull.st_PullTs.bEnable = st_Pull["bEnable"].asBool();
157+
pSt_ServerConfig->st_XPull.st_PullTs.bPrePull = st_Pull["bPrePull"].asBool();
148158

149159
pSt_ServerConfig->st_XPull.st_PullRtsp.bEnable = st_PullRtsp["bEnable"].asBool();
160+
pSt_ServerConfig->st_XPull.st_PullRtsp.bPrePull = st_PullRtsp["bPrePull"].asBool();
150161
pSt_ServerConfig->st_XPull.st_PullRtsp.nVRTPPort = st_PullRtsp["nVRTPPort"].asInt();
151162
pSt_ServerConfig->st_XPull.st_PullRtsp.nVRTCPPort = st_PullRtsp["nVRTCPPort"].asInt();
152163
pSt_ServerConfig->st_XPull.st_PullRtsp.nARTPPort = st_PullRtsp["nARTPPort"].asInt();
@@ -156,6 +167,8 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE
156167
pSt_ServerConfig->st_XPull.st_PullHls.nTime = st_PullHls["nTime"].asInt();
157168
_tcsxcpy(pSt_ServerConfig->st_XPull.st_PullHls.tszHLSPath, st_PullHls["tszHLSPath"].asCString());
158169

170+
pSt_ServerConfig->st_XPull.st_PullWebRtc.bEnable = st_PullWebRtc["bEnable"].asBool();
171+
pSt_ServerConfig->st_XPull.st_PullWebRtc.bPrePull = st_PullWebRtc["bPrePull"].asBool();
159172
_tcsxcpy(pSt_ServerConfig->st_XPull.st_PullWebRtc.tszICEUser, st_PullWebRtc["tszICEUser"].asCString());
160173
_tcsxcpy(pSt_ServerConfig->st_XPull.st_PullWebRtc.tszICEPass, st_PullWebRtc["tszICEPass"].asCString());
161174
_tcsxcpy(pSt_ServerConfig->st_XPull.st_PullWebRtc.tszCertStr, st_PullWebRtc["tszCertStr"].asCString());

XEngine_Source/XEngine_ServiceApp/XEngine_StreamMediaApp/StreamMedia_PullStream/PullStream_ClientGet.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,16 @@ bool PullStream_ClientGet_Handle(LPCXSTR lpszClientAddr, XCHAR*** ppptszListHdr,
130130
}
131131
else if (0 == _tcsxnicmp(tszVluBuffer, "xstream", 7))
132132
{
133-
if (!ModuleSession_PushStream_FindStream(tszSMSAddr, tszPushAddr))
133+
if (!st_ServiceConfig.st_XPull.st_PullXStream.bPrePull)
134134
{
135-
ModuleProtocol_Packet_Comm(tszRVBuffer, &nRVLen, NULL, 404, "not found");
136-
HttpProtocol_Server_SendMsgEx(xhHttpPacket, tszSDBuffer, &nSDLen, &st_HDRParam, tszRVBuffer, nRVLen);
137-
XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_HTTP);
138-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("拉流端:%s,请求拉流的URL参数不正确:%s,可能流不存在,错误:%lX"), lpszClientAddr, tszVluBuffer, ModuleSession_GetLastError());
139-
return false;
135+
if (!ModuleSession_PushStream_FindStream(tszSMSAddr, tszPushAddr))
136+
{
137+
ModuleProtocol_Packet_Comm(tszRVBuffer, &nRVLen, NULL, 404, "not found");
138+
HttpProtocol_Server_SendMsgEx(xhHttpPacket, tszSDBuffer, &nSDLen, &st_HDRParam, tszRVBuffer, nRVLen);
139+
XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_HTTP);
140+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("拉流端:%s,请求拉流的URL参数不正确:%s,可能流不存在,错误:%lX"), lpszClientAddr, tszVluBuffer, ModuleSession_GetLastError());
141+
return false;
142+
}
140143
}
141144
enStreamType = ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_PULL_XSTREAM;
142145
XENGINE_PROTOCOL_AVINFO st_AVInfo;
@@ -168,14 +171,19 @@ bool PullStream_ClientGet_Handle(LPCXSTR lpszClientAddr, XCHAR*** ppptszListHdr,
168171
}
169172
else if (0 == _tcsxnicmp(tszVluBuffer, "ts", 2))
170173
{
171-
if (!ModuleSession_PushStream_FindStream(tszSMSAddr, tszPushAddr))
174+
if (!st_ServiceConfig.st_XPull.st_PullTs.bPrePull)
172175
{
173-
ModuleProtocol_Packet_Comm(tszRVBuffer, &nRVLen, NULL, 404, "not found");
174-
HttpProtocol_Server_SendMsgEx(xhHttpPacket, tszSDBuffer, &nSDLen, &st_HDRParam, tszRVBuffer, nRVLen);
175-
XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_HTTP);
176-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("拉流端:%s,请求拉流的URL参数不正确:%s,可能流不存在,错误:%lX"), lpszClientAddr, tszVluBuffer, ModuleSession_GetLastError());
177-
return false;
176+
//TS流,需要预拉流
177+
if (!ModuleSession_PushStream_FindStream(tszSMSAddr, tszPushAddr))
178+
{
179+
ModuleProtocol_Packet_Comm(tszRVBuffer, &nRVLen, NULL, 404, "not found");
180+
HttpProtocol_Server_SendMsgEx(xhHttpPacket, tszSDBuffer, &nSDLen, &st_HDRParam, tszRVBuffer, nRVLen);
181+
XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_HTTP);
182+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("拉流端:%s,请求拉流的URL参数不正确:%s,可能流不存在,错误:%lX"), lpszClientAddr, tszVluBuffer, ModuleSession_GetLastError());
183+
return false;
184+
}
178185
}
186+
179187
enStreamType = ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_PULL_TS;
180188
//返回数据,为HTTP CHUNKED
181189
nSDLen = _xstprintf(tszSDBuffer, _X("HTTP/1.1 200 OK\r\n"

XEngine_Source/XEngine_ServiceApp/XEngine_StreamMediaApp/StreamMedia_PushStream/PushStream_SrtTask.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ bool PushStream_SrtTask_Connct(LPCXSTR lpszClientAddr, XSOCKET hSocket)
3535
{
3636
XCHAR tszPushAddr[128];
3737
memset(tszPushAddr, '\0', sizeof(tszPushAddr));
38-
//得到推流地址
39-
if (!ModuleSession_PushStream_FindStream(tszSMSAddr, tszPushAddr))
38+
if (!st_ServiceConfig.st_XPull.st_PullSrt.bPrePull)
4039
{
41-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("SRT客户端:%s,请求拉流的参数不正确:%s,错误:%lX"), lpszClientAddr, tszSMSAddr, ModuleSession_GetLastError());
42-
return false;
40+
//得到推流地址
41+
if (!ModuleSession_PushStream_FindStream(tszSMSAddr, tszPushAddr))
42+
{
43+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("SRT客户端:%s,请求拉流的参数不正确:%s,错误:%lX"), lpszClientAddr, tszSMSAddr, ModuleSession_GetLastError());
44+
return false;
45+
}
4346
}
4447
ModuleSession_PullStream_Insert(lpszClientAddr, tszSMSAddr, tszPushAddr, ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_PULL_SRT);
4548
ModuleSession_PushStream_ClientInsert(tszPushAddr, lpszClientAddr, ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_PULL_SRT);

0 commit comments

Comments
 (0)