in amazon-chime-sdk/src/main/java/com/amazonaws/services/chime/sdk/meetings/audiovideo/video/capture/DefaultScreenCaptureSource.kt [263:290]
override fun onVideoFrameReceived(frame: VideoFrame) {
// Check if display rotation has changed; since this is
// not an activity there is otherwise no way to observe this
// besides checking every frame
val display = displayManager.getDisplay(Display.DEFAULT_DISPLAY)
?: throw RuntimeException("No display found.")
val rotation = display.rotation
val isOrientationInPortrait = rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180
if (this.isOrientationInPortrait != isOrientationInPortrait) {
isRestartingForOrientationChange = true
logger.info(TAG, "Orientation changed from ${if (this.isOrientationInPortrait) "portrait" else "landscape"} " +
"to ${if (isOrientationInPortrait) "portrait" else "landscape"}, restarting screen capture to update dimensions")
// Post this task to avoid deadlock with the surface texture source handler
handler.post {
// Double check that start or stop hasn't been called since this was posted
if (isRestartingForOrientationChange) {
stopInternal()
startInternal()
isRestartingForOrientationChange = false
}
}
return
}
// Ignore frames while we are recreating the surface and display
if (isRestartingForOrientationChange) return
sinks.forEach { it.onVideoFrameReceived(frame) }
}