refactor(synthetic): make switch of disable copy and disable unnessary copy
This commit is contained in:
parent
c9bfdbb4d6
commit
f744fa06d5
|
@ -42,9 +42,9 @@ Processor::Processor(std::int32_t proc_period)
|
||||||
Processor::~Processor() {
|
Processor::~Processor() {
|
||||||
VLOG(2) << __func__;
|
VLOG(2) << __func__;
|
||||||
Deactivate();
|
Deactivate();
|
||||||
input_.reset(nullptr);
|
input_ = nullptr;
|
||||||
output_.reset(nullptr);
|
output_ = nullptr;
|
||||||
output_result_.reset(nullptr);
|
output_result_ = nullptr;
|
||||||
childs_.clear();
|
childs_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ bool Processor::IsIdle() {
|
||||||
return idle_;
|
return idle_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Processor::Process(const Object &in) {
|
bool Processor::Process(std::shared_ptr<Object> in) {
|
||||||
if (!activated_)
|
if (!activated_)
|
||||||
return false;
|
return false;
|
||||||
if (!idle_) {
|
if (!idle_) {
|
||||||
|
@ -132,13 +132,17 @@ bool Processor::Process(const Object &in) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!in.DecValidity()) {
|
if (in && !in->DecValidity()) {
|
||||||
LOG(WARNING) << Name() << " process with invalid input";
|
LOG(WARNING) << Name() << " process with invalid input";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lk(mtx_input_ready_);
|
std::lock_guard<std::mutex> lk(mtx_input_ready_);
|
||||||
input_.reset(in.Clone());
|
if (ProcessInputConnection() == WITH_CLONE) {
|
||||||
|
input_.reset(in->Clone());
|
||||||
|
} else {
|
||||||
|
input_ = in;
|
||||||
|
}
|
||||||
input_ready_ = true;
|
input_ready_ = true;
|
||||||
}
|
}
|
||||||
cond_input_ready_.notify_all();
|
cond_input_ready_.notify_all();
|
||||||
|
@ -229,12 +233,16 @@ void Processor::Run() {
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lk(mtx_result_);
|
std::unique_lock<std::mutex> lk(mtx_result_);
|
||||||
output_result_.reset(output_->Clone());
|
if (ProcessOutputConnection() == WITH_CLONE) {
|
||||||
|
output_result_.reset(output_->Clone());
|
||||||
|
} else {
|
||||||
|
output_result_ = output_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!childs_.empty()) {
|
if (!childs_.empty()) {
|
||||||
for (auto child : childs_) {
|
for (auto child : childs_) {
|
||||||
child->Process(*output_);
|
child->Process(output_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,6 +254,14 @@ void Processor::Run() {
|
||||||
VLOG(2) << Name() << " thread end";
|
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) {
|
api::StreamData Processor::GetStreamData(const Stream &stream) {
|
||||||
auto sum = getStreamsSum();
|
auto sum = getStreamsSum();
|
||||||
auto &&out = GetOutput();
|
auto &&out = GetOutput();
|
||||||
|
|
|
@ -64,7 +64,7 @@ class Processor :
|
||||||
bool IsIdle();
|
bool IsIdle();
|
||||||
|
|
||||||
/** Returns dropped or not. */
|
/** Returns dropped or not. */
|
||||||
bool Process(const Object &in);
|
bool Process(std::shared_ptr<Object> in);
|
||||||
|
|
||||||
virtual api::StreamData GetStreamData(const Stream &stream);
|
virtual api::StreamData GetStreamData(const Stream &stream);
|
||||||
|
|
||||||
|
@ -83,6 +83,13 @@ class Processor :
|
||||||
virtual bool OnProcess(
|
virtual bool OnProcess(
|
||||||
Object *const in, Object *const out,
|
Object *const in, Object *const out,
|
||||||
std::shared_ptr<Processor> const parent) = 0;
|
std::shared_ptr<Processor> const parent) = 0;
|
||||||
|
enum process_type{
|
||||||
|
WITH_CLONE,
|
||||||
|
WITHOUT_CLONE
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual process_type ProcessOutputConnection();
|
||||||
|
virtual process_type ProcessInputConnection();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Run in standalone thread. */
|
/** Run in standalone thread. */
|
||||||
|
@ -102,10 +109,10 @@ class Processor :
|
||||||
std::uint64_t dropped_count_;
|
std::uint64_t dropped_count_;
|
||||||
std::mutex mtx_state_;
|
std::mutex mtx_state_;
|
||||||
|
|
||||||
std::unique_ptr<Object> input_;
|
std::shared_ptr<Object> input_;
|
||||||
std::unique_ptr<Object> output_;
|
std::shared_ptr<Object> output_;
|
||||||
|
|
||||||
std::unique_ptr<Object> output_result_;
|
std::shared_ptr<Object> output_result_;
|
||||||
std::mutex mtx_result_;
|
std::mutex mtx_result_;
|
||||||
|
|
||||||
PreProcessCallback pre_callback_;
|
PreProcessCallback pre_callback_;
|
||||||
|
|
|
@ -31,6 +31,9 @@ class DepthProcessorOCV : public Processor {
|
||||||
std::string Name() override;
|
std::string Name() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
inline Processor::process_type ProcessOutputConnection() override {
|
||||||
|
return Processor::WITHOUT_CLONE;
|
||||||
|
}
|
||||||
Object *OnCreateOutput() override;
|
Object *OnCreateOutput() override;
|
||||||
bool OnProcess(
|
bool OnProcess(
|
||||||
Object *const in, Object *const out,
|
Object *const in, Object *const out,
|
||||||
|
|
|
@ -31,6 +31,12 @@ class DisparityNormalizedProcessor : public Processor {
|
||||||
std::string Name() override;
|
std::string Name() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
inline Processor::process_type ProcessOutputConnection() override {
|
||||||
|
return Processor::WITHOUT_CLONE;
|
||||||
|
}
|
||||||
|
inline Processor::process_type ProcessInputConnection() override {
|
||||||
|
return Processor::WITHOUT_CLONE;
|
||||||
|
}
|
||||||
Object *OnCreateOutput() override;
|
Object *OnCreateOutput() override;
|
||||||
bool OnProcess(
|
bool OnProcess(
|
||||||
Object *const in, Object *const out,
|
Object *const in, Object *const out,
|
||||||
|
|
|
@ -36,6 +36,9 @@ class PointsProcessor : public Processor {
|
||||||
std::string Name() override;
|
std::string Name() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
inline Processor::process_type ProcessOutputConnection() override {
|
||||||
|
return Processor::WITHOUT_CLONE;
|
||||||
|
}
|
||||||
Object *OnCreateOutput() override;
|
Object *OnCreateOutput() override;
|
||||||
bool OnProcess(
|
bool OnProcess(
|
||||||
Object *const in, Object *const out,
|
Object *const in, Object *const out,
|
||||||
|
|
|
@ -79,6 +79,12 @@ class RectifyProcessor : public Processor {
|
||||||
bool OnProcess(
|
bool OnProcess(
|
||||||
Object *const in, Object *const out,
|
Object *const in, Object *const out,
|
||||||
std::shared_ptr<Processor> const parent) override;
|
std::shared_ptr<Processor> const parent) override;
|
||||||
|
inline Processor::process_type ProcessOutputConnection() override {
|
||||||
|
return Processor::WITHOUT_CLONE;
|
||||||
|
}
|
||||||
|
inline Processor::process_type ProcessInputConnection() override {
|
||||||
|
return Processor::WITHOUT_CLONE;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InitParams(IntrinsicsEquidistant in_left,
|
void InitParams(IntrinsicsEquidistant in_left,
|
||||||
|
|
|
@ -49,6 +49,13 @@ class RectifyProcessorOCV : public Processor {
|
||||||
cv::Mat map11, map12, map21, map22;
|
cv::Mat map11, map12, map21, map22;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
inline Processor::process_type ProcessOutputConnection() override {
|
||||||
|
return Processor::WITHOUT_CLONE;
|
||||||
|
}
|
||||||
|
inline Processor::process_type ProcessInputConnection() override {
|
||||||
|
return Processor::WITHOUT_CLONE;
|
||||||
|
}
|
||||||
|
|
||||||
Object *OnCreateOutput() override;
|
Object *OnCreateOutput() override;
|
||||||
bool OnProcess(
|
bool OnProcess(
|
||||||
Object *const in, Object *const out,
|
Object *const in, Object *const out,
|
||||||
|
|
|
@ -73,7 +73,7 @@ void s1s2Processor::ProcessNativeStream(
|
||||||
}
|
}
|
||||||
if (left_data.img && right_data.img &&
|
if (left_data.img && right_data.img &&
|
||||||
left_data.img->frame_id == right_data.img->frame_id) {
|
left_data.img->frame_id == right_data.img->frame_id) {
|
||||||
Process(data_obj(left_data, right_data));
|
Process(std::make_shared<ObjMat2>(data_obj(left_data, right_data)));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,12 @@ class s1s2Processor : public RootProcessor {
|
||||||
api::StreamData GetStreamData(const Stream &stream) override;
|
api::StreamData GetStreamData(const Stream &stream) override;
|
||||||
std::vector<api::StreamData> GetStreamDatas(const Stream &stream) override; // NOLINT
|
std::vector<api::StreamData> GetStreamDatas(const Stream &stream) override; // NOLINT
|
||||||
protected:
|
protected:
|
||||||
|
inline Processor::process_type ProcessOutputConnection() override {
|
||||||
|
return Processor::WITHOUT_CLONE;
|
||||||
|
}
|
||||||
|
inline Processor::process_type ProcessInputConnection() override {
|
||||||
|
return Processor::WITHOUT_CLONE;
|
||||||
|
}
|
||||||
Object *OnCreateOutput() override;
|
Object *OnCreateOutput() override;
|
||||||
bool OnProcess(
|
bool OnProcess(
|
||||||
Object *const in, Object *const out,
|
Object *const in, Object *const out,
|
||||||
|
|
|
@ -364,6 +364,10 @@ void Synthetic::InitProcessors() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
root_processor->addTargetStreams(
|
||||||
|
{Stream::LEFT, Mode::MODE_OFF, nullptr});
|
||||||
|
root_processor->addTargetStreams(
|
||||||
|
{Stream::RIGHT, Mode::MODE_OFF, nullptr});
|
||||||
rectify_processor->addTargetStreams(
|
rectify_processor->addTargetStreams(
|
||||||
{Stream::LEFT_RECTIFIED, Mode::MODE_OFF, nullptr});
|
{Stream::LEFT_RECTIFIED, Mode::MODE_OFF, nullptr});
|
||||||
rectify_processor->addTargetStreams(
|
rectify_processor->addTargetStreams(
|
||||||
|
@ -376,10 +380,6 @@ void Synthetic::InitProcessors() {
|
||||||
{Stream::POINTS, Mode::MODE_OFF, nullptr});
|
{Stream::POINTS, Mode::MODE_OFF, nullptr});
|
||||||
depth_processor->addTargetStreams(
|
depth_processor->addTargetStreams(
|
||||||
{Stream::DEPTH, Mode::MODE_OFF, nullptr});
|
{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(root_processor);
|
||||||
processors_.push_back(rectify_processor);
|
processors_.push_back(rectify_processor);
|
||||||
|
@ -421,7 +421,8 @@ bool Synthetic::OnDeviceProcess(
|
||||||
Object *const in, Object *const out,
|
Object *const in, Object *const out,
|
||||||
std::shared_ptr<Processor> const parent) {
|
std::shared_ptr<Processor> const parent) {
|
||||||
MYNTEYE_UNUSED(parent)
|
MYNTEYE_UNUSED(parent)
|
||||||
return GetStreamEnabledMode(Stream::LEFT) != MODE_ON;
|
return GetStreamEnabledMode(Stream::LEFT) != MODE_ON
|
||||||
|
|| GetStreamEnabledMode(Stream::RIGHT) != MODE_ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Synthetic::OnRectifyProcess(
|
bool Synthetic::OnRectifyProcess(
|
||||||
|
@ -431,8 +432,8 @@ bool Synthetic::OnRectifyProcess(
|
||||||
if (plugin_ && plugin_->OnRectifyProcess(in, out)) {
|
if (plugin_ && plugin_->OnRectifyProcess(in, out)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return GetStreamEnabledMode(Stream::LEFT_RECTIFIED) != MODE_ON;
|
return GetStreamEnabledMode(Stream::LEFT_RECTIFIED) != MODE_ON
|
||||||
// && GetStreamEnabledMode(Stream::RIGHT_RECTIFIED) != MODE_ON
|
&& GetStreamEnabledMode(Stream::RIGHT_RECTIFIED) != MODE_ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Synthetic::OnDisparityProcess(
|
bool Synthetic::OnDisparityProcess(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user