Conversation
e06777a to
4841fdd
Compare
|
To make the session data more compact, additional metadata is reserved. Would it be better to put the flag and width together in the first 4 bytes? scrcpy/server/src/main/java/com/genymobile/scrcpy/device/Streamer.java Lines 92 to 102 in 02047ff |
|
That way, the packet header is always 12 bytes: Line 103 in e5e58b1 If it was variable, it would require the client to buffer the data (more copies) and "packetize" (more complexity). As a tradeoff, it uses 2 syscalls (one to read the header, one to read the full payload). |
|
Sorry, I may not have explained it clearly enough. The Session Meta data is indeed always 12 bytes. However, since the flag, width, and height each occupy 4 bytes, there’s no remaining space for expansion. Therefore, my proposal is to combine the flag and width into 4 bytes, keep height as 4 bytes, and reserve the remaining 4 bytes for future expansion. |
|
Note that there is no backward or forward compatibility (the protocol is always used between matching client and server), so there is nothing to "reserve", the protocol can be changed completely for any version. If we want to add something taking 31 bits or less, you can store it just after the flag. If we need a lot more data, we can add a payload. We can also move the width/height fields as needed. |
|
Now that #6216 is merged, the next scrcpy version will be 4.0. This is a good time to merge this protocol change. |
Introduce a new packet type, a "session" packet, containing metadata
about the encoding session. It is used only for the video stream and
currently includes the video resolution.
For illustration, here is a sequence of packets on the video stream:
device rotation
v
CODEC | SESSION | MEDIA | MEDIA | … | SESSION | MEDIA | MEDIA | …
1920x1080 <-----------------> 1080x1920 <------------------
encoding session 1 encoding session 2
This metadata is not strictly necessary, since the video resolution can
be determined after decoding. However, it allows detection of cases
where the encoder does not respect the requested size (and logs a
warning), even without decoding (e.g., when there is no video playback).
Additional metadata could be added later if necessary, for example the
actual device rotation.
Refs #5918 <#5918>
Refs #5894 <#5894>
PR #6159 <#6159>
Co-authored-by: gz0119 <liyong2@4399.com>
Introduce a new packet type, a "session" packet, containing metadata about the encoding session. It is used only for the video stream, and currently includes the video resolution.
For illustration, here is a sequence of packets on the video stream:
This metadata is not strictly necessary, since the video resolution can be determined after decoding. However, it allows detection of cases where the encoder does not respect the requested size (and logs a warning), even without decoding (e.g., when there is no video playback).
Additional metadata could be added later if necessary, for example the actual device rotation.
Refs #5918
Refs #5894