Skip to content

Conversation

sbfkcel
Copy link

@sbfkcel sbfkcel commented Mar 13, 2025

This is useful if need to draw the device appearance correctly.

Related Discussions

#5704
#3605
#925

#5894


CODEC    SESSION packet                         SESSION packet
[codec] [type|width|height|orient] […] […] […] [type|width|height|orient] […] […]
                                              ^
                                              rotation occurs

CODEC packet:

  • codecId 4byte

SESSION packet:

  • type 1byte, The SESSION packet type is 0xff
  • width 4byte
  • hegiht 4byte
  • orient 3byte
    • isFlip 1byte
    • 180° 1byte
    • 90° 1byte

Orient format reference source

scrcpy/app/src/options.h

Lines 72 to 85 in 7998811

// ,----- hflip (applied before the rotation)
// | ,--- 180°
// | | ,- 90° clockwise
// | | |
enum sc_orientation { // v v v
SC_ORIENTATION_0, // 0 0 0
SC_ORIENTATION_90, // 0 0 1
SC_ORIENTATION_180, // 0 1 0
SC_ORIENTATION_270, // 0 1 1
SC_ORIENTATION_FLIP_0, // 1 0 0
SC_ORIENTATION_FLIP_90, // 1 0 1
SC_ORIENTATION_FLIP_180, // 1 1 0
SC_ORIENTATION_FLIP_270, // 1 1 1
};

Test run

meson setup x --buildtype=release --strip -Db_lto=true &&  ninja -Cx && ./run x

Output

INFO: Width=1920, Height=864, Flip=False, Direction=1

@sbfkcel
Copy link
Author

sbfkcel commented Mar 13, 2025

The previous fork has too many redundant records, use the new pull.

@rom1v Please check again to see if there are any new suggestions.

@sbfkcel
Copy link
Author

sbfkcel commented Apr 2, 2025

@rom1v Can this PR be merged in the next version? If it can be confirmed, I can't wait to update the Web client protocol parsing method.

rom1v added a commit that referenced this pull request Jun 15, 2025
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 <liyong2@4399.com>
@rom1v
Copy link
Collaborator

rom1v commented Jun 15, 2025

I just submitted #6159.

It introduces the protocol change to add a "session packet" (you're mentioned as co-author of that commit).

The session packet only includes the video resolution (since scrcpy currently does not use the device rotation), but the architecture is here, you can add the rotation on your branch with minimal changes I guess.

I adapted the client so that everything works correctly (as mentioned here: #5894 (comment)).

@rom1v rom1v force-pushed the dev branch 2 times, most recently from e06777a to 4841fdd Compare June 20, 2025 17:54
@sbfkcel
Copy link
Author

sbfkcel commented Jul 30, 2025

Okay, future versions will align with the new protocol.
Adding different flags to distinguish data will not pollute the project.
look forward to merging it into the official branch after implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants