--
---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrtc+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/de59cc8f-1804-42fe-a990-5a7abff1bca3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
// Make sure the AudioDeviceModule is deleted on the same thread as it was created on
// (i.e. the workerThread) to avoid errors on shutdown.
workerThread->Invoke<void>(
RTC_FROM_HERE,
[this]()
{
LOG_DEBUG << "Removing audioDeviceModule";
this->audioDeviceModule.release();
this->audioDeviceModule = nullptr;
}
);
networkManager.reset();
socketFactory.reset();
peerConnectionFactory = nullptr; // Forces release of the factory
rtc::CleanupSSL();
// Post quit messages
signalThread->Quit();
signalThread.reset();
workerThread->Quit();
workerThread.reset();
networkThread->Quit();
networkThread.reset();void Init(std::string audio_card) {
RTC_CHECK(rtc::InitializeSSL()) << "Failed to initialize ssl";
audio_card_id = std::move(audio_card);
worker_thread = rtc::Thread::Create();
worker_thread->SetName("worker_thread", nullptr);
RTC_CHECK(worker_thread->Start()) << "Failed to start thread";
signaling_thread = rtc::Thread::Create();
signaling_thread->SetName("signaling_thread", nullptr);
RTC_CHECK(signaling_thread->Start()) << "Failed to start thread";
network_thread = rtc::Thread::CreateWithSocketServer();
network_thread->SetName("network_thread", nullptr);
RTC_CHECK(network_thread->Start()) << "Failed to start thread";
audio_device_module = worker_thread->Invoke<rtc::scoped_refptr<webrtc::AudioDeviceModule>>(
RTC_FROM_HERE,
[=]() {
auto audio_device =
new AudioDeviceModuleWrapper(webrtc::AudioDeviceModule::AudioLayer::kPlatformDefaultAudio);
audio_device->Init();
int16_t num = audio_device->RecordingDevices();
for (int16_t i = 0; i < num; i++) {
char name[webrtc::kAdmMaxDeviceNameSize];
char guid[webrtc::kAdmMaxGuidSize];
int ret = audio_device->RecordingDeviceName(static_cast<uint16_t>(i), name, guid);
std::string name_str(name);
if (!audio_card_id.empty() && name_str.find(audio_card_id) == 0) {
is_connect_to_audio_card = true;
audio_device->SetDeviceId(static_cast<uint16_t>(i));
}
}
return audio_device;
});
peer_connection_factory = webrtc::CreatePeerConnectionFactory(network_thread.get(), worker_thread.get(),
signaling_thread.get(),
audio_device_module, nullptr, nullptr);
is_init_finished = true;
}
~RTC() {
worker_thread->Invoke<void>(
RTC_FROM_HERE,
[this]()
{
this->audio_device_module.release();
this->audio_device_module = nullptr;
}
);
peer_connection_factory = nullptr;
RTC_CHECK(rtc::CleanupSSL()) << "Failed to clean up ssl";
signaling_thread->Quit();
signaling_thread.reset();
worker_thread->Quit();
worker_thread.reset();
network_thread->Quit();
network_thread.reset();
}
socket_factory.reset(new rtc::BasicPacketSocketFactory(network_thread.get()));
network_manager.reset(new rtc::BasicNetworkManager());
std::unique_ptr<cricket::PortAllocator> port_allocator(
new cricket::BasicPortAllocator(network_manager.get(), socket_factory.get()));
port_allocator->SetPortRange(min_port, max_port);
pure_peer_connection = peer_connection_factory->CreatePeerConnection(
configuration, std::move(port_allocator), nullptr, peerConnectionObserver);
Our cleanup code currently looks like this: