Skip to content
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

Screen Resolution Issue After Rotation #2

Closed
Duckinahat opened this issue Mar 8, 2018 · 5 comments
Closed

Screen Resolution Issue After Rotation #2

Duckinahat opened this issue Mar 8, 2018 · 5 comments

Comments

@Duckinahat
Copy link

Hi, I noticed an issue that arises when using the default camera app on my phone. When I enter my camera in portrait mode it works fine. If I change to landscape however the viewing window does not follow and instead gets squished. Upon rotating back to portrait, the window remains in a weird squished state. This continues after closing the app and returning to the home screen. I have been able to fix this by entering a different app that supports a landscape mode (such as messaging) where the window will correctly resize.

When first initialized, the terminal shows:
INFO: Initial texture: 1440x2560
I have noticed that when changing orientation in most apps the computer recieves a [h264 @ 0x7fa2140008c0] Reinit context to 1440x2560, pix_fmt: yuv420p and then reorients the display window accordingly. However, I noticed that when the camera app changes to landscape no reinit message appears in the terminal. Navigating to a different app and rotating yields a reinit and fixes the issue.

I am sure this is the source of the issue, I don't know how scrcpy gets the signal to reinit the display. Wondering if there's perhaps a different signal that could be caught?

I built scrcpy on desktop Ubuntu 16.04 64-bit and it seems to be working just fine besides this. The phone is a stock LG G5 running android 7.0

Let me know if there's any more information that would be helpful. Thanks for looking.

@rom1v
Copy link
Collaborator

rom1v commented Mar 9, 2018

To avoid flickering, some camera apps are always in portrait mode.

When you rotate them, they manually rotate their components without reinitializing the camera. But this is still a portrait app!

@Duckinahat
Copy link
Author

Interesting, I wonder why then it leaves it in an odd state afterwards. When the phone rotates in the camera app, the scrcpy window rotates the contents inside without resizing. Does scrcpy get orientation information from the gyroscope as well?

I took a series of screenshots of the window exactly as it appears.
Portrait:
camera_portrait
Landscape:
camera_landscape
Portrait (again):
camera_portrait_return

It seems to know the phone is horizontal, or else the second photo would simply appear sideways and not squished, correct?

@rom1v
Copy link
Collaborator

rom1v commented Mar 9, 2018

Thank you for the screenshots. Now, this is a bug 😉

What's the camera app?

@rom1v rom1v added the bug label Mar 9, 2018
@Duckinahat
Copy link
Author

It's the LG Camera app version 5.20.15
adb shows it as "com.lge.camera"

@rom1v
Copy link
Collaborator

rom1v commented Apr 9, 2020

Does it still happen with the latest version?

What about the current dev branch (here is a binary)? With --lock-video-orientation 1 for example.

@rom1v rom1v closed this as completed Feb 26, 2021
rom1v added a commit that referenced this issue Oct 27, 2021
On Linux, socket functions are unblocked by shutdown(), but on Windows
they are unblocked by closesocket().

Expose net_interrupt() and net_close() to abstract these differences:
 - net_interrupt() calls shutdown() on Linux and closesocket() on
   Windows (if not already called);
 - net_close() calls close() on Linux and closesocket() on Windows (if
   not already called).

This simplifies the server code, and prevents a data race on close
(reported by TSAN) on Linux (but does not fix it on Windows):

    WARNING: ThreadSanitizer: data race (pid=836124)
      Write of size 8 at 0x7ba0000000d0 by main thread:
        #0 close ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:1690 (libtsan.so.0+0x359d8)
        #1 net_close ../app/src/util/net.c:211 (scrcpy+0x1c76b)
        #2 close_socket ../app/src/server.c:330 (scrcpy+0x19442)
        #3 server_stop ../app/src/server.c:522 (scrcpy+0x19e33)
        #4 scrcpy ../app/src/scrcpy.c:532 (scrcpy+0x156fc)
        #5 main ../app/src/main.c:92 (scrcpy+0x622a)

      Previous read of size 8 at 0x7ba0000000d0 by thread T6:
        #0 recv ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:6603 (libtsan.so.0+0x4f4a6)
        #1 net_recv ../app/src/util/net.c:167 (scrcpy+0x1c5a7)
        #2 run_receiver ../app/src/receiver.c:76 (scrcpy+0x12819)
        #3 <null> <null> (libSDL2-2.0.so.0+0x84f40)
rom1v added a commit that referenced this issue Oct 27, 2021
On Linux, socket functions are unblocked by shutdown(), but on Windows
they are unblocked by closesocket().

Expose net_interrupt() and net_close() to abstract these differences:
 - net_interrupt() calls shutdown() on Linux and closesocket() on
   Windows (if not already called);
 - net_close() calls close() on Linux and closesocket() on Windows (if
   not already called).

This simplifies the server code, and prevents a data race on close
(reported by TSAN) on Linux (but does not fix it on Windows):

    WARNING: ThreadSanitizer: data race (pid=836124)
      Write of size 8 at 0x7ba0000000d0 by main thread:
        #0 close ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:1690 (libtsan.so.0+0x359d8)
        #1 net_close ../app/src/util/net.c:211 (scrcpy+0x1c76b)
        #2 close_socket ../app/src/server.c:330 (scrcpy+0x19442)
        #3 server_stop ../app/src/server.c:522 (scrcpy+0x19e33)
        #4 scrcpy ../app/src/scrcpy.c:532 (scrcpy+0x156fc)
        #5 main ../app/src/main.c:92 (scrcpy+0x622a)

      Previous read of size 8 at 0x7ba0000000d0 by thread T6:
        #0 recv ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:6603 (libtsan.so.0+0x4f4a6)
        #1 net_recv ../app/src/util/net.c:167 (scrcpy+0x1c5a7)
        #2 run_receiver ../app/src/receiver.c:76 (scrcpy+0x12819)
        #3 <null> <null> (libSDL2-2.0.so.0+0x84f40)
rom1v added a commit that referenced this issue Jan 27, 2022
The server needs to interrupt the sockets on stop, but it must not close
them while other threads may attempt to read from or write to them.

In particular, the video_socket is read by the stream thread, and the
control_socket is written by the controller and read by receiver.

Therefore, close the socket only on sc_server_destroy(), which is called
after all other threads are joined.

Reported by TSAN on close:

    WARNING: ThreadSanitizer: data race (pid=3287612)
      Write of size 8 at 0x7ba000000080 by thread T1:
        #0 close ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:1690 (libtsan.so.0+0x359d8)
        #1 net_close ../app/src/util/net.c:280 (scrcpy+0x23643)
        #2 run_server ../app/src/server.c:772 (scrcpy+0x20047)
        #3 <null> <null> (libSDL2-2.0.so.0+0x905a0)

      Previous read of size 8 at 0x7ba000000080 by thread T16:
        #0 recv ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:6603 (libtsan.so.0+0x4f4a6)
        #1 net_recv_all ../app/src/util/net.c:228 (scrcpy+0x234a9)
        #2 stream_recv_packet ../app/src/stream.c:33 (scrcpy+0x2045c)
        #3 run_stream ../app/src/stream.c:228 (scrcpy+0x21169)
        #4 <null> <null> (libSDL2-2.0.so.0+0x905a0)

Refs ddb9396
@meroz92 meroz92 mentioned this issue Jun 25, 2022
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants