Skip to content

Commit 24473b5

Browse files
committed
added:ts stream pull supported
1 parent 3567391 commit 24473b5

File tree

5 files changed

+25
-31
lines changed

5 files changed

+25
-31
lines changed

XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ typedef struct tag_XEngine_ServiceConfig
7575
{
7676
bool bEnable;
7777
}st_PullSrt;
78+
struct
79+
{
80+
bool bEnable;
81+
}st_PullTs;
7882
struct
7983
{
8084
bool bEnable;

XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE
120120
pSt_ServerConfig->st_XTime.nRTMPTimeout = st_JsonXTime["nRTMPTimeout"].asInt();
121121
pSt_ServerConfig->st_XTime.nJT1078Timeout = st_JsonXTime["nJT1078Timeout"].asInt();
122122
//时间配置
123-
if (st_JsonRoot["XPull"].empty() || (7 != st_JsonRoot["XPull"].size()))
123+
if (st_JsonRoot["XPull"].empty() || (8 != st_JsonRoot["XPull"].size()))
124124
{
125125
Config_IsErrorOccur = true;
126126
Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XPULL;
@@ -134,14 +134,16 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE
134134
Json::Value st_PullHls = st_Pull["HLS"];
135135
Json::Value st_PullWebRtc = st_Pull["RTC"];
136136
Json::Value st_PullSrt = st_Pull["SRT"];
137+
Json::Value st_PullTs = st_Pull["TS"];
137138

138139
pSt_ServerConfig->st_XPull.st_PullXStream.bEnable = st_PullXStream["bEnable"].asBool();
139140
pSt_ServerConfig->st_XPull.st_PullRtmp.bEnable = st_PullRtmp["bEnable"].asBool();
140141
pSt_ServerConfig->st_XPull.st_PullFlv.bEnable = st_PullFlv["bEnable"].asBool();
141142
pSt_ServerConfig->st_XPull.st_PullHls.bEnable = st_PullHls["bEnable"].asBool();
142143
pSt_ServerConfig->st_XPull.st_PullWebRtc.bEnable = st_PullWebRtc["bEnable"].asBool();
143144
pSt_ServerConfig->st_XPull.st_PullSrt.bEnable = st_PullSrt["bEnable"].asBool();
144-
145+
pSt_ServerConfig->st_XPull.st_PullTs.bEnable = st_Pull["bEnable"].asBool();
146+
145147
pSt_ServerConfig->st_XPull.st_PullRtsp.bEnable = st_PullRtsp["bEnable"].asBool();
146148
pSt_ServerConfig->st_XPull.st_PullRtsp.nVRTPPort = st_PullRtsp["nVRTPPort"].asInt();
147149
pSt_ServerConfig->st_XPull.st_PullRtsp.nVRTCPPort = st_PullRtsp["nVRTCPPort"].asInt();

XEngine_Source/XEngine_ModuleHelp/ModuleHelp_Error.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define ERROR_MODULE_HELP_SRT_ACCEPT 0xD1008 //接受失败
2828
#define ERROR_MODULE_HELP_SRT_GETID 0xD1009 //获取STREAMID
2929
#define ERROR_MODULE_HELP_SRT_NOTFOUND 0xD100A //没有找到
30+
#define ERROR_MODULE_HELP_SRT_SENDFAILED 0xD100B //发送失败
3031
//////////////////////////////////////////////////////////////////////////
3132
// 导出的RTSP错误
3233
//////////////////////////////////////////////////////////////////////////

XEngine_Source/XEngine_ServiceApp/XEngine_StreamMediaApp/StreamMedia_PullStream/PullStream_ClientGet.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -152,30 +152,15 @@ bool PullStream_ClientGet_Handle(LPCXSTR lpszClientAddr, XCHAR*** ppptszListHdr,
152152
}
153153
else if (0 == _tcsxnicmp(tszVluBuffer, "ts", 2))
154154
{
155-
int nPATLen = 0;
156-
int nPMTLen = 0;
157155
enStreamType = ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_PULL_TS;
158-
159-
memset(tszRVBuffer, '\0', sizeof(tszRVBuffer));
160-
memset(tszSDBuffer, '\0', sizeof(tszSDBuffer));
161-
162-
HLSProtocol_TSPacket_PATInfo(tszPushAddr, (XBYTE*)tszRVBuffer, &nPATLen);
163-
HLSProtocol_TSPacket_PMTInfo(tszPushAddr, (XBYTE*)tszRVBuffer + nPATLen, &nPMTLen);
164-
nRVLen = nPATLen + nPMTLen;
165156
//返回数据,为HTTP CHUNKED
166157
nSDLen = _xstprintf(tszSDBuffer, _X("HTTP/1.1 200 OK\r\n"
167158
"Connection: Close\r\n"
168159
"Content-Type: video/x-stream\r\n"
169160
"Server: XEngine/%s\r\n"
170161
"Access-Control-Allow-Origin: *\r\n"
171162
"Access-Control-Allow-Credentials: true\r\n"
172-
"Transfer-Encoding: chunked\r\n\r\n"
173-
"%x\r\n"), BaseLib_OperatorVer_XTypeStr(), nRVLen);
174-
memcpy(tszSDBuffer + nSDLen, tszRVBuffer, nRVLen);
175-
nSDLen += nRVLen;
176-
memcpy(tszSDBuffer + nSDLen, _X("\r\n"), 2);
177-
nSDLen += 2;
178-
163+
"Transfer-Encoding: chunked\r\n\r\n"), BaseLib_OperatorVer_XTypeStr());
179164
XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_HTTP);
180165

181166
ModuleSession_PullStream_Insert(lpszClientAddr, tszSMSAddr, tszPushAddr, enStreamType);

