From a2ea58c567a078bb97a9e45a56fe50df41438d22 Mon Sep 17 00:00:00 2001
From: chenshijun <csj_sky@126.com>
Date: 星期一, 15 四月 2019 10:37:31 +0800
Subject: [PATCH] 整合c++ver1.3的修改代码进入该分支
---
QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp | 193 ++++++++++++++++++++++++++++++++++++++----------
1 files changed, 153 insertions(+), 40 deletions(-)
diff --git a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp
index 77862e7..2524d1d 100644
--- a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp
+++ b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp
@@ -5,19 +5,19 @@
#include <opencv2/imgproc.hpp>
#include <qt5/QtCore/QDateTime>
#include <basic/util/app/AppPreference.hpp>
+#include <basic/util/app/AppConfig.h>
#include "VideoCaptureElementWithRtp.h"
+#include <VideoToImageMulth/RtspAnalysManager.h>
//std::string BASICGB28181::VideoCaptureElementWithRtp::m_chanPubID;
//BASICGB28181::FFmpegDecoderJPG BASICGB28181::VideoCaptureElementWithRtp::m_fFmpegDecoderJPG;
BASICGB28181::VideoCaptureElementWithRtp::VideoCaptureElementWithRtp(std::string &chanPubID, int fps,
int streamTransType,
- int gpuIdx) : m_chanPubID(chanPubID), m_fps(fps),
- m_running(false),
- m_waitSignal(false),
- m_streamTransType(streamTransType),
- m_gpuIdx(gpuIdx),
- m_userdata((long) this) {
+ int gpuIdx, RtspAnalysManager *manager)
+ : m_chanPubID(chanPubID), m_fps(fps), m_running(false),
+ m_waitSignal(false), m_streamTransType(streamTransType),
+ m_gpuIdx(gpuIdx), m_userdata((long) this), m_pManager(manager) {
// m_chanPubID = chanPubID;
m_cutPath = appPref.getStringData("user.loop.absolute.path");
@@ -36,8 +36,83 @@
bool BASICGB28181::VideoCaptureElementWithRtp::startRtpStream(int streamTransType) {
+ if (!m_waitSignalrunning) {
+ DBG("std::thread waitSignalAndEmit create New!!");
+ //绛夊緟涓嬪眰ffmpeg灏唕tp鍖呰В鐮佹垚涓哄浘鐗囧悗瑙﹀彂淇″彿,鐒跺悗瑙﹀彂褰撳墠绫荤殑submit
+ std::thread waitSignalAndEmit([&](BASICGB28181::VideoCaptureElementWithRtp *p_this) {
+ p_this->m_waitSignal = true;
+ p_this->m_waitSignalrunning = 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
+ {
+ 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::VideoPublishElement(path, size_, "flv", 25, gupIdx);
+ p_this->videoPublishElement->start();
+ } else {
+// DBG("videoPublishElement->setImage() : " << p_this->m_chanPubID);
+ if (!p_this->m_image.empty()) {
+ p_this->videoPublishElement->setImage(p_this->m_image);
+ } else {
+ ERR("m_image.empty()");
+ }
+ }
+ } else {
+ 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);
+ }
+ }
+ }
+
+ /****褰曞儚妯″潡浠g爜*****/
+ p_this->m_picCount++;
+ //鍑犲紶閫変竴寮犳斁鍏edis
+ if (p_this->m_picCount % m_nPicsPickOne != 0) {
+ continue;
+ } else {
+ p_this->m_picCount.store(0);
+ }
+
+// 浠巉fmpeg瑙g爜绫讳腑鑾峰彇鍥剧墖
+ 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);
+ p_this->m_pManager->SaveImageToRedis(p_this->m_chanPubID, imageName, copyMat);
+ }
+ /*********/
+
+ p_this->submit();
+ }
+ p_this->m_waitSignalrunning = false;
+ INFO("waitSignalAndEmit is exit...");
+ }, this);
+ waitSignalAndEmit.detach();
+ }
+
TryCath(
//--------------鍥芥爣璁惧鎴栧垯鍥芥爣涓嬬骇骞冲彴蹇呴』鏀寔GB28181-2016----------------------------------------------
+ //瑙g爜绾跨▼锛屽彂璧风偣鎾姹傦紝鍚姩ffmpeg瑙g爜妯″潡
std::thread videoCaptureElementThd([&](VideoCaptureElementWithRtp *p_this, int streamType) {
DBG("videoCaptureElementThd start...");
StreamTransType_E etype;
@@ -62,23 +137,57 @@
}
DBG("C_RealVideoStart start... m_chanPubID is " << p_this->m_chanPubID << " etype is " << etype
<< " m_userdata is " << m_userdata);
+ //寮�濮嬬偣鎾棰�
long lrealhandle = C_RealVideoStart(const_cast<char *>(p_this->m_chanPubID.c_str()), etype,
p_this->streamcallback, m_userdata);
if (lrealhandle != -1) {
+ //鐐规挱鎴愬姛
DBG(p_this->m_chanPubID << " C_RealVideoStart ok ... type is " << etype);
p_this->m_running = true;
+ //鍚姩ffmpeg瑙g爜妯″潡
p_this->m_fFmpegDecoderJPG.startThd(p_this->m_chanPubID, p_this->m_fps, p_this->m_gpuIdx);
+ usleep(1000000);
+ //闃诲绾跨▼锛岀瓑寰呭閮ㄨЕ鍙戝叧闂偣鎾�
while (p_this->m_running) {
- usleep(300000);
+ if (p_this->m_fFmpegDecoderJPG.getRunning()) {
+ usleep(300000);
+ } else {
+
+ // 鏍规嵁reopenTime鍒ゆ柇鏄惁闇�瑕侀噸鍚�
+ if (reopenTime < 0) {
+ p_this->m_running = false;
+ stop();
+ INFO("grabFrame faild, element stopping");
+ } else {
+ //todo 涓氬姟姝婚攣
+ usleep((6 - reopenTime--) * 1000000);
+ INFO("grabFrame faild, try reopen video, reopenTime:" << reopenTime);
+
+ //鍏抽棴ffmpeg瑙g爜妯″潡
+ p_this->m_fFmpegDecoderJPG.stopThd();
+ //鍚姩ffmpeg瑙g爜妯″潡
+ p_this->m_fFmpegDecoderJPG.startThd(p_this->m_chanPubID, p_this->m_fps, p_this->m_gpuIdx);
+ continue;
+ }
+ }
}
DBG("videoCaptureElementThd stop ...");
+ //鍋滄鐐规挱
C_RealVideoStop(lrealhandle);
+ //灏唚aitSignalAndEmit 绾跨▼閫�鍑�
+ p_this->m_waitSignal = false;
DBG("videoCaptureElementThd stop ok...");
} else {
+ //鐐规挱澶辫触
+ p_this->m_waitSignal = false;
p_this->m_running = false;
+
+ //鍏抽棴ffmpeg瑙g爜妯″潡
p_this->m_fFmpegDecoderJPG.stopThd();
ERR(p_this->m_chanPubID << " C_RealVideoStart is error lrealhandle is " << lrealhandle);
+
+ p_this->startRtpStream(p_this->m_streamTransType);
}
}, this, streamTransType);
@@ -119,48 +228,44 @@
// fwrite(data, sizeof(char), datalen, fp11);
}
#endif
-
+ //灏嗗簳灞傜粍濂界殑rtp鍖咃紝瀛樺叆ffmpeg涓殑缂撳瓨闃熷垪
CHKDBG(p_this->m_fFmpegDecoderJPG.pushInfo(data, datalen, p_this->m_chanPubID), true,
"pushInfo is error !! handle is " << handle << " datatype is " << datatype << " frametype is " << frametype);
}
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");
+// DBG("videoPublishpath:" << path << " h:" << size_.height << " w:" << size_.width);
+// videoPublishElement = new ffmpeg::VideoPublishElement(path, size_, "flv", 25, gupIdx);
+// videoPublishElement->start();
+// } else {
+// if (!m_image.empty()) {
+// videoPublishElement->setImage(m_image);
+// } else {
+// ERR("m_image.empty()");
+// }
+// }
+// } else {
+// if (videoPublishElement != nullptr) {
+// DBG("videoPublishElement->stop()");
+// videoPublishElement->stop();
+// videoPublishElement->wait();
+// delete videoPublishElement;
+// videoPublishElement = nullptr;
+// }
+// }
+// }
+
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++;
- //鍑犲紶閫変竴寮犳斁鍏edis
- 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(m_camId, imageName, copyMat);
- }
- p_this->submit();
- }
- INFO("waitSignalAndEmit is exit...");
- }, this);
- waitSignalAndEmit.detach();
startRtpStream(m_streamTransType);
}
@@ -180,7 +285,7 @@
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);
@@ -208,3 +313,11 @@
return t_FilePath;
}
+
+void BASICGB28181::VideoCaptureElementWithRtp::startPublishVideo() {
+ m_publishVideoRet = true;
+}
+
+void BASICGB28181::VideoCaptureElementWithRtp::stopPublishVideo() {
+ m_publishVideoRet = false;
+}
--
Gitblit v1.8.0