【问题标题】:Can't reuse PeerConnectionClient after activity recreated重新创建活动后无法重用 PeerConnectionClient
【发布时间】:2018-09-18 14:49:10
【问题描述】:

我正在尝试在 Android 上的 WebRTC 调用期间正确处理屏幕旋转。 但在第一次旋转后,本地视频翻译停止。 创建(或重新创建)活动后,我正在为本地和远程视图创建 SurfaceViewRenderers:

ourView.init(eglBase.eglBaseContext, null)
ourView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT)
ourView.setZOrderMediaOverlay(true)
ourView.setEnableHardwareScaler(true)
ourView.setMirror(true)


theirView.init(eglBase.eglBaseContext, null)
theirView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT)
theirView.setEnableHardwareScaler(false)
theirView.setMirror(true) 

localVideoSyncer.setTarget(ourView)
remoteVideoSyncer.setTarget(theirView)

之后,如果这是第一次必须创建连接,我正在初始化对等连接:

iceConnected = false
 val dataChannelParameters = CallUtils.createChannelParameters()
 peerConnectionParameters = CallUtils.createConnectionParameters(videoWidth, videoHeight, dataChannelParameters)
 if(appRTCClient == null) {
 appRTCClient = CallUtils.createAppRTCClient(roomId, this, info?.ice ?: emptyList())
 }
 roomConnectionParameters = CallUtils.createRoomConnectionParameters(info?.address, roomId)
 if(peerConnectionClient == null) {
 peerConnectionClient = PeerConnectionClient(
 applicationContext, eglBase, peerConnectionParameters, this)
 }
 val options = PeerConnectionFactory.Options()
 peerConnectionClient!!.createPeerConnectionFactory(options)
 if (appRTCClient == null) {
 NetworkLogger.log(TAG,"AppRTC client is not allocated for a call.")
 return
 }
 if(callStartedTimeMs == 0L)
 callStartedTimeMs = System.currentTimeMillis()

 appRTCClient!!.connectToRoom(roomConnectionParameters!!)

 if(audioManager == null)
 audioManager = AppRTCAudioManager(applicationContext)

如果重新创建活动,PeerConnectionClient 将不再可以将视频发送到远程目标。我试图重新分配 localRender & videoCapturer,但这没有效果。重新创建活动后是否可以重用现有连接?

【问题讨论】:

    标签: android webrtc apprtc


    【解决方案1】:

    我认为这里最好的解决方案是将 appRTCClient 和相关对象放在活动之外,并使它们独立于活动的生命周期。您使用 applicationContext 这就是为什么您可以将它存储在一些依赖于应用程序生命周期的单调中。另一种方法是在您的活动中使用片段来显示聊天窗口并在 onConfigurationChanged 方法中手动处理旋转,因此您必须将纵向片段替换为横向片段。

    【讨论】:

    • 我已经使用 Moxy 库来保存所有这些对象。但是如何在没有活动重新创建的情况下重新创建和旋转片段?此外,如果在通话期间活动轮换,在通话结束后几秒钟后,SIGSEGV 接收:A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 30674
    • 可能是重复的 EGL 上下文导致了这种情况。但是在活动停止时明确释放它并没有解决这个问题
    猜你喜欢
    • 2022-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-21
    • 2019-07-26
    • 2015-08-17
    • 2015-11-25
    • 1970-01-01
    相关资源
    最近更新 更多