Commit 9a922a540331a84dd301eda625ebb38be6bded06

Authored by Hu Chunming
1 parent 7442c1d4

自动请求流修改到了sip服务端,解码器这里超过3分钟未收到流这自动结束解码器

src/decoder/gb28181/rtp/RTPUdpReceiver.cpp
@@ -62,7 +62,7 @@ static int connecting_thread_(void* param) @@ -62,7 +62,7 @@ static int connecting_thread_(void* param)
62 } 62 }
63 63
64 RTPUdpReceiver* self = (RTPUdpReceiver*)param; 64 RTPUdpReceiver* self = (RTPUdpReceiver*)param;
65 - return self->IsConnecting(); 65 + return self->CheckConnecting();
66 } 66 }
67 67
68 RTPUdpReceiver::RTPUdpReceiver() 68 RTPUdpReceiver::RTPUdpReceiver()
@@ -175,161 +175,37 @@ int RTPUdpReceiver::OnRtpRecv() @@ -175,161 +175,37 @@ int RTPUdpReceiver::OnRtpRecv()
175 return -1; 175 return -1;
176 } 176 }
177 177
  178 + m_bRecvExit = false;
  179 +
178 LOG_INFO("[{}] OnRtpRecv started.", m_SipChannelId); 180 LOG_INFO("[{}] OnRtpRecv started.", m_SipChannelId);
179 - while (!m_bRtpExit) 181 + while (!m_bRecvExit)
180 { 182 {
181 - //try  
182 - //{  
183 - m_rtpSessionPtr->Poll();  
184 - m_rtpSessionPtr->BeginDataAccess();  
185 -  
186 - if (m_rtpSessionPtr->GotoFirstSourceWithData()) 183 + m_rtpSessionPtr->Poll();
  184 + m_rtpSessionPtr->BeginDataAccess();
  185 +
  186 + if (m_rtpSessionPtr->GotoFirstSourceWithData())
  187 + {
  188 + // LOG_INFO("OnRtpRecv GotoFirstSourceWithData --{}", m_SipChannelId);
  189 + last_recv_ts = UtilTools::get_cur_time_ms();
  190 + m_idleCount = 0;
  191 + m_noDataCount = 0;
  192 + do
187 { 193 {
188 - // LOG_INFO("OnRtpRecv GotoFirstSourceWithData --{}", m_SipChannelId);  
189 - last_recv_ts = UtilTools::get_cur_time_ms();  
190 - m_idleCount = 0;  
191 - m_noDataCount = 0;  
192 - do 194 + RTPPacket* packet;
  195 + while ((packet = m_rtpSessionPtr->GetNextPacket()) != NULL)
193 { 196 {
194 - RTPPacket* packet;  
195 - while ((packet = m_rtpSessionPtr->GetNextPacket()) != NULL)  
196 - {  
197 - m_bNoData = false;  
198 - // LOG_INFO("OnRtpRecv GetNextPacket --{}", m_SipChannelId);  
199 - int ret = ParsePacket(packet);  
200 - m_rtpSessionPtr->DeletePacket(packet);  
201 -  
202 - if(ret != 0){  
203 - m_bRtpExit = true;  
204 - } 197 + m_bNoData = false;
  198 + // LOG_INFO("OnRtpRecv GetNextPacket --{}", m_SipChannelId);
  199 + int ret = ParsePacket(packet);
  200 + m_rtpSessionPtr->DeletePacket(packet);
  201 +
  202 + if(ret != 0){
  203 + m_bRecvExit = true;
205 } 204 }
206 - } while (m_rtpSessionPtr->GotoNextSourceWithData());  
207 - }  
208 - //else {  
209 - // if (m_idleCount != -1)  
210 - // {  
211 - // ++m_idleCount;//流中断计数  
212 - // }  
213 - // if (m_noDataCount != 0)  
214 - // {  
215 - // --m_noDataCount;//没流计数  
216 - // }  
217 - // //if (m_idleCount > 3000) {  
218 - // // m_hVodEndFunc(m_usrParam);  
219 - // // m_idleCount = 0;  
220 - // //历史流结束的时候,也会出现超时,这个是正常的  
221 - // if(m_usrParam && ((VideoSession *)GetUsrParam())->video_type() == VideoType::ERECORD)  
222 - // {  
223 - // if (m_idleCount > 10000)  
224 - // {  
225 - // //这里要判断下历史流是否结束,如果未结束,就设置为流中断  
226 - // //由于record_stream_status这个函数返回值不准确,所以增加一个进度条大于80%  
227 - // if(record_stream_status(((VideoSession *)GetUsrParam())->streamHandle()))  
228 - // {  
229 - // LOG_INFO("************Record stream is finished**{}**m_progress = {}********", m_SipChannelId, ((VideoSession *)GetUsrParam())->progress());  
230 - // m_idleCount = -1;  
231 - // m_hVodEndFunc(m_usrParam);  
232 - // record_stream_stop(((VideoSession *)GetUsrParam())->streamHandle());  
233 - // ((VideoSession *)GetUsrParam())->streamHandle().clear();  
234 - // }  
235 - // else  
236 - // {  
237 - // //如果此时进度大于80% 算完成吧  
238 - // if(((VideoSession *)GetUsrParam())->progress() > 0.80)  
239 - // {  
240 - // LOG_INFO("************Record stream is overtime**{}**m_progress = {}********", m_SipChannelId, ((VideoSession *)GetUsrParam())->progress());  
241 -  
242 - // m_idleCount = 0;  
243 - // m_hVodEndFunc(m_usrParam);  
244 - // record_stream_stop(((VideoSession *)GetUsrParam())->streamHandle());  
245 - // ((VideoSession *)GetUsrParam())->streamHandle().clear();  
246 - // }  
247 - // else  
248 - // {  
249 - // m_idleCount = -1;  
250 - // //LOG_ERROR("************post ERROR_REALSTREAM_INTERRUPT to structure****{}********", m_SipChannelId);  
251 - // //发送流中断  
252 - // //throw GeneralException2(ERROR_REALSTREAM_INTERRUPT, "Record time video streaming interruption!");  
253 - // }  
254 - // }  
255 - //  
256 - //  
257 - // }  
258 - //  
259 - // if (m_noDataCount < -200000)//任务开始时没收到流  
260 - // {  
261 - // //LOG_ERROR("************m_hVodEndFunc(m_usrParam)!!!m_hVodEndFunc(m_usrParam)********{}******", m_SipChannelId);  
262 - // m_noDataCount = -1;  
263 -  
264 - // //throw GeneralException2(ERROR_REALSTREAM_INTERRUPT, "Record time video streaming interruption2!");  
265 - // //m_hVodEndFunc(m_usrParam);  
266 - // }  
267 - // }  
268 - // else//实时任务断流  
269 - // //if (m_usrParam && ((VideoSession *)GetUsrParam())->video_type() == VideoType::EREAL)  
270 - // {  
271 - //  
272 - // //每超过3000次,发送一次send_vedio_eof 时长大约1.5s  
273 - // //若是30000,时长大约 18s  
274 - // if(m_idleCount > 30000)  
275 - // {  
276 - // uint64_t cts = UtilTools::get_cur_time_ms();  
277 - // float duration_not_recv = (cts - last_recv_ts) / 1000.0;  
278 - //  
279 - // //LOG_ERROR("************I haven't got stream from hik gateway exceed {}s,send eof********{}******", duration_not_recv, m_SipChannelId);  
280 - // m_idleCount = -1;  
281 -  
282 - // //throw GeneralException2(ERROR_REALSTREAM_INTERRUPT, "Real time video streaming interruption!");  
283 - // }  
284 - //  
285 - // if (m_noDataCount < -200000)//任务开始时没收到流  
286 - // {  
287 - // //LOG_ERROR("************m_noDataCount < -200000********{}******", m_SipChannelId);  
288 - // m_noDataCount = -1;  
289 -  
290 - // //throw GeneralException2(ERROR_REALSTREAM_INTERRUPT, "Real time video streaming interruption2!");  
291 - // }  
292 - //  
293 - // }  
294 - //}  
295 - //}  
296 - // catch (GeneralException2& e)  
297 - //{  
298 - // //LOG_ERROR("---> video streaming interruption!<---{}, error: {}", m_SipChannelId, e.err_msg());  
299 -  
300 - // byte_buffer bb(64);  
301 - // bb << VasCmd::VAS_CMD_REALSTREAM_INTERRUPT << e.err_msg();  
302 -  
303 - // if (m_usrParam)  
304 - // {  
305 - // if (((VideoSession *)GetUsrParam())->msgChan()->is_valid()) {  
306 - // try {  
307 - // ((VideoSession *)GetUsrParam())->msgChan()->send_msg(bb.data_ptr(), bb.data_size());  
308 - // }  
309 - // catch (GeneralException2& e) {  
310 - // //LOG_ERROR("[{}] send vas cmd VAS_CMD_REALSTREAM_INTERRUPT error: {}, {}", m_SipChannelId, e.err_code(), e.err_str());  
311 - // }  
312 - // }  
313 -  
314 - // //通知网关关闭句柄  
315 - // if(!((VideoSession *)GetUsrParam())->streamHandle().empty())  
316 - // {  
317 -  
318 - // LOG_INFO("---->Notify hisense gateway release handle = {} !<----{}", ((VideoSession *)GetUsrParam())->streamHandle().c_str(), m_SipChannelId);  
319 - // if (((VideoSession *)GetUsrParam())->video_type() == VideoType::EREAL)  
320 - // real_stream_stop(((VideoSession *)GetUsrParam())->streamHandle());  
321 - //  
322 - // if (((VideoSession *)GetUsrParam())->video_type() == VideoType::ERECORD)  
323 - // record_stream_stop(((VideoSession *)GetUsrParam())->streamHandle());  
324 - //  
325 - // //清理保活的句柄  
326 - // ((VideoSession *)GetUsrParam())->streamHandle().clear();  
327 - // }  
328 - // }  
329 - //  
330 - // bb.bset(0);  
331 - //  
332 - //} 205 + }
  206 + } while (m_rtpSessionPtr->GotoNextSourceWithData());
  207 + }
  208 +
333 m_rtpSessionPtr->EndDataAccess(); 209 m_rtpSessionPtr->EndDataAccess();
334 210
335 std::this_thread::sleep_for(std::chrono::milliseconds(10)); 211 std::this_thread::sleep_for(std::chrono::milliseconds(10));
@@ -351,24 +227,24 @@ bool RTPUdpReceiver::RequestStream() { @@ -351,24 +227,24 @@ bool RTPUdpReceiver::RequestStream() {
351 return true; 227 return true;
352 } 228 }
353 229
354 -int RTPUdpReceiver::IsConnecting() {  
355 - LOG_INFO("[{}] IsConnecting started.", m_SipChannelId); 230 +int RTPUdpReceiver::CheckConnecting() {
  231 + LOG_INFO("[{}] CheckConnecting started.", m_SipChannelId);
356 232
357 int count = 0; 233 int count = 0;
358 while (!m_bRtpExit) 234 while (!m_bRtpExit)
359 { 235 {
360 if (m_bNoData) { 236 if (m_bNoData) {
361 - bool bReq = RequestStream();  
362 - if (!bReq) {  
363 - LOG_INFO("[{}] RequestStream failed !", m_SipChannelId);  
364 - } 237 + // bool bReq = RequestStream();
  238 + // if (!bReq) {
  239 + // LOG_INFO("[{}] RequestStream failed !", m_SipChannelId);
  240 + // }
365 241
366 - wait_times(30); // 等待3s 242 + wait_times(50); // 等待5s
367 243
368 count++; 244 count++;
369 245
370 - if (count > 10) {  
371 - // 30s 依然没数据过来,则关闭 246 + if (count > 60) {
  247 + // 3min 依然没数据过来,则关闭
372 m_bRtpExit = true; 248 m_bRtpExit = true;
373 break; 249 break;
374 } 250 }
@@ -379,7 +255,7 @@ int RTPUdpReceiver::IsConnecting() { @@ -379,7 +255,7 @@ int RTPUdpReceiver::IsConnecting() {
379 } 255 }
380 } 256 }
381 257
382 - LOG_DEBUG("[{}] while", m_SipChannelId); 258 + m_bRecvExit = true;
383 259
384 // 结束整个任务 260 // 结束整个任务
385 WebsocketClient* pClient = WebsocketClient::getInstance(); 261 WebsocketClient* pClient = WebsocketClient::getInstance();
@@ -397,17 +273,13 @@ int RTPUdpReceiver::IsConnecting() { @@ -397,17 +273,13 @@ int RTPUdpReceiver::IsConnecting() {
397 m_rtpThreadPtr = nullptr; 273 m_rtpThreadPtr = nullptr;
398 } 274 }
399 275
400 - LOG_DEBUG("[{}] m_rtpThreadPtr", m_SipChannelId);  
401 -  
402 m_rtpSessionPtr->Destroy(); 276 m_rtpSessionPtr->Destroy();
403 277
404 - LOG_DEBUG("[{}] m_rtpSessionPtr", m_SipChannelId);  
405 -  
406 ClosePsThread(); 278 ClosePsThread();
407 279
408 m_bOpened = false; 280 m_bOpened = false;
409 281
410 - LOG_INFO("[{}] IsConnecting exited.", m_SipChannelId); 282 + LOG_INFO("[{}] CheckConnecting exited.", m_SipChannelId);
411 283
412 return 0; 284 return 0;
413 } 285 }
src/decoder/gb28181/rtp/RTPUdpReceiver.h
@@ -33,7 +33,7 @@ public: @@ -33,7 +33,7 @@ public:
33 33
34 public: 34 public:
35 int OnRtpRecv(); 35 int OnRtpRecv();
36 - int IsConnecting(); 36 + int CheckConnecting();
37 37
38 private: 38 private:
39 bool wait_times(int times); 39 bool wait_times(int times);
@@ -56,6 +56,7 @@ private: @@ -56,6 +56,7 @@ private:
56 string m_sip_channel_id; 56 string m_sip_channel_id;
57 57
58 std::atomic_bool m_bNoData{false}; 58 std::atomic_bool m_bNoData{false};
  59 + bool m_bRecvExit{false};
59 }; 60 };
60 61
61 #endif // _RTP_UDP_RECEIVER_H_ 62 #endif // _RTP_UDP_RECEIVER_H_