diff --git a/src/mynteye/api/synthetic.cc b/src/mynteye/api/synthetic.cc index f519370..a92287c 100644 --- a/src/mynteye/api/synthetic.cc +++ b/src/mynteye/api/synthetic.cc @@ -158,16 +158,9 @@ const struct Synthetic::stream_control_t Synthetic::getControlDateWithStream( std::shared_ptr Synthetic::getProcessorWithStream( const Stream& stream) { - // for (auto &&it : processors_) { - // std::cout << it->Name(); - // for (auto it_s : it->getTargetStreams()) { - // std::cout << it_s.stream << "----" << it_s.mode << std::endl; - // } - // } for (auto &&it : processors_) { for (auto it_s : it->getTargetStreams()) { if (it_s.stream == stream) { - // std::cout << it_s.stream << "----" << it_s.mode << std::endl; return it; } } @@ -190,20 +183,20 @@ void Synthetic::setControlDateCallbackWithStream( LOG(ERROR) << "ERROR: no suited processor for stream "<< ctr_data.stream; } -void Synthetic::setControlDateModeWithStream( - const struct stream_control_t& ctr_data) { - for (auto &&it : processors_) { - int i = 0; - for (auto it_s : it->getTargetStreams()) { - if (it_s.stream == ctr_data.stream) { - it->target_streams_[i].mode = ctr_data.mode; - return; - } - i++; - } - } - LOG(ERROR) << "ERROR: no suited processor for stream "<< ctr_data.stream; -} +// void Synthetic::setControlDateModeWithStream( +// const struct stream_control_t& ctr_data) { +// for (auto &&it : processors_) { +// int i = 0; +// for (auto it_s : it->getTargetStreams()) { +// if (it_s.stream == ctr_data.stream) { +// it->target_streams_[i].mode = ctr_data.mode; +// return; +// } +// i++; +// } +// } +// LOG(ERROR) << "ERROR: no suited processor for stream "<< ctr_data.stream; +// } bool Synthetic::checkControlDateWithStream(const Stream& stream) const { for (auto &&it : processors_) { @@ -220,15 +213,15 @@ bool Synthetic::checkControlDateWithStream(const Stream& stream) const { // return checkControlDateWithStream(stream); // } -Synthetic::status_mode_t Synthetic::GetStreamStatusMode( - const Stream &stream) const { - if (checkControlDateWithStream(stream)) { - auto ctrData = getControlDateWithStream(stream); - return ctrData.mode; - } else { - return MODE_STATUS_LAST; - } -} +// Synthetic::status_mode_t Synthetic::GetStreamStatusMode( +// const Stream &stream) const { +// if (checkControlDateWithStream(stream)) { +// auto ctrData = getControlDateWithStream(stream); +// return ctrData.mode; +// } else { +// return MODE_STATUS_LAST; +// } +// } // void Synthetic::EnableStreamData(const Stream &stream) { // // Activate processors of synthetic stream @@ -283,15 +276,24 @@ bool Synthetic::IsStreamDataEnabled(const Stream &stream) const { void Synthetic::SetStreamCallback( const Stream &stream, stream_callback_t callback) { + stream_control_t data; + data.stream = stream; if (callback == nullptr) { - stream_callbacks_.erase(stream); + data.stream_callback = nullptr; } else { - stream_callbacks_[stream] = callback; + data.stream_callback = callback; } + setControlDateCallbackWithStream(data); } bool Synthetic::HasStreamCallback(const Stream &stream) const { - return stream_callbacks_.find(stream) != stream_callbacks_.end(); + if (checkControlDateWithStream(stream)) { + auto data = getControlDateWithStream(stream); + if (data.stream_callback != nullptr) { + return true; + } + } + return false; } void Synthetic::StartVideoStreaming() { @@ -308,7 +310,8 @@ void Synthetic::StartVideoStreaming() { ProcessNativeStream(stream, stream_data); // Need mutex if set callback after start if (HasStreamCallback(stream)) { - stream_callbacks_.at(stream)(stream_data); + auto data = getControlDateWithStream(stream); + data.stream_callback(stream_data); } }, true); @@ -790,14 +793,22 @@ void Synthetic::InitProcessors() { std::make_shared(RECTIFY_PROC_PERIOD); root_processor->AddChild(rectify_processor); - rectify_processor->addTargetStreams({Stream::LEFT_RECTIFIED, StatusMode::MODE_STATUS_LAST, Mode::MODE_LAST, Mode::MODE_LAST, nullptr}); - rectify_processor->addTargetStreams({Stream::RIGHT_RECTIFIED, StatusMode::MODE_STATUS_LAST, Mode::MODE_LAST, Mode::MODE_LAST, nullptr}); - disparity_processor->addTargetStreams({Stream::DISPARITY, StatusMode::MODE_STATUS_LAST, Mode::MODE_LAST, Mode::MODE_LAST, nullptr}); - disparitynormalized_processor->addTargetStreams({Stream::DISPARITY_NORMALIZED, StatusMode::MODE_STATUS_LAST, Mode::MODE_LAST, Mode::MODE_LAST, nullptr}); - points_processor->addTargetStreams({Stream::POINTS, StatusMode::MODE_STATUS_LAST, Mode::MODE_LAST, Mode::MODE_LAST, nullptr}); - depth_processor->addTargetStreams({Stream::DEPTH, StatusMode::MODE_STATUS_LAST, Mode::MODE_LAST, Mode::MODE_LAST, nullptr}); - root_processor->addTargetStreams({Stream::LEFT, StatusMode::MODE_STATUS_LAST, Mode::MODE_NATIVE, Mode::MODE_NATIVE, nullptr}); - root_processor->addTargetStreams({Stream::RIGHT, StatusMode::MODE_STATUS_LAST, Mode::MODE_NATIVE, Mode::MODE_NATIVE, nullptr}); + rectify_processor->addTargetStreams( + {Stream::LEFT_RECTIFIED, Mode::MODE_LAST, Mode::MODE_LAST, nullptr}); + rectify_processor->addTargetStreams( + {Stream::RIGHT_RECTIFIED, Mode::MODE_LAST, Mode::MODE_LAST, nullptr}); + disparity_processor->addTargetStreams( + {Stream::DISPARITY, Mode::MODE_LAST, Mode::MODE_LAST, nullptr}); + disparitynormalized_processor->addTargetStreams( + {Stream::DISPARITY_NORMALIZED, Mode::MODE_LAST, Mode::MODE_LAST, nullptr}); + points_processor->addTargetStreams( + {Stream::POINTS, Mode::MODE_LAST, Mode::MODE_LAST, nullptr}); + depth_processor->addTargetStreams( + {Stream::DEPTH, Mode::MODE_LAST, Mode::MODE_LAST, nullptr}); + root_processor->addTargetStreams( + {Stream::LEFT, Mode::MODE_NATIVE, Mode::MODE_NATIVE, nullptr}); + root_processor->addTargetStreams( + {Stream::RIGHT, Mode::MODE_NATIVE, Mode::MODE_NATIVE, nullptr}); processors_.push_back(root_processor); processors_.push_back(rectify_processor); @@ -1007,11 +1018,13 @@ bool Synthetic::OnDepthProcess( void Synthetic::OnRectifyPostProcess(Object *const out) { const ObjMat2 *output = Object::Cast(out); if (HasStreamCallback(Stream::LEFT_RECTIFIED)) { - stream_callbacks_.at(Stream::LEFT_RECTIFIED)( + auto data = getControlDateWithStream(Stream::LEFT_RECTIFIED); + data.stream_callback( {output->first_data, output->first, nullptr, output->first_id}); } if (HasStreamCallback(Stream::RIGHT_RECTIFIED)) { - stream_callbacks_.at(Stream::RIGHT_RECTIFIED)( + auto data = getControlDateWithStream(Stream::RIGHT_RECTIFIED); + data.stream_callback( {output->second_data, output->second, nullptr, output->second_id}); } } @@ -1019,7 +1032,8 @@ void Synthetic::OnRectifyPostProcess(Object *const out) { void Synthetic::OnDisparityPostProcess(Object *const out) { const ObjMat *output = Object::Cast(out); if (HasStreamCallback(Stream::DISPARITY)) { - stream_callbacks_.at(Stream::DISPARITY)( + auto data = getControlDateWithStream(Stream::DISPARITY); + data.stream_callback( {output->data, output->value, nullptr, output->id}); } } @@ -1027,7 +1041,8 @@ void Synthetic::OnDisparityPostProcess(Object *const out) { void Synthetic::OnDisparityNormalizedPostProcess(Object *const out) { const ObjMat *output = Object::Cast(out); if (HasStreamCallback(Stream::DISPARITY_NORMALIZED)) { - stream_callbacks_.at(Stream::DISPARITY_NORMALIZED)( + auto data = getControlDateWithStream(Stream::DISPARITY_NORMALIZED); + data.stream_callback( {output->data, output->value, nullptr, output->id}); } } @@ -1035,7 +1050,8 @@ void Synthetic::OnDisparityNormalizedPostProcess(Object *const out) { void Synthetic::OnPointsPostProcess(Object *const out) { const ObjMat *output = Object::Cast(out); if (HasStreamCallback(Stream::POINTS)) { - stream_callbacks_.at(Stream::POINTS)( + auto data = getControlDateWithStream(Stream::POINTS); + data.stream_callback( {output->data, output->value, nullptr, output->id}); } } @@ -1043,7 +1059,8 @@ void Synthetic::OnPointsPostProcess(Object *const out) { void Synthetic::OnDepthPostProcess(Object *const out) { const ObjMat *output = Object::Cast(out); if (HasStreamCallback(Stream::DEPTH)) { - stream_callbacks_.at(Stream::DEPTH)( + auto data = getControlDateWithStream(Stream::DEPTH); + data.stream_callback( {output->data, output->value, nullptr, output->id}); } } diff --git a/src/mynteye/api/synthetic.h b/src/mynteye/api/synthetic.h index 4c423e6..c6e46cf 100644 --- a/src/mynteye/api/synthetic.h +++ b/src/mynteye/api/synthetic.h @@ -41,16 +41,8 @@ class Synthetic { MODE_LAST // Unsupported } mode_t; - typedef enum StatusMode { - MODE_STATUS_NATIVE, // Native stream - MODE_STATUS_DISABLE, // Synthetic stream - MODE_STATUS_ENABLE, // Synthetic stream - MODE_STATUS_LAST // Unsupported - } status_mode_t; - struct stream_control_t { Stream stream; - status_mode_t mode; mode_t support_mode_; mode_t enabled_mode_; stream_callback_t stream_callback; @@ -82,11 +74,11 @@ class Synthetic { void SetPlugin(std::shared_ptr plugin); bool HasPlugin() const; - const struct stream_control_t getControlDateWithStream(const Stream& stream) const; - void setControlDateCallbackWithStream(const struct stream_control_t& ctr_data); - void setControlDateModeWithStream(const struct stream_control_t& ctr_data); + const struct stream_control_t getControlDateWithStream( + const Stream& stream) const; + void setControlDateCallbackWithStream( + const struct stream_control_t& ctr_data); bool checkControlDateWithStream(const Stream& stream) const; - status_mode_t GetStreamStatusMode(const Stream &stream) const; std::shared_ptr getProcessorWithStream(const Stream& stream); private: @@ -133,8 +125,6 @@ class Synthetic { API *api_; - std::map stream_callbacks_; - std::shared_ptr processor_; std::shared_ptr plugin_; @@ -223,235 +213,3 @@ MYNTEYE_END_NAMESPACE #endif // MYNTEYE_API_SYNTHETIC_H_ -/* -// Copyright 2018 Slightech Co., Ltd. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#ifndef MYNTEYE_API_SYNTHETIC_H_ -#define MYNTEYE_API_SYNTHETIC_H_ -#pragma once - -#include -#include -#include -#include - -#include "mynteye/api/api.h" -#include "mynteye/api/config.h" -// #include "mynteye/api/processor.h" - -MYNTEYE_BEGIN_NAMESPACE - -class API; -class Plugin; -class Processor; - -struct Object; - -class Synthetic { - public: - using stream_callback_t = API::stream_callback_t; - - typedef enum Mode { - MODE_NATIVE, // Native stream - MODE_SYNTHETIC, // Synthetic stream - MODE_LAST // Unsupported - } mode_t; - - typedef enum StatusMode { - MODE_STATUS_NATIVE, // Native stream - MODE_STATUS_DISABLE, // Synthetic stream - MODE_STATUS_ENABLE, // Synthetic stream - MODE_STATUS_LAST // Unsupported - } status_mode_t; - - struct stream_control_t { - Stream stream; - status_mode_t mode; - stream_callback_t stream_callback; - }; - - explicit Synthetic(API *api, CalibrationModel calib_model); - ~Synthetic(); - - void NotifyImageParamsChanged(); - - bool Supports(const Stream &stream) const; - - void EnableStreamData(const Stream &stream); - void DisableStreamData(const Stream &stream); - bool IsStreamDataEnabled(const Stream &stream) const; - bool IsStreamDataNative(const Stream &stream) const; - - void SetStreamCallback(const Stream &stream, stream_callback_t callback); - bool HasStreamCallback(const Stream &stream) const; - - void StartVideoStreaming(); - void StopVideoStreaming(); - - void WaitForStreams(); - - api::StreamData GetStreamData(const Stream &stream); - std::vector GetStreamDatas(const Stream &stream); - - void SetPlugin(std::shared_ptr plugin); - bool HasPlugin() const; - - private: - void InitCalibInfo(); - void InitStreamSupports(); - - status_mode_t GetStreamStatusMode(const Stream &stream) const; - std::shared_ptr getProcessorWithStream( - const Stream& stream); - // mode_t GetStreamEnabledMode(const Stream &stream) const; - bool IsStreamEnabledNative(const Stream &stream) const; - bool IsStreamEnabledSynthetic(const Stream &stream) const; - - // void EnableStreamData(const Stream &stream, std::uint32_t depth); - // void DisableStreamData(const Stream &stream, std::uint32_t depth); - - void InitProcessors(); - - template - bool ActivateProcessor(); - template - bool DeactivateProcessor(); - - void ProcessNativeStream(const Stream &stream, const api::StreamData &data); - - bool OnRectifyProcess( - Object *const in, Object *const out, - std::shared_ptr const parent); - bool OnDisparityProcess( - Object *const in, Object *const out, - std::shared_ptr const parent); - bool OnDisparityNormalizedProcess( - Object *const in, Object *const out, - std::shared_ptr const parent); - bool OnPointsProcess( - Object *const in, Object *const out, - std::shared_ptr const parent); - bool OnDepthProcess( - Object *const in, Object *const out, - std::shared_ptr const parent); - - void OnRectifyPostProcess(Object *const out); - void OnDisparityPostProcess(Object *const out); - void OnDisparityNormalizedPostProcess(Object *const out); - void OnPointsPostProcess(Object *const out); - void OnDepthPostProcess(Object *const out); - - const struct stream_control_t - getControlDateWithStream(const Stream& stream) const; - void setControlDateModeWithStream(const struct stream_control_t& ctr_data); - void setControlDateCallbackWithStream( - const struct stream_control_t& ctr_data); - bool checkControlDateWithStream(const Stream& stream) const; - - std::vector> processors_; - - API *api_; - - std::map stream_supports_mode_; - std::map stream_enabled_mode_; - - std::map stream_callbacks_; - - std::shared_ptr processor_; - - std::shared_ptr plugin_; - - CalibrationModel calib_model_; - - std::shared_ptr intr_left_; - std::shared_ptr intr_right_; - std::shared_ptr extr_; - bool calib_default_tag_; -}; - -class SyntheticProcessorPart { - private: - inline std::vector getTargetStreams() { - return target_streams_; - } - inline Stream addTargetStreams(const Synthetic::stream_control_t& strm) { - target_streams_.push_back(strm); - } - - std::vector target_streams_; - - inline unsigned int getStreamsSum() {return target_streams_.size();} - friend Synthetic; -}; - -template -std::shared_ptr find_processor(const P &processor) { - return find_processor(processor, T::NAME); -} - -template -std::shared_ptr find_processor(const P &processor, const std::string &name) { - if (processor->Name() == name) { - return std::dynamic_pointer_cast(processor); - } - auto &&childs = processor->GetChilds(); - return find_processor(std::begin(childs), std::end(childs), name); -} - -template -std::shared_ptr find_processor( - InputIt first, InputIt last, const std::string &name) { - if (first == last) - return nullptr; - for (auto it = first; it != last; ++it) { - if ((*it)->Name() == name) { - return std::dynamic_pointer_cast(*it); - } - } - for (auto it = first; it != last; ++it) { - auto &&childs = (*it)->GetChilds(); - if (childs.empty()) - continue; - auto &&result = - find_processor(std::begin(childs), std::end(childs), name); - if (result == nullptr) - continue; - return result; - } - return nullptr; -} - -template -bool Synthetic::ActivateProcessor() { - auto &&processor = find_processor(processor_); - if (processor == nullptr) - return false; - processor->Activate(); - return true; -} - -template -bool Synthetic::DeactivateProcessor() { - auto &&processor = find_processor(processor_); - if (processor == nullptr) - return false; - processor->Deactivate(); - return true; -} - -MYNTEYE_END_NAMESPACE - -#endif // MYNTEYE_API_SYNTHETIC_H_ - -*/