Skip to content

Commit 84bc3a7

Browse files
Fix video orientation
Signed-off-by: Keith Conger <keith.conger@blackboxembedded.com>
1 parent d53c55f commit 84bc3a7

1 file changed

Lines changed: 22 additions & 11 deletions

File tree

app/src/main/java/com/blackboxembedded/WunderLINQ/VideoRecService.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,21 @@ public class VideoRecService extends Service {
103103
private BluetoothMicRouter btRouter;
104104

105105
// Display rotation → degrees for MediaRecorder orientation hint
106-
private static final SparseIntArray ORIENTATIONS = new SparseIntArray();
106+
private static final SparseIntArray DEFAULT_ORIENTATIONS = new SparseIntArray();
107+
private static final SparseIntArray INVERSE_ORIENTATIONS = new SparseIntArray();
107108
static {
108-
ORIENTATIONS.append(Surface.ROTATION_0, 90);
109-
ORIENTATIONS.append(Surface.ROTATION_90, 0);
110-
ORIENTATIONS.append(Surface.ROTATION_180, 270);
111-
ORIENTATIONS.append(Surface.ROTATION_270, 180);
109+
// For sensors with orientation = 90
110+
DEFAULT_ORIENTATIONS.append(Surface.ROTATION_0, 90);
111+
DEFAULT_ORIENTATIONS.append(Surface.ROTATION_90, 0);
112+
DEFAULT_ORIENTATIONS.append(Surface.ROTATION_180, 270);
113+
DEFAULT_ORIENTATIONS.append(Surface.ROTATION_270, 180);
114+
115+
// For sensors with orientation = 270
116+
INVERSE_ORIENTATIONS.append(Surface.ROTATION_0, 270);
117+
INVERSE_ORIENTATIONS.append(Surface.ROTATION_90, 180);
118+
INVERSE_ORIENTATIONS.append(Surface.ROTATION_180, 90);
119+
INVERSE_ORIENTATIONS.append(Surface.ROTATION_270, 0);
112120
}
113-
114121
@Override public void onCreate() {
115122
super.onCreate();
116123
createNotification();
@@ -250,12 +257,16 @@ private int computeOrientationHint() {
250257
}
251258
} catch (Throwable ignored) {}
252259

253-
int deviceDeg = ORIENTATIONS.get(rotation, 0);
254-
// Typical recorder mapping (front gets the +180 mirror compensation)
255-
if (lensFacing == CameraCharacteristics.LENS_FACING_FRONT) {
256-
return (sensorOrientation + deviceDeg + 180) % 360;
260+
// Use the table based on the camera sensor's mounting
261+
if (sensorOrientation == 90) {
262+
return DEFAULT_ORIENTATIONS.get(rotation);
263+
} else if (sensorOrientation == 270) {
264+
return INVERSE_ORIENTATIONS.get(rotation);
257265
} else {
258-
return (sensorOrientation + deviceDeg) % 360;
266+
// Rare sensors; fall back to a simple sum
267+
// (kept for completeness; most phones are 90 or 270)
268+
int base = DEFAULT_ORIENTATIONS.get(rotation, 0);
269+
return (base + sensorOrientation - 90 + 360) % 360;
259270
}
260271
}
261272

0 commit comments

Comments
 (0)