diff --git a/examples/messaging_recvonly_sample/src/messaging_recvonly_sample.cpp b/examples/messaging_recvonly_sample/src/messaging_recvonly_sample.cpp index e6d88f4c..b5d85512 100644 --- a/examples/messaging_recvonly_sample/src/messaging_recvonly_sample.cpp +++ b/examples/messaging_recvonly_sample/src/messaging_recvonly_sample.cpp @@ -1,6 +1,3 @@ -// WebRTC -#include - // Sora #include @@ -197,8 +194,7 @@ int main(int argc, char* argv[]) { sora::SoraClientContextConfig context_config; context_config.use_audio_device = false; context_config.use_hardware_encoder = false; - auto env = webrtc::CreateEnvironment(); - auto context = sora::SoraClientContext::Create(context_config, env); + auto context = sora::SoraClientContext::Create(context_config); auto messaging_recvonly_sample = std::make_shared(context, config); diff --git a/examples/sdl_sample/src/sdl_sample.cpp b/examples/sdl_sample/src/sdl_sample.cpp index e7875a7b..20a404c9 100644 --- a/examples/sdl_sample/src/sdl_sample.cpp +++ b/examples/sdl_sample/src/sdl_sample.cpp @@ -1,6 +1,3 @@ -// WebRTC -#include - // Sora #include #include @@ -251,9 +248,8 @@ int main(int argc, char* argv[]) { rtc::LogMessage::LogThreads(); } - auto env = webrtc::CreateEnvironment(); auto context = - sora::SoraClientContext::Create(sora::SoraClientContextConfig(), env); + sora::SoraClientContext::Create(sora::SoraClientContextConfig()); auto sdlsample = std::make_shared(context, config); sdlsample->Run(); diff --git a/examples/sumomo/src/sumomo.cpp b/examples/sumomo/src/sumomo.cpp index 516d055e..702dbacc 100644 --- a/examples/sumomo/src/sumomo.cpp +++ b/examples/sumomo/src/sumomo.cpp @@ -1,6 +1,3 @@ -// WebRTC -#include - // Sora #include #include @@ -450,8 +447,7 @@ int main(int argc, char* argv[]) { context_config.use_hardware_encoder = *use_hardware_encoder; } context_config.openh264 = openh264; - auto env = webrtc::CreateEnvironment(); - auto context = sora::SoraClientContext::Create(context_config, env); + auto context = sora::SoraClientContext::Create(context_config); auto sumomo = std::make_shared(context, config); sumomo->Run(); diff --git a/include/sora/sora_client_context.h b/include/sora/sora_client_context.h index 44efad2a..051855e0 100644 --- a/include/sora/sora_client_context.h +++ b/include/sora/sora_client_context.h @@ -60,6 +60,9 @@ class SoraClientContext { const SoraClientContextConfig& config, webrtc::Environment& env); + static std::shared_ptr Create( + const SoraClientContextConfig& config); + ~SoraClientContext(); rtc::Thread* network_thread() const { return network_thread_.get(); } @@ -78,6 +81,7 @@ class SoraClientContext { ? config_.get_android_application_context(env) : nullptr; } + std::shared_ptr env; private: SoraClientContextConfig config_; diff --git a/src/sora_client_context.cpp b/src/sora_client_context.cpp index 446b8134..ab8e62fa 100644 --- a/src/sora_client_context.cpp +++ b/src/sora_client_context.cpp @@ -53,6 +53,7 @@ std::shared_ptr SoraClientContext::Create( c->worker_thread_->Start(); c->signaling_thread_ = rtc::Thread::Create(); c->signaling_thread_->Start(); + c->env = std::make_shared(env); webrtc::PeerConnectionFactoryDependencies dependencies; dependencies.network_thread = c->network_thread_.get(); @@ -137,4 +138,10 @@ std::shared_ptr SoraClientContext::Create( return c; } +std::shared_ptr SoraClientContext::Create( + const SoraClientContextConfig& config) { + auto env = webrtc::CreateEnvironment(); + return Create(config, env); +} + } // namespace sora \ No newline at end of file diff --git a/test/connect_disconnect.cpp b/test/connect_disconnect.cpp index aa21bfad..3f1d4d64 100644 --- a/test/connect_disconnect.cpp +++ b/test/connect_disconnect.cpp @@ -3,7 +3,6 @@ #include // WebRTC -#include #include #ifdef _WIN32 @@ -146,9 +145,8 @@ int main(int argc, char* argv[]) { //rtc::LogMessage::LogTimestamps(); //rtc::LogMessage::LogThreads(); - auto env = webrtc::CreateEnvironment(); auto context = - sora::SoraClientContext::Create(sora::SoraClientContextConfig(), env); + sora::SoraClientContext::Create(sora::SoraClientContextConfig()); boost::json::value v; { diff --git a/test/datachannel.cpp b/test/datachannel.cpp index ccf0a3c1..ec6cbbec 100644 --- a/test/datachannel.cpp +++ b/test/datachannel.cpp @@ -3,7 +3,6 @@ #include // WebRTC -#include #include #ifdef _WIN32 @@ -161,8 +160,7 @@ int main(int argc, char* argv[]) { sora::SoraClientContextConfig context_config; context_config.use_audio_device = false; context_config.use_hardware_encoder = false; - auto env = webrtc::CreateEnvironment(); - auto context = sora::SoraClientContext::Create(context_config, env); + auto context = sora::SoraClientContext::Create(context_config); boost::json::value v; { diff --git a/test/e2e.cpp b/test/e2e.cpp index 2902727d..3d6316ac 100644 --- a/test/e2e.cpp +++ b/test/e2e.cpp @@ -4,7 +4,6 @@ #include // WebRTC -#include #include #ifdef _WIN32 @@ -45,8 +44,7 @@ class SoraClient : public std::enable_shared_from_this, sora::SoraClientContextConfig context_config; context_config.use_audio_device = false; context_config.use_hardware_encoder = false; - auto env = webrtc::CreateEnvironment(); - auto context = sora::SoraClientContext::Create(context_config, env); + auto context = sora::SoraClientContext::Create(context_config); auto pc_factory = context->peer_connection_factory(); context_ = context; diff --git a/test/hello.cpp b/test/hello.cpp index 8a13e3e8..1e5ebf4e 100644 --- a/test/hello.cpp +++ b/test/hello.cpp @@ -4,7 +4,6 @@ #include // WebRTC -#include #include #ifdef _WIN32 @@ -180,8 +179,7 @@ int main(int argc, char* argv[]) { if (auto it = v.as_object().find("openh264"); it != v.as_object().end()) { context_config.openh264 = it->value().as_string(); } - auto env = webrtc::CreateEnvironment(); - auto context = sora::SoraClientContext::Create(context_config, env); + auto context = sora::SoraClientContext::Create(context_config); auto hello = std::make_shared(context, config); hello->Run();