-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add device orientation information to header information #5894
base: dev
Are you sure you want to change the base?
Conversation
Hi, Thanks for your work. However, as I said in #5704 (comment), there is no really need to know the device orientation, since it can be inferred from the frame size in practice, and there are cases where the "orientation" to write is not clear. You replied:
You can do this based on the actual frame size. In theory, it could make sense to pass the device orientation (at least in some cases) in packets headers (even if it could be argued that it's overkill to pass it for each packet/frame). But then, the orientation must exactly match the frame it describes, which is not guaranteed here. There is no mechanism to make sure that the frame produced by MediaCodec is in the current device orientation (as returned by |
OK. What is the client on your screenshot? Is it a modified scrcpy client, or an alternative client you wrote?
If the orientation is sent "inline", it must be in sync with the encoded frames. Btw, it could allow to print a better error message for #1645. The current protocol has two "packet types":
To support your use case, I suggest to add a new packet type:
The session packet could be distinguished from the media packet with a single bit, and for simplicity both headers would have 12 bytes. It would be sent when a new encoding session starts, with the values in sync to what is passed to the encoder. |
Yes, I wrote an alternative client(browser-based). I will try to make some adjustments based on your suggestions and then submit a new implementation. |
…ackets (12 headers + screen width, screen height, device orientation)
…nd add whether to flip it
Based on your recommendations, I have implemented the modifications and completed local testing and verification. A new video session packet has been added, consisting of a 12-byte header + 16-byte data payload:
Orientation reflects the device’s original orientation, decoupled from the flip parameter in the The Build and execution command: meson setup x --buildtype=release --strip -Db_lto=true && ninja -Cx && ./run x -V debug Example debug output:
|
Thank you for your work. After a quick glance, here are some remarks. In my previous comment, the idea was to replace:
by:
The session packet would be 12 bytes (like media packets, this simplifies reader the header) without payload. Although scrcpy currently does not need/use this data, in principle I would be ok to add a session packet like that (a first commit could just refactor to include width and height for each session, without the orientation, then the orientation would be added in a separate commit). But this has consequences: the information should be passed "downstream" to the decoder, display, recorder and v4l2 (it impacts the way they work, since the codec context needs the initial size, which would not be in the "codec packet" anymore).
The orientation/flip only requires 3 bits: Lines 72 to 85 in 7998811
This would allow to make the session packet payload-less. In your implementation, you should not add display-specific data to |
OK, I did overlook factors like the camera. I'll submit a new implementation plan later. |
Through testing and verification, it is found that the changes in each device direction cannot be captured in ScreenCapture. For example: 0->2, 1->3, when the screen size does not change, the logic will not be called, but the physical device direction has changed. Rotating from 0->1->2->3 in sequence will trigger re-capture because the size has changed. Therefore, perhaps the best way is to implement it in SurfaceEncoder. By adding a parameter to SurfaceEncoder to distinguish whether the device is a display, or is there another better way? |
Because currently the encoding session is "reset" only if the size changes: scrcpy/server/src/main/java/com/genymobile/scrcpy/video/DisplaySizeMonitor.java Lines 107 to 138 in 7998811
|
Reset encoding on rotation even if the resulting size is the same. Refs <#5894 (comment)>
With this change, it resets on rotation even if the size is the same: a98e500 |
On a PR, please never include merge commits, always rebase on the latest |
OK, wrong operation |
On the other hand, it causes an unnecessary reset (since it works without it). This is just a corner case, but in theory we should NOT reset the encoding, but still send a new session packet to signal the new rotation. But tht's probably not possible in a non racy way (we can't determine exactly from which frame the new rotation is taken into account). |
This is useful if need to draw the device appearance correctly.
Related Discussions
#5704
#3605
#925