33static bool bRecord = false ;
44static XHANDLE xhSound = NULL ;
55static XHANDLE xhScreen = NULL ;
6- static XNETHANDLE xhAudio = 0 ;
7- static XNETHANDLE xhVideo = 0 ;
86static XHANDLE xhStream = NULL ;
97
108void XCALLBACK HTTPTask_TaskPost_CBVideo (uint8_t * ptszAVBuffer, int nAVLen, AVCOLLECT_TIMEINFO* pSt_TimeInfo, XPVOID lParam)
@@ -341,14 +339,6 @@ bool HTTPTask_TaskPost_BackService(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer
341339 // 音频编码参数
342340 st_AVInfo.st_AudioInfo .enAVCodec = ENUM_XENGINE_AVCODEC_AUDIO_TYPE_AAC;
343341 st_AVInfo.st_AudioInfo .nSampleFmt = ENUM_AVCODEC_AUDIO_SAMPLEFMT_S16;
344- if (!AudioCodec_Stream_EnInit (&xhAudio, &st_AVInfo.st_AudioInfo ))
345- {
346- st_HDRParam.nHttpCode = 400 ;
347- HttpProtocol_Server_SendMsgEx (xhHTTPPacket, m_MemorySend.get (), &nSDLen, &st_HDRParam);
348- XEngine_Network_Send (lpszClientAddr, m_MemorySend.get (), nSDLen);
349- XLOG_PRINT (xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X (" HTTP客户端:%s,初始化音频编码器失败,错误码:%lX" ), lpszClientAddr, AudioCodec_GetLastError ());
350- return false ;
351- }
352342 AVCollect_Audio_Start (xhSound);
353343 }
354344 // 屏幕采集
@@ -358,6 +348,7 @@ bool HTTPTask_TaskPost_BackService(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer
358348 st_AVScreen.nFrameRate = 24 ;
359349 st_AVScreen.nPosX = 0 ;
360350 st_AVScreen.nPosY = 0 ;
351+ _xstprintf (st_AVScreen.tszVideoSize , _X (" %s" ), _X (" 1920x1080" ));
361352#ifdef _MSC_BUILD
362353 xhScreen = AVCollect_Video_Init (" gdigrab" , tszDstBuffer, &st_AVScreen, HTTPTask_TaskPost_CBVideo);
363354#elif __linux__
@@ -374,17 +365,7 @@ bool HTTPTask_TaskPost_BackService(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer
374365 return false ;
375366 }
376367 AVCollect_Video_GetInfo (xhScreen, &st_AVInfo);
377-
378368 st_AVInfo.st_VideoInfo .enAVCodec = ENUM_XENGINE_AVCODEC_VIDEO_TYPE_H264;
379- if (!VideoCodec_Stream_EnInit (&xhVideo, &st_AVInfo.st_VideoInfo ))
380- {
381- st_HDRParam.nHttpCode = 400 ;
382- HttpProtocol_Server_SendMsgEx (xhHTTPPacket, m_MemorySend.get (), &nSDLen, &st_HDRParam);
383- XEngine_Network_Send (lpszClientAddr, m_MemorySend.get (), nSDLen);
384- XLOG_PRINT (xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X (" HTTP客户端:%s,初始化视频编码器失败,错误码:%lX" ), lpszClientAddr, VideoCodec_GetLastError ());
385- return false ;
386- }
387-
388369 xhStream = XClient_StreamPush_LiveInit ();
389370 if (NULL == xhStream)
390371 {
@@ -394,10 +375,12 @@ bool HTTPTask_TaskPost_BackService(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer
394375 XLOG_PRINT (xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X (" HTTP客户端:%s,推流:%s 请求失败,错误码:%lX" ), lpszClientAddr, tszDstBuffer, StreamClient_GetLastError ());
395376 return false ;
396377 }
378+ bRecord = true ;
397379 XClient_StreamPush_LiveOutput (xhStream, tszAPIBuffer, _X (" flv" ));
398380 XClient_StreamPush_LiveCreate (xhStream, &st_AVInfo);
399- bRecord = true ;
381+
400382 AVCollect_Video_Start (xhScreen);
383+ XClient_StreamPush_LiveWriteHdr (xhStream);
401384 HttpProtocol_Server_SendMsgEx (xhHTTPPacket, m_MemorySend.get (), &nSDLen, &st_HDRParam);
402385 XEngine_Network_Send (lpszClientAddr, m_MemorySend.get (), nSDLen);
403386 XLOG_PRINT (xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X (" HTTP客户端:%s,开始屏幕录制,音频:%s,视频:%s 推流:%s 请求成功" ), lpszClientAddr, tszSrcBuffer, tszDstBuffer, tszAPIBuffer);
@@ -410,8 +393,6 @@ bool HTTPTask_TaskPost_BackService(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer
410393 AVCollect_Video_Destory (xhScreen);
411394 AVCollect_Audio_Destory (xhSound);
412395 XClient_StreamPush_LiveClose (xhStream);
413- VideoCodec_Stream_Destroy (xhVideo);
414- AudioCodec_Stream_Destroy (xhAudio);
415396 bRecord = false ;
416397 }
417398 HttpProtocol_Server_SendMsgEx (xhHTTPPacket, m_MemorySend.get (), &nSDLen, &st_HDRParam);
0 commit comments