| | |
| | | |
| | | bool BASICGB28181::VideoCaptureElementWithRtp::startRtpStream(int streamTransType) { |
| | | |
| | | std::thread waitSignalAndEmit([&](BASICGB28181::VideoCaptureElementWithRtp *p_this) { |
| | | p_this->m_waitSignal = true; |
| | | while (p_this->m_waitSignal) { |
| | | //#TODO wait test |
| | | #ifdef TestCode |
| | | DBG("waitSignal(\"DecoderImageOK\") begin"); |
| | | #endif |
| | | gSignalLock.waitSignal(p_this->m_chanPubID + "DecoderImageOK"); |
| | | #ifdef TestCode |
| | | DBG("waitSignal(\"DecoderImageOK\") after"); |
| | | #endif |
| | | p_this->m_picCount++; |
| | | //几张选一张放入Redis |
| | | if (p_this->m_picCount % m_nPicsPickOne != 0) { |
| | | continue; |
| | | } else { |
| | | p_this->m_picCount.store(0); |
| | | } |
| | | |
| | | p_this->m_fFmpegDecoderJPG.getImage().copyTo(p_this->m_image); |
| | | { |
| | | cv::Mat copyMat; |
| | | std::string imageName = p_this->m_fFmpegDecoderJPG.GetImageName(); |
| | | p_this->m_image.copyTo(copyMat); |
| | | m_pManager->SaveImageToRedis(p_this->m_chanPubID, imageName, copyMat); |
| | | } |
| | | p_this->submit(); |
| | | } |
| | | INFO("waitSignalAndEmit is exit..."); |
| | | }, this); |
| | | waitSignalAndEmit.detach(); |
| | | |
| | | TryCath( |
| | | //--------------国标设备或则国标下级平台必须支持GB28181-2016---------------------------------------------- |
| | | std::thread videoCaptureElementThd([&](VideoCaptureElementWithRtp *p_this, int streamType) { |
| | |
| | | p_this->m_running = true; |
| | | p_this->m_fFmpegDecoderJPG.startThd(p_this->m_chanPubID, p_this->m_fps, p_this->m_gpuIdx); |
| | | while (p_this->m_running) { |
| | | usleep(300000); |
| | | // if(p_this->m_fFmpegDecoderJPG.getRunning()) { |
| | | usleep(300000); |
| | | // }else{ |
| | | // p_this->m_running = false; |
| | | // break; |
| | | // } |
| | | } |
| | | DBG("videoCaptureElementThd stop ..."); |
| | | C_RealVideoStop(lrealhandle); |
| | | p_this->m_waitSignal = false; |
| | | DBG("videoCaptureElementThd stop ok..."); |
| | | } else { |
| | | p_this->m_waitSignal = false; |
| | | p_this->m_running = false; |
| | | p_this->m_fFmpegDecoderJPG.stopThd(); |
| | | ERR(p_this->m_chanPubID << " C_RealVideoStart is error lrealhandle is " << lrealhandle); |
| | |
| | | } |
| | | |
| | | void BASICGB28181::VideoCaptureElementWithRtp::threadFunc() { |
| | | if ((!m_running) || (!m_waitSignal)) { |
| | | if (reopenTime < 0) { |
| | | stop(); |
| | | INFO("grabFrame faild, element stopping"); |
| | | return; |
| | | } else { |
| | | usleep(reopenTime * 1000); |
| | | INFO("grabFrame faild, try reopen video: "); |
| | | startRtpStream(m_streamTransType); |
| | | return; |
| | | } |
| | | } |
| | | fireConnectors(); |
| | | } |
| | | |
| | | void BASICGB28181::VideoCaptureElementWithRtp::threadInitial() { |
| | | |
| | | std::thread waitSignalAndEmit([&](BASICGB28181::VideoCaptureElementWithRtp *p_this) { |
| | | p_this->m_waitSignal = true; |
| | | while (p_this->m_waitSignal) { |
| | | //#TODO wait test |
| | | #ifdef TestCode |
| | | DBG("waitSignal(\"DecoderImageOK\") begin"); |
| | | #endif |
| | | gSignalLock.waitSignal(p_this->m_chanPubID + "DecoderImageOK"); |
| | | #ifdef TestCode |
| | | DBG("waitSignal(\"DecoderImageOK\") after"); |
| | | #endif |
| | | p_this->m_picCount++; |
| | | //几张选一张放入Redis |
| | | if (p_this->m_picCount % m_nPicsPickOne != 0) { |
| | | continue; |
| | | } else { |
| | | p_this->m_picCount.store(0); |
| | | } |
| | | |
| | | p_this->m_fFmpegDecoderJPG.getImage().copyTo(p_this->m_image); |
| | | { |
| | | cv::Mat copyMat; |
| | | std::string imageName = p_this->m_fFmpegDecoderJPG.GetImageName(); |
| | | p_this->m_image.copyTo(copyMat); |
| | | m_pManager->SaveImageToRedis(p_this->m_chanPubID, imageName, copyMat); |
| | | } |
| | | p_this->submit(); |
| | | } |
| | | INFO("waitSignalAndEmit is exit..."); |
| | | }, this); |
| | | waitSignalAndEmit.detach(); |
| | | startRtpStream(m_streamTransType); |
| | | } |
| | | |