[DEV] start work on dynamic chain

This commit is contained in:
2015-02-01 22:21:03 +01:00
parent 12a60900cc
commit 29f8b24b2b
6 changed files with 137 additions and 72 deletions

View File

@@ -13,6 +13,7 @@
#include <airtalgo/EndPointCallback.h>
#include <airtalgo/EndPointWrite.h>
#include <airtalgo/EndPointRead.h>
#include <airtalgo/Volume.h>
#undef __class__
@@ -43,6 +44,13 @@ bool airtio::Interface::init(const std::string& _name,
// Create convertion interface
if (m_node->isInput() == true) {
// add all time the volume stage :
std::shared_ptr<airtalgo::Volume> algo = airtalgo::Volume::create();
algo->setInputFormat(airtalgo::IOFormatInterface(m_node->getMap(), m_node->getFormat(), m_node->getFrequency()));
algo->setName("volume");
m_process->pushBack(algo);
AIRTIO_INFO("add basic volume stage");
/*
// TODO : Set an auto update of IO
if (m_map != m_node->getMap()) {
std::shared_ptr<airtalgo::ChannelReorder> algo = airtalgo::ChannelReorder::create();
@@ -65,23 +73,15 @@ bool airtio::Interface::init(const std::string& _name,
m_process->pushBack(algo);
AIRTIO_INFO("convert " << m_node->getFormat() << " -> " << m_format);
}
// by default we add a read node
if (true) {
std::shared_ptr<airtalgo::EndPointRead> algo = airtalgo::EndPointRead::create();
algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq));
algo->setOutputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq));
m_process->pushBack(algo);
AIRTIO_INFO("add default read node ...");
}
*/
} else {
// by default we add a write node:
if (true) {
std::shared_ptr<airtalgo::EndPointWrite> algo = airtalgo::EndPointWrite::create();
algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq));
algo->setOutputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq));
m_process->pushBack(algo);
AIRTIO_INFO("add default write node ...");
}
// add all time the volume stage :
std::shared_ptr<airtalgo::Volume> algo = airtalgo::Volume::create();
algo->setOutputFormat(airtalgo::IOFormatInterface(m_node->getMap(), m_node->getFormat(), m_node->getFrequency()));
algo->setName("volume");
m_process->pushBack(algo);
AIRTIO_INFO("add basic volume stage");
/*
// TODO : Set an auto update of IO
if (m_format != m_node->getFormat()) {
std::shared_ptr<airtalgo::FormatUpdate> algo = airtalgo::FormatUpdate::create();
@@ -104,6 +104,7 @@ bool airtio::Interface::init(const std::string& _name,
m_process->pushBack(algo);
AIRTIO_INFO("convert " << m_map << " -> " << m_node->getMap());
}
*/
}
//m_node->interfaceAdd(shared_from_this());
return true;
@@ -125,7 +126,31 @@ airtio::Interface::~Interface() {
//m_node->interfaceRemove(shared_from_this());
m_process.reset();
}
/*
bool airtio::Interface::hasEndPoint() {
}
*/
void airtio::Interface::setReadwrite() {
std::unique_lock<std::recursive_mutex> lock(m_mutex);
if (m_process->hasType<airtalgo::EndPoint>() ) {
AIRTIO_ERROR("Endpoint is already present ==> can not change");
return;
}
if (m_node->isInput() == true) {
m_process->removeIfLast<airtalgo::EndPoint>();
std::shared_ptr<airtalgo::EndPointRead> algo = airtalgo::EndPointRead::create();
///algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq));
algo->setOutputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq));
m_process->pushBack(algo);
} else {
m_process->removeIfFirst<airtalgo::EndPoint>();
std::shared_ptr<airtalgo::EndPointWrite> algo = airtalgo::EndPointWrite::create();
algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq));
//algo->setOutputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq));
m_process->pushBack(algo);
}
}
void airtio::Interface::setOutputCallback(size_t _chunkSize, airtalgo::needDataFunction _function) {
std::unique_lock<std::recursive_mutex> lock(m_mutex);
@@ -133,7 +158,7 @@ void airtio::Interface::setOutputCallback(size_t _chunkSize, airtalgo::needDataF
std::shared_ptr<airtalgo::Algo> algo = airtalgo::EndPointCallback::create(_function);
AIRTIO_INFO("set property: " << m_map << " " << m_format << " " << m_freq);
algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq));
algo->setOutputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq));
//algo->setOutputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq));
m_process->pushFront(algo);
}
@@ -141,7 +166,7 @@ void airtio::Interface::setInputCallback(size_t _chunkSize, airtalgo::haveNewDat
std::unique_lock<std::recursive_mutex> lock(m_mutex);
m_process->removeIfLast<airtalgo::EndPoint>();
std::shared_ptr<airtalgo::Algo> algo = airtalgo::EndPointCallback::create(_function);
algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq));
//algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq));
algo->setOutputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq));
m_process->pushBack(algo);
}
@@ -158,6 +183,7 @@ void airtio::Interface::setWriteCallback(airtalgo::needDataFunctionWrite _functi
void airtio::Interface::start(const std::chrono::system_clock::time_point& _time) {
std::unique_lock<std::recursive_mutex> lock(m_mutex);
AIRTIO_DEBUG("start [BEGIN]");
m_process->updateInterAlgo();
m_node->interfaceAdd(shared_from_this());
AIRTIO_DEBUG("start [ END ]");
}
@@ -165,6 +191,7 @@ void airtio::Interface::start(const std::chrono::system_clock::time_point& _time
void airtio::Interface::stop(bool _fast, bool _abort) {
std::unique_lock<std::recursive_mutex> lock(m_mutex);
AIRTIO_DEBUG("stop [BEGIN]");
m_process->removeAlgoDynamic();
m_node->interfaceRemove(shared_from_this());
AIRTIO_DEBUG("stop [ END]");
}
@@ -285,4 +312,6 @@ void airtio::Interface::systemNeedOutputData(std::chrono::system_clock::time_poi
m_process->pull(_time, _data, _nbChunk, _chunkSize);
}
bool airtio::Interface::systemSetVolume(const std::string& _parameter, const std::string& _value);
bool airtio::Interface::systemSetVolume(const std::string& _parameter, const std::string& _value) {
return false;
}

View File

@@ -61,13 +61,29 @@ namespace airtio {
const std::vector<airtalgo::channel>& _map,
airtalgo::format _format,
const std::shared_ptr<airtio::io::Node>& _node);
public:
/**
* @brief When we want to implement a Callback Mode :
* @brief set the read/write mode enable.
*/
virtual void setReadwrite();
/**
* @brief When we want to implement a Callback Mode:
*/
virtual void setWriteCallback(airtalgo::needDataFunctionWrite _function);
virtual void setOutputCallback(size_t _chunkSize, airtalgo::needDataFunction _function);
virtual void setInputCallback(size_t _chunkSize, airtalgo::haveNewDataFunction _function);
/**
* @brief Add a volume group of the current channel.
* @note If you do not call this function with the group "FLOW" you chan not have a channel volume.
* @note the set volume stage can not be set after the start.
* @param[in] _name Name of the group classicle common group:
* - FLOW for channel volume.
* - MEDIA for multimedia volume control (audio player, player video, web streaming ...).
* - TTS for Test-to-speech volume control.
* - COMMUNICATION for user communication volume control.
* - NOTIFICATION for urgent notification volume control.
* - NOISE for small nose volume control.
*/
virtual void addVolumeGroup(const std::string& _name) {}
public:
/**
* @brief Start the Audio interface flow.

View File

@@ -11,6 +11,7 @@
#include "io/Manager.h"
#include "io/Node.h"
#include "debug.h"
#undef __class__
#define __class__ "Manager"
@@ -21,9 +22,7 @@ std::shared_ptr<airtio::Manager> airtio::Manager::create(const std::string& _app
airtio::Manager::Manager(const std::string& _applicationUniqueId) :
m_applicationUniqueId(_applicationUniqueId),
m_listOpenInterface(),
m_masterVolume(0.0f),
m_masterVolumeRange(std::make_pair(-120.0f, 0.0f)) {
m_listOpenInterface() {
}
@@ -45,7 +44,7 @@ std::vector<std::pair<std::string,std::string> > airtio::Manager::getListStreamO
}
bool setParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter, const std::string& _value) {
bool airtio::Manager::setParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter, const std::string& _value) {
AIRTIO_DEBUG("setParameter [BEGIN] : '" << _flow << "':'" << _filter << "':'" << _parameter << "':'" << _value << "'");
bool out = false;
if ( _filter == "volume"
@@ -56,7 +55,7 @@ bool setParameter(const std::string& _flow, const std::string& _filter, const st
AIRTIO_DEBUG("setParameter [ END ] : '" << out << "'");
return out;
}
std::string getParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter) const {
std::string airtio::Manager::getParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter) const {
AIRTIO_DEBUG("getParameter [BEGIN] : '" << _flow << "':'" << _filter << "':'" << _parameter << "'");
std::string out;
AIRTIO_TODO(" IMPLEMENT");
@@ -64,7 +63,7 @@ std::string getParameter(const std::string& _flow, const std::string& _filter, c
return out;
}
std::string getParameterProperty(const std::string& _flow, const std::string& _filter, const std::string& _parameter) const {
std::string airtio::Manager::getParameterProperty(const std::string& _flow, const std::string& _filter, const std::string& _parameter) const {
AIRTIO_DEBUG("getParameterProperty [BEGIN] : '" << _flow << "':'" << _filter << "':'" << _parameter << "'");
std::string out;
AIRTIO_TODO(" IMPLEMENT");
@@ -72,47 +71,6 @@ std::string getParameterProperty(const std::string& _flow, const std::string& _f
return out;
}
// TODO : Deprecated ...
void airtio::Manager::setMasterOutputVolume(float _gainDB) {
if (_gainDB < m_masterVolumeRange.first) {
//throw std::range_error(std::string(_gainDB) + " is out of bonds : [" + m_masterVolumeRange.first + ".." + m_masterVolumeRange.second + "]");
return;
}
if (_gainDB > m_masterVolumeRange.second) {
//throw std::range_error(std::string(_gainDB) + " is out of bonds : [" + m_masterVolumeRange.first + ".." + m_masterVolumeRange.second + "]");
return;
}
m_masterVolume = _gainDB;
for (auto &it : m_listOpenInterface) {
std::shared_ptr<airtio::Interface> tmpElem = it.lock();
if (tmpElem == nullptr) {
continue;
}
// TODO : Deprecated ...
//tmpElem->setMasterVolume(m_masterVolume);
}
}
float airtio::Manager::getMasterOutputVolume() {
return m_masterVolume;
}
std::pair<float,float> airtio::Manager::getMasterOutputVolumeRange() {
return m_masterVolumeRange;
}
void airtio::Manager::setSectionVolume(const std::string& _section, float _gainDB) {
}
float airtio::Manager::getSectionVolume(const std::string& _section) {
return 0.0f;
}
std::pair<float,float> airtio::Manager::getSectionVolumeRange(const std::string& _section) {
return std::make_pair(0.0f, 0.0f);
}
std::shared_ptr<airtio::Interface>
airtio::Manager::createOutput(float _freq,
const std::vector<airtalgo::channel>& _map,