From e878e92811a2dbfb6b4d3f7b2c357435f56e28db Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期日, 29 九月 2019 10:27:21 +0800
Subject: [PATCH] add trytime
---
csrc/worker/rec.cpp | 22 ++++++++++++++--------
1 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/csrc/worker/rec.cpp b/csrc/worker/rec.cpp
index 797e047..01896b0 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"
@@ -137,8 +141,8 @@
std::string rid(id);
std::string dir(output);
- minduration_ = mindur * 25;
- maxduration_ = maxdur * 25;
+ minduration_ = mindur * recRef_->getFPS();
+ maxduration_ = maxdur * recRef_->getFPS();
{
std::lock_guard<std::mutex> l(mtx_rec_);
@@ -181,12 +185,14 @@
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();
}
@@ -194,12 +200,12 @@
int rec::shrinkCache(){
//瓒呰繃鏈�澶х紦瀛�,涓㈠純gop
//缂撳瓨鏈�灏忛暱搴︾殑,鐢ㄤ簬璁板綍
- while (list_pkt_.size() > minduration_/2) {
+ int md = minduration_ < 201 ? 200 : minduration_;
+ 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