Romain Vimont
6fd7e89da1
Explicitly initialize decoder sink_count
...
The zero-initialization relied on the fact that the decoder instance is
static.
2021-05-28 21:23:18 +02:00
Romain Vimont
4c31911df2
Pass serial within struct server_params
...
This was the only option passed separately.
2021-05-28 21:21:54 +02:00
Romain Vimont
6adc97198b
Provide device info directly on server connection
...
This avoids to retrieve them in a separate step.
2021-05-17 08:52:08 +02:00
Romain Vimont
6a2cd089a1
Initialize input manager dynamically
...
The input manager was partially initialized statically, but a call to
input_manager_init() was needed anyway, so initialize all the fields
from the "constructor".
This is consistent with the initialization of the other structs.
2021-05-17 08:48:51 +02:00
Romain Vimont
dcee7c0f7f
Factorize screen_init() error management
2021-05-16 18:48:04 +02:00
Romain Vimont
e604e8a752
Move fps_counter to screen
...
The FPS counter specifically count frames from the screen video buffer,
so it is specific to the screen.
2021-05-16 18:47:16 +02:00
Romain Vimont
f19c455110
Fix leak on error
...
Destroy video buffer if screen window creation failed.
2021-05-16 18:46:47 +02:00
Romain Vimont
83116fc199
Notify end-of-stream via callback
...
Do not send a SDL event directly, to make stream independent of SDL.
2021-05-16 15:48:07 +02:00
Romain Vimont
1e64f0f931
Use ARRAY_LEN() macro
2021-05-09 11:06:02 +02:00
Romain Vimont
8fb5715740
Add libavdevice-dev in BUILD instructions
...
On Linux, scrcpy now depends on libavdevice for v4l2.
2021-05-09 11:01:16 +02:00
Romain Vimont
f062dfd30b
Merge branch 'master' into dev
2021-05-09 11:00:30 +02:00
Romain Vimont
1b9dcce23c
Fix double-free on error
...
On error, server->serial was freed twice: immediately and in
server_destroy().
Refs #2292 <https://github.com/Genymobile/scrcpy/issues/2292#issuecomment-831424820 >
2021-05-03 20:43:45 +02:00
Romain Vimont
233f8e6cc4
Rename keycode injection method
...
Make it explicit that it injects both "press" and "release" events.
2021-04-30 23:07:37 +02:00
Romain Vimont
9a7d351d67
Simplify non-static injectEvent() implementation
...
Just call the static version (having a displayId) from the non-static
version (using the displayId field).
2021-04-30 23:07:37 +02:00
Romain Vimont
d00ee640c0
Simplify Device.java
...
Remove useless intermediate method with a "mode" parameter (it's always
called with the same mode).
This also avoids the need for a specific injectEventOnDisplay() method,
since it does not conflict with another injectEvent() method anymore.
2021-04-30 23:07:29 +02:00
Romain Vimont
ae6ec7a194
Unref decoder AVFrame immediately
...
The frame can be unref immediately after it is pushed to the frame
sinks.
It was not really a memory leak because the frame was unref every time
by avcodec_receive_frame() (and freed on close), but a reference was
unnecessarily kept for too long.
2021-04-26 18:05:43 +02:00
Romain Vimont
84f17fdeab
Fix v4l2 AVPacket memory leak on error
...
Unref v4l2 AVPacket even if writing failed.
2021-04-26 18:05:11 +02:00
Romain Vimont
1cde68a1fa
Fix v4l2 AVFrame memory leak
...
Unref frame immediately once encoded.
Fixes #2279 <https://github.com/Genymobile/scrcpy/pull/2279 >
2021-04-26 18:04:51 +02:00
Romain Vimont
45e7280148
Rename --v4l2_sink to --v4l2-sink
...
This was a rebase issue, the previous version in #2268 was correct.
Refs #2268 <https://github.com/Genymobile/scrcpy/pull/2268 >
2021-04-26 17:59:35 +02:00
Romain Vimont
41a0383d7c
Document v4l2 sink in README
2021-04-25 15:00:56 +02:00
Romain Vimont
5af9d0ee0f
Make --lock-video-orientation argument optional
...
If the option is set without argument, lock the initial device
orientation (as if the value "initial" was passed).
2021-04-25 14:55:54 +02:00
Romain Vimont
fd0dc6c0cd
Add --lock-video-orientation=initial
...
Add a new mode to the --lock-video-orientation option, to lock the
initial orientation of the device.
This avoids to pass an explicit value (0, 1, 2 or 3) and think about
which is the right one.
2021-04-25 14:55:54 +02:00
Romain Vimont
151bc16644
Use strlist_contains() to find a muxer
...
The AVOutputFormat name is a string list: it contains names separated by
',' (possibly only one).
2021-04-25 14:55:19 +02:00
Romain Vimont
ffc00210e9
Add strlist_contains()
...
Add a function to know if a string list, using some separator, contains
a specific string.
2021-04-25 14:38:42 +02:00
Romain Vimont
243854a408
Fix recorder comment
2021-04-25 14:38:42 +02:00
Romain Vimont
8b90dc61b9
Handle EAGAIN on send_packet in decoder
...
EAGAIN was only handled on receive_frame.
In practice, it should not be necessary, since one packet always
contains one frame. But just in case.
2021-04-25 14:38:42 +02:00
Romain Vimont
2a5dfc1c17
Handle errors using gotos in recorder_open()
...
There are many initializations in recorder_open(). Handle RAII-like
deinitialization using gotos.
2021-04-25 14:38:42 +02:00
Romain Vimont
e3fccc5a5e
Initialize recorder fields on open
...
Only initialize ops and parameters copy from recorder_init(). It was
inconsistent to initialize some fields from _init() and some others from
_open().
2021-04-25 14:38:42 +02:00
Romain Vimont
0541f1bff2
Hide the window immediately on close
...
The screen may not be destroyed immediately on close to avoid undefined
behavior, because it may still receive events from the decoder.
But the visual window must still be closed immediately.
2021-04-25 14:38:42 +02:00
Romain Vimont
0272e6dc77
Assert screen closed on destroy
...
The destruction order is important, but tricky, because the screen is
open/close by the decoder, but destroyed by scrcpy.c on the main thread.
Add assertions to guarantee that the screen is not destroyed before
being closed.
2021-04-25 14:38:42 +02:00
Romain Vimont
2a94a2b119
Remove video_buffer callbacks
...
Now that screen is both the owner and the listener of the video buffer,
execute the code directly without callbacks.
2021-04-25 14:38:42 +02:00
Romain Vimont
e91acdb0c4
Move video_buffer to screen
...
The video buffer is now an internal detail of the screen component.
Since the screen is plugged to the decoder via the frame sink trait, the
decoder does not access to the video buffer anymore.
2021-04-25 14:38:42 +02:00
Romain Vimont
6f5ad21f57
Make decoder push frames to sinks
...
Now that screen implements the packet sink trait, make decoder push
packets to the sinks without depending on the concrete sink types.
2021-04-25 14:38:42 +02:00
Romain Vimont
08b3086ffc
Expose screen as frame sink
...
Make screen implement the frame sink trait.
This will allow the decoder to push frames without depending on the
concrete sink type.
2021-04-25 14:38:42 +02:00
Romain Vimont
deab7da761
Add frame sink trait
...
This trait will allow to abstract the concrete sink types from the frame
producer (decoder.c).
2021-04-25 14:38:42 +02:00
Romain Vimont
f7a1b67d66
Make stream push packets to sinks
...
Now that decoder and recorder implement the packet sink trait, make
stream push packets to the sinks without depending on the concrete sink
types.
2021-04-25 14:38:42 +02:00
Romain Vimont
cbed38799e
Expose decoder as packet sink
...
Make decoder implement the packet sink trait.
This will allow the stream to push packets without depending on the
concrete sink type.
2021-04-25 14:38:42 +02:00
Romain Vimont
5beb7d6c02
Reorder decoder functions
...
This will make further commits more readable.
2021-04-25 14:38:42 +02:00
Romain Vimont
5980183a33
Expose recorder as packet sink
...
Make recorder implement the packet sink trait.
This will allow the stream to push packets without depending on the
concrete sink type.
2021-04-25 14:38:42 +02:00
Romain Vimont
fe8de893ca
Privatize recorder threading
...
The fact that the recorder uses a separate thread is an internal detail,
so the functions _start(), _stop() and _join() should not be exposed.
Instead, start the thread on _open() and _stop()+_join() on close().
This paves the way to expose the recorder as a packet sink trait.
2021-04-25 14:38:42 +02:00
Romain Vimont
a974483c15
Reorder recorder functions
...
This will make further commits more readable.
2021-04-25 14:38:42 +02:00
Romain Vimont
1b072a24c4
Add packet sink trait
...
This trait will allow to abstract the concrete sink types from the
packet producer (stream.c).
2021-04-25 14:38:42 +02:00
Romain Vimont
08f1fd46c8
Add container_of() macro
...
This will allow to get the parent of an embedded struct.
2021-04-25 14:38:42 +02:00
Romain Vimont
2ddf760c09
Make video_buffer more generic
...
The video buffer took ownership of the producer frame (so that it could
swap frames quickly).
In order to support multiple sinks plugged to the decoder, the decoded
frame must not be consumed by the display video buffer.
Therefore, move the producer and consumer frames out of the video
buffer, and use FFmpeg AVFrame refcounting to share ownership while
avoiding copies.
2021-04-25 14:38:42 +02:00
Romain Vimont
5d9e96dc4e
Remove compat with old FFmpeg codec params API
...
The new API has been introduced in 2016 in libavformat 57.xx, it's very
old.
This will avoid to maintain two code paths for codec parameters.
2021-04-25 14:38:42 +02:00
Romain Vimont
de9b79ec2d
Remove compat with old FFmpeg decoding API
...
The new API has been introduced in 2016 in libavcodec 57.xx, it's very
old.
This will avoid to maintain two code paths for decoding.
2021-04-25 14:38:42 +02:00
Romain Vimont
55806e7d31
Remove option --render-expired-frames
...
This flag forced the decoder to wait for the previous frame to be
consumed by the display.
It was initially implemented as a compilation flag for testing, not
intended to be exposed at runtime. But to remove ifdefs and to allow
users to test this flag easily, it had finally been exposed by commit
ebccb9f6cc .
In practice, it turned out to be useless: it had no practical impact,
and it did not solve or mitigate any performance issues causing frame
skipping.
But that added some complexity to the codebase: it required an
additional condition variable, and made video buffer calls possibly
blocking, which in turn required code to interrupt it on exit.
To prepare support for multiple sinks plugged to the decoder (display
and v4l2 for example), the blocking call used for pacing the decoder
output becomes unacceptable, so just remove this useless "feature".
2021-04-25 14:38:42 +02:00
Romain Vimont
21b590b766
Write trailer from recorder thread
...
The recorder thread wrote the whole content except the trailer, which
was odd.
2021-04-25 14:38:42 +02:00
Romain Vimont
bb4614d558
Reverse boolean logic for readability
...
Refs #2260 <https://github.com/Genymobile/scrcpy/pull/2260#issuecomment-823508759 >
2021-04-25 14:36:48 +02:00
Romain Vimont
d0739911a3
Forward DOWN and UP separately for right-click
...
The shortcut "back on screen on" is a bit special: the control is
requested by the client, but the actual event injection (POWER or BACK)
is determined on the device.
To properly inject DOWN and UP events for BACK, transmit the action as
a control parameter.
If the screen is off:
- on DOWN, inject POWER (DOWN and UP) (wake up the device immediately)
- on UP, do nothing
If the screen is on:
- on DOWN, inject BACK DOWN
- on UP, inject BACK UP
A corner case is when the screen turns off between the DOWN and UP
event. In that case, a BACK UP event will be injected, so it's harmless.
As a consequence of this change, the BACK button is now handled by
Android on mouse released. This is consistent with the keyboard shortcut
(Mod+b) behavior.
PR #2259 <https://github.com/Genymobile/scrcpy/pull/2259 >
Refs #2258 <https://github.com/Genymobile/scrcpy/pull/2258 >
2021-04-19 20:16:45 +02:00
Romain Vimont
964b6d2243
Forward DOWN and UP separately for middle-click
...
As a consequence of this change, the HOME button is now handled by
Android on mouse released. This is consistent with the keyboard shortcut
(MOD+h) behavior.
PR #2259 <https://github.com/Genymobile/scrcpy/pull/2259 >
Refs #2258 <https://github.com/Genymobile/scrcpy/pull/2258 >
2021-04-17 18:04:24 +02:00
Romain Vimont
8cc057c8f1
Prevent forwarding only "mouse released" events
...
Some mouse clicks DOWN are captured for shortcuts, but the matching UP
events were still forwarded to the device.
Instead, capture both DOWN and UP for shortcuts, and do nothing on UP.
PR #2259 <https://github.com/Genymobile/scrcpy/pull/2259 >
Refs #2258 <https://github.com/Genymobile/scrcpy/pull/2258 >
2021-04-17 18:04:13 +02:00
Romain Vimont
edee69d637
Fix options alphabetical order
...
"verbosity" < "version"
2021-04-16 17:40:39 +02:00
Romain Vimont
8ef4c044fa
Do not forward SDL_DROPFILE event
...
The event is handled by scrcpy.c, it is not necessary to send it to
screen or input_manager.
2021-04-13 22:37:08 +02:00
Romain Vimont
c23c38f99d
Move resizing workaround to screen.c
2021-04-13 22:36:59 +02:00
Romain Vimont
65c4f487b3
Set initial fullscreen from screen.c
2021-04-13 22:15:05 +02:00
Romain Vimont
c6d7f5ee96
Make screen_show_window() static
...
It is only used from screen.c now.
2021-04-13 22:04:38 +02:00
Romain Vimont
28f6cbaea6
Destroy screen once stream is finished
...
The screen receives callbacks from the decoder, fed by the stream.
The decoder is run from the stream thread, so waiting for the end of
stream is sufficient to avoid possible use-after-destroy.
2021-04-11 14:42:09 +02:00
Romain Vimont
08fc6694e1
Do not destroy uninitialized screen
...
When --no-display was passed, screen_destroy() was called while
screen_init() was never called.
In practice, it did not crash because it just freed NULL pointers, but
it was still incorrect.
2021-04-11 13:07:44 +02:00
Romain Vimont
d0983db592
Make internal recorder function static
2021-04-10 18:48:52 +02:00
Romain Vimont
fb7870500a
Remove unused field from input_manager
2021-04-10 18:48:52 +02:00
Romain Vimont
33006561c7
Remove useless forward declaration from stream.h
2021-04-10 18:48:52 +02:00
Romain Vimont
a09733d175
Remove useless includes from decoder.c
2021-04-10 18:48:44 +02:00
Romain Vimont
07a85b7c94
Fix typo in command-line help
...
Refs #2237 <https://github.com/Genymobile/scrcpy/issues/2237 >
2021-04-07 15:12:33 +02:00
Romain Vimont
6231f683af
Fix compilation error for old decoding API
...
Commits cb9c42bdcb and
441d3fb119 updated the code only for the
new decoding API.
2021-04-05 22:35:14 +02:00
Romain Vimont
9826c5c4a4
Remove HiDPI compilation flag
...
Always enable HiDPI support, there is no reason to expose a compilation
flag.
2021-04-04 15:00:13 +02:00
Romain Vimont
2812de8a9a
Update brew java version to JDK 11
...
Refs f8524a2be7
Refs 7b51a0313e
2021-04-04 14:39:16 +02:00
Romain Vimont
b77932a5b7
Add instructions to uninstall
2021-04-01 09:47:15 +02:00
Romain Vimont
47d16a57ac
Add simplified installation script
...
Add a script to download the server and build scrcpy using the
prebuilt server.
2021-03-29 09:33:39 +02:00
Romain Vimont
fda293f9bb
Fix BUILD.md line wrapping
2021-03-29 09:11:40 +02:00
Romain Vimont
38f392f08f
Fix typo in BUILD.md
2021-03-29 08:39:02 +02:00
Romain Vimont
8414b688f0
Link release to main README in translations
...
This avoids to link an older version.
2021-03-28 21:36:00 +02:00
Romain Vimont
3a4b10a38d
Improve --push-target example in README
...
A common use case for the --push-target option is to pass the device
Download directory.
2021-03-28 12:25:08 +02:00
Romain Vimont
1fb7957525
Fix typo in README
...
Refs <https://github.com/Genymobile/scrcpy/pull/2195#discussion_r595664697 >
2021-03-17 08:52:16 +01:00
Romain Vimont
19ad107f1f
Add "Get the app" summary section
...
Give quick instructions to download/install scrcpy.
2021-03-16 21:43:52 +01:00
Romain Vimont
0308ef43f2
Do not set buttons on touch events
...
BUTTON_PRIMARY must not be set for touch events:
> This button constant is not set in response to simple touches with a
> finger or stylus tip. The user must actually push a button.
<https://developer.android.com/reference/android/view/MotionEvent#BUTTON_PRIMARY >
Fixes #2169 <https://github.com/Genymobile/scrcpy/issues/2169 >
2021-03-15 18:46:56 +01:00
Romain Vimont
40febf4a91
Use device id 0 for touch/mouse events
...
Virtual device is only for keyboard sources, not mouse or touchscreen
sources. Here is the value of InputDevice.getDevice(-1).toString():
Input Device -1: Virtual
Descriptor: ...
Generation: 2
Location: built-in
Keyboard Type: alphabetic
Has Vibrator: false
Has mic: false
Sources: 0x301 ( keyboard dpad )
InputDevice.getDeviceId() documentation says:
> An id of zero indicates that the event didn't come from a physical
> device and maps to the default keymap.
<https://developer.android.com/reference/android/view/InputEvent#getDeviceId() >
However, injecting events with a device id of 0 causes event.getDevice()
to be null on the client-side.
Commit 26529d377f used -1 as a workaround
to avoid a NPE on a specific Android TV device. But this is a bug in the
device system, which wrongly assumes that input device may not be null.
A similar issue was present in Flutter, but it is now fixed:
- <https://github.com/flutter/flutter/issues/30665 >
- <https://github.com/flutter/engine/pull/7986 >
On the other hand, using an id of -1 for touchscreen events (which is
invalid) causes issues for some apps:
<https://github.com/Genymobile/scrcpy/issues/2125#issuecomment-790535792 >
Therefore, use a device id of 0.
An alternative could be to find an existing device matching the source,
like "adb shell input" does. See getInputDeviceId():
<https://android.googlesource.com/platform/frameworks/base.git/+/master/cmds/input/src/com/android/commands/input/Input.java >
But it seems better to indicate that the event didn't come from a
physical device, and it would not solve #962 anyway, because an Android
TV has no touchscreen.
Refs #962 <https://github.com/Genymobile/scrcpy/issues/962 >
Fixes #2125 <https://github.com/Genymobile/scrcpy/issues/2125 >
2021-03-14 18:30:56 +01:00
Romain Vimont
429fdef04f
Fix encoder parameter suggestion
...
The option is --encoder, not --encoder-name.
2021-03-11 10:55:12 +01:00
Romain Vimont
eb7e1070cf
Release frame data as soon as possible
...
During a frame swap, one of the two frames involved can be released.
2021-03-06 22:58:03 +01:00
Romain Vimont
386f017ba9
Factorize frame swap
2021-03-06 22:58:03 +01:00
Romain Vimont
cc48b24324
Simplify screen initialization
...
Use a single function to initialize the screen instance.
2021-03-06 22:58:03 +01:00
Romain Vimont
597c54f049
Group screen parameters into a struct
...
The function screen_init_rendering had too many parameters.
2021-03-06 22:58:03 +01:00
Romain Vimont
955da3b578
Remove screen static initializer
...
Most of the fields are initialized dynamically.
2021-03-06 22:58:03 +01:00
Romain Vimont
cb9c42bdcb
Use a callback to notify frame skip
...
A skipped frame is detected when the producer offers a frame while the
current pending frame has not been consumed.
However, the producer (in practice the decoder) is not interested in the
fact that a frame has been skipped, only the consumer (the renderer) is.
Therefore, notify frame skip via a consumer callback. This allows to
manage the skipped and rendered frames count at the same place, and
remove fps_counter from decoder.
2021-03-06 22:58:03 +01:00
Romain Vimont
fb9f9848bd
Use a callback to notify a new frame
...
Make the decoder independant of the SDL even mechanism, by making the
consumer register a callback on the video_buffer.
2021-03-06 22:58:03 +01:00
Romain Vimont
c50b958ee4
Initialize screen before starting the stream
...
As soon as the stream is started, the video buffer could notify a new
frame available.
In order to pass this event to the screen without race condition, the
screen must be initialized before the screen is started.
2021-03-06 22:58:03 +01:00
Romain Vimont
441d3fb119
Make video buffer more generic
...
Video buffer is a tool between a frame producer and a frame consumer.
For now, it is used between a decoder and a renderer, but in the future
another instance might be used to swscale decoded frames.
2021-03-06 22:58:03 +01:00
Romain Vimont
cb197ee3a2
Move fps counter out of video buffer
...
In order to make video buffer more generic, move out its specific
responsibility to count the fps between the decoder and the renderer.
2021-03-06 22:58:03 +01:00
Romain Vimont
dca11f6c51
Remove obsolete FAQ entry
...
Issue #15 had been fixed in v1.14 by
e40532a376 .
2021-03-06 14:28:06 +01:00
Romain Vimont
08baaf4b57
Mention adb debugging in FAQ
2021-03-04 15:19:00 +01:00
Romain Vimont
218636dc10
Inject touch events with smallest detectable size
...
A value of 1 means the "largest detectable size", a value of 0 means the
"smallest detectable size".
https://developer.android.com/reference/android/view/MotionEvent.PointerCoords#size
https://developer.android.com/reference/android/view/MotionEvent#AXIS_SIZE
Fixes #2125 <https://github.com/Genymobile/scrcpy/issues/2125 >
2021-03-03 18:22:54 +01:00
Romain Vimont
7b51a0313e
Update another java version in BUILD.md
...
Commit f8524a2be7 updated one reference to
the openjdk package, but there was another one.
2021-02-27 00:27:58 +01:00
Romain Vimont
a2919b3ef2
Fix release instructions in BUILD.md
...
Makefile.CrossWindows have been renamed to release.mk, which is called
from release.sh.
2021-02-27 00:20:18 +01:00
Romain Vimont
b16b65a715
Simplify default values
...
It makes sense to extract default values for bitrate and port range
(which are arbitrary and might be changed in the future).
However, the default values for "max size" and "lock video orientation"
are naturally unlimited/unlocked, and will never be changed. Extracting
these options just added complexity for no benefit, so hardcode them.
2021-02-25 22:19:05 +01:00
Romain Vimont
a3aa5ac95e
Insert numerical values statically in usage string
2021-02-25 22:19:05 +01:00
Romain Vimont
0207e3df33
Remove unused no_window field
2021-02-25 22:19:05 +01:00
Romain Vimont
9cd1a7380d
Enable NDEBUG via Meson built-in option
2021-02-25 22:19:05 +01:00
Romain Vimont
24b637b972
Handle im-related events from input_manager.c
2021-02-25 22:19:05 +01:00
Romain Vimont
76a3d9805b
Inline window events handling
...
Now that all screen-related events are handled from screen.c, there is
no need for a separate method for window events.
2021-02-25 22:19:05 +01:00
Romain Vimont
50b4a730e3
Handle screen-related events from screen.c
2021-02-25 22:19:05 +01:00