| | |
| | | #include "worker/stream.hpp" |
| | | #include "worker/decoder.hpp" |
| | | #include "worker/rec.hpp" |
| | | #include "common.hpp" |
| | | |
| | | using namespace logif; |
| | | using namespace ffwrapper; |
| | |
| | | } |
| | | } |
| | | |
| | | int Wrapper::run_worker(ffwrapper::FormatIn *in, std::shared_ptr<ffwrapper::CodedData> data, int64_t &id){ |
| | | int Wrapper::run_worker(ffwrapper::FormatIn *in, const CPacket &pkt){ |
| | | if (gb_){ |
| | | AVPacket &pkt = data->getAVPacket(); |
| | | pkt.pts = pkt.dts = AV_NOPTS_VALUE; |
| | | AVPacket &p = pkt.data->getAVPacket(); |
| | | p.pts = p.dts = AV_NOPTS_VALUE; |
| | | } |
| | | int flag = 0; |
| | | if (stream_) stream_->SetPacket(data, id); |
| | | if (decoder_ && run_dec_) flag = decoder_->SetFrame(data, id); |
| | | if (rec_->Loaded()) rec_->SetPacket(data, id); |
| | | if (stream_) stream_->SetPacket(pkt); |
| | | if (decoder_ && run_dec_) flag = decoder_->SetFrame(pkt); |
| | | if (rec_->Loaded()) rec_->SetPacket(pkt); |
| | | |
| | | return flag; |
| | | } |
| | |
| | | init_worker(in.get()); |
| | | |
| | | int64_t id = gb_ ? 0 : -1; |
| | | |
| | | int64_t v_id = id; |
| | | int64_t a_id = id; |
| | | |
| | | bool exist = access(input_url_.c_str(), 0) == 0 ? true : false; |
| | | |
| | | while(!stop_stream_.load()){ |
| | |
| | | logIt("read packet error, id: %lld", id); |
| | | break; |
| | | } |
| | | // 非音视频 |
| | | if (in->notVideoAudio(&data->getAVPacket())){ |
| | | continue; |
| | | } |
| | | |
| | | // 非国标跳过第一帧,测试第一帧有问题 |
| | | if (!gb_ && id < 0){ |
| | | id++; |
| | | id++; v_id++; a_id++; |
| | | continue; |
| | | } |
| | | |
| | | CPacket pkt{data, v_id, a_id, id}; |
| | | // decode error |
| | | if (run_worker(in.get(), data, id) == -1){ |
| | | if (run_worker(in.get(), pkt) == -1){ |
| | | break; |
| | | } |
| | | |
| | | if (in->isVideoPkt(&data->getAVPacket())){ |
| | | v_id++; |
| | | }else{ |
| | | a_id++; |
| | | } |
| | | |
| | | id++; |
| | | |
| | | //本地文件太快sleep一下 |
| | | if (exist){ |
| | | usleep(wTime); |
| | | } |
| | | |
| | | id++; |
| | | } |
| | | |
| | | deinit_worker(); |
| | |
| | | void Wrapper::BuildRecorder(const char* id, const char *output, const int64_t &fid, const int mindur, const int maxdur, const bool audio){ |
| | | bool a = audio; |
| | | if (gb_) a = false; |
| | | |
| | | |
| | | if (rec_->Loaded()){ |
| | | rec_->NewRec(id, output, fid, mindur, maxdur, a); |
| | | }else{ |