ice/turn transport: make sure PJSIP is initialized before it's used
Using PJSIP functions without calling pj_init first can lead to subtle
non-deterministic bugs.
GitLab: #18
Change-Id: I9364fd247165c0ce19a8d0d42575fb66651b54a3
diff --git a/include/ice_transport_factory.h b/include/ice_transport_factory.h
index df3367c..3e4c931 100644
--- a/include/ice_transport_factory.h
+++ b/include/ice_transport_factory.h
@@ -19,6 +19,7 @@
#include "ice_options.h"
#include "ice_transport.h"
#include "ip_utils.h"
+#include "pj_init_lock.h"
#include <functional>
#include <memory>
@@ -50,6 +51,9 @@
std::shared_ptr<pj_caching_pool> getPoolCaching() { return cp_; }
private:
+ // Declaring pjInitLock_ before cp_ because its constructor needs to be called
+ // first (see constructor implementation for a comment with more information).
+ PjInitLock pjInitLock_;
std::shared_ptr<pj_caching_pool> cp_;
pj_ice_strans_cfg ice_cfg_;
std::shared_ptr<Logger> logger_ {};