XEngine_Source/XEngine_ServiceApp/XEngine_StreamMediaApp/XEngine_AVPacket.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ bool XEngine_AVPacket_AVCreate(LPCXSTR lpszClientAddr)
2020
{
2121
RTMPProtocol_Packet_Insert(lpszClientAddr);
2222
}
23-
if (st_ServiceConfig.st_XPull.st_PullHls.bEnable || st_ServiceConfig.st_XPull.st_PullSrt.bEnable)
23+
if (st_ServiceConfig.st_XPull.st_PullHls.bEnable || st_ServiceConfig.st_XPull.st_PullSrt.bEnable || st_ServiceConfig.st_XPull.st_PullTs.bEnable)
2424
{
2525
HLSProtocol_TSPacket_Insert(lpszClientAddr, 100);
2626

@@ -386,13 +386,12 @@ bool XEngine_AVPacket_AVFrame(XCHAR* ptszSDBuffer, int* pInt_SDLen, XCHAR* ptszR
386386
}
387387
}
388388
}
389-
if (st_ServiceConfig.st_XPull.st_PullHls.bEnable || st_ServiceConfig.st_XPull.st_PullSrt.bEnable)
389+
if (st_ServiceConfig.st_XPull.st_PullHls.bEnable || st_ServiceConfig.st_XPull.st_PullSrt.bEnable || st_ServiceConfig.st_XPull.st_PullTs.bEnable)
390390
{
391-
int nListCount = 0;
392-
XBYTE** pptszMsgBuffer = NULL;
391+
*pInt_SDLen = 0;
393392
if (0 == byAVType)
394393
{
395-
HLSProtocol_TSPacket_AVPacket(lpszClientAddr, &pptszMsgBuffer, &nListCount, 0x100, lpszMsgBuffer, nMsgLen);
394+
HLSProtocol_TSPacket_AVPacket(lpszClientAddr, (XBYTE *)ptszSDBuffer, pInt_SDLen, 0x100, lpszMsgBuffer, nMsgLen);
396395
}
397396
else
398397
{
@@ -403,7 +402,7 @@ bool XEngine_AVPacket_AVFrame(XCHAR* ptszSDBuffer, int* pInt_SDLen, XCHAR* ptszR
403402
AVHelp_Packet_AACHdr((XBYTE*)byAACBuffer, st_AVInfo.st_AudioInfo.nSampleRate, st_AVInfo.st_AudioInfo.nChannel, nMsgLen);
404403
memcpy(byAACBuffer + 7, lpszMsgBuffer, nMsgLen);
405404
nMsgLen += 7;
406-
HLSProtocol_TSPacket_AVPacket(lpszClientAddr, &pptszMsgBuffer, &nListCount, 0x101, byAACBuffer, nMsgLen);
405+
HLSProtocol_TSPacket_AVPacket(lpszClientAddr, (XBYTE*)ptszSDBuffer, pInt_SDLen, 0x101, byAACBuffer, nMsgLen);
407406
}
408407

409408
int nPATLen = 0;
@@ -452,10 +451,7 @@ bool XEngine_AVPacket_AVFrame(XCHAR* ptszSDBuffer, int* pInt_SDLen, XCHAR* ptszR
452451
//HLS推流
453452
if (st_ServiceConfig.st_XPull.st_PullHls.bEnable)
454453
{
455-
for (int i = 0; i < nListCount; i++)
456-
{
457-
ModuleSession_PushStream_HLSWrite(lpszClientAddr, (LPCXSTR)pptszMsgBuffer[i], 188);
458-
}
454+
ModuleSession_PushStream_HLSWrite(lpszClientAddr, ptszSDBuffer, *pInt_SDLen);
459455
}
460456
//SRT推流
461457
if (st_ServiceConfig.st_XPull.st_PullSrt.bEnable)
@@ -472,14 +468,20 @@ bool XEngine_AVPacket_AVFrame(XCHAR* ptszSDBuffer, int* pInt_SDLen, XCHAR* ptszR
472468
XEngine_Network_Send(stl_ListIteratorClient->tszClientID, (LPCXSTR)tszPATBuffer, 188, ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_PUSH_SRT);
473469
XEngine_Network_Send(stl_ListIteratorClient->tszClientID, (LPCXSTR)tszPMTBuffer, 188, ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_PUSH_SRT);
474470
}
475-
for (int i = 0; i < nListCount; i++)
471+
XEngine_Network_Send(stl_ListIteratorClient->tszClientID, ptszSDBuffer, *pInt_SDLen, ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_PUSH_SRT);
472+
}
473+
if (ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_PULL_TS == stl_ListIteratorClient->enClientType)
474+
{
475+
//如果是关键帧
476+
if (1 == byFrameType)
476477
{
477-
XEngine_Network_Send(stl_ListIteratorClient->tszClientID, (LPCXSTR)pptszMsgBuffer[i], 188, ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_PUSH_SRT);
478+
XEngine_Network_Send(stl_ListIteratorClient->tszClientID, (LPCXSTR)tszPATBuffer, 188, ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_HTTP);
479+
XEngine_Network_Send(stl_ListIteratorClient->tszClientID, (LPCXSTR)tszPMTBuffer, 188, ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_HTTP);
478480
}
481+
XEngine_Network_Send(stl_ListIteratorClient->tszClientID, ptszSDBuffer, *pInt_SDLen, ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_HTTP);
479482
}
480483
}
481484
}
482-
BaseLib_OperatorMemory_Free((XPPPMEM)&pptszMsgBuffer, nListCount);
483485
}
484486
if (st_ServiceConfig.st_XPull.st_PullRtsp.bEnable)
485487
{

0 commit comments

Comments
 (0)