bool VideoPipelineSource::Run() { while (!(sink_->IsExhausted() && sink_->GetQueueSize() == 0)) { FrameSetPtr frame_set_ptr; float timeout = 200; // 0.2 ms if (max_fps_ > 0) { timeout = 1.0f / max_fps_ * 1e6; // in micros. } if (sink_->TryFetchingFrameSet(&frame_set_ptr)) { // Measure time difference. boost::posix_time::ptime curr_time = boost::posix_time::microsec_clock::local_time(); if (frame_num_ > 0) { float micros_passed = boost::posix_time::time_period( prev_process_time_, curr_time).length().total_microseconds(); int wait_time = timeout - micros_passed; while (wait_time > 10) { OnIdle(); // Update wait time. curr_time = boost::posix_time::microsec_clock::local_time(); micros_passed = boost::posix_time::time_period( prev_process_time_, curr_time).length().total_microseconds(); wait_time = timeout - micros_passed; // We only sleep a fraction of the wait time to keep OnIdle going. if (wait_time > 100) { boost::thread::sleep(boost::get_system_time() + boost::posix_time::microseconds(wait_time / 5)); } } } // Update processing time. prev_process_time_ = boost::posix_time::microsec_clock::local_time(); // Pass to children. for (auto child : children_) { child->ProcessFrameImpl(frame_set_ptr, this); } ++frame_num_; } else { OnIdle(); boost::thread::sleep(boost::get_system_time() + boost::posix_time::microseconds(timeout / 5)); } } PostProcessImpl(this); return true; }
bool VideoUnit::Run() { // Initial frame_set is empty. PostProcessImpl(0); return true; }