Originally created by: lycfr
Scrcpy returns different width and height in versions 1.24 and 2.3.1. Can you help explain? In addition, I want to simulate encapsulation and click mobile phone commands on the front end. Version 1.24 is OK, but version 2.3.1 is not. Is there still an error? Can you help me analyze it?
The java code I use
final Socket screenSocket = new Socket("127.0.0.1", localPort);
InputStream screenStream = screenSocket.getInputStream();
controlSocket = new Socket("127.0.0.1", localPort);
controlOutputStream = controlSocket.getOutputStream();
for (int i = 0; i < 64; i++) {
          screenStream.read();
}
width = screenStream.read() << 8 | screenStream.read();
height = screenStream.read() << 8 | screenStream.read();
System.out.println("scrcpy:width:" + width + ",height:" + height);
Version 1.24 obtains the width and height of scrcpy, Simulate click normally
CLASSPATH=/data/local/tmp/scrcpy-server1.jar app_process / com.genymobile.scrcpy.Server 1.24 log_level=info max_size=1000 bit_rate=8000000 max_fps=60 lock_video_orientation=-1 tunnel_forward=true send_frame_meta=false control=true display_id=0 show_touches=false stay_awake=true power_off_on_close=false
[server] INFO: Device: HUAWEI MHA-AL00 (Android 9)
scrcpy:width:560,height:1000
Version 2.3.1 obtains the width and height of scrcpy
CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 2.3.1 log_level=info max_size=1000 video_bit_rate=8000000 max_fps=60 lock_video_orientation=-1 tunnel_forward=true send_frame_meta=false control=true audio=false display_id=0 show_touches=false stay_awake=true raw_stream=false power_off_on_close=false
[server] INFO: Device: [HUAWEI] HUAWEI MHA-AL00 (Android 9)
scrcpy:width:26674,height:13876
The scrcpy versions output by the two versions are inconsistent. What is the reason?
There is another one, the same code simulates the request click event, and found that the 2.3.1 version cannot take effect, and some prompt messages
Simulate click request code
private void commitTouchEvent(byte actionType, int x, int y, int screenWidth, int screenHeight) {
        // Scrcpy.server Device.computeVideoSize
        if (screenHeight == maxSize) {
            screenWidth = height == maxSize ? width : height;
        } else if (screenWidth == maxSize) {
            screenHeight = width == maxSize ? height : width;
        }
        System.out.println(screenWidth + "x" + screenHeight);
        touchEventBuffer.rewind();
        touchEventBuffer.put(TYPE_INJECT_TOUCH_EVENT);
        touchEventBuffer.put(actionType);
        touchEventBuffer.putLong(-1L); // pointerId
        touchEventBuffer.putInt(x);
        touchEventBuffer.putInt(y);
        touchEventBuffer.putShort((short) screenWidth);
        touchEventBuffer.putShort((short) screenHeight);
        touchEventBuffer.putShort((short) 0xffff); // pressure
        touchEventBuffer.putInt(1); // buttons left button: 1 << 0 | right button: 1 << 1 | middle button: 1 << 2
        commit(touchEventBuffer.array());
    }
    private void commit(byte[] msg) {
        try {
            controlOutputStream.write(msg);
            controlOutputStream.flush();
        } catch (IOException e) {
            e.printStackTrace();
//            System.out.println(mobileId + " commit msg error");
        }
    }
2.3.1 Error information
[server] WARN: Ignore touch event, it was generated for a different device size
[server] WARN: Unknown event type: -1
Originally posted by: lycfr
I set max_size=1000 and found that 2.3.1 did not take effect.
Originally posted by: rom1v
The header has changed in scrcpy 2.0 by 238ab872ba0ea18c2553dfe3c2202d64d67d8960.
The protocol is documented here.