| | |
| | | namespace cffmpeg_wrap{ |
| | | using namespace buz; |
| | | |
| | | Wrapper::Wrapper() |
| | | Wrapper::Wrapper(const bool logit, const char *logfile) |
| | | :input_url_("") |
| | | ,scale_w_(0) |
| | | ,scale_h_(0) |
| | |
| | | ,rec_(new rec) |
| | | { |
| | | makeTheWorld(); |
| | | if (logit){ |
| | | logif::CreateLogger(logfile, true); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | logIt("WRAPPER EXCEPTION: ", e.what()); |
| | | } |
| | | logif::DestroyLogger(); |
| | | } |
| | | |
| | | std::unique_ptr<ffwrapper::FormatIn> Wrapper::init_reader(const char* input){ |
| | |
| | | |
| | | void Wrapper::AudioSwitch(const bool a){ |
| | | audio_ = a; |
| | | if (stream_){ |
| | | stream_->AudioSwitch(a); |
| | | } |
| | | // if (stream_){ |
| | | // stream_->AudioSwitch(a); |
| | | // } |
| | | } |
| | | |
| | | void Wrapper::init_worker(ffwrapper::FormatIn *in){ |
| | | if (rec_->Loaded() && stream_ && decoder_) return; |
| | | |
| | | stream_ = new stream(in, 3 * 25); |
| | | stream_->AudioSwitch(audio_); |
| | | // stream_->AudioSwitch(audio_); |
| | | |
| | | decoder_ = new decoder(in, scale_w_, scale_h_, scale_f_); |
| | | |
| | |
| | | } |
| | | |
| | | void Wrapper::run_worker(ffwrapper::FormatIn *in, std::shared_ptr<ffwrapper::CodedData> data, int64_t &id){ |
| | | |
| | | if (gb_){ |
| | | AVPacket &pkt = data->getAVPacket(); |
| | | pkt.pts = pkt.dts = AV_NOPTS_VALUE; |
| | | } |
| | | if (stream_) stream_->SetPacket(data, id); |
| | | if (decoder_ && run_dec_) decoder_->SetFrame(data, id); |
| | | if (rec_->Loaded()) rec_->SetPacket(data, id); |
| | |
| | | |
| | | void Wrapper::run_stream_thread(){ |
| | | |
| | | int tryTime = 0; |
| | | while(!stop_stream_.load()){ |
| | | auto in = init_reader(input_url_.c_str()); |
| | | |
| | | if (!in) { |
| | | logIt("ERROR: init_reader! url: %s\n", input_url_.c_str()); |
| | | usleep(200000); |
| | | tryTime++; |
| | | if (tryTime == 50){ |
| | | break; |
| | | } |
| | | continue; |
| | | } |
| | | |
| | |
| | | |
| | | init_worker(in.get()); |
| | | |
| | | int64_t id = -1; |
| | | int64_t id = gb_ ? 0 : -1; |
| | | |
| | | while(!stop_stream_.load()){ |
| | | auto data(std::make_shared<CodedData>()); |
| | | if (in->readPacket(&data->getAVPacket()) != 0){ |
| | | logIt("read packet error, id: %lld", id); |
| | | break; |
| | | } |
| | | if (id < 0){ |
| | | |
| | | if (!gb_ && id < 0){ |
| | | id++; |
| | | continue; |
| | | } |
| | | |
| | | |
| | | run_worker(in.get(), data, id); |
| | | usleep(wTime); |
| | | |
| | |
| | | } |
| | | |
| | | void Wrapper::BuildRecorder(const char* id, const char *output, const int mindur, const int maxdur, const bool audio){ |
| | | |
| | | bool a = audio; |
| | | if (gb_) a = false; |
| | | |
| | | if (rec_->Loaded()){ |
| | | rec_->NewRec(id, output, mindur, maxdur, audio); |
| | | rec_->NewRec(id, output, mindur, maxdur, a); |
| | | }else{ |
| | | std::string rid(id), dir(output); |
| | | fn_rec_lazy_ = |
| | | [=]{rec_->NewRec(rid.c_str(), dir.c_str(), mindur, maxdur, audio);}; |
| | | [=]{rec_->NewRec(rid.c_str(), dir.c_str(), mindur, maxdur, a);}; |
| | | } |
| | | } |
| | | |