Commit graph

1967 commits

Author SHA1 Message Date
Romain Vimont
48e3ff284f Make serial mandatory for sc_usb
In practice, it is already mandatory.

PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2022-01-27 23:35:57 +01:00
Romain Vimont
1d6f9952ee Extract USB handling from AOA
The AOA code handled both USB initialization and AOA commands/events.
Extract USB-related code to a separate file and structure.

PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2022-01-27 23:35:55 +01:00
Romain Vimont
d48d191262 Rename HAVE_AOA_HID to HAVE_USB
The condition actually determines whether scrcpy can use libusb or not.

PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2022-01-27 23:35:48 +01:00
Romain Vimont
2762f5d183 Move AOA/HID code to usb/
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974>
2022-01-27 23:35:34 +01:00
Romain Vimont
c996a6d462 Fix socket close race condition
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 ddb9396743
2022-01-27 23:26:46 +01:00
Romain Vimont
8ea6fb1f0f Print version on stdout
Refs b25404ee4b
2022-01-27 21:26:56 +01:00
Romain Vimont
b546c33eff Do not print scrcpy version twice on --version
Refs 6da6d905c2
2022-01-27 21:12:46 +01:00
Tomás Raiti
8615813005 Update README.sp.md to v1.21
PR #2962 <https://github.com/Genymobile/scrcpy/pull/2962>

Signed-off-by: Romain Vimont <rom@rom1v.com>
2022-01-27 19:14:07 +01:00
Romain Vimont
f51c53e913 Mention "screen copy" in README
Help users make sense of the app name :)
2022-01-27 19:05:33 +01:00
Romain Vimont
c0de365f67 Upgrade platform-tools (32.0.0) for Windows
Include the latest version of adb in Windows releases.
2022-01-27 19:02:07 +01:00
Romain Vimont
34e19dcc57 Upgrade SDL (2.0.20) for Windows
Include the latest version of SDL in Windows releases.
2022-01-27 19:02:07 +01:00
Romain Vimont
4817cadd09 Fix code style
Align function parameters.
2022-01-27 19:02:07 +01:00
Romain Vimont
02b5e87802 Slightly reduce lock usage
Locking the frame_buffer mutex to reference the input frame into the
tmp_frame is unnecessary.

This also fixes the missing unlock on error.
2022-01-27 19:01:43 +01:00
Romain Vimont
8e4d3beb01 Fix return value on adb commands error 2022-01-27 16:47:51 +01:00
Romain Vimont
50f4f1639c Add a shorcut "open a terminal here" on Windows
On Windows, the file explorer does not provide any "open a terminal
here" shortcut.

Add a bat file which just runs `cmd` to easily open a terminal directly
in the scrcpy directory (so there is no need to `cd C:\path\…`).

PR #2970 <https://github.com/Genymobile/scrcpy/pull/2970>
2022-01-27 16:47:51 +01:00
Romain Vimont
c8dc1917f4 Do not restore power mode if --no-control
This totally disables deferred cleanup when --no-control is passed.

Refs f289d206ea
2022-01-27 16:47:51 +01:00
Romain Vimont
9d2e00697e Use sc_ prefix for control_msg enums
Refs afa4a1b728
2022-01-27 16:47:51 +01:00
Romain Vimont
2faf9715be Add server option raw_video_stream
For convenience, this new option forces the 3 following options:
 - send_device_meta=false
 - send_frame_meta=false
 - send_dummy_byte=false

This allows to send a raw H.264 stream on the video socket.

Concretely:

    adb push scrcpy-server /data/local/tmp/scrcpy-server.jar
    adb forward tcp:1234 localabstract:scrcpy
    adb shell CLASSPATH=/data/local/tmp/scrcpy-server.jar \
        app_process / com.genymobile.scrcpy.Server 1.21 \
        raw_video_stream=true tunnel_forward=true control=false

As soon as a client connects via TCP to localhost:1234, it will receive
the raw H.264 stream.

Refs #1419 comment <https://github.com/Genymobile/scrcpy/pull/1419#issuecomment-1013964650>
PR #2971 <https://github.com/Genymobile/scrcpy/pull/2971>
2022-01-27 16:47:51 +01:00
Romain Vimont
45a5e560df Add server option send_dummy_byte
If set to false, no dummy byte is written to detect a connection error.

PR #2971 <https://github.com/Genymobile/scrcpy/pull/2971>
2022-01-26 11:30:46 +01:00
Romain Vimont
3ba32c2a0d Add server option send_device_meta
Similar to send_device_frame, this option allows to disable sending the
device name and size on start.

This is only useful when using the scrcpy-server alone to get a raw
H.264 stream, without using the scrcpy client.

PR #2971 <https://github.com/Genymobile/scrcpy/pull/2971>
2022-01-26 11:30:37 +01:00
Romain Vimont
6b21f4ae13 Reorder scrcpy-server options
Move the options unused by the scrcpy client at the end.

These options may be useful to use scrcpy-server directly (to get a raw
H.264 stream for example).

PR #2971 <https://github.com/Genymobile/scrcpy/pull/2971>
2022-01-26 11:30:30 +01:00
Romain Vimont
31a5d0c2bf Move call to send device name and size
This will allow to optionally disable it.

PR #2971 <https://github.com/Genymobile/scrcpy/pull/2971>
2022-01-26 11:30:19 +01:00
Romain Vimont
f289d206ea Disable more actions if --no-control
If control is disabled, then do not enable "show touches" or
automatically power off the device on close.
2022-01-24 21:45:44 +01:00
Romain Vimont
ca516f4318 Refactor if-block in cli
Several tests must be performed if opts->control is false.
2022-01-24 21:44:28 +01:00
Romain Vimont
5d6076bffd Move misplaced break statements
With ifdefs, the resulting code could contain both a return statement
and a break.
2022-01-24 21:38:30 +01:00
Romain Vimont
e0bce1725b Fix header guard prefix 2022-01-24 21:37:40 +01:00
Romain Vimont
ae8fdda09e Improve FAQ explanations 2022-01-24 08:55:27 +01:00
Romain Vimont
1ff69e21c2 Update error messages in FAQ
With the recent versions, scrcpy first executes "adb get-serialno", so
the adb error messages are not exactly the same.
2022-01-24 08:54:09 +01:00
Romain Vimont
a9429efa34 Fix downsize on error before first frame
Retry with a lower definition if MediaCodec fails before the first
frame, not the first packet.

In practice, the first packet is a config packet without any frame, and
MediaCodec might fail just after.

Refs 2eb6fe7d81
Refs #2963 <https://github.com/Genymobile/scrcpy/issues/2963>
2022-01-23 21:46:57 +01:00
Romain Vimont
063d103dd6 Capture mouse on start for --hid-mouse
If relative mode is enabled, capture the mouse immediately.
2022-01-23 21:31:53 +01:00
Romain Vimont
4bf9c057fe Extract relative mode check to an inline function
This will allow to reuse the condition in another function.
2022-01-23 21:31:11 +01:00
Romain Vimont
17c97820b2 Never forward capture keys
In relative mode, Alt and Super are "capture keys". Never forward them
to the input manager, to avoid inconsistencies between UP and DOWN
events.
2022-01-23 21:16:40 +01:00
Romain Vimont
8c7f0ed5ea Fix warning message
Make the message consistent for HID keyboard and HID mouse.
2022-01-23 21:16:35 +01:00
Romain Vimont
ac038f276e Add missing break statement
This was harmless because this is the last "case" of the switch, but for
consistency, add the missing break.
2022-01-23 15:01:11 +01:00
Romain Vimont
1f65b1bf87 Remove inline hint
There is no reason to request inlining here.
2022-01-23 15:01:11 +01:00
Romain Vimont
d41a46dc95 Handle libusb_get_device_descriptor() error
The function libusb_get_device_descriptor() might return an error.
Handle it.
2022-01-23 12:32:37 +01:00
Romain Vimont
308a1f8192 Simplify error handling in sc_aoa_init()
Use goto to avoid many repetitions.
2022-01-23 12:32:37 +01:00
Romain Vimont
241a587e61 Fix missing HID mouse destructor call
The destructor unregisters the HID mouse, so it was not reported as a
leak, but it must still be called.
2022-01-23 12:32:04 +01:00
Romain Vimont
7e35bfe382 Refactor if-blocks
Group all conditions requiring a controller in a single if-block.
2022-01-23 12:16:24 +01:00
Romain Vimont
855819bbd8 Remove redundant control boolean
The controller is NULL if and only if control is disabled, so an
additional control boolean is redundant.
2022-01-23 12:16:24 +01:00
Romain Vimont
557daf280e Pass NULL controller if control is disabled
If --no-control is requested, then the controller instance is not
initialized. However, its reference was still passed to screen and
input_manager.

Instead, pass NULL if no controller is available.
2022-01-23 12:16:24 +01:00
Romain Vimont
0b8e926330 Do not process finger events if no control
If --no-control is passed, then im->mp is NULL, so processing touches
would crash.
2022-01-23 12:16:24 +01:00
Romain Vimont
0ec3361bc9 Fix crash on --no-control
Relative mouse mode assumed that a mouse processor was always available,
but this is not the case if --no-control is passed.
2022-01-23 12:16:07 +01:00
Romain Vimont
81ff7ebd06 Simplify event loop
Merge single event handling with the event loop function.
2022-01-21 21:52:41 +01:00
Romain Vimont
1ffe312369 Handle file drop from input_manager
A file is pushed (or an apk is installed) to the device on file drop.
This behavior is specific to the screen and its input_manager.
2022-01-21 21:52:41 +01:00
Romain Vimont
ebef027c4f Do not return status for event handling
It is never read. Simplify.
2022-01-21 21:52:41 +01:00
Romain Vimont
8e4e7d42f1 Fix leak on file pusher error
If a file_push request fails, the allocated filename must be freed.
2022-01-21 21:52:41 +01:00
Romain Vimont
b066dc0bbf Rename file_handler to sc_file_pusher
Rename handler to pusher ("handler" is too generic), and add sc_ prefix.
2022-01-21 21:52:41 +01:00
Romain Vimont
262506c733 Limit retry-on-error to IllegalStateException
MediaCodec errors always trigger IllegalStateException or a subtype
(like MediaCodec.CodecException).

In practice, this avoids to retry if the error is caused by an
IOException when writing the video packet to the socket.
2022-01-21 21:52:29 +01:00
Romain Vimont
2eb6fe7d81 Downsize on error only before the first frame
The purpose of automatic downscaling on error is to make mirroring work
by just starting scrcpy without an explicit -m value, even if the
encoder could not encode at the screen definition.

It is only useful when we detect an encoding failure before the first
frame. Downsizing later could be surprising, so disable it.

PR #2947 <https://github.com/Genymobile/scrcpy/pull/2947>
2022-01-21 18:44:05 +01:00