From a086674189909701bd64898c24b0352eefd38f8f Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Thu, 12 Feb 2015 22:08:23 +0100 Subject: [PATCH] [DEV] add virtual interface --- data/virtual.json | 7 +++--- river/Interface.cpp | 33 ++++++++++++++++---------- river/Interface.h | 21 ++++++++++------- river/Manager.cpp | 56 ++++++++++++++++++++++++++++++++++++++++---- river/Manager.h | 2 ++ river/io/Manager.cpp | 5 ++-- river/io/Node.cpp | 7 ++++-- 7 files changed, 99 insertions(+), 32 deletions(-) diff --git a/data/virtual.json b/data/virtual.json index a204c9a..cde69e5 100644 --- a/data/virtual.json +++ b/data/virtual.json @@ -12,7 +12,7 @@ resampling-option:"quality=10" }, feedback:{ - io:"input", + io:"feedback", # note : Feedback is plugged on an output not an input map-on:"speaker", resampling-type:"speexdsp", resampling-option:"quality=10" @@ -22,8 +22,9 @@ map-on:"speaker", resampling-type:"speexdsp", resampling-option:"quality=10", - aec-map-on:"microphone", the second input of the AEC (get a single - aec-type:"airtio-remover", # some type is "airtio-remover", + # specific case for AEC : only 3 options + aec-map-on:"microphone", # the second input of the AEC (get a single) + aec-type:"river-remover", # some type is "airtio-remover", aec-option:"mode=cutter" } } \ No newline at end of file diff --git a/river/Interface.cpp b/river/Interface.cpp index 8414dbd..d352b13 100644 --- a/river/Interface.cpp +++ b/river/Interface.cpp @@ -27,18 +27,27 @@ river::Interface::Interface(void) : } bool river::Interface::init(const std::string& _name, - float _freq, - const std::vector& _map, - audio::format _format, - const std::shared_ptr& _node, - bool _isInput) { + float _freq, + const std::vector& _map, + audio::format _format, + const std::shared_ptr& _node, + const std::shared_ptr& _config) { m_name = _name; m_node = _node; m_freq = _freq; m_map = _map; m_format = _format; m_volume = 0.0f; - m_isInput = _isInput; + m_config = _config; + m_mode = river::modeInterface_unknow; + std::string type = m_config->getStringValue("io", "error"); + if (type == "output") { + m_mode = river::modeInterface_output; + } else if (type == "input") { + m_mode = river::modeInterface_input; + } else if (type == "feedback") { + m_mode = river::modeInterface_feedback; + } // register interface to be notify from the volume change. m_node->registerAsRemote(shared_from_this()); // Create convertion interface @@ -75,13 +84,13 @@ bool river::Interface::init(const std::string& _name, } std::shared_ptr river::Interface::create(const std::string& _name, - float _freq, - const std::vector& _map, - audio::format _format, - const std::shared_ptr& _node, - bool _isInput) { + float _freq, + const std::vector& _map, + audio::format _format, + const std::shared_ptr& _node, + const std::shared_ptr& _config) { std::shared_ptr out = std::shared_ptr(new river::Interface()); - out->init(_name, _freq, _map, _format, _node, _isInput); + out->init(_name, _freq, _map, _format, _node, _config); return out; } diff --git a/river/Interface.h b/river/Interface.h index 6980253..d5a78da 100644 --- a/river/Interface.h +++ b/river/Interface.h @@ -19,11 +19,18 @@ #include #include #include +#include namespace river { namespace io { class Node; } + enum modeInterface { + modeInterface_unknow, + modeInterface_input, + modeInterface_output, + modeInterface_feedback, + }; class Interface : public std::enable_shared_from_this { friend class io::Node; friend class Manager; @@ -35,6 +42,7 @@ namespace river { std::vector m_map; audio::format m_format; drain::Process m_process; + std::shared_ptr m_config; protected: std::string m_name; public: @@ -42,13 +50,10 @@ namespace river { return m_name; }; protected: - bool m_isInput; + enum modeInterface m_mode; public: - bool isInput() { - return m_isInput; - } - bool isOutput() { - return !m_isInput; + enum modeInterface getMode() { + return m_mode; } protected: /** @@ -60,7 +65,7 @@ namespace river { const std::vector& _map, audio::format _format, const std::shared_ptr& _node, - bool _isInput); + const std::shared_ptr& _config); public: /** * @brief Destructor @@ -71,7 +76,7 @@ namespace river { const std::vector& _map, audio::format _format, const std::shared_ptr& _node, - bool _isInput); + const std::shared_ptr& _config); /** * @brief set the read/write mode enable. */ diff --git a/river/Manager.cpp b/river/Manager.cpp index 7088692..d98d845 100644 --- a/river/Manager.cpp +++ b/river/Manager.cpp @@ -23,7 +23,10 @@ std::shared_ptr river::Manager::create(const std::string& _appli river::Manager::Manager(const std::string& _applicationUniqueId) : m_applicationUniqueId(_applicationUniqueId), m_listOpenInterface() { - + // TODO : Maybe create a single interface property (and all get the same ...) + if (m_config.load("DATA:virtual.json") == false) { + RIVER_ERROR("you must set a basic configuration file for virtual configuration: DATA:virtual.json"); + } } river::Manager::~Manager() { @@ -33,13 +36,30 @@ river::Manager::~Manager() { std::vector > river::Manager::getListStreamInput() { std::vector > output; - //output.push_back(std::make_pair("default", "48000 Hz, 16 bits, 2 channels: Default input ")); + for (auto &it : m_config.getKeys()) { + const std::shared_ptr tmppp = m_config.getObject(it); + if (tmppp != nullptr) { + std::string type = tmppp->getStringValue("io", "error"); + if ( type == "input" + || type == "feedback") { + output.push_back(std::make_pair(std::string(it), std::string("---"))); + } + } + } return output; } std::vector > river::Manager::getListStreamOutput() { std::vector > output; - //output.push_back(std::make_pair("default", "48000 Hz, 16 bits, 2 channels: Default output ")); + for (auto &it : m_config.getKeys()) { + const std::shared_ptr tmppp = m_config.getObject(it); + if (tmppp != nullptr) { + std::string type = tmppp->getStringValue("io", "error"); + if (type == "output") { + output.push_back(std::make_pair(std::string(it), std::string("---"))); + } + } + } return output; } @@ -61,13 +81,26 @@ std::shared_ptr river::Manager::createOutput(float _freq, audio::format _format, const std::string& _streamName, const std::string& _name) { + // check if the output exist + const std::shared_ptr tmppp = m_config.getObject(_streamName); + if (tmppp == nullptr) { + RIVER_ERROR("can not open a non existance virtual input: '" << _streamName << "' not present in : " << m_config.getKeys()); + return nullptr; + } + // check if it is an Output: + std::string type = tmppp->getStringValue("io", "error"); + if (type != "output") { + RIVER_ERROR("can not open in output a virtual interface: '" << _streamName << "' configured has : " << type); + return nullptr; + } + // get global hardware interface: std::shared_ptr manager = river::io::Manager::getInstance(); // get the output or input channel : std::shared_ptr node = manager->getNode(_streamName); // create user iterface: std::shared_ptr interface; - interface = river::Interface::create(_name, _freq, _map, _format, node, false); + interface = river::Interface::create(_name, _freq, _map, _format, node, tmppp); // store it in a list (needed to apply some parameters). m_listOpenInterface.push_back(interface); return interface; @@ -78,13 +111,26 @@ std::shared_ptr river::Manager::createInput(float _freq, audio::format _format, const std::string& _streamName, const std::string& _name) { + // check if the output exist + const std::shared_ptr tmppp = m_config.getObject(_streamName); + if (tmppp == nullptr) { + RIVER_ERROR("can not open a non existance virtual interface: '" << _streamName << "' not present in : " << m_config.getKeys()); + return nullptr; + } + // check if it is an Output: + std::string type = tmppp->getStringValue("io", "error"); + if ( type != "input" + && type != "feedback") { + RIVER_ERROR("can not open in output a virtual interface: '" << _streamName << "' configured has : " << type); + return nullptr; + } // get global hardware interface: std::shared_ptr manager = river::io::Manager::getInstance(); // get the output or input channel : std::shared_ptr node = manager->getNode(_streamName); // create user iterface: std::shared_ptr interface; - interface = river::Interface::create(_name, _freq, _map, _format, node, true); + interface = river::Interface::create(_name, _freq, _map, _format, node, tmppp); // store it in a list (needed to apply some parameters). m_listOpenInterface.push_back(interface); return interface; diff --git a/river/Manager.h b/river/Manager.h index eeaa4d9..d208d96 100644 --- a/river/Manager.h +++ b/river/Manager.h @@ -13,6 +13,7 @@ #include #include