1

I'm trying to correctly handle screen rotation during WebRTC call on Android. But after first rotation local video translation stopping. After creating (or recreating) activty I am creating SurfaceViewRenderers for local & remote views:

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)

After that, if this is a first time when connection must be created, I am initializing peer connection:

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)

If activity is recreated, PeerConnectionClient is no longer can send video to remote target. I tried to reassign localRender & videoCapturer, but that has no effect. Is it possible to reuse existing connection after activity recreated?

wingear
  • 819
  • 9
  • 21

1 Answers1

0

I think the best solution here is to place appRTCClient and related objects outside of activity and make them independent from activity's lifecycle. You use applicationContext thats why you can store it in some singletone which relies on application's lifecycle. Another way is to use fragment inside your activity for displaying chat windows and manually handle rotatation inside onConfigurationChanged method, so you will have to replace portrait fragment with landscape one.

Alexey Osminin
  • 190
  • 1
  • 4
  • 14
  • I already use Moxy library to hold all these objects. But how can I recreate & rotate fragment without activity recreation? Also, if activity is rotated during call, few seconds later after call ended, SIGSEGV receiving: A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 30674 – wingear Sep 21 '18 at 12:31
  • Maybe duplicated EGL context causes this. But with explicitly releasing it on activity stop is not solved this sutialion – wingear Sep 21 '18 at 12:40