mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-03 06:39:39 +00:00
Always reset encoding on rotation
Reset encoding on rotation even if the resulting size is the same. Refs <https://github.com/Genymobile/scrcpy/pull/5894#issuecomment-2717035585>
This commit is contained in:
parent
c63d9e1803
commit
a98e50078a
3 changed files with 46 additions and 15 deletions
|
@ -15,8 +15,35 @@ import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
import android.view.IDisplayWindowListener;
|
import android.view.IDisplayWindowListener;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class DisplaySizeMonitor {
|
public class DisplaySizeMonitor {
|
||||||
|
|
||||||
|
private static class SessionInfo {
|
||||||
|
private Size size;
|
||||||
|
private int rotation;
|
||||||
|
|
||||||
|
public SessionInfo(Size size, int rotation) {
|
||||||
|
this.size = size;
|
||||||
|
this.rotation = rotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o)
|
||||||
|
return true;
|
||||||
|
if (!(o instanceof SessionInfo))
|
||||||
|
return false;
|
||||||
|
SessionInfo that = (SessionInfo) o;
|
||||||
|
return rotation == that.rotation && Objects.equals(size, that.size);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "{" + "size=" + size + ", rotation=" + rotation + '}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public interface Listener {
|
public interface Listener {
|
||||||
void onDisplaySizeChanged();
|
void onDisplaySizeChanged();
|
||||||
}
|
}
|
||||||
|
@ -34,7 +61,7 @@ public class DisplaySizeMonitor {
|
||||||
|
|
||||||
private int displayId = Device.DISPLAY_ID_NONE;
|
private int displayId = Device.DISPLAY_ID_NONE;
|
||||||
|
|
||||||
private Size sessionDisplaySize;
|
private SessionInfo sessionInfo;
|
||||||
|
|
||||||
private Listener listener;
|
private Listener listener;
|
||||||
|
|
||||||
|
@ -98,12 +125,16 @@ public class DisplaySizeMonitor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized Size getSessionDisplaySize() {
|
private synchronized SessionInfo getSessionInfo() {
|
||||||
return sessionDisplaySize;
|
return sessionInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void setSessionDisplaySize(Size sessionDisplaySize) {
|
private synchronized void setSessionInfo(SessionInfo sessionInfo) {
|
||||||
this.sessionDisplaySize = sessionDisplaySize;
|
this.sessionInfo = sessionInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSessionInfo(Size size, int rotation) {
|
||||||
|
setSessionInfo(new SessionInfo(size, rotation));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkDisplaySizeChanged() {
|
private void checkDisplaySizeChanged() {
|
||||||
|
@ -112,29 +143,29 @@ public class DisplaySizeMonitor {
|
||||||
Ln.w("DisplayInfo for " + displayId + " cannot be retrieved");
|
Ln.w("DisplayInfo for " + displayId + " cannot be retrieved");
|
||||||
// We can't compare with the current size, so reset unconditionally
|
// We can't compare with the current size, so reset unconditionally
|
||||||
if (Ln.isEnabled(Ln.Level.VERBOSE)) {
|
if (Ln.isEnabled(Ln.Level.VERBOSE)) {
|
||||||
Ln.v("DisplaySizeMonitor: requestReset(): " + getSessionDisplaySize() + " -> (unknown)");
|
Ln.v("DisplaySizeMonitor: requestReset(): " + getSessionInfo() + " -> (unknown)");
|
||||||
}
|
}
|
||||||
setSessionDisplaySize(null);
|
setSessionInfo(null);
|
||||||
listener.onDisplaySizeChanged();
|
listener.onDisplaySizeChanged();
|
||||||
} else {
|
} else {
|
||||||
Size size = di.getSize();
|
SessionInfo si = new SessionInfo(di.getSize(), di.getRotation());
|
||||||
|
|
||||||
// The field is hidden on purpose, to read it with synchronization
|
// The field is hidden on purpose, to read it with synchronization
|
||||||
@SuppressWarnings("checkstyle:HiddenField")
|
@SuppressWarnings("checkstyle:HiddenField")
|
||||||
Size sessionDisplaySize = getSessionDisplaySize(); // synchronized
|
SessionInfo sessionInfo = getSessionInfo(); // synchronized
|
||||||
|
|
||||||
// .equals() also works if sessionDisplaySize == null
|
// .equals() also works if sessionDisplaySize == null
|
||||||
if (!size.equals(sessionDisplaySize)) {
|
if (!si.equals(sessionInfo)) {
|
||||||
// Reset only if the size is different
|
// Reset only if the size is different
|
||||||
if (Ln.isEnabled(Ln.Level.VERBOSE)) {
|
if (Ln.isEnabled(Ln.Level.VERBOSE)) {
|
||||||
Ln.v("DisplaySizeMonitor: requestReset(): " + sessionDisplaySize + " -> " + size);
|
Ln.v("DisplaySizeMonitor: requestReset(): " + sessionInfo + " -> " + si);
|
||||||
}
|
}
|
||||||
// Set the new size immediately, so that a future onDisplayChanged() event called before the asynchronous prepare()
|
// Set the new size immediately, so that a future onDisplayChanged() event called before the asynchronous prepare()
|
||||||
// considers that the current size is the requested size (to avoid a duplicate requestReset())
|
// considers that the current size is the requested size (to avoid a duplicate requestReset())
|
||||||
setSessionDisplaySize(size);
|
setSessionInfo(si);
|
||||||
listener.onDisplaySizeChanged();
|
listener.onDisplaySizeChanged();
|
||||||
} else if (Ln.isEnabled(Ln.Level.VERBOSE)) {
|
} else if (Ln.isEnabled(Ln.Level.VERBOSE)) {
|
||||||
Ln.v("DisplaySizeMonitor: Size not changed (" + size + "): do not requestReset()");
|
Ln.v("DisplaySizeMonitor: Size and rotation not changed (" + sessionInfo + "): do not requestReset()");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ public class NewDisplayCapture extends SurfaceCapture {
|
||||||
videoSize = displaySize;
|
videoSize = displaySize;
|
||||||
displayRotation = 0;
|
displayRotation = 0;
|
||||||
// Set the current display size to avoid an unnecessary call to invalidate()
|
// Set the current display size to avoid an unnecessary call to invalidate()
|
||||||
displaySizeMonitor.setSessionDisplaySize(displaySize);
|
displaySizeMonitor.setSessionInfo(displaySize, displayRotation);
|
||||||
} else {
|
} else {
|
||||||
DisplayInfo displayInfo = ServiceManager.getDisplayManager().getDisplayInfo(virtualDisplay.getDisplay().getDisplayId());
|
DisplayInfo displayInfo = ServiceManager.getDisplayManager().getDisplayInfo(virtualDisplay.getDisplay().getDisplayId());
|
||||||
displaySize = displayInfo.getSize();
|
displaySize = displayInfo.getSize();
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class ScreenCapture extends SurfaceCapture {
|
||||||
}
|
}
|
||||||
|
|
||||||
Size displaySize = displayInfo.getSize();
|
Size displaySize = displayInfo.getSize();
|
||||||
displaySizeMonitor.setSessionDisplaySize(displaySize);
|
displaySizeMonitor.setSessionInfo(displaySize, displayInfo.getRotation());
|
||||||
|
|
||||||
if (captureOrientationLock == Orientation.Lock.LockedInitial) {
|
if (captureOrientationLock == Orientation.Lock.LockedInitial) {
|
||||||
// The user requested to lock the video orientation to the current orientation
|
// The user requested to lock the video orientation to the current orientation
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue