Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
106.53k stars 10.31k forks source link

How to listen on the change of the screen when the screen is rotated #3605

Open codematrixer opened 1 year ago

codematrixer commented 1 year ago

If I only use the scrcpy-server, and then use the jmuxer to decode on frontend, how will the frontend listen when the screen is rotated. Only when it listens, can the next step, such as reset jmuxer to make sure the screen display is normal

I refer to this issue, but didn't find the answer.

Looking forward to your reply. @rom1v

rom1v commented 1 year ago

how will the frontend listen when the screen is rotated

On the client side, scrcpy does not detect rotation per-se, but only video frame size changes. So when a new frame has a different size from the previous one, it resizes the window accordingly.

codematrixer commented 1 year ago

but only video frame size changes

That is to say, my frontend needs to detect the size of each frame in real time, and reset jmuxer if it is different from the last time?

rom1v commented 1 year ago

my frontend needs to detect the size of each frame in real time

This is what the scrcpy client does. Alternatively, you could adapt the protocol to send a "rotation" event on the wire before sending the next frame at the new dimension.

Since when the frame is decoded, the size is available directly in the resulting AVFrame, such an event is not necessary for the scrcpy client currently.