如何正确关闭对等连接

时间:2014-10-14 07:04:11

标签: ios webrtc

我有一个使用webrtc的voip应用程序。我最近重新设计了许多代码,使信令更加一致。我现在唯一的大问题是,当我关闭对等连接时,应用程序崩溃了一些内部opengl代码。我使用此代码关闭连接:

[peerConnection removeStream:lms];
[peerConnection close];
peerConnection = nil;

我之前使用的代码几乎删除了与webrtc相关的任何内容,但我发现很多对象都可以重用,只需要在应用程序开始时进行。我该怎么做才能确保应用程序不会让我结束通话的所有内容崩溃?

  • 我使用的是修订版6825
  • 我正在使用xcode 5.1.1
  • 在运行iOS7的第4代iPad上进行测试

编辑:
我将上面的代码移动到后台线程,它不再崩溃。但是现在,经过几次通话后,我的日志会被以下行发送垃圾邮件(大约每秒3到4次):

Failed to make complete framebuffer object 8cdd

这是发生这种情况时日志历史记录的最后一部分:

2014-10-14 11:53:45.045 BeeldZorgApp[4912:3903] peerConnection iceConnectionChanged:(RTCICEConnectionState)2
2014-10-14 11:53:45.046 BeeldZorgApp[4912:3903] peerConnection iceConnectionChanged:(RTCICEConnectionState)3
2014-10-14 11:53:50.732 BeeldZorgApp[4912:3903] peerConnectionOnRenegotiationNeeded:(RTCPeerConnection *)<RTCPeerConnection: 0x157c9640>
2014-10-14 11:53:50.742 BeeldZorgApp[4912:3903] peerConnection iceConnectionChanged:(RTCICEConnectionState)6
2014-10-14 11:53:50.743 BeeldZorgApp[4912:3903] peerConnection signalingStateChanged:(RTCSignalingState)5
2014-10-14 11:53:59.955 BeeldZorgApp[4912:3903] peerConnectionOnRenegotiationNeeded:(RTCPeerConnection *)<RTCPeerConnection: 0x19a62e30>
2014-10-14 11:53:59.980 BeeldZorgApp[4912:60b] Failed to make complete framebuffer object 8cdd
2014-10-14 11:54:00.028 BeeldZorgApp[4912:60b] Failed to make complete framebuffer object 8cdd
2014-10-14 11:54:00.091 BeeldZorgApp[4912:60b] Failed to make complete framebuffer object 8cdd
2014-10-14 11:54:00.119 BeeldZorgApp[4912:60b] Failed to make complete framebuffer object 8cdd
2014-10-14 11:54:00.152 BeeldZorgApp[4912:60b] Failed to make complete framebuffer object 8cdd
2014-10-14 11:54:00.185 BeeldZorgApp[4912:60b] Failed to make complete framebuffer object 8cdd
2014-10-14 11:54:00.218 BeeldZorgApp[4912:60b] Failed to make complete framebuffer object 8cdd
2014-10-14 11:54:00.252 BeeldZorgApp[4912:60b] Failed to make complete framebuffer object 8cdd
2014-10-14 11:54:00.284 BeeldZorgApp[4912:60b] Failed to make complete framebuffer object 8cdd
2014-10-14 11:54:00.319 BeeldZorgApp[4912:60b] Failed to make complete framebuffer object 8cdd
2014-10-14 11:54:00.352 BeeldZorgApp[4912:60b] Failed to make complete framebuffer object 8cdd
2014-10-14 11:54:00.384 BeeldZorgApp[4912:60b] Failed to make complete framebuffer object 8cdd
2014-10-14 11:54:00.417 BeeldZorgApp[4912:60b] Failed to make complete framebuffer object 8cdd
2014-10-14 11:54:00.451 BeeldZorgApp[4912:60b] Failed to make complete framebuffer object 8cdd
2014-10-14 11:54:00.486 BeeldZorgApp[4912:60b] Failed to make complete framebuffer object 8cdd
2014-10-14 11:54:00.518 BeeldZorgApp[4912:60b] Failed to make complete framebuffer object 8cdd
2014-10-14 11:54:00.552 BeeldZorgApp[4912:60b] Failed to make complete framebuffer object 8cdd

2 个答案:

答案 0 :(得分:7)

事实证明,在远离视图控制器之前,需要从超级视图中删除RTCEAGLVideoViews。我现在使用以下代码进行清理:

//these are both RTCEAGLVideoViews
[remoteVideoView removeFromSuperview];
[localVideoView removeFromSuperview];
[peerConnection removeStream:lms];
[peerConnection close];
peerConnection = nil;

答案 1 :(得分:1)

如果您将peerConnection设置为nil,当您尝试再次呼叫某人时(第二次),您将在视图控制器中收到有关此内容的错误消息。 我认为它设置为 PeerConnectionFactory 静态类的peerConnection值的零。因此,当您调用工厂的 peerConnectionWithConfiguration 方法时,您将获得nil值。 我的建议是close()方法就足够了(快速):

self.remoteVideoView.removeFromSuperview()
self.localVideoView.removeFromSuperview()
self.peerConnection.removeStream(self.mediaStream)
self.peerConnection.close()

PS:我正在使用最新版本的webrtc库