Commit 158da98b authored by Guillaume Roguez's avatar Guillaume Roguez

sip: move remaining PJSIP init at managerimpl level

Note that iax has been modified also to remove a duplicate code
at application wide.

Refs #64903

Change-Id: Ie0739fa6b4cc66b4042837c920442e16fd50043f
parent 53746f62
......@@ -53,9 +53,7 @@ namespace ring {
std::mutex IAXVoIPLink::mutexIAX = {};
IAXVoIPLink::IAXVoIPLink(IAXAccount& account) : account_(account), resampler_(new Resampler{44100})
{
srand(time(NULL)); // to get random number for RANDOM_PORT
}
{}
IAXVoIPLink::~IAXVoIPLink()
{
......
......@@ -124,6 +124,32 @@ restore_backup(const std::string &path)
copy_over(backup_path, path);
}
/**
* Set pjsip's log level based on the SIPLOGLEVEL environment variable.
* SIPLOGLEVEL = 0 minimum logging
* SIPLOGLEVEL = 6 maximum logging
*/
/** Environment variable used to set pjsip's logging level */
static constexpr const char* SIPLOGLEVEL = "SIPLOGLEVEL";
static void
setSipLogLevel()
{
char* envvar = getenv(SIPLOGLEVEL);
int level = 0;
if (envvar != nullptr) {
if (not (std::istringstream(envvar) >> level))
level = 0;
// From 0 (min) to 6 (max)
level = std::max(0, std::min(level, 6));
}
pj_log_set_level(level);
}
void
ManagerImpl::loadDefaultAccountMap()
{
......@@ -184,13 +210,18 @@ ManagerImpl::init(const std::string &config_file)
throw std::runtime_error(#ret " failed"); \
} while (0)
// Our PJSIP dependency (SIP and ICE)
srand(time(NULL)); // to get random number for RANDOM_PORT
// Initialize PJSIP (SIP and ICE implementation)
TRY(pj_init());
setSipLogLevel();
TRY(pjlib_util_init());
TRY(pjnath_init());
#undef TRY
RING_DBG("pjsip version %s for %s initialized",
pj_get_version(), PJ_OS_NAME);
ice_tf_.reset(new IceTransportFactory());
path_ = config_file.empty() ? retrieveConfigPath() : config_file;
......
......@@ -85,9 +85,6 @@
namespace ring {
/** Environment variable used to set pjsip's logging level */
#define SIPLOGLEVEL "SIPLOGLEVEL"
/**************** EXTERN VARIABLES AND FUNCTIONS (callbacks) **************************/
/**
......@@ -488,18 +485,8 @@ SIPVoIPLink::SIPVoIPLink()
throw VoipLinkException(#ret " failed"); \
} while (0)
srand(time(NULL)); // to get random number for RANDOM_PORT
TRY(pj_init());
TRY(pjlib_util_init());
setSipLogLevel();
TRY(pjnath_init());
pj_caching_pool_init(cp_, &pj_pool_factory_default_policy, 0);
pool_ = pj_pool_create(&cp_->factory, PACKAGE, 4096, 4096, nullptr);
if (!pool_)
throw VoipLinkException("UserAgent: Could not initialize memory pool");
......@@ -575,8 +562,6 @@ SIPVoIPLink::SIPVoIPLink()
static const pj_str_t accepted = CONST_PJ_STR("application/sdp");
pjsip_endpt_add_capability(endpt_, &mod_ua_, PJSIP_H_ACCEPT, nullptr, 1, &accepted);
RING_DBG("pjsip version %s for %s initialized", pj_get_version(), PJ_OS_NAME);
TRY(pjsip_replaces_init_module(endpt_));
#undef TRY
......@@ -612,8 +597,6 @@ SIPVoIPLink::~SIPVoIPLink()
pjsip_endpt_destroy(endpt_);
pj_pool_release(pool_);
pj_caching_pool_destroy(cp_);
pj_shutdown();
}
std::shared_ptr<SIPAccountBase>
......@@ -662,24 +645,6 @@ SIPVoIPLink::guessAccount(const std::string& userName,
return result;
}
void SIPVoIPLink::setSipLogLevel()
{
char *envvar = getenv(SIPLOGLEVEL);
int level = 0;
if (envvar != NULL) {
std::string loglevel = envvar;
if (!(std::istringstream(loglevel) >> level)) level = 0;
level = level > 6 ? 6 : level;
level = level < 0 ? 0 : level;
}
// From 0 (min) to 6 (max)
pj_log_set_level(level);
}
// Called from EventThread::run (not main thread)
void
SIPVoIPLink::handleEvents()
......
......@@ -79,13 +79,6 @@ extern decltype(getGlobalInstance<SIPVoIPLink>)& getSIPVoIPLink;
class SIPVoIPLink {
public:
/**
* Set pjsip's log level based on the SIPLOGLEVEL environment variable.
* SIPLOGLEVEL = 0 minimum logging
* SIPLOGLEVEL = 6 maximum logging
*/
static void setSipLogLevel();
#ifdef __ANDROID__
static void setSipLogger();
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment