Romain Vimont
8fc9dca8cb
Make serial optional to find USB devices
...
If no serial is provided, then list all available USB devices (which can
be open and having a serial).
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:36:15 +01:00
Romain Vimont
1c17f57c10
Find a list of devices instead of a single one
...
Several devices may match the requested serial, but above all, this
paves the way to list all devices (when no serial is provided).
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:36:13 +01:00
Romain Vimont
d8b37fe189
Wrap libusb_device
...
Introduce a structure to wrap a libusb_device and expose its descriptor
data read during discovery.
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:36:11 +01:00
Romain Vimont
0ee9e2ff51
Expose function to find a USB device
...
The device was automatically found by sc_usb_connect(). Instead, expose
a function to find a device from a serial, and let the caller connect to
the device found (if any).
This will allow to list all devices first, then select one device to
connect to.
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:36:08 +01:00
Romain Vimont
1ab3692f3d
Add util function to read USB descriptor string
...
Use it from accept_device() to simplify (at the cost an additional
allocation for each serial, but it is not important).
It will also be useful in other functions in further commits.
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:36:06 +01:00
Romain Vimont
bbef426a4b
Split USB initialization and connection
...
This will allow to execute other USB calls (retrieving the device list
for example) before connecting to the selected device.
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:36:04 +01:00
Romain Vimont
2114f48185
Find device with USB context
...
An explicit context was used everywhere except for listing the devices.
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:36:02 +01:00
Romain Vimont
b779eca8d3
Remove libusb_device field
...
It is possible to retrieve the device instance from the handle via
libusb_get_device(), so we don't need to reference the device one more
time.
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:36:00 +01:00
Romain Vimont
adda47b0f7
Move sc_usb out of sc_aoa
...
This will allow to initialize a USB device separately and pass it to
sc_aoa.
PR #2974 <https://github.com/Genymobile/scrcpy/pull/2974 >
2022-01-27 23:35:59 +01:00
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
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
9d2e00697e
Use sc_ prefix for control_msg enums
...
Refs afa4a1b728
2022-01-27 16:47:51 +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
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
3a0ba7d0a4
Disable downsizing on error if V4L2 is enabled
...
V4L2 device is created with the initial device size, it does not support
resizing.
PR #2947 <https://github.com/Genymobile/scrcpy/pull/2947 >
2022-01-21 18:44:05 +01:00
Romain Vimont
75c5dc6859
Position and size the window on first frame
...
The optimal initial size was computed from the expected dimensions, sent
immediately by the server before encoding any video frame.
However, the actual frame size may be different, for example when the
device encoder does not support the requested size.
To always handle this case properly, position and size the window only
once the first frame size is known.
PR #2947 <https://github.com/Genymobile/scrcpy/pull/2947 >
2022-01-21 18:43:46 +01:00
Romain Vimont
fa30f9806a
Move "show window" call on first frame
...
Show the window only after the actual frame size is known (and if no
error has occurred).
This will allow to properly position and size the window when the size
of the first frame is different from the size initially announced by the
server.
PR #2947 <https://github.com/Genymobile/scrcpy/pull/2947 >
2022-01-21 18:42:39 +01:00
Romain Vimont
4fb61ac83d
Fix screen comments
...
The position fields accept SC_WINDOW_POSITION_UNDEFINED, not the size
fields.
PR #2947 <https://github.com/Genymobile/scrcpy/pull/2947 >
2022-01-21 18:42:39 +01:00
Romain Vimont
15bf27afdd
Make auto-downsize on error optional
...
Add --no-downsize-on-error option to disable attempts to use a lower
definition on MediaCodec error.
PR #2947 <https://github.com/Genymobile/scrcpy/pull/2947 >
2022-01-21 18:36:46 +01:00
Romain Vimont
b3ff1f6b3b
Upgrade FFmpeg (5.0) for Windows 64-bit
...
Use FFmpeg win64 binaries from gyan.dev (referenced from ffmpeg.org):
- https://www.gyan.dev/ffmpeg/builds/
- https://ffmpeg.org/download.html#build-windows
Keep the old FFmpeg prebuilt binaries (4.3.1) for win32 builds.
Fixes #1753 <https://github.com/Genymobile/scrcpy/issues/1753 >
Refs #1838 <https://github.com/Genymobile/scrcpy/pull/1838 >
Refs #2583 <https://github.com/Genymobile/scrcpy/pull/2583 >
PR #2952 <https://github.com/Genymobile/scrcpy/pull/2952 >
Co-authored-by: Yu-Chen Lin <npes87184@gmail.com>
Co-authored-by: nkh0472 <nkh0472@hotmail.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
2022-01-18 10:13:41 +01:00
Romain Vimont
a2495c5ef1
Use symlink to simplify Windows ffmpeg dependency
...
The FFmpeg dependency is downloaded from two separate zipfiles.
Symlink include/ to expose everything from a single directory, to
simplify the meson script.
PR #2952 <https://github.com/Genymobile/scrcpy/pull/2952 >
2022-01-18 10:13:38 +01:00