| | |
| | | using namespace ffwrapper; |
| | | using namespace cffmpeg_wrap::buz; |
| | | |
| | | static const int cache_time = 6 * 60; |
| | | static const int cache_time = 3 * 60 + 30; |
| | | |
| | | namespace cffmpeg_wrap |
| | | { |
| | | rec::rec() |
| | | :recRef_(NULL) |
| | | ,min_cache_len_(cache_time * 25) // 最小缓存?分钟的视频,因为整个流程会有延迟,暂定?分钟 |
| | | ,min_cache_len_(cache_time * 25) |
| | | {} |
| | | |
| | | rec::~rec() |
| | |
| | | list_recInfo_.emplace_back(info); |
| | | } |
| | | |
| | | void rec::findRecFramesIndex(const int64_t &fired_id, const int duration, int &start, int &end){ |
| | | void rec::findRecFramesIndex(int64_t &fired_id, const int duration, int &start, int &end){ |
| | | |
| | | start = end = -1; |
| | | |
| | |
| | | start_id = i.v_id; |
| | | } |
| | | } |
| | | }else if (recRef_->isVideoPkt(&i.data->getAVPacket())){ |
| | | }else { |
| | | // 视频帧,看是否缓存中有所有的duration数据 |
| | | if (i.v_id - start_id == duration){ |
| | | end = index; |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | // 如果fired_id在startid之前,将其放入start_id之后 |
| | | if (start_id > fired_id) fired_id = start_id + duration / 2; |
| | | |
| | | if (end < 0) end = index; |
| | | } |
| | |
| | | std::lock_guard<std::mutex> locker(mtx_pkt_); |
| | | logIt("cache size: %ld", list_pkt_.size()); |
| | | // 首次获取录像信息,先存一个最短时长 |
| | | findRecFramesIndex(frameID, duration, start, end); |
| | | rec->StartWritePacket(list_pkt_, frameID, start, end); |
| | | // maybe fired_id changed by findRecFramesIndex |
| | | int64_t fired_id = frameID; |
| | | findRecFramesIndex(fired_id, duration, start, end); |
| | | rec->StartWritePacket(list_pkt_, fired_id, start, end); |
| | | |
| | | return rec; |
| | | } |
| | |
| | | |
| | | void rec::SetRecMinCacheTime(const int min){ |
| | | // 由于整个流程耗时,补偿time_offset_ |
| | | int fps = 25; |
| | | if (recRef_){ |
| | | fps = recRef_->getFPS(); |
| | | } |
| | | min_cache_len_ += min * fps; |
| | | // int fps = 25; |
| | | // if (recRef_){ |
| | | // fps = recRef_->getFPS(); |
| | | // } |
| | | // if (min_cache_len_ > (cache_time+min) * fps){ |
| | | // return; |
| | | // } |
| | | // min_cache_len_ += min * fps; |
| | | } |
| | | |
| | | int rec::shrinkCache(){ |
| | | //超过最大缓存,丢弃gop |
| | | |
| | | while (list_pkt_.size() > min_cache_len_) { |
| | | list_pkt_.pop_front(); |
| | | while(!list_pkt_.empty()){ |