Skip to content

fix: fit video inside the screen, refit on rotation (#17, #31) - #49

Merged
compot-dev merged 1 commit into
v2from
fix/video-fit
Oct 12, 2026
Merged

compot-dev merged 1 commit into
v2from
fix/video-fit

Conversation

@compot-dev

Copy link
Copy Markdown
Collaborator

Fixes #17, fixes #31.

⚠️ Do not merge before testing on a device (label awaiting device test).

Issue Problem Fix
#17 The view width was derived from the screen height only, so on 16:10 and 4:3 tablets the left and right edges were cut off fitInside(): the largest size with the stream's aspect ratio that fits inside the container. A narrower screen gets black bars top and bottom, a wider one left and right
#31 On large screens Android 16 ignores the fixed landscape orientation; in portrait the cropping was even worse The root's OnLayoutChangeListener refits the video whenever the container size changes: rotation, multi-window, a resized window

Zoom is reset on refit, because it depends on the view size.

Tests

VideoFitTest: same aspect ratio; 16:9 on 16:10 and on 4:3; 4:3 on 16:9; 21:9; portrait screen; never larger than the box. assembleDebug and lintDebug pass.

Device checklist

Independent of #48. Both touch Decoder.java, but in different places.

@compot-dev compot-dev added the awaiting device test PR ready, merge only after testing on a real device label Oct 12, 2026
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Fit video within the screen and refit after resizing

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Fit video within its container to prevent cropping across screen and stream aspect ratios.
• Refit after resolution or window-size changes, resetting zoom for the resized view.
• Add aspect-ratio and bounds tests; device verification remains pending before merge.
Diagram

graph TD
  R["Stream resolution"] --> F["Fit video"] --> S["Fit inside"] --> V["Centered video"] --> Z["Reset zoom"]
  L["Root resize"] --> F
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Fit with a TextureView transform
  • ➕ Could retain a full-container TextureView while scaling its rendered contents.
  • ➖ Would need to coordinate fitting with the existing pinch-to-zoom and pan transform.

Recommendation: Keep the centered-layout approach: it preserves the existing zoom transform and makes the fitted bounds explicit. Verify resizing and zoom on a device before merging.

Files changed (2) +87 / -6

Bug fix (1) +40 / -6
Decoder.javaFit the video surface on resolution and container-size changes +40/-6

Fit the video surface on resolution and container-size changes

• Stores the stream dimensions and sizes the centered TextureView to the largest aspect-preserving rectangle within its parent. A root layout listener refits after resizing, and each refit resets zoom and pan.

android/app/src/main/java/com/openipc/decoder/Decoder.java

Tests (1) +47 / -0
VideoFitTest.javaCover video fitting across screen shapes +47/-0

Cover video fitting across screen shapes

• Adds unit tests for matching and differing aspect ratios, portrait containers, and fitted dimensions that do not exceed the container.

android/app/src/test/java/com/openipc/decoder/VideoFitTest.java

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can commit Qodo's fix in one click with committable suggestions (GitHub & GitLab)

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

The view width was derived from the screen height only, so on screens
narrower than the stream (16:10 and 4:3 tablets) the left and right
edges were cut off (fixes #17).

- fitInside() picks the largest size with the stream's aspect ratio that
  fits in the container (letterbox or pillarbox).
- A layout-change listener on the root refits the video when the
  container size changes: rotation, multi-window, and Android 16 ignoring
  the fixed landscape orientation on large screens (fixes #31).
- Zoom is reset on refit, since it depends on the view size.
@compot-dev

Copy link
Copy Markdown
Collaborator Author

Device-tested (#53): on an emulated 4:3 screen (wm size 960x720) v2 crops the image while this PR letterboxes it with the whole frame visible; 16:9 is unchanged. Rebased onto the current v2, CI is green.

@compot-dev compot-dev removed the awaiting device test PR ready, merge only after testing on a real device label Oct 12, 2026
@compot-dev
compot-dev merged commit 923a527 into v2 Oct 12, 2026
4 checks passed
@compot-dev
compot-dev deleted the fix/video-fit branch October 13, 2026 17:16
compot-dev added a commit that referenced this pull request Oct 15, 2026
fix: fit video inside the screen, refit on rotation (#17, #31)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android 16: fixed landscape orientation is ignored on large screens Image is cropped at the edges on non-16:9 screens

1 participant