diff --git a/src/mynteye/api/processor.cc b/src/mynteye/api/processor.cc index 1f30e4c..175e0ba 100644 --- a/src/mynteye/api/processor.cc +++ b/src/mynteye/api/processor.cc @@ -42,9 +42,9 @@ Processor::Processor(std::int32_t proc_period) Processor::~Processor() { VLOG(2) << __func__; Deactivate(); - input_.reset(nullptr); - output_.reset(nullptr); - output_result_.reset(nullptr); + input_ = nullptr; + output_ = nullptr; + output_result_ = nullptr; childs_.clear(); } @@ -122,7 +122,7 @@ bool Processor::IsIdle() { return idle_; } -bool Processor::Process(const Object &in) { +bool Processor::Process(std::shared_ptr in) { if (!activated_) return false; if (!idle_) { @@ -132,13 +132,17 @@ bool Processor::Process(const Object &in) { return false; } } - if (!in.DecValidity()) { + if (in && !in->DecValidity()) { LOG(WARNING) << Name() << " process with invalid input"; return false; } { std::lock_guard lk(mtx_input_ready_); - input_.reset(in.Clone()); + if (ProcessInputConnection() == WITH_CLONE) { + input_.reset(in->Clone()); + } else { + input_ = in; + } input_ready_ = true; } cond_input_ready_.notify_all(); @@ -229,12 +233,16 @@ void Processor::Run() { } { std::unique_lock lk(mtx_result_); - output_result_.reset(output_->Clone()); + if (ProcessOutputConnection() == WITH_CLONE) { + output_result_.reset(output_->Clone()); + } else { + output_result_ = output_; + } } if (!childs_.empty()) { for (auto child : childs_) { - child->Process(*output_); + child->Process(output_); } } @@ -246,6 +254,14 @@ void Processor::Run() { VLOG(2) << Name() << " thread end"; } +Processor::process_type Processor::ProcessOutputConnection() { + return WITH_CLONE; +} + +Processor::process_type Processor::ProcessInputConnection() { + return WITH_CLONE; +} + api::StreamData Processor::GetStreamData(const Stream &stream) { auto sum = getStreamsSum(); auto &&out = GetOutput(); diff --git a/src/mynteye/api/processor.h b/src/mynteye/api/processor.h index 6ac1644..4cdaeac 100644 --- a/src/mynteye/api/processor.h +++ b/src/mynteye/api/processor.h @@ -64,7 +64,7 @@ class Processor : bool IsIdle(); /** Returns dropped or not. */ - bool Process(const Object &in); + bool Process(std::shared_ptr in); virtual api::StreamData GetStreamData(const Stream &stream); @@ -83,6 +83,13 @@ class Processor : virtual bool OnProcess( Object *const in, Object *const out, std::shared_ptr const parent) = 0; + enum process_type{ + WITH_CLONE, + WITHOUT_CLONE + }; + + virtual process_type ProcessOutputConnection(); + virtual process_type ProcessInputConnection(); private: /** Run in standalone thread. */ @@ -102,10 +109,10 @@ class Processor : std::uint64_t dropped_count_; std::mutex mtx_state_; - std::unique_ptr input_; - std::unique_ptr output_; + std::shared_ptr input_; + std::shared_ptr output_; - std::unique_ptr output_result_; + std::shared_ptr output_result_; std::mutex mtx_result_; PreProcessCallback pre_callback_; diff --git a/src/mynteye/api/processor/depth_processor_ocv.h b/src/mynteye/api/processor/depth_processor_ocv.h index 1618713..fbe7cd5 100644 --- a/src/mynteye/api/processor/depth_processor_ocv.h +++ b/src/mynteye/api/processor/depth_processor_ocv.h @@ -31,6 +31,9 @@ class DepthProcessorOCV : public Processor { std::string Name() override; protected: + inline Processor::process_type ProcessOutputConnection() override { + return Processor::WITHOUT_CLONE; + } Object *OnCreateOutput() override; bool OnProcess( Object *const in, Object *const out, diff --git a/src/mynteye/api/processor/disparity_normalized_processor.h b/src/mynteye/api/processor/disparity_normalized_processor.h index 1b61420..9c9fb0b 100644 --- a/src/mynteye/api/processor/disparity_normalized_processor.h +++ b/src/mynteye/api/processor/disparity_normalized_processor.h @@ -31,6 +31,12 @@ class DisparityNormalizedProcessor : public Processor { std::string Name() override; protected: + inline Processor::process_type ProcessOutputConnection() override { + return Processor::WITHOUT_CLONE; + } + inline Processor::process_type ProcessInputConnection() override { + return Processor::WITHOUT_CLONE; + } Object *OnCreateOutput() override; bool OnProcess( Object *const in, Object *const out, diff --git a/src/mynteye/api/processor/points_processor.h b/src/mynteye/api/processor/points_processor.h index 5cdf958..b9d1ab9 100644 --- a/src/mynteye/api/processor/points_processor.h +++ b/src/mynteye/api/processor/points_processor.h @@ -36,6 +36,9 @@ class PointsProcessor : public Processor { std::string Name() override; protected: + inline Processor::process_type ProcessOutputConnection() override { + return Processor::WITHOUT_CLONE; + } Object *OnCreateOutput() override; bool OnProcess( Object *const in, Object *const out, diff --git a/src/mynteye/api/processor/rectify_processor.h b/src/mynteye/api/processor/rectify_processor.h index 029ed6d..3ddb504 100644 --- a/src/mynteye/api/processor/rectify_processor.h +++ b/src/mynteye/api/processor/rectify_processor.h @@ -79,6 +79,12 @@ class RectifyProcessor : public Processor { bool OnProcess( Object *const in, Object *const out, std::shared_ptr const parent) override; + inline Processor::process_type ProcessOutputConnection() override { + return Processor::WITHOUT_CLONE; + } + inline Processor::process_type ProcessInputConnection() override { + return Processor::WITHOUT_CLONE; + } private: void InitParams(IntrinsicsEquidistant in_left, diff --git a/src/mynteye/api/processor/rectify_processor_ocv.h b/src/mynteye/api/processor/rectify_processor_ocv.h index 9c450ec..19e1ca7 100644 --- a/src/mynteye/api/processor/rectify_processor_ocv.h +++ b/src/mynteye/api/processor/rectify_processor_ocv.h @@ -49,6 +49,13 @@ class RectifyProcessorOCV : public Processor { cv::Mat map11, map12, map21, map22; protected: + inline Processor::process_type ProcessOutputConnection() override { + return Processor::WITHOUT_CLONE; + } + inline Processor::process_type ProcessInputConnection() override { + return Processor::WITHOUT_CLONE; + } + Object *OnCreateOutput() override; bool OnProcess( Object *const in, Object *const out, diff --git a/src/mynteye/api/processor/root_camera_processor.cc b/src/mynteye/api/processor/root_camera_processor.cc index a802b3a..2d7212f 100644 --- a/src/mynteye/api/processor/root_camera_processor.cc +++ b/src/mynteye/api/processor/root_camera_processor.cc @@ -73,7 +73,7 @@ void s1s2Processor::ProcessNativeStream( } if (left_data.img && right_data.img && left_data.img->frame_id == right_data.img->frame_id) { - Process(data_obj(left_data, right_data)); + Process(std::make_shared(data_obj(left_data, right_data))); } return; } diff --git a/src/mynteye/api/processor/root_camera_processor.h b/src/mynteye/api/processor/root_camera_processor.h index f7e1ed7..469067a 100644 --- a/src/mynteye/api/processor/root_camera_processor.h +++ b/src/mynteye/api/processor/root_camera_processor.h @@ -56,6 +56,12 @@ class s1s2Processor : public RootProcessor { api::StreamData GetStreamData(const Stream &stream) override; std::vector GetStreamDatas(const Stream &stream) override; // NOLINT protected: + inline Processor::process_type ProcessOutputConnection() override { + return Processor::WITHOUT_CLONE; + } + inline Processor::process_type ProcessInputConnection() override { + return Processor::WITHOUT_CLONE; + } Object *OnCreateOutput() override; bool OnProcess( Object *const in, Object *const out, diff --git a/src/mynteye/api/synthetic.cc b/src/mynteye/api/synthetic.cc index b9a5401..26c8947 100644 --- a/src/mynteye/api/synthetic.cc +++ b/src/mynteye/api/synthetic.cc @@ -364,6 +364,10 @@ void Synthetic::InitProcessors() { return; } + root_processor->addTargetStreams( + {Stream::LEFT, Mode::MODE_OFF, nullptr}); + root_processor->addTargetStreams( + {Stream::RIGHT, Mode::MODE_OFF, nullptr}); rectify_processor->addTargetStreams( {Stream::LEFT_RECTIFIED, Mode::MODE_OFF, nullptr}); rectify_processor->addTargetStreams( @@ -376,10 +380,6 @@ void Synthetic::InitProcessors() { {Stream::POINTS, Mode::MODE_OFF, nullptr}); depth_processor->addTargetStreams( {Stream::DEPTH, Mode::MODE_OFF, nullptr}); - root_processor->addTargetStreams( - {Stream::LEFT, Mode::MODE_OFF, nullptr}); - root_processor->addTargetStreams( - {Stream::RIGHT, Mode::MODE_OFF, nullptr}); processors_.push_back(root_processor); processors_.push_back(rectify_processor); @@ -421,7 +421,8 @@ bool Synthetic::OnDeviceProcess( Object *const in, Object *const out, std::shared_ptr const parent) { MYNTEYE_UNUSED(parent) - return GetStreamEnabledMode(Stream::LEFT) != MODE_ON; + return GetStreamEnabledMode(Stream::LEFT) != MODE_ON + || GetStreamEnabledMode(Stream::RIGHT) != MODE_ON; } bool Synthetic::OnRectifyProcess( @@ -431,8 +432,8 @@ bool Synthetic::OnRectifyProcess( if (plugin_ && plugin_->OnRectifyProcess(in, out)) { return true; } - return GetStreamEnabledMode(Stream::LEFT_RECTIFIED) != MODE_ON; - // && GetStreamEnabledMode(Stream::RIGHT_RECTIFIED) != MODE_ON + return GetStreamEnabledMode(Stream::LEFT_RECTIFIED) != MODE_ON + && GetStreamEnabledMode(Stream::RIGHT_RECTIFIED) != MODE_ON; } bool Synthetic::OnDisparityProcess(