Skip to content

Display and control your Android device

Ensure minimum codec size respects alignment

Romain Vimont2dd31b814ff1
diff --git a/server/src/main/java/com/genymobile/scrcpy/model/Size.java b/server/src/main/java/com/genymobile/scrcpy/model/Size.java
index 7581dc8d..363d2528 100644
--- a/server/src/main/java/com/genymobile/scrcpy/model/Size.java
+++ b/server/src/main/java/com/genymobile/scrcpy/model/Size.java
@@ -73,7 +73,7 @@ public final class Size {
assert h <= maxHeight : "The height cannot exceed maxHeight";
// Minimum codec size must be respected (regardless of requested maxSize)
- int minCodecSize = constraints.getMinCodecSize();
+ int minCodecSize = alignUp(constraints.getMinCodecSize(), alignment);
if (w < minCodecSize) {
w = minCodecSize;
}
@@ -81,6 +81,9 @@ public final class Size {
h = minCodecSize;
}
+ assert w % alignment == 0 : "The width must be a multiple of alignment";
+ assert h % alignment == 0 : "The height must be a multiple of alignment";
+
return new Size(w, h);
}
@@ -97,6 +100,10 @@ public final class Size {
return value / alignment * alignment;
}
+ private static int alignUp(int value, int alignment) {
+ return (value + alignment - 1) / alignment * alignment;
+ }
+
public Rect toRect() {
return new Rect(0, 0, width, height);
}