/** @file * @author Edouard DUPIN * @copyright 2015, Edouard DUPIN, all right reserved * @license APACHE v2.0 (see license file) */ #include "Manager.h" #include "Interface.h" #include #include "io/Manager.h" #include "io/Node.h" #include "debug.h" #include #undef __class__ #define __class__ "Manager" static std11::mutex g_mutex; static std::vector > g_listOfAllManager; std11::shared_ptr audio::river::Manager::create(const std::string& _applicationUniqueId) { std11::unique_lock lock(g_mutex); for (size_t iii=0; iii tmp = g_listOfAllManager[iii].lock(); if (tmp == nullptr) { continue; } if (tmp->m_applicationUniqueId == _applicationUniqueId) { return tmp; } } // create a new one: std11::shared_ptr out = std11::shared_ptr(new audio::river::Manager(_applicationUniqueId)); // add it at the list: for (size_t iii=0; iii audio::river::Manager::getListStreamInput() { std::vector output; std11::shared_ptr manager = audio::river::io::Manager::getInstance(); if (manager == nullptr) { RIVER_ERROR("Unable to load harware IO manager ... "); } else { output = manager->getListStreamInput(); } return output; } std::vector audio::river::Manager::getListStreamOutput() { std::vector output; std11::shared_ptr manager = audio::river::io::Manager::getInstance(); if (manager == nullptr) { RIVER_ERROR("Unable to load harware IO manager ... "); } else { output = manager->getListStreamOutput(); } return output; } std::vector audio::river::Manager::getListStreamVirtual() { std::vector output; std11::shared_ptr manager = audio::river::io::Manager::getInstance(); if (manager == nullptr) { RIVER_ERROR("Unable to load harware IO manager ... "); } else { output = manager->getListStreamVirtual(); } return output; } std::vector audio::river::Manager::getListStream() { std::vector output; std11::shared_ptr manager = audio::river::io::Manager::getInstance(); if (manager == nullptr) { RIVER_ERROR("Unable to load harware IO manager ... "); } else { output = manager->getListStream(); } return output; } bool audio::river::Manager::setVolume(const std::string& _volumeName, float _valuedB) { std11::shared_ptr manager = audio::river::io::Manager::getInstance(); if (manager == nullptr) { RIVER_ERROR("Unable to load harware IO manager ... "); return false; } return manager->setVolume(_volumeName, _valuedB); } float audio::river::Manager::getVolume(const std::string& _volumeName) const { std11::shared_ptr manager = audio::river::io::Manager::getInstance(); if (manager == nullptr) { RIVER_ERROR("Unable to load harware IO manager ... "); return false; } return manager->getVolume(_volumeName); } std::pair audio::river::Manager::getVolumeRange(const std::string& _volumeName) const { std11::shared_ptr manager = audio::river::io::Manager::getInstance(); if (manager == nullptr) { RIVER_ERROR("Unable to load harware IO manager ... "); return std::make_pair(0.0f,0.0f); } return manager->getVolumeRange(_volumeName); } void audio::river::Manager::setMute(const std::string& _volumeName, bool _mute) { std11::shared_ptr manager = audio::river::io::Manager::getInstance(); if (manager == nullptr) { RIVER_ERROR("Unable to load harware IO manager ... "); return; } manager->setMute(_volumeName, _mute); } bool audio::river::Manager::getMute(const std::string& _volumeName) const { std11::shared_ptr manager = audio::river::io::Manager::getInstance(); if (manager == nullptr) { RIVER_ERROR("Unable to load harware IO manager ... "); return false; } return manager->getMute(_volumeName); } std11::shared_ptr audio::river::Manager::createOutput(float _freq, const std::vector& _map, audio::format _format, const std::string& _streamName, const std::string& _options) { // get global hardware interface: std11::shared_ptr manager = audio::river::io::Manager::getInstance(); if (manager == nullptr) { RIVER_ERROR("Unable to load harware IO manager ... "); return std11::shared_ptr(); } // get the output or input channel : std11::shared_ptr node = manager->getNode(_streamName); if (node == nullptr) { RIVER_ERROR("Can not get the Requested stream '" << _streamName << "' ==> not listed in : " << manager->getListStream()); return std11::shared_ptr(); } if (node->isOutput() != true) { RIVER_ERROR("Can not Connect output on other thing than output ... for stream '" << _streamName << "'");; return std11::shared_ptr(); } // create user iterface: std11::shared_ptr interface; std11::shared_ptr tmpOption = ejson::Object::create(_options); tmpOption->addString("io", "output"); interface = audio::river::Interface::create(_freq, _map, _format, node, tmpOption); // store it in a list (needed to apply some parameters). m_listOpenInterface.push_back(interface); return interface; } std11::shared_ptr audio::river::Manager::createInput(float _freq, const std::vector& _map, audio::format _format, const std::string& _streamName, const std::string& _options) { // get global hardware interface: std11::shared_ptr manager = audio::river::io::Manager::getInstance(); if (manager == nullptr) { RIVER_ERROR("Unable to load harware IO manager ... "); return std11::shared_ptr(); } // get the output or input channel : std11::shared_ptr node = manager->getNode(_streamName); if (node == nullptr) { RIVER_ERROR("Can not get the Requested stream '" << _streamName << "' ==> not listed in : " << manager->getListStream()); return std11::shared_ptr(); } if (node->isInput() != true) { RIVER_ERROR("Can not Connect input on other thing than input ... for stream '" << _streamName << "'");; return std11::shared_ptr(); } // create user iterface: std11::shared_ptr interface; std11::shared_ptr tmpOption = ejson::Object::create(_options); tmpOption->addString("io", "input"); interface = audio::river::Interface::create(_freq, _map, _format, node, tmpOption); // store it in a list (needed to apply some parameters). m_listOpenInterface.push_back(interface); return interface; } std11::shared_ptr audio::river::Manager::createFeedback(float _freq, const std::vector& _map, audio::format _format, const std::string& _streamName, const std::string& _options) { // get global hardware interface: std11::shared_ptr manager = audio::river::io::Manager::getInstance(); if (manager == nullptr) { RIVER_ERROR("Unable to load harware IO manager ... "); return std11::shared_ptr(); } // get the output or input channel : std11::shared_ptr node = manager->getNode(_streamName); if (node == nullptr) { RIVER_ERROR("Can not get the Requested stream '" << _streamName << "' ==> not listed in : " << manager->getListStream()); return std11::shared_ptr(); } if (node->isOutput() != true) { RIVER_ERROR("Can not Connect feedback on other thing than output ... for stream '" << _streamName << "'");; return std11::shared_ptr(); } // create user iterface: std11::shared_ptr interface; std11::shared_ptr tmpOption = ejson::Object::create(_options); tmpOption->addString("io", "feedback"); interface = audio::river::Interface::create(_freq, _map, _format, node, tmpOption); // store it in a list (needed to apply some parameters). m_listOpenInterface.push_back(interface); return interface; } void audio::river::Manager::generateDotAll(const std::string& _filename) { // get global hardware interface: std11::shared_ptr manager = audio::river::io::Manager::getInstance(); if (manager == nullptr) { RIVER_ERROR("Can not get the harware manager"); return; } manager->generateDot(_filename); }