Audio API C++
Namespaces | |
dpyAudio | |
Deepsy Audio namespace that includes the different enums, structs or method signatures that should be used. | |
Classes | |
class | ServiceAvailabilityObserver |
Service Availability observer class. More... | |
class | Audio |
Allows to interact with a Audio service. More... | |
class | AudioTaskObserver |
Audio Task Observer class. More... | |
class | IAudioTask |
Interface representing a Audio Task which will be reproduced in a specific port. More... | |
Detailed Description
Service Name Api related documentation
Audio API related documentation
A quick overview of basic Audio API capabilities and examples is given.
If you find Audio API useful and would like to know more details, please check out further sections of the Audio API documentation or contact the Deepsy team.
Examples
-
Create and remove connections
#include <iostream>#include <dpy/audioApi.h>#include <boost/thread.hpp>volatile bool waiting = true;using namespace dpyAudio;static Audio audio;static std::map<dpyAudio::PortType, std::string> portTypeToStringMap;static std::list<dpyAudio::Port> gUserPortsList;static std::list<dpyAudio::Connection> gConnectionsList;static dpyAudio::Port userOutPort, userInPort;static dpyAudio::Port systemOutPort, systemInPort;void set_connection_volume_handler(boost::system::error_code &ec, dpyAudio::Connection connection, unsigned int volume);void set_connection_gain_handler(boost::system::error_code &ec, dpyAudio::Connection connection, unsigned int gain);void printConnectionList(boost::system::error_code &ec, std::list<dpyAudio::Connection> connectionList);void port_list_handler(boost::system::error_code &ec, std::list<dpyAudio::Port> portList);void create_port_handler(boost::system::error_code& ec, dpyAudio::Port& port);void remove_port_handler(boost::system::error_code &ec, dpyAudio::Port &port);void create_connection_handler(boost::system::error_code &ec, dpyAudio::Connection connection);void remove_connection_handler(boost::system::error_code &ec, dpyAudio::Connection connection);void set_connection_volume_handler(boost::system::error_code &ec, dpyAudio::Connection connection, unsigned int volume){if (ec.value() == 0) {std::cout << "\rConnection [" << connection.id << "] volume updated correctly to " << volume << ". " << std::endl;} else {std::cout << "\rError : " << ec.message() << std::endl;}waiting = false;}void set_connection_gain_handler(boost::system::error_code &ec, dpyAudio::Connection connection, unsigned int gain){if (ec.value() == 0) {std::cout << "\rConnection [" << connection.id << "] gain updated correctly to " << gain << ". " << std::endl;} else {std::cout << "\rError : " << ec.message() << std::endl;}waiting = false;}void printConnectionList(boost::system::error_code &ec, std::list<dpyAudio::Connection> connectionList){if (ec.value() == 0) {gConnectionsList.clear();std::cout << "\rConnection list: " << std::endl;std::cout << "\tConnection id\t|\t Origin Port \t|\t Destination Port \t|\tPriority\t|\tState\t|\tVolume\t|\tGain\t|\tBlocked By\n";std::cout << "\t---------------------------------------------------------------------------------------------------------------------------------\n";// Iterate and print values of the listfor (auto const &c : connectionList) {gConnectionsList.push_back(c);std::cout << "\t" << c.id;std::string originPort = c.originPort.client + ":" + c.originPort.name;std::string destinationPort = c.destinationPort.client + ":" + c.destinationPort.name;std::cout << "\t|\t" << originPort << "\t|\t";std::cout << destinationPort << "\t|\t";std::cout << c.priority << "\t|\t";if (c.isActive) {std::cout << "ENABLED";} else {std::cout << "DISABLED";}std::cout << "\t|\t";std::cout << c.volume << "\t|\t";std::cout << c.gain << "\t|\t";for (auto block : c.blockedBy) {std::cout << block << " ";}std::cout << std::endl;}} else {std::cout << "\rError : " << ec.message() << std::endl;}waiting = false;}void port_list_handler(boost::system::error_code &ec, std::list<dpyAudio::Port> portList){if (ec.value() == 0) {//Create connectionif (portList.size() != 0) {for (auto const& p : portList) {if (p.type == PortType::INPUT && p.client.find("user") == std::string::npos) {systemInPort = p; //Take the first of the speakersbreak;}}for (auto const& p : portList) {if (p.type == PortType::OUTPUT && p.client.find("user") == std::string::npos) {systemOutPort = p; //Take the first of the microphonesbreak;}}} else {std::cout << "Port list is not available or cannot be read" << std::endl;}} else {std::cout << "\rError : " << ec.message() << std::endl;}waiting = false;}void create_port_handler(boost::system::error_code& ec, dpyAudio::Port& port){if (ec.value() == 0) {std::cout << "\rPort with name [" << port.name << "] created correctly. Type " << portTypeToStringMap[port.type] << ". Port full name [" << port.client << ":" << port.name << "]" << std::endl;} else {std::cout << "\rError : " << ec.message() << std::endl;}waiting = false;}void remove_port_handler(boost::system::error_code &ec, dpyAudio::Port &port){if (ec.value() == 0) {} else {std::cout << "\rError : " << ec.message() << std::endl;}waiting = false;}void create_connection_handler(boost::system::error_code &ec, dpyAudio::Connection connection){if (ec.value() == 0) {std::cout << "Connection [" << connection.id << "] created correctly : Origin " << connection.originPort.getPortFullName() << " --> Destination " << connection.destinationPort.getPortFullName() << std::endl;} else {std::cout << "\rError : " << ec.message() << std::endl;}waiting = false;}void remove_connection_handler(boost::system::error_code &ec, dpyAudio::Connection connection){if (ec.value() == 0) {} else {std::cout << "\rError : " << ec.message() << std::endl;}waiting = false;}int main() {waiting = true;portTypeToStringMap[dpyAudio::PortType::NA_TYPE] = "Not available ";portTypeToStringMap[dpyAudio::PortType::INPUT] = "Input";portTypeToStringMap[dpyAudio::PortType::OUTPUT] = "Output";userOutPort.client = "user1";userOutPort.name = "output_1";userOutPort.type = PortType::OUTPUT;std::cout << "Creating user port" << std::endl;audio.asyncCreatePort(userOutPort, create_port_handler);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;gUserPortsList.push_back(userOutPort);userInPort.client = "user2";userInPort.name = "input_1";userInPort.type = PortType::INPUT;std::cout << "Creating user port" << std::endl;audio.asyncCreatePort(userInPort, create_port_handler);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;gUserPortsList.push_back(userInPort);audio.asyncGetPortList(port_list_handler);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;Connection connectionBlocked;connectionBlocked.id = "connectionBlocked";connectionBlocked.originPort = userOutPort;connectionBlocked.destinationPort = systemInPort;connectionBlocked.priority = 20;connectionBlocked.volume = 50;std::cout << "Creating connection [" << connectionBlocked.id << "].\nConnecting port " << connectionBlocked.originPort.getPortFullName() << " with port " << connectionBlocked.destinationPort.getPortFullName() << std::endl;audio.asyncCreateConnection(connectionBlocked, create_connection_handler);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;Connection connection1;connection1.id = "connection1";connection1.originPort = userOutPort;connection1.destinationPort = systemInPort;connection1.priority = 10;connection1.volume = 70;std::cout << "Creating connection [" << connection1.id << "].\nConnecting port " << connection1.originPort.getPortFullName() << " with port " << connection1.destinationPort.getPortFullName() << std::endl;audio.asyncCreateConnection(connection1, create_connection_handler);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;Connection connection2;connection2.id = "connection2";connection2.originPort = systemOutPort;connection2.destinationPort = userInPort;connection2.priority = 5;connection2.gain = 60;std::cout << "Creating connection [" << connection2.id << "].\nConnecting port " << connection2.originPort.getPortFullName() << " with port " << connection2.destinationPort.getPortFullName() << std::endl;audio.asyncCreateConnection(connection2, create_connection_handler);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;audio.asyncGetConnectionList(printConnectionList);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;int newVolume = 55;audio.asyncSetVolume(connection1, newVolume, set_connection_volume_handler);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;int newGain = 42;audio.asyncSetGain(connection2, newGain, set_connection_gain_handler);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;audio.asyncGetConnectionList(printConnectionList);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;std::cout << "Removing connections." << std::endl;for (auto const &c : gConnectionsList) {audio.asyncRemoveConnection(c, remove_connection_handler);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;}std::cout << "Removing ports." << std::endl;for (auto const &port : gUserPortsList) {audio.asyncRemovePort(port, remove_port_handler);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;}return 0;} -
Playing a example sound track
#include <iostream>#include <dpy/audioApi.h>#include <boost/thread.hpp>volatile bool waiting = true;using namespace dpyAudio;static Audio audio;static std::list<dpyAudio::Port> gDestinationPortsList;static std::map<dpyAudio::PortType, std::string> portTypeToStringMap;static dpyAudio::Port userPort;void getAudioTaskStatus(boost::system::error_code ec, int taskId, dpyAudio::TaskType taskType, dpyAudio::AudioTaskStatus taskStatus);void play_result_async_handler(boost::system::error_code ec, int trackId);void print_port_list(boost::system::error_code &ec, std::list<dpyAudio::Port> portList);void port_list_handler(boost::system::error_code &ec, std::list<dpyAudio::Port> portList);void create_port_handler(boost::system::error_code& ec, dpyAudio::Port& port);void create_connection_handler(boost::system::error_code &ec, dpyAudio::Connection connection);void getAudioTaskStatus(boost::system::error_code ec, int taskId, dpyAudio::TaskType taskType, dpyAudio::AudioTaskStatus taskStatus){if (ec.value() == 0) {if (taskType == dpyAudio::TaskType::PLAY) {if (taskStatus == dpyAudio::AudioTaskStatus::QUEUED) {std::cout << "\rAudio track status: Track " << taskId << " queued." << std::endl;std::cout << "\rAudio track status: Track " << taskId << " is being played." << std::endl;std::cout << "\rAudio track status: Track " << taskId << " finished, played successfully." << std::endl;std::cout << "\rAudio track status: Track " << taskId << " error before playing." << std::endl;std::cout << "\rAudio track status: Track " << taskId << " error while playing." << std::endl;std::cout << "\rAudio track status: Track " << taskId << " error after playing." << std::endl;} else {std::cout << "\rAudio track status: Track " << taskId << " stopped." << std::endl;}}} else {std::cout << "\rError : " << ec.message() << std::endl;}}void play_result_async_handler(boost::system::error_code ec, int trackId){if (ec) {std::cout << "\rError : " << ec.message() << std::endl;} else {std::cout << "\rPlay operation forwarded successfully, resultant track id is "<< trackId << std::endl;boost::this_thread::sleep_for(boost::chrono::seconds(1));audio.getTaskStatus(trackId, getAudioTaskStatus);boost::this_thread::sleep_for(boost::chrono::seconds(2));audio.getTaskStatus(trackId, getAudioTaskStatus);}waiting = false;}void print_port_list(boost::system::error_code &ec, std::list<dpyAudio::Port> portList){if (ec.value() == 0) {std::cout << "\rPort list: " << std::endl;// Iterate and print values of the liststd::cout << "\t Port id \t\t\t|\t Port Type \n";std::cout << "\t-----------------------------------------------------------------\n";for (auto const& p : portList) {std::string fullname = p.client + ":" + p.name;std::cout << "\t " << fullname;std::cout << (fullname.size() > 25 ? "\t|\t " : "\t\t\t|\t "); //To print the tablestd::cout << portTypeToStringMap[p.type] << std::endl;}} else {std::cout << "\rError : " << ec.message() << std::endl;}waiting = false;}void port_list_handler(boost::system::error_code &ec, std::list<dpyAudio::Port> portList){if (ec.value() == 0) {//Create connectionif (portList.size() != 0){for (auto const& p : portList) {if (p.getPortFullName().find("driver_speaker") != std::string::npos || p.getPortFullName().find("external_speaker_r") != std::string::npos){gDestinationPortsList.push_back(p);}}Connection connection;connection.id = "my_connection";connection.originPort = userPort;connection.destinationPort = gDestinationPortsList.front(); //Take the first of the speakersconnection.priority = 10;connection.volume = 70;std::cout << "Creating connection [" << connection.id << "].\nConnecting port " << connection.originPort.getPortFullName() << " with port " << connection.destinationPort.getPortFullName() << std::endl;audio.asyncCreateConnection(connection, create_connection_handler);} else {std::cout << "Port list is not available or cannot be read" << std::endl;waiting = false;}} else {std::cout << "\rError : " << ec.message() << std::endl;waiting = false;}}void create_port_handler(boost::system::error_code& ec, dpyAudio::Port& port){if (ec.value() == 0) {std::cout << "\rPort with name [" << port.name << "] created correctly. Type " << portTypeToStringMap[port.type] << ". Port full name [" << port.client << ":" << port.name << "]" << std::endl;} else {std::cout << "\rError : " << ec.message() << std::endl;}waiting = false;}void create_connection_handler(boost::system::error_code &ec, dpyAudio::Connection connection){if (ec.value() == 0) {std::cout << "Connection [" << connection.id << "] created correctly : Origin " << connection.originPort.getPortFullName() << " --> Destination " << connection.destinationPort.getPortFullName() << std::endl;std::cout << "Playing audio via " << connection.originPort.getPortFullName() << ". All ports connected to this port will play the specified sound"<< std::endl;std::list<dpyAudio::AudioConfig> configurations;dpyAudio::AudioConfig config = dpyAudio::AudioConfig(param, 80);configurations.push_back(config);audio.asyncPlay(userPort, "/usr/share/sounds/alsa/Front_Center.wav", configurations, play_result_async_handler);} else {std::cout << "\rError : " << ec.message() << std::endl;waiting = false;}}int main() {waiting = true;portTypeToStringMap[dpyAudio::PortType::NA_TYPE] = "Not available ";portTypeToStringMap[dpyAudio::PortType::INPUT] = "Input";portTypeToStringMap[dpyAudio::PortType::OUTPUT] = "Output";userPort.client = "user";userPort.name = "output_1";userPort.type = PortType::OUTPUT;std::cout << "Initial port list:" << std::endl;audio.asyncGetPortList(print_port_list);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;std::cout << "Creating user port" << std::endl;audio.asyncCreatePort(userPort, create_port_handler);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;audio.asyncGetPortList(port_list_handler);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}return 0;} -
Create a sound recording
#include <iostream>#include <dpy/audioApi.h>#include <enum.h>#include <boost/thread.hpp>BETTER_ENUM(TextTaskStatus, uint8_t, UNKNOWN_STATUS, QUEUED, PROCESSING, PROCESSED_OK, ERROR_BEFORE_PROCESSING, ERROR_WHILE_PROCESSING, ERROR_AFTER_PROCESSING, TASK_STOPPED)volatile bool waiting = true;using namespace dpyAudio;static std::list<dpyAudio::Port> gDestinationPortsList;static dpyAudio::Port userPort;static int sTrackId = -1;void print_port_list(boost::system::error_code &ec, std::list<dpyAudio::Port> portList);void port_list_handler(boost::system::error_code &ec, std::list<dpyAudio::Port> portList);void create_port_handler(boost::system::error_code &ec, dpyAudio::Port &port);void create_connection_handler(boost::system::error_code &ec, dpyAudio::Connection connection);void get_status_task_handler(boost::system::error_code ec, int taskId, dpyAudio::TaskType taskType, dpyAudio::AudioTaskStatus taskStatus);void get_status_task_handler(boost::system::error_code ec, int taskId, dpyAudio::TaskType taskType, dpyAudio::AudioTaskStatus taskStatus){if (ec) {std::cout << "\rError : " << ec.message() << std::endl;} else {sTrackId = taskId;TextTaskStatus text_task_status = TextTaskStatus::_from_integral(taskStatus);TextTaskType text_task_type = TextTaskType::_from_integral(taskType);std::cout << "\rGet status task " << taskId << " forwarded successfully. The task type is " << text_task_type._to_string() << " And its status " << text_task_status._to_string() << std::endl;}}void stop_task_async_handler(boost::system::error_code ec, int ID){if (ec) {std::cout << "\rError : " << ec.message() << std::endl;} else {std::cout << "\rSuccessful operation. Stop task ID: " << ID << std::endl;std::cout << "\rThe record has finished, you can have a look under /tmp to find your record file." << std::endl;}waiting = false;}void audio_task_async_handler(boost::system::error_code ec, int trackId){if (ec) {std::cout << "\rError : " << ec.message() << std::endl;waiting = false;} else {sTrackId = trackId;std::cout << "\rPlay operation forwarded successfully, resultant track id is " << trackId << std::endl;std::cout << "\rThe 10 seconds recording starts now! " << std::endl;audio.getTaskStatus(sTrackId, get_status_task_handler);boost::this_thread::sleep_for(boost::chrono::milliseconds(3333));audio.getTaskStatus(sTrackId, get_status_task_handler);boost::this_thread::sleep_for(boost::chrono::milliseconds(3333));audio.getTaskStatus(sTrackId, get_status_task_handler);boost::this_thread::sleep_for(boost::chrono::milliseconds(3333));audio.asyncStop(sTrackId, stop_task_async_handler);}}void print_port_list(boost::system::error_code &ec, std::list<dpyAudio::Port> portList){if (ec.value() == 0) {std::cout << "\rPort list: " << std::endl;// Iterate and print values of the liststd::cout << "\t Port id \t\t\t|\t Port Type \n";std::cout << "\t-----------------------------------------------------------------\n";for (auto const &p : portList) {std::string fullname = p.client + ":" + p.name;std::cout << "\t " << fullname;std::cout << (fullname.size() > 25 ? "\t|\t " : "\t\t\t|\t "); //To print the tablestd::cout << portTypeToStringMap[p.type] << std::endl;}} else {std::cout << "\rError : " << ec.message() << std::endl;}waiting = false;}void port_list_handler(boost::system::error_code &ec, std::list<dpyAudio::Port> portList){if (ec.value() == 0) {//Create connectionif (portList.size() != 0) {for (auto const &p : portList) {if (p.getPortFullName().find("external_microphone") != std::string::npos || p.getPortFullName().find("driver_microphone") != std::string::npos) {gDestinationPortsList.push_back(p);}}Connection connection;connection.id = "my_connection";connection.originPort = gDestinationPortsList.front(); //Take the first of the speakersconnection.destinationPort = userPort;connection.priority = 15;connection.gain = 70;std::cout << "Creating connection [" << connection.id << "].\nConnecting port " << connection.originPort.getPortFullName() << " with port " << connection.destinationPort.getPortFullName() << std::endl;audio.asyncCreateConnection(connection, create_connection_handler);} else {std::cout << "Port list is not available or cannot be read" << std::endl;waiting = false;}} else {std::cout << "\rError : " << ec.message() << std::endl;waiting = false;}}void create_port_handler(boost::system::error_code &ec, dpyAudio::Port &port){if (ec.value() == 0) {std::cout << "\rPort with name [" << port.name << "] created correctly. Type " << portTypeToStringMap[port.type] << ". Port full name [" << port.client << ":" << port.name << "]" << std::endl;} else {std::cout << "\rError : " << ec.message() << std::endl;}waiting = false;}void create_connection_handler(boost::system::error_code &ec, dpyAudio::Connection connection){if (ec.value() == 0) {std::cout << "Connection [" << connection.id << "] created correctly : Origin " << connection.originPort.getPortFullName() << " --> Destination " << connection.destinationPort.getPortFullName() << std::endl;std::cout << "Recording audio via " << connection.originPort.getPortFullName() << ". It is going to be recorded 10 seconds on that port." << std::endl;std::list<dpyAudio::AudioConfig> configurations;dpyAudio::AudioConfig config = dpyAudio::AudioConfig(param, 80);configurations.push_back(config);audio.asyncRecord(userPort, "/tmp/test_record.wav",configurations, audio_task_async_handler);} else {std::cout << "\rError : " << ec.message() << std::endl;waiting = false;}}int main(){waiting = true;portTypeToStringMap[dpyAudio::PortType::NA_TYPE] = "Not available ";portTypeToStringMap[dpyAudio::PortType::INPUT] = "Input";portTypeToStringMap[dpyAudio::PortType::OUTPUT] = "Output";userPort.client = "user";userPort.name = "input_1";userPort.type = PortType::INPUT;std::cout << "Initial port list:" << std::endl;audio.asyncGetPortList(print_port_list);while (waiting == true) {boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;std::cout << "Creating user port" << std::endl;audio.asyncCreatePort(userPort, create_port_handler);while (waiting == true) {boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;audio.asyncGetPortList(port_list_handler);while (waiting == true) {boost::this_thread::sleep_for(boost::chrono::seconds(1));}return 0;} -
Set and get audio configuration
#include <iostream>#include <dpy/audioApi.h>#include <boost/thread.hpp>volatile bool waiting = true;using namespace dpyAudio;static Audio audio;void print_audioConfiguration(boost::system::error_code &ec, std::list<dpyAudio::AudioConfig> configurations);void setConfigurationHandler(boost::system::error_code &ec);void print_audioConfiguration(boost::system::error_code &ec, std::list<dpyAudio::AudioConfig> configurations){if (ec.value() == 0) {std::cout << "\rConfiguration list: " << std::endl;// Iterate and print values of the liststd::cout << "\t Param \t\t\t|\t Value \n";std::cout << "\t-----------------------------------------------------------------\n";//More clear for the user if we print first the inputs and then the outputsfor (auto const &config : configurations) {std::cout << "\t\t\t\t|\t ";std::cout << config.getValue() << "\n";std::cout << "\n";}} else {std::cout << "\rError : " << ec.message() << std::endl;}waiting = false;}void setConfigurationHandler(boost::system::error_code &ec){if (ec.value() == 0) {std::cout << "\rConfiguration set successfully " << std::endl;} else {std::cout << "\rError : " << ec.message() << std::endl;}waiting = false;}int main() {waiting = true;audio.asyncGetAudioConfiguration(print_audioConfiguration);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;std::cout<< "Setting configuration volume to 80" << std::endl;dpyAudio::AudioConfig config = dpyAudio::AudioConfig(param, 80);audio.asyncSetAudioConfiguration(config, setConfigurationHandler);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;audio.asyncGetAudioConfiguration(print_audioConfiguration);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;return 0;} -
Set and get ports with assigned GPIO
#include <iostream>#include <map>#include <dpy/audioApi.h>#include <boost/thread.hpp>volatile bool waiting = true;using namespace dpyAudio;static Audio audio;static dpyAudio::Port userInPort1, userInPort2;static std::list<dpyAudio::Port> gUserPortsList;void resultHandler(boost::system::error_code ec);void create_port_handler(boost::system::error_code& ec, dpyAudio::Port& port);void remove_port_handler(boost::system::error_code &ec, dpyAudio::Port &port);void print_port_gpio_map(boost::system::error_code &ec, std::list<dpyAudio::PortGpio> portGpioList);void resultHandler(boost::system::error_code ec){if (ec) {std::cout << "\rError : " << ec.message() << std::endl;} else {std::cout << "\rAsynchronous operation performed successfully" << std::endl;}waiting = false;}void create_port_handler(boost::system::error_code& ec, dpyAudio::Port& port){if (ec.value() == 0) {} else {std::cout << "\rError : " << ec.message() << std::endl;}waiting = false;}void remove_port_handler(boost::system::error_code &ec, dpyAudio::Port &port){if (ec.value() == 0) {} else {std::cout << "\rError : " << ec.message() << std::endl;}waiting = false;}void print_port_gpio_map(boost::system::error_code &ec, std::list<dpyAudio::PortGpio> portGpioList){if (ec.value() == 0) {std::cout << "\rPort GPIO map: " << std::endl;// Iterate and print values of the liststd::cout << "\t Port id \t\t\t\t|\tGpio Sink \n";std::cout << "\t------------------------------------------------------------------\n";//More clear for the user if we print first the inputs and then the outputsfor (auto it : portGpioList) {std::string fullname = it.port.getPortFullName();std::cout << "\t " << fullname;std::cout << (fullname.size() > 25 ? "\t|\t " : "\t\t\t|\t "); //To print the table correctly almost in all casesstd::cout << it.gpio << std::endl;}} else {std::cout << "\rError : " << ec.message() << std::endl;}waiting = false;}int main() {waiting = true;userInPort1.client = "user1";userInPort1.name = "input_1";userInPort1.type = PortType::INPUT;std::cout << "Creating user1:input_1 port " << std::endl;audio.asyncCreatePort(userInPort1, create_port_handler);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;gUserPortsList.push_back(userInPort1);userInPort2.client = "user2";userInPort2.name = "input_2";userInPort2.type = PortType::INPUT;std::cout << "Creating user2:input_2 port " << std::endl;audio.asyncCreatePort(userInPort2, create_port_handler);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;gUserPortsList.push_back(userInPort2);std::string gpio_id("DO1");std::cout<< "Assign " << gpio_id << " to user1:input_1 port " << std::endl;dpyAudio::PortGpio portGpio = {userInPort1, gpio_id};audio.asyncSetPortGpio(portGpio, &resultHandler);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;audio.asyncGetPortGpio(print_port_gpio_map);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(5));}waiting = true;gpio_id = "DO2";std::cout<< "Assign " << gpio_id << " to user2:input_2 port " << std::endl;portGpio = {userInPort2, gpio_id};audio.asyncSetPortGpio(portGpio, &resultHandler);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;audio.asyncGetPortGpio(print_port_gpio_map);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(5));}waiting = true;std::cout<< "Release gpio from user1:input_1 port " << std::endl;gpio_id = "";portGpio = {userInPort1, gpio_id};audio.asyncSetPortGpio(portGpio, &resultHandler);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;audio.asyncGetPortGpio(print_port_gpio_map);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(5));}waiting = true;std::cout<< "Release gpio from user2:input_2 port " << std::endl;portGpio = {userInPort2, gpio_id};audio.asyncSetPortGpio(portGpio, &resultHandler);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;audio.asyncGetPortGpio(print_port_gpio_map);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(5));}waiting = true;std::cout << "Removing ports." << std::endl;for (auto const &port : gUserPortsList) {audio.asyncRemovePort(port, remove_port_handler);while (waiting == true){boost::this_thread::sleep_for(boost::chrono::seconds(1));}waiting = true;}return 0;}