-
-
Couldn't load subscription status.
- Fork 12.2k
Add session metadata for video stream #6159
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
base: dev
Are you sure you want to change the base?
Conversation
The stream metadata will contain both: - the codec id at the start of the stream - the session metadata (video width and height) at the start of every "session" (typically on rotation)
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 #5984 <#5894>
Co-authored-by: gz0119 <[email protected]>
The delay buffer must forward the session packets while preserving their order relative to media packets.
Warn if the size of a decoded video frame does not match the session metadata.
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. |
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