android / android/camera-samples

OrientationLiveData is incorrect when camera sensor orientation is 0 degrees

Open
#361 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Kotlin
Stars
5.5k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

Research direction

Start with Camera2Video/utils/src/main/java/com/example/android/camera/utils/OrientationLiveData.kt and inspect computeRelativeRotation, then follow its use at Camera2Video/app/src/main/java/com/example/android/camera2/video/fragments/CameraFragment.kt around setOrientationHint. Verify the reported Surface.ROTATION_90 case with a camera sensor orientation of 0; done means the recording no longer receives an incorrect 90-degree orientation hint.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
mobile-dev
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.