diff --git a/daemon/bin/main.cpp b/daemon/bin/main.cpp index 26f293ac602203e4d5eca206779b786abf8e9d08..3a1c29bde1d665b46ebb2e42b662e8920a4e049a 100644 --- a/daemon/bin/main.cpp +++ b/daemon/bin/main.cpp @@ -169,7 +169,7 @@ int main(int argc, char *argv []) std::vector<char> writable(programName.size() + 1); std::copy(programName.begin(), programName.end(), writable.begin()); - fileutils::set_program_dir(writable.data()); + ring::fileutils::set_program_dir(writable.data()); #ifdef TOP_BUILDDIR if (!getenv("CODECS_PATH")) diff --git a/daemon/src/account.cpp b/daemon/src/account.cpp index a23a6e14cbeb26b706a35793b213cde9d8835206..8183b2c9e1db7ff1525ada6ad0ce34c73779d37c 100644 --- a/daemon/src/account.cpp +++ b/daemon/src/account.cpp @@ -52,6 +52,8 @@ #include <yaml-cpp/yaml.h> +namespace ring { + const char * const Account::AUDIO_CODECS_KEY = "audioCodecs"; // 0/9/110/111/112/ const char * const Account::VIDEO_CODECS_KEY = "videoCodecs"; const char * const Account::VIDEO_CODEC_ENABLED = "enabled"; @@ -173,8 +175,6 @@ void Account::loadDefaultCodecs() void Account::serialize(YAML::Emitter &out) { - using namespace Conf; - out << YAML::Key << ID_KEY << YAML::Value << accountID_; out << YAML::Key << ALIAS_KEY << YAML::Value << alias_; out << YAML::Key << ACCOUNT_ENABLE_KEY << YAML::Value << enabled_; @@ -193,7 +193,8 @@ void Account::serialize(YAML::Emitter &out) void Account::unserialize(const YAML::Node &node) { - using namespace yaml_utils; + using yaml_utils::parseValue; + parseValue(node, ALIAS_KEY, alias_); parseValue(node, ACCOUNT_ENABLE_KEY, enabled_); parseValue(node, USERNAME_KEY, username_); @@ -204,7 +205,7 @@ void Account::unserialize(const YAML::Node &node) parseValue(node, AUDIO_CODECS_KEY, audioCodecStr_); // Update codec list which one is used for SDP offer - setActiveAudioCodecs(ring::split_string(audioCodecStr_, '/')); + setActiveAudioCodecs(split_string(audioCodecStr_, '/')); parseValue(node, DISPLAY_NAME_KEY, displayName_); parseValue(node, HOSTNAME_KEY, hostname_); @@ -217,18 +218,18 @@ void Account::unserialize(const YAML::Node &node) void Account::setAccountDetails(const std::map<std::string, std::string> &details) { // Account setting common to SIP and IAX - parseString(details, CONFIG_ACCOUNT_ALIAS, alias_); - parseBool(details, CONFIG_ACCOUNT_ENABLE, enabled_); - parseString(details, CONFIG_ACCOUNT_USERNAME, username_); - parseString(details, CONFIG_ACCOUNT_HOSTNAME, hostname_); - parseString(details, CONFIG_ACCOUNT_MAILBOX, mailBox_); - parseString(details, CONFIG_ACCOUNT_USERAGENT, userAgent_); - parseBool(details, CONFIG_ACCOUNT_AUTOANSWER, autoAnswerEnabled_); - parseBool(details, CONFIG_RINGTONE_ENABLED, ringtoneEnabled_); - parseString(details, CONFIG_RINGTONE_PATH, ringtonePath_); - parseBool(details, CONFIG_ACCOUNT_HAS_CUSTOM_USERAGENT, hasCustomUserAgent_); + parseString(details, Conf::CONFIG_ACCOUNT_ALIAS, alias_); + parseBool(details, Conf::CONFIG_ACCOUNT_ENABLE, enabled_); + parseString(details, Conf::CONFIG_ACCOUNT_USERNAME, username_); + parseString(details, Conf::CONFIG_ACCOUNT_HOSTNAME, hostname_); + parseString(details, Conf::CONFIG_ACCOUNT_MAILBOX, mailBox_); + parseString(details, Conf::CONFIG_ACCOUNT_USERAGENT, userAgent_); + parseBool(details, Conf::CONFIG_ACCOUNT_AUTOANSWER, autoAnswerEnabled_); + parseBool(details, Conf::CONFIG_RINGTONE_ENABLED, ringtoneEnabled_); + parseString(details, Conf::CONFIG_RINGTONE_PATH, ringtonePath_); + parseBool(details, Conf::CONFIG_ACCOUNT_HAS_CUSTOM_USERAGENT, hasCustomUserAgent_); if (hasCustomUserAgent_) - parseString(details, CONFIG_ACCOUNT_USERAGENT, userAgent_); + parseString(details, Conf::CONFIG_ACCOUNT_USERAGENT, userAgent_); else userAgent_ = DEFAULT_USER_AGENT; } @@ -237,23 +238,23 @@ std::map<std::string, std::string> Account::getAccountDetails() const { std::map<std::string, std::string> a; - a[CONFIG_ACCOUNT_ALIAS] = alias_; - a[CONFIG_ACCOUNT_ENABLE] = enabled_ ? "true" : "false"; - a[CONFIG_ACCOUNT_TYPE] = getAccountType(); - a[CONFIG_ACCOUNT_HOSTNAME] = hostname_; - a[CONFIG_ACCOUNT_USERNAME] = username_; - a[CONFIG_ACCOUNT_MAILBOX] = mailBox_; + a[Conf::CONFIG_ACCOUNT_ALIAS] = alias_; + a[Conf::CONFIG_ACCOUNT_ENABLE] = enabled_ ? "true" : "false"; + a[Conf::CONFIG_ACCOUNT_TYPE] = getAccountType(); + a[Conf::CONFIG_ACCOUNT_HOSTNAME] = hostname_; + a[Conf::CONFIG_ACCOUNT_USERNAME] = username_; + a[Conf::CONFIG_ACCOUNT_MAILBOX] = mailBox_; RegistrationState state(registrationState_); // This method should only stores user-settable fields // For legacy reasons, the STATUS will be kept for some time - a[CONFIG_ACCOUNT_REGISTRATION_STATUS] = mapStateNumberToString(state); - a[CONFIG_ACCOUNT_USERAGENT] = hasCustomUserAgent_ ? userAgent_ : DEFAULT_USER_AGENT; - a[CONFIG_ACCOUNT_HAS_CUSTOM_USERAGENT] = hasCustomUserAgent_ ? TRUE_STR : FALSE_STR; - a[CONFIG_ACCOUNT_AUTOANSWER] = autoAnswerEnabled_ ? TRUE_STR : FALSE_STR; - a[CONFIG_RINGTONE_ENABLED] = ringtoneEnabled_ ? TRUE_STR : FALSE_STR; - a[CONFIG_RINGTONE_PATH] = ringtonePath_; + a[Conf::CONFIG_ACCOUNT_REGISTRATION_STATUS] = mapStateNumberToString(state); + a[Conf::CONFIG_ACCOUNT_USERAGENT] = hasCustomUserAgent_ ? userAgent_ : DEFAULT_USER_AGENT; + a[Conf::CONFIG_ACCOUNT_HAS_CUSTOM_USERAGENT] = hasCustomUserAgent_ ? TRUE_STR : FALSE_STR; + a[Conf::CONFIG_ACCOUNT_AUTOANSWER] = autoAnswerEnabled_ ? TRUE_STR : FALSE_STR; + a[Conf::CONFIG_RINGTONE_ENABLED] = ringtoneEnabled_ ? TRUE_STR : FALSE_STR; + a[Conf::CONFIG_RINGTONE_PATH] = ringtonePath_; return a; } @@ -262,7 +263,7 @@ std::map<std::string, std::string> Account::getVolatileAccountDetails() const { std::map<std::string, std::string> a; - a[CONFIG_ACCOUNT_REGISTRATION_STATUS] = mapStateNumberToString(registrationState_); + a[Conf::CONFIG_ACCOUNT_REGISTRATION_STATUS] = mapStateNumberToString(registrationState_); return a; } @@ -452,3 +453,5 @@ Account::parseBool(const std::map<std::string, std::string> &details, const char } #undef find_iter + +} // namespace ring diff --git a/daemon/src/account.h b/daemon/src/account.h index 016750a5061f2dfdd0a1c4de52430fc4400193d1..73658097a02f6470d5f96142b83cb0264c6936c7 100644 --- a/daemon/src/account.h +++ b/daemon/src/account.h @@ -46,6 +46,13 @@ #include <random> #include <stdexcept> +namespace YAML { +class Emitter; +class Node; +} + +namespace ring { + class Call; class VoipLinkException : public std::runtime_error { @@ -54,11 +61,6 @@ class VoipLinkException : public std::runtime_error { std::runtime_error("VoipLinkException occured: " + str) {} }; -namespace YAML { - class Emitter; - class Node; -} - /** * @file account.h * @brief Interface to protocol account (SIPAccount, IAXAccount) @@ -375,4 +377,6 @@ class Account : public Serializable, public std::enable_shared_from_this<Account std::mt19937_64 rand_ {}; }; +} // namespace ring + #endif diff --git a/daemon/src/account_factory.cpp b/daemon/src/account_factory.cpp index 71b2cc2601944e04e76f2aaa56d98f1fb5cb5361..1d55ef44faeb0718b2b676b8cbfd289bff66d338 100644 --- a/daemon/src/account_factory.cpp +++ b/daemon/src/account_factory.cpp @@ -46,6 +46,8 @@ #include <stdexcept> +namespace ring { + const char* const AccountFactory::DEFAULT_ACCOUNT_TYPE = SIPAccount::ACCOUNT_TYPE; AccountFactory::AccountFactory() @@ -213,3 +215,5 @@ void AccountFactory::initIP2IPAccount() ip2ip_account_ = createAccount(SIPAccount::ACCOUNT_TYPE, SIPAccount::IP2IP_PROFILE); } + +} // namespace ring diff --git a/daemon/src/account_factory.h b/daemon/src/account_factory.h index d3734e6c9816755da85a0414ef96693bfd4a50c9..2d1d11f6f2b6993d52cd0958cf3a8348f986aab7 100644 --- a/daemon/src/account_factory.h +++ b/daemon/src/account_factory.h @@ -38,6 +38,8 @@ #include <mutex> #include <utility> +namespace ring { + class Account; class AccountGeneratorBase; @@ -169,4 +171,6 @@ template <> std::size_t AccountFactory::accountCount() const; +} // namespace ring + #endif // ACCOUNT_FACTORY_H diff --git a/daemon/src/account_schema.h b/daemon/src/account_schema.h index 13774ddbe965fda1fbde66f194a3ade7a552800a..4c2607809ca2a4c8ebc0e3f0ee322c52df9a5d20 100644 --- a/daemon/src/account_schema.h +++ b/daemon/src/account_schema.h @@ -37,6 +37,8 @@ * @brief Account specfic keys/constants that must be shared in daemon and clients. */ +namespace ring { namespace Conf { + // Common account parameters static const char *const CONFIG_ACCOUNT_TYPE = "Account.type"; static const char *const CONFIG_ACCOUNT_ALIAS = "Account.alias"; @@ -112,4 +114,6 @@ static const char *const CONFIG_ACCOUNT_REGISTRATION_STATE_DESC = "Account.regis static const char *const CONFIG_TRANSPORT_STATE_CODE = "Transport.statusCode"; static const char *const CONFIG_TRANSPORT_STATE_DESC = "Transport.statusDescription"; +}} // namespace ring::Conf + #endif // ACCOUNT_SCHEMA_H_ diff --git a/daemon/src/call.cpp b/daemon/src/call.cpp index 0b7dfe679dfa2ac07eb6c84a689941ac61051cf2..8e3ee2ffb7a03b996beaddb4c298af01157baa3b 100644 --- a/daemon/src/call.cpp +++ b/daemon/src/call.cpp @@ -42,6 +42,8 @@ #include "map_utils.h" #include "call_factory.h" +namespace ring { + Call::Call(Account& account, const std::string& id, Call::CallType type) : id_(id) , type_(type) @@ -199,17 +201,17 @@ bool Call::toggleRecording() { const bool startRecording = Recordable::toggleRecording(); - ring::RingBufferPool &rbPool = Manager::instance().getRingBufferPool(); + RingBufferPool &rbPool = Manager::instance().getRingBufferPool(); std::string process_id = Recordable::recorder_.getRecorderID(); if (startRecording) { rbPool.bindHalfDuplexOut(process_id, id_); - rbPool.bindHalfDuplexOut(process_id, ring::RingBufferPool::DEFAULT_ID); + rbPool.bindHalfDuplexOut(process_id, RingBufferPool::DEFAULT_ID); Recordable::recorder_.start(); } else { rbPool.unBindHalfDuplexOut(process_id, id_); - rbPool.unBindHalfDuplexOut(process_id, ring::RingBufferPool::DEFAULT_ID); + rbPool.unBindHalfDuplexOut(process_id, RingBufferPool::DEFAULT_ID); } return startRecording; @@ -244,7 +246,6 @@ timestamp_to_string(const time_t ×tamp) std::map<std::string, std::string> Call::createHistoryEntry() const { - using ring::HistoryItem; std::map<std::string, std::string> result; result[HistoryItem::ACCOUNT_ID_KEY] = getAccountId(); @@ -334,8 +335,10 @@ Call::isIceRunning() const return iceTransport_->isRunning(); } -ring::IceSocket* +IceSocket* Call::newIceSocket(unsigned compId) const { - return new ring::IceSocket(iceTransport_, compId); + return new IceSocket(iceTransport_, compId); } + +} // namespace ring diff --git a/daemon/src/call.h b/daemon/src/call.h index 6238b00daf064abafb5abd3b95087a3bd72e97fe..d1bd08e1b9e43a8f1291eeeef89e2ede7a5c8dac 100644 --- a/daemon/src/call.h +++ b/daemon/src/call.h @@ -47,6 +47,8 @@ #include <vector> #include <condition_variable> +namespace ring { + class VoIPLink; class Account; @@ -57,7 +59,7 @@ template <class T> using CallMap = std::map<std::string, std::shared_ptr<T> >; * @brief A call is the base class for protocol-based calls */ -class Call : public ring::Recordable, public std::enable_shared_from_this<Call> { +class Call : public Recordable, public std::enable_shared_from_this<Call> { public: static const char * const DEFAULT_ID; @@ -310,8 +312,8 @@ class Call : public ring::Recordable, public std::enable_shared_from_this<Call> bool isIceUsed() const; bool isIceRunning() const; - ring::IceSocket* newIceSocket(unsigned compId) const; - std::shared_ptr<ring::IceTransport> getIceTransport() const { + IceSocket* newIceSocket(unsigned compId) const; + std::shared_ptr<IceTransport> getIceTransport() const { return iceTransport_; } @@ -323,7 +325,7 @@ class Call : public ring::Recordable, public std::enable_shared_from_this<Call> */ Call(Account& account, const std::string& id, Call::CallType type); - std::shared_ptr<ring::IceTransport> iceTransport_ {}; + std::shared_ptr<IceTransport> iceTransport_ {}; private: bool validTransition(CallState newState); @@ -374,4 +376,6 @@ class Call : public ring::Recordable, public std::enable_shared_from_this<Call> time_t timestamp_stop_ {0}; }; +} // namespace ring + #endif // __CALL_H__ diff --git a/daemon/src/call_factory.cpp b/daemon/src/call_factory.cpp index 694c2045b891494116c80a22fd337daac6d40d57..50b02c142e504e7ef1da98d053f4eec0a704927b 100644 --- a/daemon/src/call_factory.cpp +++ b/daemon/src/call_factory.cpp @@ -32,6 +32,8 @@ #include <stdexcept> +namespace ring { + void CallFactory::forbid() { @@ -156,3 +158,5 @@ CallFactory::callCount<Call>() return count; } + +} // namespace ring diff --git a/daemon/src/call_factory.h b/daemon/src/call_factory.h index 11f66ef6cfd7e22dd238a9cfca0b569fdfd4b074..d4076a3b373f6e5e6d6c658a10b5c7484521478c 100644 --- a/daemon/src/call_factory.h +++ b/daemon/src/call_factory.h @@ -41,6 +41,8 @@ #include <string> #include <utility> +namespace ring { + class CallFactory { public: /** @@ -239,4 +241,6 @@ CallFactory::getCallIDs<Call>() const; template <> std::size_t CallFactory::callCount<Call>(); +} // namespace ring + #endif // CALL_FACTORY_H diff --git a/daemon/src/client/callmanager.cpp b/daemon/src/client/callmanager.cpp index 8fad82a7c4effcb25bf9a0c3532a92d238499f1c..bdf0e53cd0e7cbf017f242d3bc9b0adab939653d 100644 --- a/daemon/src/client/callmanager.cpp +++ b/daemon/src/client/callmanager.cpp @@ -42,6 +42,8 @@ #include "logger.h" #include "manager.h" +namespace ring { + CallManager::CallManager() { libav_utils::sfl_avcodec_init(); @@ -488,3 +490,5 @@ void CallManager::onRtcpReportReceived(const std::string& callID, const std::map evHandlers_.on_rtcp_receive_report(callID, stats); } } + +} // namespace ring diff --git a/daemon/src/client/callmanager.h b/daemon/src/client/callmanager.h index c8ebec64ca21d95a7bd84b10667d5d084ff21d88..a9a4f3e5e7cacac8973b3c079bc7798057047177 100644 --- a/daemon/src/client/callmanager.h +++ b/daemon/src/client/callmanager.h @@ -42,16 +42,16 @@ #include "ring.h" +namespace ring { + +class AudioZrtpSession; + class CallManagerException: public std::runtime_error { public: CallManagerException(const std::string& str = "") : std::runtime_error("A CallManagerException occured: " + str) {} }; -namespace ring { -class AudioZrtpSession; -} - class CallManager { public: @@ -162,4 +162,6 @@ class CallManager #pragma GCC diagnostic warning "-Wmissing-field-initializers" }; +} // namespace ring + #endif//CALLMANAGER_H diff --git a/daemon/src/client/client.cpp b/daemon/src/client/client.cpp index d2f72336fd5c1d385c2d18a5015e3b890944cd00..11bbae1fc71c31fc917f8b09a7123c602b2442ba 100644 --- a/daemon/src/client/client.cpp +++ b/daemon/src/client/client.cpp @@ -41,6 +41,8 @@ #include "videomanager.h" #endif // RING_VIDEO +namespace ring { + Client::Client() : callManager_(new CallManager) , configurationManager_(new ConfigurationManager) @@ -87,3 +89,5 @@ VideoManager * Client::getVideoManager() return videoManager_; } #endif + +} // namespace ring diff --git a/daemon/src/client/client.h b/daemon/src/client/client.h index 4eea3af2da3eec41c162a892e09a37c7691ef763..329bb65c6554a2a1ef9afbd1ca7da21d9de49b72 100644 --- a/daemon/src/client/client.h +++ b/daemon/src/client/client.h @@ -36,11 +36,12 @@ #endif #include "noncopyable.h" +namespace ring { + class ConfigurationManager; class CallManager; class NetworkManager; class Instance; - class PresenceManager; #ifdef RING_VIDEO @@ -75,4 +76,6 @@ class Client { #endif }; +} // namespace ring + #endif diff --git a/daemon/src/client/configurationmanager.cpp b/daemon/src/client/configurationmanager.cpp index 7e27ae19acd68b24f4c32c0a171c8f9a40ede87a..5519d0574c7f000eafc9ca66c7b701c40f35eebe 100644 --- a/daemon/src/client/configurationmanager.cpp +++ b/daemon/src/client/configurationmanager.cpp @@ -55,6 +55,8 @@ #define CODECS_NOT_LOADED 0x1000 /** Codecs not found */ +namespace ring { + void ConfigurationManager::registerEvHandlers(struct ring_config_ev_handlers* evHandlers) { evHandlers_ = *evHandlers; @@ -93,18 +95,18 @@ ConfigurationManager::getTlsSettingsDefault() portstr << DEFAULT_SIP_TLS_PORT; std::map<std::string, std::string> tlsSettingsDefault; - tlsSettingsDefault[CONFIG_TLS_LISTENER_PORT] = portstr.str(); - tlsSettingsDefault[CONFIG_TLS_CA_LIST_FILE] = ""; - tlsSettingsDefault[CONFIG_TLS_CERTIFICATE_FILE] = ""; - tlsSettingsDefault[CONFIG_TLS_PRIVATE_KEY_FILE] = ""; - tlsSettingsDefault[CONFIG_TLS_PASSWORD] = ""; - tlsSettingsDefault[CONFIG_TLS_METHOD] = "TLSv1"; - tlsSettingsDefault[CONFIG_TLS_CIPHERS] = ""; - tlsSettingsDefault[CONFIG_TLS_SERVER_NAME] = ""; - tlsSettingsDefault[CONFIG_TLS_VERIFY_SERVER] = "true"; - tlsSettingsDefault[CONFIG_TLS_VERIFY_CLIENT] = "true"; - tlsSettingsDefault[CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE] = "true"; - tlsSettingsDefault[CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC] = "2"; + tlsSettingsDefault[Conf::CONFIG_TLS_LISTENER_PORT] = portstr.str(); + tlsSettingsDefault[Conf::CONFIG_TLS_CA_LIST_FILE] = ""; + tlsSettingsDefault[Conf::CONFIG_TLS_CERTIFICATE_FILE] = ""; + tlsSettingsDefault[Conf::CONFIG_TLS_PRIVATE_KEY_FILE] = ""; + tlsSettingsDefault[Conf::CONFIG_TLS_PASSWORD] = ""; + tlsSettingsDefault[Conf::CONFIG_TLS_METHOD] = "TLSv1"; + tlsSettingsDefault[Conf::CONFIG_TLS_CIPHERS] = ""; + tlsSettingsDefault[Conf::CONFIG_TLS_SERVER_NAME] = ""; + tlsSettingsDefault[Conf::CONFIG_TLS_VERIFY_SERVER] = "true"; + tlsSettingsDefault[Conf::CONFIG_TLS_VERIFY_CLIENT] = "true"; + tlsSettingsDefault[Conf::CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE] = "true"; + tlsSettingsDefault[Conf::CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC] = "2"; return tlsSettingsDefault; } @@ -282,17 +284,17 @@ std::vector<std::string> ConfigurationManager::getAudioInputDeviceList() void ConfigurationManager::setAudioOutputDevice(int32_t index) { - return Manager::instance().setAudioDevice(index, ring::DeviceType::PLAYBACK); + return Manager::instance().setAudioDevice(index, DeviceType::PLAYBACK); } void ConfigurationManager::setAudioInputDevice(int32_t index) { - return Manager::instance().setAudioDevice(index, ring::DeviceType::CAPTURE); + return Manager::instance().setAudioDevice(index, DeviceType::CAPTURE); } void ConfigurationManager::setAudioRingtoneDevice(int32_t index) { - return Manager::instance().setAudioDevice(index, ring::DeviceType::RINGTONE); + return Manager::instance().setAudioDevice(index, DeviceType::RINGTONE); } std::vector<std::string> ConfigurationManager::getCurrentAudioDevicesIndex() @@ -681,3 +683,5 @@ std::vector< int32_t > ConfigurationManager::getHardwareAudioFormat() { return std::vector<int32_t> {44100, 64}; } + +} // namespace ring diff --git a/daemon/src/client/configurationmanager.h b/daemon/src/client/configurationmanager.h index ffd05a3dc63a90edc03999512be310e8a0dda480..6ea802eb4bee2ce92fb65796488ca50aebc541a1 100644 --- a/daemon/src/client/configurationmanager.h +++ b/daemon/src/client/configurationmanager.h @@ -44,6 +44,8 @@ #include "ring.h" +namespace ring { + class ConfigurationManager { public: @@ -172,4 +174,6 @@ class ConfigurationManager #pragma GCC diagnostic warning "-Wmissing-field-initializers" }; +} // namespace ring + #endif //CONFIGURATIONMANAGER_H diff --git a/daemon/src/client/presencemanager.cpp b/daemon/src/client/presencemanager.cpp index a61f16e079c82c5f5e592a5b9ac3d2e345347b43..bb7564c6278c46b5c98d75975579ae20cac3eee6 100644 --- a/daemon/src/client/presencemanager.cpp +++ b/daemon/src/client/presencemanager.cpp @@ -44,6 +44,8 @@ #include "sip/sippresence.h" #include "sip/pres_sub_client.h" +namespace ring { + constexpr static const char* STATUS_KEY = "Status"; constexpr static const char* LINESTATUS_KEY = "LineStatus"; constexpr static const char* ONLINE_KEY = "Online"; @@ -205,3 +207,5 @@ void PresenceManager::subscriptionStateChanged(const std::string& accountID, con evHandlers_.on_subscription_state_change(accountID, buddyUri, state); } } + +} // namespace ring diff --git a/daemon/src/client/presencemanager.h b/daemon/src/client/presencemanager.h index 2fa04b614996ad2081fb5cef9d6a2b2dd9dd077f..0b6ae9052c9395e8017f42a0c7d52d22326b7b55 100644 --- a/daemon/src/client/presencemanager.h +++ b/daemon/src/client/presencemanager.h @@ -40,6 +40,8 @@ #include "ring.h" +namespace ring { + class PresenceManager { public: @@ -69,4 +71,6 @@ class PresenceManager #pragma GCC diagnostic warning "-Wmissing-field-initializers" }; +} // namespace ring + #endif //PRESENCEINT_H diff --git a/daemon/src/client/videomanager.cpp b/daemon/src/client/videomanager.cpp index f1b30dc5aa2005c4bdc9a60d3e52c30ab22e9981..2afdd9f6e8a8e809b4af96bc5362cac125d515e9 100644 --- a/daemon/src/client/videomanager.cpp +++ b/daemon/src/client/videomanager.cpp @@ -38,12 +38,14 @@ #include "logger.h" #include "manager.h" +namespace ring { + void VideoManager::registerEvHandlers(struct ring_video_ev_handlers* evHandlers) { evHandlers_ = *evHandlers; } -ring::video::VideoDeviceMonitor & +video::VideoDeviceMonitor & VideoManager::getVideoDeviceMonitor() { return videoDeviceMonitor_; @@ -74,7 +76,7 @@ VideoManager::getDeviceList() return videoDeviceMonitor_.getDeviceList(); } -ring::video::VideoCapabilities +video::VideoCapabilities VideoManager::getCapabilities(const std::string& name) { return videoDeviceMonitor_.getCapabilities(name); @@ -137,13 +139,13 @@ VideoManager::switchToCamera() return switchInput("v4l2://" + videoDeviceMonitor_.getDefaultDevice()); } -std::shared_ptr<ring::video::VideoFrameActiveWriter> +std::shared_ptr<video::VideoFrameActiveWriter> VideoManager::getVideoCamera() { auto input = videoInput_.lock(); if (!input) { started_ = false; - input.reset(new ring::video::VideoInput()); + input.reset(new video::VideoInput()); videoInput_ = input; } return input; @@ -181,3 +183,5 @@ void VideoManager::stoppedDecoding(const std::string &id, const std::string& shm evHandlers_.on_stop_decoding(id, shmPath, isMixer); } } + +} // namespace ring diff --git a/daemon/src/client/videomanager.h b/daemon/src/client/videomanager.h index c6c21f48ccc78cb4038df1198900c326d384dbd8..f653448e4d4df6518e4bfc275537f9647b0c6f5f 100644 --- a/daemon/src/client/videomanager.h +++ b/daemon/src/client/videomanager.h @@ -45,6 +45,8 @@ #include "ring.h" +namespace ring { + class VideoManager { private: @@ -56,13 +58,13 @@ class VideoManager * this video input instance: this instance is destroyed when the last * external user has released its shared pointer. */ - std::weak_ptr<ring::video::VideoInput> videoInput_ = {}; - std::shared_ptr<ring::video::VideoFrameActiveWriter> videoPreview_ = nullptr; - ring::video::VideoDeviceMonitor videoDeviceMonitor_ = {}; + std::weak_ptr<video::VideoInput> videoInput_ = {}; + std::shared_ptr<video::VideoFrameActiveWriter> videoPreview_ = nullptr; + video::VideoDeviceMonitor videoDeviceMonitor_ = {}; public: void registerEvHandlers(struct ring_video_ev_handlers* evHandlers); - ring::video::VideoDeviceMonitor& getVideoDeviceMonitor(); + video::VideoDeviceMonitor& getVideoDeviceMonitor(); // Methods public: @@ -76,7 +78,7 @@ class VideoManager std::vector<std::string> getDeviceList(); - ring::video::VideoCapabilities + video::VideoCapabilities getCapabilities(const std::string& name); std::map<std::string, std::string> @@ -100,7 +102,7 @@ class VideoManager bool hasCameraStarted(); bool switchInput(const std::string& resource); bool switchToCamera(); - std::shared_ptr<ring::video::VideoFrameActiveWriter> getVideoCamera(); + std::shared_ptr<video::VideoFrameActiveWriter> getVideoCamera(); // Signals public: @@ -114,4 +116,6 @@ class VideoManager #pragma GCC diagnostic warning "-Wmissing-field-initializers" }; +} // namespace ring + #endif // VIDEOMANAGER_H_ diff --git a/daemon/src/conference.cpp b/daemon/src/conference.cpp index a031df59fd8639f98963ed7370332dc0905dfc29..744a5ad856b7fbe40ff1e1ac1d9df53381506a74 100644 --- a/daemon/src/conference.cpp +++ b/daemon/src/conference.cpp @@ -46,6 +46,7 @@ #include "logger.h" +namespace ring { Conference::Conference() : id_(Manager::instance().getNewCallID()) @@ -108,8 +109,8 @@ void Conference::bindParticipant(const std::string &participant_id) rbPool.flush(item); } - rbPool.bindCallID(participant_id, ring::RingBufferPool::DEFAULT_ID); - rbPool.flush(ring::RingBufferPool::DEFAULT_ID); + rbPool.bindCallID(participant_id, RingBufferPool::DEFAULT_ID); + rbPool.flush(RingBufferPool::DEFAULT_ID); } std::string Conference::getStateStr() const @@ -162,14 +163,14 @@ bool Conference::toggleRecording() for (const auto &item : participants_) rbPool.bindHalfDuplexOut(process_id, item); - rbPool.bindHalfDuplexOut(process_id, ring::RingBufferPool::DEFAULT_ID); + rbPool.bindHalfDuplexOut(process_id, RingBufferPool::DEFAULT_ID); Recordable::recorder_.start(); } else { for (const auto &item : participants_) rbPool.unBindHalfDuplexOut(process_id, item); - rbPool.unBindHalfDuplexOut(process_id, ring::RingBufferPool::DEFAULT_ID); + rbPool.unBindHalfDuplexOut(process_id, RingBufferPool::DEFAULT_ID); } return startRecording; @@ -180,10 +181,12 @@ std::string Conference::getConfID() const { } #ifdef RING_VIDEO -std::shared_ptr<ring::video::VideoMixer> Conference::getVideoMixer() +std::shared_ptr<video::VideoMixer> Conference::getVideoMixer() { if (!videoMixer_) - videoMixer_.reset(new ring::video::VideoMixer(id_)); + videoMixer_.reset(new video::VideoMixer(id_)); return videoMixer_; } #endif + +} // namespace ring diff --git a/daemon/src/conference.h b/daemon/src/conference.h index c322af7f914f24261d5ab79319a507c7e4971710..24e8519f8241a4ed5a9179e5db2523046356ed60 100644 --- a/daemon/src/conference.h +++ b/daemon/src/conference.h @@ -44,9 +44,11 @@ #include "video/video_mixer.h" #endif +namespace ring { + typedef std::set<std::string> ParticipantSet; -class Conference : public ring::Recordable { +class Conference : public Recordable { public: enum ConferenceState {ACTIVE_ATTACHED, ACTIVE_DETACHED, ACTIVE_ATTACHED_REC, ACTIVE_DETACHED_REC, HOLD, HOLD_REC}; @@ -112,7 +114,7 @@ class Conference : public ring::Recordable { virtual bool toggleRecording(); #ifdef RING_VIDEO - std::shared_ptr<ring::video::VideoMixer> getVideoMixer(); + std::shared_ptr<video::VideoMixer> getVideoMixer(); #endif private: @@ -121,8 +123,10 @@ class Conference : public ring::Recordable { ParticipantSet participants_; #ifdef RING_VIDEO - std::shared_ptr<ring::video::VideoMixer> videoMixer_; + std::shared_ptr<video::VideoMixer> videoMixer_; #endif }; +} // namespace ring + #endif diff --git a/daemon/src/config/serializable.h b/daemon/src/config/serializable.h index 81e6dca46758dc0f69aeb77c594b279d07d495df..d5a83ab52eab24d11ae6b3d464970241a24f7afe 100644 --- a/daemon/src/config/serializable.h +++ b/daemon/src/config/serializable.h @@ -36,6 +36,8 @@ namespace YAML { class Node; } +namespace ring { + class Serializable { public: @@ -44,4 +46,6 @@ class Serializable { virtual void unserialize(const YAML::Node &node) = 0; }; +} // namespace ring + #endif diff --git a/daemon/src/config/yamlparser.cpp b/daemon/src/config/yamlparser.cpp index 71f7b8cdcbb3e840d16ffe4a853b7eace71e573e..b410c0d042aef430f6af4612a272614767abc0fe 100644 --- a/daemon/src/config/yamlparser.cpp +++ b/daemon/src/config/yamlparser.cpp @@ -28,14 +28,14 @@ * as that of the covered work. */ -#include <yaml-cpp/yaml.h> +#include "yamlparser.h" -namespace yaml_utils { +namespace ring { // FIXME: Maybe think of something more clever, this is due to yaml-cpp's poor // handling of empty values for nested collections. std::vector<std::map<std::string, std::string>> -parseVectorMap(const YAML::Node &node, const std::initializer_list<std::string> &keys) +yaml_utils::parseVectorMap(const YAML::Node &node, const std::initializer_list<std::string> &keys) { std::vector<std::map<std::string, std::string>> result; for (const auto &n : node) { @@ -48,4 +48,4 @@ parseVectorMap(const YAML::Node &node, const std::initializer_list<std::string> return result; } -} +} // namespace ring diff --git a/daemon/src/config/yamlparser.h b/daemon/src/config/yamlparser.h index 06920fa2b1666ada74d5718edb9b2f870d86bbc3..d947228c9fc1f818bfd4104daa3377c0fb514373 100644 --- a/daemon/src/config/yamlparser.h +++ b/daemon/src/config/yamlparser.h @@ -33,7 +33,8 @@ #include <yaml-cpp/yaml.h> -namespace yaml_utils { +namespace ring { namespace yaml_utils { + // set T to the value stored at key, or leaves T unchanged // if no value is stored. template <typename T> @@ -44,6 +45,7 @@ void parseValue(const YAML::Node &node, const char *key, T &value) std::vector<std::map<std::string, std::string>> parseVectorMap(const YAML::Node &node, const std::initializer_list<std::string> &keys); -} + +}} // namespace ring::yaml_utils #endif diff --git a/daemon/src/enumclass_utils.h b/daemon/src/enumclass_utils.h index f67f38b3c910395a48e93b17bded1656c7a598bc..344679bc35c2d6b7f226429c91b5dde7097f7692 100644 --- a/daemon/src/enumclass_utils.h +++ b/daemon/src/enumclass_utils.h @@ -97,7 +97,7 @@ private: * This is useful to use enum class in C++11 foreach loops * * @usage - * for (const MyEnum& value : ring::Matrix0D<MyEnum>()) { + * for (const MyEnum& value : Matrix0D<MyEnum>()) { * std::cout << "Name: " << MyEnumNames[value] << std::endl; * } */ @@ -210,7 +210,7 @@ template <class E, class T, class A> std::map<A,E> Matrix1D<E,T,A>::reverseMappi template<class Row, typename Value, typename Accessor> void Matrix1D<Row,Value,Accessor>::setReverseMapping(Matrix1D<Row,const char*> names) { - for ( const Row row : ring::Matrix0D<Row>() ) + for ( const Row row : Matrix0D<Row>() ) reverseMapping_[names[row]] = row; } @@ -291,6 +291,6 @@ typename Matrix1D<Row,Value,Accessor>::EnumClassIter Matrix1D<Row,Value,Accessor return Matrix1D<Row,Value,Accessor>::EnumClassIter( this, enum_class_size<Row>() ); } -}; //sfl +} // namespace ring #endif //ENUM_CLASS_UTILS_H diff --git a/daemon/src/fileutils.cpp b/daemon/src/fileutils.cpp index ea96d4d1757cfeeb36d9610b41eebb38c3b4ef19..196820dbd41fd59f10fcc03b6afc86885546d5f8 100644 --- a/daemon/src/fileutils.cpp +++ b/daemon/src/fileutils.cpp @@ -63,7 +63,8 @@ #include <cerrno> #include <cstddef> -namespace fileutils { +namespace ring { namespace fileutils { + // returns true if directory exists bool check_dir(const char *path) { @@ -362,4 +363,4 @@ get_data_dir() "share" DIR_SEPARATOR_STR + PACKAGE; } -} +}} // namespace ring::fileutils diff --git a/daemon/src/fileutils.h b/daemon/src/fileutils.h index 21486e982fc823b9804683e0b9c2fa5959ea36d2..c48653c18c8e7b85803461a06e82769bc7a1b897 100644 --- a/daemon/src/fileutils.h +++ b/daemon/src/fileutils.h @@ -47,7 +47,8 @@ #define DIR_SEPARATOR_STR "/" // Directory separator char #define DIR_SEPARATOR_CH '/' // Directory separator string -namespace fileutils { +namespace ring { namespace fileutils { + std::string get_data_dir(); std::string get_home_dir(); std::string get_cache_dir(); @@ -75,6 +76,7 @@ namespace fileutils { ~FileHandle(); }; FileHandle create_pidfile(); -} -#endif // FILEUTILS_H_ +}} // namespace ring::fileutils + +#endif // FILEUTILS_H_ diff --git a/daemon/src/history/history.cpp b/daemon/src/history/history.cpp index 2e79ed4d6d24c7b482c91b7b697d48752ad8255f..48a6ce25e8db9dd62e3333ef9e0f8450cde77d17 100644 --- a/daemon/src/history/history.cpp +++ b/daemon/src/history/history.cpp @@ -169,4 +169,4 @@ History::getNameFromHistory(const std::string &number, return it2->second; } -} +} // namespace ring diff --git a/daemon/src/history/history.h b/daemon/src/history/history.h index eefe97811ec290f3a316d2fa4f884c63a0536557..6e4c2acab70fc5e54f0209576776e1bd55d05cce 100644 --- a/daemon/src/history/history.h +++ b/daemon/src/history/history.h @@ -37,10 +37,14 @@ #include <mutex> #include <vector> -class Call; - namespace ring { +namespace test { +class HistoryTest; +} + +class Call; + class History { public: @@ -94,7 +98,7 @@ class History { /* The path to the history file */ std::string path_; - friend class HistoryTest; + friend class test::HistoryTest; }; } diff --git a/daemon/src/history/historyitem.cpp b/daemon/src/history/historyitem.cpp index 2ce05929932d8ff098acbd1e709bd66e86a6a500..2bbc702df5fa8cf543de04badb22f3a689d1a9d7 100644 --- a/daemon/src/history/historyitem.cpp +++ b/daemon/src/history/historyitem.cpp @@ -121,4 +121,4 @@ std::ostream& operator << (std::ostream& o, const HistoryItem& item) return o; } -} +} // namespace ring diff --git a/daemon/src/history/historyitem.h b/daemon/src/history/historyitem.h index 17d2e7fecc99853985687e0c432e17ce92b8600f..a5cc81c4c1a06e627e331dfdfaac952f7f993697 100644 --- a/daemon/src/history/historyitem.h +++ b/daemon/src/history/historyitem.h @@ -81,6 +81,6 @@ class HistoryItem { std::ostream& operator << (std::ostream& o, const HistoryItem& item); -} +} // namespace ring #endif // HISTORY_ITEM diff --git a/daemon/src/hooks/urlhook.cpp b/daemon/src/hooks/urlhook.cpp index 233fcaca98524fef8c8ecce369876209d2e1d916..373fa2bc0cc6d8df2142b25b556cfba83b9fb94f 100644 --- a/daemon/src/hooks/urlhook.cpp +++ b/daemon/src/hooks/urlhook.cpp @@ -31,6 +31,8 @@ #include "urlhook.h" #include <cstdlib> +namespace ring { + int UrlHook::runAction(const std::string &command, const std::string &args) { //FIXME : use fork and execve, so no need to escape shell arguments @@ -39,3 +41,4 @@ int UrlHook::runAction(const std::string &command, const std::string &args) return system(cmd.c_str()); } +} // namespace ring diff --git a/daemon/src/hooks/urlhook.h b/daemon/src/hooks/urlhook.h index 8388c8cb1e47cb0d37e9ebc8b3da7101d63a6e1a..2c51325181a5d71bf73af84d8ce407f4f31d46a2 100644 --- a/daemon/src/hooks/urlhook.h +++ b/daemon/src/hooks/urlhook.h @@ -33,7 +33,10 @@ #include <string> -namespace UrlHook { +namespace ring { namespace UrlHook { + int runAction(const std::string &command, const std::string &arg); -} + +}} // namespace ring::UrlHook + #endif // URL_HOOK_H diff --git a/daemon/src/iax/iaxaccount.cpp b/daemon/src/iax/iaxaccount.cpp index f26f9c8c84ab5d1e8df1649771a04f7f578568b4..6a90d40df2e58f5b920159069ecc68c537086bc7 100644 --- a/daemon/src/iax/iaxaccount.cpp +++ b/daemon/src/iax/iaxaccount.cpp @@ -47,6 +47,8 @@ #include "config/yamlparser.h" #include <yaml-cpp/yaml.h> +namespace ring { + constexpr const char * const IAXAccount::ACCOUNT_TYPE; IAXAccount::IAXAccount(const std::string& accountID) @@ -55,8 +57,6 @@ IAXAccount::IAXAccount(const std::string& accountID) void IAXAccount::serialize(YAML::Emitter &out) { - using namespace Conf; - out << YAML::BeginMap; Account::serialize(out); out << YAML::Key << PASSWORD_KEY << YAML::Value << password_; @@ -65,22 +65,21 @@ void IAXAccount::serialize(YAML::Emitter &out) void IAXAccount::unserialize(const YAML::Node &node) { - using namespace yaml_utils; Account::unserialize(node); - parseValue(node, PASSWORD_KEY, password_); + yaml_utils::parseValue(node, PASSWORD_KEY, password_); } void IAXAccount::setAccountDetails(const std::map<std::string, std::string> &details) { // Account setting common to SIP and IAX Account::setAccountDetails(details); - parseString(details, CONFIG_ACCOUNT_PASSWORD, password_); + parseString(details, Conf::CONFIG_ACCOUNT_PASSWORD, password_); } std::map<std::string, std::string> IAXAccount::getAccountDetails() const { std::map<std::string, std::string> a = Account::getAccountDetails(); - a[CONFIG_ACCOUNT_PASSWORD] = password_; + a[Conf::CONFIG_ACCOUNT_PASSWORD] = password_; return a; } @@ -236,3 +235,5 @@ IAXAccount::matchRegSession(const iax_session* session) const { return regSession_.get() == session; } + +} // namespace ring diff --git a/daemon/src/iax/iaxaccount.h b/daemon/src/iax/iaxaccount.h index 2e524e571b5ae25365c551081ed2268e95d5460c..ff3a70989e4c95d199a68e389ce0ec51153b6e0e 100644 --- a/daemon/src/iax/iaxaccount.h +++ b/daemon/src/iax/iaxaccount.h @@ -42,6 +42,8 @@ namespace YAML { class Node; } +namespace ring { + class IAXCall; /** @@ -156,4 +158,6 @@ class IAXAccount : public Account { int nextRefreshStamp_ = 0; }; +} // namespace ring + #endif diff --git a/daemon/src/iax/iaxcall.cpp b/daemon/src/iax/iaxcall.cpp index 4f6a0eb195d0867ba006211ddf8f1d41b340fa78..3f7710ad7dfc217c81c65ee186a6e8fd9e6d905d 100644 --- a/daemon/src/iax/iaxcall.cpp +++ b/daemon/src/iax/iaxcall.cpp @@ -48,6 +48,8 @@ #include "im/instant_messaging.h" #endif +namespace ring { + const char* const IAXCall::LINK_TYPE = IAXAccount::ACCOUNT_TYPE; static int @@ -239,12 +241,14 @@ void IAXCall::sendTextMessage(const std::string& message, const std::string& /*from*/) { std::lock_guard<std::mutex> lock(IAXVoIPLink::mutexIAX); - ring::InstantMessaging::send_iax_message(session, getCallId(), message.c_str()); + InstantMessaging::send_iax_message(session, getCallId(), message.c_str()); } #endif void -IAXCall::putAudioData(ring::AudioBuffer& buf) +IAXCall::putAudioData(AudioBuffer& buf) { ringbuffer_->put(buf); } + +} // namespace ring diff --git a/daemon/src/iax/iaxcall.h b/daemon/src/iax/iaxcall.h index a910804b0c790f357778ff8a6fca7c22f6006a62..3545d635a6267748642281f2b9c8b555f11b2a31 100644 --- a/daemon/src/iax/iaxcall.h +++ b/daemon/src/iax/iaxcall.h @@ -39,18 +39,18 @@ #include "call.h" #include "noncopyable.h" -class IAXAccount; +class iax_session; namespace ring { - class RingBuffer; - class AudioBuffer; -} + +class IAXAccount; +class RingBuffer; +class AudioBuffer; /** * @file: iaxcall.h * @brief IAXCall are IAX implementation of a normal Call */ -class iax_session; class IAXCall : public Call { @@ -114,13 +114,15 @@ class IAXCall : public Call const std::string& from); #endif - void putAudioData(ring::AudioBuffer& buf); + void putAudioData(AudioBuffer& buf); private: NON_COPYABLE(IAXCall); // Incoming audio ring buffer - std::shared_ptr<ring::RingBuffer> ringbuffer_{}; + std::shared_ptr<RingBuffer> ringbuffer_{}; }; +} // namespace ring + #endif diff --git a/daemon/src/iax/iaxvoiplink.cpp b/daemon/src/iax/iaxvoiplink.cpp index 675d865a9945fab07a74182020f1cc8bdaf50546..8994f21f007645d94e56e65ed58973bbf91c7f54 100644 --- a/daemon/src/iax/iaxvoiplink.cpp +++ b/daemon/src/iax/iaxvoiplink.cpp @@ -48,7 +48,7 @@ #include "call_factory.h" #include "ring_types.h" -using namespace ring; +namespace ring { std::mutex IAXVoIPLink::mutexIAX = {}; @@ -178,7 +178,7 @@ IAXVoIPLink::sendAudioFromMic() int compSize; unsigned int audioRate = audioCodec->getClockRate(); int outSamples; - ring::AudioBuffer *in; + AudioBuffer *in; if (audioRate != mainBufferSampleRate) { rawBuffer_.setSampleRate(audioRate); @@ -350,7 +350,7 @@ IAXVoIPLink::iaxHandleVoiceEvent(iax_event* event, IAXCall& call) size = max; audioCodec->decode(rawBuffer_.getData(), data , size); - ring::AudioBuffer *out = &rawBuffer_; + AudioBuffer *out = &rawBuffer_; unsigned int audioRate = audioCodec->getClockRate(); if (audioRate != mainBufferSampleRate) { @@ -443,3 +443,5 @@ void IAXVoIPLink::iaxHandlePrecallEvent(iax_event* event) break; } } + +} // namespace ring diff --git a/daemon/src/iax/iaxvoiplink.h b/daemon/src/iax/iaxvoiplink.h index 152fd38a5cdd773ecae888f79053f35a71431ca6..ad3c515232815902740e2524c2a86c50a621adb7 100644 --- a/daemon/src/iax/iaxvoiplink.h +++ b/daemon/src/iax/iaxvoiplink.h @@ -46,14 +46,13 @@ #include <mutex> #include <memory> +namespace ring { + class IAXAccount; class IAXCall; class AudioCodec; class AudioLayer; - -namespace ring { - class Resampler; -} +class Resampler; /** * @file iaxvoiplink.h @@ -153,11 +152,11 @@ class IAXVoIPLink { IAXAccount& account_; /** encoder/decoder/resampler buffers */ - ring::AudioBuffer rawBuffer_{RAW_BUFFER_SIZE, ring::AudioFormat::MONO()}; - ring::AudioBuffer resampledData_{RAW_BUFFER_SIZE * 4, ring::AudioFormat::MONO()}; + AudioBuffer rawBuffer_{RAW_BUFFER_SIZE, AudioFormat::MONO()}; + AudioBuffer resampledData_{RAW_BUFFER_SIZE * 4, AudioFormat::MONO()}; unsigned char encodedData_[RAW_BUFFER_SIZE] = {}; - std::unique_ptr<ring::Resampler> resampler_; + std::unique_ptr<Resampler> resampler_; /** Whether init() was called already or not * This should be used in init() and terminate(), to @@ -166,4 +165,6 @@ class IAXVoIPLink { bool initDone_{false}; }; +} // namespace ring + #endif diff --git a/daemon/src/ice_transport.cpp b/daemon/src/ice_transport.cpp index 3b34d93c5a3162bebc27175c52803001ae4b8915..d26a59f205c6c59a7ec26df2bd3ee13915d45d84 100644 --- a/daemon/src/ice_transport.cpp +++ b/daemon/src/ice_transport.cpp @@ -760,4 +760,4 @@ IceSocket::waitForData(unsigned int timeout) return ice_transport_->waitForData(compId_, timeout); } -} +} // namespace ring diff --git a/daemon/src/im/instant_messaging.cpp b/daemon/src/im/instant_messaging.cpp index 47680df8367a4d79b8bf089b05bb05f69c2c8571..bda87681700eb5539b9739a708d1d1788880d5c0 100644 --- a/daemon/src/im/instant_messaging.cpp +++ b/daemon/src/im/instant_messaging.cpp @@ -33,25 +33,26 @@ #include "logger.h" #include <expat.h> +namespace ring { + static void XMLCALL startElementCallback(void *userData, const char *name, const char **atts) { if (strcmp(name, "entry")) return; - ring::InstantMessaging::UriEntry entry = ring::InstantMessaging::UriEntry(); + InstantMessaging::UriEntry entry = InstantMessaging::UriEntry(); for (const char **att = atts; *att; att += 2) entry.insert(std::pair<std::string, std::string> (*att, *(att+1))); - static_cast<ring::InstantMessaging::UriList *>(userData)->push_back(entry); + static_cast<InstantMessaging::UriList *>(userData)->push_back(entry); } static void XMLCALL endElementCallback(void * /*userData*/, const char * /*name*/) {} -namespace ring { bool InstantMessaging::saveMessage(const std::string &message, const std::string &author, const std::string &id, int mode) { std::ofstream File; @@ -135,7 +136,7 @@ std::string InstantMessaging::generateXmlUriList(UriList &list) "<list>"; for (auto &item : list) - xmlbuffer += "<entry uri=" + item[ring::IM_XML_URI] + " cp:copyControl=\"to\" />"; + xmlbuffer += "<entry uri=" + item[IM_XML_URI] + " cp:copyControl=\"to\" />"; return xmlbuffer + "</list></resource-lists>"; } @@ -211,5 +212,4 @@ std::string InstantMessaging::findTextMessage(const std::string &text) return text.substr(begin, end - begin); } - -} +} // namespace ring diff --git a/daemon/src/im/instant_messaging.h b/daemon/src/im/instant_messaging.h index 632bcd3bbd4c1aef40f18b3e4ccba4df9a270907..415857c52891582b20c0d9fc15e73dd3da3b7832 100644 --- a/daemon/src/im/instant_messaging.h +++ b/daemon/src/im/instant_messaging.h @@ -57,7 +57,7 @@ #define MODE_APPEND std::ios::out || std::ios::app #define MODE_TEST std::ios::out -namespace ring { +namespace ring { namespace InstantMessaging { const std::string IM_XML_URI("uri"); const std::string BOUNDARY("--boundary"); @@ -68,81 +68,81 @@ class InstantMessageException : public std::runtime_error { std::runtime_error("InstantMessageException occured: " + str) {} }; -namespace InstantMessaging { - typedef std::map<std::string, std::string> UriEntry; - typedef std::list<UriEntry> UriList; - - /* - * Write the text message to the right file - * The call ID is associated to a file descriptor, so it is easy then to retrieve the right file - * - * @param message The text message - * @param id The current call - * @return True if the message could have been successfully saved, False otherwise - */ - bool saveMessage(const std::string& message, const std::string& author, const std::string& id, int mode = MODE_APPEND); - - /* - * Send a SIP string message inside a call - * - * @param id The call ID we will retrieve the invite session from - * @param message The string message, as sent by the client - */ - void sip_send(pjsip_inv_session*, const std::string& id, const std::string&); - - void send_sip_message(pjsip_inv_session*, const std::string& id, const std::string&); +typedef std::map<std::string, std::string> UriEntry; +typedef std::list<UriEntry> UriList; + +/* + * Write the text message to the right file + * The call ID is associated to a file descriptor, so it is easy then to retrieve the right file + * + * @param message The text message + * @param id The current call + * @return True if the message could have been successfully saved, False otherwise + */ +bool saveMessage(const std::string& message, const std::string& author, const std::string& id, int mode = MODE_APPEND); + +/* + * Send a SIP string message inside a call + * + * @param id The call ID we will retrieve the invite session from + * @param message The string message, as sent by the client + */ +void sip_send(pjsip_inv_session*, const std::string& id, const std::string&); + +void send_sip_message(pjsip_inv_session*, const std::string& id, const std::string&); #if HAVE_IAX - void send_iax_message(iax_session *session, const std::string& id, const std::string&); +void send_iax_message(iax_session *session, const std::string& id, const std::string&); #endif - std::vector<std::string> split_message(std::string); - - /** - * Generate Xml participant list for multi recipient based on RFC Draft 5365 - * - * @param A UriList of UriEntry - * - * @return A string containing the full XML formated information to be included in the - * sip instant message. - */ - std::string generateXmlUriList(UriList &list); - - /** - * Parse the Urilist from a SIP Instant Message provided by a UriList service. - * - * @param A XML formated string as obtained from a SIP instant message. - * - * @return An UriList of UriEntry containing parsed XML information as a map. - */ - UriList parseXmlUriList(const std::string &urilist); - - /** - * Format text message according to RFC 5365, append recipient-list to the message - * - * @param text to be displayed - * @param list containing the recipients - * - * @return formated text stored into a string to be included in sip MESSAGE - */ - std::string appendUriList(const std::string &text, UriList &list); - - /** - * Retreive the xml formated uri list in formated text data according to RFC 5365 - * - * @param text The formated text message as retreived in the SIP message - * - * @return A string containing the XML content - */ - std::string findTextUriList(const std::string &text); - - /** - * Retrive the plain text message in formated text data according to RFC 5365 - * - * @param text The formated text message as retreived in the SIP message - * - * @return A string containing the actual message - */ - std::string findTextMessage(const std::string &text); -} // end namespace InstantMessaging -} +std::vector<std::string> split_message(std::string); + +/** + * Generate Xml participant list for multi recipient based on RFC Draft 5365 + * + * @param A UriList of UriEntry + * + * @return A string containing the full XML formated information to be included in the + * sip instant message. + */ +std::string generateXmlUriList(UriList &list); + +/** + * Parse the Urilist from a SIP Instant Message provided by a UriList service. + * + * @param A XML formated string as obtained from a SIP instant message. + * + * @return An UriList of UriEntry containing parsed XML information as a map. + */ +UriList parseXmlUriList(const std::string &urilist); + +/** + * Format text message according to RFC 5365, append recipient-list to the message + * + * @param text to be displayed + * @param list containing the recipients + * + * @return formated text stored into a string to be included in sip MESSAGE + */ +std::string appendUriList(const std::string &text, UriList &list); + +/** + * Retreive the xml formated uri list in formated text data according to RFC 5365 + * + * @param text The formated text message as retreived in the SIP message + * + * @return A string containing the XML content + */ +std::string findTextUriList(const std::string &text); + +/** + * Retrive the plain text message in formated text data according to RFC 5365 + * + * @param text The formated text message as retreived in the SIP message + * + * @return A string containing the actual message + */ +std::string findTextMessage(const std::string &text); + +}} // namespace ring::InstantMessaging + #endif // __INSTANT_MESSAGING_H_ diff --git a/daemon/src/ip_utils.cpp b/daemon/src/ip_utils.cpp index d01dfa1586e6c8e46c3e7cb4de9de1d7630d06f9..422f67a457b3246032e60c83b4b22d472eb05475 100644 --- a/daemon/src/ip_utils.cpp +++ b/daemon/src/ip_utils.cpp @@ -44,6 +44,8 @@ #include <sys/ioctl.h> #include <unistd.h> +namespace ring { + std::vector<IpAddr> ip_utils::getAddrList(const std::string &name, pj_uint16_t family) { @@ -308,3 +310,5 @@ IpAddr::isPrivate() const return false; } } + +} // namespace ring diff --git a/daemon/src/ip_utils.h b/daemon/src/ip_utils.h index 8c7adeede4fb720ead5ecdfc888f59425273cc57..2b094831b1edbe032ae84ced70cd41bf2f984326 100644 --- a/daemon/src/ip_utils.h +++ b/daemon/src/ip_utils.h @@ -45,6 +45,7 @@ #define IN_IS_ADDR_UNSPECIFIED(a) (((long int) (a)->s_addr) == 0x00000000) #endif /* IN_IS_ADDR_UNSPECIFIED */ +namespace ring { class IpAddr { public: @@ -204,57 +205,60 @@ private: }; namespace ip_utils { - static const char *const DEFAULT_INTERFACE = "default"; - /** - * Return the generic "any host" IP address of the specified family. - * If family is unspecified, default to pj_AF_INET6() (IPv6). - */ - IpAddr getAnyHostAddr(pj_uint16_t family = pj_AF_UNSPEC()); - - /** - * Return the first host IP address of the specified family. - * If no address of the specified family is found, another family will - * be tried. - * Ex. : if family is pj_AF_INET6() (IPv6/default) and the system does not - * have an IPv6 address, an IPv4 address will be returned if available. - * - * If family is unspecified, default to pj_AF_INET6() if compiled - * with IPv6, or pj_AF_INET() otherwise. - */ - IpAddr getLocalAddr(pj_uint16_t family = pj_AF_UNSPEC()); +static const char *const DEFAULT_INTERFACE = "default"; - /** - * Get the IP address of the network interface interface with the specified - * address family, or of any address family if unspecified (default). - */ - IpAddr getInterfaceAddr(const std::string &interface, pj_uint16_t family = pj_AF_UNSPEC()); +/** + * Return the generic "any host" IP address of the specified family. + * If family is unspecified, default to pj_AF_INET6() (IPv6). + */ +IpAddr getAnyHostAddr(pj_uint16_t family = pj_AF_UNSPEC()); + +/** + * Return the first host IP address of the specified family. + * If no address of the specified family is found, another family will + * be tried. + * Ex. : if family is pj_AF_INET6() (IPv6/default) and the system does not + * have an IPv6 address, an IPv4 address will be returned if available. + * + * If family is unspecified, default to pj_AF_INET6() if compiled + * with IPv6, or pj_AF_INET() otherwise. + */ +IpAddr getLocalAddr(pj_uint16_t family = pj_AF_UNSPEC()); - /** - * List all the interfaces on the system and return - * a vector list containing their name (eth0, eth0:1 ...). - * @param void - * @return std::vector<std::string> A std::string vector - * of interface name available on all of the interfaces on - * the system. - */ - std::vector<std::string> getAllIpInterfaceByName(); +/** + * Get the IP address of the network interface interface with the specified + * address family, or of any address family if unspecified (default). + */ +IpAddr getInterfaceAddr(const std::string &interface, pj_uint16_t family = pj_AF_UNSPEC()); + +/** + * List all the interfaces on the system and return + * a vector list containing their name (eth0, eth0:1 ...). + * @param void + * @return std::vector<std::string> A std::string vector + * of interface name available on all of the interfaces on + * the system. + */ +std::vector<std::string> getAllIpInterfaceByName(); + +/** + * List all the interfaces on the system and return + * a vector list containing their IP address. + * @param void + * @return std::vector<std::string> A std::string vector + * of IP address available on all of the interfaces on + * the system. + */ +std::vector<std::string> getAllIpInterface(); - /** - * List all the interfaces on the system and return - * a vector list containing their IP address. - * @param void - * @return std::vector<std::string> A std::string vector - * of IP address available on all of the interfaces on - * the system. - */ - std::vector<std::string> getAllIpInterface(); +std::vector<IpAddr> getAddrList(const std::string &name, pj_uint16_t family = pj_AF_UNSPEC()); - std::vector<IpAddr> getAddrList(const std::string &name, pj_uint16_t family = pj_AF_UNSPEC()); +bool haveCommonAddr(const std::vector<IpAddr>& a, const std::vector<IpAddr>& b); - bool haveCommonAddr(const std::vector<IpAddr>& a, const std::vector<IpAddr>& b); +std::vector<IpAddr> getLocalNameservers(); - std::vector<IpAddr> getLocalNameservers(); -} +} // namespace ip_utils +} // namespace ring #endif // IP_UTILS_H_ diff --git a/daemon/src/manager.cpp b/daemon/src/manager.cpp index 8c35ac9fd49a64574a52376692b05b5263743e88..e5c92b9692240c567265b1af32da5db4072f7d52 100644 --- a/daemon/src/manager.cpp +++ b/daemon/src/manager.cpp @@ -31,6 +31,8 @@ #include "manager.h" #include "logger.h" +namespace ring { + ManagerImpl& Manager::instance() { // Meyers singleton @@ -43,3 +45,5 @@ ManagerImpl& Manager::instance() return instance_; } + +} // namespace ring diff --git a/daemon/src/manager.h b/daemon/src/manager.h index d5da6a023d147526dbca61b45e8dc3b537612712..476a4717e99fe9da0c78e90a23140154c98d6255 100644 --- a/daemon/src/manager.h +++ b/daemon/src/manager.h @@ -36,9 +36,11 @@ // will need this include. #include "managerimpl.h" -namespace Manager { - ManagerImpl& instance(); -} +namespace ring { namespace Manager { + +ManagerImpl& instance(); + +}} // namespace ring::Manager #endif // MANAGER_H_ diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index d42e5718963efb22d5532445e0a9b2259d71c158..4780bc2678bc612cb98275e793c8e8aac1bda850 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -92,12 +92,10 @@ #include <sys/stat.h> // mkdir(2) #include <memory> -using namespace ring; +namespace ring { std::atomic_bool ManagerImpl::initialized = {false}; -using namespace ring; - static void copy_over(const std::string &srcPath, const std::string &destPath) { @@ -135,10 +133,10 @@ ManagerImpl::ManagerImpl() : , preferences(), voipPreferences(), hookPreference(), audioPreference(), shortcutPreferences(), hasTriedToRegister_(false), audioCodecFactory(*pluginManager_), client_(), - currentCallMutex_(), dtmfKey_(), dtmfBuf_(0, ring::AudioFormat::MONO()), + currentCallMutex_(), dtmfKey_(), dtmfBuf_(0, AudioFormat::MONO()), toneMutex_(), telephoneTone_(), audiofile_(), audioLayerMutex_(), waitingCalls_(), waitingCallsMutex_(), path_() - , ringbufferpool_(new ring::RingBufferPool) + , ringbufferpool_(new RingBufferPool) , callFactory(), conferenceMap_(), history_(), finished_(false), accountFactory_(), ice_tf_() { @@ -235,9 +233,9 @@ ManagerImpl::init(const std::string &config_file) if (audiodriver_) { { std::lock_guard<std::mutex> toneLock(toneMutex_); - telephoneTone_.reset(new ring::TelephoneTone(preferences.getZoneToneChoice(), audiodriver_->getSampleRate())); + telephoneTone_.reset(new TelephoneTone(preferences.getZoneToneChoice(), audiodriver_->getSampleRate())); } - dtmfKey_.reset(new ring::DTMF(getRingBufferPool().getInternalSamplingRate())); + dtmfKey_.reset(new DTMF(getRingBufferPool().getInternalSamplingRate())); } } @@ -376,7 +374,7 @@ ManagerImpl::outgoingCall(const std::string& preferred_account_id, if (not isConference(current_call_id) and not isConferenceParticipant(current_call_id)) onHoldCall(current_call_id); else if (isConference(current_call_id) and not isConferenceParticipant(call_id)) - detachParticipant(ring::RingBufferPool::DEFAULT_ID); + detachParticipant(RingBufferPool::DEFAULT_ID); } std::shared_ptr<Call> call; @@ -437,7 +435,7 @@ ManagerImpl::answerCall(const std::string& call_id) } else if (isConference(current_call_id) and not isConferenceParticipant(call_id)) { // if we are talking to a conference and we are answering an incoming call RING_DBG("Detach main participant from conference"); - detachParticipant(ring::RingBufferPool::DEFAULT_ID); + detachParticipant(RingBufferPool::DEFAULT_ID); } } @@ -603,7 +601,7 @@ ManagerImpl::offHoldCall(const std::string& callId) } else if (isConference(currentCallId) && callId != currentCallId) { holdConference(currentCallId); } else if (isConference(currentCallId) and not isConferenceParticipant(callId)) - detachParticipant(ring::RingBufferPool::DEFAULT_ID); + detachParticipant(RingBufferPool::DEFAULT_ID); } std::shared_ptr<Call> call; @@ -741,7 +739,7 @@ ManagerImpl::removeConference(const std::string& conference_id) // We now need to bind the audio to the remain participant // Unbind main participant audio from conference - getRingBufferPool().unBindAll(ring::RingBufferPool::DEFAULT_ID); + getRingBufferPool().unBindAll(RingBufferPool::DEFAULT_ID); ParticipantSet participants(conf->getParticipantList()); @@ -749,7 +747,7 @@ ManagerImpl::removeConference(const std::string& conference_id) ParticipantSet::iterator iter_p = participants.begin(); if (iter_p != participants.end()) - getRingBufferPool().bindCallID(*iter_p, ring::RingBufferPool::DEFAULT_ID); + getRingBufferPool().bindCallID(*iter_p, RingBufferPool::DEFAULT_ID); // Then remove the conference from the conference map if (conferenceMap_.erase(conference_id)) @@ -875,7 +873,7 @@ ManagerImpl::addParticipant(const std::string& callId, // detach from prior communication and switch to this conference if (current_call_id != callId) { if (isConference(current_call_id)) - detachParticipant(ring::RingBufferPool::DEFAULT_ID); + detachParticipant(RingBufferPool::DEFAULT_ID); else onHoldCall(current_call_id); } @@ -927,7 +925,7 @@ ManagerImpl::addMainParticipant(const std::string& conference_id) std::string current_call_id(getCurrentCallId()); if (isConference(current_call_id)) - detachParticipant(ring::RingBufferPool::DEFAULT_ID); + detachParticipant(RingBufferPool::DEFAULT_ID); else onHoldCall(current_call_id); } @@ -945,12 +943,12 @@ ManagerImpl::addMainParticipant(const std::string& conference_id) ParticipantSet participants(conf->getParticipantList()); for (const auto &item_p : participants) { - getRingBufferPool().bindCallID(item_p, ring::RingBufferPool::DEFAULT_ID); + getRingBufferPool().bindCallID(item_p, RingBufferPool::DEFAULT_ID); // Reset ringbuffer's readpointers getRingBufferPool().flush(item_p); } - getRingBufferPool().flush(ring::RingBufferPool::DEFAULT_ID); + getRingBufferPool().flush(RingBufferPool::DEFAULT_ID); if (conf->getState() == Conference::ACTIVE_DETACHED) conf->setState(Conference::ACTIVE_ATTACHED); @@ -1011,7 +1009,7 @@ ManagerImpl::joinParticipant(const std::string& callId1, if ((current_call_id != callId1) and (current_call_id != callId2)) { // If currently in a conference if (isConference(current_call_id)) - detachParticipant(ring::RingBufferPool::DEFAULT_ID); + detachParticipant(RingBufferPool::DEFAULT_ID); else onHoldCall(current_call_id); // currently in a call } @@ -1121,7 +1119,7 @@ ManagerImpl::detachParticipant(const std::string& call_id) { const std::string current_call_id(getCurrentCallId()); - if (call_id != ring::RingBufferPool::DEFAULT_ID) { + if (call_id != RingBufferPool::DEFAULT_ID) { auto call = getCallFromCallID(call_id); if (!call) { RING_ERR("Could not find call %s", call_id.c_str()); @@ -1151,7 +1149,7 @@ ManagerImpl::detachParticipant(const std::string& call_id) } else { RING_DBG("Unbind main participant from conference %d"); - getRingBufferPool().unBindAll(ring::RingBufferPool::DEFAULT_ID); + getRingBufferPool().unBindAll(RingBufferPool::DEFAULT_ID); if (not isConference(current_call_id)) { RING_ERR("Current call id (%s) is not a conference", current_call_id.c_str()); @@ -1226,7 +1224,7 @@ ManagerImpl::processRemainingParticipants(Conference &conf) for (const auto &p : participants) getRingBufferPool().flush(p); - getRingBufferPool().flush(ring::RingBufferPool::DEFAULT_ID); + getRingBufferPool().flush(RingBufferPool::DEFAULT_ID); } else if (n == 1) { // this call is the last participant, hence // the conference is over @@ -1292,7 +1290,7 @@ ManagerImpl::addStream(Call& call) RING_DBG("Add stream to call"); // bind to main - getRingBufferPool().bindCallID(call_id, ring::RingBufferPool::DEFAULT_ID); + getRingBufferPool().bindCallID(call_id, RingBufferPool::DEFAULT_ID); std::lock_guard<std::mutex> lock(audioLayerMutex_); if (!audiodriver_) { @@ -1674,7 +1672,7 @@ ManagerImpl::callBusy(Call& call) client_.getCallManager()->callStateChanged(call_id, "BUSY"); if (isCurrentCall(call)) { - playATone(ring::Tone::TONE_BUSY); + playATone(Tone::TONE_BUSY); unsetCurrentCall(); } @@ -2424,8 +2422,8 @@ ManagerImpl::addAccount(const std::map<std::string, std::string>& details) // Get the type const char* accountType; - if (details.find(CONFIG_ACCOUNT_TYPE) != details.end()) - accountType = (*details.find(CONFIG_ACCOUNT_TYPE)).second.c_str(); + if (details.find(Conf::CONFIG_ACCOUNT_TYPE) != details.end()) + accountType = (*details.find(Conf::CONFIG_ACCOUNT_TYPE)).second.c_str(); else accountType = AccountFactory::DEFAULT_ACCOUNT_TYPE; @@ -2434,7 +2432,7 @@ ManagerImpl::addAccount(const std::map<std::string, std::string>& details) auto newAccount = accountFactory_.createAccount(accountType, newAccountID); if (!newAccount) { RING_ERR("Unknown %s param when calling addAccount(): %s", - CONFIG_ACCOUNT_TYPE, accountType); + Conf::CONFIG_ACCOUNT_TYPE, accountType); return ""; } @@ -2503,7 +2501,8 @@ void ManagerImpl::loadAccount(const YAML::Node &node, int &errorCount, const std::string &accountOrder) { - using namespace yaml_utils; + using yaml_utils::parseValue; + std::string accountType; parseValue(node, "type", accountType); @@ -2541,8 +2540,6 @@ ManagerImpl::loadAccount(const YAML::Node &node, int &errorCount, int ManagerImpl::loadAccountMap(const YAML::Node &node) { - using namespace Conf; - accountFactory_.initIP2IPAccount(); // build preferences @@ -2790,3 +2787,5 @@ ManagerImpl::newOutgoingCall(const std::string& id, return account->newOutgoingCall(id, finalToUrl); } + +} // namespace ring diff --git a/daemon/src/managerimpl.h b/daemon/src/managerimpl.h index c93d576f60f5671f684d236e293b26908c0238f1..845492de9685e93e73fe41be04e406346a693aab 100644 --- a/daemon/src/managerimpl.h +++ b/daemon/src/managerimpl.h @@ -63,22 +63,17 @@ #include "history/history.h" #include "noncopyable.h" -namespace Conf { - class YamlParser; - class YamlEmitter; -} - namespace ring { - class AudioFile; - class AudioLayer; - class RingBufferPool; - class DTMF; - class TelephoneTone; - class IceTransportFactory; + +namespace Conf { +class YamlParser; +class YamlEmitter; } class PluginManager; - +class AudioFile; +class DTMF; +class TelephoneTone; /** To send multiple string */ typedef std::list<std::string> TokenList; @@ -148,7 +143,7 @@ class ManagerImpl { * it's multi-thread and use mutex internally * @return AudioLayer* The audio layer object */ - std::shared_ptr<ring::AudioLayer> getAudioDriver(); + std::shared_ptr<AudioLayer> getAudioDriver(); void startAudioDriverStream(); @@ -513,7 +508,7 @@ class ManagerImpl { * @param index The index of the soundcard * @param the type of stream, either PLAYBACK, CAPTURE, RINGTONE */ - void setAudioDevice(int index, ring::DeviceType streamType); + void setAudioDevice(int index, DeviceType streamType); /** * Get list of supported audio output device @@ -657,14 +652,14 @@ class ManagerImpl { * Callback called when the audio layer initialised with its * preferred format. */ - void hardwareAudioFormatChanged(ring::AudioFormat format); + void hardwareAudioFormatChanged(AudioFormat format); /** * Should be called by any component dealing with an external * audio source, indicating the format used so the mixer format * can be eventually adapted. */ - void audioFormatUsed(ring::AudioFormat format); + void audioFormatUsed(AudioFormat format); /** * Handle audio sounds heard by a caller while they wait for their @@ -702,13 +697,13 @@ class ManagerImpl { * Retrieve the current telephone tone * @return AudioLoop* The audio tone or 0 if no tone (init before calling this function) */ - ring::AudioLoop* getTelephoneTone(); + AudioLoop* getTelephoneTone(); /** * Retrieve the current telephone file * @return AudioLoop* The audio file or 0 if the wav is stopped */ - ring::AudioLoop* getTelephoneFile(); + AudioLoop* getTelephoneFile(); /** * @return true is there is one or many incoming call waiting @@ -786,7 +781,7 @@ class ManagerImpl { * Play one tone * @return false if the driver is uninitialize */ - void playATone(ring::Tone::TONEID toneId); + void playATone(Tone::TONEID toneId); Client client_; @@ -797,20 +792,20 @@ class ManagerImpl { std::mutex currentCallMutex_; /** Audio layer */ - std::shared_ptr<ring::AudioLayer> audiodriver_{nullptr}; + std::shared_ptr<AudioLayer> audiodriver_{nullptr}; // Main thread - std::unique_ptr<ring::DTMF> dtmfKey_; + std::unique_ptr<DTMF> dtmfKey_; /** Buffer to generate DTMF */ - ring::AudioBuffer dtmfBuf_; + AudioBuffer dtmfBuf_; ///////////////////// // Protected by Mutex ///////////////////// std::mutex toneMutex_; - std::unique_ptr<ring::TelephoneTone> telephoneTone_; - std::unique_ptr<ring::AudioFile> audiofile_; + std::unique_ptr<TelephoneTone> telephoneTone_; + std::unique_ptr<AudioFile> audiofile_; // To handle volume control // short speakerVolume_; @@ -861,14 +856,14 @@ class ManagerImpl { * Audio instances must be registered into the RingBufferMananger and bound together via the ManagerImpl. * */ - std::unique_ptr<ring::RingBufferPool> ringbufferpool_; + std::unique_ptr<RingBufferPool> ringbufferpool_; public: /** * Return a pointer to the instance of the RingBufferPool */ - ring::RingBufferPool& getRingBufferPool() { return *ringbufferpool_; } + RingBufferPool& getRingBufferPool() { return *ringbufferpool_; } /** * Tell if there is a current call processed @@ -967,7 +962,7 @@ class ManagerImpl { */ void unregisterEventHandler(uintptr_t handlerId); - ring::IceTransportFactory& getIceTransportFactory() { return *ice_tf_; } + IceTransportFactory& getIceTransportFactory() { return *ice_tf_; } private: NON_COPYABLE(ManagerImpl); @@ -995,7 +990,7 @@ class ManagerImpl { * To handle the persistent history * TODO: move this to ConfigurationManager */ - ring::History history_; + History history_; bool finished_; AccountFactory accountFactory_; @@ -1008,7 +1003,9 @@ class ManagerImpl { const std::string &accountOrder); /* ICE support */ - std::unique_ptr<ring::IceTransportFactory> ice_tf_; + std::unique_ptr<IceTransportFactory> ice_tf_; }; +} // namespace ring + #endif // MANAGER_IMPL_H_ diff --git a/daemon/src/map_utils.h b/daemon/src/map_utils.h index 98046b836228dd484aa5beff3e8fac2bbac635e5..11f816b1c1e7dcd06d1b57e7565d8d2febaf2a10 100644 --- a/daemon/src/map_utils.h +++ b/daemon/src/map_utils.h @@ -34,7 +34,7 @@ #include <vector> #include <map> -namespace map_utils { +namespace ring { namespace map_utils { template <typename M, typename V> void vectorFromMapKeys(const M &m, V &v) @@ -59,6 +59,6 @@ findByValue(const M &m, V &v) { return m.cend(); } -} +}} // namespace ring::map_utils #endif // MAP_UTILS_H_ diff --git a/daemon/src/media/audio/alsa/alsalayer.cpp b/daemon/src/media/audio/alsa/alsalayer.cpp index de89cfbf9c18d0830c3d1cbe6132e2b5e3768c98..e8c885aecd22ff810cbe2d2cf8e10d3e1a009f1f 100644 --- a/daemon/src/media/audio/alsa/alsalayer.cpp +++ b/daemon/src/media/audio/alsa/alsalayer.cpp @@ -412,7 +412,7 @@ bool AlsaLayer::alsa_set_params(snd_pcm_t *pcm_handle) // TODO first frame causes broken pipe (underrun) because not enough data is sent // we should wait until the handle is ready void -AlsaLayer::write(ring::AudioSample* buffer, int frames, snd_pcm_t * handle) +AlsaLayer::write(AudioSample* buffer, int frames, snd_pcm_t * handle) { // Skip empty buffers if (!frames) @@ -473,7 +473,7 @@ AlsaLayer::write(ring::AudioSample* buffer, int frames, snd_pcm_t * handle) } int -AlsaLayer::read(ring::AudioSample* buffer, int frames) +AlsaLayer::read(AudioSample* buffer, int frames) { if (snd_pcm_state(captureHandle_) == SND_PCM_STATE_XRUN) { prepareCaptureStream(); @@ -851,4 +851,4 @@ void AlsaLayer::updatePreference(AudioPreference &preference, int index, DeviceT } } -} +} // namespace ring diff --git a/daemon/src/media/audio/alsa/alsalayer.h b/daemon/src/media/audio/alsa/alsalayer.h index b4fc42d11e08c76ca512cb019811e0d556e94bca..f1a64c3d2c532280c7e03bccc0adec419f9285ad 100644 --- a/daemon/src/media/audio/alsa/alsalayer.h +++ b/daemon/src/media/audio/alsa/alsalayer.h @@ -55,6 +55,7 @@ namespace ring { class AlsaThread; class RingBuffer; +class AudioPreference; /** Associate a sound card index to its string description */ typedef std::pair<int , std::string> HwIDPair; @@ -205,7 +206,7 @@ class AlsaLayer : public AudioLayer { * @param buffer The non-interleaved data to be copied * @param frames Frames in the buffer */ - void write(ring::AudioSample* buffer, int frames, snd_pcm_t *handle); + void write(AudioSample* buffer, int frames, snd_pcm_t *handle); /** * Read data from the internal ring buffer @@ -214,7 +215,7 @@ class AlsaLayer : public AudioLayer { * @param frames The number of frames to get * @return int The number of frames actually read */ - int read(ring::AudioSample* buffer, int frames); + int read(AudioSample* buffer, int frames); virtual void updatePreference(AudioPreference &pref, int index, DeviceType type); @@ -249,8 +250,8 @@ class AlsaLayer : public AudioLayer { AudioBuffer captureBuff_; /** Interleaved buffer */ - std::vector<ring::AudioSample> playbackIBuff_; - std::vector<ring::AudioSample> captureIBuff_; + std::vector<AudioSample> playbackIBuff_; + std::vector<AudioSample> captureIBuff_; bool is_playback_prepared_; bool is_capture_prepared_; @@ -263,6 +264,6 @@ class AlsaLayer : public AudioLayer { std::shared_ptr<RingBuffer> mainRingBuffer_; }; -} +} // namespace ring #endif // ALSA_LAYER_H_ diff --git a/daemon/src/media/audio/audiobuffer.cpp b/daemon/src/media/audio/audiobuffer.cpp index 5310536e9e0682cc06bd1cb07f34f8a4519f804b..c691572546f76a337f9e2f5ca8274774bc04d827 100644 --- a/daemon/src/media/audio/audiobuffer.cpp +++ b/daemon/src/media/audio/audiobuffer.cpp @@ -41,13 +41,13 @@ std::ostream& operator <<(std::ostream& stream, const AudioFormat& f) { AudioBuffer::AudioBuffer(size_t sample_num, AudioFormat format) : sampleRate_(format.sample_rate), samples_(std::max(1U, format.nb_channels), - std::vector<ring::AudioSample>(sample_num, 0)) + std::vector<AudioSample>(sample_num, 0)) { } -AudioBuffer::AudioBuffer(const ring::AudioSample* in, size_t sample_num, AudioFormat format) +AudioBuffer::AudioBuffer(const AudioSample* in, size_t sample_num, AudioFormat format) : sampleRate_(format.sample_rate), - samples_((std::max(1U, format.nb_channels)), std::vector<ring::AudioSample>(sample_num, 0)) + samples_((std::max(1U, format.nb_channels)), std::vector<AudioSample>(sample_num, 0)) { deinterleave(in, sample_num, format.nb_channels); } @@ -55,7 +55,7 @@ AudioBuffer::AudioBuffer(const ring::AudioSample* in, size_t sample_num, AudioFo AudioBuffer::AudioBuffer(const AudioBuffer& other, bool copy_content /* = false */) : sampleRate_(other.sampleRate_), samples_(copy_content ? other.samples_ : - std::vector<std::vector<ring::AudioSample> >(other.samples_.size(), std::vector<ring::AudioSample>(other.frames()))) + std::vector<std::vector<AudioSample> >(other.samples_.size(), std::vector<AudioSample>(other.frames()))) {} AudioBuffer& AudioBuffer::operator=(const AudioBuffer& other) { @@ -92,14 +92,14 @@ void AudioBuffer::setChannelNum(unsigned n, bool mix /* = false */) if (n < c) samples_.resize(n); else - samples_.resize(n, std::vector<ring::AudioSample>(frames(), 0)); + samples_.resize(n, std::vector<AudioSample>(frames(), 0)); return; } // 2ch->1ch if (n == 1) { - std::vector<ring::AudioSample>& chan1 = samples_[0]; - std::vector<ring::AudioSample>& chan2 = samples_[1]; + std::vector<AudioSample>& chan1 = samples_[0]; + std::vector<AudioSample>& chan2 = samples_[1]; for (unsigned i = 0, f = frames(); i < f; i++) chan1[i] = chan1[i] / 2 + chan2[i] / 2; samples_.resize(1); @@ -132,7 +132,7 @@ void AudioBuffer::resize(size_t sample_num) s.resize(sample_num, 0); } -std::vector<ring::AudioSample> * AudioBuffer::getChannel(unsigned chan /* = 0 */) +std::vector<AudioSample> * AudioBuffer::getChannel(unsigned chan /* = 0 */) { if (chan < samples_.size()) return &samples_[chan]; @@ -163,7 +163,7 @@ size_t AudioBuffer::channelToFloat(float* out, const int& channel) const return frames() * samples_.size(); } -size_t AudioBuffer::interleave(ring::AudioSample* out) const +size_t AudioBuffer::interleave(AudioSample* out) const { for (unsigned i=0, f=frames(), c=channels(); i < f; ++i) for (unsigned j = 0; j < c; ++j) @@ -172,15 +172,15 @@ size_t AudioBuffer::interleave(ring::AudioSample* out) const return frames() * channels(); } -size_t AudioBuffer::interleave(std::vector<ring::AudioSample>& out) const +size_t AudioBuffer::interleave(std::vector<AudioSample>& out) const { out.resize(capacity()); return interleave(out.data()); } -std::vector<ring::AudioSample> AudioBuffer::interleave() const +std::vector<AudioSample> AudioBuffer::interleave() const { - std::vector<ring::AudioSample> data(capacity()); + std::vector<AudioSample> data(capacity()); interleave(data.data()); return data; } @@ -194,7 +194,7 @@ size_t AudioBuffer::interleaveFloat(float* out) const return frames() * samples_.size(); } -void AudioBuffer::deinterleave(const ring::AudioSample* in, size_t frame_num, unsigned nb_channels) +void AudioBuffer::deinterleave(const AudioSample* in, size_t frame_num, unsigned nb_channels) { if (in == nullptr) return; @@ -208,7 +208,7 @@ void AudioBuffer::deinterleave(const ring::AudioSample* in, size_t frame_num, un samples_[j][i] = *in++; } -void AudioBuffer::deinterleave(const std::vector<ring::AudioSample>& in, AudioFormat format) +void AudioBuffer::deinterleave(const std::vector<AudioSample>& in, AudioFormat format) { sampleRate_ = format.sample_rate; deinterleave(in.data(), in.size()/format.nb_channels, format.nb_channels); @@ -275,7 +275,7 @@ size_t AudioBuffer::copy(AudioBuffer& in, int sample_num /* = -1 */, size_t pos_ return to_copy; } -size_t AudioBuffer::copy(ring::AudioSample* in, size_t sample_num, size_t pos_out /* = 0 */) +size_t AudioBuffer::copy(AudioSample* in, size_t sample_num, size_t pos_out /* = 0 */) { if (in == nullptr || sample_num == 0) return 0; @@ -289,4 +289,4 @@ size_t AudioBuffer::copy(ring::AudioSample* in, size_t sample_num, size_t pos_ou return sample_num; } -} +} // namespace ring diff --git a/daemon/src/media/audio/audiobuffer.h b/daemon/src/media/audio/audiobuffer.h index fffd5c2c7e3deebda5f45c7c32853812865efb72..a8ef5c7048d5d1279c4b891dad497f1ff94abdc1 100644 --- a/daemon/src/media/audio/audiobuffer.h +++ b/daemon/src/media/audio/audiobuffer.h @@ -67,7 +67,7 @@ struct AudioFormat { * Returns bytes necessary to hold one frame of audio data. */ inline size_t getBytesPerFrame() const { - return sizeof(ring::AudioSample)*nb_channels; + return sizeof(AudioSample)*nb_channels; } /** @@ -96,7 +96,7 @@ class AudioBuffer { /** * Construtor from existing interleaved data (copied into the buffer). */ - AudioBuffer(const ring::AudioSample* in, size_t sample_num, AudioFormat format); + AudioBuffer(const AudioSample* in, size_t sample_num, AudioFormat format); /** * Copy constructor that by default only copies the buffer parameters (channel number, sample rate and buffer size). @@ -129,7 +129,7 @@ class AudioBuffer { } inline size_t size() const { - return frames() * channels() * sizeof(ring::AudioSample); + return frames() * channels() * sizeof(AudioSample); } /** @@ -217,12 +217,12 @@ class AudioBuffer { * Return the data (audio samples) for a given channel number. * Channel data can be modified but size of individual channel vectors should not be changed by the user. */ - std::vector<ring::AudioSample> *getChannel(unsigned chan); + std::vector<AudioSample> *getChannel(unsigned chan); /** * Return a pointer to the raw data in this buffer. */ - inline std::vector<std::vector<ring::AudioSample> > &getData() { + inline std::vector<std::vector<AudioSample> > &getData() { return samples_; } @@ -231,9 +231,9 @@ class AudioBuffer { * Caller should not store result because pointer validity is * limited in time. */ - inline const std::vector<ring::AudioSample*> getDataRaw() { + inline const std::vector<AudioSample*> getDataRaw() { const unsigned chans = samples_.size(); - std::vector<ring::AudioSample*> raw_data(chans, nullptr); + std::vector<AudioSample*> raw_data(chans, nullptr); for(unsigned i=0; i<chans; i++) raw_data[i] = samples_[i].data(); return raw_data; @@ -249,11 +249,11 @@ class AudioBuffer { /** * Write interleaved multichannel data to the out buffer (fixed-point 16-bits). - * The out buffer must be at least of size capacity()*sizeof(ring::AudioSample) bytes. + * The out buffer must be at least of size capacity()*sizeof(AudioSample) bytes. * * @returns Number of samples writen. */ - size_t interleave(ring::AudioSample* out) const; + size_t interleave(AudioSample* out) const; /** * Write interleaved multichannel data to the out buffer (fixed-point 16-bits). @@ -261,12 +261,12 @@ class AudioBuffer { * * @returns Number of samples writen. */ - size_t interleave(std::vector<ring::AudioSample>& out) const; + size_t interleave(std::vector<AudioSample>& out) const; /** * Returns vector of interleaved data (fixed-point 16-bits). */ - std::vector<ring::AudioSample> interleave() const; + std::vector<AudioSample> interleave() const; /** * Write interleaved multichannel data to the out buffer, while samples are converted to float. @@ -280,13 +280,13 @@ class AudioBuffer { * Import interleaved multichannel data. Internal buffer is resized as needed. * Function will read sample_num*channel_num elements of the in buffer. */ - void deinterleave(const ring::AudioSample* in, size_t frame_num, unsigned nb_channels = 1); + void deinterleave(const AudioSample* in, size_t frame_num, unsigned nb_channels = 1); /** * Import interleaved multichannel data. Internal buffer is resized as needed. * Sample rate is set according to format. */ - void deinterleave(const std::vector<ring::AudioSample>& in, AudioFormat format); + void deinterleave(const std::vector<AudioSample>& in, AudioFormat format); /** * convert float planar data to signed 16 @@ -331,15 +331,15 @@ class AudioBuffer { * * Buffer sample number is increased if required to hold the new requested samples. */ - size_t copy(ring::AudioSample* in, size_t sample_num, size_t pos_out = 0); + size_t copy(AudioSample* in, size_t sample_num, size_t pos_out = 0); private: int sampleRate_; // buffers holding data for each channels - std::vector<std::vector<ring::AudioSample> > samples_; + std::vector<std::vector<AudioSample> > samples_; }; -} +} // namespace ring #endif // _AUDIO_BUFFER_H diff --git a/daemon/src/media/audio/audiolayer.cpp b/daemon/src/media/audio/audiolayer.cpp index e92be981e8c2054693a7509a613805af4e9910fb..30411a5573322bd06b6b163757d25c3f841737f1 100644 --- a/daemon/src/media/audio/audiolayer.cpp +++ b/daemon/src/media/audio/audiolayer.cpp @@ -122,4 +122,4 @@ void AudioLayer::notifyIncomingCall() putUrgent(buf); } -} +} // namespace ring diff --git a/daemon/src/media/audio/audiolayer.h b/daemon/src/media/audio/audiolayer.h index 98afab5695e5256801cf4792b88e1c296a34b1f6..dd448a3e6cf04a1ec71e685cfb34c16e5bda79f0 100644 --- a/daemon/src/media/audio/audiolayer.h +++ b/daemon/src/media/audio/audiolayer.h @@ -58,10 +58,9 @@ #define PCM_DSNOOP "plug:dsnoop" // Alsa plugin for microphone sharing #define PCM_DMIX_DSNOOP "dmix/dsnoop" // Audio profile using Alsa dmix/dsnoop -class AudioPreference; - namespace ring { +class AudioPreference; class Resampler; enum class DeviceType { @@ -281,6 +280,6 @@ class AudioLayer { time_t lastNotificationTime_; }; -} +} // namespace ring #endif // _AUDIO_LAYER_H_ diff --git a/daemon/src/media/audio/audioloop.cpp b/daemon/src/media/audio/audioloop.cpp index bbf6ff1f11662c64dfa37e137580ad6077550332..8a181791ae6b0ab5ad2f55af8dc6ee20b8ce082c 100644 --- a/daemon/src/media/audio/audioloop.cpp +++ b/daemon/src/media/audio/audioloop.cpp @@ -99,4 +99,4 @@ AudioLoop::getNext(AudioBuffer& output, double gain) void AudioLoop::onBufferFinish() {} -} +} // namespace ring diff --git a/daemon/src/media/audio/audioloop.h b/daemon/src/media/audio/audioloop.h index e97c10ba1ba6ec6f24d93d6d3b3b3b6460b59e95..e4087df2d948a9dc085a01f214be254764ecce80 100644 --- a/daemon/src/media/audio/audioloop.h +++ b/daemon/src/media/audio/audioloop.h @@ -88,6 +88,6 @@ class AudioLoop { virtual void onBufferFinish(); }; -} +} // namespace ring #endif // __AUDIOLOOP_H__ diff --git a/daemon/src/media/audio/audiorecord.cpp b/daemon/src/media/audio/audiorecord.cpp index 91d98a4110026f4dc98343bb489a8ddf412cda2b..c1ed7f263a6dce91787503112e360019c0354e32 100644 --- a/daemon/src/media/audio/audiorecord.cpp +++ b/daemon/src/media/audio/audiorecord.cpp @@ -238,4 +238,4 @@ void AudioRecord::recData(AudioBuffer& buffer) } } -} +} // namespace ring diff --git a/daemon/src/media/audio/audiorecord.h b/daemon/src/media/audio/audiorecord.h index 4c08bebbea064fbecc83d89494f823e5f5d02408..d60b6639405397e8cce1159ee79cad92e65c5095 100644 --- a/daemon/src/media/audio/audiorecord.h +++ b/daemon/src/media/audio/audiorecord.h @@ -154,6 +154,6 @@ class AudioRecord { NON_COPYABLE(AudioRecord); }; -} +} // namespace ring #endif // _AUDIO_RECORD_H diff --git a/daemon/src/media/audio/audiorecorder.cpp b/daemon/src/media/audio/audiorecorder.cpp index 9d9e934bef1cd58976c029fe8527f698de28b2ce..2e1600bce11c405879a8b6c197dc9949b0d86641 100644 --- a/daemon/src/media/audio/audiorecorder.cpp +++ b/daemon/src/media/audio/audiorecorder.cpp @@ -101,4 +101,4 @@ void AudioRecorder::run() } } -} +} // namespace ring diff --git a/daemon/src/media/audio/audiorecorder.h b/daemon/src/media/audio/audiorecorder.h index 96cf7329236f37674c44b1269e6aec771daad541..8766119a838e20920317401d142309ab1198fed1 100644 --- a/daemon/src/media/audio/audiorecorder.h +++ b/daemon/src/media/audio/audiorecorder.h @@ -74,6 +74,6 @@ class AudioRecorder { std::thread thread_; }; -} +} // namespace ring #endif diff --git a/daemon/src/media/audio/audiortp/avformat_rtp_session.cpp b/daemon/src/media/audio/audiortp/avformat_rtp_session.cpp index 3f26ef5f405bd22d055c0882d2b593b43e9fafae..61173f2167a6235125e6eea643c81240bc2d6047 100644 --- a/daemon/src/media/audio/audiortp/avformat_rtp_session.cpp +++ b/daemon/src/media/audio/audiortp/avformat_rtp_session.cpp @@ -50,11 +50,6 @@ namespace ring { -using ring::MediaEncoder; -using ring::MediaDecoder; -using ring::MediaEncoderException; -using ring::MediaIOHandle; - class AudioSender { public: AudioSender(const std::string& id, @@ -71,9 +66,9 @@ class AudioSender { std::string id_; std::map<std::string, std::string> args_; const AudioFormat format_; - std::unique_ptr<ring::MediaEncoder> audioEncoder_; - std::unique_ptr<ring::MediaIOHandle> muxContext_; - std::unique_ptr<ring::Resampler> resampler_; + std::unique_ptr<MediaEncoder> audioEncoder_; + std::unique_ptr<MediaIOHandle> muxContext_; + std::unique_ptr<Resampler> resampler_; const double secondsPerPacket_ {0.02}; // 20 ms ThreadLoop loop_; @@ -217,11 +212,11 @@ class AudioReceiveThread /*-----------------------------------------------------------------*/ const std::string id_; std::istringstream stream_; - std::unique_ptr<ring::MediaDecoder> audioDecoder_; - std::unique_ptr<ring::MediaIOHandle> sdpContext_; - std::unique_ptr<ring::MediaIOHandle> demuxContext_; + std::unique_ptr<MediaDecoder> audioDecoder_; + std::unique_ptr<MediaIOHandle> sdpContext_; + std::unique_ptr<MediaIOHandle> demuxContext_; - std::shared_ptr<ring::RingBuffer> ringbuffer_; + std::shared_ptr<RingBuffer> ringbuffer_; ThreadLoop loop_; bool setup(); @@ -247,7 +242,7 @@ AudioReceiveThread::~AudioReceiveThread() bool AudioReceiveThread::setup() { - audioDecoder_.reset(new ring::MediaDecoder()); + audioDecoder_.reset(new MediaDecoder()); audioDecoder_->setInterruptCallback(interruptCb, this); // custom_io so the SDP demuxer will not open any UDP connections args_["sdp_flags"] = "custom_io"; @@ -269,17 +264,17 @@ AudioReceiveThread::setup() void AudioReceiveThread::process() { - ring::AudioFormat mainBuffFormat = Manager::instance().getRingBufferPool().getInternalAudioFormat(); + AudioFormat mainBuffFormat = Manager::instance().getRingBufferPool().getInternalAudioFormat(); std::unique_ptr<AVFrame, void(*)(AVFrame*)> decodedFrame(av_frame_alloc(), [](AVFrame*p){av_frame_free(&p);}); switch (audioDecoder_->decode_audio(decodedFrame.get())) { - case ring::MediaDecoder::Status::FrameFinished: + case MediaDecoder::Status::FrameFinished: audioDecoder_->writeToRingBuffer(decodedFrame.get(), *ringbuffer_, mainBuffFormat); return; - case ring::MediaDecoder::Status::DecodeError: + case MediaDecoder::Status::DecodeError: RING_WARN("decoding failure, trying to reset decoder..."); if (not setup()) { RING_ERR("fatal error, rx thread re-setup failed"); @@ -293,7 +288,7 @@ AudioReceiveThread::process() } break; - case ring::MediaDecoder::Status::ReadError: + case MediaDecoder::Status::ReadError: RING_ERR("fatal error, read failed"); loop_.stop(); break; @@ -509,4 +504,4 @@ AVFormatRtpSession::stop() socketPair_.reset(); } -} // end namespace ring +} // namespace ring diff --git a/daemon/src/media/audio/audiortp/avformat_rtp_session.h b/daemon/src/media/audio/audiortp/avformat_rtp_session.h index a8c56c417abc1f6be2467e14408a4956776c6acb..03e9d4475bf59673603a80dab8bfcaf9503cae5b 100644 --- a/daemon/src/media/audio/audiortp/avformat_rtp_session.h +++ b/daemon/src/media/audio/audiortp/avformat_rtp_session.h @@ -40,12 +40,11 @@ #include <memory> #include <mutex> +namespace ring { + class Sdp; class ThreadLoop; class MediaEncoder; - -namespace ring { - class SocketPair; class RingBuffer; class Resampler; @@ -75,15 +74,15 @@ class AVFormatRtpSession { std::string id_; std::map<std::string, std::string> txArgs_; std::string receivingSDP_; - std::unique_ptr<ring::SocketPair> socketPair_; + std::unique_ptr<SocketPair> socketPair_; std::unique_ptr<AudioSender> sender_; std::unique_ptr<AudioReceiveThread> receiveThread_; - std::shared_ptr<ring::RingBuffer> ringbuffer_; + std::shared_ptr<RingBuffer> ringbuffer_; std::recursive_mutex mutex_; bool sending_; bool receiving_; }; -} +} // namespace ring #endif // __AVFORMAT_RTP_SESSION_H__ diff --git a/daemon/src/media/audio/codecs/audiocodec.cpp b/daemon/src/media/audio/codecs/audiocodec.cpp index f8de110ff397ac859d4f5d92764faa53599a40ab..0ba8676b1123e9356f38e443cacc74186c9b55eb 100644 --- a/daemon/src/media/audio/codecs/audiocodec.cpp +++ b/daemon/src/media/audio/codecs/audiocodec.cpp @@ -32,10 +32,11 @@ #include "audiocodec.h" #include <cassert> -using std::ptrdiff_t; namespace ring { +using std::ptrdiff_t; + AudioCodec::AudioCodec(uint8_t payload, const std::string &codecName, uint32_t clockRate, unsigned frameSize, uint8_t channels) : codecName_(codecName), clockRate_(clockRate), @@ -60,14 +61,14 @@ AudioCodec::AudioCodec(const AudioCodec& c) : hasDynamicPayload_(c.hasDynamicPayload_) {} -int AudioCodec::decode(ring::AudioSample *, unsigned char *, size_t) +int AudioCodec::decode(AudioSample *, unsigned char *, size_t) { // Unimplemented! assert(false); return 0; } -int AudioCodec::encode(unsigned char *, ring::AudioSample *, size_t) +int AudioCodec::encode(unsigned char *, AudioSample *, size_t) { // Unimplemented! assert(false); @@ -76,18 +77,18 @@ int AudioCodec::encode(unsigned char *, ring::AudioSample *, size_t) // Mono only, subclasses must implement multichannel support -int AudioCodec::decode(std::vector<std::vector<ring::AudioSample> > &pcm, const uint8_t* data, size_t len) +int AudioCodec::decode(std::vector<std::vector<AudioSample> > &pcm, const uint8_t* data, size_t len) { return decode(pcm[0].data(), const_cast<uint8_t*>(data), len); } // Mono only, subclasses must implement multichannel support -size_t AudioCodec::encode(const std::vector<std::vector<ring::AudioSample> > &pcm, uint8_t *data, size_t len) +size_t AudioCodec::encode(const std::vector<std::vector<AudioSample> > &pcm, uint8_t *data, size_t len) { - return encode(data, const_cast<ring::AudioSample*>(pcm[0].data()), len); + return encode(data, const_cast<AudioSample*>(pcm[0].data()), len); } -int AudioCodec::decode(std::vector<std::vector<ring::AudioSample> > &pcm) +int AudioCodec::decode(std::vector<std::vector<AudioSample> > &pcm) { pcm.clear(); return frameSize_; @@ -149,4 +150,4 @@ AudioCodec::getSDPChannels() const return ""; } -} // end namespace ring +} // namespace ring diff --git a/daemon/src/media/audio/codecs/audiocodec.h b/daemon/src/media/audio/codecs/audiocodec.h index 468aa206cf690518c27c17a78c97e6dbbd5448a3..b012e7faa71795c7f3399d890ac84c03f5272c5c 100644 --- a/daemon/src/media/audio/codecs/audiocodec.h +++ b/daemon/src/media/audio/codecs/audiocodec.h @@ -63,20 +63,20 @@ class AudioCodec { * Multichannel version of decode(). * Default implementation calls mono version */ - virtual int decode(std::vector<std::vector<ring::AudioSample> > &pcm, const uint8_t* data, size_t len); + virtual int decode(std::vector<std::vector<AudioSample> > &pcm, const uint8_t* data, size_t len); /** * Inform the codec of a lost packet and perform packet loss concealment. * Default implementation fills dst with 0. */ - virtual int decode(std::vector<std::vector<ring::AudioSample> > &pcm); + virtual int decode(std::vector<std::vector<AudioSample> > &pcm); /** * Multichannel version of encode(). * Default implementation calls encode() on the first channel (assume 1 channel). * @return the number of bytes encoded */ - virtual size_t encode(const std::vector<std::vector<ring::AudioSample> > &pcm, uint8_t *data, size_t len); + virtual size_t encode(const std::vector<std::vector<AudioSample> > &pcm, uint8_t *data, size_t len); uint8_t getPayloadType() const; @@ -157,7 +157,7 @@ class AudioCodec { * @param len: length of input buffer * @return the number of samples decoded */ - virtual int decode(ring::AudioSample *pcm, unsigned char *data, size_t len); + virtual int decode(AudioSample *pcm, unsigned char *data, size_t len); /** * Encode an input buffer and fill the output buffer with the encoded data @@ -166,7 +166,7 @@ class AudioCodec { * @param max_data_bytes: the maximum size of the encoded data buffer (data) * @return the number of bytes encoded */ - virtual int encode(unsigned char *data, ring::AudioSample *pcm, size_t max_data_bytes); + virtual int encode(unsigned char *data, AudioSample *pcm, size_t max_data_bytes); /** Holds SDP-compliant codec name */ std::string codecName_; // what we put inside sdp @@ -190,8 +190,6 @@ class AudioCodec { AudioCodec& operator=(const AudioCodec&); }; -} // end namespace ring - /** Enumeration that contains known audio payloads */ enum { @@ -218,4 +216,6 @@ enum { PAYLOAD_CODEC_SPEEX_32000 = 112 }; +} // namespace ring + #endif diff --git a/daemon/src/media/audio/codecs/audiocodecfactory.cpp b/daemon/src/media/audio/codecs/audiocodecfactory.cpp index 003a2bc135cd566769271e0d91e9a8ef35c60003..68c5b57faf04d7ffb0615f10831c421262119758 100644 --- a/daemon/src/media/audio/codecs/audiocodecfactory.cpp +++ b/daemon/src/media/audio/codecs/audiocodecfactory.cpp @@ -51,6 +51,8 @@ #include <stdexcept> #include <sstream> +namespace ring { + AudioCodecFactory::AudioCodecFactory(PluginManager& pluginManager) : pluginManager_(pluginManager) { @@ -58,7 +60,7 @@ AudioCodecFactory::AudioCodecFactory(PluginManager& pluginManager) * with our C++ binding by providing 'this' access. */ const auto callback = [this](void* data) { - if (auto codec = reinterpret_cast<ring::AudioCodec*>(data)) { + if (auto codec = reinterpret_cast<AudioCodec*>(data)) { this->registerAudioCodec(codec); return 0; } @@ -78,9 +80,9 @@ AudioCodecFactory::~AudioCodecFactory() } void -AudioCodecFactory::registerAudioCodec(ring::AudioCodec* codec) +AudioCodecFactory::registerAudioCodec(AudioCodec* codec) { - codecsMap_[(int) codec->getPayloadType()] = std::shared_ptr<ring::AudioCodec>(codec); + codecsMap_[(int) codec->getPayloadType()] = std::shared_ptr<AudioCodec>(codec); RING_DBG("Loaded codec %s" , codec->getMimeSubtype().c_str()); } @@ -114,7 +116,7 @@ AudioCodecFactory::getCodecList() const return list; } -std::shared_ptr<ring::AudioCodec> +std::shared_ptr<AudioCodec> AudioCodecFactory::getCodec(int payload) const { const auto iter = codecsMap_.find(payload); @@ -124,7 +126,7 @@ AudioCodecFactory::getCodec(int payload) const return nullptr; } -std::shared_ptr<ring::AudioCodec> +std::shared_ptr<AudioCodec> AudioCodecFactory::getCodec(const std::string &name) const { for (const auto& item : codecsMap_) { @@ -236,7 +238,7 @@ AudioCodecFactory::scanCodecDirectory() } } -ring::AudioCodec* +AudioCodec* AudioCodecFactory::instantiateCodec(int payload) const { for (const auto& item : codecsMap_) { @@ -332,3 +334,5 @@ AudioCodecFactory::getCodecSpecifications(const int32_t& payload) const return v; } + +} // namespace ring diff --git a/daemon/src/media/audio/codecs/audiocodecfactory.h b/daemon/src/media/audio/codecs/audiocodecfactory.h index af3bac2606e276641ce5afe8db5b3288a4ba5a7a..e2da6ae48d3bf73d7356bbaa54ec84e97f72ef82 100644 --- a/daemon/src/media/audio/codecs/audiocodecfactory.h +++ b/daemon/src/media/audio/codecs/audiocodecfactory.h @@ -38,6 +38,8 @@ #include <map> #include <vector> +namespace ring { + class PluginManager; /* @@ -67,14 +69,14 @@ class AudioCodecFactory { * @param payload The payload looked for * @return A shared pointer on a AudioCodec object */ - std::shared_ptr<ring::AudioCodec> getCodec(int payload) const; + std::shared_ptr<AudioCodec> getCodec(int payload) const; /** * Get the codec object associated with the codec attribute * @param string The name to compare, should be in the form speex/16000 * @return A shared pointer to an AudioCodec object */ - std::shared_ptr<ring::AudioCodec> getCodec(const std::string &name) const; + std::shared_ptr<AudioCodec> getCodec(const std::string &name) const; /** * Set the default codecs order. @@ -113,7 +115,7 @@ class AudioCodecFactory { * Instantiate a codec, used in AudioRTP to get an instance of Codec per call * @param CodecHandlePointer The map containing the pointer on the object and the pointer on the handle function */ - ring::AudioCodec* instantiateCodec(int payload) const; + AudioCodec* instantiateCodec(int payload) const; /** * For a given codec, return its specification @@ -135,7 +137,7 @@ class AudioCodecFactory { PluginManager& pluginManager_; /** Maps a pointer on an audiocodec object to a payload */ - typedef std::map<Id, std::shared_ptr<ring::AudioCodec>> AudioCodecsMap; + typedef std::map<Id, std::shared_ptr<AudioCodec>> AudioCodecsMap; /** * Scan the installation directory ( --prefix configure option ) @@ -147,7 +149,7 @@ class AudioCodecFactory { * Add a new audiocodec to the system. * @note Steals the ownership on given codec. */ - void registerAudioCodec(ring::AudioCodec* codec); + void registerAudioCodec(AudioCodec* codec); /** * Check if the files found in searched directories seems valid @@ -169,4 +171,6 @@ class AudioCodecFactory { std::vector<int> defaultCodecList_ {}; }; +} // namespace ring + #endif // __CODEC_DESCRIPTOR_H__ diff --git a/daemon/src/media/audio/codecs/speexcodec.h b/daemon/src/media/audio/codecs/speexcodec.h index 3b70170ea4a9e0428a58de1d2bda4c847d3eb491..ba3cf8254be4c3741688de6961680fe1c0849586 100644 --- a/daemon/src/media/audio/codecs/speexcodec.h +++ b/daemon/src/media/audio/codecs/speexcodec.h @@ -48,9 +48,9 @@ public: speex_frame_size_(0), mode_(mode) { assert(payload >= 110 && payload <= 112); - assert(110 == PAYLOAD_CODEC_SPEEX_8000 && - 111 == PAYLOAD_CODEC_SPEEX_16000 && - 112 == PAYLOAD_CODEC_SPEEX_32000); + assert(110 == ring::PAYLOAD_CODEC_SPEEX_8000 && + 111 == ring::PAYLOAD_CODEC_SPEEX_16000 && + 112 == ring::PAYLOAD_CODEC_SPEEX_32000); bitrate_ = bitRate; hasDynamicPayload_ = dynamicPayload; diff --git a/daemon/src/media/audio/coreaudio/audiodevice.cpp b/daemon/src/media/audio/coreaudio/audiodevice.cpp index aed4e1ede85b1fa7c902a14e4b64d2d2406ea13f..591154b56a7e4c52d8a5fd25634b7a2809772384 100644 --- a/daemon/src/media/audio/coreaudio/audiodevice.cpp +++ b/daemon/src/media/audio/coreaudio/audiodevice.cpp @@ -177,4 +177,4 @@ std::string AudioDevice::getName() const return buf; } -} +} // namespace ring diff --git a/daemon/src/media/audio/coreaudio/corelayer.cpp b/daemon/src/media/audio/coreaudio/corelayer.cpp index 5cbcf25a843dc51c2f76e0ccc87c89910922fdfc..71fd296943c02b544342b20916a334ffcbc8872e 100644 --- a/daemon/src/media/audio/coreaudio/corelayer.cpp +++ b/daemon/src/media/audio/coreaudio/corelayer.cpp @@ -497,7 +497,7 @@ void CoreLayer::read(AudioUnitRenderActionFlags* ioActionFlags, for (int i = 0; i < info.mChannelsPerFrame; ++i) { Float32* data = (Float32*)captureBuff_->mBuffers[i].mData; for (int j = 0; j < inNumberFrames; ++j) { - (*inBuff.getChannel(i))[j] = (ring::AudioSample)((data)[j] / .000030517578125f); + (*inBuff.getChannel(i))[j] = (AudioSample)((data)[j] / .000030517578125f); } } @@ -577,4 +577,4 @@ std::vector<AudioDevice> CoreLayer::getDeviceList(bool getCapture) const return ret; } -} +} // namespace ring diff --git a/daemon/src/media/audio/coreaudio/corelayer.h b/daemon/src/media/audio/coreaudio/corelayer.h index 51ff8be4db889b0230073e114825dc46ea1d93df..d5b39493b8dd235492f7f8acb54e9bcc68f62933 100644 --- a/daemon/src/media/audio/coreaudio/corelayer.h +++ b/daemon/src/media/audio/coreaudio/corelayer.h @@ -171,8 +171,8 @@ class CoreLayer : public AudioLayer { ::AudioBufferList* captureBuff_; // CoreAudio buffer. /** Interleaved buffer */ - std::vector<ring::AudioSample> playbackIBuff_; - std::vector<ring::AudioSample> captureIBuff_; + std::vector<AudioSample> playbackIBuff_; + std::vector<AudioSample> captureIBuff_; AudioUnit outputUnit_; AudioUnit inputUnit_; @@ -184,6 +184,6 @@ class CoreLayer : public AudioLayer { std::vector<AudioDevice> getDeviceList(bool getCapture) const; }; -} +} // namespace ring #endif // CORE_LAYER_H_ diff --git a/daemon/src/media/audio/dcblocker.cpp b/daemon/src/media/audio/dcblocker.cpp index 24229e08c78b70dd3673285e7c5278f5b870667d..418969bd9d7dc048cfeb5393e9dab6c0f1f73854 100644 --- a/daemon/src/media/audio/dcblocker.cpp +++ b/daemon/src/media/audio/dcblocker.cpp @@ -41,13 +41,13 @@ void DcBlocker::reset() states.assign(states.size(), (struct StreamState){0, 0, 0, 0}); } -void DcBlocker::doProcess(ring::AudioSample *out, ring::AudioSample *in, unsigned samples, struct StreamState * state) +void DcBlocker::doProcess(AudioSample *out, AudioSample *in, unsigned samples, struct StreamState * state) { for (unsigned i = 0; i < samples; ++i) { state->x_ = in[i]; - state->y_ = (ring::AudioSample) ((float) state->x_ - (float) state->xm1_ + 0.9999 * (float) state->y_); + state->y_ = (AudioSample) ((float) state->x_ - (float) state->xm1_ + 0.9999 * (float) state->y_); state->xm1_ = state->x_; state->ym1_ = state->y_; @@ -55,7 +55,7 @@ void DcBlocker::doProcess(ring::AudioSample *out, ring::AudioSample *in, unsigne } } -void DcBlocker::process(ring::AudioSample *out, ring::AudioSample *in, int samples) +void DcBlocker::process(AudioSample *out, AudioSample *in, int samples) { if (out == NULL or in == NULL or samples == 0) return; doProcess(out, in, samples, &states[0]); @@ -70,9 +70,9 @@ void DcBlocker::process(AudioBuffer& buf) unsigned i; for(i=0; i<chans; i++) { - ring::AudioSample *chan = buf.getChannel(i)->data(); + AudioSample *chan = buf.getChannel(i)->data(); doProcess(chan, chan, samples, &states[i]); } } -} +} // namespace ring diff --git a/daemon/src/media/audio/dcblocker.h b/daemon/src/media/audio/dcblocker.h index 6cc42557986b4a576ddef8aa2cf90a44436343c4..aeac13f62edb1288de83321f618b87d6cb98d8f7 100644 --- a/daemon/src/media/audio/dcblocker.h +++ b/daemon/src/media/audio/dcblocker.h @@ -42,7 +42,7 @@ class DcBlocker { DcBlocker(unsigned channels = 1); void reset(); - void process(ring::AudioSample *out, ring::AudioSample *in, int samples); + void process(AudioSample *out, AudioSample *in, int samples); /** * In-place processing of all samples in buf (each channel treated independently) @@ -51,14 +51,14 @@ class DcBlocker { private: struct StreamState { - ring::AudioSample y_, x_, xm1_, ym1_; + AudioSample y_, x_, xm1_, ym1_; }; - void doProcess(ring::AudioSample *out, ring::AudioSample *in, unsigned samples, struct StreamState * state); + void doProcess(AudioSample *out, AudioSample *in, unsigned samples, struct StreamState * state); std::vector<StreamState> states; }; -} +} // namespace ring #endif diff --git a/daemon/src/media/audio/dsp.cpp b/daemon/src/media/audio/dsp.cpp index 8ba0e1037c2ee569bc17ebfe0feb91a105cc5d4b..2ffb5c9c19584022eb63cb020e675694fac6f0fb 100644 --- a/daemon/src/media/audio/dsp.cpp +++ b/daemon/src/media/audio/dsp.cpp @@ -101,4 +101,4 @@ void DSP::process(AudioBuffer& buff, int samples) } } -} +} // namespace ring diff --git a/daemon/src/media/audio/dsp.h b/daemon/src/media/audio/dsp.h index 69a64b27dc603fd678f4d6dbb5e53c2b82e5348d..699772ab2f5c4901c0673539cdc73e39aed76054 100644 --- a/daemon/src/media/audio/dsp.h +++ b/daemon/src/media/audio/dsp.h @@ -59,6 +59,6 @@ class DSP { std::vector<SpeexStatePtr> dspStates_; }; -} +} // namespace ring #endif // DSP_H_ diff --git a/daemon/src/media/audio/jack/jacklayer.cpp b/daemon/src/media/audio/jack/jacklayer.cpp index 4b796b7dc9922e9b0ede7cc5789bdf725e5104e2..ad0fff6f6b74662b8b3a35d7ca60a94b74674946 100644 --- a/daemon/src/media/audio/jack/jacklayer.cpp +++ b/daemon/src/media/audio/jack/jacklayer.cpp @@ -173,7 +173,7 @@ JackLayer::capture() } static void -convertToFloat(const std::vector<ring::AudioSample> &src, std::vector<float> &dest) +convertToFloat(const std::vector<AudioSample> &src, std::vector<float> &dest) { static const float INV_SHORT_MAX = 1 / (float) SHRT_MAX; if (dest.size() != src.size()) { @@ -185,7 +185,7 @@ convertToFloat(const std::vector<ring::AudioSample> &src, std::vector<float> &de } static void -convertFromFloat(std::vector<float> &src, std::vector<ring::AudioSample> &dest) +convertFromFloat(std::vector<float> &src, std::vector<AudioSample> &dest) { if (dest.size() != src.size()) { RING_ERR("MISMATCH"); @@ -535,4 +535,4 @@ JackLayer::stopStream() flushUrgent(); } -} +} // namespace ring diff --git a/daemon/src/media/audio/opensl/opensllayer.cpp b/daemon/src/media/audio/opensl/opensllayer.cpp index 284df53d8d3eafa57d9606fc65ec7743a547e12d..0275c131dec8f24007578ed264494c4aad4f1a43 100644 --- a/daemon/src/media/audio/opensl/opensllayer.cpp +++ b/daemon/src/media/audio/opensl/opensllayer.cpp @@ -658,7 +658,7 @@ OpenSLLayer::playback(SLAndroidSimpleBufferQueueItf queue) } if (bufferIsFilled_) { - SLresult result = (*queue)->Enqueue(queue, buffer.getChannel(0)->data(), buffer.frames()*sizeof(ring::AudioSample)); + SLresult result = (*queue)->Enqueue(queue, buffer.getChannel(0)->data(), buffer.frames()*sizeof(AudioSample)); if (SL_RESULT_SUCCESS != result) { RING_DBG("Error could not enqueue buffers in playback callback\n"); } @@ -687,7 +687,7 @@ OpenSLLayer::capture(SLAndroidSimpleBufferQueueItf queue) SLresult result; // enqueue an empty buffer to be filled by the recorder // (for streaming recording, we enqueue at least 2 empty buffers to start things off) - result = (*recorderBufferQueue_)->Enqueue(recorderBufferQueue_, buffer.getChannel(0)->data(), buffer.frames()*sizeof(ring::AudioSample)); + result = (*recorderBufferQueue_)->Enqueue(recorderBufferQueue_, buffer.getChannel(0)->data(), buffer.frames()*sizeof(AudioSample)); audioCaptureFillBuffer(old_buffer); @@ -858,4 +858,4 @@ void dumpAvailableEngineInterfaces() } } -} +} // namespace ring diff --git a/daemon/src/media/audio/pulseaudio/audiostream.cpp b/daemon/src/media/audio/pulseaudio/audiostream.cpp index f18604da86dc36f3a463c1766af0a0fc7b49cd5e..d4b0150daefad645f6bfeeb0cb73f5c74a852cda 100644 --- a/daemon/src/media/audio/pulseaudio/audiostream.cpp +++ b/daemon/src/media/audio/pulseaudio/audiostream.cpp @@ -153,4 +153,4 @@ bool AudioStream::isReady() return pa_stream_get_state(audiostream_) == PA_STREAM_READY; } -} +} // namespace ring diff --git a/daemon/src/media/audio/pulseaudio/pulselayer.cpp b/daemon/src/media/audio/pulseaudio/pulselayer.cpp index 4ea5858fbdbca30a8fb42a1e283e798bf412f02e..1fd4e62764f23260b6e76890446097bb80325ec0 100644 --- a/daemon/src/media/audio/pulseaudio/pulselayer.cpp +++ b/daemon/src/media/audio/pulseaudio/pulselayer.cpp @@ -490,7 +490,7 @@ void PulseLayer::writeToSpeaker() urgentBytes = urgentSamples * sample_size; } - ring::AudioSample *data = 0; + AudioSample *data = 0; if (urgentBytes) { AudioBuffer linearbuff(urgentSamples, format); @@ -585,7 +585,7 @@ void PulseLayer::readFromMic() const size_t samples = bytes / sample_size / format.nb_channels; AudioBuffer in(samples, format); - in.deinterleave((ring::AudioSample*)data, samples, format.nb_channels); + in.deinterleave((AudioSample*)data, samples, format.nb_channels); unsigned int mainBufferSampleRate = Manager::instance().getRingBufferPool().getInternalSamplingRate(); bool resample = audioFormat_.sample_rate != mainBufferSampleRate; @@ -635,7 +635,7 @@ void PulseLayer::ringtoneToSpeaker() const unsigned samples = (bytes / sample_size) / ringtone_->channels(); AudioBuffer tmp(samples, ringtone_->getFormat()); fileToPlay->getNext(tmp, playbackGain_); - tmp.interleave((ring::AudioSample*) data); + tmp.interleave((AudioSample*) data); } else { memset(data, 0, bytes); } @@ -847,4 +847,4 @@ int PulseLayer::getIndexRingtone() const return getAudioDeviceIndexByName(preference_.getPulseDeviceRingtone(), DeviceType::RINGTONE); } -} +} // namespace ring diff --git a/daemon/src/media/audio/pulseaudio/pulselayer.h b/daemon/src/media/audio/pulseaudio/pulselayer.h index 812577d07e047b67e7f1fb462ccc2e312f43a326..3ec548ac02b38d5fc6937edabb482c734eadd231 100644 --- a/daemon/src/media/audio/pulseaudio/pulselayer.h +++ b/daemon/src/media/audio/pulseaudio/pulselayer.h @@ -45,10 +45,9 @@ #include <memory> -class AudioPreference; - namespace ring { +class AudioPreference; class AudioStream; class RingBuffer; @@ -230,6 +229,6 @@ class PulseLayer : public AudioLayer { friend class AudioLayerTest; }; -} +} // namespace ring #endif // PULSE_LAYER_H_ diff --git a/daemon/src/media/audio/recordable.cpp b/daemon/src/media/audio/recordable.cpp index ee953a62baede2e2b807e449a3fd7ce98395bc45..6c0832c355e06fe34fb181949eeef488a45c5019 100644 --- a/daemon/src/media/audio/recordable.cpp +++ b/daemon/src/media/audio/recordable.cpp @@ -60,4 +60,4 @@ void Recordable::setRecordingFormat(AudioFormat format) recAudio_.setSndFormat(format); } -} +} // namespace ring diff --git a/daemon/src/media/audio/recordable.h b/daemon/src/media/audio/recordable.h index dd32b3058e7e3a6f35c76e7d375a6187b6dffb42..cc8bb4325d8e83d8df7b9efb590a8c13b20a0622 100644 --- a/daemon/src/media/audio/recordable.h +++ b/daemon/src/media/audio/recordable.h @@ -87,6 +87,6 @@ class Recordable { AudioRecorder recorder_; }; -} +} // namespace ring #endif diff --git a/daemon/src/media/audio/resampler.cpp b/daemon/src/media/audio/resampler.cpp index b422c749b5bf791d0580b4ac20234c29c81f6a6f..e4125a9f02e2b2229274bd6556a5cee777ab8536 100644 --- a/daemon/src/media/audio/resampler.cpp +++ b/daemon/src/media/audio/resampler.cpp @@ -133,4 +133,4 @@ void Resampler::resample(const AudioBuffer &dataIn, AudioBuffer &dataOut) dataOut.deinterleave(scratchBuffer_.data(), src_data.output_frames, nbChans); } -} +} // namespace ring diff --git a/daemon/src/media/audio/resampler.h b/daemon/src/media/audio/resampler.h index 6d90b90c56a268bf0ea261fcaad7a996e07cc12c..bfceca866bab74a4be21f5a806eb459689ec9e53 100644 --- a/daemon/src/media/audio/resampler.h +++ b/daemon/src/media/audio/resampler.h @@ -77,7 +77,7 @@ class Resampler { /* temporary buffers */ std::vector<float> floatBufferIn_; std::vector<float> floatBufferOut_; - std::vector<ring::AudioSample> scratchBuffer_; + std::vector<AudioSample> scratchBuffer_; size_t samples_; // size in samples of temporary buffers AudioFormat format_; // number of channels and max output frequency @@ -85,6 +85,6 @@ class Resampler { std::unique_ptr<SrcState> src_state_; }; -} +} // namespace ring #endif //_SAMPLE_RATE_H diff --git a/daemon/src/media/audio/ringbuffer.cpp b/daemon/src/media/audio/ringbuffer.cpp index 531bb2843c8c4d4246a6cb0ae699ca2c32745aee..2c03e867e1c5135a43705362244fc8e7645a06f2 100644 --- a/daemon/src/media/audio/ringbuffer.cpp +++ b/daemon/src/media/audio/ringbuffer.cpp @@ -313,4 +313,4 @@ RingBuffer::discard(size_t toDiscard) return toDiscard; } -} +} // namespace ring diff --git a/daemon/src/media/audio/ringbuffer.h b/daemon/src/media/audio/ringbuffer.h index c8d8bdcd1f6bb343318017dd84796b0ed28c783d..2bdaf8756b0626e96b1c9ded657cddaebc8c99de 100644 --- a/daemon/src/media/audio/ringbuffer.h +++ b/daemon/src/media/audio/ringbuffer.h @@ -180,6 +180,6 @@ class RingBuffer { ReadOffset readoffsets_; }; -} +} // namespace ring #endif /* __RING_BUFFER__ */ diff --git a/daemon/src/media/audio/ringbufferpool.cpp b/daemon/src/media/audio/ringbufferpool.cpp index f94ab7efd5044e1c99a768ce8afd0bbb336966e5..8104a57afe1f3d35aa33fd72beec7bb61522c2d3 100644 --- a/daemon/src/media/audio/ringbufferpool.cpp +++ b/daemon/src/media/audio/ringbufferpool.cpp @@ -425,4 +425,4 @@ RingBufferPool::flushAllBuffers() } } -} +} // namespace ring diff --git a/daemon/src/media/audio/ringbufferpool.h b/daemon/src/media/audio/ringbufferpool.h index e3ad68fd542cebc79cbb8fd9c40c2a94bd79a152..3864c3159100ae338247f51a26fabd579907d753 100644 --- a/daemon/src/media/audio/ringbufferpool.h +++ b/daemon/src/media/audio/ringbufferpool.h @@ -164,6 +164,6 @@ class RingBufferPool { std::shared_ptr<RingBuffer> defaultRingBuffer_; }; -} +} // namespace ring #endif // RING_BUFFER_POOL_H_ diff --git a/daemon/src/media/audio/sound/audiofile.cpp b/daemon/src/media/audio/sound/audiofile.cpp index cc04c9bf592fa5720bec0b46371fd765ce4e4a8f..0ab5bc9395413338b2c4078e8fadaade2e38e550 100644 --- a/daemon/src/media/audio/sound/audiofile.cpp +++ b/daemon/src/media/audio/sound/audiofile.cpp @@ -115,7 +115,7 @@ AudioFile::AudioFile(const std::string &fileName, unsigned int sampleRate) : const sf_count_t nbFrames = hasHeader ? fileHandle.frames() : fileSize / fileHandle.channels(); - ring::AudioSample * interleaved = new ring::AudioSample[nbFrames * fileHandle.channels()]; + AudioSample * interleaved = new AudioSample[nbFrames * fileHandle.channels()]; // get n "items", aka samples (not frames) fileHandle.read(interleaved, nbFrames * fileHandle.channels()); @@ -139,4 +139,4 @@ AudioFile::AudioFile(const std::string &fileName, unsigned int sampleRate) : } } -} +} // namespace ring diff --git a/daemon/src/media/audio/sound/audiofile.h b/daemon/src/media/audio/sound/audiofile.h index 63cf2fc639c012b2893001276fbe4b0d8ed3b85f..8a4c33074d51d794df3ffba662a2cace1c24eb59 100644 --- a/daemon/src/media/audio/sound/audiofile.h +++ b/daemon/src/media/audio/sound/audiofile.h @@ -66,6 +66,6 @@ class AudioFile : public AudioLoop { unsigned updatePlaybackScale_; }; -} +} // namespace ring #endif // __AUDIOFILE_H__ diff --git a/daemon/src/media/audio/sound/dtmf.cpp b/daemon/src/media/audio/sound/dtmf.cpp index 4f35d3298b1229d91209b47dc1bd5a2e6fc96255..09cf18d9e14892650909913c0f3d03f135fa77fe 100644 --- a/daemon/src/media/audio/sound/dtmf.cpp +++ b/daemon/src/media/audio/sound/dtmf.cpp @@ -47,7 +47,7 @@ void DTMF::startTone(char code) using std::vector; -bool DTMF::generateDTMF(vector<ring::AudioSample> &buffer) +bool DTMF::generateDTMF(vector<AudioSample> &buffer) { try { if (currentTone_ != 0) { @@ -82,4 +82,4 @@ bool DTMF::generateDTMF(vector<ring::AudioSample> &buffer) } } -} +} // namespace ring diff --git a/daemon/src/media/audio/sound/dtmf.h b/daemon/src/media/audio/sound/dtmf.h index a0d64c71157b80df7c120bfa7b99a1609bc0dffe..476500d7823a087a85f9e1f7ada4a23e6b2df035 100644 --- a/daemon/src/media/audio/sound/dtmf.h +++ b/daemon/src/media/audio/sound/dtmf.h @@ -41,6 +41,7 @@ * @file dtmf.h * @brief DMTF library to generate a dtmf sample */ + namespace ring { class DTMF { @@ -59,9 +60,9 @@ class DTMF { /** * Copy the sound inside the sampling* buffer - * @param buffer : a vector of ring::AudioSample + * @param buffer : a vector of AudioSample */ - bool generateDTMF(std::vector<ring::AudioSample> &buffer); + bool generateDTMF(std::vector<AudioSample> &buffer); private: char currentTone_; @@ -70,6 +71,6 @@ class DTMF { DTMFGenerator dtmfgenerator_; }; -} +} // namespace ring #endif // __KEY_DTMF_H_ diff --git a/daemon/src/media/audio/sound/dtmfgenerator.cpp b/daemon/src/media/audio/sound/dtmfgenerator.cpp index 94bc0ba3614312ba29b07db977f2c750f6a54beb..ab16eecb1105542a2184ebe713050e78f99140cb 100644 --- a/daemon/src/media/audio/sound/dtmfgenerator.cpp +++ b/daemon/src/media/audio/sound/dtmfgenerator.cpp @@ -87,7 +87,7 @@ using std::vector; /* * Get n samples of the signal of code code */ -void DTMFGenerator::getSamples(vector<ring::AudioSample> &buffer, unsigned char code) +void DTMFGenerator::getSamples(vector<AudioSample> &buffer, unsigned char code) { code = toupper(code); @@ -124,7 +124,7 @@ void DTMFGenerator::getSamples(vector<ring::AudioSample> &buffer, unsigned char * Get next n samples (continues where previous call to * genSample or genNextSamples stopped */ -void DTMFGenerator::getNextSamples(vector<ring::AudioSample> &buffer) +void DTMFGenerator::getNextSamples(vector<AudioSample> &buffer) { if (state.sample == 0) throw DTMFException("DTMF generator not initialized"); @@ -138,12 +138,12 @@ void DTMFGenerator::getNextSamples(vector<ring::AudioSample> &buffer) state.offset = (state.offset + i) % sampleRate_; } -ring::AudioSample* DTMFGenerator::fillToneBuffer(int index) +AudioSample* DTMFGenerator::fillToneBuffer(int index) { assert(index >= 0 and index < NUM_TONES); - ring::AudioSample* ptr = new ring::AudioSample[sampleRate_]; + AudioSample* ptr = new AudioSample[sampleRate_]; tone_.genSin(ptr, tones_[index].higher, tones_[index].lower, sampleRate_); return ptr; } -} +} // namespace ring diff --git a/daemon/src/media/audio/sound/dtmfgenerator.h b/daemon/src/media/audio/sound/dtmfgenerator.h index cea0bc481c994bba0b7c2731e4f8b98dc9e77085..0f4b43dd51d6151c728f26c3ecccb4ab4397d8a8 100644 --- a/daemon/src/media/audio/sound/dtmfgenerator.h +++ b/daemon/src/media/audio/sound/dtmfgenerator.h @@ -72,7 +72,7 @@ class DTMFGenerator { /** State of the DTMF generator */ struct DTMFState { unsigned int offset; /** Offset in the sample currently being played */ - ring::AudioSample* sample; /** Currently generated code */ + AudioSample* sample; /** Currently generated code */ }; /** State of the DTMF generator */ @@ -82,7 +82,7 @@ class DTMFGenerator { static const DTMFTone tones_[NUM_TONES]; /** Generated samples for each tone */ - ring::AudioSample* toneBuffers_[NUM_TONES]; + AudioSample* toneBuffers_[NUM_TONES]; /** Sampling rate of generated dtmf */ int sampleRate_; @@ -104,28 +104,28 @@ class DTMFGenerator { /* * Get n samples of the signal of code code - * @param buffer a ring::AudioSample vector + * @param buffer a AudioSample vector * @param code dtmf code to get sound */ - void getSamples(std::vector<ring::AudioSample> &buffer, unsigned char code); + void getSamples(std::vector<AudioSample> &buffer, unsigned char code); /* * Get next n samples (continues where previous call to * genSample or genNextSamples stopped - * @param buffer a ring::AudioSample vector + * @param buffer a AudioSample vector */ - void getNextSamples(std::vector<ring::AudioSample> &buffer); + void getNextSamples(std::vector<AudioSample> &buffer); private: /** * Fill tone buffer for a given index of the array of tones. * @param index of the tone in the array tones_ - * @return ring::AudioSample* The generated data + * @return AudioSample* The generated data */ - ring::AudioSample* fillToneBuffer(int index); + AudioSample* fillToneBuffer(int index); }; -} +} // namespace ring #endif // DTMFGENERATOR_H diff --git a/daemon/src/media/audio/sound/tone.cpp b/daemon/src/media/audio/sound/tone.cpp index f35ca63cfac0831729a61de8092d2d2aa54e5421..a4948f73f9e8e30245c84650b9898267317dbe55 100644 --- a/daemon/src/media/audio/sound/tone.cpp +++ b/daemon/src/media/audio/sound/tone.cpp @@ -61,7 +61,7 @@ Tone::genBuffer(const std::string& definition) size_t size = 0; const int sampleRate = buffer_->getSampleRate(); - std::vector<ring::AudioSample> buffer(SIZEBUF); + std::vector<AudioSample> buffer(SIZEBUF); size_t bufferPos(0); // Number of format sections @@ -155,7 +155,7 @@ Tone::interpolate(double x) const } void -Tone::genSin(ring::AudioSample* buffer, int lowFrequency, int highFrequency, int nb) +Tone::genSin(AudioSample* buffer, int lowFrequency, int highFrequency, int nb) { xhigher_ = 0.0; xlower_ = 0.0; @@ -188,4 +188,4 @@ Tone::genSin(ring::AudioSample* buffer, int lowFrequency, int highFrequency, int xlower_ = x_l; } -} +} // namespace ring diff --git a/daemon/src/media/audio/sound/tone.h b/daemon/src/media/audio/sound/tone.h index decf8f056282a979b4cd9e354533bf06f0b9725b..691a0fca0c2b262a26a05520c137f1d2bdd64fbc 100644 --- a/daemon/src/media/audio/sound/tone.h +++ b/daemon/src/media/audio/sound/tone.h @@ -69,7 +69,7 @@ class Tone : public AudioLoop { * @param nb are the number of int16 (mono) to generate * by example nb=5 generate 10 int16, 5 for the left, 5 for the right */ - void genSin(ring::AudioSample* buffer, int frequency1, int frequency2, int nb); + void genSin(AudioSample* buffer, int frequency1, int frequency2, int nb); /** * @@ -93,6 +93,6 @@ class Tone : public AudioLoop { double xlower_; }; -} +} // namespace ring #endif // __TONE_H__ diff --git a/daemon/src/media/audio/sound/tonelist.cpp b/daemon/src/media/audio/sound/tonelist.cpp index a425fc5816d694ee0c949da25491d9157ae6dcc0..482c5a829484e1f77e94634051961dee8155c390 100644 --- a/daemon/src/media/audio/sound/tonelist.cpp +++ b/daemon/src/media/audio/sound/tonelist.cpp @@ -135,4 +135,4 @@ TelephoneTone::getCurrentTone() return tone_[currentTone_]; } -} +} // namespace ring diff --git a/daemon/src/media/audio/sound/tonelist.h b/daemon/src/media/audio/sound/tonelist.h index aa8e8e002b6d015ae7ad5d833ea786c95ea11749..83eed03734bfdc0022b6dc53a770cb8bb198fe69 100644 --- a/daemon/src/media/audio/sound/tonelist.h +++ b/daemon/src/media/audio/sound/tonelist.h @@ -68,6 +68,6 @@ class TelephoneTone { Tone::TONEID currentTone_; }; -} +} // namespace ring #endif diff --git a/daemon/src/media/libav_utils.cpp b/daemon/src/media/libav_utils.cpp index 4a22348cfa0278fece5498bdfc2099d63b80cfa9..164a33cda8b9163fa7d71628b5cca24748dcbbeb 100644 --- a/daemon/src/media/libav_utils.cpp +++ b/daemon/src/media/libav_utils.cpp @@ -43,6 +43,8 @@ #include <mutex> #include <exception> +namespace ring { namespace libav_utils { + std::map<std::string, std::string> encoders_; #ifdef RING_VIDEO @@ -64,11 +66,7 @@ findInstalledVideoCodecs() RING_ERR("Didn't find \"%s\" encoder", it.second.c_str()); } } -#endif // RING_VIDEO -namespace libav_utils { - -#ifdef RING_VIDEO std::vector<std::string> getVideoCodecList() { if (installed_video_codecs_.empty()) @@ -210,4 +208,4 @@ void sfl_url_split(const char *url, path, path_size, url); } -} // end namespace libav_utils +}} // namespace ring::libav_utils diff --git a/daemon/src/media/libav_utils.h b/daemon/src/media/libav_utils.h index 91f17844afd3ab63e2a598bb0ce0356a0eef0a79..47e171f211b4824c5af6771ce5f68763d86e0f2e 100644 --- a/daemon/src/media/libav_utils.h +++ b/daemon/src/media/libav_utils.h @@ -35,8 +35,8 @@ #include <map> #include <string> +namespace ring { namespace libav_utils { -namespace libav_utils { void sfl_avcodec_init(); int libav_pixel_format(int fmt); @@ -56,6 +56,7 @@ namespace libav_utils { void sfl_url_split(const char *url, char *hostname, size_t hostname_size, int *port, char *path, size_t path_size); -} + +}} // namespace ring::libav_utils #endif // __LIBAV_UTILS_H__ diff --git a/daemon/src/media/media_decoder.cpp b/daemon/src/media/media_decoder.cpp index 2b8a517da7e6ba42e0db7e21e6128bb4141fdee6..d1a5e5abd90e92d6891ca4080b605ba0aa027f45 100644 --- a/daemon/src/media/media_decoder.cpp +++ b/daemon/src/media/media_decoder.cpp @@ -280,7 +280,7 @@ int MediaDecoder::setupFromVideoData() } MediaDecoder::Status -MediaDecoder::decode(ring::video::VideoFrame& result, ring::video::VideoPacket& video_packet) +MediaDecoder::decode(video::VideoFrame& result, video::VideoPacket& video_packet) { AVPacket *inpacket = video_packet.get(); int ret = av_read_frame(inputCtx_, inpacket); @@ -391,7 +391,7 @@ MediaDecoder::decode_audio(AVFrame *decoded_frame) #ifdef RING_VIDEO MediaDecoder::Status -MediaDecoder::flush(ring::video::VideoFrame& result) +MediaDecoder::flush(video::VideoFrame& result) { AVPacket inpacket; memset(&inpacket, 0, sizeof(inpacket)); @@ -422,29 +422,29 @@ int MediaDecoder::getPixelFormat() const { return libav_utils::sfl_pixel_format(decoderCtx_->pix_fmt); } void MediaDecoder::writeToRingBuffer(AVFrame* decoded_frame, - ring::RingBuffer& rb, - const ring::AudioFormat outFormat) + RingBuffer& rb, + const AudioFormat outFormat) { - const ring::AudioFormat decoderFormat = { + const AudioFormat decoderFormat = { (unsigned) decoded_frame->sample_rate, (unsigned) decoderCtx_->channels }; - ring::AudioBuffer out(decoded_frame->nb_samples, decoderFormat); + AudioBuffer out(decoded_frame->nb_samples, decoderFormat); if ( decoderCtx_->sample_fmt == AV_SAMPLE_FMT_FLTP ) { out.convertFloatPlanarToSigned16(decoded_frame->extended_data, - decoded_frame->nb_samples, decoderCtx_->channels); + decoded_frame->nb_samples, decoderCtx_->channels); } else if ( decoderCtx_->sample_fmt == AV_SAMPLE_FMT_S16 ) { - out.deinterleave(reinterpret_cast<const ring::AudioSample*>(decoded_frame->data[0]), + out.deinterleave(reinterpret_cast<const AudioSample*>(decoded_frame->data[0]), decoded_frame->nb_samples, decoderCtx_->channels); } if ((unsigned)decoded_frame->sample_rate != outFormat.sample_rate) { if (!resampler_) { RING_DBG("Creating audio resampler"); - resampler_.reset(new ring::Resampler(outFormat)); + resampler_.reset(new Resampler(outFormat)); } - ring::AudioBuffer resampledData(decoded_frame->nb_samples, + AudioBuffer resampledData(decoded_frame->nb_samples, {(unsigned) outFormat.sample_rate, (unsigned) decoderCtx_->channels}); resampler_->resample(out, resampledData); @@ -454,4 +454,4 @@ void MediaDecoder::writeToRingBuffer(AVFrame* decoded_frame, } } -} +} // namespace ring diff --git a/daemon/src/media/media_decoder.h b/daemon/src/media/media_decoder.h index 42fee0429aa3b2f2933bc6febc6983274bdf57d4..2615b1ad9f00f21840b0e8fda399686a15ff9c36 100644 --- a/daemon/src/media/media_decoder.h +++ b/daemon/src/media/media_decoder.h @@ -53,14 +53,15 @@ class AVDictionary; class AVFormatContext; class AVCodec; +namespace ring { + #ifdef RING_VIDEO -namespace ring { namespace video { +namespace video { class VideoFrame; class VideoPacket; -}} +} #endif // RING_VIDEO -namespace ring { class AudioBuffer; class AudioFormat; class RingBuffer; @@ -89,14 +90,14 @@ public: void setIOContext(MediaIOHandle *ioctx); #ifdef RING_VIDEO int setupFromVideoData(); - Status decode(ring::video::VideoFrame&, ring::video::VideoPacket&); - Status flush(ring::video::VideoFrame&); + Status decode(video::VideoFrame&, video::VideoPacket&); + Status flush(video::VideoFrame&); #endif // RING_VIDEO int setupFromAudioData(); Status decode_audio(AVFrame* frame); - void writeToRingBuffer(AVFrame* frame, ring::RingBuffer& rb, - const ring::AudioFormat outFormat); + void writeToRingBuffer(AVFrame* frame, RingBuffer& rb, + const AudioFormat outFormat); int getWidth() const; int getHeight() const; @@ -110,7 +111,7 @@ public: AVCodec *inputDecoder_ = nullptr; AVCodecContext *decoderCtx_ = nullptr; AVFormatContext *inputCtx_ = nullptr; - std::unique_ptr<ring::Resampler> resampler_; + std::unique_ptr<Resampler> resampler_; int streamIndex_ = -1; bool emulateRate_ = false; int64_t startTime_; @@ -122,6 +123,7 @@ public: protected: AVDictionary *options_ = nullptr; }; -} + +} // namespace ring #endif // __MEDIA_DECODER_H__ diff --git a/daemon/src/media/media_encoder.cpp b/daemon/src/media/media_encoder.cpp index 7efc040328548cc8a374759c94a56975f383c6eb..8640beb6cd91dba9da52edae9d7073c4b4818cee 100644 --- a/daemon/src/media/media_encoder.cpp +++ b/daemon/src/media/media_encoder.cpp @@ -39,7 +39,6 @@ #include <sstream> #include <algorithm> - namespace ring { using std::string; @@ -238,7 +237,7 @@ print_averror(const char *funcname, int err) } #ifdef RING_VIDEO -int MediaEncoder::encode(ring::video::VideoFrame &input, bool is_keyframe, int64_t frame_number) +int MediaEncoder::encode(video::VideoFrame &input, bool is_keyframe, int64_t frame_number) { /* Prepare a frame suitable to our encoder frame format, * keeping also the input aspect ratio. @@ -327,7 +326,7 @@ int MediaEncoder::encode(ring::video::VideoFrame &input, bool is_keyframe, int64 } #endif // RING_VIDEO -int MediaEncoder::encode_audio(const ring::AudioBuffer &buffer) +int MediaEncoder::encode_audio(const AudioBuffer &buffer) { const int needed_bytes = av_samples_get_buffer_size(NULL, buffer.channels(), buffer.frames(), AV_SAMPLE_FMT_S16, 0); if (needed_bytes < 0) { @@ -335,11 +334,11 @@ int MediaEncoder::encode_audio(const ring::AudioBuffer &buffer) return -1; } - ring::AudioSample *sample_data = reinterpret_cast<ring::AudioSample*>(av_malloc(needed_bytes)); + AudioSample *sample_data = reinterpret_cast<AudioSample*>(av_malloc(needed_bytes)); if (!sample_data) return -1; - ring::AudioSample *offset_ptr = sample_data; + AudioSample *offset_ptr = sample_data; int nb_frames = buffer.frames(); buffer.interleave(sample_data); @@ -613,4 +612,4 @@ void MediaEncoder::extractProfileLevelID(const std::string ¶meters, RING_DBG("Using profile %x and level %d", ctx->profile, ctx->level); } -} +} // namespace ring diff --git a/daemon/src/media/media_encoder.h b/daemon/src/media/media_encoder.h index 1360c82fd638edfadf31424ebd8ff05cea9dad4c..5b0e11ecd4aea105420d73724a2652038209fa78 100644 --- a/daemon/src/media/media_encoder.h +++ b/daemon/src/media/media_encoder.h @@ -52,11 +52,9 @@ class AVDictionary; class AVCodec; namespace ring { - class AudioBuffer; - class MediaIOHandle; -} -namespace ring { +class AudioBuffer; +class MediaIOHandle; class MediaEncoderException : public std::runtime_error { public: @@ -77,10 +75,10 @@ public: void setIOContext(const std::unique_ptr<MediaIOHandle> &ioctx); #ifdef RING_VIDEO - int encode(ring::video::VideoFrame &input, bool is_keyframe, int64_t frame_number); + int encode(video::VideoFrame &input, bool is_keyframe, int64_t frame_number); #endif // RING_VIDEO - int encode_audio(const ring::AudioBuffer &input); + int encode_audio(const AudioBuffer &input); int flush(); void print_sdp(std::string &sdp_); @@ -103,8 +101,8 @@ private: AVStream *stream_ = nullptr; #ifdef RING_VIDEO - ring::video::VideoScaler scaler_; - ring::video::VideoFrame scaledFrame_; + video::VideoScaler scaler_; + video::VideoFrame scaledFrame_; #endif // RING_VIDEO uint8_t *scaledFrameBuffer_ = nullptr; @@ -121,6 +119,6 @@ protected: AVDictionary *options_ = nullptr; }; -} +} // namespace ring #endif // __MEDIA_ENCODER_H__ diff --git a/daemon/src/media/media_io_handle.cpp b/daemon/src/media/media_io_handle.cpp index 5ba2bb555f14cecc73827934babe253c228ecf81..98634a2d431452856d32de99402a87ea1157f7a5 100644 --- a/daemon/src/media/media_io_handle.cpp +++ b/daemon/src/media/media_io_handle.cpp @@ -50,4 +50,4 @@ MediaIOHandle::MediaIOHandle(ssize_t buffer_size, MediaIOHandle::~MediaIOHandle() { av_free(ctx_); av_free(buf_); } -} +} // namespace ring diff --git a/daemon/src/media/media_io_handle.h b/daemon/src/media/media_io_handle.h index 8d1d6374a61465ebf0c1c9e4667f4e47414e0c60..4efa050a2725ca88840ddc70769ccc7eef86a8ea 100644 --- a/daemon/src/media/media_io_handle.h +++ b/daemon/src/media/media_io_handle.h @@ -62,6 +62,6 @@ private: unsigned char *buf_; }; -} +} // namespace ring #endif // __MEDIA_DECODER_H__ diff --git a/daemon/src/media/socket_pair.cpp b/daemon/src/media/socket_pair.cpp index a762f4458c0472128a04ceaaf7f67125130e7f3b..e8ac6a824d4f0c0af0bf0fdf78b36f76dd800451 100644 --- a/daemon/src/media/socket_pair.cpp +++ b/daemon/src/media/socket_pair.cpp @@ -54,6 +54,8 @@ #define SOCK_NONBLOCK O_NONBLOCK #endif +namespace ring { + static const int NET_POLL_TIMEOUT = 100; /* poll() timeout in ms */ static int @@ -138,8 +140,6 @@ udp_socket_create(sockaddr_storage *addr, socklen_t *addr_len, int local_port) return udp_fd; } -namespace ring { - using std::string; static const int RTP_BUFFER_SIZE = 1472; @@ -155,8 +155,8 @@ SocketPair::SocketPair(const char *uri, int localPort) openSockets(uri, localPort); } -SocketPair::SocketPair(std::unique_ptr<ring::IceSocket> rtp_sock, - std::unique_ptr<ring::IceSocket> rtcp_sock) +SocketPair::SocketPair(std::unique_ptr<IceSocket> rtp_sock, + std::unique_ptr<IceSocket> rtcp_sock) : rtp_sock_(std::move(rtp_sock)) , rtcp_sock_(std::move(rtcp_sock)) , rtcpWriteMutex_() @@ -390,4 +390,4 @@ retry: return ret < 0 ? errno : ret; } -} +} // namespace ring diff --git a/daemon/src/media/socket_pair.h b/daemon/src/media/socket_pair.h index bb5f51df5bc363bcb8644cc2b2173fc21b922696..d387a76e3cf13f7549b79532185be8fbf3873bf5 100644 --- a/daemon/src/media/socket_pair.h +++ b/daemon/src/media/socket_pair.h @@ -83,6 +83,6 @@ class SocketPair { bool interrupted_ {false}; }; -} +} // namespace ring #endif // SOCKET_PAIR_H_ diff --git a/daemon/src/media/video/shm_sink.cpp b/daemon/src/media/video/shm_sink.cpp index 71baaf2dad6c5a0ad7686b3fc8b136a78510c92b..f76cff316e5b61cb0f12ce7d991807ffa5f79926 100644 --- a/daemon/src/media/video/shm_sink.cpp +++ b/daemon/src/media/video/shm_sink.cpp @@ -261,4 +261,4 @@ void SHMSink::update(Observable<std::shared_ptr<VideoFrame> >* /*obs*/, std::sha render_frame(*f.get()); } -}} +}} // namespace ring::video diff --git a/daemon/src/media/video/shm_sink.h b/daemon/src/media/video/shm_sink.h index 1951aebc36b3c9fa22df7f29fbe8c9ccba2c0ad2..a84225050645d3a26c74e7d35b0d1ddac18f1ce9 100644 --- a/daemon/src/media/video/shm_sink.h +++ b/daemon/src/media/video/shm_sink.h @@ -82,6 +82,6 @@ private: #endif }; -}} +}} // namespace ring::video #endif // SHM_SINK_H_ diff --git a/daemon/src/media/video/test/test_video_endpoint.cpp b/daemon/src/media/video/test/test_video_endpoint.cpp index df29a85469d8e02f73d3b60b25b76f0a4d13a184..62b3b6d2978c046f0fac8104277aad13e42622e3 100644 --- a/daemon/src/media/video/test/test_video_endpoint.cpp +++ b/daemon/src/media/video/test/test_video_endpoint.cpp @@ -35,6 +35,8 @@ #include <cassert> #include "libav_utils.h" +namespace ring { namespace video { namespace test { + void VideoEndpointTest::testListInstalledCodecs() { /* This would list codecs */ @@ -45,10 +47,12 @@ void VideoEndpointTest::testListInstalledCodecs() std::cout << '\t' << *it << std::endl; } +}}} // namespace ring::video::test + int main () { - libav_utils::sfl_avcodec_init(); - VideoEndpointTest test; + ring::libav_utils::sfl_avcodec_init(); + ring::video::test::VideoEndpointTest test; test.testListInstalledCodecs(); return 0; } diff --git a/daemon/src/media/video/test/test_video_endpoint.h b/daemon/src/media/video/test/test_video_endpoint.h index cf16c6a9b94727f6994f99cfabd950503aa689a7..090abfd54c32f1e19592816703fca8e5874aa54c 100644 --- a/daemon/src/media/video/test/test_video_endpoint.h +++ b/daemon/src/media/video/test/test_video_endpoint.h @@ -31,6 +31,8 @@ #ifndef _VIDEO_ENDPOINT_TEST_ #define _VIDEO_ENDPOINT_TEST_ +namespace ring { namespace video { namespace test { + class VideoEndpointTest { public: void testListInstalledCodecs(); @@ -39,4 +41,6 @@ public: void testRTPSession(); }; +}}} // namespace ring::video::test + #endif // _VIDEO_ENDPOINT_TEST_ diff --git a/daemon/src/media/video/test/test_video_input.cpp b/daemon/src/media/video/test/test_video_input.cpp index 7ba8754d43175b045f6a33756681001f4076890d..8463b38a501bd20fed7c50f52039efdfa632a308 100644 --- a/daemon/src/media/video/test/test_video_input.cpp +++ b/daemon/src/media/video/test/test_video_input.cpp @@ -34,20 +34,22 @@ #include <map> #include <string> -using namespace std; +namespace ring { namespace video { namespace test { void VideoInputTest::testInput() { - string resource = "display://" + string(getenv("DISPLAY") ? : ":0.0"); - ring::video::VideoInput video; + std::string resource = "display://" + std::string(getenv("DISPLAY") ? : ":0.0"); + VideoInput video; video.switchInput(resource); usleep(10000); } +}}} // namespace ring::video::test + int main () { for (int i = 0; i < 20; ++i) { - VideoInputTest test; + ring::video::test::VideoInputTest test; test.testInput(); } return 0; diff --git a/daemon/src/media/video/test/test_video_input.h b/daemon/src/media/video/test/test_video_input.h index d80768e4774b6cac73ab97e7f1e51980ab3601ad..2104ff2869f634694dcbf9a47f20b0a58fe05453 100644 --- a/daemon/src/media/video/test/test_video_input.h +++ b/daemon/src/media/video/test/test_video_input.h @@ -31,9 +31,13 @@ #ifndef _VIDEO_INPUT_TEST_ #define _VIDEO_INPUT_TEST_ +namespace ring { namespace video { namespace test { + class VideoInputTest { public: void testInput(); }; +}}} // namespace ring::video::test + #endif // _VIDEO_INPUT_TEST_ diff --git a/daemon/src/media/video/v4l2/video_device_impl.cpp b/daemon/src/media/video/v4l2/video_device_impl.cpp index 8fdf3768d661079d3dd1659be51090b900e093c3..9b804e50c1a5bdfc8bac75af32b2970d51fdf6c2 100644 --- a/daemon/src/media/video/v4l2/video_device_impl.cpp +++ b/daemon/src/media/video/v4l2/video_device_impl.cpp @@ -582,4 +582,4 @@ VideoDevice::getCapabilities() const VideoDevice::~VideoDevice() {} -}} // namespace ring // namespace video +}} // namespace ring::video diff --git a/daemon/src/media/video/v4l2/video_device_monitor_impl.cpp b/daemon/src/media/video/v4l2/video_device_monitor_impl.cpp index d98cfa97d1517ca963ac9b9a07ece956fc81236d..8d867f647b39425c97bed9ce79fd7ec6da70cb6c 100644 --- a/daemon/src/media/video/v4l2/video_device_monitor_impl.cpp +++ b/daemon/src/media/video/v4l2/video_device_monitor_impl.cpp @@ -259,4 +259,4 @@ VideoDeviceMonitor::VideoDeviceMonitor() : VideoDeviceMonitor::~VideoDeviceMonitor() {} -}} +}} // namespace ring::video diff --git a/daemon/src/media/video/video_base.cpp b/daemon/src/media/video/video_base.cpp index 25a85c924fb5261b89ef1a357a65060fe9cef749..8b0d2f3246171b4a2b9b2f7c57e7677acf0d6f3e 100644 --- a/daemon/src/media/video/video_base.cpp +++ b/daemon/src/media/video/video_base.cpp @@ -189,4 +189,4 @@ std::shared_ptr<VideoFrame> VideoGenerator::obtainLastFrame() return lastFrame_; } -}} +}} // namespace ring::video diff --git a/daemon/src/media/video/video_base.h b/daemon/src/media/video/video_base.h index 42505ee58034b894aa89cc0d330b3e481a501911..028586ec958b40aa29106639f04c26727ab61e10 100644 --- a/daemon/src/media/video/video_base.h +++ b/daemon/src/media/video/video_base.h @@ -193,6 +193,6 @@ private: std::mutex mutex_ = {}; // lock writableFrame_/lastFrame_ access }; -}} +}} // namespace ring::video #endif // __VIDEO_BASE_H__ diff --git a/daemon/src/media/video/video_device.h b/daemon/src/media/video/video_device.h index af7a9e6b10fff5ddf23c0247ca4c54226feb43ef..47ec3bc40e38b6e3d3bf02054a3357ea1a048275 100644 --- a/daemon/src/media/video/video_device.h +++ b/daemon/src/media/video/video_device.h @@ -111,6 +111,6 @@ private: std::shared_ptr<VideoDeviceImpl> deviceImpl_; }; -}} //namespace ring //namespace video +}} // namespace ring::video #endif // __VIDEO_DEVICE_H__ diff --git a/daemon/src/media/video/video_device_monitor.cpp b/daemon/src/media/video/video_device_monitor.cpp index b96862f7ce7c9379e201b60c5c47f643f0d35128..3e1a450626070c398eaf4b1c398a22116aaaf2d2 100644 --- a/daemon/src/media/video/video_device_monitor.cpp +++ b/daemon/src/media/video/video_device_monitor.cpp @@ -283,7 +283,6 @@ VideoDeviceMonitor::serialize(YAML::Emitter &out) void VideoDeviceMonitor::unserialize(const YAML::Node &in) { - using namespace Conf; const auto &node = in[CONFIG_LABEL]; /* load the device list from the "video" YAML section */ @@ -309,4 +308,4 @@ VideoDeviceMonitor::unserialize(const YAML::Node &in) defaultDevice_ = first; } -}} //namespace ring //namespace video +}} // namespace ring::video diff --git a/daemon/src/media/video/video_device_monitor.h b/daemon/src/media/video/video_device_monitor.h index d0a5c5808923b254c5551d57cd4e6dc1cd36fd6a..29b38de0a8830ee8874ed8c27b97e8ac0386b648 100644 --- a/daemon/src/media/video/video_device_monitor.h +++ b/daemon/src/media/video/video_device_monitor.h @@ -42,8 +42,8 @@ #include "video_device.h" namespace YAML { - class Emitter; - class Node; +class Emitter; +class Node; } namespace ring { namespace video { @@ -102,6 +102,6 @@ class VideoDeviceMonitor : public Serializable constexpr static const char *CONFIG_LABEL = "video"; }; -}} //namespace ring //namespace video +}} // namespace ring::video #endif /* VIDEO_DEVICE_MONITOR_H__ */ diff --git a/daemon/src/media/video/video_input.cpp b/daemon/src/media/video/video_input.cpp index 8b49d15a29fe56f50b4b9071e5e052f401f88291..6854db9452d05baf547a41053656223091e3639f 100644 --- a/daemon/src/media/video/video_input.cpp +++ b/daemon/src/media/video/video_input.cpp @@ -146,7 +146,7 @@ VideoInput::createDecoder() if (input_.empty()) return; - decoder_ = new ring::MediaDecoder(); + decoder_ = new MediaDecoder(); decoder_->setOptions(decOpts_); if (emulateRate_) @@ -320,4 +320,4 @@ int VideoInput::getHeight() const int VideoInput::getPixelFormat() const { return decoder_->getPixelFormat(); } -}} //namespace ring //namespace video +}} // namespace ring::video diff --git a/daemon/src/media/video/video_input.h b/daemon/src/media/video/video_input.h index ac1338740bfec6b751567e72c1fa38f8f0dcd79e..701613fa6f601b51d2625bca75c39f1255dae3c3 100644 --- a/daemon/src/media/video/video_input.h +++ b/daemon/src/media/video/video_input.h @@ -43,12 +43,11 @@ #include <string> namespace ring { - class MediaDecoder; +class MediaDecoder; } namespace ring { namespace video { - class VideoInput : public VideoGenerator { public: @@ -67,7 +66,7 @@ private: std::string sinkID_ = "local"; - ring::MediaDecoder *decoder_ = nullptr; + MediaDecoder *decoder_ = nullptr; SHMSink sink_; std::atomic<bool> switchPending_ = {false}; @@ -101,6 +100,6 @@ private: bool captureFrame(); }; -}} +}} // namespace ring::video #endif // __VIDEO_INPUT_H__ diff --git a/daemon/src/media/video/video_mixer.cpp b/daemon/src/media/video/video_mixer.cpp index 75234c5450cce1cfbc652cb4298d19bed6345ce0..ea7dbd86b246a7c84774978ad38525151a7fda5d 100644 --- a/daemon/src/media/video/video_mixer.cpp +++ b/daemon/src/media/video/video_mixer.cpp @@ -39,10 +39,10 @@ #include <cmath> #include <unistd.h> -static const double FRAME_DURATION = 1/30.; - namespace ring { namespace video { +static const double FRAME_DURATION = 1/30.; + VideoMixer::VideoMixer(const std::string &id) : VideoGenerator::VideoGenerator() , id_(id) @@ -214,4 +214,4 @@ int VideoMixer::getHeight() const int VideoMixer::getPixelFormat() const { return VIDEO_PIXFMT_YUV420P; } -}} //namespace ring //namespace video +}} // namespace ring::video diff --git a/daemon/src/media/video/video_mixer.h b/daemon/src/media/video/video_mixer.h index 2a117ed202cd9fee7bc4c156b1b5ca6cbce1482e..50d4895bdd9fbea67f4668f2b3ee072f3691a272 100644 --- a/daemon/src/media/video/video_mixer.h +++ b/daemon/src/media/video/video_mixer.h @@ -90,7 +90,7 @@ private: int width_ = 0; int height_ = 0; std::list<VideoMixerSource *> sources_ = {}; - ring::rw_mutex rwMutex_ = {}; + rw_mutex rwMutex_ = {}; SHMSink sink_; ThreadLoop loop_; std::chrono::time_point<std::chrono::system_clock> lastProcess_ = {}; @@ -98,6 +98,6 @@ private: VideoScaler scaler_ = {}; }; -}} +}} // namespace ring::video #endif // __VIDEO_MIXER_H__ diff --git a/daemon/src/media/video/video_provider.h b/daemon/src/media/video/video_provider.h index 37ad819e347445c9d71a293b414e70a553e8631d..d724e163efac39331059115dc2feb55dfe4f912c 100644 --- a/daemon/src/media/video/video_provider.h +++ b/daemon/src/media/video/video_provider.h @@ -39,6 +39,6 @@ class VideoProvider { virtual ~VideoProvider() {} }; -}} +}} // namespace ring::video #endif // VIDEO_PROVIDER_H_ diff --git a/daemon/src/media/video/video_receive_thread.cpp b/daemon/src/media/video/video_receive_thread.cpp index cccac927cb9d8239fbb95e1f63fede100fe72d6d..9cd8493a4e6321af72fbc98dc29239b1b87cab0b 100644 --- a/daemon/src/media/video/video_receive_thread.cpp +++ b/daemon/src/media/video/video_receive_thread.cpp @@ -173,7 +173,7 @@ int VideoReceiveThread::readFunction(void *opaque, uint8_t *buf, int buf_size) return is.gcount(); } -void VideoReceiveThread::addIOContext(ring::SocketPair &socketPair) +void VideoReceiveThread::addIOContext(SocketPair &socketPair) { demuxContext_ = socketPair.createIOContext(); } @@ -255,4 +255,4 @@ int VideoReceiveThread::getHeight() const int VideoReceiveThread::getPixelFormat() const { return videoDecoder_->getPixelFormat(); } -}} //namespace ring //namespace video +}} // namespace ring::video diff --git a/daemon/src/media/video/video_receive_thread.h b/daemon/src/media/video/video_receive_thread.h index cd858e9adaf975b2cc5d6dc32880b6fb8efa3ae9..2961acbe987d06eab9f810d7299411a8e6122f40 100644 --- a/daemon/src/media/video/video_receive_thread.h +++ b/daemon/src/media/video/video_receive_thread.h @@ -44,10 +44,10 @@ #include <memory> namespace ring { - class SocketPair; +} // namespace ring - namespace video { +namespace ring { namespace video { class VideoReceiveThread : public VideoGenerator { public: @@ -98,6 +98,6 @@ private: void cleanup(); }; -}} +}} // namespace ring::video #endif // _VIDEO_RECEIVE_THREAD_H_ diff --git a/daemon/src/media/video/video_rtp_session.cpp b/daemon/src/media/video/video_rtp_session.cpp index dae710221edec927513eb484f0896c4bdb3ba9ff..ea73d238299a1ec79d5fa8be9b87f8ae03046b38 100644 --- a/daemon/src/media/video/video_rtp_session.cpp +++ b/daemon/src/media/video/video_rtp_session.cpp @@ -47,7 +47,6 @@ namespace ring { namespace video { -using ring::SocketPair; using std::map; using std::string; @@ -199,8 +198,8 @@ void VideoRtpSession::start(int localPort) } } -void VideoRtpSession::start(std::unique_ptr<ring::IceSocket> rtp_sock, - std::unique_ptr<ring::IceSocket> rtcp_sock) +void VideoRtpSession::start(std::unique_ptr<IceSocket> rtp_sock, + std::unique_ptr<IceSocket> rtcp_sock) { std::lock_guard<std::recursive_mutex> lock(mutex_); @@ -313,4 +312,4 @@ void VideoRtpSession::exitConference() conference_ = nullptr; } -}} //namespace ring //namespace video +}} // namespace ring::video diff --git a/daemon/src/media/video/video_rtp_session.h b/daemon/src/media/video/video_rtp_session.h index 9fe90fe674cbc5fabf46aa73324f946eafa19694..705670d6cd8b3d184f454a3ae017e49161360b89 100644 --- a/daemon/src/media/video/video_rtp_session.h +++ b/daemon/src/media/video/video_rtp_session.h @@ -44,13 +44,10 @@ #include <memory> #include <mutex> +namespace ring { class Sdp; class Conference; - -namespace ring { - class IceSocket; - class SocketPair; -}; +} // namespace ring namespace ring { namespace video { @@ -61,8 +58,8 @@ public: ~VideoRtpSession(); void start(int localPort); - void start(std::unique_ptr<ring::IceSocket> rtp_sock, - std::unique_ptr<ring::IceSocket> rtcp_sock); + void start(std::unique_ptr<IceSocket> rtp_sock, + std::unique_ptr<IceSocket> rtcp_sock); void stop(); void updateDestination(const std::string &destination, unsigned int port); @@ -83,7 +80,7 @@ private: // all public methods must be locked internally before use std::recursive_mutex mutex_ = {}; - std::unique_ptr<ring::SocketPair> socketPair_ = nullptr; + std::unique_ptr<SocketPair> socketPair_ = nullptr; std::unique_ptr<VideoSender> sender_ = nullptr; std::unique_ptr<VideoReceiveThread> receiveThread_ = nullptr; std::map<std::string, std::string> txArgs_; @@ -96,6 +93,6 @@ private: std::shared_ptr<VideoFrameActiveWriter> videoLocal_ = nullptr; }; -}} +}} // namespace ring::video #endif // __VIDEO_RTP_SESSION_H__ diff --git a/daemon/src/media/video/video_scaler.cpp b/daemon/src/media/video/video_scaler.cpp index 79b4cf5cf5b7bb3f2d1821a0c9b339b2df727cc3..9eb467a9a8f952ef1e0424e5ccc7f9e25f17edb8 100644 --- a/daemon/src/media/video/video_scaler.cpp +++ b/daemon/src/media/video/video_scaler.cpp @@ -158,4 +158,4 @@ void VideoScaler::reset() } } -}} +}} // namespace ring::video diff --git a/daemon/src/media/video/video_scaler.h b/daemon/src/media/video/video_scaler.h index 223ee27e0dbbbddef68f7afe81022c22925fe1f5..2f0cfe20efde19b9057957aae721e7fff806125c 100644 --- a/daemon/src/media/video/video_scaler.h +++ b/daemon/src/media/video/video_scaler.h @@ -59,6 +59,6 @@ private: uint8_t *tmp_data_[4]; // used by scale_and_pad }; -}} +}} // namespace ring::video #endif // __VIDEO_SCALER_H__ diff --git a/daemon/src/media/video/video_sender.cpp b/daemon/src/media/video/video_sender.cpp index 06d8ae07be51a2b5ca465db424dcd99bfeaacbfc..d2b58b6eebe05936ba16933f97aa352f74ad4820 100644 --- a/daemon/src/media/video/video_sender.cpp +++ b/daemon/src/media/video/video_sender.cpp @@ -39,7 +39,6 @@ #include <map> #include <unistd.h> - namespace ring { namespace video { using std::string; @@ -83,4 +82,4 @@ void VideoSender::forceKeyFrame() ++forceKeyFrame_; } -}} //namespace ring //namespace video +}} // namespace ring::video diff --git a/daemon/src/media/video/video_sender.h b/daemon/src/media/video/video_sender.h index 78aea60cd51631d32d34b8a156ab3d3bcebd683b..50bc932603ceb024f261fe315c110b3886a68306 100644 --- a/daemon/src/media/video/video_sender.h +++ b/daemon/src/media/video/video_sender.h @@ -75,6 +75,6 @@ private: std::string sdp_ = ""; }; -}} +}} // namespace ring::video #endif // __VIDEO_SENDER_H__ diff --git a/daemon/src/numbercleaner.cpp b/daemon/src/numbercleaner.cpp index a79b6780cf6dedbd551fd0aac8915fca04264434..0208de5fb25e5094cc25d0a01779be3c6137f146 100644 --- a/daemon/src/numbercleaner.cpp +++ b/daemon/src/numbercleaner.cpp @@ -34,6 +34,8 @@ #define INVALID_CHAR " -()" +namespace ring { namespace NumberCleaner { + static void strip_chars(const std::string &to_strip, std::string &num) { @@ -41,7 +43,8 @@ strip_chars(const std::string &to_strip, std::string &num) num.erase(std::remove(num.begin(), num.end(), item), num.end()); } -std::string NumberCleaner::clean(std::string to_clean, const std::string &prefix) +std::string +clean(std::string to_clean, const std::string &prefix) { size_t pos; //Hostname and DNS can have '-' @@ -55,3 +58,5 @@ std::string NumberCleaner::clean(std::string to_clean, const std::string &prefix return high+to_clean.substr(pos+1); } } + +}} // namespace ring::NumberCleaner diff --git a/daemon/src/numbercleaner.h b/daemon/src/numbercleaner.h index ee395eac5865bdf5aa629853e87ce117bfa9205c..22c557fe734897651f63d09b87350c3bce9dbc8d 100644 --- a/daemon/src/numbercleaner.h +++ b/daemon/src/numbercleaner.h @@ -34,8 +34,10 @@ #include <string> -namespace NumberCleaner { +namespace ring { namespace NumberCleaner { + std::string clean(std::string to_clean, const std::string &prefix = ""); -} + +}} // namespace ring::NumberCleaner #endif // _NUMBER_CLEANER_H_ diff --git a/daemon/src/plugin_loader.h b/daemon/src/plugin_loader.h index f27bb67196b314277110620da0cbc656ca301cd4..4455cd8c7d2954f72ee3a252be98c3992977f96d 100644 --- a/daemon/src/plugin_loader.h +++ b/daemon/src/plugin_loader.h @@ -34,6 +34,8 @@ #include <string> +namespace ring { + class Plugin { public: @@ -50,4 +52,6 @@ class Plugin Plugin() = default; }; +} // namespace ring + #endif /* PLUGIN_LOADER_H */ diff --git a/daemon/src/plugin_loader_dl.cpp b/daemon/src/plugin_loader_dl.cpp index 8bc6612ab626b12e84d62d7c302673bafe849bc7..bf358200f65c5dd775b7a2e4953950be16cb3d9b 100644 --- a/daemon/src/plugin_loader_dl.cpp +++ b/daemon/src/plugin_loader_dl.cpp @@ -33,6 +33,8 @@ #include <dlfcn.h> #include <memory> +namespace ring { + class DLPlugin : public Plugin { public: @@ -75,3 +77,5 @@ Plugin::load(const std::string& path, std::string& error) return new DLPlugin(handle); } + +} // namespace ring diff --git a/daemon/src/plugin_manager.cpp b/daemon/src/plugin_manager.cpp index 767816e0755d0d1d6d38c750c92de79b817a761a..41e74c3113a822e831785ba877774263aac41636 100644 --- a/daemon/src/plugin_manager.cpp +++ b/daemon/src/plugin_manager.cpp @@ -34,6 +34,8 @@ #include <utility> +namespace ring { + PluginManager::PluginManager() { pluginApi_.context = reinterpret_cast<void*>(this); @@ -258,3 +260,5 @@ PluginManager::invokeService_(const RING_PluginAPI* api, const char* name, return manager->invokeService(name, data); } + +} // namespace ring diff --git a/daemon/src/plugin_manager.h b/daemon/src/plugin_manager.h index a94bc297aa3590907f74e0e3a0f884990f0b68c7..1c04f160576de97f8fa2895dfd52a40904bc10fe 100644 --- a/daemon/src/plugin_manager.h +++ b/daemon/src/plugin_manager.h @@ -43,6 +43,8 @@ #include <inttypes.h> +namespace ring { + class Plugin; class PluginManager @@ -159,4 +161,6 @@ class PluginManager std::map<std::string, ServiceFunction> services_ {{}}; }; +} // namespace ring + #endif /* PLUGIN_MANAGER_H */ diff --git a/daemon/src/preferences.cpp b/daemon/src/preferences.cpp index 3ce9dea63170a35cba5e91bec8256a50eda1c7c7..504c34fbc3e7c22631ebf3652f7473b70bc29bea 100644 --- a/daemon/src/preferences.cpp +++ b/daemon/src/preferences.cpp @@ -60,6 +60,10 @@ #include <algorithm> #include "fileutils.h" +namespace ring { + +using yaml_utils::parseValue; + constexpr const char * const Preferences::CONFIG_LABEL; const char * const Preferences::DFT_ZONE = "North America"; const char * const Preferences::REGISTRATION_EXPIRE_KEY = "registrationexpire"; @@ -137,10 +141,8 @@ Preferences::Preferences() : void Preferences::verifyAccountOrder(const std::vector<std::string> &accountIDs) { - using namespace std; - - vector<string> tokens; - string token; + std::vector<std::string> tokens; + std::string token; bool drop = false; for (const auto c : accountOrder_) { @@ -198,7 +200,6 @@ void Preferences::serialize(YAML::Emitter &out) void Preferences::unserialize(const YAML::Node &in) { - using namespace yaml_utils; const auto &node = in[CONFIG_LABEL]; parseValue(node, ORDER_KEY, accountOrder_); @@ -232,7 +233,6 @@ void VoipPreference::serialize(YAML::Emitter &out) void VoipPreference::unserialize(const YAML::Node &in) { - using namespace yaml_utils; const auto &node = in[CONFIG_LABEL]; parseValue(node, PLAY_DTMF_KEY, playDtmf_); parseValue(node, PLAY_TONES_KEY, playTones_); @@ -285,7 +285,6 @@ void HookPreference::serialize(YAML::Emitter &out) void HookPreference::unserialize(const YAML::Node &in) { - using namespace yaml_utils; const auto &node = in[CONFIG_LABEL]; parseValue(node, IAX2_ENABLED_KEY, iax2Enabled_); @@ -328,26 +327,26 @@ AudioPreference::AudioPreference() : static const int ALSA_DFT_CARD_ID = 0; // Index of the default soundcard static void -checkSoundCard(int &card, ring::DeviceType type) +checkSoundCard(int &card, DeviceType type) { - if (not ring::AlsaLayer::soundCardIndexExists(card, type)) { + if (not AlsaLayer::soundCardIndexExists(card, type)) { RING_WARN(" Card with index %d doesn't exist or is unusable.", card); card = ALSA_DFT_CARD_ID; } } #endif -ring::AudioLayer* AudioPreference::createAudioLayer() +AudioLayer* AudioPreference::createAudioLayer() { #if HAVE_OPENSL - return new ring::OpenSLLayer(*this); + return new OpenSLLayer(*this); #else #if HAVE_JACK if (audioApi_ == JACK_API_STR) { if (system("jack_lsp > /dev/null") == 0) { try { - return new ring::JackLayer(*this); + return new JackLayer(*this); } catch (const std::runtime_error &e) { RING_ERR("%s", e.what()); #if HAVE_PULSE @@ -369,7 +368,7 @@ ring::AudioLayer* AudioPreference::createAudioLayer() if (audioApi_ == PULSEAUDIO_API_STR) { try { - return new ring::PulseLayer(*this); + return new PulseLayer(*this); } catch (const std::runtime_error &e) { RING_WARN("Could not create pulseaudio layer, falling back to ALSA"); } @@ -380,17 +379,17 @@ ring::AudioLayer* AudioPreference::createAudioLayer() #if HAVE_ALSA audioApi_ = ALSA_API_STR; - checkSoundCard(alsaCardin_, ring::DeviceType::CAPTURE); - checkSoundCard(alsaCardout_, ring::DeviceType::PLAYBACK); - checkSoundCard(alsaCardring_, ring::DeviceType::RINGTONE); + checkSoundCard(alsaCardin_, DeviceType::CAPTURE); + checkSoundCard(alsaCardout_, DeviceType::PLAYBACK); + checkSoundCard(alsaCardring_, DeviceType::RINGTONE); - return new ring::AlsaLayer(*this); + return new AlsaLayer(*this); #endif #if HAVE_COREAUDIO audioApi_ = COREAUDIO_API_STR; try { - return new ring::CoreLayer(*this); + return new CoreLayer(*this); } catch (const std::runtime_error &e) { RING_WARN("Could not create coreaudio layer. There will be no sound."); } @@ -450,7 +449,6 @@ AudioPreference::setRecordPath(const std::string &r) void AudioPreference::unserialize(const YAML::Node &in) { - using namespace yaml_utils; const auto &node = in[CONFIG_LABEL]; // alsa submap @@ -521,7 +519,6 @@ void ShortcutPreferences::serialize(YAML::Emitter &out) void ShortcutPreferences::unserialize(const YAML::Node &in) { - using namespace yaml_utils; const auto &node = in[CONFIG_LABEL]; parseValue(node, HANGUP_SHORT_KEY, hangup_); @@ -531,3 +528,4 @@ void ShortcutPreferences::unserialize(const YAML::Node &in) parseValue(node, TOGGLE_PICKUP_HANGUP_SHORT_KEY, togglePickupHangup_); } +} // namespace ring diff --git a/daemon/src/preferences.h b/daemon/src/preferences.h index a3e081a99e3a1d4782a9185471c77a333c300bdf..54887d326565a5c89f54106e3ae45e11215dd549 100644 --- a/daemon/src/preferences.h +++ b/daemon/src/preferences.h @@ -36,15 +36,17 @@ #include <map> #include <vector> -namespace ring { - class AudioLayer; -} - namespace YAML { class Emitter; class Node; } +struct pjsip_msg; + +namespace ring { + +class AudioLayer; + class Preferences : public Serializable { public: static const char * const DFT_ZONE; @@ -190,8 +192,6 @@ class VoipPreference : public Serializable { constexpr static const char * const CONFIG_LABEL = "voipPreferences"; }; -struct pjsip_msg; - class HookPreference : public Serializable { public: HookPreference(); @@ -226,8 +226,8 @@ class HookPreference : public Serializable { class AudioPreference : public Serializable { public: AudioPreference(); - ring::AudioLayer *createAudioLayer(); - ring::AudioLayer *switchAndCreateAudioLayer(); + AudioLayer *createAudioLayer(); + AudioLayer *switchAndCreateAudioLayer(); std::string getAudioApi() const { return audioApi_; @@ -451,4 +451,6 @@ class ShortcutPreferences : public Serializable { constexpr static const char * const CONFIG_LABEL = "shortcuts"; }; +} // namespace ring + #endif diff --git a/daemon/src/registration_states.h b/daemon/src/registration_states.h index fd4ed74c978176599b5c4045ef2edbf28a67d89f..5b72325b44287fe0701cb04f00767d5633dea0c7 100644 --- a/daemon/src/registration_states.h +++ b/daemon/src/registration_states.h @@ -32,6 +32,8 @@ #ifndef REGISTRATION_STATES_H_ #define REGISTRATION_STATES_H_ +namespace ring { + /** Contains all the Registration states for an account can be in */ enum class RegistrationState { UNREGISTERED, @@ -46,4 +48,6 @@ enum class RegistrationState { ERROR_NOT_ACCEPTABLE }; +} // namespace ring + #endif // REGISTRATION_STATES_H_ diff --git a/daemon/src/ring_api.cpp b/daemon/src/ring_api.cpp index d0592e02201543a913fcca1f5910165b597ecacf..327f3f464ac4bc168fa0164292f21d805c73a088 100644 --- a/daemon/src/ring_api.cpp +++ b/daemon/src/ring_api.cpp @@ -48,25 +48,25 @@ #include "client/videomanager.h" #endif // RING_VIDEO -static CallManager* getCallManager() +static ring::CallManager* getCallManager() { - return Manager::instance().getClient()->getCallManager(); + return ring::Manager::instance().getClient()->getCallManager(); } -static ConfigurationManager* getConfigurationManager() +static ring::ConfigurationManager* getConfigurationManager() { - return Manager::instance().getClient()->getConfigurationManager(); + return ring::Manager::instance().getClient()->getConfigurationManager(); } -static PresenceManager* getPresenceManager() +static ring::PresenceManager* getPresenceManager() { - return Manager::instance().getClient()->getPresenceManager(); + return ring::Manager::instance().getClient()->getPresenceManager(); } #ifdef RING_VIDEO -static VideoManager* getVideoManager() +static ring::VideoManager* getVideoManager() { - return Manager::instance().getClient()->getVideoManager(); + return ring::Manager::instance().getClient()->getVideoManager(); } #endif // RING_VIDEO @@ -92,10 +92,10 @@ int ring_init(ring_ev_handlers* ev_handlers, enum ring_init_flag flags) // Create manager try { // FIXME: static evil - static ManagerImpl *manager; + static ring::ManagerImpl *manager; // ensure that we haven't been in this function before assert(!manager); - manager = &(Manager::instance()); + manager = &(ring::Manager::instance()); } catch (...) { return -RING_ERR_MANAGER_INIT; } @@ -111,7 +111,7 @@ int ring_init(ring_ev_handlers* ev_handlers, enum ring_init_flag flags) // Initialize manager now try { - Manager::instance().init(""); + ring::Manager::instance().init(""); } catch (...) { return -RING_ERR_MANAGER_INIT; } @@ -122,12 +122,12 @@ int ring_init(ring_ev_handlers* ev_handlers, enum ring_init_flag flags) void ring_fini(void) { // Finish manager - Manager::instance().finish(); + ring::Manager::instance().finish(); } void ring_poll_events() { - Manager::instance().pollEvents(); + ring::Manager::instance().pollEvents(); } bool ring_call_place(const std::string& account_id, const std::string& call_id, const std::string& to) diff --git a/daemon/src/ring_types.h b/daemon/src/ring_types.h index 04c26d015b4250c97ff85e270942bc7b45e92d91..130a94680ca8445c31b3dcfefa8ebeec317d0702 100644 --- a/daemon/src/ring_types.h +++ b/daemon/src/ring_types.h @@ -36,8 +36,8 @@ #include <cstddef> // for size_t namespace ring { + typedef int16_t AudioSample; -} static constexpr size_t SIZEBUF = 32000; /** About 1s of buffering at 48kHz */ @@ -69,4 +69,6 @@ getGlobalInstance() return wlink.lock(); } +} // namespace ring + #endif // RING_TYPES_H_ diff --git a/daemon/src/ringdht/ringaccount.cpp b/daemon/src/ringdht/ringaccount.cpp index 338aaccb7a0dc3a0f19889069767377f75522843..f0e5bd722362280286a4a81352274d0b67299cf1 100644 --- a/daemon/src/ringdht/ringaccount.cpp +++ b/daemon/src/ringdht/ringaccount.cpp @@ -67,6 +67,8 @@ #include <sstream> #include <cctype> +namespace ring { + static constexpr int ICE_COMPONENTS {1}; static constexpr int ICE_COMP_SIP_TRANSPORT {0}; static constexpr int ICE_INIT_TIMEOUT {5}; @@ -232,11 +234,11 @@ RingAccount::createOutgoingCall(const std::shared_ptr<SIPCall>& call, const std: // Initialize the session using ULAW as default codec in case of early media // The session should be ready to receive media once the first INVITE is sent, before // the session initialization is completed - ring::AudioCodec* ac = Manager::instance().audioCodecFactory.instantiateCodec(PAYLOAD_CODEC_ULAW); + AudioCodec* ac = Manager::instance().audioCodecFactory.instantiateCodec(PAYLOAD_CODEC_ULAW); if (!ac) throw VoipLinkException("Could not instantiate codec for early media"); - std::vector<ring::AudioCodec *> audioCodecs; + std::vector<AudioCodec *> audioCodecs; audioCodecs.push_back(ac); // Building the local SDP offer @@ -344,17 +346,15 @@ RingAccount::SIPStartCall(const std::shared_ptr<SIPCall>& call, IpAddr target) void RingAccount::serialize(YAML::Emitter &out) { - using namespace Conf; - out << YAML::BeginMap; SIPAccountBase::serialize(out); - out << YAML::Key << DHT_PORT_KEY << YAML::Value << dhtPort_; - out << YAML::Key << DHT_PRIVKEY_PATH_KEY << YAML::Value << privkeyPath_; - out << YAML::Key << DHT_CERT_PATH_KEY << YAML::Value << certPath_; - out << YAML::Key << DHT_CA_CERT_PATH_KEY << YAML::Value << cacertPath_; + out << YAML::Key << Conf::DHT_PORT_KEY << YAML::Value << dhtPort_; + out << YAML::Key << Conf::DHT_PRIVKEY_PATH_KEY << YAML::Value << privkeyPath_; + out << YAML::Key << Conf::DHT_CERT_PATH_KEY << YAML::Value << certPath_; + out << YAML::Key << Conf::DHT_CA_CERT_PATH_KEY << YAML::Value << cacertPath_; // tls submap - out << YAML::Key << TLS_KEY << YAML::Value << YAML::BeginMap; + out << YAML::Key << Conf::TLS_KEY << YAML::Value << YAML::BeginMap; SIPAccountBase::serializeTls(out); out << YAML::EndMap; @@ -363,7 +363,8 @@ void RingAccount::serialize(YAML::Emitter &out) void RingAccount::unserialize(const YAML::Node &node) { - using namespace yaml_utils; + using yaml_utils::parseValue; + SIPAccountBase::unserialize(node); in_port_t port {DHT_DEFAULT_PORT}; parseValue(node, Conf::DHT_PORT_KEY, port); @@ -486,11 +487,11 @@ void RingAccount::setAccountDetails(const std::map<std::string, std::string> &de SIPAccountBase::setAccountDetails(details); if (hostname_ == "") hostname_ = DHT_DEFAULT_BOOTSTRAP; - parseInt(details, CONFIG_DHT_PORT, dhtPort_); + parseInt(details, Conf::CONFIG_DHT_PORT, dhtPort_); if (dhtPort_ == 0) dhtPort_ = DHT_DEFAULT_PORT; - parseString(details, CONFIG_DHT_PRIVKEY_PATH, privkeyPath_); - parseString(details, CONFIG_DHT_CERT_PATH, certPath_); + parseString(details, Conf::CONFIG_DHT_PRIVKEY_PATH, privkeyPath_); + parseString(details, Conf::CONFIG_DHT_CERT_PATH, certPath_); checkIdentityPath(); } @@ -500,9 +501,9 @@ std::map<std::string, std::string> RingAccount::getAccountDetails() const std::stringstream dhtport; dhtport << dhtPort_; - a[CONFIG_DHT_PORT] = dhtport.str(); - a[CONFIG_DHT_PRIVKEY_PATH] = privkeyPath_; - a[CONFIG_DHT_CERT_PATH] = certPath_; + a[Conf::CONFIG_DHT_PORT] = dhtport.str(); + a[Conf::CONFIG_DHT_PRIVKEY_PATH] = privkeyPath_; + a[Conf::CONFIG_DHT_CERT_PATH] = certPath_; return a; } @@ -1017,3 +1018,5 @@ void RingAccount::updateDialogViaSentBy(pjsip_dialog *dlg) pjsip_dlg_set_via_sent_by(dlg, &via_addr_, via_tp_); } */ + +} // namespace ring diff --git a/daemon/src/ringdht/ringaccount.h b/daemon/src/ringdht/ringaccount.h index 9089c647465c0e8ed59cc9dad3dc57d8a9c9c8b5..1d43b2a1c261d6fbb9cabc9e6004b8443b7d5f44 100644 --- a/daemon/src/ringdht/ringaccount.h +++ b/daemon/src/ringdht/ringaccount.h @@ -49,6 +49,18 @@ #include <map> #include <chrono> +/** + * @file sipaccount.h + * @brief A SIP Account specify SIP specific functions and object = SIPCall/SIPVoIPLink) + */ + +namespace YAML { +class Node; +class Emitter; +} + +namespace ring { + namespace Conf { const char *const DHT_PORT_KEY = "dhtPort"; const char *const DHT_PRIVKEY_PATH_KEY = "dhtPrivkeyPath"; @@ -58,15 +70,6 @@ namespace Conf { const char *const DHT_VALUES_PATH_KEY = "dhtValuesPath"; } -namespace YAML { - class Node; - class Emitter; -} - -/** - * @file sipaccount.h - * @brief A SIP Account specify SIP specific functions and object = SIPCall/SIPVoIPLink) - */ class RingAccount : public SIPAccountBase { public: constexpr static const char * const ACCOUNT_TYPE = "RING"; @@ -290,7 +293,7 @@ class RingAccount : public SIPAccountBase { struct PendingCall { std::chrono::steady_clock::time_point start; - std::shared_ptr<ring::IceTransport> ice; + std::shared_ptr<IceTransport> ice; std::shared_ptr<SIPCall> call; dht::InfoHash id; }; @@ -373,4 +376,6 @@ class RingAccount : public SIPAccountBase { }; +} // namespace ring + #endif diff --git a/daemon/src/ringdht/sip_transport_ice.cpp b/daemon/src/ringdht/sip_transport_ice.cpp index d7410981e2906af68dd74b623ac07b770cf8e445..af01be27d28591ffb6ab5cc61262000ba31b006b 100644 --- a/daemon/src/ringdht/sip_transport_ice.cpp +++ b/daemon/src/ringdht/sip_transport_ice.cpp @@ -39,6 +39,8 @@ #include <algorithm> +namespace ring { + static constexpr int POOL_TP_INIT {512}; static constexpr int POOL_TP_INC {512}; static constexpr int TRANSPORT_INFO_LENGTH {64}; @@ -56,7 +58,7 @@ sockaddr_to_host_port(pj_pool_t* pool, SipIceTransport::SipIceTransport(pjsip_endpoint* endpt, pj_pool_t& /* pool */, long /* t_type */, - const std::shared_ptr<ring::IceTransport>& ice, + const std::shared_ptr<IceTransport>& ice, int comp_id, std::function<int()> destroy_cb) : base() , pool_(nullptr, pj_pool_release) @@ -252,3 +254,5 @@ SipIceTransport::destroy() RING_WARN("SIP transport ICE: destroy"); return destroy_cb_(); } + +} // namespace ring diff --git a/daemon/src/ringdht/sip_transport_ice.h b/daemon/src/ringdht/sip_transport_ice.h index 3665b15f4b77e96344284e1b53762344a6807c0a..47aba2f35e643dfdcab25ca15b43ee8038395acf 100644 --- a/daemon/src/ringdht/sip_transport_ice.h +++ b/daemon/src/ringdht/sip_transport_ice.h @@ -40,13 +40,13 @@ #include <memory> namespace ring { + class IceTransport; -} struct SipIceTransport { SipIceTransport(pjsip_endpoint* endpt, pj_pool_t& pool, long t_type, - const std::shared_ptr<ring::IceTransport>& ice, + const std::shared_ptr<IceTransport>& ice, int comp_id, std::function<int()> destroy_cb); ~SipIceTransport(); @@ -57,7 +57,7 @@ struct SipIceTransport IpAddr getLocalAddress() const; - std::shared_ptr<ring::IceTransport> getIceTransport() const { + std::shared_ptr<IceTransport> getIceTransport() const { return ice_; } @@ -69,7 +69,7 @@ struct SipIceTransport pjsip_rx_data rdata; bool is_registered_ {false}; - const std::shared_ptr<ring::IceTransport> ice_; + const std::shared_ptr<IceTransport> ice_; const int comp_id_; std::function<int()> destroy_cb_ {}; @@ -84,3 +84,5 @@ struct SipIceTransport pj_status_t destroy(); }; + +} // namespace ring diff --git a/daemon/src/rw_mutex.h b/daemon/src/rw_mutex.h index e346a235424d9e15ee89eff8270bd3357be9923d..466465a04c166698d91d86172ecaf6b6ab8c049b 100644 --- a/daemon/src/rw_mutex.h +++ b/daemon/src/rw_mutex.h @@ -121,6 +121,6 @@ class rw_mutex { bool writing; }; -} +} // namespace ring #endif diff --git a/daemon/src/sip/pattern.cpp b/daemon/src/sip/pattern.cpp index 46eb35f450836066bb23329acc513f06d94aec3d..340e47d65491453aafd4512eea19f1ba1a656dce 100644 --- a/daemon/src/sip/pattern.cpp +++ b/daemon/src/sip/pattern.cpp @@ -159,4 +159,5 @@ std::vector<std::string> Pattern::split() tokenStart - tokenEnd - 1)); return substringSplitted; } -} + +} // namespace ring diff --git a/daemon/src/sip/pres_sub_client.cpp b/daemon/src/sip/pres_sub_client.cpp index 269285e6b2b5554510bf3cc6420ddbdb54f8e774..8a85819cc7fa5084fdf1ee8f8fcd6a0a3ae37983 100644 --- a/daemon/src/sip/pres_sub_client.cpp +++ b/daemon/src/sip/pres_sub_client.cpp @@ -58,6 +58,8 @@ #define PRES_TIMER 300 // 5min +namespace ring { + int PresSubClient::modId_ = 0; // used to extract data structure from event_subscription void @@ -614,3 +616,5 @@ bool PresSubClient::match(PresSubClient *b) { return (b->getURI() == getURI()); } + +} // namespace ring diff --git a/daemon/src/sip/pres_sub_client.h b/daemon/src/sip/pres_sub_client.h index e99709b563414518a171537f341609efdd891c67..19398ab68bee97eb54c155443949c0da4726b2bb 100644 --- a/daemon/src/sip/pres_sub_client.h +++ b/daemon/src/sip/pres_sub_client.h @@ -42,6 +42,8 @@ #include <pjsip/sip_transport.h> #include "noncopyable.h" +namespace ring { + class SIPPresence; class PresSubClient { @@ -182,4 +184,6 @@ class PresSubClient { static int modId_; // used to extract data structure from event_subscription }; +} // namespace ring + #endif /* PRES_SUB_CLIENT_H */ diff --git a/daemon/src/sip/pres_sub_server.cpp b/daemon/src/sip/pres_sub_server.cpp index 2a52c7feab15f0383f59afed4cbdf22f29bc0a54..85a0cbf82f5f0916c0fdb49a171759bf306e6366 100644 --- a/daemon/src/sip/pres_sub_server.cpp +++ b/daemon/src/sip/pres_sub_server.cpp @@ -40,6 +40,8 @@ #include "logger.h" #include "pres_sub_server.h" +namespace ring { + /* Callback called when *server* subscription state has changed. */ void PresSubServer::pres_evsub_on_srv_state(pjsip_evsub *sub, pjsip_event *event) @@ -346,3 +348,5 @@ void PresSubServer::notify() } } } + +} // namespace ring diff --git a/daemon/src/sip/pres_sub_server.h b/daemon/src/sip/pres_sub_server.h index af3e848871016003d406be580f2cb2a7bb36f959..e75423537c9305eaeee9b8a6b75b8a97cadb771d 100644 --- a/daemon/src/sip/pres_sub_server.h +++ b/daemon/src/sip/pres_sub_server.h @@ -42,6 +42,8 @@ #include "noncopyable.h" #include "array_size.h" +namespace ring { + extern pj_bool_t pres_on_rx_subscribe_request(pjsip_rx_data *rdata); class SIPpresence; @@ -88,5 +90,6 @@ class PresSubServer { bool approved_; }; +} // namespace ring #endif /* SERVERPRESENCESUB_H */ diff --git a/daemon/src/sip/sdes_negotiator.cpp b/daemon/src/sip/sdes_negotiator.cpp index 33076c4649feec1104080ab83b8de954f5a42d17..22091418320efc384a7783eb0a2f5fd36f91933b 100644 --- a/daemon/src/sip/sdes_negotiator.cpp +++ b/daemon/src/sip/sdes_negotiator.cpp @@ -38,7 +38,7 @@ #include <algorithm> #include <stdexcept> -using namespace ring; +namespace ring { SdesNegotiator::SdesNegotiator(const std::vector<CryptoSuiteDefinition>& localCapabilites, const std::vector<std::string>& remoteAttribute) : @@ -208,3 +208,5 @@ bool SdesNegotiator::negotiate() return negotiationSuccess; } + +} // namespace ring diff --git a/daemon/src/sip/sdp.cpp b/daemon/src/sip/sdp.cpp index 136bef2c0e63d8ca81f9c3297a4a526782a5529f..4a221280824a7fb19bf19d92560d1655b0febfab 100644 --- a/daemon/src/sip/sdp.cpp +++ b/daemon/src/sip/sdp.cpp @@ -45,6 +45,8 @@ #include <algorithm> #include <cassert> +namespace ring { + using std::string; using std::map; using std::vector; @@ -94,7 +96,7 @@ Sdp::~Sdp() } static bool -hasPayload(const std::vector<ring::AudioCodec*> &codecs, int pt) +hasPayload(const std::vector<AudioCodec*> &codecs, int pt) { for (const auto &i : codecs) if (i and i->getPayloadType() == pt) @@ -120,7 +122,7 @@ rtpmapToString(pjmedia_sdp_rtpmap *rtpmap) return os.str(); } -static ring::AudioCodec * +static AudioCodec * findCodecByName(const std::string &codec) { // try finding by name @@ -242,10 +244,10 @@ string Sdp::getSessionVideoCodec() const return sessionVideoMedia_[0]; } -std::vector<ring::AudioCodec*> +std::vector<AudioCodec*> Sdp::getSessionAudioMedia() const { - vector<ring::AudioCodec*> codecs; + vector<AudioCodec*> codecs; // Common codecs first for (auto c : sessionAudioMediaLocal_) { @@ -292,7 +294,7 @@ Sdp::setMediaDescriptorLines(bool audio) const char *channels = ""; if (audio) { - ring::AudioCodec *codec = audio_codec_list_[i]; + AudioCodec *codec = audio_codec_list_[i]; payload = codec->getPayloadType(); enc_name = codec->getMimeSubtype(); clock_rate = codec->getSDPClockRate(); @@ -972,7 +974,7 @@ Sdp::getIceCandidates(unsigned media_index) const } void -Sdp::addIceAttributes(const ring::IceTransport::Attribute&& ice_attrs) +Sdp::addIceAttributes(const IceTransport::Attribute&& ice_attrs) { pj_str_t value; pjmedia_sdp_attr *attr; @@ -990,10 +992,10 @@ Sdp::addIceAttributes(const ring::IceTransport::Attribute&& ice_attrs) throw SdpException("Could not add ICE.pwd attribute to local SDP"); } -ring::IceTransport::Attribute +IceTransport::Attribute Sdp::getIceAttributes() const { - ring::IceTransport::Attribute ice_attrs; + IceTransport::Attribute ice_attrs; auto session = remoteSession_ ? remoteSession_ : activeRemoteSession_; assert(session); @@ -1176,3 +1178,5 @@ bool Sdp::getOutgoingAudioSettings(map<string, string> &args) const } return false; } + +} // namespace ring diff --git a/daemon/src/sip/sdp.h b/daemon/src/sip/sdp.h index 18a4b0393906e6f6d61c504025350c99f66e16fb..71901c22d4fad864edff30f2333ee26f571f15b3 100644 --- a/daemon/src/sip/sdp.h +++ b/daemon/src/sip/sdp.h @@ -51,9 +51,13 @@ #include <stdexcept> namespace ring { -class AudioCodec; + +namespace test { +class SDPTest; } +class AudioCodec; + class SdpException : public std::runtime_error { public: SdpException(const std::string& str="") : @@ -266,14 +270,14 @@ class Sdp { void setMediaTransportInfoFromRemoteSdp(); std::string getSessionVideoCodec() const; - std::vector<ring::AudioCodec*> getSessionAudioMedia() const; + std::vector<AudioCodec*> getSessionAudioMedia() const; // Sets @param settings with appropriate values and returns true if // we are sending video, false otherwise bool getOutgoingVideoSettings(std::map<std::string, std::string> &settings) const; bool getOutgoingAudioSettings(std::map<std::string, std::string> &settings) const; - void addIceAttributes(const ring::IceTransport::Attribute&& ice_attrs); - ring::IceTransport::Attribute getIceAttributes() const; + void addIceAttributes(const IceTransport::Attribute&& ice_attrs); + IceTransport::Attribute getIceAttributes() const; void addIceCandidates(unsigned media_index, const std::vector<std::string>& cands); @@ -281,9 +285,9 @@ class Sdp { std::vector<std::string> getIceCandidates(unsigned media_index) const; private: + friend class test::SDPTest; NON_COPYABLE(Sdp); - friend class SDPTest; std::string getLineFromSession(const pjmedia_sdp_session *sess, const std::string &keyword) const; std::string getOutgoingVideoCodec() const; @@ -331,14 +335,14 @@ class Sdp { /** * Codec Map used for offer */ - std::vector<ring::AudioCodec *> audio_codec_list_; + std::vector<AudioCodec *> audio_codec_list_; std::vector<std::map<std::string, std::string> > video_codec_list_; /** * The codecs that will be used by the session (after the SDP negotiation) */ - std::vector<ring::AudioCodec *> sessionAudioMediaLocal_; - std::vector<ring::AudioCodec *> sessionAudioMediaRemote_; + std::vector<AudioCodec *> sessionAudioMediaLocal_; + std::vector<AudioCodec *> sessionAudioMediaRemote_; std::vector<std::string> sessionVideoMedia_; std::string publishedIpAddr_; @@ -404,5 +408,6 @@ class Sdp { void addRTCPAttribute(pjmedia_sdp_media *med); }; +} // namespace ring #endif diff --git a/daemon/src/sip/sip_utils.cpp b/daemon/src/sip/sip_utils.cpp index dbb4f4c2fcc79b8bafb710f19bc7b84907423f9c..0df195756ab3b4b6bf782edd7899a29b51aba0d8 100644 --- a/daemon/src/sip/sip_utils.cpp +++ b/daemon/src/sip/sip_utils.cpp @@ -51,8 +51,10 @@ #include <vector> #include <algorithm> +namespace ring { namespace sip_utils { + std::string -sip_utils::fetchHeaderValue(pjsip_msg *msg, const std::string &field) +fetchHeaderValue(pjsip_msg *msg, const std::string &field) { pj_str_t name = pj_str((char*) field.c_str()); pjsip_generic_string_hdr *hdr = static_cast<pjsip_generic_string_hdr*>(pjsip_msg_find_hdr_by_name(msg, &name, NULL)); @@ -71,7 +73,7 @@ sip_utils::fetchHeaderValue(pjsip_msg *msg, const std::string &field) } pjsip_route_hdr * -sip_utils::createRouteSet(const std::string &route, pj_pool_t *hdr_pool) +createRouteSet(const std::string &route, pj_pool_t *hdr_pool) { pjsip_route_hdr *route_set = pjsip_route_hdr_create(hdr_pool); @@ -99,7 +101,7 @@ sip_utils::createRouteSet(const std::string &route, pj_pool_t *hdr_pool) // FIXME: replace with regex std::string -sip_utils::parseDisplayName(const char * buffer) +parseDisplayName(const char * buffer) { // Start in From: in short and long form const char* from_header = strstr(buffer, "\nFrom: "); @@ -150,7 +152,7 @@ sip_utils::parseDisplayName(const char * buffer) } void -sip_utils::stripSipUriPrefix(std::string& sipUri) +stripSipUriPrefix(std::string& sipUri) { // Remove sip: prefix static const char SIP_PREFIX[] = "sip:"; @@ -175,7 +177,7 @@ sip_utils::stripSipUriPrefix(std::string& sipUri) } std::string -sip_utils::getHostFromUri(const std::string& sipUri) +getHostFromUri(const std::string& sipUri) { std::string hostname(sipUri); size_t found = hostname.find("@"); @@ -190,7 +192,7 @@ sip_utils::getHostFromUri(const std::string& sipUri) } void -sip_utils::addContactHeader(const pj_str_t *contact_str, pjsip_tx_data *tdata) +addContactHeader(const pj_str_t *contact_str, pjsip_tx_data *tdata) { pjsip_contact_hdr *contact = pjsip_contact_hdr_create(tdata->pool); contact->uri = pjsip_parse_uri(tdata->pool, contact_str->ptr, @@ -202,9 +204,11 @@ sip_utils::addContactHeader(const pj_str_t *contact_str, pjsip_tx_data *tdata) void -sip_utils::sip_strerror(pj_status_t code) +sip_strerror(pj_status_t code) { char err_msg[PJ_ERR_MSG_SIZE]; pj_strerror(code, err_msg, sizeof err_msg); RING_ERR("%d: %s", code, err_msg); } + +}} // namespace ring::sip_utils diff --git a/daemon/src/sip/sip_utils.h b/daemon/src/sip/sip_utils.h index ed416dce6102c2345c7cdec518c7c3c01dc45575..a1f7c23f42883b5618eb4e372b2ea04375cfc9cd 100644 --- a/daemon/src/sip/sip_utils.h +++ b/daemon/src/sip/sip_utils.h @@ -41,7 +41,8 @@ struct pjsip_msg; -namespace sip_utils { +namespace ring { namespace sip_utils { + /** * Helper function to parser header from incoming sip messages * @return Header from SIP message @@ -60,6 +61,7 @@ namespace sip_utils { void addContactHeader(const pj_str_t *contactStr, pjsip_tx_data *tdata); void sip_strerror(pj_status_t code); -} + +}} // namespace ring::sip_utils #endif // SIP_UTILS_H_ diff --git a/daemon/src/sip/sipaccount.cpp b/daemon/src/sip/sipaccount.cpp index e51b160f69213595e5260dbbc4001f0f42ea7be2..e6afd1daf03f287e426c06b1cfe518b8dfcd695c 100644 --- a/daemon/src/sip/sipaccount.cpp +++ b/daemon/src/sip/sipaccount.cpp @@ -70,6 +70,11 @@ #include <sstream> #include <cstdlib> +namespace ring { + +using yaml_utils::parseValue; +using yaml_utils::parseVectorMap; + static const int MIN_REGISTRATION_TIME = 60; static const int DEFAULT_REGISTRATION_TIME = 3600; static const char *const VALID_TLS_METHODS[] = {"Default", "TLSv1", "SSLv3", "SSLv23"}; @@ -228,11 +233,11 @@ SIPAccount::newOutgoingCall(const std::string& id, const std::string& toUrl) // Initialize the session using ULAW as default codec in case of early media // The session should be ready to receive media once the first INVITE is sent, before // the session initialization is completed - ring::AudioCodec* ac = Manager::instance().audioCodecFactory.instantiateCodec(PAYLOAD_CODEC_ULAW); + AudioCodec* ac = Manager::instance().audioCodecFactory.instantiateCodec(PAYLOAD_CODEC_ULAW); if (!ac) throw VoipLinkException("Could not instantiate codec for early media"); - std::vector<ring::AudioCodec *> audioCodecs; + std::vector<AudioCodec *> audioCodecs; audioCodecs.push_back(ac); // Building the local SDP offer @@ -347,55 +352,53 @@ SIPAccount::SIPStartCall(std::shared_ptr<SIPCall>& call) void SIPAccount::serialize(YAML::Emitter &out) { - using namespace Conf; - out << YAML::BeginMap; SIPAccountBase::serialize(out); // each credential is a map, and we can have multiple credentials - out << YAML::Key << CRED_KEY << YAML::Value << credentials_; - out << YAML::Key << KEEP_ALIVE_ENABLED << YAML::Value << keepAliveEnabled_; + out << YAML::Key << Conf::CRED_KEY << YAML::Value << credentials_; + out << YAML::Key << Conf::KEEP_ALIVE_ENABLED << YAML::Value << keepAliveEnabled_; out << YAML::Key << PRESENCE_MODULE_ENABLED_KEY << YAML::Value << (presence_ and presence_->isEnabled()); - out << YAML::Key << PRESENCE_PUBLISH_SUPPORTED_KEY << YAML::Value << (presence_ and presence_->isSupported(PRESENCE_FUNCTION_PUBLISH)); - out << YAML::Key << PRESENCE_SUBSCRIBE_SUPPORTED_KEY << YAML::Value << (presence_ and presence_->isSupported(PRESENCE_FUNCTION_SUBSCRIBE)); + out << YAML::Key << Conf::PRESENCE_PUBLISH_SUPPORTED_KEY << YAML::Value << (presence_ and presence_->isSupported(PRESENCE_FUNCTION_PUBLISH)); + out << YAML::Key << Conf::PRESENCE_SUBSCRIBE_SUPPORTED_KEY << YAML::Value << (presence_ and presence_->isSupported(PRESENCE_FUNCTION_SUBSCRIBE)); out << YAML::Key << Preferences::REGISTRATION_EXPIRE_KEY << YAML::Value << registrationExpire_; - out << YAML::Key << SERVICE_ROUTE_KEY << YAML::Value << serviceRoute_; + out << YAML::Key << Conf::SERVICE_ROUTE_KEY << YAML::Value << serviceRoute_; - out << YAML::Key << STUN_ENABLED_KEY << YAML::Value << stunEnabled_; - out << YAML::Key << STUN_SERVER_KEY << YAML::Value << stunServer_; + out << YAML::Key << Conf::STUN_ENABLED_KEY << YAML::Value << stunEnabled_; + out << YAML::Key << Conf::STUN_SERVER_KEY << YAML::Value << stunServer_; // tls submap - out << YAML::Key << TLS_KEY << YAML::Value << YAML::BeginMap; + out << YAML::Key << Conf::TLS_KEY << YAML::Value << YAML::BeginMap; SIPAccountBase::serializeTls(out); - out << YAML::Key << TLS_ENABLE_KEY << YAML::Value << tlsEnable_; - out << YAML::Key << VERIFY_CLIENT_KEY << YAML::Value << tlsVerifyClient_; - out << YAML::Key << VERIFY_SERVER_KEY << YAML::Value << tlsVerifyServer_; - out << YAML::Key << REQUIRE_CERTIF_KEY << YAML::Value << tlsRequireClientCertificate_; - out << YAML::Key << TIMEOUT_KEY << YAML::Value << tlsNegotiationTimeoutSec_; - out << YAML::Key << CALIST_KEY << YAML::Value << tlsCaListFile_; - out << YAML::Key << CERTIFICATE_KEY << YAML::Value << tlsCertificateFile_; - out << YAML::Key << CIPHERS_KEY << YAML::Value << tlsCiphers_; - out << YAML::Key << METHOD_KEY << YAML::Value << tlsMethod_; - out << YAML::Key << TLS_PASSWORD_KEY << YAML::Value << tlsPassword_; - out << YAML::Key << PRIVATE_KEY_KEY << YAML::Value << tlsPrivateKeyFile_; - out << YAML::Key << SERVER_KEY << YAML::Value << tlsServerName_; + out << YAML::Key << Conf::TLS_ENABLE_KEY << YAML::Value << tlsEnable_; + out << YAML::Key << Conf::VERIFY_CLIENT_KEY << YAML::Value << tlsVerifyClient_; + out << YAML::Key << Conf::VERIFY_SERVER_KEY << YAML::Value << tlsVerifyServer_; + out << YAML::Key << Conf::REQUIRE_CERTIF_KEY << YAML::Value << tlsRequireClientCertificate_; + out << YAML::Key << Conf::TIMEOUT_KEY << YAML::Value << tlsNegotiationTimeoutSec_; + out << YAML::Key << Conf::CALIST_KEY << YAML::Value << tlsCaListFile_; + out << YAML::Key << Conf::CERTIFICATE_KEY << YAML::Value << tlsCertificateFile_; + out << YAML::Key << Conf::CIPHERS_KEY << YAML::Value << tlsCiphers_; + out << YAML::Key << Conf::METHOD_KEY << YAML::Value << tlsMethod_; + out << YAML::Key << Conf::TLS_PASSWORD_KEY << YAML::Value << tlsPassword_; + out << YAML::Key << Conf::PRIVATE_KEY_KEY << YAML::Value << tlsPrivateKeyFile_; + out << YAML::Key << Conf::SERVER_KEY << YAML::Value << tlsServerName_; out << YAML::EndMap; // srtp submap - out << YAML::Key << SRTP_KEY << YAML::Value << YAML::BeginMap; - out << YAML::Key << SRTP_ENABLE_KEY << YAML::Value << srtpEnabled_; - out << YAML::Key << KEY_EXCHANGE_KEY << YAML::Value << srtpKeyExchange_; - out << YAML::Key << RTP_FALLBACK_KEY << YAML::Value << srtpFallback_; + out << YAML::Key << Conf::SRTP_KEY << YAML::Value << YAML::BeginMap; + out << YAML::Key << Conf::SRTP_ENABLE_KEY << YAML::Value << srtpEnabled_; + out << YAML::Key << Conf::KEY_EXCHANGE_KEY << YAML::Value << srtpKeyExchange_; + out << YAML::Key << Conf::RTP_FALLBACK_KEY << YAML::Value << srtpFallback_; out << YAML::EndMap; // zrtp submap - out << YAML::Key << ZRTP_KEY << YAML::Value << YAML::BeginMap; - out << YAML::Key << DISPLAY_SAS_KEY << YAML::Value << zrtpDisplaySas_; - out << YAML::Key << DISPLAY_SAS_ONCE_KEY << YAML::Value << zrtpDisplaySasOnce_; - out << YAML::Key << HELLO_HASH_ENABLED_KEY << YAML::Value << zrtpHelloHash_; - out << YAML::Key << NOT_SUPP_WARNING_KEY << YAML::Value << zrtpNotSuppWarning_; + out << YAML::Key << Conf::ZRTP_KEY << YAML::Value << YAML::BeginMap; + out << YAML::Key << Conf::DISPLAY_SAS_KEY << YAML::Value << zrtpDisplaySas_; + out << YAML::Key << Conf::DISPLAY_SAS_ONCE_KEY << YAML::Value << zrtpDisplaySasOnce_; + out << YAML::Key << Conf::HELLO_HASH_ENABLED_KEY << YAML::Value << zrtpHelloHash_; + out << YAML::Key << Conf::NOT_SUPP_WARNING_KEY << YAML::Value << zrtpNotSuppWarning_; out << YAML::EndMap; out << YAML::EndMap; @@ -422,80 +425,77 @@ validate(std::string &member, const std::string ¶m, const T& valid) void SIPAccount::unserialize(const YAML::Node &node) { - using namespace Conf; - using namespace yaml_utils; - SIPAccountBase::unserialize(node); if (not publishedSameasLocal_) usePublishedAddressPortInVIA(); if (not isIP2IP()) parseValue(node, Preferences::REGISTRATION_EXPIRE_KEY, registrationExpire_); - if (not isIP2IP()) parseValue(node, KEEP_ALIVE_ENABLED, keepAliveEnabled_); + if (not isIP2IP()) parseValue(node, Conf::KEEP_ALIVE_ENABLED, keepAliveEnabled_); bool presEnabled = false; parseValue(node, PRESENCE_MODULE_ENABLED_KEY, presEnabled); enablePresence(presEnabled); bool publishSupported = false; - parseValue(node, PRESENCE_PUBLISH_SUPPORTED_KEY, publishSupported); + parseValue(node, Conf::PRESENCE_PUBLISH_SUPPORTED_KEY, publishSupported); bool subscribeSupported = false; - parseValue(node, PRESENCE_SUBSCRIBE_SUPPORTED_KEY, subscribeSupported); + parseValue(node, Conf::PRESENCE_SUBSCRIBE_SUPPORTED_KEY, subscribeSupported); if (presence_) { presence_->support(PRESENCE_FUNCTION_PUBLISH, publishSupported); presence_->support(PRESENCE_FUNCTION_SUBSCRIBE, subscribeSupported); } - if (not isIP2IP()) parseValue(node, SERVICE_ROUTE_KEY, serviceRoute_); + if (not isIP2IP()) parseValue(node, Conf::SERVICE_ROUTE_KEY, serviceRoute_); // stun enabled - if (not isIP2IP()) parseValue(node, STUN_ENABLED_KEY, stunEnabled_); - if (not isIP2IP()) parseValue(node, STUN_SERVER_KEY, stunServer_); + if (not isIP2IP()) parseValue(node, Conf::STUN_ENABLED_KEY, stunEnabled_); + if (not isIP2IP()) parseValue(node, Conf::STUN_SERVER_KEY, stunServer_); // Init stun server name with default server name stunServerName_ = pj_str((char*) stunServer_.data()); - const auto &credsNode = node[CRED_KEY]; - const auto creds = parseVectorMap(credsNode, {CONFIG_ACCOUNT_PASSWORD, - CONFIG_ACCOUNT_REALM, CONFIG_ACCOUNT_USERNAME}); + const auto &credsNode = node[Conf::CRED_KEY]; + const auto creds = parseVectorMap(credsNode, {Conf::CONFIG_ACCOUNT_PASSWORD, + Conf::CONFIG_ACCOUNT_REALM, Conf::CONFIG_ACCOUNT_USERNAME}); setCredentials(creds); // get zrtp submap - const auto &zrtpMap = node[ZRTP_KEY]; + const auto &zrtpMap = node[Conf::ZRTP_KEY]; - parseValue(zrtpMap, DISPLAY_SAS_KEY, zrtpDisplaySas_); - parseValue(zrtpMap, DISPLAY_SAS_ONCE_KEY, zrtpDisplaySasOnce_); - parseValue(zrtpMap, HELLO_HASH_ENABLED_KEY, zrtpHelloHash_); - parseValue(zrtpMap, NOT_SUPP_WARNING_KEY, zrtpNotSuppWarning_); + parseValue(zrtpMap, Conf::DISPLAY_SAS_KEY, zrtpDisplaySas_); + parseValue(zrtpMap, Conf::DISPLAY_SAS_ONCE_KEY, zrtpDisplaySasOnce_); + parseValue(zrtpMap, Conf::HELLO_HASH_ENABLED_KEY, zrtpHelloHash_); + parseValue(zrtpMap, Conf::NOT_SUPP_WARNING_KEY, zrtpNotSuppWarning_); // get tls submap - const auto &tlsMap = node[TLS_KEY]; + const auto &tlsMap = node[Conf::TLS_KEY]; - parseValue(tlsMap, TLS_ENABLE_KEY, tlsEnable_); - parseValue(tlsMap, CERTIFICATE_KEY, tlsCertificateFile_); - parseValue(tlsMap, CALIST_KEY, tlsCaListFile_); - parseValue(tlsMap, CIPHERS_KEY, tlsCiphers_); + parseValue(tlsMap, Conf::TLS_ENABLE_KEY, tlsEnable_); + parseValue(tlsMap, Conf::CERTIFICATE_KEY, tlsCertificateFile_); + parseValue(tlsMap, Conf::CALIST_KEY, tlsCaListFile_); + parseValue(tlsMap, Conf::CIPHERS_KEY, tlsCiphers_); std::string tmpMethod(tlsMethod_); - parseValue(tlsMap, METHOD_KEY, tmpMethod); + parseValue(tlsMap, Conf::METHOD_KEY, tmpMethod); validate(tlsMethod_, tmpMethod, VALID_TLS_METHODS); - parseValue(tlsMap, TLS_PASSWORD_KEY, tlsPassword_); - parseValue(tlsMap, PRIVATE_KEY_KEY, tlsPrivateKeyFile_); - parseValue(tlsMap, SERVER_KEY, tlsServerName_); - parseValue(tlsMap, REQUIRE_CERTIF_KEY, tlsRequireClientCertificate_); - parseValue(tlsMap, VERIFY_CLIENT_KEY, tlsVerifyClient_); - parseValue(tlsMap, VERIFY_SERVER_KEY, tlsVerifyServer_); + parseValue(tlsMap, Conf::TLS_PASSWORD_KEY, tlsPassword_); + parseValue(tlsMap, Conf::PRIVATE_KEY_KEY, tlsPrivateKeyFile_); + parseValue(tlsMap, Conf::SERVER_KEY, tlsServerName_); + parseValue(tlsMap, Conf::REQUIRE_CERTIF_KEY, tlsRequireClientCertificate_); + parseValue(tlsMap, Conf::VERIFY_CLIENT_KEY, tlsVerifyClient_); + parseValue(tlsMap, Conf::VERIFY_SERVER_KEY, tlsVerifyServer_); // FIXME - parseValue(tlsMap, TIMEOUT_KEY, tlsNegotiationTimeoutSec_); + parseValue(tlsMap, Conf::TIMEOUT_KEY, tlsNegotiationTimeoutSec_); // get srtp submap - const auto &srtpMap = node[SRTP_KEY]; - parseValue(srtpMap, SRTP_ENABLE_KEY, srtpEnabled_); + const auto &srtpMap = node[Conf::SRTP_KEY]; + parseValue(srtpMap, Conf::SRTP_ENABLE_KEY, srtpEnabled_); std::string tmpKey; - parseValue(srtpMap, KEY_EXCHANGE_KEY, tmpKey); + parseValue(srtpMap, Conf::KEY_EXCHANGE_KEY, tmpKey); validate(srtpKeyExchange_, tmpKey, VALID_SRTP_KEY_EXCHANGES); - parseValue(srtpMap, RTP_FALLBACK_KEY, srtpFallback_); + parseValue(srtpMap, Conf::RTP_FALLBACK_KEY, srtpFallback_); } template <typename T> @@ -515,55 +515,55 @@ void SIPAccount::setAccountDetails(const std::map<std::string, std::string> &det SIPAccountBase::setAccountDetails(details); // SIP specific account settings - parseString(details, CONFIG_ACCOUNT_ROUTESET, serviceRoute_); + parseString(details, Conf::CONFIG_ACCOUNT_ROUTESET, serviceRoute_); if (not publishedSameasLocal_) usePublishedAddressPortInVIA(); - parseString(details, CONFIG_STUN_SERVER, stunServer_); - parseBool(details, CONFIG_STUN_ENABLE, stunEnabled_); - parseInt(details, CONFIG_ACCOUNT_REGISTRATION_EXPIRE, registrationExpire_); + parseString(details, Conf::CONFIG_STUN_SERVER, stunServer_); + parseBool(details, Conf::CONFIG_STUN_ENABLE, stunEnabled_); + parseInt(details, Conf::CONFIG_ACCOUNT_REGISTRATION_EXPIRE, registrationExpire_); if (registrationExpire_ < MIN_REGISTRATION_TIME) registrationExpire_ = MIN_REGISTRATION_TIME; - parseBool(details, CONFIG_KEEP_ALIVE_ENABLED, keepAliveEnabled_); + parseBool(details, Conf::CONFIG_KEEP_ALIVE_ENABLED, keepAliveEnabled_); bool presenceEnabled = false; - parseBool(details, CONFIG_PRESENCE_ENABLED, presenceEnabled); + parseBool(details, Conf::CONFIG_PRESENCE_ENABLED, presenceEnabled); enablePresence(presenceEnabled); // srtp settings - parseBool(details, CONFIG_ZRTP_DISPLAY_SAS, zrtpDisplaySas_); - parseBool(details, CONFIG_ZRTP_DISPLAY_SAS_ONCE, zrtpDisplaySasOnce_); - parseBool(details, CONFIG_ZRTP_NOT_SUPP_WARNING, zrtpNotSuppWarning_); - parseBool(details, CONFIG_ZRTP_HELLO_HASH, zrtpHelloHash_); + parseBool(details, Conf::CONFIG_ZRTP_DISPLAY_SAS, zrtpDisplaySas_); + parseBool(details, Conf::CONFIG_ZRTP_DISPLAY_SAS_ONCE, zrtpDisplaySasOnce_); + parseBool(details, Conf::CONFIG_ZRTP_NOT_SUPP_WARNING, zrtpNotSuppWarning_); + parseBool(details, Conf::CONFIG_ZRTP_HELLO_HASH, zrtpHelloHash_); // TLS settings - parseBool(details, CONFIG_TLS_ENABLE, tlsEnable_); - parseInt(details, CONFIG_TLS_LISTENER_PORT, tlsListenerPort_); - parseString(details, CONFIG_TLS_CA_LIST_FILE, tlsCaListFile_); - parseString(details, CONFIG_TLS_CERTIFICATE_FILE, tlsCertificateFile_); - - parseString(details, CONFIG_TLS_PRIVATE_KEY_FILE, tlsPrivateKeyFile_); - parseString(details, CONFIG_TLS_PASSWORD, tlsPassword_); - auto iter = details.find(CONFIG_TLS_METHOD); + parseBool(details, Conf::CONFIG_TLS_ENABLE, tlsEnable_); + parseInt(details, Conf::CONFIG_TLS_LISTENER_PORT, tlsListenerPort_); + parseString(details, Conf::CONFIG_TLS_CA_LIST_FILE, tlsCaListFile_); + parseString(details, Conf::CONFIG_TLS_CERTIFICATE_FILE, tlsCertificateFile_); + + parseString(details, Conf::CONFIG_TLS_PRIVATE_KEY_FILE, tlsPrivateKeyFile_); + parseString(details, Conf::CONFIG_TLS_PASSWORD, tlsPassword_); + auto iter = details.find(Conf::CONFIG_TLS_METHOD); if (iter != details.end()) validate(tlsMethod_, iter->second, VALID_TLS_METHODS); - parseString(details, CONFIG_TLS_CIPHERS, tlsCiphers_); - parseString(details, CONFIG_TLS_SERVER_NAME, tlsServerName_); - parseBool(details, CONFIG_TLS_VERIFY_SERVER, tlsVerifyServer_); - parseBool(details, CONFIG_TLS_VERIFY_CLIENT, tlsVerifyClient_); - parseBool(details, CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE, tlsRequireClientCertificate_); - parseString(details, CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC, tlsNegotiationTimeoutSec_); - parseBool(details, CONFIG_TLS_VERIFY_SERVER, tlsVerifyServer_); - parseBool(details, CONFIG_TLS_VERIFY_CLIENT, tlsVerifyClient_); - parseBool(details, CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE, tlsRequireClientCertificate_); - parseString(details, CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC, tlsNegotiationTimeoutSec_); + parseString(details, Conf::CONFIG_TLS_CIPHERS, tlsCiphers_); + parseString(details, Conf::CONFIG_TLS_SERVER_NAME, tlsServerName_); + parseBool(details, Conf::CONFIG_TLS_VERIFY_SERVER, tlsVerifyServer_); + parseBool(details, Conf::CONFIG_TLS_VERIFY_CLIENT, tlsVerifyClient_); + parseBool(details, Conf::CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE, tlsRequireClientCertificate_); + parseString(details, Conf::CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC, tlsNegotiationTimeoutSec_); + parseBool(details, Conf::CONFIG_TLS_VERIFY_SERVER, tlsVerifyServer_); + parseBool(details, Conf::CONFIG_TLS_VERIFY_CLIENT, tlsVerifyClient_); + parseBool(details, Conf::CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE, tlsRequireClientCertificate_); + parseString(details, Conf::CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC, tlsNegotiationTimeoutSec_); // srtp settings - parseBool(details, CONFIG_SRTP_ENABLE, srtpEnabled_); - parseBool(details, CONFIG_SRTP_RTP_FALLBACK, srtpFallback_); - iter = details.find(CONFIG_SRTP_KEY_EXCHANGE); + parseBool(details, Conf::CONFIG_SRTP_ENABLE, srtpEnabled_); + parseBool(details, Conf::CONFIG_SRTP_RTP_FALLBACK, srtpFallback_); + iter = details.find(Conf::CONFIG_SRTP_KEY_EXCHANGE); if (iter != details.end()) validate(srtpKeyExchange_, iter->second, VALID_SRTP_KEY_EXCHANGES); @@ -571,9 +571,9 @@ void SIPAccount::setAccountDetails(const std::map<std::string, std::string> &det RING_WARN("No credentials set, inferring them..."); std::vector<std::map<std::string, std::string> > v; std::map<std::string, std::string> map; - map[CONFIG_ACCOUNT_USERNAME] = username_; - parseString(details, CONFIG_ACCOUNT_PASSWORD, map[CONFIG_ACCOUNT_PASSWORD]); - map[CONFIG_ACCOUNT_REALM] = "*"; + map[Conf::CONFIG_ACCOUNT_USERNAME] = username_; + parseString(details, Conf::CONFIG_ACCOUNT_PASSWORD, map[Conf::CONFIG_ACCOUNT_PASSWORD]); + map[Conf::CONFIG_ACCOUNT_REALM] = "*"; v.push_back(map); setCredentials(v); } @@ -583,11 +583,11 @@ static std::string retrievePassword(const std::map<std::string, std::string>& ma { std::map<std::string, std::string>::const_iterator map_iter_username; std::map<std::string, std::string>::const_iterator map_iter_password; - map_iter_username = map.find(CONFIG_ACCOUNT_USERNAME); + map_iter_username = map.find(Conf::CONFIG_ACCOUNT_USERNAME); if (map_iter_username != map.end()) { if (map_iter_username->second == username) { - map_iter_password = map.find(CONFIG_ACCOUNT_PASSWORD); + map_iter_password = map.find(Conf::CONFIG_ACCOUNT_PASSWORD); if (map_iter_password != map.end()) { return map_iter_password->second; @@ -602,13 +602,13 @@ std::map<std::string, std::string> SIPAccount::getAccountDetails() const { std::map<std::string, std::string> a = SIPAccountBase::getAccountDetails(); - a[CONFIG_ACCOUNT_PASSWORD] = ""; + a[Conf::CONFIG_ACCOUNT_PASSWORD] = ""; if (hasCredentials()) { for (const auto &vect_item : credentials_) { const std::string password = retrievePassword(vect_item, username_); if (not password.empty()) - a[CONFIG_ACCOUNT_PASSWORD] = password; + a[Conf::CONFIG_ACCOUNT_PASSWORD] = password; } } @@ -623,49 +623,49 @@ std::map<std::string, std::string> SIPAccount::getAccountDetails() const registrationStateCode = out.str(); registrationStateDescription = registrationStateDetailed_.second; } - a[CONFIG_ACCOUNT_REGISTRATION_STATE_CODE] = registrationStateCode; - a[CONFIG_ACCOUNT_REGISTRATION_STATE_DESC] = registrationStateDescription; + a[Conf::CONFIG_ACCOUNT_REGISTRATION_STATE_CODE] = registrationStateCode; + a[Conf::CONFIG_ACCOUNT_REGISTRATION_STATE_DESC] = registrationStateDescription; - a[CONFIG_PRESENCE_ENABLED] = presence_ and presence_->isEnabled()? TRUE_STR : FALSE_STR; - a[CONFIG_PRESENCE_PUBLISH_SUPPORTED] = presence_ and presence_->isSupported(PRESENCE_FUNCTION_PUBLISH)? TRUE_STR : FALSE_STR; - a[CONFIG_PRESENCE_SUBSCRIBE_SUPPORTED] = presence_ and presence_->isSupported(PRESENCE_FUNCTION_SUBSCRIBE)? TRUE_STR : FALSE_STR; + a[Conf::CONFIG_PRESENCE_ENABLED] = presence_ and presence_->isEnabled()? TRUE_STR : FALSE_STR; + a[Conf::CONFIG_PRESENCE_PUBLISH_SUPPORTED] = presence_ and presence_->isSupported(PRESENCE_FUNCTION_PUBLISH)? TRUE_STR : FALSE_STR; + a[Conf::CONFIG_PRESENCE_SUBSCRIBE_SUPPORTED] = presence_ and presence_->isSupported(PRESENCE_FUNCTION_SUBSCRIBE)? TRUE_STR : FALSE_STR; // initialize status values - a[CONFIG_PRESENCE_STATUS] = presence_ and presence_->isOnline()? TRUE_STR : FALSE_STR; - a[CONFIG_PRESENCE_NOTE] = presence_ ? presence_->getNote() : " "; + a[Conf::CONFIG_PRESENCE_STATUS] = presence_ and presence_->isOnline()? TRUE_STR : FALSE_STR; + a[Conf::CONFIG_PRESENCE_NOTE] = presence_ ? presence_->getNote() : " "; // Add sip specific details - a[CONFIG_ACCOUNT_ROUTESET] = serviceRoute_; + a[Conf::CONFIG_ACCOUNT_ROUTESET] = serviceRoute_; std::stringstream registrationExpireStr; registrationExpireStr << registrationExpire_; - a[CONFIG_ACCOUNT_REGISTRATION_EXPIRE] = registrationExpireStr.str(); + a[Conf::CONFIG_ACCOUNT_REGISTRATION_EXPIRE] = registrationExpireStr.str(); - a[CONFIG_STUN_ENABLE] = stunEnabled_ ? TRUE_STR : FALSE_STR; - a[CONFIG_STUN_SERVER] = stunServer_; - a[CONFIG_KEEP_ALIVE_ENABLED] = keepAliveEnabled_ ? TRUE_STR : FALSE_STR; + a[Conf::CONFIG_STUN_ENABLE] = stunEnabled_ ? TRUE_STR : FALSE_STR; + a[Conf::CONFIG_STUN_SERVER] = stunServer_; + a[Conf::CONFIG_KEEP_ALIVE_ENABLED] = keepAliveEnabled_ ? TRUE_STR : FALSE_STR; // TLS listener is unique and parameters are modified through IP2IP_PROFILE - a[CONFIG_TLS_ENABLE] = tlsEnable_ ? TRUE_STR : FALSE_STR; - a[CONFIG_TLS_CA_LIST_FILE] = tlsCaListFile_; - a[CONFIG_TLS_CERTIFICATE_FILE] = tlsCertificateFile_; - a[CONFIG_TLS_PRIVATE_KEY_FILE] = tlsPrivateKeyFile_; - a[CONFIG_TLS_PASSWORD] = tlsPassword_; - a[CONFIG_TLS_METHOD] = tlsMethod_; - a[CONFIG_TLS_CIPHERS] = tlsCiphers_; - a[CONFIG_TLS_SERVER_NAME] = tlsServerName_; - a[CONFIG_TLS_VERIFY_SERVER] = tlsVerifyServer_ ? TRUE_STR : FALSE_STR; - a[CONFIG_TLS_VERIFY_CLIENT] = tlsVerifyClient_ ? TRUE_STR : FALSE_STR; - a[CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE] = tlsRequireClientCertificate_ ? TRUE_STR : FALSE_STR; - a[CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC] = tlsNegotiationTimeoutSec_; - - a[CONFIG_SRTP_KEY_EXCHANGE] = srtpKeyExchange_; - a[CONFIG_SRTP_ENABLE] = srtpEnabled_ ? TRUE_STR : FALSE_STR; - a[CONFIG_SRTP_RTP_FALLBACK] = srtpFallback_ ? TRUE_STR : FALSE_STR; - - a[CONFIG_ZRTP_DISPLAY_SAS] = zrtpDisplaySas_ ? TRUE_STR : FALSE_STR; - a[CONFIG_ZRTP_DISPLAY_SAS_ONCE] = zrtpDisplaySasOnce_ ? TRUE_STR : FALSE_STR; - a[CONFIG_ZRTP_HELLO_HASH] = zrtpHelloHash_ ? TRUE_STR : FALSE_STR; - a[CONFIG_ZRTP_NOT_SUPP_WARNING] = zrtpNotSuppWarning_ ? TRUE_STR : FALSE_STR; + a[Conf::CONFIG_TLS_ENABLE] = tlsEnable_ ? TRUE_STR : FALSE_STR; + a[Conf::CONFIG_TLS_CA_LIST_FILE] = tlsCaListFile_; + a[Conf::CONFIG_TLS_CERTIFICATE_FILE] = tlsCertificateFile_; + a[Conf::CONFIG_TLS_PRIVATE_KEY_FILE] = tlsPrivateKeyFile_; + a[Conf::CONFIG_TLS_PASSWORD] = tlsPassword_; + a[Conf::CONFIG_TLS_METHOD] = tlsMethod_; + a[Conf::CONFIG_TLS_CIPHERS] = tlsCiphers_; + a[Conf::CONFIG_TLS_SERVER_NAME] = tlsServerName_; + a[Conf::CONFIG_TLS_VERIFY_SERVER] = tlsVerifyServer_ ? TRUE_STR : FALSE_STR; + a[Conf::CONFIG_TLS_VERIFY_CLIENT] = tlsVerifyClient_ ? TRUE_STR : FALSE_STR; + a[Conf::CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE] = tlsRequireClientCertificate_ ? TRUE_STR : FALSE_STR; + a[Conf::CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC] = tlsNegotiationTimeoutSec_; + + a[Conf::CONFIG_SRTP_KEY_EXCHANGE] = srtpKeyExchange_; + a[Conf::CONFIG_SRTP_ENABLE] = srtpEnabled_ ? TRUE_STR : FALSE_STR; + a[Conf::CONFIG_SRTP_RTP_FALLBACK] = srtpFallback_ ? TRUE_STR : FALSE_STR; + + a[Conf::CONFIG_ZRTP_DISPLAY_SAS] = zrtpDisplaySas_ ? TRUE_STR : FALSE_STR; + a[Conf::CONFIG_ZRTP_DISPLAY_SAS_ONCE] = zrtpDisplaySasOnce_ ? TRUE_STR : FALSE_STR; + a[Conf::CONFIG_ZRTP_HELLO_HASH] = zrtpHelloHash_ ? TRUE_STR : FALSE_STR; + a[Conf::CONFIG_ZRTP_NOT_SUPP_WARNING] = zrtpNotSuppWarning_ ? TRUE_STR : FALSE_STR; return a; } @@ -675,12 +675,12 @@ std::map<std::string, std::string> SIPAccount::getVolatileAccountDetails() const std::map<std::string, std::string> a = SIPAccountBase::getVolatileAccountDetails(); std::stringstream codestream; codestream << registrationStateDetailed_.first; - a[CONFIG_ACCOUNT_REGISTRATION_STATE_CODE] = codestream.str(); - a[CONFIG_ACCOUNT_REGISTRATION_STATE_DESC] = registrationStateDetailed_.second; + a[Conf::CONFIG_ACCOUNT_REGISTRATION_STATE_CODE] = codestream.str(); + a[Conf::CONFIG_ACCOUNT_REGISTRATION_STATE_DESC] = registrationStateDetailed_.second; if (presence_) { - a[CONFIG_PRESENCE_STATUS] = presence_ and presence_->isOnline()? TRUE_STR : FALSE_STR; - a[CONFIG_PRESENCE_NOTE] = presence_ ? presence_->getNote() : " "; + a[Conf::CONFIG_PRESENCE_STATUS] = presence_ and presence_->isOnline()? TRUE_STR : FALSE_STR; + a[Conf::CONFIG_PRESENCE_NOTE] = presence_ ? presence_->getNote() : " "; } #if HAVE_TLS @@ -1523,11 +1523,11 @@ void SIPAccount::setCredentials(const std::vector<std::map<std::string, std::str /* md5 hashing */ for (auto &it : credentials_) { - map<string, string>::const_iterator val = it.find(CONFIG_ACCOUNT_USERNAME); + map<string, string>::const_iterator val = it.find(Conf::CONFIG_ACCOUNT_USERNAME); const std::string username = val != it.end() ? val->second : ""; - val = it.find(CONFIG_ACCOUNT_REALM); + val = it.find(Conf::CONFIG_ACCOUNT_REALM); const std::string realm(val != it.end() ? val->second : ""); - val = it.find(CONFIG_ACCOUNT_PASSWORD); + val = it.find(Conf::CONFIG_ACCOUNT_PASSWORD); const std::string password(val != it.end() ? val->second : ""); if (md5HashingEnabled) { @@ -1541,7 +1541,7 @@ void SIPAccount::setCredentials(const std::vector<std::map<std::string, std::str // re-hash a hashed password. if (password.length() != 32) - it[CONFIG_ACCOUNT_PASSWORD] = computeMd5HashFromCredential(username, password, realm); + it[Conf::CONFIG_ACCOUNT_PASSWORD] = computeMd5HashFromCredential(username, password, realm); } } @@ -1551,20 +1551,20 @@ void SIPAccount::setCredentials(const std::vector<std::map<std::string, std::str size_t i = 0; for (const auto &item : credentials_) { - map<string, string>::const_iterator val = item.find(CONFIG_ACCOUNT_PASSWORD); + map<string, string>::const_iterator val = item.find(Conf::CONFIG_ACCOUNT_PASSWORD); const std::string password = val != item.end() ? val->second : ""; int dataType = (md5HashingEnabled and password.length() == 32) ? PJSIP_CRED_DATA_DIGEST : PJSIP_CRED_DATA_PLAIN_PASSWD; - val = item.find(CONFIG_ACCOUNT_USERNAME); + val = item.find(Conf::CONFIG_ACCOUNT_USERNAME); if (val != item.end()) cred_[i].username = pj_str((char*) val->second.c_str()); cred_[i].data = pj_str((char*) password.c_str()); - val = item.find(CONFIG_ACCOUNT_REALM); + val = item.find(Conf::CONFIG_ACCOUNT_REALM); if (val != item.end()) cred_[i].realm = pj_str((char*) val->second.c_str()); @@ -1592,17 +1592,17 @@ std::map<std::string, std::string> SIPAccount::getIp2IpDetails() const { assert(isIP2IP()); std::map<std::string, std::string> ip2ipAccountDetails; - ip2ipAccountDetails[CONFIG_SRTP_KEY_EXCHANGE] = srtpKeyExchange_; - ip2ipAccountDetails[CONFIG_SRTP_ENABLE] = srtpEnabled_ ? TRUE_STR : FALSE_STR; - ip2ipAccountDetails[CONFIG_SRTP_RTP_FALLBACK] = srtpFallback_ ? TRUE_STR : FALSE_STR; - ip2ipAccountDetails[CONFIG_ZRTP_DISPLAY_SAS] = zrtpDisplaySas_ ? TRUE_STR : FALSE_STR; - ip2ipAccountDetails[CONFIG_ZRTP_HELLO_HASH] = zrtpHelloHash_ ? TRUE_STR : FALSE_STR; - ip2ipAccountDetails[CONFIG_ZRTP_NOT_SUPP_WARNING] = zrtpNotSuppWarning_ ? TRUE_STR : FALSE_STR; - ip2ipAccountDetails[CONFIG_ZRTP_DISPLAY_SAS_ONCE] = zrtpDisplaySasOnce_ ? TRUE_STR : FALSE_STR; - ip2ipAccountDetails[CONFIG_LOCAL_INTERFACE] = interface_; + ip2ipAccountDetails[Conf::CONFIG_SRTP_KEY_EXCHANGE] = srtpKeyExchange_; + ip2ipAccountDetails[Conf::CONFIG_SRTP_ENABLE] = srtpEnabled_ ? TRUE_STR : FALSE_STR; + ip2ipAccountDetails[Conf::CONFIG_SRTP_RTP_FALLBACK] = srtpFallback_ ? TRUE_STR : FALSE_STR; + ip2ipAccountDetails[Conf::CONFIG_ZRTP_DISPLAY_SAS] = zrtpDisplaySas_ ? TRUE_STR : FALSE_STR; + ip2ipAccountDetails[Conf::CONFIG_ZRTP_HELLO_HASH] = zrtpHelloHash_ ? TRUE_STR : FALSE_STR; + ip2ipAccountDetails[Conf::CONFIG_ZRTP_NOT_SUPP_WARNING] = zrtpNotSuppWarning_ ? TRUE_STR : FALSE_STR; + ip2ipAccountDetails[Conf::CONFIG_ZRTP_DISPLAY_SAS_ONCE] = zrtpDisplaySasOnce_ ? TRUE_STR : FALSE_STR; + ip2ipAccountDetails[Conf::CONFIG_LOCAL_INTERFACE] = interface_; std::stringstream portstr; portstr << localPort_; - ip2ipAccountDetails[CONFIG_LOCAL_PORT] = portstr.str(); + ip2ipAccountDetails[Conf::CONFIG_LOCAL_PORT] = portstr.str(); std::map<std::string, std::string> tlsSettings(getTlsSettings()); std::copy(tlsSettings.begin(), tlsSettings.end(), std::inserter( @@ -1618,19 +1618,19 @@ std::map<std::string, std::string> SIPAccount::getTlsSettings() const std::stringstream portstr; portstr << tlsListenerPort_; - tlsSettings[CONFIG_TLS_LISTENER_PORT] = portstr.str(); - tlsSettings[CONFIG_TLS_ENABLE] = tlsEnable_ ? TRUE_STR : FALSE_STR; - tlsSettings[CONFIG_TLS_CA_LIST_FILE] = tlsCaListFile_; - tlsSettings[CONFIG_TLS_CERTIFICATE_FILE] = tlsCertificateFile_; - tlsSettings[CONFIG_TLS_PRIVATE_KEY_FILE] = tlsPrivateKeyFile_; - tlsSettings[CONFIG_TLS_PASSWORD] = tlsPassword_; - tlsSettings[CONFIG_TLS_METHOD] = tlsMethod_; - tlsSettings[CONFIG_TLS_CIPHERS] = tlsCiphers_; - tlsSettings[CONFIG_TLS_SERVER_NAME] = tlsServerName_; - tlsSettings[CONFIG_TLS_VERIFY_SERVER] = tlsVerifyServer_ ? TRUE_STR : FALSE_STR; - tlsSettings[CONFIG_TLS_VERIFY_CLIENT] = tlsVerifyClient_ ? TRUE_STR : FALSE_STR; - tlsSettings[CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE] = tlsRequireClientCertificate_ ? TRUE_STR : FALSE_STR; - tlsSettings[CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC] = tlsNegotiationTimeoutSec_; + tlsSettings[Conf::CONFIG_TLS_LISTENER_PORT] = portstr.str(); + tlsSettings[Conf::CONFIG_TLS_ENABLE] = tlsEnable_ ? TRUE_STR : FALSE_STR; + tlsSettings[Conf::CONFIG_TLS_CA_LIST_FILE] = tlsCaListFile_; + tlsSettings[Conf::CONFIG_TLS_CERTIFICATE_FILE] = tlsCertificateFile_; + tlsSettings[Conf::CONFIG_TLS_PRIVATE_KEY_FILE] = tlsPrivateKeyFile_; + tlsSettings[Conf::CONFIG_TLS_PASSWORD] = tlsPassword_; + tlsSettings[Conf::CONFIG_TLS_METHOD] = tlsMethod_; + tlsSettings[Conf::CONFIG_TLS_CIPHERS] = tlsCiphers_; + tlsSettings[Conf::CONFIG_TLS_SERVER_NAME] = tlsServerName_; + tlsSettings[Conf::CONFIG_TLS_VERIFY_SERVER] = tlsVerifyServer_ ? TRUE_STR : FALSE_STR; + tlsSettings[Conf::CONFIG_TLS_VERIFY_CLIENT] = tlsVerifyClient_ ? TRUE_STR : FALSE_STR; + tlsSettings[Conf::CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE] = tlsRequireClientCertificate_ ? TRUE_STR : FALSE_STR; + tlsSettings[Conf::CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC] = tlsNegotiationTimeoutSec_; return tlsSettings; } @@ -1665,18 +1665,18 @@ set_opt(const std::map<std::string, std::string> &details, const char *key, pj_u void SIPAccount::setTlsSettings(const std::map<std::string, std::string>& details) { assert(isIP2IP()); - set_opt(details, CONFIG_TLS_LISTENER_PORT, tlsListenerPort_); - set_opt(details, CONFIG_TLS_ENABLE, tlsEnable_); - set_opt(details, CONFIG_TLS_CA_LIST_FILE, tlsCaListFile_); - set_opt(details, CONFIG_TLS_CERTIFICATE_FILE, tlsCertificateFile_); - set_opt(details, CONFIG_TLS_PRIVATE_KEY_FILE, tlsPrivateKeyFile_); - set_opt(details, CONFIG_TLS_PASSWORD, tlsPassword_); - set_opt(details, CONFIG_TLS_METHOD, tlsMethod_); - set_opt(details, CONFIG_TLS_CIPHERS, tlsCiphers_); - set_opt(details, CONFIG_TLS_SERVER_NAME, tlsServerName_); - set_opt(details, CONFIG_TLS_VERIFY_CLIENT, tlsVerifyClient_); - set_opt(details, CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE, tlsRequireClientCertificate_); - set_opt(details, CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC, tlsNegotiationTimeoutSec_); + set_opt(details, Conf::CONFIG_TLS_LISTENER_PORT, tlsListenerPort_); + set_opt(details, Conf::CONFIG_TLS_ENABLE, tlsEnable_); + set_opt(details, Conf::CONFIG_TLS_CA_LIST_FILE, tlsCaListFile_); + set_opt(details, Conf::CONFIG_TLS_CERTIFICATE_FILE, tlsCertificateFile_); + set_opt(details, Conf::CONFIG_TLS_PRIVATE_KEY_FILE, tlsPrivateKeyFile_); + set_opt(details, Conf::CONFIG_TLS_PASSWORD, tlsPassword_); + set_opt(details, Conf::CONFIG_TLS_METHOD, tlsMethod_); + set_opt(details, Conf::CONFIG_TLS_CIPHERS, tlsCiphers_); + set_opt(details, Conf::CONFIG_TLS_SERVER_NAME, tlsServerName_); + set_opt(details, Conf::CONFIG_TLS_VERIFY_CLIENT, tlsVerifyClient_); + set_opt(details, Conf::CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE, tlsRequireClientCertificate_); + set_opt(details, Conf::CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC, tlsNegotiationTimeoutSec_); } bool SIPAccount::isIP2IP() const @@ -2050,3 +2050,5 @@ void SIPAccount::updateDialogViaSentBy(pjsip_dialog *dlg) if (allowViaRewrite_ && via_addr_.host.slen > 0) pjsip_dlg_set_via_sent_by(dlg, &via_addr_, via_tp_); } + +} // namespace ring diff --git a/daemon/src/sip/sipaccount.h b/daemon/src/sip/sipaccount.h index f1cbda09507344a922877a8b31bc3bf3a0450b31..5c3dc64e87444834c81b1fc4497c11435ac78f3f 100644 --- a/daemon/src/sip/sipaccount.h +++ b/daemon/src/sip/sipaccount.h @@ -51,7 +51,12 @@ #include <vector> #include <map> -typedef std::vector<pj_ssl_cipher> CipherArray; +namespace YAML { + class Node; + class Emitter; +} + +namespace ring { namespace Conf { const char *const KEEP_ALIVE_ENABLED = "keepAlive"; @@ -70,10 +75,7 @@ namespace Conf { const char *const NOT_SUPP_WARNING_KEY = "notSuppWarning"; } -namespace YAML { - class Node; - class Emitter; -} +typedef std::vector<pj_ssl_cipher> CipherArray; class SIPPresence; class SIPCall; @@ -730,4 +732,6 @@ class SIPAccount : public SIPAccountBase { SIPPresence * presence_; }; +} // namespace ring + #endif diff --git a/daemon/src/sip/sipaccountbase.cpp b/daemon/src/sip/sipaccountbase.cpp index 36b07ee3138936ea6b33d5735b1175f7ed79be23..0c5dab3afac05edb6dc11757a88471ffa25b9a0f 100644 --- a/daemon/src/sip/sipaccountbase.cpp +++ b/daemon/src/sip/sipaccountbase.cpp @@ -43,6 +43,8 @@ #include "config/yamlparser.h" #include <yaml-cpp/yaml.h> +namespace ring { + bool SIPAccountBase::portsInUse_[HALF_MAX_PORT]; SIPAccountBase::SIPAccountBase(const std::string& accountID) @@ -94,35 +96,32 @@ parseInt(const std::map<std::string, std::string> &details, const char *key, T & void SIPAccountBase::serialize(YAML::Emitter &out) { - using namespace Conf; - Account::serialize(out); - out << YAML::Key << AUDIO_PORT_MAX_KEY << YAML::Value << audioPortRange_.second; - out << YAML::Key << AUDIO_PORT_MIN_KEY << YAML::Value << audioPortRange_.first; - out << YAML::Key << DTMF_TYPE_KEY << YAML::Value << dtmfType_; - out << YAML::Key << INTERFACE_KEY << YAML::Value << interface_; - out << YAML::Key << PORT_KEY << YAML::Value << localPort_; - out << YAML::Key << PUBLISH_ADDR_KEY << YAML::Value << publishedIpAddress_; - out << YAML::Key << PUBLISH_PORT_KEY << YAML::Value << publishedPort_; - out << YAML::Key << SAME_AS_LOCAL_KEY << YAML::Value << publishedSameasLocal_; + out << YAML::Key << Conf::AUDIO_PORT_MAX_KEY << YAML::Value << audioPortRange_.second; + out << YAML::Key << Conf::AUDIO_PORT_MIN_KEY << YAML::Value << audioPortRange_.first; + out << YAML::Key << Conf::DTMF_TYPE_KEY << YAML::Value << dtmfType_; + out << YAML::Key << Conf::INTERFACE_KEY << YAML::Value << interface_; + out << YAML::Key << Conf::PORT_KEY << YAML::Value << localPort_; + out << YAML::Key << Conf::PUBLISH_ADDR_KEY << YAML::Value << publishedIpAddress_; + out << YAML::Key << Conf::PUBLISH_PORT_KEY << YAML::Value << publishedPort_; + out << YAML::Key << Conf::SAME_AS_LOCAL_KEY << YAML::Value << publishedSameasLocal_; out << YAML::Key << VIDEO_CODECS_KEY << YAML::Value << videoCodecList_; out << YAML::Key << VIDEO_ENABLED_KEY << YAML::Value << videoEnabled_; - out << YAML::Key << VIDEO_PORT_MAX_KEY << YAML::Value << videoPortRange_.second; - out << YAML::Key << VIDEO_PORT_MIN_KEY << YAML::Value << videoPortRange_.first; + out << YAML::Key << Conf::VIDEO_PORT_MAX_KEY << YAML::Value << videoPortRange_.second; + out << YAML::Key << Conf::VIDEO_PORT_MIN_KEY << YAML::Value << videoPortRange_.first; } void SIPAccountBase::serializeTls(YAML::Emitter &out) { - using namespace Conf; - out << YAML::Key << TLS_PORT_KEY << YAML::Value << tlsListenerPort_; + out << YAML::Key << Conf::TLS_PORT_KEY << YAML::Value << tlsListenerPort_; } void SIPAccountBase::unserialize(const YAML::Node &node) { - using namespace Conf; - using namespace yaml_utils; + using yaml_utils::parseValue; + using yaml_utils::parseVectorMap; Account::unserialize(node); @@ -139,29 +138,29 @@ void SIPAccountBase::unserialize(const YAML::Node &node) // validate it setVideoCodecs(tmp); - parseValue(node, INTERFACE_KEY, interface_); + parseValue(node, Conf::INTERFACE_KEY, interface_); int port = DEFAULT_SIP_PORT; - parseValue(node, PORT_KEY, port); + parseValue(node, Conf::PORT_KEY, port); localPort_ = port; - parseValue(node, SAME_AS_LOCAL_KEY, publishedSameasLocal_); + parseValue(node, Conf::SAME_AS_LOCAL_KEY, publishedSameasLocal_); std::string publishedIpAddress; - parseValue(node, PUBLISH_ADDR_KEY, publishedIpAddress); + parseValue(node, Conf::PUBLISH_ADDR_KEY, publishedIpAddress); IpAddr publishedIp = publishedIpAddress; if (publishedIp and not publishedSameasLocal_) setPublishedAddress(publishedIp); - parseValue(node, PUBLISH_PORT_KEY, port); + parseValue(node, Conf::PUBLISH_PORT_KEY, port); publishedPort_ = port; - parseValue(node, DTMF_TYPE_KEY, dtmfType_); + parseValue(node, Conf::DTMF_TYPE_KEY, dtmfType_); // get tls submap - const auto &tlsMap = node[TLS_KEY]; - parseValue(tlsMap, TLS_PORT_KEY, tlsListenerPort_); + const auto &tlsMap = node[Conf::TLS_KEY]; + parseValue(tlsMap, Conf::TLS_PORT_KEY, tlsListenerPort_); - unserializeRange(node, AUDIO_PORT_MIN_KEY, AUDIO_PORT_MAX_KEY, audioPortRange_); - unserializeRange(node, VIDEO_PORT_MIN_KEY, VIDEO_PORT_MAX_KEY, videoPortRange_); + unserializeRange(node, Conf::AUDIO_PORT_MIN_KEY, Conf::AUDIO_PORT_MAX_KEY, audioPortRange_); + unserializeRange(node, Conf::VIDEO_PORT_MIN_KEY, Conf::VIDEO_PORT_MAX_KEY, videoPortRange_); } @@ -169,32 +168,32 @@ void SIPAccountBase::setAccountDetails(const std::map<std::string, std::string> { Account::setAccountDetails(details); - parseBool(details, CONFIG_VIDEO_ENABLED, videoEnabled_); + parseBool(details, Conf::CONFIG_VIDEO_ENABLED, videoEnabled_); // general sip settings - parseString(details, CONFIG_LOCAL_INTERFACE, interface_); - parseBool(details, CONFIG_PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal_); - parseString(details, CONFIG_PUBLISHED_ADDRESS, publishedIpAddress_); - parseInt(details, CONFIG_LOCAL_PORT, localPort_); - parseInt(details, CONFIG_PUBLISHED_PORT, publishedPort_); + parseString(details, Conf::CONFIG_LOCAL_INTERFACE, interface_); + parseBool(details, Conf::CONFIG_PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal_); + parseString(details, Conf::CONFIG_PUBLISHED_ADDRESS, publishedIpAddress_); + parseInt(details, Conf::CONFIG_LOCAL_PORT, localPort_); + parseInt(details, Conf::CONFIG_PUBLISHED_PORT, publishedPort_); - parseString(details, CONFIG_ACCOUNT_DTMF_TYPE, dtmfType_); + parseString(details, Conf::CONFIG_ACCOUNT_DTMF_TYPE, dtmfType_); int tmpMin = -1; - parseInt(details, CONFIG_ACCOUNT_AUDIO_PORT_MIN, tmpMin); + parseInt(details, Conf::CONFIG_ACCOUNT_AUDIO_PORT_MIN, tmpMin); int tmpMax = -1; - parseInt(details, CONFIG_ACCOUNT_AUDIO_PORT_MAX, tmpMax); + parseInt(details, Conf::CONFIG_ACCOUNT_AUDIO_PORT_MAX, tmpMax); updateRange(tmpMin, tmpMax, audioPortRange_); #ifdef RING_VIDEO tmpMin = -1; - parseInt(details, CONFIG_ACCOUNT_VIDEO_PORT_MIN, tmpMin); + parseInt(details, Conf::CONFIG_ACCOUNT_VIDEO_PORT_MIN, tmpMin); tmpMax = -1; - parseInt(details, CONFIG_ACCOUNT_VIDEO_PORT_MAX, tmpMax); + parseInt(details, Conf::CONFIG_ACCOUNT_VIDEO_PORT_MAX, tmpMax); updateRange(tmpMin, tmpMax, videoPortRange_); #endif // TLS - parseInt(details, CONFIG_TLS_LISTENER_PORT, tlsListenerPort_); + parseInt(details, Conf::CONFIG_TLS_LISTENER_PORT, tlsListenerPort_); } std::map<std::string, std::string> @@ -203,31 +202,31 @@ SIPAccountBase::getAccountDetails() const std::map<std::string, std::string> a = Account::getAccountDetails(); // note: The IP2IP profile will always have IP2IP as an alias - a[CONFIG_VIDEO_ENABLED] = videoEnabled_ ? TRUE_STR : FALSE_STR; - a[CONFIG_ACCOUNT_REGISTRATION_STATUS] = isIP2IP() ? "READY" : mapStateNumberToString(registrationState_); + a[Conf::CONFIG_VIDEO_ENABLED] = videoEnabled_ ? TRUE_STR : FALSE_STR; + a[Conf::CONFIG_ACCOUNT_REGISTRATION_STATUS] = isIP2IP() ? "READY" : mapStateNumberToString(registrationState_); // Add sip specific details - addRangeToDetails(a, CONFIG_ACCOUNT_AUDIO_PORT_MIN, CONFIG_ACCOUNT_AUDIO_PORT_MAX, audioPortRange_); + addRangeToDetails(a, Conf::CONFIG_ACCOUNT_AUDIO_PORT_MIN, Conf::CONFIG_ACCOUNT_AUDIO_PORT_MAX, audioPortRange_); #ifdef RING_VIDEO - addRangeToDetails(a, CONFIG_ACCOUNT_VIDEO_PORT_MIN, CONFIG_ACCOUNT_VIDEO_PORT_MAX, videoPortRange_); + addRangeToDetails(a, Conf::CONFIG_ACCOUNT_VIDEO_PORT_MIN, Conf::CONFIG_ACCOUNT_VIDEO_PORT_MAX, videoPortRange_); #endif - a[CONFIG_ACCOUNT_DTMF_TYPE] = dtmfType_; - a[CONFIG_LOCAL_INTERFACE] = interface_; - a[CONFIG_PUBLISHED_SAMEAS_LOCAL] = publishedSameasLocal_ ? TRUE_STR : FALSE_STR; - a[CONFIG_PUBLISHED_ADDRESS] = publishedIpAddress_; + a[Conf::CONFIG_ACCOUNT_DTMF_TYPE] = dtmfType_; + a[Conf::CONFIG_LOCAL_INTERFACE] = interface_; + a[Conf::CONFIG_PUBLISHED_SAMEAS_LOCAL] = publishedSameasLocal_ ? TRUE_STR : FALSE_STR; + a[Conf::CONFIG_PUBLISHED_ADDRESS] = publishedIpAddress_; std::stringstream localport; localport << localPort_; - a[CONFIG_LOCAL_PORT] = localport.str(); + a[Conf::CONFIG_LOCAL_PORT] = localport.str(); std::stringstream publishedport; publishedport << publishedPort_; - a[CONFIG_PUBLISHED_PORT] = publishedport.str(); + a[Conf::CONFIG_PUBLISHED_PORT] = publishedport.str(); std::stringstream tlslistenerport; tlslistenerport << tlsListenerPort_; - a[CONFIG_TLS_LISTENER_PORT] = tlslistenerport.str(); + a[Conf::CONFIG_TLS_LISTENER_PORT] = tlslistenerport.str(); return a; } @@ -235,11 +234,11 @@ std::map<std::string, std::string> SIPAccountBase::getVolatileAccountDetails() const { std::map<std::string, std::string> a = Account::getVolatileAccountDetails(); - a[CONFIG_ACCOUNT_REGISTRATION_STATUS] = isIP2IP() ? "READY" : mapStateNumberToString(registrationState_); + a[Conf::CONFIG_ACCOUNT_REGISTRATION_STATUS] = isIP2IP() ? "READY" : mapStateNumberToString(registrationState_); std::stringstream codestream; codestream << transportStatus_; - a[CONFIG_TRANSPORT_STATE_CODE] = codestream.str(); - a[CONFIG_TRANSPORT_STATE_DESC] = transportError_ ; + a[Conf::CONFIG_TRANSPORT_STATE_CODE] = codestream.str(); + a[Conf::CONFIG_TRANSPORT_STATE_DESC] = transportError_ ; return a; } @@ -280,7 +279,6 @@ SIPAccountBase::onTransportStateChanged(pjsip_transport_state state, const pjsip void SIPAccountBase::setTransport(const std::shared_ptr<SipTransport>& t) { - using namespace std::placeholders; if (t == transport_) return; if (transport_) { @@ -291,7 +289,7 @@ SIPAccountBase::setTransport(const std::shared_ptr<SipTransport>& t) transport_ = t; if (transport_) - transport_->addStateListener(reinterpret_cast<uintptr_t>(this), std::bind(&SIPAccountBase::onTransportStateChanged, this, _1, _2)); + transport_->addStateListener(reinterpret_cast<uintptr_t>(this), std::bind(&SIPAccountBase::onTransportStateChanged, this, std::placeholders::_1, std::placeholders::_2)); } // returns even number in range [lower, upper] @@ -328,3 +326,5 @@ SIPAccountBase::generateVideoPort() const return getRandomEvenNumber(videoPortRange_); } #endif + +} // namespace ring diff --git a/daemon/src/sip/sipaccountbase.h b/daemon/src/sip/sipaccountbase.h index f7fda76fe951897f1632b27ea9eb97803ec1aa1a..d47721187057e5db03e13b549238ced1ac974205 100644 --- a/daemon/src/sip/sipaccountbase.h +++ b/daemon/src/sip/sipaccountbase.h @@ -47,7 +47,7 @@ #include <map> #include <sstream> -typedef std::vector<pj_ssl_cipher> CipherArray; +namespace ring { namespace Conf { // SIP specific configuration keys @@ -89,6 +89,8 @@ namespace Conf { const char *const VIDEO_PORT_MAX_KEY = "videoPortMax"; } +typedef std::vector<pj_ssl_cipher> CipherArray; + class SIPVoIPLink; class SIPCall; @@ -378,4 +380,6 @@ private: }; +} // namespace ring + #endif diff --git a/daemon/src/sip/sipcall.cpp b/daemon/src/sip/sipcall.cpp index 31575639a060abda2d542260573e148a99bd400e..0fea72980af81c44e9d3723ca7debbf0ae6a315e 100644 --- a/daemon/src/sip/sipcall.cpp +++ b/daemon/src/sip/sipcall.cpp @@ -43,9 +43,6 @@ #include "manager.h" #include "array_size.h" -using namespace ring; - - #include "audio/audiortp/avformat_rtp_session.h" #include "client/callmanager.h" @@ -56,10 +53,13 @@ using namespace ring; #ifdef RING_VIDEO #include "video/video_rtp_session.h" #include "client/videomanager.h" - #include <chrono> +#endif + +namespace ring { -static ring::video::VideoSettings +#ifdef RING_VIDEO +static video::VideoSettings getSettings() { const auto videoman = Manager::instance().getClient()->getVideoManager(); @@ -118,8 +118,8 @@ dtmfSend(SIPCall &call, char code, const std::string &dtmf) SIPCall::SIPCall(SIPAccountBase& account, const std::string& id, Call::CallType type) : Call(account, id, type) - //, avformatrtp_(new ring::AVFormatRtpSession(id, /* FIXME: These are video! */ getSettings())) - , avformatrtp_(new ring::AVFormatRtpSession(id, *new std::map<std::string, std::string>)) + //, avformatrtp_(new AVFormatRtpSession(id, /* FIXME: These are video! */ getSettings())) + , avformatrtp_(new AVFormatRtpSession(id, *new std::map<std::string, std::string>)) #ifdef RING_VIDEO // The ID is used to associate video streams to calls , videortp_(id, getSettings()) @@ -181,8 +181,6 @@ void SIPCall::setContactHeader(pj_str_t *contact) std::map<std::string, std::string> SIPCall::createHistoryEntry() const { - using ring::HistoryItem; - std::map<std::string, std::string> entry(Call::createHistoryEntry()); return entry; } @@ -587,14 +585,14 @@ SIPCall::internalOffHold(const std::function<void()> &SDPUpdateFunc) if (not setState(Call::ACTIVE)) return; - std::vector<ring::AudioCodec*> sessionMedia(sdp_->getSessionAudioMedia()); + std::vector<AudioCodec*> sessionMedia(sdp_->getSessionAudioMedia()); if (sessionMedia.empty()) { RING_WARN("Session media is empty"); return; } - std::vector<ring::AudioCodec*> audioCodecs; + std::vector<AudioCodec*> audioCodecs; for (auto & i : sessionMedia) { @@ -602,7 +600,7 @@ SIPCall::internalOffHold(const std::function<void()> &SDPUpdateFunc) continue; // Create a new instance for this codec - ring::AudioCodec* ac = Manager::instance().audioCodecFactory.instantiateCodec(i->getPayloadType()); + AudioCodec* ac = Manager::instance().audioCodecFactory.instantiateCodec(i->getPayloadType()); if (ac == NULL) { RING_ERR("Could not instantiate codec %d", i->getPayloadType()); @@ -667,17 +665,16 @@ SIPCall::carryingDTMFdigits(char code) void SIPCall::sendTextMessage(const std::string &message, const std::string &from) { - using namespace ring::InstantMessaging; - if (not inv) throw VoipLinkException("No invite session for this call"); /* Send IM message */ - UriList list; - UriEntry entry; - entry[ring::IM_XML_URI] = std::string("\"" + from + "\""); // add double quotes for xml formating + InstantMessaging::UriList list; + InstantMessaging::UriEntry entry; + entry[InstantMessaging::IM_XML_URI] = std::string("\"" + from + "\""); // add double quotes for xml formating list.push_front(entry); - send_sip_message(inv.get(), getCallId(), appendUriList(message, list)); + auto msg = InstantMessaging::appendUriList(message, list); + InstantMessaging::send_sip_message(inv.get(), getCallId(), msg); } #endif // HAVE_INSTANT_MESSAGING @@ -728,13 +725,13 @@ SIPCall::setupLocalSDPFromIce() #endif } -std::vector<ring::IceCandidate> +std::vector<IceCandidate> SIPCall::getAllRemoteCandidates() { - std::vector<ring::IceCandidate> rem_candidates; + std::vector<IceCandidate> rem_candidates; auto addSDPCandidates = [this](unsigned sdpMediaId, - std::vector<ring::IceCandidate>& out) { + std::vector<IceCandidate>& out) { IceCandidate cand; for (auto& line : sdp_->getIceCandidates(sdpMediaId)) { if (iceTransport_->getCandidateFromSDP(line, cand)) @@ -770,8 +767,8 @@ SIPCall::startAllMedia() avformatrtp_->updateSDP(*sdp_); avformatrtp_->updateDestination(remoteIP, sdp_->getRemoteAudioPort()); if (isIceRunning()) { - std::unique_ptr<ring::IceSocket> sockRTP(newIceSocket(0)); - std::unique_ptr<ring::IceSocket> sockRTCP(newIceSocket(1)); + std::unique_ptr<IceSocket> sockRTP(newIceSocket(0)); + std::unique_ptr<IceSocket> sockRTCP(newIceSocket(1)); avformatrtp_->start(std::move(sockRTP), std::move(sockRTCP)); } else { const auto localAudioPort = sdp_->getLocalAudioPort(); @@ -783,8 +780,8 @@ SIPCall::startAllMedia() videortp_.updateSDP(*sdp_); videortp_.updateDestination(remoteIP, remoteVideoPort); if (isIceRunning()) { - std::unique_ptr<ring::IceSocket> sockRTP(newIceSocket(2)); - std::unique_ptr<ring::IceSocket> sockRTCP(newIceSocket(3)); + std::unique_ptr<IceSocket> sockRTP(newIceSocket(2)); + std::unique_ptr<IceSocket> sockRTCP(newIceSocket(3)); try { videortp_.start(std::move(sockRTP), std::move(sockRTCP)); } catch (const std::runtime_error &e) { @@ -804,7 +801,7 @@ SIPCall::startAllMedia() CryptoOffer crypto_offer; getSDP().getRemoteSdpCryptoFromOffer(sdp_->getActiveRemoteSdpSession(), crypto_offer); - std::vector<ring::AudioCodec*> sessionMedia(sdp_->getSessionAudioMedia()); + std::vector<AudioCodec*> sessionMedia(sdp_->getSessionAudioMedia()); if (sessionMedia.empty()) { RING_WARN("Session media is empty"); @@ -822,7 +819,7 @@ SIPCall::startAllMedia() const int pl = i->getPayloadType(); - ring::AudioCodec *ac = Manager::instance().audioCodecFactory.instantiateCodec(pl); + AudioCodec *ac = Manager::instance().audioCodecFactory.instantiateCodec(pl); if (!ac) { RING_ERR("Could not instantiate codec %d", pl); @@ -846,3 +843,5 @@ SIPCall::stopAllMedias() videortp_.stop(); #endif } + +} // namespace ring diff --git a/daemon/src/sip/sipcall.h b/daemon/src/sip/sipcall.h index e8dfbecc9b8eb384ec3250cd7e6b49cc19637a26..5880f1501fc7632752bea5276d896b8dc337771b 100644 --- a/daemon/src/sip/sipcall.h +++ b/daemon/src/sip/sipcall.h @@ -53,13 +53,12 @@ struct pjsip_evsub; struct pjsip_inv_session; +namespace ring { + class Sdp; class SIPAccountBase; class SipTransport; - -namespace ring { class AVFormatRtpSession; -} /** * @file sipcall.h @@ -95,7 +94,7 @@ class SIPCall : public Call /** * Returns a pointer to the AVFormatRtpSession object */ - ring::AVFormatRtpSession& getAVFormatRTP() const { + AVFormatRtpSession& getAVFormatRTP() const { return *avformatrtp_; } @@ -103,7 +102,7 @@ class SIPCall : public Call /** * Returns a pointer to the VideoRtp object */ - ring::video::VideoRtpSession& getVideoRtp () { + video::VideoRtpSession& getVideoRtp () { return videortp_; } #endif @@ -197,15 +196,15 @@ class SIPCall : public Call int SIPSessionReinvite(); - std::vector<ring::IceCandidate> getAllRemoteCandidates(); + std::vector<IceCandidate> getAllRemoteCandidates(); - std::unique_ptr<ring::AVFormatRtpSession> avformatrtp_; + std::unique_ptr<AVFormatRtpSession> avformatrtp_; #ifdef RING_VIDEO /** * Video Rtp Session factory */ - ring::video::VideoRtpSession videortp_; + video::VideoRtpSession videortp_; #endif /** @@ -224,4 +223,6 @@ class SIPCall : public Call pj_str_t contactHeader_ {contactBuffer_, 0}; }; +} // namespace ring + #endif // __SIPCALL_H__ diff --git a/daemon/src/sip/sippresence.cpp b/daemon/src/sip/sippresence.cpp index 5c5669a37a3a75961c7b22c091ea129dc7faaf15..2f361e8f91640cd72ab774706667e34069564e2e 100644 --- a/daemon/src/sip/sippresence.cpp +++ b/daemon/src/sip/sippresence.cpp @@ -47,6 +47,8 @@ #define MAX_N_SUB_SERVER 50 #define MAX_N_SUB_CLIENT 50 +namespace ring { + SIPPresence::SIPPresence(SIPAccount *acc) : publish_sess_() , status_data_() @@ -555,3 +557,5 @@ SIPPresence::publish(SIPPresence *pres) return PJ_SUCCESS; } + +} // namespace ring diff --git a/daemon/src/sip/sippresence.h b/daemon/src/sip/sippresence.h index 1d22ee52873df6fef1a3eff991657cdffcac5fa3..8efe56208dcac78b6963cbc7a6eb8b7255227e2b 100644 --- a/daemon/src/sip/sippresence.h +++ b/daemon/src/sip/sippresence.h @@ -49,6 +49,13 @@ #define PRESENCE_LOCK_FLAG 1 #define PRESENCE_CLIENT_LOCK_FLAG 2 +/** + * TODO Clean this: + */ +struct pj_caching_pool; + +namespace ring { + struct pres_msg_data { /** * Additional message headers as linked list. Application can add @@ -86,15 +93,9 @@ struct pres_msg_data { pjsip_multipart_part multipart_parts; }; - - class SIPAccount; class PresSubClient; class PresSubServer; -/** - * TODO Clean this: - */ -struct pj_caching_pool; /** @@ -252,4 +253,6 @@ class SIPPresence { pj_pool_t *pool_; }; +} // namespace ring + #endif diff --git a/daemon/src/sip/siptransport.cpp b/daemon/src/sip/siptransport.cpp index 2eed77e57e76a58018b8f4f5103f60a8140acbf6..8c6b65fbf757ab18e5dfa8bb68527ab5132deb34 100644 --- a/daemon/src/sip/siptransport.cpp +++ b/daemon/src/sip/siptransport.cpp @@ -57,6 +57,8 @@ #define RETURN_IF_FAIL(A, VAL, M, ...) if (!(A)) { RING_ERR(M, ##__VA_ARGS__); return (VAL); } +namespace ring { + // FIXME: remove this when pjsip_tp_state_callback gives us enough info static SipTransportBroker* instance = nullptr; @@ -433,7 +435,7 @@ SipTransportBroker::getTlsTransport(const std::shared_ptr<TlsListener>& l, const #if HAVE_DHT std::shared_ptr<SipTransport> -SipTransportBroker::getIceTransport(const std::shared_ptr<ring::IceTransport> ice, unsigned comp_id) +SipTransportBroker::getIceTransport(const std::shared_ptr<IceTransport> ice, unsigned comp_id) { std::unique_lock<std::mutex> lock(iceMutex_); iceTransports_.emplace_front(endpt_, pool_, ice_pj_transport_type_, ice, comp_id, [=]() -> int { @@ -564,3 +566,5 @@ SipTransportBroker::findLocalAddressFromSTUN(pjsip_transport *transport, } #undef RETURN_IF_NULL + +} // namespace ring diff --git a/daemon/src/sip/siptransport.h b/daemon/src/sip/siptransport.h index f65a087dabd9364f21d1c84f68fd17f608a9386e..bca0197a53e7bdf608a9558f1e91ca2c3c6459fd 100644 --- a/daemon/src/sip/siptransport.h +++ b/daemon/src/sip/siptransport.h @@ -54,6 +54,8 @@ #define DEFAULT_SIP_PORT 5060 #define DEFAULT_SIP_TLS_PORT 5061 +namespace ring { + struct SipTransportDescr { SipTransportDescr() {} @@ -136,9 +138,8 @@ private: class IpAddr; class SipIceTransport; -namespace ring { - class IceTransport; -} +class IceTransport; + /** * Manages the transports and receive callbacks from PJSIP */ @@ -157,7 +158,7 @@ public: #endif #if HAVE_DHT - std::shared_ptr<SipTransport> getIceTransport(const std::shared_ptr<ring::IceTransport>, unsigned comp_id); + std::shared_ptr<SipTransport> getIceTransport(const std::shared_ptr<IceTransport>, unsigned comp_id); #endif std::shared_ptr<SipTransport> findTransport(pjsip_transport*); @@ -249,4 +250,6 @@ private: }; +} // namespace ring + #endif // SIPTRANSPORT_H_ diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index 6e65b611f46963f3402547c9e96f8d72b541a329..e2bf329e314a4c834c10c726b9b681ecaeecd952 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -83,7 +83,7 @@ #include <istream> #include <algorithm> -using namespace ring; +namespace ring { /** Environment variable used to set pjsip's logging level */ #define SIPLOGLEVEL "SIPLOGLEVEL" @@ -338,14 +338,14 @@ transaction_request_cb(pjsip_rx_data *rdata) call->setupLocalSDPFromIce(); - ring::AudioCodec* ac = Manager::instance().audioCodecFactory.instantiateCodec(PAYLOAD_CODEC_ULAW); + AudioCodec* ac = Manager::instance().audioCodecFactory.instantiateCodec(PAYLOAD_CODEC_ULAW); if (!ac) { RING_ERR("Could not instantiate codec"); return PJ_FALSE; } - std::vector<ring::AudioCodec *> audioCodecs; + std::vector<AudioCodec *> audioCodecs; audioCodecs.push_back(ac); pjsip_dialog *dialog = 0; @@ -1137,12 +1137,10 @@ transaction_state_changed_cb(pjsip_inv_session * inv, pjsip_transaction *tsx, std::string formattedMessage(formattedMsgPtr, strlen(formattedMsgPtr)); - using namespace ring::InstantMessaging; - try { // retreive the recipient-list of this message - std::string urilist = findTextUriList(formattedMessage); - UriList list = parseXmlUriList(urilist); + std::string urilist = InstantMessaging::findTextUriList(formattedMessage); + auto list = InstantMessaging::parseXmlUriList(urilist); // If no item present in the list, peer is considered as the sender std::string from; @@ -1150,7 +1148,7 @@ transaction_state_changed_cb(pjsip_inv_session * inv, pjsip_transaction *tsx, if (list.empty()) { from = call->getPeerNumber(); } else { - from = list.front()[IM_XML_URI]; + from = list.front()[InstantMessaging::IM_XML_URI]; if (from == "Me") from = call->getPeerNumber(); @@ -1160,12 +1158,13 @@ transaction_state_changed_cb(pjsip_inv_session * inv, pjsip_transaction *tsx, if (from[0] == '<' && from[from.size() - 1] == '>') from = from.substr(1, from.size() - 2); - Manager::instance().incomingMessage(call->getCallId(), from, findTextMessage(formattedMessage)); + Manager::instance().incomingMessage(call->getCallId(), from, + InstantMessaging::findTextMessage(formattedMessage)); // Respond with a 200/OK sendOK(inv->dlg, r_data, tsx); - } catch (const ring::InstantMessageException &except) { + } catch (const InstantMessaging::InstantMessageException &except) { RING_ERR("%s", except.what()); } #endif @@ -1220,7 +1219,7 @@ SIPVoIPLink::resolveSrvName(const std::string &name, pjsip_transport_type_e type 0, type, {{(char*)name.data(), (pj_ssize_t)name.size()}, 0}, }; - auto token = std::hash<std::string>()(name + ring::to_string(type)); + auto token = std::hash<std::string>()(name + to_string(type)); { std::lock_guard<std::mutex> lock(resolveMutex_); resolveCallbacks_[token] = [cb](pj_status_t s, const pjsip_server_addresses* r) { @@ -1259,3 +1258,5 @@ SIPVoIPLink::resolver_callback(pj_status_t status, void *token, const struct pjs } } } + +} // namespace ring diff --git a/daemon/src/sip/sipvoiplink.h b/daemon/src/sip/sipvoiplink.h index 99416d296c253e5540718ef00e95094f65b74095..ea3a8acff3ea09325f4bbfafbfdae14e15fbc539 100644 --- a/daemon/src/sip/sipvoiplink.h +++ b/daemon/src/sip/sipvoiplink.h @@ -59,6 +59,8 @@ #include <mutex> #include <memory> +namespace ring { + class SIPCall; class SIPAccountBase; class SIPVoIPLink; @@ -172,4 +174,6 @@ class SIPVoIPLink { friend class SIPTest; }; +} // namespace ring + #endif // SIPVOIPLINK_H_ diff --git a/daemon/src/sip/tlsvalidator.cpp b/daemon/src/sip/tlsvalidator.cpp index 3549a960171bfe2c309e60d94d4818895ff9e74b..c7b1e203f81528516d8f31f99cfa11c7f101330c 100644 --- a/daemon/src/sip/tlsvalidator.cpp +++ b/daemon/src/sip/tlsvalidator.cpp @@ -61,7 +61,9 @@ #include <gnutls/gnutls.h> #include <gnutls/x509.h> -const ring::EnumClassNames<TlsValidator::CheckValues> TlsValidator::CheckValuesNames = {{ +namespace ring { + +const EnumClassNames<TlsValidator::CheckValues> TlsValidator::CheckValuesNames = {{ /* CheckValues Name */ /* PASSED */ "PASSED" , /* FAILED */ "FAILED" , @@ -71,7 +73,7 @@ const ring::EnumClassNames<TlsValidator::CheckValues> TlsValidator::CheckValuesN /* CUSTOM */ "DATE" , }}; -const ring::CallbackMatrix1D<TlsValidator::CertificateCheck, TlsValidator, TlsValidator::CheckResult> TlsValidator::checkCallback = {{ +const CallbackMatrix1D<TlsValidator::CertificateCheck, TlsValidator, TlsValidator::CheckResult> TlsValidator::checkCallback = {{ /* CertificateCheck Callback */ /*HAS_PRIVATE_KEY */ &TlsValidator::hasPrivateKey , /*EXPIRED */ &TlsValidator::notExpired , @@ -98,7 +100,7 @@ const ring::CallbackMatrix1D<TlsValidator::CertificateCheck, TlsValidator, TlsVa }}; -const ring::CallbackMatrix1D<TlsValidator::CertificateDetails, TlsValidator, TlsValidator::CheckResult> TlsValidator::getterCallback = {{ +const CallbackMatrix1D<TlsValidator::CertificateDetails, TlsValidator, TlsValidator::CheckResult> TlsValidator::getterCallback = {{ /* EXPIRATION_DATE */ &TlsValidator::getExpirationDate , /* ACTIVATION_DATE */ &TlsValidator::getActivationDate , /* REQUIRE_PRIVATE_KEY_PASSWORD */ &TlsValidator::requirePrivateKeyPassword , @@ -118,7 +120,7 @@ const ring::CallbackMatrix1D<TlsValidator::CertificateDetails, TlsValidator, Tls /* NEXT_EXPECTED_UPDATE_DATE */ &TlsValidator::getIssuerDN , // TODO }}; -const ring::Matrix1D<TlsValidator::CertificateCheck, TlsValidator::CheckValuesType> TlsValidator::enforcedCheckType = {{ +const Matrix1D<TlsValidator::CertificateCheck, TlsValidator::CheckValuesType> TlsValidator::enforcedCheckType = {{ /* CertificateCheck Callback */ /*HAS_PRIVATE_KEY */ CheckValuesType::BOOLEAN , /*EXPIRED */ CheckValuesType::BOOLEAN , @@ -147,7 +149,7 @@ const ring::Matrix1D<TlsValidator::CertificateCheck, TlsValidator::CheckValuesTy /*NOT_ACTIVATED */ CheckValuesType::BOOLEAN , }}; -const ring::EnumClassNames<TlsValidator::CertificateCheck> TlsValidator::CertificateCheckNames = {{ +const EnumClassNames<TlsValidator::CertificateCheck> TlsValidator::CertificateCheckNames = {{ /* CertificateCheck Name */ /*HAS_PRIVATE_KEY */ "HAS_PRIVATE_KEY" , /*EXPIRED */ "EXPIRED" , @@ -176,7 +178,7 @@ const ring::EnumClassNames<TlsValidator::CertificateCheck> TlsValidator::Certifi /*NOT_ACTIVATED */ "NOT_ACTIVATED" , }}; -const ring::EnumClassNames<TlsValidator::CertificateDetails> TlsValidator::CertificateDetailsNames = {{ +const EnumClassNames<TlsValidator::CertificateDetails> TlsValidator::CertificateDetailsNames = {{ /* EXPIRATION_DATE */ "EXPIRATION_DATE" , /* ACTIVATION_DATE */ "ACTIVATION_DATE" , /* REQUIRE_PRIVATE_KEY_PASSWORD */ "REQUIRE_PRIVATE_KEY_PASSWORD" , @@ -196,7 +198,7 @@ const ring::EnumClassNames<TlsValidator::CertificateDetails> TlsValidator::Certi /* NEXT_EXPECTED_UPDATE_DATE */ "NEXT_EXPECTED_UPDATE_DATE" , }}; -const ring::EnumClassNames<const TlsValidator::CheckValuesType> TlsValidator::CheckValuesTypeNames = {{ +const EnumClassNames<const TlsValidator::CheckValuesType> TlsValidator::CheckValuesTypeNames = {{ /* Type Name */ /* BOOLEAN */ "BOOLEAN" , /* ISO_DATE */ "ISO_DATE" , @@ -204,7 +206,7 @@ const ring::EnumClassNames<const TlsValidator::CheckValuesType> TlsValidator::Ch /* NUMBER */ "NUMBER" , }}; -const ring::Matrix2D<TlsValidator::CheckValuesType , TlsValidator::CheckValues , bool> TlsValidator::acceptedCheckValuesResult = {{ +const Matrix2D<TlsValidator::CheckValuesType , TlsValidator::CheckValues , bool> TlsValidator::acceptedCheckValuesResult = {{ /* Type PASSED FAILED UNSUPPORTED ISO_DATE CUSTOM NUMBER */ /* BOOLEAN */ {{ true , true , true , false , false ,false }}, /* ISO_DATE */ {{ false , false , true , true , false , false }}, @@ -277,7 +279,7 @@ std::string TlsValidator::getStringValue(const TlsValidator::CertificateCheck ch */ bool TlsValidator::isValid(bool verbose) { - for (const CertificateCheck check : ring::Matrix0D<CertificateCheck>()) { + for (const CertificateCheck check : Matrix0D<CertificateCheck>()) { if (enforcedCheckType[check] == CheckValuesType::BOOLEAN) { if (((this->*(checkCallback[check]))()).first == CheckValues::FAILED) { if (verbose) @@ -301,7 +303,7 @@ std::map<std::string,std::string> TlsValidator::getSerializedChecks() = getStringValue(CertificateCheck::EXIST, exist()); } else { - for (const CertificateCheck check : ring::Matrix0D<CertificateCheck>()) + for (const CertificateCheck check : Matrix0D<CertificateCheck>()) ret[CertificateCheckNames[check]] = getStringValue(check,(this->*(checkCallback[check]))()); } @@ -315,7 +317,7 @@ std::map<std::string,std::string> TlsValidator::getSerializedDetails() { std::map<std::string,std::string> ret; if (certificateFound_) { - for (const CertificateDetails det : ring::Matrix0D<CertificateDetails>()) { + for (const CertificateDetails det : Matrix0D<CertificateDetails>()) { const CheckResult r = (this->*(getterCallback[det]))(); std::string val; // TODO move this to a fuction @@ -1174,3 +1176,5 @@ TlsValidator::CheckResult TlsValidator::getActivationDate() return formatDate(expiration); } + +} // namespace ring diff --git a/daemon/src/sip/tlsvalidator.h b/daemon/src/sip/tlsvalidator.h index 3283d1b521845246deaedd7c072220fcd6070499..fdd33508bc0d05e1f67a54ac77a0dd9b6772154e 100644 --- a/daemon/src/sip/tlsvalidator.h +++ b/daemon/src/sip/tlsvalidator.h @@ -31,6 +31,8 @@ #include <string> #include <vector> +namespace ring { + class TlsValidatorException : public std::runtime_error { public: TlsValidatorException(const std::string& str) : std::runtime_error(str) {}; @@ -197,30 +199,30 @@ public: private: // Enum class names - static const ring::EnumClassNames<CertificateCheck> CertificateCheckNames; + static const EnumClassNames<CertificateCheck> CertificateCheckNames; - static const ring::EnumClassNames<CertificateDetails> CertificateDetailsNames; + static const EnumClassNames<CertificateDetails> CertificateDetailsNames; - static const ring::EnumClassNames<const CheckValuesType> CheckValuesTypeNames; + static const EnumClassNames<const CheckValuesType> CheckValuesTypeNames; - static const ring::EnumClassNames<CheckValues> CheckValuesNames; + static const EnumClassNames<CheckValues> CheckValuesNames; /** * Map check to their check method */ - static const ring::CallbackMatrix1D<CertificateCheck, TlsValidator, CheckResult> checkCallback; + static const CallbackMatrix1D<CertificateCheck, TlsValidator, CheckResult> checkCallback; /** * Map check to their getter method */ - static const ring::CallbackMatrix1D<CertificateDetails, TlsValidator, CheckResult> getterCallback; + static const CallbackMatrix1D<CertificateDetails, TlsValidator, CheckResult> getterCallback; /** * Valid values for each categories */ - static const ring::Matrix2D<CheckValuesType , CheckValues , bool> acceptedCheckValuesResult; + static const Matrix2D<CheckValuesType , CheckValues , bool> acceptedCheckValuesResult; - static const ring::Matrix1D<CertificateCheck, CheckValuesType> enforcedCheckType; + static const Matrix1D<CertificateCheck, CheckValuesType> enforcedCheckType; std::string certificatePath_; std::string privateKeyPath_; @@ -260,4 +262,6 @@ public: }; // TlsValidator +} // namespace ring + #endif diff --git a/daemon/src/string_utils.cpp b/daemon/src/string_utils.cpp index b9699a5cc486e945a311c39d2785c0309f0da271..6158b048383e45b39f4a7fa3fb496de79eba2ee8 100644 --- a/daemon/src/string_utils.cpp +++ b/daemon/src/string_utils.cpp @@ -47,4 +47,4 @@ split_string(const std::string &s, char delim) return result; } -} +} // namespace ring diff --git a/daemon/src/string_utils.h b/daemon/src/string_utils.h index af5ae328c2f48f9ef8c49135b4b7eaaa378d3034..82738e983a1d252bf61df493ccffbb6f71271ff9 100644 --- a/daemon/src/string_utils.h +++ b/daemon/src/string_utils.h @@ -65,6 +65,6 @@ std::string to_string(T &&value) std::vector<std::string> split_string(const std::string& s, char sep); -} +} // namespace ring #endif diff --git a/daemon/src/threadloop.cpp b/daemon/src/threadloop.cpp index 0cfe1071b66a3b6d1cc6201a10236661559a62c2..693398c6b17f824ddaebb479818b28f06059355b 100644 --- a/daemon/src/threadloop.cpp +++ b/daemon/src/threadloop.cpp @@ -32,6 +32,8 @@ #include "threadloop.h" #include "logger.h" +namespace ring { + void ThreadLoop::mainloop() { try { @@ -95,3 +97,5 @@ bool ThreadLoop::isRunning() const { return running_; } + +} // namespace ring diff --git a/daemon/src/threadloop.h b/daemon/src/threadloop.h index c4f6d36e0ed4d58bb549f598e704e366ecbb6eca..95659ecc53430a7a06d0db76a1c3a6f6e82a7dd7 100644 --- a/daemon/src/threadloop.h +++ b/daemon/src/threadloop.h @@ -37,6 +37,8 @@ #include <functional> #include <stdexcept> +namespace ring { + // FIXME: this is ugly // If condition A is false, print the error message in M and exit thread #define EXIT_IF_FAIL(A, M, ...) if (!(A)) { \ @@ -72,4 +74,6 @@ private: std::thread thread_ = {}; }; +} // namespace ring + #endif // __THREADLOOP_H__ diff --git a/daemon/src/utf8_utils.cpp b/daemon/src/utf8_utils.cpp index 72af6a6d8e5d1a935f6cff0c18c60ee7b1e156a6..2751b66e2c6b74df31657202c8612057e3bee146 100644 --- a/daemon/src/utf8_utils.cpp +++ b/daemon/src/utf8_utils.cpp @@ -70,6 +70,8 @@ val <<= 6; \ val |= (*(unsigned char *)p) & 0x3f; +namespace ring { + static const char * fast_validate(const char *str) { @@ -302,3 +304,5 @@ utf8_make_valid(const std::string & name) return answer; } + +} // namespace ring diff --git a/daemon/src/utf8_utils.h b/daemon/src/utf8_utils.h index 88a1ca921915deb2e5c74160923497f11ab47b27..111ebffb671a2f799e84145a0166b95f43e22ad3 100644 --- a/daemon/src/utf8_utils.h +++ b/daemon/src/utf8_utils.h @@ -37,6 +37,8 @@ #include <cstdlib> #include <string> +namespace ring { + /** * utf8_validate: * @@ -66,4 +68,6 @@ utf8_validate(const std::string & str); std::string utf8_make_valid(const std::string & name); +} // namespace ring + #endif // H_UTF8_UTILS diff --git a/daemon/test/accounttest.cpp b/daemon/test/accounttest.cpp index 571a14bd4c79bc69efac13cd1da061796e08e52a..cc1a6d088bb89ae25c0cd2ef889b0d90858d1207 100644 --- a/daemon/test/accounttest.cpp +++ b/daemon/test/accounttest.cpp @@ -37,15 +37,17 @@ #include "client/configurationmanager.h" #include "logger.h" +namespace ring { namespace test { + void AccountTest::TestAddRemove() { RING_DBG("-------------------- %s --------------------\n", __PRETTY_FUNCTION__); std::map<std::string, std::string> details(Manager::instance().getClient()->getConfigurationManager()->getAccountTemplate()); - details[CONFIG_ACCOUNT_TYPE] = "SIP"; - details[CONFIG_ACCOUNT_ENABLE] = "false"; - details[CONFIG_LOCAL_INTERFACE] = "default"; - details[CONFIG_LOCAL_PORT] = "5060"; + details[Conf::CONFIG_ACCOUNT_TYPE] = "SIP"; + details[Conf::CONFIG_ACCOUNT_ENABLE] = "false"; + details[Conf::CONFIG_LOCAL_INTERFACE] = "default"; + details[Conf::CONFIG_LOCAL_PORT] = "5060"; std::string accountId = Manager::instance().addAccount(details); CPPUNIT_ASSERT(not accountId.empty()); @@ -55,3 +57,5 @@ void AccountTest::TestAddRemove() CPPUNIT_ASSERT(!Manager::instance().hasAccount(accountId)); } + +}} // namespace ring::test diff --git a/daemon/test/accounttest.h b/daemon/test/accounttest.h index d4fda0267464c7fc96b3454b1d6358e4568c0c2c..1c1606e8131b2d433cc465c579ac5ab48c3b2988 100644 --- a/daemon/test/accounttest.h +++ b/daemon/test/accounttest.h @@ -34,6 +34,8 @@ #include <cppunit/TestFixture.h> #include <cppunit/extensions/HelperMacros.h> +namespace ring { namespace test { + class AccountTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(AccountTest); @@ -46,4 +48,6 @@ class AccountTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AccountTest, "AccountTest"); CPPUNIT_TEST_SUITE_REGISTRATION(AccountTest); +}} // namespace ring::test + #endif /* ACCOUNTTEST_H_ */ diff --git a/daemon/test/audiobuffertest.cpp b/daemon/test/audiobuffertest.cpp index ca1564cfea29d7a4d174d6af944b3bee5a492d27..f006cb8997ace7ca82ce4fe3cd3143573e4b4a66 100644 --- a/daemon/test/audiobuffertest.cpp +++ b/daemon/test/audiobuffertest.cpp @@ -34,7 +34,7 @@ #include "logger.h" #include "test_utils.h" -using namespace ring; +namespace ring { namespace test { void AudioBufferTest::testAudioBufferConstructors() { @@ -100,3 +100,5 @@ void AudioBufferTest::testAudioBufferMix() AudioBufferTest::AudioBufferTest() : CppUnit::TestCase("Audio Buffer Tests") {} + +}} // namespace ring::test diff --git a/daemon/test/audiobuffertest.h b/daemon/test/audiobuffertest.h index 82aabc87899e32f73a7a92eae97c2e8ae8fb7cdb..48cf7c2668857d03632ae841398cd8399118a822 100644 --- a/daemon/test/audiobuffertest.h +++ b/daemon/test/audiobuffertest.h @@ -42,6 +42,8 @@ * @brief Regroups unit tests related to an audio buffer. */ +namespace ring { namespace test { + class AudioBufferTest : public CppUnit::TestCase { /* @@ -65,4 +67,6 @@ class AudioBufferTest : public CppUnit::TestCase { CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AudioBufferTest, "AudioBufferTest"); CPPUNIT_TEST_SUITE_REGISTRATION(AudioBufferTest); +}} // namespace ring::test + #endif // AUDIOBUFFER_TEST_ diff --git a/daemon/test/audiocodectest.cpp b/daemon/test/audiocodectest.cpp index c9859ce4db3a2240fb13af37b3a6ec695c44aae4..2473d3fbd09df7197bd9bec3eb4972b4b1a4225d 100644 --- a/daemon/test/audiocodectest.cpp +++ b/daemon/test/audiocodectest.cpp @@ -37,18 +37,20 @@ #include "plugin_manager.h" #include "test_utils.h" -#include "ring_types.h" // for ring::AudioSample +#include "ring_types.h" // for AudioSample #include <cmath> #include <climits> +namespace ring { namespace test { + /* * Detect the power of a signal for a given frequency. * Adapted from: * http://netwerkt.wordpress.com/2011/08/25/goertzel-filter/ */ static double -goertzelFilter(ring::AudioSample *samples, double freq, unsigned N, double sample_rate) +goertzelFilter(AudioSample *samples, double freq, unsigned N, double sample_rate) { double s_prev = 0.0; double s_prev2 = 0.0; @@ -71,13 +73,13 @@ void AudioCodecTest::testCodecs() AudioCodecFactory factory(pluginMgr); const auto payloadTypes = factory.getCodecList(); - std::vector<std::shared_ptr<ring::AudioCodec>> codecs; + std::vector<std::shared_ptr<AudioCodec>> codecs; for (auto p : payloadTypes) codecs.push_back(factory.getCodec(p)); - std::vector<std::vector<ring::AudioSample>> sine = {}; - std::vector<std::vector<ring::AudioSample>> pcm; + std::vector<std::vector<AudioSample>> sine = {}; + std::vector<std::vector<AudioSample>> pcm; unsigned sampleRate = 0; double referencePower = 0.0; @@ -88,8 +90,8 @@ void AudioCodecTest::testCodecs() if (sampleRate != c->getCurrentClockRate()) { sampleRate = c->getCurrentClockRate(); const unsigned nbSamples = sampleRate * 0.02; // 20 ms worth of samples - sine = {std::vector<ring::AudioSample>(nbSamples)}; - pcm = {std::vector<ring::AudioSample>(nbSamples)}; + sine = {std::vector<AudioSample>(nbSamples)}; + pcm = {std::vector<AudioSample>(nbSamples)}; const float theta = M_2_PI * frequency_ / sampleRate; @@ -115,3 +117,5 @@ void AudioCodecTest::testCodecs() CPPUNIT_ASSERT(decodedRatio > 0.0); } } + +}} // namespace ring::test diff --git a/daemon/test/audiocodectest.h b/daemon/test/audiocodectest.h index e18a307065ad7cb71d11356a8f5afe74e63b961e..6151c9bdeba801bcae821c72e38ea1fdbc608928 100644 --- a/daemon/test/audiocodectest.h +++ b/daemon/test/audiocodectest.h @@ -44,6 +44,8 @@ #include <cppunit/TestCase.h> #include <cppunit/TestSuite.h> +namespace ring { namespace test { + class AudioCodecTest: public CppUnit::TestFixture { /* @@ -58,8 +60,11 @@ class AudioCodecTest: public CppUnit::TestFixture { public: void testCodecs(); }; + /* Register our test module */ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AudioCodecTest, "AudioCodecTest"); CPPUNIT_TEST_SUITE_REGISTRATION(AudioCodecTest); +}} // namespace ring::test + #endif // AUDIO_CODEC_TEST_ diff --git a/daemon/test/audiolayertest.cpp b/daemon/test/audiolayertest.cpp index 8a99da2b9798f5be1bd1d2bc74b97220c0e40550..88c17d048546420b6346cbb47d57155c114bddc4 100644 --- a/daemon/test/audiolayertest.cpp +++ b/daemon/test/audiolayertest.cpp @@ -37,7 +37,7 @@ #include "test_utils.h" #include <unistd.h> -using namespace ring; +namespace ring { namespace test { AudioLayerTest::AudioLayerTest() : manager_(0), pulselayer_(0), layer_(0) {} @@ -104,3 +104,5 @@ void AudioLayerTest::testPulseConnect() CPPUNIT_ASSERT(pulselayer_); } + +}} // namespace ring::test diff --git a/daemon/test/audiolayertest.h b/daemon/test/audiolayertest.h index e2791b0833dec7ec0727ac2f2e25184ecfed592e..adfc05a922a9ee2c401800fa4a4255d3c9c35092 100644 --- a/daemon/test/audiolayertest.h +++ b/daemon/test/audiolayertest.h @@ -44,11 +44,14 @@ #include "noncopyable.h" +namespace ring { + class ManagerImpl; +class PulseLayer; -namespace ring { - class PulseLayer; -} +} // namespace ring + +namespace ring { namespace test { class AudioLayerTest: public CppUnit::TestFixture { @@ -69,10 +72,12 @@ class AudioLayerTest: public CppUnit::TestFixture { NON_COPYABLE(AudioLayerTest); ManagerImpl* manager_; - ring::PulseLayer* pulselayer_; + PulseLayer* pulselayer_; int layer_; }; CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AudioLayerTest, "AudioLayerTest"); CPPUNIT_TEST_SUITE_REGISTRATION(AudioLayerTest); +}} // namespace ring::test + #endif // AUDIOLAYER_TEST_ diff --git a/daemon/test/configurationtest.cpp b/daemon/test/configurationtest.cpp index 08e291c65595b1fc57e5541ca7ad7dc70b479114..0ccc7f56e0bea0f580148fab3665a86978aab854 100644 --- a/daemon/test/configurationtest.cpp +++ b/daemon/test/configurationtest.cpp @@ -32,6 +32,8 @@ #include "fileutils.h" #include "config/yamlparser.h" +namespace ring { namespace test { + void ConfigurationTest::testNodeParse() { YAML::Node node = YAML::Load("[{a: 0, b: 1, c: 2}, {a: 0, b: 1, c: 2}]"); @@ -50,3 +52,5 @@ void ConfigurationTest::test_expand_path(void){ CPPUNIT_ASSERT(fileutils::expand_path(pattern_2) == home.append("/x")); CPPUNIT_ASSERT(fileutils::expand_path(pattern_3) == "~foo/x"); } + +}} // namespace ring::test diff --git a/daemon/test/configurationtest.h b/daemon/test/configurationtest.h index 3a4172ec0037afaa0c92f1ac39fd2e9ae9e14f32..446d9e0c42068930e52ee5125302ad0f24b44398 100644 --- a/daemon/test/configurationtest.h +++ b/daemon/test/configurationtest.h @@ -43,6 +43,8 @@ #include <cppunit/TestCase.h> #include <cppunit/TestSuite.h> +namespace ring { namespace test { + class ConfigurationTest: public CppUnit::TestFixture { /* @@ -58,8 +60,11 @@ class ConfigurationTest: public CppUnit::TestFixture { void testNodeParse(); void test_expand_path(); }; + /* Register our test module */ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ConfigurationTest, "ConfigurationTest"); CPPUNIT_TEST_SUITE_REGISTRATION(ConfigurationTest); +}} // namespace ring::test + #endif // CONFIGURATION_TEST_ diff --git a/daemon/test/historytest.cpp b/daemon/test/historytest.cpp index c65f142ad62b9b2ed7006cbf709d43c3824679cd..d153ac3f814b2762a1b2e93d73308ad079f2c399 100644 --- a/daemon/test/historytest.cpp +++ b/daemon/test/historytest.cpp @@ -35,6 +35,8 @@ #include "logger.h" #include "constants.h" +namespace ring { namespace test { + namespace { void restore() { @@ -49,8 +51,6 @@ void backup() } } -namespace ring { - void HistoryTest::setUp() { backup(); @@ -103,4 +103,4 @@ void HistoryTest::tearDown() restore(); } -} +}} // namespace ring::test diff --git a/daemon/test/historytest.h b/daemon/test/historytest.h index 2934e25552413180f1eadbb7333ccfc0ec81971e..b8671f8476f2ba564ff801885a3aedf8a86f5d40 100644 --- a/daemon/test/historytest.h +++ b/daemon/test/historytest.h @@ -37,10 +37,6 @@ // Application import #include "noncopyable.h" -namespace ring { - -class History; - /* * @file historyTest.h * @brief Regroups unitary tests related to the phone number cleanup function. @@ -49,6 +45,12 @@ class History; #ifndef HISTORY_TEST_ #define HISTORY_TEST_ +namespace ring { +class History; +} // namespace ring + +namespace ring { namespace test { + class HistoryTest : public CppUnit::TestCase { /** @@ -95,6 +97,7 @@ class HistoryTest : public CppUnit::TestCase { CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(HistoryTest, "HistoryTest"); CPPUNIT_TEST_SUITE_REGISTRATION(HistoryTest); -} + +}} // namespace ring::test #endif // HISTORY_TEST_ diff --git a/daemon/test/hooktest.cpp b/daemon/test/hooktest.cpp index 805e7e2703f81fc53156484430a4b632010744c8..1ef998148adac47191a2c3a43427b369bd506376 100644 --- a/daemon/test/hooktest.cpp +++ b/daemon/test/hooktest.cpp @@ -31,6 +31,8 @@ #include "hooktest.h" #include "hooks/urlhook.h" +namespace ring { namespace test { + void HookTest::RunHookWithNoArgs() { CPPUNIT_ASSERT(!UrlHook::runAction("ls", "")); @@ -40,3 +42,5 @@ void HookTest::RunHookWithArgs() { CPPUNIT_ASSERT(!UrlHook::runAction("ls", "-l")); } + +}} // namespace ring::test diff --git a/daemon/test/hooktest.h b/daemon/test/hooktest.h index aaf54c27adfbcaae1637714db5038433af35cb0b..d5e9e5730e48abebf368381f4f0295ce0e16dd93 100644 --- a/daemon/test/hooktest.h +++ b/daemon/test/hooktest.h @@ -34,6 +34,8 @@ #include <cppunit/TestFixture.h> #include <cppunit/extensions/HelperMacros.h> +namespace ring { namespace test { + class HookTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(HookTest); @@ -49,4 +51,6 @@ class HookTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(HookTest, "HookTest"); CPPUNIT_TEST_SUITE_REGISTRATION(HookTest); +}} // namespace ring::test + #endif /* HOOKTEST_H_ */ diff --git a/daemon/test/instantmessagingtest.cpp b/daemon/test/instantmessagingtest.cpp index 76427746ce81743c450b91f696cba86bfd2c5b57..148f2d8a921e4f63315cad885e68aecf03fbf30a 100644 --- a/daemon/test/instantmessagingtest.cpp +++ b/daemon/test/instantmessagingtest.cpp @@ -40,7 +40,7 @@ #define MAXIMUM_SIZE 10 #define DELIMITER_CHAR "\n\n" -using namespace ring::InstantMessaging; +namespace ring { namespace InstantMessaging { namespace test { void InstantMessagingTest::testSaveSingleMessage() { @@ -143,13 +143,13 @@ void InstantMessagingTest::testGenerateXmlUriList() std::cout << std::endl; // Create a test list with two entries - ring::InstantMessaging::UriList list; + UriList list; - ring::InstantMessaging::UriEntry entry1; - entry1[ring::IM_XML_URI] = "\"sip:alex@example.com\""; + UriEntry entry1; + entry1[IM_XML_URI] = "\"sip:alex@example.com\""; - ring::InstantMessaging::UriEntry entry2; - entry2[ring::IM_XML_URI] = "\"sip:manu@example.com\""; + UriEntry entry2; + entry2[IM_XML_URI] = "\"sip:manu@example.com\""; list.push_front(entry1); list.push_front(entry2); @@ -185,15 +185,15 @@ void InstantMessagingTest::testXmlUriListParsing() xmlbuffer.append("</resource-lists>"); - ring::InstantMessaging::UriList list = parseXmlUriList(xmlbuffer); + UriList list = parseXmlUriList(xmlbuffer); CPPUNIT_ASSERT(list.size() == 2); // An iterator over xml attribute - ring::InstantMessaging::UriEntry::iterator iterAttr; + UriEntry::iterator iterAttr; // An iterator over list entries for (auto &entry : list) { - iterAttr = entry.find(ring::IM_XML_URI); + iterAttr = entry.find(IM_XML_URI); CPPUNIT_ASSERT((iterAttr->second == std::string("sip:alex@example.com")) or (iterAttr->second == std::string("sip:manu@example.com"))); @@ -245,14 +245,14 @@ void InstantMessagingTest::testGetUriListArea() std::cout << "urilist: " << urilist << std::endl; - ring::InstantMessaging::UriList list = parseXmlUriList(urilist); + UriList list = parseXmlUriList(urilist); CPPUNIT_ASSERT(list.size() == 2); // order may be important, for example to identify message sender - ring::InstantMessaging::UriEntry entry = list.front(); + UriEntry entry = list.front(); CPPUNIT_ASSERT(entry.size() == 2); - ring::InstantMessaging::UriEntry::iterator iterAttr = entry.find(ring::IM_XML_URI); + UriEntry::iterator iterAttr = entry.find(IM_XML_URI); if (iterAttr == entry.end()) { RING_ERR("Did not find attribute"); @@ -284,9 +284,11 @@ void InstantMessagingTest::testIllFormatedMessage() try { std::string message = findTextMessage(formatedText); - } catch (const ring::InstantMessageException &e) { + } catch (const InstantMessageException &e) { exceptionCaught = true; } CPPUNIT_ASSERT(exceptionCaught); } + +}}} // namespace ring::InstantMessaging::test diff --git a/daemon/test/instantmessagingtest.h b/daemon/test/instantmessagingtest.h index 149cfec68a44a63af0fd47e7acbcf23d41a14553..2485acba5cf69b48ea4fa6227b685159d0b33143 100644 --- a/daemon/test/instantmessagingtest.h +++ b/daemon/test/instantmessagingtest.h @@ -42,6 +42,8 @@ #ifndef INSTANTMANAGER_TEST_ #define INSTANTMANAGER_TEST_ +namespace ring { namespace InstantMessaging { namespace test { + class InstantMessagingTest : public CppUnit::TestCase { CPPUNIT_TEST_SUITE(InstantMessagingTest); CPPUNIT_TEST(testSaveSingleMessage); @@ -69,4 +71,6 @@ class InstantMessagingTest : public CppUnit::TestCase { CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(InstantMessagingTest, "InstantMessagingTest"); CPPUNIT_TEST_SUITE_REGISTRATION(InstantMessagingTest); +}}} // namespace ring::InstantMessaging::test + #endif diff --git a/daemon/test/iptest.cpp b/daemon/test/iptest.cpp index 5eff76041272317e1fff24e623ec79dc88318441..ca8f2ac7601ac842111076fb089f4ca1966f4fec 100644 --- a/daemon/test/iptest.cpp +++ b/daemon/test/iptest.cpp @@ -34,6 +34,8 @@ #include "logger.h" #include "test_utils.h" +namespace ring { namespace test { + void IpTest::testIpAddr() { TITLE(); @@ -87,3 +89,5 @@ void IpTest::testIpAddr() } IpTest::IpTest() : CppUnit::TestCase("IP Tests") {} + +}} // namespace ring::test diff --git a/daemon/test/iptest.h b/daemon/test/iptest.h index 9d2673e63222bd08dfda4528004bfb7195867d44..5ac72f7c578704b1fa6802dd837a32b0d9893e36 100644 --- a/daemon/test/iptest.h +++ b/daemon/test/iptest.h @@ -42,6 +42,8 @@ * @brief Regroups unit tests related to an audio buffer. */ +namespace ring { namespace test { + class IpTest : public CppUnit::TestCase { /* @@ -62,4 +64,6 @@ class IpTest : public CppUnit::TestCase { CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(IpTest, "IpTest"); CPPUNIT_TEST_SUITE_REGISTRATION(IpTest); +}} // namespace ring::test + #endif // IP_TEST_ diff --git a/daemon/test/main.cpp b/daemon/test/main.cpp index e65d51dd0a290cb5d32c82c62fe6cfc38505c47e..66a202f89cd18ec921daf1861feb575533d820c4 100644 --- a/daemon/test/main.cpp +++ b/daemon/test/main.cpp @@ -65,7 +65,7 @@ int main(int argc, char* argv[]) printf("\nRing Daemon Test Suite, by Savoir-Faire Linux 2004-2015\n\n"); setConsoleLog(true); setDebugMode(true); - fileutils::FileHandle f(fileutils::create_pidfile()); + ring::fileutils::FileHandle f(ring::fileutils::create_pidfile()); if (f.fd == -1) { fprintf(stderr, "An dring instance is already running, quitting...\n"); return 1; @@ -117,7 +117,7 @@ int main(int argc, char* argv[]) printf("\n\n=== SFLphone initialization ===\n\n"); backup(); - Manager::instance().init(CONFIG_SAMPLE); + ring::Manager::instance().init(CONFIG_SAMPLE); // Get the top level suite from the registry printf("\n\n=== Test Suite: %s ===\n\n", testSuiteName.c_str()); @@ -147,7 +147,7 @@ int main(int argc, char* argv[]) bool wasSuccessful = runner.run(); printf("=== Test suite ending ===\n"); - Manager::instance().finish(); + ring::Manager::instance().finish(); restore(); diff --git a/daemon/test/numbercleanertest.cpp b/daemon/test/numbercleanertest.cpp index af7a71ae5bbc7735cf2cbf0c936c300389b9e6d4..f2c4cb0469b050f15c53b697aec3956e93652eb2 100644 --- a/daemon/test/numbercleanertest.cpp +++ b/daemon/test/numbercleanertest.cpp @@ -51,6 +51,8 @@ #define VALID_PREPENDED_NUMBER "95143334444" #define VALID_EXTENSION "136" +namespace ring { namespace test { + void NumberCleanerTest::test_format_1(void) { RING_DBG("-------------------- NumberCleanerTest::test_format_1 --------------------\n"); @@ -126,3 +128,5 @@ void NumberCleanerTest::test_format_11(void) CPPUNIT_ASSERT(NumberCleaner::clean(NUMBER_TEST_10, "9") == VALID_EXTENSION); } + +}} // namespace ring::test diff --git a/daemon/test/numbercleanertest.h b/daemon/test/numbercleanertest.h index d2220f8b51c6dd16a2b2f37f3946fc65fd7e833f..3e60df6a3bc0b92d343380f5381bc72255e89e77 100644 --- a/daemon/test/numbercleanertest.h +++ b/daemon/test/numbercleanertest.h @@ -45,6 +45,8 @@ #ifndef _NUMBERCLEANER_TEST_ #define _NUMBERCLEANER_TEST_ +namespace ring { namespace test { + class NumberCleanerTest : public CppUnit::TestCase { /** @@ -83,4 +85,6 @@ class NumberCleanerTest : public CppUnit::TestCase { CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(NumberCleanerTest, "NumberCleanerTest"); CPPUNIT_TEST_SUITE_REGISTRATION(NumberCleanerTest); +}} // namespace ring::test + #endif diff --git a/daemon/test/resamplertest.cpp b/daemon/test/resamplertest.cpp index 41410f8ea553aea7f0b7655db3bf4d86279705af..b0a1c5f88a726271a1ace17bdd4cad5721b182f9 100644 --- a/daemon/test/resamplertest.cpp +++ b/daemon/test/resamplertest.cpp @@ -35,7 +35,7 @@ #include "resamplertest.h" -using namespace ring; +namespace ring { namespace test { ResamplerTest::ResamplerTest() : CppUnit::TestCase("Resampler module test"), inputBuffer(MAX_BUFFER_LENGTH, AudioFormat::MONO()), outputBuffer(MAX_BUFFER_LENGTH, AudioFormat::MONO()) @@ -235,3 +235,5 @@ void ResamplerTest::performDownsampling(Resampler &resampler) outputBuffer.copy(tmpOutputBuffer, -1, 0, j); } } + +}} // namespace ring::test diff --git a/daemon/test/resamplertest.h b/daemon/test/resamplertest.h index fbb5272c5d0172297765e0c8e01fc47770d072c9..1c6f1279059aa8ef1e41e5fa6dbe82be0d1dce33 100644 --- a/daemon/test/resamplertest.h +++ b/daemon/test/resamplertest.h @@ -43,6 +43,8 @@ #define TMP_LOWSMPLR_BUFFER_LENGTH 160 #define TMP_HIGHSMPLR_BUFFER_LENGTH 320 +namespace ring { namespace test { + class ResamplerTest : public CppUnit::TestCase { /** @@ -145,4 +147,6 @@ private: CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ResamplerTest, "ResamplerTest"); CPPUNIT_TEST_SUITE_REGISTRATION(ResamplerTest); +}} // namespace ring::test + #endif // _RESAMPLER_TEST_ diff --git a/daemon/test/ringbufferpooltest.cpp b/daemon/test/ringbufferpooltest.cpp index f50ced92db797f6f90369261b18922a02046b3cc..ba76e7742c90407d47edeb6dfc0c8adc964952b2 100644 --- a/daemon/test/ringbufferpooltest.cpp +++ b/daemon/test/ringbufferpooltest.cpp @@ -37,7 +37,7 @@ #include "logger.h" #include "test_utils.h" -using namespace ring; +namespace ring { namespace test { void RingBufferPoolTest::testBindUnbindBuffer() { @@ -219,3 +219,5 @@ void RingBufferPoolTest::testConference() RingBufferPoolTest::RingBufferPoolTest() : CppUnit::TestCase("Audio Layer Tests") , rbPool_(new RingBufferPool) {} + +}} // namespace ring::test diff --git a/daemon/test/ringbufferpooltest.h b/daemon/test/ringbufferpooltest.h index 350d9b1298ebfd5bd616189e6fb9d0dcfff52d5b..ae48bb8e85b35cc67bbdb4ff205f0d67f379bfba 100644 --- a/daemon/test/ringbufferpooltest.h +++ b/daemon/test/ringbufferpooltest.h @@ -39,15 +39,17 @@ #include <memory> -namespace ring { - class RingBufferPool; -} - /* * @file audiorecorderTest.cpp * @brief Regroups unit tests related to the main buffer. */ +namespace ring { +class RingBufferPool; +} // namespace ring + +namespace ring { namespace test { + class RingBufferPoolTest : public CppUnit::TestCase { /* @@ -83,4 +85,6 @@ class RingBufferPoolTest : public CppUnit::TestCase { CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(RingBufferPoolTest, "RingBufferPoolTest"); CPPUNIT_TEST_SUITE_REGISTRATION(RingBufferPoolTest); +}} // namespace ring::test + #endif // RINGBUFFERPOOL_TEST_ diff --git a/daemon/test/sdesnegotiatortest.cpp b/daemon/test/sdesnegotiatortest.cpp index ef2180318bab9a68cf88455e1324c8b30d7184b5..77bcd41f6ac367f1da92b6466da6f1ccd1c0a99b 100644 --- a/daemon/test/sdesnegotiatortest.cpp +++ b/daemon/test/sdesnegotiatortest.cpp @@ -47,6 +47,8 @@ #include "test_utils.h" #include "logger.h" +namespace ring { namespace test { + using std::cout; using std::endl; @@ -231,3 +233,4 @@ void SdesNegotiatorTest::test32ByteKeyLength() CPPUNIT_ASSERT(negotiator.getAuthTagLength() == "32"); } +}} // namespace ring::test diff --git a/daemon/test/sdesnegotiatortest.h b/daemon/test/sdesnegotiatortest.h index 9e4548e028405dfac34f824f01a408265f521fdd..168d65ca71d40732be0a92d6d894718d42ad6609 100644 --- a/daemon/test/sdesnegotiatortest.h +++ b/daemon/test/sdesnegotiatortest.h @@ -59,9 +59,9 @@ #include "sip/sdes_negotiator.h" // for CryptoSuiteDefinition -namespace ring { - class Pattern; -} +namespace ring { namespace test { + +class Pattern; class SdesNegotiatorTest : public CppUnit::TestCase { @@ -106,4 +106,6 @@ class SdesNegotiatorTest : public CppUnit::TestCase { CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(SdesNegotiatorTest, "SdesNegotiatorTest"); CPPUNIT_TEST_SUITE_REGISTRATION(SdesNegotiatorTest); +}} // namespace ring::test + #endif // __SDESNEGOTIATOR_TEST_H__ diff --git a/daemon/test/sdptest.cpp b/daemon/test/sdptest.cpp index 245645daecd48d4325b29b34f6b493c7eae60fda..52ab131b89150b79e3d7e3815e665e26ba36b919 100644 --- a/daemon/test/sdptest.cpp +++ b/daemon/test/sdptest.cpp @@ -37,6 +37,7 @@ #include "audio/codecs/audiocodec.h" +namespace ring { namespace test { enum session_type { REMOTE_OFFER, @@ -295,3 +296,5 @@ void SDPTest::testReinvite() CPPUNIT_ASSERT(session_->getRemoteIP() == "host.exampleReinvite.com"); } + +}} // namespace ring::test diff --git a/daemon/test/sdptest.h b/daemon/test/sdptest.h index 0aae52696c6da53abe3eb53e0e5d2147c88141c5..b0c69d07ef2fa9611ec21ebce395c73fa931262e 100644 --- a/daemon/test/sdptest.h +++ b/daemon/test/sdptest.h @@ -59,6 +59,8 @@ #include "sip/sdp.h" #include "noncopyable.h" +namespace ring { namespace test { + class SdpSessionException : public std::exception { public: SdpSessionException(const std::string& str="") throw() : errstr(str) {} @@ -124,4 +126,6 @@ class SDPTest : public CppUnit::TestCase { CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(SDPTest, "SDPTest"); CPPUNIT_TEST_SUITE_REGISTRATION(SDPTest); +}} // namespace ring::test + #endif diff --git a/daemon/test/siptest.cpp b/daemon/test/siptest.cpp index cb4db0ce3ebb9cb32f4de3a21b1492ca55ae947c..8b113394d6c1504643c904364cf14660cbd438dd 100644 --- a/daemon/test/siptest.cpp +++ b/daemon/test/siptest.cpp @@ -50,6 +50,8 @@ pthread_cond_t count_nb_thread; int counter = 0; } +namespace ring { namespace test { + void *sippThreadWithCount(void *str) { pthread_mutex_lock(&count_mutex); @@ -427,3 +429,5 @@ void SIPTest::testIncomingIpCallSdp() else std::cout << "SIPTest: completed join with thread" << std::endl; } + +}} // namespace ring::test diff --git a/daemon/test/siptest.h b/daemon/test/siptest.h index a2218832dda8fb55f3e5665f1eeb7a95bc517224..82ccef51b83def9c77d6af74fc3ed5c810903b03 100644 --- a/daemon/test/siptest.h +++ b/daemon/test/siptest.h @@ -45,6 +45,8 @@ #ifndef _SIP_TEST_ #define _SIP_TEST_ +namespace ring { namespace test { + class SIPTest : public CppUnit::TestCase { /** @@ -97,4 +99,6 @@ class SIPTest : public CppUnit::TestCase { CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(SIPTest, "SIPTest"); CPPUNIT_TEST_SUITE_REGISTRATION(SIPTest); +}} // namespace ring::test + #endif diff --git a/daemon/test/tlstest.cpp b/daemon/test/tlstest.cpp index da62051be0b0e45c92fd03b4340cd25adef79b20..555d2a79568c78dd12ddcac8bc6858054bcc94f5 100644 --- a/daemon/test/tlstest.cpp +++ b/daemon/test/tlstest.cpp @@ -38,6 +38,8 @@ #include "sip/tlsvalidation.h" +namespace ring { namespace test { + void TlsTest::testKey() { TITLE(); @@ -93,3 +95,5 @@ void TlsTest::testHostname() CPPUNIT_ASSERT(verifyHostnameCertificate(wrongUrl, 443) != 0); CPPUNIT_ASSERT(verifyHostnameCertificate(NULL, 443) != 0); } + +}} // namespace ring::test diff --git a/daemon/test/tlstest.h b/daemon/test/tlstest.h index eea78b28bad6d26e02bedd6097507e008c5c1f17..eb5c5e3082b0737cf87aca1bd567b926a7296aec 100644 --- a/daemon/test/tlstest.h +++ b/daemon/test/tlstest.h @@ -43,6 +43,8 @@ #include <cppunit/TestCase.h> #include <cppunit/TestSuite.h> +namespace ring { namespace test { + class TlsTest: public CppUnit::TestFixture { /* @@ -63,4 +65,6 @@ class TlsTest: public CppUnit::TestFixture { CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TlsTest, "TlsTest"); CPPUNIT_TEST_SUITE_REGISTRATION(TlsTest); +}} // namespace ring::test + #endif // TLS_TEST_