我正在尝试在 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,但这没有效果。重新创建活动后是否可以重用现有连接?