Commit 8c180bab6c51d0632bc52cdc9249a579933fd857

Authored by hucm
1 parent 76d98954

添加是否实时流判断

src/FFNvDecoder.cpp
... ... @@ -3,6 +3,7 @@
3 3  
4 4 #include <chrono>
5 5 #include <thread>
  6 +#include <fstream>
6 7  
7 8 using namespace std;
8 9  
... ... @@ -36,6 +37,7 @@ FFNvDecoder::FFNvDecoder()
36 37 name = "";
37 38  
38 39 m_bPause = false;
  40 + m_bReal = true;
39 41 }
40 42  
41 43 FFNvDecoder::~FFNvDecoder()
... ... @@ -45,6 +47,14 @@ FFNvDecoder::~FFNvDecoder()
45 47  
46 48 bool FFNvDecoder::init(const string& path)
47 49 {
  50 + fstream infile(path);
  51 + if (infile.is_open()){
  52 + m_bReal = false;
  53 + infile.close();
  54 + }else {
  55 + m_bReal = true;
  56 + }
  57 +
48 58 // 查找对应的硬件解码设备
49 59 const char* device_name = "cuda";
50 60 AVHWDeviceType hw_device_type = av_hwdevice_find_type_by_name(device_name);
... ... @@ -157,10 +167,14 @@ void FFNvDecoder::decode_thread()
157 167  
158 168 while (m_bRunning)
159 169 {
160   - if (m_bPause)
  170 +
  171 + if (!m_bReal)
161 172 {
162   - std::this_thread::sleep_for(std::chrono::milliseconds(3));
163   - continue;
  173 + if (m_bPause)
  174 + {
  175 + std::this_thread::sleep_for(std::chrono::milliseconds(3));
  176 + continue;
  177 + }
164 178 }
165 179  
166 180 int result = av_read_frame(fmt_ctx, pkt);
... ... @@ -175,6 +189,16 @@ void FFNvDecoder::decode_thread()
175 189 break;
176 190 }
177 191  
  192 + if (!m_bReal)
  193 + {
  194 + if (m_bPause)
  195 + {
  196 + av_packet_unref(pkt);
  197 + std::this_thread::sleep_for(std::chrono::milliseconds(3));
  198 + continue;
  199 + }
  200 + }
  201 +
178 202 if (stream_index == pkt->stream_index)
179 203 {
180 204 result = avcodec_send_packet(avctx, pkt);
... ...
src/FFNvDecoder.h
... ... @@ -71,4 +71,6 @@ private:
71 71  
72 72 bool m_bPause;
73 73 FrameQueue mFrameQueue;
  74 +
  75 + bool m_bReal; // 是否实时流
74 76 };
75 77 \ No newline at end of file
... ...
src/main.cpp
... ... @@ -24,7 +24,7 @@ int main(){
24 24 pDecManager->setUserPtr("dec1", decoder);
25 25 pDecManager->startDecodeByName("dec1");
26 26  
27   - FFNvDecoder* dec2 = pDecManager->createDecoder("/home/cmhu/Proj_DxDecoder/data/test.mp4",postDecoded,"dec2");
  27 + FFNvDecoder* dec2 = pDecManager->createDecoder("/home/cmhu/data/test.mp4",postDecoded,"dec2");
28 28 if (!dec2)
29 29 {
30 30 return 1;
... ...