How to release peerConnection correctly and free port in using WebRTC c++ api

211 views
Skip to first unread message

Chen Yang

unread,
Jul 30, 2018, 5:05:35 AM7/30/18
to discuss-webrtc

I am working on wrapping WebRTC's c++ lib by jni, and use it in java server. My working repository is https://github.com/BeiKeJieDeLiuLangMao/WebRTC, c++ code located in /cpp/src

I create PeerConnection codes as follow:

PeerConnection *CreatePeerConnection(PeerConnectionObserver *peerConnectionObserver) {
    webrtc::PeerConnectionInterface::RTCConfiguration configuration;
    webrtc::PeerConnectionInterface::IceServer ice_server;
    ice_server.uri = "stun:stun.l.google.com:19302";
    configuration.servers.push_back(ice_server);
    std::unique_ptr<cricket::PortAllocator> port_allocator(new cricket::BasicPortAllocator(new rtc::BasicNetworkManager()));
    port_allocator->SetPortRange(60000, 60001);
    return new PeerConnection(peer_connection_factory->
            CreatePeerConnection(configuration, std::move(port_allocator), nullptr, peerConnectionObserver), peerConnectionObserver);
}

I find that udp ports used by peerConnection will not been release after i close peerConnection, And each port could reuse once, after these is no ice candidate. By the way i close peerConnection by

webrtc::PeerConnectionInterface::Close

Reply all
Reply to author
Forward
0 new messages