| | |
| | | DBG("waitSignal(\"DecoderImageOK\") begin"); |
| | | #endif |
| | | //等待信号触发 |
| | | // DBG("waitSignal before: " << p_this->m_chanPubID); |
| | | gSignalLock.waitSignal(p_this->m_chanPubID + "DecoderImageOK"); |
| | | // DBG("waitSignal: " << p_this->m_chanPubID); |
| | | #ifdef TestCode |
| | | DBG("waitSignal(\"DecoderImageOK\") after"); |
| | | #endif |
| | | |
| | | |
| | | // 从ffmpeg解码类中获取图片 |
| | | // 从ffmpeg解码类中获取图片 |
| | | p_this->m_fFmpegDecoderJPG.getImage().copyTo(p_this->m_image); |
| | | /****debug*****///todo |
| | | if (p_this->m_image.empty()) { |
| | | ERR("camID:" << p_this->m_chanPubID); |
| | | continue; |
| | | } |
| | | // else { |
| | | // static int count =0; |
| | | // count ++; |
| | | // if(count > 100){ |
| | | // ERR("camID:" << p_this->m_chanPubID << " cols:" << p_this->m_image.cols <<\ |
| | | // " rows:" << p_this->m_image.rows << " channels:" << p_this->m_image.channels()); |
| | | // count = 0; |
| | | // } |
| | | // } |
| | | |
| | | { |
| | | /****录像模块代码*****/ |
| | | p_this->m_picCount++; |
| | | //几张选一张放入Redis |
| | | if (p_this->m_picCount % m_nPicsPickOne != 0) { |
| | | continue; |
| | | if (p_this->m_publishVideoRet) { |
| | | if (p_this->videoPublishElement == nullptr) { |
| | | string path = appConfig.getStringProperty("srsAddr") + "cam" + p_this->m_chanPubID + ".flv"; |
| | | cv::Size size_(appConfig.getIntProperty("pulish.width"), appConfig.getIntProperty("pulish.height")); |
| | | int gupIdx = appPref.getIntData("gpu.index"); |
| | | DBG("videoPublishpath: " << p_this->m_chanPubID << path << " h:" << size_.height); |
| | | p_this->videoPublishElement = new ffmpeg::PipeVideoPublishElement(path, size_, "flv", 25, gupIdx); |
| | | p_this->videoPublishElement->start(); |
| | | } else { |
| | | if (!p_this->m_image.empty()) { |
| | | p_this->videoPublishElement->setImage(p_this->m_image); |
| | | p_this->videoPublishElement->submit(); |
| | | } else { |
| | | ERR("m_image.empty()"); |
| | | } |
| | | } |
| | | } else { |
| | | p_this->m_picCount.store(0); |
| | | if (p_this->videoPublishElement != nullptr) { |
| | | DBG("videoPublishElement->stop() :" << p_this->m_chanPubID); |
| | | p_this->videoPublishElement->stop(); |
| | | p_this->videoPublishElement->wait(); |
| | | delete p_this->videoPublishElement; |
| | | p_this->videoPublishElement = nullptr; |
| | | }else{ |
| | | // DBG("videoPublishElement null :" << p_this->m_chanPubID); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /****录像模块代码*****/ |
| | | p_this->m_picCount++; |
| | | //几张选一张放入Redis |
| | | if (p_this->m_picCount % m_nPicsPickOne != 0) { |
| | | continue; |
| | | } else { |
| | | p_this->m_picCount.store(0); |
| | | } |
| | | |
| | | { |
| | | cv::Mat copyMat; |
| | | std::string imageName = p_this->m_fFmpegDecoderJPG.GetImageName(); |
| | | p_this->m_image.copyTo(copyMat); |
| | |
| | | } else { |
| | | |
| | | // 根据reopenTime判断是否需要重启 |
| | | if (reopenTime < 0) { |
| | | if (p_this->reopenTime < 0) { |
| | | p_this->m_running = false; |
| | | stop(); |
| | | INFO("grabFrame faild, element stopping"); |
| | | break; |
| | | } else { |
| | | //todo 业务死锁 |
| | | usleep((6 - reopenTime--) * 1000000); |
| | | INFO("grabFrame faild, try reopen video: "); |
| | | usleep((6 - p_this->reopenTime--) * 1000000); |
| | | INFO("grabFrame faild, try reopen video, reopenTime:" << p_this->reopenTime); |
| | | |
| | | //关闭ffmpeg解码模块 |
| | | p_this->m_fFmpegDecoderJPG.stopThd(); |
| | | //启动ffmpeg解码模块 |
| | | DBG("m_chanPubID:"<<p_this->m_chanPubID << " m_fps:" << p_this->m_fps); |
| | | p_this->m_fFmpegDecoderJPG.startThd(p_this->m_chanPubID, p_this->m_fps, p_this->m_gpuIdx); |
| | | continue; |
| | | } |
| | |
| | | |
| | | void BASICGB28181::VideoCaptureElementWithRtp::threadFunc() { |
| | | |
| | | if (m_publishVideoRet) { |
| | | if (videoPublishElement == nullptr) { |
| | | string path = appConfig.getStringProperty("srsAddr") + "cam" + m_chanPubID + ".flv"; |
| | | cv::Size size_(appConfig.getIntProperty("pulish.width"), appConfig.getIntProperty("pulish.height")); |
| | | int gupIdx = appPref.getIntData("gpu.index"); |
| | | videoPublishElement = new ffmpeg::VideoPublishElement(path, size_, "flv", 25, gupIdx); |
| | | } else { |
| | | videoPublishElement->stop(); |
| | | videoPublishElement->wait(); |
| | | delete videoPublishElement; |
| | | videoPublishElement = nullptr; |
| | | } |
| | | } |
| | | |
| | | fireConnectors(); |
| | | } |
| | | |
| | |
| | | |
| | | void BASICGB28181::VideoCaptureElementWithRtp::SaveVideo(const std::string &strImageName) { |
| | | |
| | | INFO("SaveVideo: " << strImageName); |
| | | // INFO("SaveVideo: " << strImageName); |
| | | std::string strTimeStamp = AppUtil::getTimeUSecString(); |
| | | std::string strPath = MakeDir(strTimeStamp); |
| | | m_fFmpegDecoderJPG.SaveVideoByImageName(strPath, strImageName); |