chenshijun
2019-03-30 438d661832cce9431ec1b56aa13aae61cb896b47
C_RealVideoStart失败后再次打开
2个文件已修改
97 ■■■■ 已修改文件
QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp 96 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.cpp
@@ -35,44 +35,49 @@
bool BASICGB28181::VideoCaptureElementWithRtp::startRtpStream(int streamTransType) {
    //等待下层ffmpeg将rtp包解码成为图片后触发信号,然后触发当前类的submit
    std::thread waitSignalAndEmit([&](BASICGB28181::VideoCaptureElementWithRtp *p_this) {
        p_this->m_waitSignal = true;
        //循环,由成员变量来维护这个线程的运行状态
        while (p_this->m_waitSignal) {
    if(!m_waitSignalrunning) {
        DBG("std::thread waitSignalAndEmit create New!!");
        //等待下层ffmpeg将rtp包解码成为图片后触发信号,然后触发当前类的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");
                DBG("waitSignal(\"DecoderImageOK\") begin");
#endif
            //等待信号触发
            gSignalLock.waitSignal(p_this->m_chanPubID + "DecoderImageOK");
                //等待信号触发
                gSignalLock.waitSignal(p_this->m_chanPubID + "DecoderImageOK");
#ifdef TestCode
            DBG("waitSignal(\"DecoderImageOK\") after");
                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_picCount++;
                //几张选一张放入Redis
                if (p_this->m_picCount % m_nPicsPickOne != 0) {
                    continue;
                } else {
                    p_this->m_picCount.store(0);
                }
//            从ffmpeg解码类中获取图片
            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->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();
                p_this->submit();
            }
            p_this->m_waitSignalrunning = false;
            INFO("waitSignalAndEmit is exit...");
        }, this);
        waitSignalAndEmit.detach();
    }
    TryCath(
    //--------------国标设备或则国标下级平台必须支持GB28181-2016----------------------------------------------
@@ -146,9 +151,12 @@
                //点播失败
                p_this->m_waitSignal = false;
                p_this->m_running = false;
                //关闭ffmpeg解码模块
                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);
@@ -196,20 +204,20 @@
void BASICGB28181::VideoCaptureElementWithRtp::threadFunc() {
    if ((!m_running) || (!m_waitSignal)) {
//        根据reopenTime判断是否需要重启
        if (reopenTime < 0) {
            stop();
            INFO("grabFrame faild, element stopping");
            return;
        } else {
            //todo 业务死锁
            usleep(reopenTime * 1000);
            INFO("grabFrame faild, try reopen video: ");
            startRtpStream(m_streamTransType);
            return;
        }
    }
//    if ((!m_running) || (!m_waitSignal)) {
////        根据reopenTime判断是否需要重启
//        if (reopenTime < 0) {
//            stop();
//            INFO("grabFrame faild, element stopping");
//            return;
//        } else {
//            //todo 业务死锁
//            usleep(reopenTime * 1000);
//            INFO("grabFrame faild, try reopen video: ");
//            startRtpStream(m_streamTransType);
//            return;
//        }
//    }
    fireConnectors();
}
QiaoJiaSystem/GB28181DecoderModel/VideoCaptureElementWithRtp.h
@@ -68,6 +68,7 @@
        std::atomic<bool> m_running;
        std::atomic<bool> m_waitSignal;
        std::atomic<bool> m_waitSignalrunning;
        //用来保存录像视频的路径
        std::string m_cutPath;