Skip to content

Commit 1e958e0

Browse files
committed
fixed:screen stream push not work
1 parent db9c1fc commit 1e958e0

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_TaskPost/TaskPost_BackService.cpp

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ static bool bRecord = false;
44
static XHANDLE xhSound = NULL;
55
static XHANDLE xhScreen = NULL;
66
static XHANDLE xhStream = NULL;
7+
static XHANDLE xhAudioFifo = NULL;
78

89
void XCALLBACK HTTPTask_TaskPost_CBVideo(uint8_t* ptszAVBuffer, int nAVLen, AVCOLLECT_TIMEINFO* pSt_TimeInfo, XPVOID lParam)
910
{
@@ -14,9 +15,21 @@ void XCALLBACK HTTPTask_TaskPost_CBVideo(uint8_t* ptszAVBuffer, int nAVLen, AVCO
1415
}
1516
void XCALLBACK HTTPTask_TaskPost_CBAudio(uint8_t* ptszAVBuffer, int nAVLen, AVCOLLECT_TIMEINFO* pSt_TimeInfo, XPVOID lParam)
1617
{
17-
if (!XClient_StreamPush_LiveAudio(xhStream, ptszAVBuffer, nAVLen))
18+
if (AudioCodec_Help_FifoSend(xhAudioFifo, (LPCXSTR)ptszAVBuffer, nAVLen))
1819
{
19-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("音频采集器,推流编码失败,需要关闭推流服务,错误码:%lX"), StreamClient_GetLastError());
20+
while (true)
21+
{
22+
int nALen = 0;
23+
XBYTE tszAVBuffer[8192] = {};
24+
if (!AudioCodec_Help_FifoRecv(xhAudioFifo, tszAVBuffer, &nAVLen))
25+
{
26+
break;
27+
}
28+
if (!XClient_StreamPush_LiveAudio(xhStream, tszAVBuffer, nAVLen))
29+
{
30+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("音频采集器,推流编码失败,需要关闭推流服务,错误码:%lX"), StreamClient_GetLastError());
31+
}
32+
}
2033
}
2134
}
2235

@@ -334,12 +347,20 @@ bool HTTPTask_TaskPost_BackService(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer
334347
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,初始化音频采集器请求失败,错误码:%lX"), lpszClientAddr, AVCollect_GetLastError());
335348
return false;
336349
}
350+
xhAudioFifo = AudioCodec_Help_FifoInit(ENUM_AVCODEC_AUDIO_SAMPLEFMT_S16, 2);
351+
if (NULL == xhAudioFifo)
352+
{
353+
st_HDRParam.nHttpCode = 400;
354+
HttpProtocol_Server_SendMsgEx(xhHTTPPacket, m_MemorySend.get(), &nSDLen, &st_HDRParam);
355+
XEngine_Network_Send(lpszClientAddr, m_MemorySend.get(), nSDLen);
356+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,初始化音频采集器请求失败,错误码:%lX"), lpszClientAddr, AudioCodec_GetLastError());
357+
return false;
358+
}
337359
st_AVInfo.st_AudioInfo.bEnable = true;
338360
AVCollect_Audio_GetInfo(xhSound, &st_AVInfo);
339361
//音频编码参数
340362
st_AVInfo.st_AudioInfo.enAVCodec = ENUM_XENGINE_AVCODEC_AUDIO_TYPE_AAC;
341363
st_AVInfo.st_AudioInfo.nSampleFmt = ENUM_AVCODEC_AUDIO_SAMPLEFMT_S16;
342-
AVCollect_Audio_Start(xhSound);
343364
}
344365
//屏幕采集
345366
AVCOLLECT_SCREENINFO st_AVScreen;
@@ -378,7 +399,14 @@ bool HTTPTask_TaskPost_BackService(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer
378399
bRecord = true;
379400
XClient_StreamPush_LiveOutput(xhStream, tszAPIBuffer, _X("flv"));
380401
XClient_StreamPush_LiveCreate(xhStream, &st_AVInfo);
381-
402+
403+
AVCODEC_TIMEBASE st_VideoTime = {};
404+
AVCODEC_TIMEBASE st_AudioTime = {};
405+
AVCollect_Audio_GetTimeBase(xhSound, &st_AudioTime);
406+
AVCollect_Video_GetTimeBase(xhScreen, &st_VideoTime);
407+
XClient_StreamPush_LiveTime(xhStream, &st_VideoTime, &st_AudioTime);
408+
409+
AVCollect_Audio_Start(xhSound);
382410
AVCollect_Video_Start(xhScreen);
383411
XClient_StreamPush_LiveWriteHdr(xhStream);
384412
HttpProtocol_Server_SendMsgEx(xhHTTPPacket, m_MemorySend.get(), &nSDLen, &st_HDRParam);
@@ -393,6 +421,9 @@ bool HTTPTask_TaskPost_BackService(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer
393421
AVCollect_Video_Destory(xhScreen);
394422
AVCollect_Audio_Destory(xhSound);
395423
XClient_StreamPush_LiveClose(xhStream);
424+
xhScreen = NULL;
425+
xhSound = NULL;
426+
xhStream = NULL;
396427
bRecord = false;
397428
}
398429
HttpProtocol_Server_SendMsgEx(xhHTTPPacket, m_MemorySend.get(), &nSDLen, &st_HDRParam);

0 commit comments

Comments
 (0)