Commit Graph

794 Commits (9e78b765da01843b4986f93179b0c92701269062)
 

Author SHA1 Message Date
Romain Vimont d104d3bda9 Add cond_wait_timeout()
Add a "timed out" version of cond_wait().
5 years ago
Romain Vimont eda44b6068 Fix controller cleanup
After commit bfb86ca2c2, the controller
was not stopped and destroyed on quit.
5 years ago
Romain Vimont ebccb9f6cc Add runtime option to render expired frames
Replace the compilation flag SKIP_FRAMES by a runtime flag to force
rendering of expired frames. By default, the expired frames are skipped.
5 years ago
Romain Vimont a143b8b07a Indent command-line options
Prepare indentation for --render-expired-frames.
5 years ago
Romain Vimont 9253996873 Add README section explaining --turn-screen-off 5 years ago
Romain Vimont a13524e7f9 Replace android-tools-adb by adb
Here is the description of the adb package in Debian:

> Description: Android Debug Bridge
>
> A versatile command line tool that lets you communicate with an
> emulator instance or connected Android-powered device.
>
> This package recommends "android-sdk-platform-tools-common" which
> contains the udev rules for Android devices. Without this package, adb
> and fastboot need to be running with root permission.

And android-tools-adb:

> Description: transitional package
>
> This is a transitional package. It can safely be removed.
5 years ago
Romain Vimont f3f3433163
Merge pull request #574 from crow1170/patch-1
Fix dependencies
5 years ago
Chris Knowles 232aaa386e
Fix dependencies
Some missing or misspelled dependencies. Checked on Ubuntu 19.04.
5 years ago
Romain Vimont 8e66b33000 Add option to turn device screen off
In addition to the shortcut (Ctrl+o) to turn the device screen off, add
a command-line argument to turn it off on start.
5 years ago
Romain Vimont 7f07b13446 Indent command-line options
Preparse indentation for --turn-screen-off.
5 years ago
Romain Vimont acc4dcd520 Disable server controller if --no-control
If --no-control is disabled, there is no need for a controller.

It also avoids to power on the device on start if control is disabled.
5 years ago
Romain Vimont ca767ba364 Group server params in a struct
Starting the server requires more and more parameters. For clarity,
group them in a struct.
5 years ago
Romain Vimont c8a6783494 Use positive options names internally
For clarity, store the flag resulting of the command-line options
--no-control and --no-display into "control" and "display".
5 years ago
Romain Vimont 5b56900e2b Rename unused field
The flag is used only in the server_start() implementation, there is no
need to store it in the structure.
5 years ago
Romain Vimont 8c8649cfcd Remove "turn device screen on" feature
Only keep "turn device screen off" and POWER button.

After we turn the device screen off (with Ctrl+o), turning it back on
does not always work, and leaves the device in a weird state, where even
the power button may not be sufficient:
<https://github.com/Genymobile/scrcpy/issues/175#issuecomment-497946596>

This is not an acceptable behavior, so disable the shortcut to turn the
physical device screen on. We can use the POWER button (or Ctrl+p)
instead.
5 years ago
Romain Vimont e572d81fa2 Rename function to "power on"
This will reduce confusion between "power on" when the device is off and
"turn device screen off" while mirroring.
5 years ago
Romain Vimont 41225c3e41 Improve key processing readability
The condition "event->type == SDL_KEYDOWN" and the variable
input_manager->controller are used many times. Replace them by local
variables to reduce verbosity.
5 years ago
Romain Vimont 296047d82a Use net_close() to close sockets
So that it also works on Windows.
5 years ago
Romain Vimont 0792998cc2 Remove unused import
Introduced by the previous commit.
5 years ago
Romain Vimont 12a3bb25d3 Implement device screen off while mirroring
Add two shortcuts:
 - Ctrl+o to turn the device screen off while mirroring
 - Ctrl+Shift+o to turn it back on

On power on (either via the POWER key or BACK while screen is off), both
the device screen and the mirror are turned on.

<https://github.com/Genymobile/scrcpy/issues/175>
5 years ago
Romain Vimont 3ee9560ece Fix comment style
For consistency.
5 years ago
Yu-Chen Lin a56045dd80 Prevent socket leak on error
Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
5 years ago
Yu-Chen Lin fcf225049d Use consistent variable names
Use the same variable name in functions declaration and definition.

Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
5 years ago
Romain Vimont 6537c2ef01 Add clipboard logs
Synchronizing local and device clipboards in invisible. Add INFO logs
on success.
5 years ago
Romain Vimont 9712cb8123 Do not minimize on focus loss
The default behavior seems annoying.

Fixes <https://github.com/Genymobile/scrcpy/issues/554>
5 years ago
Romain Vimont ad55a9addc Prefix server logs
Sometimes, it is not obvious whether a log is generated by the server or
by the client. Prefix server logs for clarity.
5 years ago
Romain Vimont 28980bbc90 Rename "event" to "message"
After the recent refactorings, a "control event" is not necessarily an
"event" (it may be a "command"). Similarly, the unique "device event"
used to send the device clipboard content is more a "reponse" to the
request from the client than an "event".

