From d9952f61a53b693a75490e4932d7136e14e7dc08 Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期二, 01 九月 2020 15:22:05 +0800 Subject: [PATCH] bug fixed --- csrc/wrapper.cpp | 39 +++++++++++++++++++++++---------------- 1 files changed, 23 insertions(+), 16 deletions(-) diff --git a/csrc/wrapper.cpp b/csrc/wrapper.cpp index 7ad32f1..e0aef2d 100644 --- a/csrc/wrapper.cpp +++ b/csrc/wrapper.cpp @@ -45,6 +45,7 @@ ,audio_(false) ,gb_(0) ,cpu_(0) + ,devid_(-1) ,run_dec_(false) ,run_stream_(true) ,run_rec_(false) @@ -56,7 +57,7 @@ ,logit_(false) ,fps_(25) ,file_finished_(false) - ,min_duration_(60) + ,min_duration_(0) { makeTheWorld(); } @@ -66,6 +67,7 @@ ,audio_(false) ,gb_(0) ,cpu_(0) + ,devid_(-1) ,run_dec_(false) ,run_stream_(true) ,run_rec_(false) @@ -77,7 +79,7 @@ ,logit_(true) ,fps_(25) ,file_finished_(false) - ,min_duration_(60) + ,min_duration_(0) { makeTheWorld(); logif::CreateLogger(logfile, true); @@ -108,8 +110,9 @@ prop.url_ = input; prop.rtsp_tcp_ = true; prop.gpu_acc_ = !cpu_; + prop.gpu_index_ = devid_; - std::unique_ptr<FormatIn> in(new FormatIn(prop.gpuAccl())); + std::unique_ptr<FormatIn> in(new FormatIn(prop, prop.gpuAccl())); int flag = -1; if (gb_){ flag = in->openGb28181(input, NULL); @@ -193,7 +196,8 @@ void Wrapper::run_stream_thread(){ - int64_t rebootime = -1; + int64_t file_rebootime = 0; + int64_t file_frame = 0; while(!stop_stream_.load()){ auto in = init_reader(input_url_.c_str()); @@ -203,8 +207,6 @@ sleep(2); continue; } - - rebootime++; fps_ = in->getFPS(); @@ -223,9 +225,9 @@ bool exist = access(input_url_.c_str(), 0) == 0; if (exist){ - wTime <<= 1; + wTime += wTime/2; + file_rebootime++; } - int64_t file_frame = 0; logIt("WAIT TIME PER FRAME: %d", wTime); @@ -260,24 +262,29 @@ id++; //鏈湴鏂囦欢澶揩sleep涓�涓� - if (exist){ - usleep(wTime); + if (exist && in->isVideoPkt(&data->getAVPacket())){ // 璁板綍瑙g爜鐨勬枃浠舵湁澶氬皯甯� file_frame++; + usleep(wTime); } } deinit_worker(); if (exist) { - if (file_frame == 0 && rebootime > 3){ - file_finished_ = true; - break; - } - if (file_frame < min_duration_ * fps_){ + // 涓夋涓�甯ч兘娌¤В鍑烘潵锛岄��鍑� + if (file_frame == 0 && file_rebootime < 3){ + logIt("libcffmpeg.so-> run %lld time, current frames %lld", file_rebootime, file_frame); continue; } - logIt("libcffmpeg.so-> local file %s run %lld time, all frames %lld", input_url_.c_str(), rebootime, file_frame); + // 鏈�灏忛渶瑕佽В鍑哄灏戝抚 + if (file_frame < min_duration_ * fps_){ + logIt("libcffmpeg.so-> run %lld time, current frames %lld, mind %d, fps: %d", + file_rebootime, file_frame, min_duration_, fps_); + continue; + } + logIt("libcffmpeg.so-> local file %s run %lld time, all frames %lld, mind %d, fps: %d", + input_url_.c_str(), file_rebootime, file_frame, min_duration_, fps_); file_finished_ = true; break; } -- Gitblit v1.8.0