From 657185145236c12eb0fcf104b4712d8bb88efe16 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期六, 19 十月 2019 11:04:27 +0800
Subject: [PATCH] bug fix

---
 csrc/wrapper.cpp |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/csrc/wrapper.cpp b/csrc/wrapper.cpp
index 7149cbf..fe6d576 100644
--- a/csrc/wrapper.cpp
+++ b/csrc/wrapper.cpp
@@ -2,6 +2,7 @@
 
 #include <thread>
 #include <unistd.h>
+#include <sys/time.h>
 
 extern "C"{
 #include <libavformat/avformat.h>
@@ -188,7 +189,7 @@
                 sleep(2);
                 continue;
             }
-            
+
             int wTime = 1000000.0 / in->getFPS() ;
             wTime >>= 1;
             logIt("WAIT TIME PER FRAME: %d", wTime);
@@ -196,6 +197,8 @@
             init_worker(in.get());
 
             int64_t id = gb_ ? 0 : -1;
+            
+            bool exist = access(input_url_.c_str(), 0) == 0 ? true : false;
 
             while(!stop_stream_.load()){
                 auto data(std::make_shared<CodedData>());
@@ -203,20 +206,23 @@
                     logIt("read packet error, id: %lld", id);
                     break;
                 }
-
                 if (in->notVideoAudio(&data->getAVPacket())){
                     continue;
                 }
-                
+
                 if (!gb_ && id < 0){
                     id++;
                     continue;
                 }
+
     	        // decode error
                 if (run_worker(in.get(), data, id) == -1){
                     break;
                 }
-                usleep(wTime);
+
+                if (exist){
+                    usleep(wTime);
+                }
 
                 id++;
             }
@@ -225,6 +231,10 @@
         }
     }
 
+    void Wrapper::SetRecMinCacheTime(const int mind){
+        rec_->SetRecMinCacheTime(mind);
+    }
+
     void Wrapper::BuildRecorder(const char* id, const char *output, const int mindur, const int maxdur, const bool audio){
         bool a = audio;
         if (gb_) a = false;

--
Gitblit v1.8.0