From 25928e3093a7c0257128192d7785ec3f74e89e81 Mon Sep 17 00:00:00 2001
From: pans <pansen626@sina.com>
Date: 星期六, 30 三月 2019 12:46:20 +0800
Subject: [PATCH] 添加注释
---
QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.h | 7 +++
QiaoJiaSystem/GB28181DecoderModel/GB28181Server.cpp | 1
QiaoJiaSystem/GB28181DecoderModel/SpinLock.hpp | 4 +
QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h | 15 +++++++
QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp | 22 ++++++++++-
QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp | 19 ++++++---
6 files changed, 57 insertions(+), 11 deletions(-)
diff --git a/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp b/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp
index 7fa85cd..0cfd3b4 100644
--- a/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp
+++ b/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp
@@ -45,7 +45,9 @@
}
BASICGB28181::FFmpegDecoderJPG::~FFmpegDecoderJPG() {
+ //娓呯┖闃熷垪
while (m_rtpQueue.count_queue()) {
+ //#todo delete frameBuffInfo*
m_rtpQueue.popNotWait();
}
@@ -75,10 +77,9 @@
}
#ifdef TestCode
- DBG(" m_rtpQueue.push before ");
+ DBG(" m_rtpQueue.push befores ");
#endif
- m_rtpQueue.
- push(info);
+ m_rtpQueue.push(info);
#ifdef TestCode
DBG(" m_rtpQueue.push after ");
#endif
@@ -96,10 +97,11 @@
do {
// DBG(" m_rtpQueue.pop before ");
+ //浠庣紦瀛樹腑鑾峰彇buffinfo
frameBuffInfo *buffinfo = fFmpegDecoderJPG->m_rtpQueue.pop();
// DBG(" m_rtpQueue.pop after ");
diff = len - buffinfo->buffLen;
-// printf("bufsize is :%ld,len is :%ld, datalen:%d \n", bufsize, len, buffinfo->buffLen);
+
//甯ч暱澶т簬bufsize
if (diff < 0) {
// DBG("/甯ч暱澶т簬bufsize" << diff);
@@ -130,7 +132,7 @@
delete[] buffinfo->buff;
delete buffinfo;
} while (diff > 0);
- //#todo 瑙﹀彂淇″彿
+
// DBG("emitSigal(\"read_dataOk\") begin");
// gSignalLock.emitSigal("read_dataOk");
fFmpegDecoderJPG->m_readData = true;
@@ -151,12 +153,14 @@
// avformat_network_init();
p_this->ic = avformat_alloc_context();
+ //鍒涘缓ffmpeg浣跨敤鐨勫唴瀛樼┖闂�
p_this->iobuffer = (unsigned char *) av_malloc(p_this->m_buf_size);
if (!p_this->iobuffer) {
ERR("av_malloc: err======" << p_this->m_camIdx);
p_this->m_running = false;
continue;
}
+// 浣跨敤鍥炶皟鍑芥暟鍜屽唴瀛樺潡鍒涘缓 AVIOContext
p_this->avio = avio_alloc_context(p_this->iobuffer, p_this->m_buf_size, 0, p_this, p_this->read_data, NULL,
NULL);
if (!p_this->avio) {
@@ -267,7 +271,7 @@
// BASICGB28181::avframe_to_cvmat(frame).copyTo(p_this->m_image);
p_this->m_image = std::move(BASICGB28181::avframe_to_cvmat(p_this->frame));
-
+// 灏唅甯т繚瀛樹负蹇収
if (p_this->m_SnapshotNotSaveRet && (p_this->pkt.flags & AV_PKT_FLAG_KEY)) {
try {
std::string strNewName = "./";
@@ -304,7 +308,7 @@
#ifdef TestCode
DBG("emitSigal(\"DecoderImageOK\") begin");
#endif
- //瑙﹀彂淇″彿
+ //瑙﹀彂涓婂眰淇″彿
gSignalLock.emitSigal(p_this->m_camIdx + "DecoderImageOK");
//#ifdef TestCode
// DBG("emitSigal(\"DecoderImageOK\") after");
@@ -349,6 +353,7 @@
}
m_camIdx = camIdx;
DBG("BareFlowDecoderThd camIdx : " << camIdx);
+// 鍚姩瑙g爜绾跨▼
std::thread t_BareFlowDecoder(BareFlowDecoderThd, this);
t_BareFlowDecoder.detach();
);
diff --git a/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.h b/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.h
index dcfa1d2..cdfe87e 100644
--- a/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.h
+++ b/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.h
@@ -48,6 +48,11 @@
static void initFFmpeg();
+ /***
+ * AVframe杞琧vmat
+ * @param frame
+ * @return
+ */
static cv::Mat avframe_to_cvmat(AVFrame *frame);
typedef struct _buffInfo {
@@ -56,6 +61,7 @@
std::string camIdx;
} frameBuffInfo;
+ //************褰曞儚妯″潡浣跨敤鐨勭粨鏋勪綋********************//
struct FrameIdPackage_s_t {
int64_t m_frameId;
AVPacket m_packet;
@@ -82,6 +88,7 @@
RECORDING_VIDEO,
STOP_RECORD,
};
+ //********************************//
// std::map<std::string, MyQueue<frameBuffInfo *> > MapMyQueue;
static std::mutex g_mutex;
diff --git a/QiaoJiaSystem/GB28181DecoderModel/GB28181Server.cpp b/QiaoJiaSystem/GB28181DecoderModel/GB28181Server.cpp
index 44378a5..d10530a 100644
--- a/QiaoJiaSystem/GB28181DecoderModel/GB28181Server.cpp
+++ b/QiaoJiaSystem/GB28181DecoderModel/GB28181Server.cpp
@@ -52,6 +52,7 @@
bool iRet = C_InitSDK(&GBServerParam, &MysqlConnParam, NULL, enventcallback);
DBG("iRet is " << iRet);
+// 绛夊緟璁惧娉ㄥ唽
sleep(90);
return iRet;
diff --git a/QiaoJiaSystem/GB28181DecoderModel/SpinLock.hpp b/QiaoJiaSystem/GB28181DecoderModel/SpinLock.hpp
index e6e74f8..7737af6 100644
--- a/QiaoJiaSystem/GB28181DecoderModel/SpinLock.hpp
+++ b/QiaoJiaSystem/GB28181DecoderModel/SpinLock.hpp
@@ -6,7 +6,9 @@
#define GB28181SDK_SPINLOCK_H
#include <atomic>
-
+/***
+ * 鑷棆閿侊紝鍙兘浼氭湁娌¢攣涓婄殑bug
+ */
class SpinLock {
public:
SpinLock() : m_lock(ATOMIC_FLAG_INIT) {}
diff --git a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp
index 8a1d652..b2acfc4 100644
--- a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp
+++ b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp
@@ -35,17 +35,21 @@
bool BASICGB28181::VideoCaptureElementWithRtp::startRtpStream(int streamTransType) {
+ //绛夊緟涓嬪眰ffmpeg灏唕tp鍖呰В鐮佹垚涓哄浘鐗囧悗瑙﹀彂淇″彿,鐒跺悗瑙﹀彂褰撳墠绫荤殑submit
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
+ /****褰曞儚妯″潡浠g爜*****/
p_this->m_picCount++;
//鍑犲紶閫変竴寮犳斁鍏edis
if (p_this->m_picCount % m_nPicsPickOne != 0) {
@@ -54,6 +58,7 @@
p_this->m_picCount.store(0);
}
+// 浠巉fmpeg瑙g爜绫讳腑鑾峰彇鍥剧墖
p_this->m_fFmpegDecoderJPG.getImage().copyTo(p_this->m_image);
{
cv::Mat copyMat;
@@ -61,6 +66,8 @@
p_this->m_image.copyTo(copyMat);
m_pManager->SaveImageToRedis(p_this->m_chanPubID, imageName, copyMat);
}
+ /*********/
+
p_this->submit();
}
INFO("waitSignalAndEmit is exit...");
@@ -69,6 +76,7 @@
TryCath(
//--------------鍥芥爣璁惧鎴栧垯鍥芥爣涓嬬骇骞冲彴蹇呴』鏀寔GB28181-2016----------------------------------------------
+ //瑙g爜绾跨▼锛屽彂璧风偣鎾姹傦紝鍚姩ffmpeg瑙g爜妯″潡
std::thread videoCaptureElementThd([&](VideoCaptureElementWithRtp *p_this, int streamType) {
DBG("videoCaptureElementThd start...");
StreamTransType_E etype;
@@ -93,28 +101,36 @@
}
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);
+ //闃诲绾跨▼锛岀瓑寰呭閮ㄨЕ鍙戝叧闂偣鎾�
while (p_this->m_running) {
// if(p_this->m_fFmpegDecoderJPG.getRunning()) {
- usleep(300000);
+ usleep(300000);
// }else{
// p_this->m_running = false;
// break;
// }
}
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);
}
@@ -157,13 +173,15 @@
// 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_running) || (!m_waitSignal)) {
+// 鏍规嵁reopenTime鍒ゆ柇鏄惁闇�瑕侀噸鍚�
if (reopenTime < 0) {
stop();
INFO("grabFrame faild, element stopping");
diff --git a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h
index cc6b4b9..4722443 100644
--- a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h
+++ b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h
@@ -17,6 +17,14 @@
class VideoCaptureElementWithRtp : public basic::PipeElement {
public:
+ /***
+ * VideoCaptureElementWithRtp 瑙嗛瑙g爜
+ * @param chanPubID 閫氶亾鍦�(鎽勫儚鏈篿d)
+ * @param fps
+ * @param streamTransType 璇锋眰鐨勮棰戞祦绫诲瀷
+ * @param gpuIdx gpuindex
+ * @param manager 涓婂眰绫荤殑鎸囬拡
+ */
explicit VideoCaptureElementWithRtp(std::string &chanPubID, int fps, int streamTransType, int gpuIdx = -1,
RtspAnalysManager *manager = nullptr);
@@ -28,6 +36,11 @@
*/
bool getRunning();
+
+ /***
+ * 鑾峰彇鍥剧墖
+ * @return
+ */
cv::Mat getImage();
//淇濆瓨瑙嗛鎺ュ彛,浠嶳tspAnalysManager鍙戣捣璋冪敤
@@ -74,7 +87,7 @@
/***
- * rtp缁勫寘鍥炶皟鍑芥暟
+ * GB28181 SDK rtp缁勫寘鍥炶皟鍑芥暟
* @param handle
* @param datatype
* @param frametype
--
Gitblit v1.8.0