From f6aa35eedbc76e7467a68dbe3aba63ec8cb352a5 Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期五, 26 七月 2019 10:51:03 +0800 Subject: [PATCH] add log --- csrc/wrapper.cpp | 39 ++++++++++++++++++++++++++++++++++----- 1 files changed, 34 insertions(+), 5 deletions(-) diff --git a/csrc/wrapper.cpp b/csrc/wrapper.cpp index ec891ab..0b7b6ca 100644 --- a/csrc/wrapper.cpp +++ b/csrc/wrapper.cpp @@ -201,7 +201,7 @@ auto in = init_reader(input_url_.c_str()); if (!in) { - logIt("ERROR: init_reader!\n"); + logIt("ERROR: init_reader! url: %s\n", input_url_.c_str()); usleep(200000); continue; } @@ -218,15 +218,18 @@ pkt.id = id++; } pkt.data = data; + if(data != nullptr) { + cacheAVPacket(data->getAVPacket()); + } run_worker(in.get(), pkt); if(!data){ break; } //test - if(recorder_) - if(id % 250 == 0) - recorder_->FireRecorder(id); + // if(recorder_) + // if(id % 250 == 0) + // recorder_->FireRecorder(id); } } } @@ -274,6 +277,7 @@ info.file_frame_index = index; info.file_path = path; list_rec_.emplace_back(info); + logIt("list rec files count : %d", list_rec_.size()); } } @@ -288,6 +292,7 @@ index = info.file_frame_index; path = info.file_path; list_rec_.pop_front(); + logIt("go get info index: %d, file: %s\n", index, path.c_str()); } ////////decoder @@ -334,6 +339,30 @@ auto p = list_pic_.front(); *data = p.data; *w = p.w; *h = p.h; list_pic_.pop_front(); + } + + void Wrapper::GetPacket(unsigned char **pktData, int *size, int *key){ + std::lock_guard<std::mutex> l(mutex_avpkt_); + if(list_avpkt_.empty()){ + return; + } + auto pkt = list_avpkt_.front(); + *key = pkt.flags & AV_PKT_FLAG_KEY; + *size = pkt.size; + *pktData = (unsigned char *)malloc(*size); + memcpy(*pktData, pkt.data, pkt.size); + + list_avpkt_.pop_front(); + } + void Wrapper::cacheAVPacket(const AVPacket &pkt){ + std::lock_guard<std::mutex> l(mutex_pic_); + while(list_avpkt_.size() > 10){ +// printf("cacheAVPacket drop packets!!!!!!!!!!\n"); + for(int i = 0; i < 5; i++){ + list_avpkt_.pop_front(); + } + } + list_avpkt_.emplace_back(pkt); } void Wrapper::run_worker(ffwrapper::FormatIn *in, avpacket &pkt){ @@ -523,7 +552,7 @@ } *size = pkt.size + extradata_size; *out = (unsigned char *)malloc(*size); - + memcpy(*out, extra, extradata_size); memcpy(*out + extradata_size, pkt.data, pkt.size); -- Gitblit v1.8.0