我正在使用C实现WebRTC Peer to Peer连接以进行音频呼叫.
我有两个线程_worker_thread和_signaling_thread.现在,当我尝试通过调用webrtc :: CreatePeerConnectionFactory()方法创建_peerConnectionFactory时,我的应用程序崩溃了.我怎样才能使它工作?
_signaling_thread.reset(new rtc::Thread());
if(!_signaling_thread->Start())
{
printf("_signaling_thread is Failed");
return;
}
_worker_thread.reset(new rtc::Thread());
if (!_worker_thread->Start()) {
printf( "_worker_thread is Failed");
return;
}
_peerConnectionFactory = webrtc::CreatePeerConnectionFactory(_worker_thread.get(),_signaling_thread.get(),NULL,NULL,NULL);
这是我得到的回溯
* thread #15: tid = 0x17e516, 0x00000001008d5674 MyAPP`rtc::MessageQueue::Get(rtc::Message*, int, bool) + 816, stop reason = EXC_BAD_ACCESS (code=1, address=0x100000038)
* frame #0: 0x00000001008d5674 MyAPP`rtc::MessageQueue::Get(rtc::Message*, int, bool) + 816
frame #1: 0x00000001008e5fb0 MyAPP`rtc::Thread::ProcessMessages(int) + 100
frame #2: 0x00000001008e5e44 MyAPP`rtc::Thread::PreRun(void*) + 88
frame #3: 0x0000000199337b3c libsystem_pthread.dylib`_pthread_body + 156
frame #4: 0x0000000199337aa0 libsystem_pthread.dylib`_pthread_start + 1
最佳答案 在查看WebRTC源代码中的PeerConnection示例之后,我总是在创建这样的线程之前初始化SSL模块:
bool Core::Init() {
rtc::InitializeSSL();
rtc::InitRandom(rtc::Time());
rtc::ThreadManager::Instance()->WrapCurrentThread();
_signalingThread = new rtc::Thread();
_workerThread = new rtc::Thread();
_signalingThread->SetName("signaling_thread", NULL);
_workerThread->SetName("worker_thread", NULL);
if (!_signalingThread->Start() || !_workerThread->Start()) {
return false;
}
_peerConnectionFactory =
webrtc::CreatePeerConnectionFactory(_signalingThread,
_workerThread,
NULL, NULL, NULL).release();
return true;
}