camera-samples
camera-samples copied to clipboard
OrientationLiveData is incorrect when camera sensor orientation is 0 degrees
https://github.com/android/camera-samples/blob/main/Camera2Video/utils/src/main/java/com/example/android/camera/utils/OrientationLiveData.kt
This method returns 270 when device is on landscape orientation (Surface.ROTATION_90) and camera orientation degrees is 0
computeRelativeRotation(Surface.ROTATION_90) returns 90 for 0 camera sensor degrees but should return 0
private fun computeRelativeRotation(
surfaceRotation: Int
): Int {
val sensorOrientationDegrees = 0 // hardcoded just for test camera with such orientation deegres
val deviceOrientationDegrees = when (surfaceRotation) {
Surface.ROTATION_0 -> 0
Surface.ROTATION_90 -> 90
Surface.ROTATION_180 -> 180
Surface.ROTATION_270 -> 270
else -> 0
}
// Reverse device orientation for front-facing cameras
val sign = -1
// Calculate desired JPEG orientation relative to camera orientation to make
// the image upright relative to the device orientation
return (sensorOrientationDegrees - (deviceOrientationDegrees * sign) + 360) % 360
}
Some devices for auto (vehicles) like alps YT9213AJ support external usb camera and it returns 0 camera sensor orientation
So this would rotate a recording video by 90 when playing i, will be setOrientationHint(90)
https://github.com/android/camera-samples/blob/main/Camera2Video/app/src/main/java/com/example/android/camera2/video/fragments/CameraFragment.kt#L273