2015-01-25 22:17:06 +01:00
|
|
|
/** @file
|
|
|
|
* @author Edouard DUPIN
|
|
|
|
* @copyright 2015, Edouard DUPIN, all right reserved
|
2017-01-05 21:28:23 +01:00
|
|
|
* @license MPL v2.0 (see license file)
|
2015-01-25 22:17:06 +01:00
|
|
|
*/
|
|
|
|
|
2016-10-02 22:19:26 +02:00
|
|
|
#include "Manager.hpp"
|
|
|
|
#include "Interface.hpp"
|
2015-01-25 22:17:06 +01:00
|
|
|
#include <stdexcept>
|
|
|
|
|
2016-10-02 22:19:26 +02:00
|
|
|
#include "io/Manager.hpp"
|
|
|
|
#include "io/Node.hpp"
|
|
|
|
#include "debug.hpp"
|
|
|
|
#include <ejson/ejson.hpp>
|
2015-01-25 22:17:06 +01:00
|
|
|
|
2016-03-08 21:29:34 +01:00
|
|
|
static std::mutex g_mutex;
|
2017-08-28 00:08:50 +02:00
|
|
|
static etk::Vector<ememory::WeakPtr<audio::river::Manager> > g_listOfAllManager;
|
2015-01-27 21:01:52 +01:00
|
|
|
|
2017-08-28 00:08:50 +02:00
|
|
|
ememory::SharedPtr<audio::river::Manager> audio::river::Manager::create(const etk::String& _applicationUniqueId) {
|
2016-03-08 21:29:34 +01:00
|
|
|
std::unique_lock<std::mutex> lock(g_mutex);
|
2015-03-23 21:26:45 +01:00
|
|
|
for (size_t iii=0; iii<g_listOfAllManager.size() ; ++iii) {
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::Manager> tmp = g_listOfAllManager[iii].lock();
|
2015-03-23 21:26:45 +01:00
|
|
|
if (tmp == nullptr) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (tmp->m_applicationUniqueId == _applicationUniqueId) {
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// create a new one:
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::Manager> out = ememory::SharedPtr<audio::river::Manager>(new audio::river::Manager(_applicationUniqueId));
|
2015-03-23 21:26:45 +01:00
|
|
|
// add it at the list:
|
|
|
|
for (size_t iii=0; iii<g_listOfAllManager.size() ; ++iii) {
|
|
|
|
if (g_listOfAllManager[iii].expired() == true) {
|
|
|
|
g_listOfAllManager[iii] = out;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
}
|
2017-08-28 00:08:50 +02:00
|
|
|
g_listOfAllManager.pushBack(out);
|
2015-03-23 21:26:45 +01:00
|
|
|
return out;
|
2015-01-25 22:17:06 +01:00
|
|
|
}
|
|
|
|
|
2017-08-28 00:08:50 +02:00
|
|
|
audio::river::Manager::Manager(const etk::String& _applicationUniqueId) :
|
2015-01-25 22:17:06 +01:00
|
|
|
m_applicationUniqueId(_applicationUniqueId),
|
2015-02-01 22:21:03 +01:00
|
|
|
m_listOpenInterface() {
|
2015-03-12 22:28:15 +01:00
|
|
|
|
2015-01-25 22:17:06 +01:00
|
|
|
}
|
|
|
|
|
2015-04-11 09:38:30 +02:00
|
|
|
audio::river::Manager::~Manager() {
|
2015-01-25 22:17:06 +01:00
|
|
|
// TODO : Stop all interfaces...
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-08-28 00:08:50 +02:00
|
|
|
etk::Vector<etk::String> audio::river::Manager::getListStreamInput() {
|
|
|
|
etk::Vector<etk::String> output;
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
|
2015-03-12 22:28:15 +01:00
|
|
|
if (manager == nullptr) {
|
|
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
|
|
|
} else {
|
|
|
|
output = manager->getListStreamInput();
|
2015-02-12 22:08:23 +01:00
|
|
|
}
|
2015-01-25 22:17:06 +01:00
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2017-08-28 00:08:50 +02:00
|
|
|
etk::Vector<etk::String> audio::river::Manager::getListStreamOutput() {
|
|
|
|
etk::Vector<etk::String> output;
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
|
2015-03-12 22:28:15 +01:00
|
|
|
if (manager == nullptr) {
|
|
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
|
|
|
} else {
|
|
|
|
output = manager->getListStreamOutput();
|
2015-02-12 22:08:23 +01:00
|
|
|
}
|
2015-01-25 22:17:06 +01:00
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2017-08-28 00:08:50 +02:00
|
|
|
etk::Vector<etk::String> audio::river::Manager::getListStreamVirtual() {
|
|
|
|
etk::Vector<etk::String> output;
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
|
2015-03-12 22:28:15 +01:00
|
|
|
if (manager == nullptr) {
|
|
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
|
|
|
} else {
|
|
|
|
output = manager->getListStreamVirtual();
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2017-08-28 00:08:50 +02:00
|
|
|
etk::Vector<etk::String> audio::river::Manager::getListStream() {
|
|
|
|
etk::Vector<etk::String> output;
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
|
2015-03-12 22:28:15 +01:00
|
|
|
if (manager == nullptr) {
|
|
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
|
|
|
} else {
|
|
|
|
output = manager->getListStream();
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
2015-01-30 21:44:36 +01:00
|
|
|
|
2017-08-28 00:08:50 +02:00
|
|
|
bool audio::river::Manager::setVolume(const etk::String& _volumeName, float _valuedB) {
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
|
2015-03-12 22:28:15 +01:00
|
|
|
if (manager == nullptr) {
|
|
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return manager->setVolume(_volumeName, _valuedB);
|
2015-01-30 21:44:36 +01:00
|
|
|
}
|
2015-02-03 23:29:34 +01:00
|
|
|
|
2017-08-28 00:08:50 +02:00
|
|
|
float audio::river::Manager::getVolume(const etk::String& _volumeName) const {
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
|
2015-03-12 22:28:15 +01:00
|
|
|
if (manager == nullptr) {
|
|
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return manager->getVolume(_volumeName);
|
2015-01-30 21:44:36 +01:00
|
|
|
}
|
|
|
|
|
2017-08-28 00:08:50 +02:00
|
|
|
etk::Pair<float,float> audio::river::Manager::getVolumeRange(const etk::String& _volumeName) const {
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
|
2015-03-12 22:28:15 +01:00
|
|
|
if (manager == nullptr) {
|
|
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
2017-08-28 00:08:50 +02:00
|
|
|
return etk::makePair<float,float>(0.0f,0.0f);
|
2015-03-12 22:28:15 +01:00
|
|
|
}
|
|
|
|
return manager->getVolumeRange(_volumeName);
|
2015-01-30 21:44:36 +01:00
|
|
|
}
|
|
|
|
|
2017-08-28 00:08:50 +02:00
|
|
|
void audio::river::Manager::setMute(const etk::String& _volumeName, bool _mute) {
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
|
2015-07-02 21:17:24 +02:00
|
|
|
if (manager == nullptr) {
|
|
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
manager->setMute(_volumeName, _mute);
|
|
|
|
}
|
|
|
|
|
2017-08-28 00:08:50 +02:00
|
|
|
bool audio::river::Manager::getMute(const etk::String& _volumeName) const {
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
|
2015-07-02 21:17:24 +02:00
|
|
|
if (manager == nullptr) {
|
|
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return manager->getMute(_volumeName);
|
|
|
|
}
|
|
|
|
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::Interface> audio::river::Manager::createOutput(float _freq,
|
2017-08-28 00:08:50 +02:00
|
|
|
const etk::Vector<audio::channel>& _map,
|
2016-09-26 22:31:05 +02:00
|
|
|
audio::format _format,
|
2017-08-28 00:08:50 +02:00
|
|
|
const etk::String& _streamName,
|
|
|
|
const etk::String& _options) {
|
2015-03-12 22:28:15 +01:00
|
|
|
// get global hardware interface:
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
|
2015-03-12 22:28:15 +01:00
|
|
|
if (manager == nullptr) {
|
|
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
2016-07-19 21:43:58 +02:00
|
|
|
return ememory::SharedPtr<audio::river::Interface>();
|
2015-02-12 22:08:23 +01:00
|
|
|
}
|
2015-03-12 22:28:15 +01:00
|
|
|
// get the output or input channel :
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::io::Node> node = manager->getNode(_streamName);
|
2015-03-12 22:28:15 +01:00
|
|
|
if (node == nullptr) {
|
|
|
|
RIVER_ERROR("Can not get the Requested stream '" << _streamName << "' ==> not listed in : " << manager->getListStream());
|
2016-07-19 21:43:58 +02:00
|
|
|
return ememory::SharedPtr<audio::river::Interface>();
|
2015-02-12 22:08:23 +01:00
|
|
|
}
|
2015-03-12 22:28:15 +01:00
|
|
|
if (node->isOutput() != true) {
|
|
|
|
RIVER_ERROR("Can not Connect output on other thing than output ... for stream '" << _streamName << "'");;
|
2016-07-19 21:43:58 +02:00
|
|
|
return ememory::SharedPtr<audio::river::Interface>();
|
2015-03-04 22:15:35 +01:00
|
|
|
}
|
2015-01-25 22:17:06 +01:00
|
|
|
// create user iterface:
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::Interface> interface;
|
2016-04-20 21:19:11 +02:00
|
|
|
ejson::Object tmpOption = ejson::Object(_options);
|
2016-04-28 23:46:12 +02:00
|
|
|
tmpOption.add("io", ejson::String("output"));
|
2015-04-11 09:38:30 +02:00
|
|
|
interface = audio::river::Interface::create(_freq, _map, _format, node, tmpOption);
|
2015-01-25 22:17:06 +01:00
|
|
|
// store it in a list (needed to apply some parameters).
|
2017-08-28 00:08:50 +02:00
|
|
|
m_listOpenInterface.pushBack(interface);
|
2015-01-25 22:17:06 +01:00
|
|
|
return interface;
|
|
|
|
}
|
|
|
|
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::Interface> audio::river::Manager::createInput(float _freq,
|
2017-08-28 00:08:50 +02:00
|
|
|
const etk::Vector<audio::channel>& _map,
|
2016-09-26 22:31:05 +02:00
|
|
|
audio::format _format,
|
2017-08-28 00:08:50 +02:00
|
|
|
const etk::String& _streamName,
|
|
|
|
const etk::String& _options) {
|
2015-03-12 22:28:15 +01:00
|
|
|
// get global hardware interface:
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
|
2015-03-12 22:28:15 +01:00
|
|
|
if (manager == nullptr) {
|
|
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
2016-07-19 21:43:58 +02:00
|
|
|
return ememory::SharedPtr<audio::river::Interface>();
|
2015-02-12 22:08:23 +01:00
|
|
|
}
|
2015-03-12 22:28:15 +01:00
|
|
|
// get the output or input channel :
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::io::Node> node = manager->getNode(_streamName);
|
2015-03-12 22:28:15 +01:00
|
|
|
if (node == nullptr) {
|
|
|
|
RIVER_ERROR("Can not get the Requested stream '" << _streamName << "' ==> not listed in : " << manager->getListStream());
|
2016-07-19 21:43:58 +02:00
|
|
|
return ememory::SharedPtr<audio::river::Interface>();
|
2015-02-12 22:08:23 +01:00
|
|
|
}
|
2015-03-12 22:28:15 +01:00
|
|
|
if (node->isInput() != true) {
|
|
|
|
RIVER_ERROR("Can not Connect input on other thing than input ... for stream '" << _streamName << "'");;
|
2016-07-19 21:43:58 +02:00
|
|
|
return ememory::SharedPtr<audio::river::Interface>();
|
2015-03-04 22:15:35 +01:00
|
|
|
}
|
2015-03-12 22:28:15 +01:00
|
|
|
// create user iterface:
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::Interface> interface;
|
2016-04-20 21:19:11 +02:00
|
|
|
ejson::Object tmpOption = ejson::Object(_options);
|
2016-04-28 23:46:12 +02:00
|
|
|
tmpOption.add("io", ejson::String("input"));
|
2015-04-11 09:38:30 +02:00
|
|
|
interface = audio::river::Interface::create(_freq, _map, _format, node, tmpOption);
|
2015-03-12 22:28:15 +01:00
|
|
|
// store it in a list (needed to apply some parameters).
|
2017-08-28 00:08:50 +02:00
|
|
|
m_listOpenInterface.pushBack(interface);
|
2015-03-12 22:28:15 +01:00
|
|
|
return interface;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::Interface> audio::river::Manager::createFeedback(float _freq,
|
2017-08-28 00:08:50 +02:00
|
|
|
const etk::Vector<audio::channel>& _map,
|
2016-09-26 22:31:05 +02:00
|
|
|
audio::format _format,
|
2017-08-28 00:08:50 +02:00
|
|
|
const etk::String& _streamName,
|
|
|
|
const etk::String& _options) {
|
2015-01-25 22:17:06 +01:00
|
|
|
// get global hardware interface:
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
|
2015-03-12 22:28:15 +01:00
|
|
|
if (manager == nullptr) {
|
|
|
|
RIVER_ERROR("Unable to load harware IO manager ... ");
|
2016-07-19 21:43:58 +02:00
|
|
|
return ememory::SharedPtr<audio::river::Interface>();
|
2015-03-12 22:28:15 +01:00
|
|
|
}
|
2015-01-25 22:17:06 +01:00
|
|
|
// get the output or input channel :
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::io::Node> node = manager->getNode(_streamName);
|
2015-03-12 22:28:15 +01:00
|
|
|
if (node == nullptr) {
|
|
|
|
RIVER_ERROR("Can not get the Requested stream '" << _streamName << "' ==> not listed in : " << manager->getListStream());
|
2016-07-19 21:43:58 +02:00
|
|
|
return ememory::SharedPtr<audio::river::Interface>();
|
2015-03-12 22:28:15 +01:00
|
|
|
}
|
|
|
|
if (node->isOutput() != true) {
|
|
|
|
RIVER_ERROR("Can not Connect feedback on other thing than output ... for stream '" << _streamName << "'");;
|
2016-07-19 21:43:58 +02:00
|
|
|
return ememory::SharedPtr<audio::river::Interface>();
|
2015-03-12 22:28:15 +01:00
|
|
|
}
|
2015-01-25 22:17:06 +01:00
|
|
|
// create user iterface:
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::Interface> interface;
|
2016-04-20 21:19:11 +02:00
|
|
|
ejson::Object tmpOption = ejson::Object(_options);
|
2016-04-28 23:46:12 +02:00
|
|
|
tmpOption.add("io", ejson::String("feedback"));
|
2015-04-11 09:38:30 +02:00
|
|
|
interface = audio::river::Interface::create(_freq, _map, _format, node, tmpOption);
|
2015-01-25 22:17:06 +01:00
|
|
|
// store it in a list (needed to apply some parameters).
|
2017-08-28 00:08:50 +02:00
|
|
|
m_listOpenInterface.pushBack(interface);
|
2015-01-25 22:17:06 +01:00
|
|
|
return interface;
|
|
|
|
}
|
2015-02-18 15:22:48 +01:00
|
|
|
|
2017-08-28 00:08:50 +02:00
|
|
|
void audio::river::Manager::generateDotAll(const etk::String& _filename) {
|
2015-02-18 15:22:48 +01:00
|
|
|
// get global hardware interface:
|
2016-07-19 21:43:58 +02:00
|
|
|
ememory::SharedPtr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
|
2015-02-18 15:22:48 +01:00
|
|
|
if (manager == nullptr) {
|
|
|
|
RIVER_ERROR("Can not get the harware manager");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
manager->generateDot(_filename);
|
|
|
|
}
|