派生自 development/c++

pansen
2019-04-03 17ae0cd78c16f55d38dc3f9ad6b27688f445aee3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//
// Created by ps on 19-1-10.
//
 
#ifndef GB28181SDK_VIDEOCAPTUREELEMENT_H
#define GB28181SDK_VIDEOCAPTUREELEMENT_H
 
#include "FFmpegDecoderJPG.h"
#include "28181SDK.h"
#include <basic/pipe/PipeElement.h>
//#include <RtspAnalysManager.h>
//#include <VideoToImageMulth/RtspAnalysManager.h>
 
class RtspAnalysManager;
 
namespace BASICGB28181 {
 
    class VideoCaptureElementWithRtp : public basic::PipeElement {
    public:
        /***
         * VideoCaptureElementWithRtp 视频解码
         * @param chanPubID 通道地(摄像机id)
         * @param fps
         * @param streamTransType 请求的视频流类型
         * @param gpuIdx gpuindex
         * @param manager 上层类的指针
         */
        explicit VideoCaptureElementWithRtp(std::string &chanPubID, int fps, int streamTransType, int gpuIdx = -1,
                                            RtspAnalysManager *manager = nullptr);
 
        virtual ~VideoCaptureElementWithRtp();
 
        /***
         * 获取当前实时流接收数据线程运行状态
         * @return
         */
        bool getRunning();
 
 
        /***
         * 获取图片
         * @return
         */
        cv::Mat getImage();
 
        //保存视频接口,从RtspAnalysManager发起调用
        void SaveVideo(const std::string &strImageName);
 
        //设置保存视频的最小和最大长度,单位是秒,实际的运行情况有一些差距,需要完善
        void SetVideoMinMaxSeconds(const int minSeconds, const int maxSeconds);
 
        //根据timeStamp创建路径
        std::string MakeDir(const std::string &timeStamp);
 
    private:
        int reopenTime{10};
        int m_gpuIdx;
        int m_fps;
        int m_streamTransType;
        std::string m_chanPubID;
        std::atomic<int> m_picCount{0};
        //几张图丢一张,目前是8张丢一张
        const int m_nPicsPickOne = 8;
        FFmpegDecoderJPG m_fFmpegDecoderJPG;
        cv::Mat m_image;
        long m_userdata;
        RtspAnalysManager *m_pManager;
 
        std::atomic<bool> m_running;
        std::atomic<bool> m_waitSignal;
        std::atomic<bool> m_waitSignalrunning;
 
        //用来保存录像视频的路径
        std::string m_cutPath;
    private:
        /***
         * 启动实时流接收数据线程
         * @param streamTransType 流数据发送方式
         * @return
         */
        bool startRtpStream(int streamTransType = 1);
 
        /***
         * 停止实时流接收数据线程
         * @return
         */
        bool stopRtpStream();
 
 
        /***
         * GB28181 SDK rtp组包回调函数
         * @param handle
         * @param datatype
         * @param frametype
         * @param data
         * @param datalen
         * @param userdata
         */
        static void streamcallback(long handle, int datatype, int frametype,
                                   unsigned char *data, int datalen, long userdata);
 
        virtual void threadFunc() override;
 
        virtual void threadInitial() override;
 
        virtual void threadClosing() override;
 
    };
 
}
 
 
#endif //GB28181SDK_VIDEOCAPTUREELEMENT_H