From 0c98249d381d6e56c78d6e752a49e768a4c4d22e Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期五, 27 九月 2019 12:46:29 +0800 Subject: [PATCH] lib log fix --- csrc/worker/rec.cpp | 26 ++++++++++++++++---------- 1 files changed, 16 insertions(+), 10 deletions(-) diff --git a/csrc/worker/rec.cpp b/csrc/worker/rec.cpp index 4307d6e..d7ce012 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" @@ -40,7 +44,7 @@ list_recInfo_.emplace_back(info); } - std::unique_ptr<buz::Recorder> rec::startRec(std::string id, std::string dir, const int mind, const int maxd){ + std::unique_ptr<buz::Recorder> rec::startRec(std::string id, std::string dir, const int mind, const int maxd, const bool audio){ if(!recRef_){ logIt("Init wrapper first"); return nullptr; @@ -54,7 +58,7 @@ int trycnt = 0; while(trycnt < 100){ - auto ret = rec->Run(dir.c_str(), mind, maxd); + auto ret = rec->Run(dir.c_str(), mind, maxd, audio); if(ret == 0) break; usleep(200000); } @@ -133,7 +137,7 @@ return recRef_ != NULL; } - void rec::NewRec(const char* id, const char *output, const int mindur, const int maxdur){ + void rec::NewRec(const char* id, const char *output, const int mindur, const int maxdur, const bool audio){ std::string rid(id); std::string dir(output); @@ -145,7 +149,7 @@ if (map_rec_.find(rid) != map_rec_.end()){ map_rec_.erase(rid); } - map_rec_[rid] = startRec(rid, dir, mindur, maxdur); + map_rec_[rid] = startRec(rid, dir, mindur, maxdur, audio); } } @@ -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