From 6de0bbb3eb860934bbe1c5e53a7ff02b8c0844f5 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期六, 19 十月 2019 10:44:37 +0800
Subject: [PATCH] udpate

---
 csrc/worker/rec.cpp |   30 +++++++++++++++++++-----------
 1 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/csrc/worker/rec.cpp b/csrc/worker/rec.cpp
index 797e047..14069ae 100644
--- a/csrc/worker/rec.cpp
+++ b/csrc/worker/rec.cpp
@@ -3,6 +3,10 @@
 #include <unistd.h>
 #include <sys/time.h>
 
+extern "C"{
+#include <libavcodec/avcodec.h>
+}
+
 #include "../ffmpeg/format/FormatIn.hpp"
 #include "../ffmpeg/data/CodedData.hpp"
 #include "../ffmpeg/log/log.hpp"
@@ -16,8 +20,8 @@
 {
     rec::rec()
     :recRef_(NULL)
-    ,minduration_(250)
-    ,maxduration_(750)
+    ,min_cache_len_(125)
+    ,time_offset_(4)
     {}
 
     rec::~rec()
@@ -137,9 +141,6 @@
         std::string rid(id);
         std::string dir(output);
         
-        minduration_ = mindur * 25;
-        maxduration_ = maxdur * 25;
-
         {
             std::lock_guard<std::mutex> l(mtx_rec_);
             if (map_rec_.find(rid) != map_rec_.end()){
@@ -181,25 +182,32 @@
         std::lock_guard<std::mutex> l(mtx_pkt_);
         //wait I 
         if (list_pkt_.empty()) {
-            AVPacket &avpkt = data->getAVPacket();
-            if (!(avpkt.flags & AV_PKT_FLAG_KEY)){
+
+            if (!(data->getAVPacket().flags & AV_PKT_FLAG_KEY)){
                 return;
             }
         }
+        
         list_pkt_.push_back({data, id});
+
         // 瓒呰繃缂撳瓨鏈�澶ч暱搴�,鍒犻櫎涓�涓猤op
         shrinkCache();
+    }
+
+    void rec::SetRecMinCacheTime(const int min){
+        // 鐢变簬鏁翠釜娴佺▼鑰楁椂,琛ュ伩time_offset_,鍥犱负鏄渶灏忕殑涓�鍗�,鍙湁time_offset_/2
+        min_cache_len_ = (min + time_offset_) * recRef_->getFPS();
     }
 
     int rec::shrinkCache(){
         //瓒呰繃鏈�澶х紦瀛�,涓㈠純gop
         //缂撳瓨鏈�灏忛暱搴︾殑,鐢ㄤ簬璁板綍
-        while (list_pkt_.size() > minduration_/2) {
+        int md = min_cache_len_ < 200 ? 200 : min_cache_len_;
+        while (list_pkt_.size() > md/2) {
             list_pkt_.pop_front();
             while(!list_pkt_.empty()){
-                auto &cache = list_pkt_.front();
-                AVPacket &avpkt = cache.data->getAVPacket();
-                if (!(avpkt.flags & AV_PKT_FLAG_KEY)){
+                auto &i = list_pkt_.front();
+                if (!(i.data->getAVPacket().flags & AV_PKT_FLAG_KEY)){
                     list_pkt_.pop_front();
                 }else{
                     break;

--
Gitblit v1.8.0