Skip to content

Commit a98e500

Browse files
committed
Always reset encoding on rotation
Reset encoding on rotation even if the resulting size is the same. Refs <#5894 (comment)>
1 parent c63d9e1 commit a98e500

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

server/src/main/java/com/genymobile/scrcpy/video/DisplaySizeMonitor.java

+44-13
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,35 @@
1515
import android.os.HandlerThread;
1616
import android.view.IDisplayWindowListener;
1717

18+
import java.util.Objects;
19+
1820
public class DisplaySizeMonitor {
1921

22+
private static class SessionInfo {
23+
private Size size;
24+
private int rotation;
25+
26+
public SessionInfo(Size size, int rotation) {
27+
this.size = size;
28+
this.rotation = rotation;
29+
}
30+
31+
@Override
32+
public boolean equals(Object o) {
33+
if (this == o)
34+
return true;
35+
if (!(o instanceof SessionInfo))
36+
return false;
37+
SessionInfo that = (SessionInfo) o;
38+
return rotation == that.rotation && Objects.equals(size, that.size);
39+
}
40+
41+
@Override
42+
public String toString() {
43+
return "{" + "size=" + size + ", rotation=" + rotation + '}';
44+
}
45+
}
46+
2047
public interface Listener {
2148
void onDisplaySizeChanged();
2249
}
@@ -34,7 +61,7 @@ public interface Listener {
3461

3562
private int displayId = Device.DISPLAY_ID_NONE;
3663

37-
private Size sessionDisplaySize;
64+
private SessionInfo sessionInfo;
3865

3966
private Listener listener;
4067

@@ -98,12 +125,16 @@ public void stopAndRelease() {
98125
}
99126
}
100127

101-
private synchronized Size getSessionDisplaySize() {
102-
return sessionDisplaySize;
128+
private synchronized SessionInfo getSessionInfo() {
129+
return sessionInfo;
130+
}
131+
132+
private synchronized void setSessionInfo(SessionInfo sessionInfo) {
133+
this.sessionInfo = sessionInfo;
103134
}
104135

105-
public synchronized void setSessionDisplaySize(Size sessionDisplaySize) {
106-
this.sessionDisplaySize = sessionDisplaySize;
136+
public void setSessionInfo(Size size, int rotation) {
137+
setSessionInfo(new SessionInfo(size, rotation));
107138
}
108139

109140
private void checkDisplaySizeChanged() {
@@ -112,29 +143,29 @@ private void checkDisplaySizeChanged() {
112143
Ln.w("DisplayInfo for " + displayId + " cannot be retrieved");
113144
// We can't compare with the current size, so reset unconditionally
114145
if (Ln.isEnabled(Ln.Level.VERBOSE)) {
115-
Ln.v("DisplaySizeMonitor: requestReset(): " + getSessionDisplaySize() + " -> (unknown)");
146+
Ln.v("DisplaySizeMonitor: requestReset(): " + getSessionInfo() + " -> (unknown)");
116147
}
117-
setSessionDisplaySize(null);
148+
setSessionInfo(null);
118149
listener.onDisplaySizeChanged();
119150
} else {
120-
Size size = di.getSize();
151+
SessionInfo si = new SessionInfo(di.getSize(), di.getRotation());
121152

122153
// The field is hidden on purpose, to read it with synchronization
123154
@SuppressWarnings("checkstyle:HiddenField")
124-
Size sessionDisplaySize = getSessionDisplaySize(); // synchronized
155+
SessionInfo sessionInfo = getSessionInfo(); // synchronized
125156

126157
// .equals() also works if sessionDisplaySize == null
127-
if (!size.equals(sessionDisplaySize)) {
158+
if (!si.equals(sessionInfo)) {
128159
// Reset only if the size is different
129160
if (Ln.isEnabled(Ln.Level.VERBOSE)) {
130-
Ln.v("DisplaySizeMonitor: requestReset(): " + sessionDisplaySize + " -> " + size);
161+
Ln.v("DisplaySizeMonitor: requestReset(): " + sessionInfo + " -> " + si);
131162
}
132163
// Set the new size immediately, so that a future onDisplayChanged() event called before the asynchronous prepare()
133164
// considers that the current size is the requested size (to avoid a duplicate requestReset())
134-
setSessionDisplaySize(size);
165+
setSessionInfo(si);
135166
listener.onDisplaySizeChanged();
136167
} else if (Ln.isEnabled(Ln.Level.VERBOSE)) {
137-
Ln.v("DisplaySizeMonitor: Size not changed (" + size + "): do not requestReset()");
168+
Ln.v("DisplaySizeMonitor: Size and rotation not changed (" + sessionInfo + "): do not requestReset()");
138169
}
139170
}
140171
}

server/src/main/java/com/genymobile/scrcpy/video/NewDisplayCapture.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void prepare() {
114114
videoSize = displaySize;
115115
displayRotation = 0;
116116
// Set the current display size to avoid an unnecessary call to invalidate()
117-
displaySizeMonitor.setSessionDisplaySize(displaySize);
117+
displaySizeMonitor.setSessionInfo(displaySize, displayRotation);
118118
} else {
119119
DisplayInfo displayInfo = ServiceManager.getDisplayManager().getDisplayInfo(virtualDisplay.getDisplay().getDisplayId());
120120
displaySize = displayInfo.getSize();

server/src/main/java/com/genymobile/scrcpy/video/ScreenCapture.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void prepare() throws ConfigurationException {
7777
}
7878

7979
Size displaySize = displayInfo.getSize();
80-
displaySizeMonitor.setSessionDisplaySize(displaySize);
80+
displaySizeMonitor.setSessionInfo(displaySize, displayInfo.getRotation());
8181

8282
if (captureOrientationLock == Orientation.Lock.LockedInitial) {
8383
// The user requested to lock the video orientation to the current orientation

0 commit comments

Comments
 (0)