audio-river/river/Manager.cpp

229 lines
8.7 KiB
C++
Raw Normal View History

2015-01-25 22:17:06 +01:00
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include "Manager.h"
2015-01-26 22:04:29 +01:00
#include "Interface.h"
2015-01-25 22:17:06 +01:00
#include <stdexcept>
#include "io/Manager.h"
#include "io/Node.h"
2015-02-01 22:21:03 +01:00
#include "debug.h"
2015-03-12 22:28:15 +01:00
#include <ejson/ejson.h>
2015-01-25 22:17:06 +01:00
2015-01-27 21:01:52 +01:00
#undef __class__
#define __class__ "Manager"
2015-03-23 21:26:45 +01:00
static std11::mutex g_mutex;
static std::vector<std11::weak_ptr<river::Manager> > g_listOfAllManager;
2015-01-27 21:01:52 +01:00
2015-02-24 22:20:11 +01:00
std11::shared_ptr<river::Manager> river::Manager::create(const std::string& _applicationUniqueId) {
2015-03-23 22:46:21 +01:00
std11::unique_lock<std11::mutex> lock(g_mutex);
2015-03-23 21:26:45 +01:00
for (size_t iii=0; iii<g_listOfAllManager.size() ; ++iii) {
std11::shared_ptr<river::Manager> tmp = g_listOfAllManager[iii].lock();
if (tmp == nullptr) {
continue;
}
if (tmp->m_applicationUniqueId == _applicationUniqueId) {
return tmp;
}
}
// create a new one:
std11::shared_ptr<river::Manager> out = std11::shared_ptr<river::Manager>(new river::Manager(_applicationUniqueId));
// 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;
}
}
g_listOfAllManager.push_back(out);
return out;
2015-01-25 22:17:06 +01:00
}
2015-02-05 19:10:53 +01:00
river::Manager::Manager(const std::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-02-05 19:10:53 +01:00
river::Manager::~Manager() {
2015-01-25 22:17:06 +01:00
// TODO : Stop all interfaces...
}
2015-03-12 22:28:15 +01:00
std::vector<std::string> river::Manager::getListStreamInput() {
std::vector<std::string> output;
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
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;
}
2015-03-12 22:28:15 +01:00
std::vector<std::string> river::Manager::getListStreamOutput() {
std::vector<std::string> output;
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
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;
}
2015-03-12 22:28:15 +01:00
std::vector<std::string> river::Manager::getListStreamVirtual() {
std::vector<std::string> output;
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
if (manager == nullptr) {
RIVER_ERROR("Unable to load harware IO manager ... ");
} else {
output = manager->getListStreamVirtual();
}
return output;
}
std::vector<std::string> river::Manager::getListStream() {
std::vector<std::string> output;
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
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
2015-02-05 19:10:53 +01:00
bool river::Manager::setVolume(const std::string& _volumeName, float _valuedB) {
2015-03-12 22:28:15 +01:00
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
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
2015-02-05 19:10:53 +01:00
float river::Manager::getVolume(const std::string& _volumeName) const {
2015-03-12 22:28:15 +01:00
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
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
}
2015-02-05 19:10:53 +01:00
std::pair<float,float> river::Manager::getVolumeRange(const std::string& _volumeName) const {
2015-03-12 22:28:15 +01:00
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
if (manager == nullptr) {
RIVER_ERROR("Unable to load harware IO manager ... ");
return std::make_pair<float,float>(0.0f,0.0f);
}
return manager->getVolumeRange(_volumeName);
2015-01-30 21:44:36 +01:00
}
2015-02-24 22:20:11 +01:00
std11::shared_ptr<river::Interface> river::Manager::createOutput(float _freq,
2015-03-12 22:28:15 +01:00
const std::vector<audio::channel>& _map,
audio::format _format,
const std::string& _streamName,
const std::string& _options) {
// get global hardware interface:
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
if (manager == nullptr) {
RIVER_ERROR("Unable to load harware IO manager ... ");
2015-02-24 22:20:11 +01:00
return std11::shared_ptr<river::Interface>();
2015-02-12 22:08:23 +01:00
}
2015-03-12 22:28:15 +01:00
// get the output or input channel :
std11::shared_ptr<river::io::Node> node = manager->getNode(_streamName);
if (node == nullptr) {
RIVER_ERROR("Can not get the Requested stream '" << _streamName << "' ==> not listed in : " << manager->getListStream());
2015-02-24 22:20:11 +01:00
return std11::shared_ptr<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 << "'");;
2015-03-04 22:15:35 +01:00
return std11::shared_ptr<river::Interface>();
}
2015-01-25 22:17:06 +01:00
// create user iterface:
2015-02-24 22:20:11 +01:00
std11::shared_ptr<river::Interface> interface;
2015-03-12 22:28:15 +01:00
std11::shared_ptr<ejson::Object> tmpOption = ejson::Object::create(_options);
tmpOption->addString("io", "output");
interface = 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).
m_listOpenInterface.push_back(interface);
return interface;
}
2015-02-24 22:20:11 +01:00
std11::shared_ptr<river::Interface> river::Manager::createInput(float _freq,
2015-03-12 22:28:15 +01:00
const std::vector<audio::channel>& _map,
audio::format _format,
const std::string& _streamName,
const std::string& _options) {
// get global hardware interface:
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
if (manager == nullptr) {
RIVER_ERROR("Unable to load harware IO manager ... ");
2015-02-24 22:20:11 +01:00
return std11::shared_ptr<river::Interface>();
2015-02-12 22:08:23 +01:00
}
2015-03-12 22:28:15 +01:00
// get the output or input channel :
std11::shared_ptr<river::io::Node> node = manager->getNode(_streamName);
if (node == nullptr) {
RIVER_ERROR("Can not get the Requested stream '" << _streamName << "' ==> not listed in : " << manager->getListStream());
2015-02-24 22:20:11 +01:00
return std11::shared_ptr<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 << "'");;
2015-03-04 22:15:35 +01:00
return std11::shared_ptr<river::Interface>();
}
2015-03-12 22:28:15 +01:00
// create user iterface:
std11::shared_ptr<river::Interface> interface;
std11::shared_ptr<ejson::Object> tmpOption = ejson::Object::create(_options);
tmpOption->addString("io", "input");
interface = 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<river::Interface> river::Manager::createFeedback(float _freq,
const std::vector<audio::channel>& _map,
audio::format _format,
const std::string& _streamName,
const std::string& _options) {
2015-01-25 22:17:06 +01:00
// get global hardware interface:
2015-02-24 22:20:11 +01:00
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
2015-03-12 22:28:15 +01:00
if (manager == nullptr) {
RIVER_ERROR("Unable to load harware IO manager ... ");
return std11::shared_ptr<river::Interface>();
}
2015-01-25 22:17:06 +01:00
// get the output or input channel :
2015-03-12 22:28:15 +01:00
std11::shared_ptr<river::io::Node> 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<river::Interface>();
}
if (node->isOutput() != true) {
RIVER_ERROR("Can not Connect feedback on other thing than output ... for stream '" << _streamName << "'");;
return std11::shared_ptr<river::Interface>();
}
2015-01-25 22:17:06 +01:00
// create user iterface:
2015-02-24 22:20:11 +01:00
std11::shared_ptr<river::Interface> interface;
2015-03-12 22:28:15 +01:00
std11::shared_ptr<ejson::Object> tmpOption = ejson::Object::create(_options);
tmpOption->addString("io", "feedback");
interface = 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).
m_listOpenInterface.push_back(interface);
return interface;
}
2015-02-18 15:22:48 +01:00
void river::Manager::generateDotAll(const std::string& _filename) {
// get global hardware interface:
2015-02-24 22:20:11 +01:00
std11::shared_ptr<river::io::Manager> manager = 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);
}