Blame view

src/decoder/dvpp/DvppRtpDecoder.h 3.52 KB
c027963f   Hu Chunming   ffmpeg6.1.1版本的接收rtp
1
2
3
4
5
6
7
8
9
  #ifndef __DVPP_RTP_DECODER_H__
  #define __DVPP_RTP_DECODER_H__
  
  #include <stdint.h>
  #include <atomic>
  #include <thread>
  #include <queue>
  #include <mutex>
  #include <chrono>
3c9776e9   Hu Chunming   代码优化
10
  #include <string>
c027963f   Hu Chunming   ffmpeg6.1.1版本的接收rtp
11
12
13
14
15
16
17
18
19
20
21
22
23
  
  #include "depend_headers.h"
  #include "dvpp_headers.h"
  #include "DvppDataMemory.hpp"
  
  #include "FFRecoderTaskManager.h"
  
  #include "VpcUtils.h"
  
  using namespace std;
  
  #define MAX_RTP_BUFFER_SIZE 4194304 // 4M = 4 * 1024 * 1024 = 4194304 字节
  
3c9776e9   Hu Chunming   代码优化
24
  
e5c14c8e   Hu Chunming   修复解码器异常退出时,接收器还在正...
25
26
  typedef void(*CallBack_DecodeFinished)(void* userdata);
  
c027963f   Hu Chunming   ffmpeg6.1.1版本的接收rtp
27
28
29
30
31
32
33
  class DvppRtpDecoder
  {
  public:
  	DvppRtpDecoder();
  	~DvppRtpDecoder();
  
  public:
c027963f   Hu Chunming   ffmpeg6.1.1版本的接收rtp
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
      bool Init(FFDecConfig cfg);
      void Close();
      bool start();
      void pause();
      void resume();
  
      void setDecKeyframe(bool bKeyframe);
  
      bool isRunning();
      bool isFinished();
      bool isPausing();
      bool getResolution( int &width, int &height );
      bool getOutResolution( int &width, int &height );
  
      bool isSurport(FFDecConfig& cfg);
  
      float fps();
  
      void setName(string nm){
          m_dec_name = nm;
      }
  
      string getName(){
          return m_dec_name;
      }
  
      DeviceMemory* snapshot();
  
      void setPostDecArg(const void* postDecArg);
      void setFinishedDecArg(const void* finishedDecArg);
  
  	DvppDataMemory* GetFrame();
  
      void doRecode(RecoderInfo& recoderInfo);
  
      void set_mq_callback(mq_callback_t cb);
  
  	void CacheBuffer(uint8_t* buf, int buf_size);
  
  	int ReadBuffer(uint8_t* buf, int buffsize);
  
e5c14c8e   Hu Chunming   修复解码器异常退出时,接收器还在正...
75
76
      void SetFinishedCallback(CallBack_DecodeFinished cb, void* param);
  
c027963f   Hu Chunming   ffmpeg6.1.1版本的接收rtp
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
  public:
      void doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *output, void *pUserData);
      void doProcessReport();
  
  private:
      bool init_dvpp(FFDecConfig cfg);
      void release_ffmpeg();
      void read_thread();
  	bool probe();//阻塞式探测国标流并获取解码参数
      
      int sendPkt(aclvdecChannelDesc *vdecChannelDesc, AVPacket* pkt, unsigned long long frame_nb);
      bool sendVdecEos(aclvdecChannelDesc *vdecChannelDesc);
      void release_dvpp();
  
      int getVdecType(int videoType, int profile);
  
      void calcOutResolution(int w, int h);
  
  private:
      FFDecConfig m_cfg;
      string m_dec_name;
  
      const void * m_finishedDecArg {nullptr};
c027963f   Hu Chunming   ffmpeg6.1.1版本的接收rtp
100
101
102
103
104
105
106
107
108
  
      bool m_bFinished{false};
      bool m_bRunning{false};
      bool m_bPause{false};
  
      bool m_bExitReportThd{false};
  
      // 读取数据
      AVFormatContext *fmt_ctx{nullptr};
c027963f   Hu Chunming   ffmpeg6.1.1版本的接收rtp
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
  	int  mVideoIndex {-1};
      AVPixelFormat pix_fmt;
      AVCodecContext *avctx{nullptr};
      AVBSFContext * h264bsfc{nullptr};
  
      int frame_width{0};
  	int frame_height{0};
      int out_frame_width{0};
  	int out_frame_height{0};
      float m_fps{0.0};
  
      std::thread* m_read_thread{nullptr};
  
      bool m_dec_keyframe {false};
      bool m_bResize {false};
  
      // 解码
      int m_dvpp_deviceId {-1};
      int m_dvpp_channel {-1};
      aclrtContext m_context{nullptr};
      acldvppStreamFormat m_enType;
  
      const void * m_postDecArg {nullptr};
      POST_DECODE_CALLBACK post_decoded_cbk {nullptr};
  
      int m_vdec_out_size {-1};
  
      FFRecoderTaskManager m_recoderManager;
  
      queue<DvppDataMemory*> m_decoded_data_queue;
      mutex m_decoded_data_queue_mtx;
  
      long long last_ts {0};
  
      long long m_last_read_ts {0};
  
      uint64_t m_in_count {0};
      uint64_t m_out_count {0};
  
      int m_frameSkip {1};
  
      std::atomic<int> m_DvppCacheCounter{0};
      int m_cache_gop{0};
  
      VpcUtils m_vpcUtils;
  
e5c14c8e   Hu Chunming   修复解码器异常退出时,接收器还在正...
155
156
157
      void*           m_finishParam;
  	CallBack_DecodeFinished m_finish_cbk;				// 录像流结束回调
  
341effc6   Hu Chunming   等待时间优化
158
159
      int m_buffer_waiting_time{3000} ;
  
3c9776e9   Hu Chunming   代码优化
160
161
162
      std::atomic<char> m_buffer[MAX_RTP_BUFFER_SIZE];
  	std::atomic_int   m_bufferSize {0};
  
c027963f   Hu Chunming   ffmpeg6.1.1版本的接收rtp
163
164
  };
  #endif //__DVPP_RTP_DECODER_H__