我正在开发webrtc PeerConnection,我得到UDP socket Creation Failed
下面提到了用于调用CreatePeerConnection方法的代码片段。
我使用了自己的眩晕并转向服务器,并在给定代码中提到了他们的ip和端口,我也尝试过使用google stun服务器地址和端口(stun:stun.l.google.com:19302
),但是遇到了同样的问题
webrtc::PeerConnectionInterface::IceServers ice_servers;
webrtc::PeerConnectionInterface::IceServer ice_server;
webrtc::PeerConnectionInterface::RTCConfiguration config;
ice_server.uri = "stun:address_stun:port_stun";
config.servers.push_back(ice_server);
webrtc::PeerConnectionInterface::IceServer turn_server;
std::string url = "turn:address_turn:port_turn?transport=udp";
turn_server.urls.push_back(url);
turn_server.username = "username";
turn_server.password = "password";
config.servers.push_back(turn_server);
webrtc::FakeConstraints constraints;
constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, "true");
config.candidate_network_policy = webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
config.tcp_candidate_policy = webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled;
constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
webrtc::MediaConstraintsInterface::kValueFalse);
constraints.AddMandatory(webrtc::MediaConstraintsInterface::kOfferToReceiveAudio,
webrtc::MediaConstraintsInterface::kValueTrue);
rtc::ThreadManager::Instance()->WrapCurrentThread();
u_worker_thread = rtc::Thread::Create();
u_worker_thread->SetName("worker_thread", NULL);
RTC_CHECK(u_worker_thread->Start()) << "Failed to start thread";
u_signaling_thread = rtc::Thread::Create();
u_signaling_thread->SetName("signaling_thread", NULL);
RTC_CHECK(u_signaling_thread->Start()) << "Failed to start thread";
m_networkThread = rtc::Thread::Create();
m_networkThread->SetName("networking_thread", NULL);
RTC_CHECK(m_networkThread->Start()) << "Failed to start thread";
cricket::WebRtcVideoEncoderFactory* video_encoder_factory = nullptr;
cricket::WebRtcVideoDecoderFactory* video_decoder_factory = nullptr;
auto audio_encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory();
auto audio_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory();
webrtc::AudioDeviceModule* adm = nullptr;
fake_network_manager_.reset(new rtc::FakeNetworkManager());
static const SocketAddress kDefaultLocalAddress("local_ip", 0);
fake_network_manager_->AddInterface(kDefaultLocalAddress);
std::unique_ptr<cricket::PortAllocator> port_allocator_(new cricket::BasicPortAllocator(fake_network_manager_.get()));
_peerConnectionFactory = webrtc::CreatePeerConnectionFactory(m_networkThread.get(),u_worker_thread.get(),u_signaling_thread.get(),adm,audio_encoder_factory,audio_decoder_factory,video_encoder_factory,video_decoder_factory);
if (!_peerConnectionFactory.get()) {
}
else
{
__android_log_print(ANDROID_LOG_INFO, TAG,"Going to initialise CreatePeerConnection" );
_peerConnection = _peerConnectionFactory->CreatePeerConnection(
config, &constraints, std::move(port_allocator_), NULL, this);
}