From 8cd0fe0b88e8a8838b30d2b5342e105aee842d51 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 23 Jan 2015 21:27:44 +0100 Subject: [PATCH] [DEV] continue configuration --- eaudiofx/base/GeneratorSignal.cpp | 2 +- eaudiofx/core/BlockMeta.cpp | 40 +++++++++ eaudiofx/core/BlockMeta.h | 3 + eaudiofx/core/Processing.cpp | 5 ++ eaudiofx/flow/Base.cpp | 10 ++- eaudiofx/flow/Base.h | 6 +- eaudiofx/flow/Flow.h | 22 ++++- eaudiofx/flow/Interface.cpp | 129 +++++++++++++++++++++++++++++- eaudiofx/flow/Interface.h | 3 + 9 files changed, 209 insertions(+), 11 deletions(-) diff --git a/eaudiofx/base/GeneratorSignal.cpp b/eaudiofx/base/GeneratorSignal.cpp index bde3880..2c400df 100644 --- a/eaudiofx/base/GeneratorSignal.cpp +++ b/eaudiofx/base/GeneratorSignal.cpp @@ -21,7 +21,7 @@ void eaudiofx::GeneratorSignal::init() { eaudiofx::GeneratorSignal::GeneratorSignal() : m_phase(0), - m_output(*this, "out", "Output sinus generated", "{ type:'audio', freq:48000, format:'int16', channels:2}") { + m_output(*this, "out", "Output sinus generated", "{ type:'audio', freq:48000, format:['int16','int32'], channels:2}") { addObjectType("eaudiofx::GeneratorSignal"); } diff --git a/eaudiofx/core/BlockMeta.cpp b/eaudiofx/core/BlockMeta.cpp index 49b532f..16f1a1e 100644 --- a/eaudiofx/core/BlockMeta.cpp +++ b/eaudiofx/core/BlockMeta.cpp @@ -207,3 +207,43 @@ void eaudiofx::BlockMeta::flowLinkInput() { // Call upper class eaudiofx::Block::flowLinkInput(); } + + +void eaudiofx::BlockMeta::flowCheckAllCompatibility() { + EAUDIOFX_INFO("[" << getId() << "] Meta block check compatibilities: '" << getName() << "'"); + // find in sub elements. + for (auto &it : m_list) { + if (it == nullptr) { + continue; + } + it->flowCheckAllCompatibility(); + } + // Call upper class + eaudiofx::Block::flowCheckAllCompatibility(); +} + +void eaudiofx::BlockMeta::flowAllocateOutput() { + EAUDIOFX_INFO("[" << getId() << "] Meta block allocate output: '" << getName() << "'"); + // find in sub elements. + for (auto &it : m_list) { + if (it == nullptr) { + continue; + } + it->flowAllocateOutput(); + } + // Call upper class + eaudiofx::Block::flowAllocateOutput(); +} + +void eaudiofx::BlockMeta::flowGetInput() { + EAUDIOFX_INFO("[" << getId() << "] Meta block get input ... : '" << getName() << "'"); + // find in sub elements. + for (auto &it : m_list) { + if (it == nullptr) { + continue; + } + it->flowGetInput(); + } + // Call upper class + eaudiofx::Block::flowGetInput(); +} diff --git a/eaudiofx/core/BlockMeta.h b/eaudiofx/core/BlockMeta.h index 41bd674..e92bf97 100644 --- a/eaudiofx/core/BlockMeta.h +++ b/eaudiofx/core/BlockMeta.h @@ -84,6 +84,9 @@ namespace eaudiofx { virtual std::shared_ptr getBlockNamed(const std::string& _name); virtual void flowLinkInput(); + virtual void flowCheckAllCompatibility(); + virtual void flowAllocateOutput(); + virtual void flowGetInput(); }; }; diff --git a/eaudiofx/core/Processing.cpp b/eaudiofx/core/Processing.cpp index 72852e5..d0159d1 100644 --- a/eaudiofx/core/Processing.cpp +++ b/eaudiofx/core/Processing.cpp @@ -41,14 +41,19 @@ int32_t eaudiofx::Processing::waitEndOfProcess() { bool eaudiofx::Processing::stateStart() { EAUDIOFX_INFO("Start Processing : '" << getName() << "'"); // TODO : Add return code ... and test all of theses events ... + EAUDIOFX_ERROR("======================================"); // Init request flow update: flowLinkInput(); + EAUDIOFX_ERROR("======================================"); // check if the IOs are compatible flowCheckAllCompatibility(); + EAUDIOFX_ERROR("======================================"); // Allocate all Outputs flowAllocateOutput(); + EAUDIOFX_ERROR("======================================"); // Get pointer on all Inputs flowGetInput(); + EAUDIOFX_ERROR("======================================"); // init algorithm int32_t ret = algoInit(); if (ret != eaudiofx::ERR_NONE) { diff --git a/eaudiofx/flow/Base.cpp b/eaudiofx/flow/Base.cpp index fc9ef9c..d0d0bc6 100644 --- a/eaudiofx/flow/Base.cpp +++ b/eaudiofx/flow/Base.cpp @@ -27,9 +27,10 @@ eaudiofx::flow::Base::Base(eaudiofx::flow::Interface& _flowInterfaceLink, m_ref = std::make_shared(this); // add a reference on the current signal ... m_flowInterfaceLink.flowAdd(this); - m_formatAvaillable.parse(_formatAvaillable); + m_formatAvaillable = std::make_shared(); + m_formatAvaillable->parse(_formatAvaillable); EAUDIOFX_INFO("Create flow : '" << m_name << "' mode:'" << (m_input==true?"input":"output") << "' prop:"); - m_formatAvaillable.display(); + m_formatAvaillable->display(); } eaudiofx::flow::Base::~Base() { @@ -46,8 +47,9 @@ void eaudiofx::flow::Base::link() { EAUDIOFX_INFO(" link flow : '" << m_name << "' mode:'" << (m_input==true?"input":"output") << "' (no code)"); } -void eaudiofx::flow::Base::checkCompatibility() { - EAUDIOFX_INFO(" chack flow : '" << m_name << "' (no code)"); +int32_t eaudiofx::flow::Base::checkCompatibility() { + EAUDIOFX_INFO(" check flow : '" << m_name << "' (no code)"); + return -1; } void eaudiofx::flow::Base::getInputBuffer() { diff --git a/eaudiofx/flow/Base.h b/eaudiofx/flow/Base.h index 81bfec1..e98c90e 100644 --- a/eaudiofx/flow/Base.h +++ b/eaudiofx/flow/Base.h @@ -24,7 +24,7 @@ namespace eaudiofx { std::string m_name; std::string m_description; bool m_input; - ejson::Document m_formatAvaillable; + std::shared_ptr m_formatAvaillable; public: /** * @brief Create a parameter with a specific type. @@ -56,7 +56,7 @@ namespace eaudiofx { bool isOutput() { return !m_input; } - const ejson::Object& getCapabilities() { + std::shared_ptr getCapabilities() { return m_formatAvaillable; } /** @@ -82,7 +82,7 @@ namespace eaudiofx { const std::string& _flowLinkName); public: virtual void link(); - virtual void checkCompatibility(); + virtual int32_t checkCompatibility(); virtual void getInputBuffer(); //virtual std::shared_ptr getBlockNamed(const std::string& _name); }; diff --git a/eaudiofx/flow/Flow.h b/eaudiofx/flow/Flow.h index ed02fc5..eda5f2c 100644 --- a/eaudiofx/flow/Flow.h +++ b/eaudiofx/flow/Flow.h @@ -105,7 +105,7 @@ namespace eaudiofx { template class Output : public Flow { protected: std::vector> m_remoteFlow; //!< List of reference on the remote flow (multiple childs). - ejson::Document m_formatMix; //!< current format that is now availlable on the flow (can be on error) represent the intersection of all flow connected + std::shared_ptr m_formatMix; //!< current format that is now availlable on the flow (can be on error) represent the intersection of all flow connected public: /** * @brief Create a parameter with a specific type. @@ -128,6 +128,26 @@ namespace eaudiofx { virtual void addReference(const std::shared_ptr& _reference) { m_remoteFlow.push_back(_reference); } + virtual int32_t checkCompatibility() { + EAUDIOFX_INFO(" check for : '" << Base::m_name << "' to " << m_remoteFlow.size() << " links"); + std::vector> list; + list.push_back(Base::getCapabilities()); + for (auto &it : m_remoteFlow) { + std::shared_ptr tmp = it.lock(); + if (tmp != nullptr) { + if (tmp->getBase() != nullptr) { + list.push_back(tmp->getBase()->getCapabilities()); + } + } + } + m_formatMix = Base::m_flowInterfaceLink.getFlowIntersection(list); + + // TODO : Check input property + EAUDIOFX_INFO("[" << Base::m_name << "] mix signal : "); + m_formatMix->display(); + return 0; + } + }; }; #undef __class__ diff --git a/eaudiofx/flow/Interface.cpp b/eaudiofx/flow/Interface.cpp index fd31ec3..ff1060e 100644 --- a/eaudiofx/flow/Interface.cpp +++ b/eaudiofx/flow/Interface.cpp @@ -74,7 +74,7 @@ void eaudiofx::flow::Interface::flowSetLinkWith(const std::string& _flowName, } void eaudiofx::flow::Interface::flowLinkInput() { - EAUDIOFX_INFO(" Block update the flows links"); + EAUDIOFX_INFO(" Block update the flows links (" << m_list.size() << " flows)"); for (auto &it : m_list) { if(it != nullptr) { it->link(); @@ -83,7 +83,7 @@ void eaudiofx::flow::Interface::flowLinkInput() { } void eaudiofx::flow::Interface::flowCheckAllCompatibility() { - EAUDIOFX_INFO(" Block Check the flows Capabilities"); + EAUDIOFX_INFO(" Block Check the flows Capabilities (" << m_list.size() << " flows)"); for (auto &it : m_list) { if(it != nullptr) { it->checkCompatibility(); @@ -117,4 +117,129 @@ std::shared_ptr eaudiofx::flow::Interface::getFlo return out; } +static std::shared_ptr intersect(const std::shared_ptr& _obj1, const std::shared_ptr& _obj2) { + std::shared_ptr out = ejson::Object::create(); + + if (_obj1 == nullptr) { + if (_obj2 == nullptr) { + EAUDIOFX_ERROR("intersect 2 null ptr ..."); + return ejson::Null::create(); + } else { + return _obj2->clone(); + } + } + if (_obj2 == nullptr) { + return _obj1->clone(); + } + if (_obj1->isNull() == true) { + return _obj2->clone(); + } + if (_obj1->isNumber() == true) { + // just a single output value ... just check if it is the same value + double value = _obj1->toNumber()->get(); + if (_obj2->isNumber() == true) { + if (value == _obj2->toNumber()->get()) { + return ejson::Number::create(value); + } + EAUDIOFX_ERROR("Not the same number value"); + } + if (_obj2->isArray() == true) { + std::shared_ptr obj = _obj2->toArray(); + for (int32_t iii=0; iiisize(); ++iii) { + if ((*obj)[iii]->isNumber() == true) { + if (value == (*obj)[iii]->toNumber()->get()) { + return ejson::Number::create(value); + } + } + } + EAUDIOFX_ERROR("Not the same values ..."); + } + } + if (_obj1->isString() == true) { + // just a single output value ... just check if it is the same value + std::string value = _obj1->toString()->get(); + if (_obj2->isString() == true) { + if (value == _obj2->toString()->get()) { + return ejson::String::create(value); + } + EAUDIOFX_ERROR("Not the same string value"); + } + if (_obj2->isArray() == true) { + std::shared_ptr obj = _obj2->toArray(); + for (int32_t iii=0; iiisize(); ++iii) { + if ((*obj)[iii]->isString() == true) { + if (value == (*obj)[iii]->toString()->get()) { + return ejson::String::create(value); + } + } + } + EAUDIOFX_ERROR("Not the same values ..."); + } + } + if (_obj1->isArray() == true) { + EAUDIOFX_TODO(" manage array"); + } + EAUDIOFX_ERROR("Can not intersect elements : (obj1)"); + _obj1->display(); + EAUDIOFX_ERROR(" (obj2)"); + _obj2->display(); + // remove sublist if it is reduce to 1 + return ejson::Null::create(); +} + +std::shared_ptr eaudiofx::flow::Interface::getFlowIntersection(const std::vector>& _list) { + EAUDIOFX_ERROR("-------------- start intersection --------------"); + std::shared_ptr out = std::make_shared(); + if (_list.size() == 0) { + return out; + } + if (_list.size() == 1) { + _list[0]->cloneIn(out); + EAUDIOFX_INFO("List clone : "); + out->display(); + EAUDIOFX_ERROR("-------------- stop intersection (no link ...) --------------"); + return out; + } + // check all same type : + for (int32_t iii=1; iii<_list.size(); ++iii) { + if (_list[iii]->getStringValue("type") != _list[0]->getStringValue("type")) { + EAUDIOFX_ERROR("All stream have not the same Type ..."); + return out; + } + } + out->add("type", ejson::String::create(_list[0]->getStringValue("type"))); + if (out->getStringValue("type") == "audio") { + // check frequency: + std::shared_ptr tmp = ejson::Null::create(); + for (int32_t iii=0; iii<_list.size(); ++iii) { + tmp = intersect(tmp, _list[iii]->get("freq")); + } + out->add("freq", tmp); + // check format: + tmp = ejson::Null::create(); + for (int32_t iii=0; iii<_list.size(); ++iii) { + tmp = intersect(tmp, _list[iii]->get("format")); + } + out->add("format", tmp); + + // check channels: + tmp = ejson::Null::create(); + for (int32_t iii=0; iii<_list.size(); ++iii) { + tmp = intersect(tmp, _list[iii]->get("channels")); + } + out->add("channels", tmp); + + } else if (out->getStringValue("type") == "video") { + for (int32_t iii=1; iii<_list.size(); ++iii) { + + } + } else { + EAUDIOFX_ERROR("not manage interface for mix ... '" << out->getStringValue("type") << "'"); + } + out->display(); + EAUDIOFX_ERROR("-------------- stop intersection --------------"); + return out; +} + + diff --git a/eaudiofx/flow/Interface.h b/eaudiofx/flow/Interface.h index c58c3ba..83014f6 100644 --- a/eaudiofx/flow/Interface.h +++ b/eaudiofx/flow/Interface.h @@ -12,6 +12,7 @@ #include #include +#include namespace eaudiofx { class Block; @@ -81,6 +82,8 @@ namespace eaudiofx { return nullptr; } std::shared_ptr getFlowReference(const std::string& _name); + public: + std::shared_ptr getFlowIntersection(const std::vector>& _list); }; }; };