[DEV] add parameter set and file hardware config file read

This commit is contained in:
2015-02-03 21:29:23 +01:00
parent 7d969673c0
commit d6cc8fce3b
11 changed files with 302 additions and 55 deletions

View File

@@ -6,26 +6,58 @@
#include "Manager.h"
#include <memory>
#include <airtio/debug.h>
#include "Node.h"
#undef __class__
#define __class__ "io::Manager"
airtio::io::Manager::Manager() {
if (m_config.load("DATA:hardware.json") == false) {
AIRTIO_ERROR("you must set a basic configuration file for harware configuration: DATA:hardware.json");
}
};
std::shared_ptr<airtio::io::Manager> airtio::io::Manager::getInstance() {
static std::shared_ptr<airtio::io::Manager> manager(new Manager());
return manager;
}
std::shared_ptr<airtio::io::Node> airtio::io::Manager::getNode(const std::string& _streamName, bool _isInput) {
std::shared_ptr<airtio::io::Node> airtio::io::Manager::getNode(const std::string& _name) {
for (size_t iii=0; iii< m_list.size(); ++iii) {
std::shared_ptr<airtio::io::Node> tmppp = m_list[iii].lock();
if ( tmppp!=nullptr
&& _streamName == tmppp->getName()
&& _isInput == tmppp->isInput()) {
if ( tmppp != nullptr
&& _name == tmppp->getName()) {
return tmppp;
}
}
std::shared_ptr<airtio::io::Node> tmp = airtio::io::Node::create(_streamName, _isInput);
m_list.push_back(tmp);
return tmp;
// check if the node can be open :
const std::shared_ptr<const ejson::Object> tmpObject = m_config.getObject(_name);
if (tmpObject != nullptr) {
std::shared_ptr<airtio::io::Node> tmp = airtio::io::Node::create(_name, tmpObject);
m_list.push_back(tmp);
return tmp;
}
AIRTIO_ERROR("Can not create the interface : '" << _name << "' the node is not DEFINED in the configuration file availlable : " << m_config.getKeys());
return nullptr;
}
std::shared_ptr<airtalgo::VolumeElement> airtio::io::Manager::getVolumeGroup(const std::string& _name) {
if (_name == "") {
AIRTIO_ERROR("Try to create an audio group with no name ...");
return nullptr;
}
for (auto &it : m_volumeGroup) {
if (it == nullptr) {
continue;
}
if (it->getName() == _name) {
return nullptr;
}
}
AIRTIO_DEBUG("Add a new volume group : '" << _name << "'");
std::shared_ptr<airtalgo::VolumeElement> tmpVolume = std::make_shared<airtalgo::VolumeElement>(_name);
m_volumeGroup.push_back(tmpVolume);
return tmpVolume;
}

View File

@@ -15,7 +15,9 @@
#include <functional>
#include <airtalgo/format.h>
#include <airtalgo/channel.h>
#include <ejson/ejson.h>
#include <memory>
#include <airtalgo/Volume.h>
namespace airtio {
namespace io {
@@ -25,7 +27,7 @@ namespace airtio {
/**
* @brief Constructor
*/
Manager() {};
Manager();
public:
static std::shared_ptr<Manager> getInstance();
/**
@@ -33,10 +35,15 @@ namespace airtio {
*/
virtual ~Manager() {};
private:
std::vector<std::weak_ptr<airtio::io::Node> > m_list;
ejson::Document m_config; // harware configuration
std::vector<std::shared_ptr<airtio::io::Node> > m_listKeepAlive; //!< list of all Node that might be keep alive sone time
std::vector<std::weak_ptr<airtio::io::Node> > m_list; //!< List of all IO node
public:
std::shared_ptr<airtio::io::Node> getNode(const std::string& _streamName, bool _isInput);
std::shared_ptr<airtio::io::Node> getNode(const std::string& _name);
private:
std::vector<std::shared_ptr<airtalgo::VolumeElement>> m_volumeGroup;
public:
std::shared_ptr<airtalgo::VolumeElement> getVolumeGroup(const std::string& _name);
};
}
}

View File

@@ -74,39 +74,115 @@ int32_t airtio::io::Node::rtAudioCallback(void* _outputBuffer,
}
std::shared_ptr<airtio::io::Node> airtio::io::Node::create(const std::string& _streamName, bool _isInput) {
return std::shared_ptr<airtio::io::Node>(new airtio::io::Node(_streamName, _isInput));
std::shared_ptr<airtio::io::Node> airtio::io::Node::create(const std::string& _name, const std::shared_ptr<const ejson::Object>& _config) {
return std::shared_ptr<airtio::io::Node>(new airtio::io::Node(_name, _config));
}
airtio::io::Node::Node(const std::string& _streamName, bool _isInput) :
m_streamName(_streamName),
m_isInput(_isInput) {
airtio::io::Node::Node(const std::string& _name, const std::shared_ptr<const ejson::Object>& _config) :
m_config(_config),
m_name(_name),
m_isInput(false) {
AIRTIO_INFO("-----------------------------------------------------------------");
AIRTIO_INFO("-- CREATE NODE --");
AIRTIO_INFO("-----------------------------------------------------------------");
// intanciate specific API ...
m_adac.instanciate();
/**
io:"input", # input or output
map-on:{ # select hardware interface and name
interface:"alsa", # interface : "alsa", "pulse", "core", ...
name:"default", # name of the interface
},
frequency:48000, # frequency to open device
channel-map:[ # mapping of the harware device (to change map if needed)
"front-left", "front-right",
"read-left", "rear-right",
],
type:"int16", # format to open device (int8, int16, int16-on-ont32, int24, int32, float)
nb-chunk:1024 # number of chunk to open device (create the latency anf the frequency to call user)
*/
m_isInput = m_config->getStringValue("io") == "input";
enum airtaudio::api::type typeInterface = airtaudio::api::LINUX_ALSA;
std::string streamName = "default";
const std::shared_ptr<const ejson::Object> tmpObject = m_config->getObject("map-on");
if (tmpObject == nullptr) {
AIRTIO_WARNING("missing node : 'map-on' ==> auto map : 'alsa:default'");
} else {
std::string value = tmpObject->getStringValue("interface", "default");
if (value == "alsa") {
typeInterface = airtaudio::api::LINUX_ALSA;
} else if (value == "pulse") {
typeInterface = airtaudio::api::LINUX_PULSE;
} else if (value == "b") {
typeInterface = airtaudio::api::LINUX_OSS;
} else if (value == "jack") {
typeInterface = airtaudio::api::UNIX_JACK;
} else if (value == "mac-core") {
typeInterface = airtaudio::api::MACOSX_CORE;
} else if (value == "ios-core") {
typeInterface = airtaudio::api::IOS_CORE;
} else if (value == "asio") {
typeInterface = airtaudio::api::WINDOWS_ASIO;
} else if (value == "ds") {
typeInterface = airtaudio::api::WINDOWS_DS;
} else if (value == "dummy") {
typeInterface = airtaudio::api::RTAUDIO_DUMMY;
} else if (value == "java") {
typeInterface = airtaudio::api::ANDROID_JAVA;
} else if (value == "user-1") {
typeInterface = airtaudio::api::USER_INTERFACE_1;
} else if (value == "user-2") {
typeInterface = airtaudio::api::USER_INTERFACE_2;
} else if (value == "user-3") {
typeInterface = airtaudio::api::USER_INTERFACE_3;
} else if (value == "user-4") {
typeInterface = airtaudio::api::USER_INTERFACE_4;
} else {
AIRTIO_WARNING("Unknow interface : '" << value << "'");
}
streamName = tmpObject->getStringValue("name", "default");
}
int32_t frequency = m_config->getNumberValue("frequency", 48000);
std::string type = m_config->getStringValue("type", "int16");
int32_t nbChunk = m_config->getNumberValue("nb-chunk", 1024);
std::string volumeName = m_config->getStringValue("volume-name", "");
if (volumeName != "") {
AIRTIO_INFO("add node volume stage : '" << volumeName << "'");
m_volume = std::make_shared<airtalgo::VolumeElement>(volumeName);
}
if (m_streamName == "") {
m_streamName = "default";
enum airtalgo::format formatType = airtalgo::format_int16;
if (type == "int16") {
formatType = airtalgo::format_int16;
} else {
AIRTIO_WARNING("not managed type : '" << type << "'");
}
// TODO : MAP ...
// intanciate specific API ...
m_adac.instanciate(typeInterface);
// TODO : Check return ...
if (streamName == "") {
streamName = "default";
}
std::vector<airtalgo::channel> map;
// set default channel property :
map.push_back(airtalgo::channel_frontLeft);
map.push_back(airtalgo::channel_frontRight);
m_hardwareFormat.set(map, airtalgo::format_int16, 48000);
m_hardwareFormat.set(map, formatType, frequency);
// TODO : Better view of interface type float -> float, int16 -> int16/int32, ...
if (m_isInput == true) {
// for input we just transfert audio with no transformation
m_interfaceFormat.set(map, airtalgo::format_int16, 48000);
m_interfaceFormat.set(map, airtalgo::format_int16, frequency);
} else {
// for output we will do a mix ...
m_interfaceFormat.set(map, airtalgo::format_int16_on_int32, 48000);
m_interfaceFormat.set(map, airtalgo::format_int16_on_int32, frequency);
}
// search device ID :
AIRTIO_INFO("Open :");
AIRTIO_INFO(" m_streamName=" << m_streamName);
AIRTIO_INFO(" m_streamName=" << streamName);
AIRTIO_INFO(" m_freq=" << m_hardwareFormat.getFrequency());
AIRTIO_INFO(" m_map=" << m_hardwareFormat.getMap());
AIRTIO_INFO(" m_format=" << m_hardwareFormat.getFormat());
@@ -116,7 +192,7 @@ airtio::io::Node::Node(const std::string& _streamName, bool _isInput) :
for (int32_t iii=0; iii<m_adac.getDeviceCount(); ++iii) {
m_info = m_adac.getDeviceInfo(iii);
AIRTIO_INFO(" " << iii << " name :" << m_info.name);
if (m_info.name == m_streamName) {
if (m_info.name == streamName) {
AIRTIO_INFO(" Select ...");
deviceId = iii;
}
@@ -165,7 +241,6 @@ airtio::io::Node::Node(const std::string& _streamName, bool _isInput) :
}
// open Audio device:
unsigned int nbChunk= 1024;
airtaudio::StreamParameters params;
params.deviceId = deviceId;
if (m_isInput == true) {
@@ -203,7 +278,7 @@ airtio::io::Node::Node(const std::string& _streamName, bool _isInput) :
);
}
if (err != airtaudio::errorNone) {
AIRTIO_ERROR("Create stream : '" << m_streamName << "' mode=" << (m_isInput?"input":"output") << " can not create strem " << err);
AIRTIO_ERROR("Create stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") << " can not create stream " << err);
}
}
@@ -220,19 +295,19 @@ airtio::io::Node::~Node() {
void airtio::io::Node::start() {
std::unique_lock<std::mutex> lock(m_mutex);
AIRTIO_INFO("Start stream : '" << m_streamName << "' mode=" << (m_isInput?"input":"output") );
AIRTIO_INFO("Start stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") );
enum airtaudio::errorType err = m_adac.startStream();
if (err != airtaudio::errorNone) {
AIRTIO_ERROR("Start stream : '" << m_streamName << "' mode=" << (m_isInput?"input":"output") << " can not start stream ... " << err);
AIRTIO_ERROR("Start stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") << " can not start stream ... " << err);
}
}
void airtio::io::Node::stop() {
std::unique_lock<std::mutex> lock(m_mutex);
AIRTIO_INFO("Stop stream : '" << m_streamName << "' mode=" << (m_isInput?"input":"output") );
AIRTIO_INFO("Stop stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") );
enum airtaudio::errorType err = m_adac.stopStream();
if (err != airtaudio::errorNone) {
AIRTIO_ERROR("Stop stream : '" << m_streamName << "' mode=" << (m_isInput?"input":"output") << " can not stop stream ... " << err);
AIRTIO_ERROR("Stop stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") << " can not stop stream ... " << err);
}
}
@@ -244,7 +319,7 @@ void airtio::io::Node::interfaceAdd(const std::shared_ptr<airtio::Interface>& _i
return;
}
}
AIRTIO_INFO("ADD interface for stream : '" << m_streamName << "' mode=" << (m_isInput?"input":"output") );
AIRTIO_INFO("ADD interface for stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") );
m_list.push_back(_interface);
}
if (m_list.size() == 1) {
@@ -258,7 +333,7 @@ void airtio::io::Node::interfaceRemove(const std::shared_ptr<airtio::Interface>&
for (size_t iii=0; iii< m_list.size(); ++iii) {
if (_interface == m_list[iii]) {
m_list.erase(m_list.begin()+iii);
AIRTIO_INFO("RM interface for stream : '" << m_streamName << "' mode=" << (m_isInput?"input":"output") );
AIRTIO_INFO("RM interface for stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") );
break;
}
}

View File

@@ -20,6 +20,7 @@
#include <airtio/Interface.h>
#include <airtaudio/Interface.h>
#include <airtalgo/IOFormatInterface.h>
#include <airtalgo/Volume.h>
namespace airtio {
namespace io {
@@ -27,13 +28,15 @@ namespace airtio {
class Node {
private:
mutable std::mutex m_mutex;
std::shared_ptr<const ejson::Object> m_config;
std::shared_ptr<airtalgo::VolumeElement> m_volume; //!< if a volume is set it is set here ...
private:
/**
* @brief Constructor
*/
Node(const std::string& _streamName, bool _isInput);
Node(const std::string& _name, const std::shared_ptr<const ejson::Object>& _config);
public:
static std::shared_ptr<Node> create(const std::string& _streamName, bool _isInput);
static std::shared_ptr<Node> create(const std::string& _name, const std::shared_ptr<const ejson::Object>& _config);
/**
* @brief Destructor
*/
@@ -54,10 +57,10 @@ namespace airtio {
double _streamTime,
airtaudio::streamStatus _status);
private:
std::string m_streamName;
std::string m_name;
public:
const std::string& getName() {
return m_streamName;
return m_name;
}
private:
airtalgo::IOFormatInterface m_interfaceFormat;
@@ -79,6 +82,10 @@ namespace airtio {
private:
void start();
void stop();
public:
const std::shared_ptr<airtalgo::VolumeElement>& getVolume() {
return m_volume;
}
};
}
}