From 91c3b892e976ecf33819c0c2664e4dfcfd88e434 Mon Sep 17 00:00:00 2001 From: chenshijun <csj_sky@126.com> Date: 星期六, 30 三月 2019 17:45:59 +0800 Subject: [PATCH] 添加新版本的GB28181代码 --- QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.h | 1 QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h | 2 QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.h | 3 + QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp | 29 +++++++++++--- QiaoJiaSystem/GB28181DecoderModel/GB28181Server.h | 15 ++++++- QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp | 10 ++++- QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp | 6 ++ 7 files changed, 53 insertions(+), 13 deletions(-) diff --git a/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp b/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp index 0cfd3b4..27a837d 100644 --- a/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp +++ b/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp @@ -32,7 +32,7 @@ dst.data, dst.linesize); sws_freeContext(convert_ctx); - DBG("m.size is " << m.size()); +// DBG("m.size is " << m.size()); // LOG_IF(); return m; @@ -197,6 +197,12 @@ vi = i; break; } + } + if(vi == -1)//鏃犺棰戝寘 + { + ERR("no video packet!!"); + p_this->m_running = false; + continue; } p_this->stream = p_this->ic->streams[vi]; p_this->video_st = p_this->stream; @@ -446,7 +452,7 @@ delete iter->m_packet.data; iter = m_packetsVec.erase(iter); while (!(iter->m_packet.flags & AV_PKT_FLAG_KEY)) { - INFO("DropFrame: " << iter->m_frameId); +// INFO("DropFrame: " << iter->m_frameId); delete iter->m_packet.data; iter = m_packetsVec.erase(iter); } diff --git a/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.h b/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.h index cdfe87e..a7dbb3f 100644 --- a/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.h +++ b/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.h @@ -37,6 +37,7 @@ } #include <mutex> +#include <basic/pipe/TimerElement.h> namespace BASICGB28181 { diff --git a/QiaoJiaSystem/GB28181DecoderModel/GB28181Server.h b/QiaoJiaSystem/GB28181DecoderModel/GB28181Server.h index ee5e6fd..515d716 100644 --- a/QiaoJiaSystem/GB28181DecoderModel/GB28181Server.h +++ b/QiaoJiaSystem/GB28181DecoderModel/GB28181Server.h @@ -17,6 +17,7 @@ #include <stdlib.h> #include <time.h> #include <string.h> +#include <VideoToImageMulth/RtspAnalysManager.h> #include "28181SDK.h" #include "SpinLock.hpp" @@ -80,10 +81,20 @@ //鎵撳嵃浜嬩欢鍥炶皟淇℃伅 static void enventcallback(int eventtype, int eventparam, int datalen, char *data) { printf("eventtype:%d, eventparam:%d, datalen:%d, data:%s\n", eventtype, eventparam, datalen, data); - if (eventtype == 2) { + if (eventtype == EVENT_DEVICE_CATALOG) { // GB28181Server::bGetLoaclRes = true; - } else if (eventtype == 1 && eventparam == 1) { + } else if (eventtype == EVENT_REGISTER_STATUS && eventparam == 1) { C_GetResource(NULL); + } else if (eventtype == EVENT_VIDEO_EXCEPTION){ + if(gRtspAnalysManagerCamera) { + auto cameraHandlePtr = (RtspAnalysManager *) gRtspAnalysManagerCamera; + ERR("gRtspAnalysManagerCamera ADDR:" << gRtspAnalysManagerCamera); + string camID(data, datalen); + ERR("EVENT_VIDEO_EXCEPTION reopen camID:" << camID); + cameraHandlePtr->addCamera(camID, camID); + }else{ + ERR("gRtspAnalysManagerCamera is nullptr"); + } } } diff --git a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp index b2acfc4..8859d91 100644 --- a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp +++ b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp @@ -111,14 +111,30 @@ 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) { -// if(p_this->m_fFmpegDecoderJPG.getRunning()) { - usleep(300000); -// }else{ -// p_this->m_running = false; -// break; -// } + 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: "); + + //鍏抽棴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 ..."); //鍋滄鐐规挱 @@ -187,6 +203,7 @@ INFO("grabFrame faild, element stopping"); return; } else { + //todo 涓氬姟姝婚攣 usleep(reopenTime * 1000); INFO("grabFrame faild, try reopen video: "); startRtpStream(m_streamTransType); diff --git a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h index 4722443..5f98e6a 100644 --- a/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h +++ b/QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h @@ -53,7 +53,7 @@ std::string MakeDir(const std::string &timeStamp); private: - int reopenTime{1000}; + int reopenTime{10}; int m_gpuIdx; int m_fps; int m_streamTransType; diff --git a/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp b/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp index ce56ad8..961c0c5 100644 --- a/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp +++ b/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp @@ -7,10 +7,11 @@ using std::string; +void *gRtspAnalysManagerCamera = nullptr; RtspAnalysManager::RtspAnalysManager(LDBTool *_dbTool) : m_lDBTool(nullptr), m_maxCount(50), m_currentCount(0) { // INFO("MYH DEBUG HERE"); - m_lDBTool = new LDBTool; + m_lDBTool = _dbTool; init(); } @@ -41,6 +42,9 @@ void RtspAnalysManager::init() { // INFO("MYH DEBUG HERE") + gRtspAnalysManagerCamera = this; + DBG("gRtspAnalysManagerCamera ADDR:" << gRtspAnalysManagerCamera); + m_GB28181_Enable = appPref.getIntData("GB28181_Enable"); //#todo GB28181 if (m_GB28181_Enable) { diff --git a/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.h b/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.h index fbd73ba..870c262 100644 --- a/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.h +++ b/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.h @@ -19,7 +19,8 @@ //#include <VideoToImageMulth/rpc/RtspAnalysServer.h> //using BASICGB28181::VideoCaptureElementWithRtp; - +//澶栭儴浣跨敤鐨勫叏灞�鎸囬拡 +extern void *gRtspAnalysManagerCamera; //鐢ㄦ潵瀹炵幇recordVideo鐨凴PC鐨勬帴鍙g被 class RtspAnalysManager : public ::RtspAnalys::RtspAnalysServer { -- Gitblit v1.8.0