Rename both to "message", and rename the message types to better
describe their intent.
5 years ago
Romain Vimont f710d76c9e
Merge pull request #568 from npes87184/dev
Correct return value type in handle_event
5 years ago
Yu-Chen Lin 2a8a3e6ed5 Correct return value type in handle_event
handle_event return the type enum event_result not bool

Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
5 years ago
Yu-Chen Lin c2cef8d501 server/meson.build: Prevent using input field for directory
This will fix build warning in newer meson.
Fix #540.

Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
5 years ago
Romain Vimont 0125af1e46 Update DEVELOP after recent refactorings 5 years ago
Romain Vimont c13a24389c Implement computer-to-device clipboard copy
It was already possible to _paste_ (with Ctrl+v) the content of the
computer clipboard on the device. Technically, it injects a sequence of
events to generate the text.

Add a new feature (Ctrl+Shift+v) to copy to the device clipboard
instead, without injecting the content. Contrary to events injection,
this preserves the UTF-8 content exactly, so the text is not broken by
special characters.

<https://github.com/Genymobile/scrcpy/issues/413>
5 years ago
Romain Vimont 2322069656 Extract control event String parsing
Parsing a String from a serialized control event, encoded as length (2
bytes) + data, will be necessary in several events.

Extract it to a separate method.
5 years ago
Romain Vimont 61f5f96b42 Fix control event String parsing
At least 2 bytes must be available to read the length of the String.
5 years ago
Romain Vimont 63c078ee6c Implement device-to-computer clipboard copy
On Ctrl+C:
 - the client sends a GET_CLIPBOARD command to the device;
 - the device retrieve its current clipboard text and sends it in a
   GET_CLIPBOARD device event;
 - the client sets this text as the system clipboard text, so that it
   can be pasted in another application.

Fixes <https://github.com/Genymobile/scrcpy/issues/145>
5 years ago
Romain Vimont 3149e2cf4a Add device event sender
Create a separate component to send device events, managed by the
controller.
5 years ago
Romain Vimont 6112095e75 Add device event receiver
Create a separate component to handle device events, managed by the
controller.
5 years ago
Romain Vimont f9d2d99166 Add GET_CLIPBOARD device event
Add the first device event, used to forward the device clipboard to the
computer.
5 years ago
Romain Vimont ec71a3f66a Use two sockets for video and control
The socket used the device-to-computer direction to stream the video and
the computer-to-device direction to send control events.

Some features, like copy-paste from device to computer, require to send
non-video data from the device to the computer.

To make them possible, use two sockets:
 - one for streaming the video from the device to the client;
 - one for control/events in both directions.
5 years ago
Romain Vimont 69360c7407 Extract control event string serialization
A string is serialized as a length (2 bytes) followed by the string data
(non nul-terminated).

For now, it is used only once, but we will need to serialize strings in
other events.
5 years ago
Romain Vimont 6ec2ddd2d1 Truncate UTF-8 properly
This will avoid to produce invalid UTF-8 results (although unlikely).
5 years ago
Romain Vimont 0a7fe7ad57 Add helpers to truncate UTF-8 at code points
This will help to avoid truncating a UTF-8 string in the middle of a
code point, producing an invalid UTF-8 result.
5 years ago
Romain Vimont 3aa5426cad Add unit tests for control events serialization
Add missing tests for serialization and deserialization of control
events.
5 years ago
Romain Vimont 63207d9cd5 Fix wrong comment in unit test 5 years ago
Romain Vimont ad4c061cd2 Use custom class Point
The framework class android.graphics.Point cannot be used in unit tests.
Implement our own Point.
5 years ago
Romain Vimont 63909fd10d Merge commands with other control events
Several commands were grouped under the same event type "command", with
a separate field to indicate the actual command.

Move these commands at the same level as other control events. It will
allow to implement commands with arguments.
5 years ago
Romain Vimont 3b4366e5bf Stop stream immediately on quit
If the stream is stopped, av_read_frame() will be woken up and yield a
corrupted packet. Do not try to decode or record it.
5 years ago
Romain Vimont 47f1003200 Close server socket before killing process
The sockets may be closed and shutdown on server_stop(). This will
interrupt the stream and controller threads more quickly and gracefully.
5 years ago
Romain Vimont bfb86ca2c2 Simplify cleanup
The cleanup is not linear: for example, the server must be stopped and
its sockets must be shutdown after the stream and controller are stopped
(so that they don't continue processing garbage), but before they are
joined, to avoid a deadlock if they are blocked on a socket read.

Simplify the spaghetti-cleanup by keeping trace of initialization at
runtime.
5 years ago
Romain Vimont 0dee9b04b2 Use net_recv() to read only one byte
Partial read is impossible for 1 byte, so net_recv_all() is useless.
5 years ago