Commit Graph

2393 Commits (uhid.38)
 

Author SHA1 Message Date
Romain Vimont b9bb4ff740 Merge branch 'sdushantha' (pull request #28)
Improve README syntax highlighting.
6 years ago
Romain Vimont cc4a015256 Add empty lines around code blocks
And fix spaces (do not randomly use non-breaking spaces for
indentation).
6 years ago
Siddharth Dushantha 8476b4aab8
removed "$" and changed Mac OS ---> MacOS 6 years ago
Siddharth Dushantha a1491862e4
added "$" in front of terminal commands 6 years ago
Romain Vimont c87d94ee27 Map middle-click to HOME
Middle-click is useless in practice. Use it for HOME.
6 years ago
Romain Vimont 675704c71c Map right-click to BACK if screen is on
Right-click was used to turn the screen on. It did nothing when the
screen was already on.

Instead, in that case, press BACK (like Vysor).

Suggested by: <https://www.reddit.com/r/Android/comments/834zmr/introducing_scrcpy_an_app_to_display_and_control/dvfueft/>
6 years ago
Romain Vimont 9396ea6d42 Fix text input event segfault
The text input control_event was initially designed for mapping
SDL_TextInputEvent, limited to 32 characters.

For simplicity, the copy/paste feature was implemented using the same
control_event: it just sends the text to paste.

However, the pasted text might have a length breaking some assumptions:
 - on the client, the event max-size was smaller than the text
   max-length,
 - on the server, the raw buffer storing the events was smaller than the
   max event size.

Fix these inconsistencies, and encode the length on 2 bytes, to accept
more than 256 characters.

Fixes <https://github.com/Genymobile/scrcpy/issues/10>.
6 years ago
Romain Vimont f9562f537a Unref the packet on error
Do not leak the packet data on error.
6 years ago
Romain Vimont a34fbd23e9 Do not leak the packet data
Oops! The content of the packets were never freed.
6 years ago
Romain Vimont e8b8a570e7 Document ./run script usage
Indicate how to run the app from the build directory in README. It's
convenient during development.
6 years ago
Romain Vimont 0e9a76c0c4 Add link to blog article in README 6 years ago
Romain Vimont f9f305d19d Update release checksums in README 6 years ago
Romain Vimont 727d1ef1e2 Add developer documentation
And update README.
6 years ago
Romain Vimont c2ac6fe7bd Upgrade version to 1.0 6 years ago
Romain Vimont e2a7abcd53 Implement clipboard paste
Paste computer clipboard to the device on Ctrl+v.

The other direction (pasting the device clipboard to the computer) is
not implemented. It would require a communication channel from the
device to the computer, other than the socket used by the video stream.
6 years ago
Romain Vimont e4d64e8752 Initialize struct field by field
Initializing with braces initializes the other fields to 0, which is not
necessary.
6 years ago
Romain Vimont fffeedffda Expose High DPI support configuration flag
The High DPI support is enabled by default, so that the renderer use the
full definition of High DPI screens.

However, there are still mouse coordinates problems on some MacOS having
High DPI support (but not all), so expose a way to disable it.
6 years ago
Romain Vimont 82b4acee73 Do not fail on EAGAIN
A call to avcodec_receive_frame() may return AVERROR(EAGAIN) if more
input is required. This is not an error, do not fail.
6 years ago
Romain Vimont 633b18d786 Provide a better URL to document key decomposition
Directly link to the relevant subsection.
6 years ago
Romain Vimont ab780ce26d Avoid useless variables initialization
Initialize variables only when necessary.
6 years ago
Romain Vimont 84ad6633a6 Move the new avcodec implementation before the old
The API to decode the video frames is different depending on the
libavcodec version.

Move the new API usage to the #if-block.
6 years ago
Romain Vimont 1b0cea61a5 Do not use return code for thread run function
The decoder sometimes returned a non-zero value on error, but not on
every path.

Since we never use the value, always return 0 at the end (like in the
controller).
6 years ago
Romain Vimont 42f6341a14 Revert "Enable high dpi support"
Just enabling this flag breaks mouse location values.

This reverts commit 38b56f552e.
6 years ago
Romain Vimont acd2dc3183 Shutdown sockets before closing
The server socket does not release the port it was listening for if we
just close it: we must also shutdown it.
6 years ago
Romain Vimont db396f2138 Fix scroll wheel mouse position
SDL_MouseWheelEvent does not provide the mouse location, so we used
SDL_GetMouseState() to retrieve it.

Unfortunately, SDL_GetMouseState() returns a position expressed in the
window coordinate system while the position filled in SDL events are
expressed in the renderer coordinate system. As a consequence, the
scroll was not applied at the right position on the device.

Therefore, convert the coordinate system.

See <https://stackoverflow.com/questions/49111054/how-to-get-mouse-position-on-mouse-wheel-event>.
6 years ago
Romain Vimont e6feb991db Fix comment typo
Replace "at network level" by "at the network level".
6 years ago
Romain Vimont e3f5d3b49b Double the default bitrate
Set the default video bitrate to 8Mbps. This greatly increase quality on
fast motion, without negative side effects.
6 years ago
Romain Vimont a7979e4e74 Rename rotation detection method name
The old name checkRotationChanged() did not suggest that the flag was
reset.
6 years ago
Romain Vimont 38b56f552e Enable high dpi support
Use high DPI if available.

Note that on Mac OS X, setting this flag is not sufficient:

> On Apple's OS X you must set the NSHighResolutionCapable Info.plist
> property to YES, otherwise you will not receive a High DPI OpenGL
> display.

<https://wiki.libsdl.org/SDL_CreateWindow#flags>
6 years ago
Romain Vimont 8ace3d1781 Update README
Explain how to build, install and run the application.
6 years ago
Romain Vimont bae8263cdd Add Apache 2 LICENSE file 6 years ago
Romain Vimont c78ad6377c Terminate the server on stop
On user request to quit, two kinds of blocking calls must be interrupted
on the server:
 1. the reads from and writes to the socket;
 2. the call to MediaCodec.dequeueOutputBuffer().

The former case was handled by calling shutdown() on the socket from the
client, but the latter was not managed.

There is no easy way to wake this call properly, so just terminate the
process from the client (i.e. send SIGTERM on Linux) instead.
6 years ago
Romain Vimont b61310a257 Initialize eof flag from BufferInfo
Stop encoding if the codec signaled the end of stream.

The eof flag was read, but never written.
6 years ago
Romain Vimont 221a7d0826 Clean up the server from temporary folder
The server is copied to /data/local/tmp/scrcpy-server.jar and executed
on the device.

As soon as we are connected, we can unlink (rm) it from /data/local/tmp,
to keep the device clean.
6 years ago
Romain Vimont 08d32e3bae Clean up useless const-casts
The function adb_execute() now expects a "const char *const *" parameter
for the adb command, so there is no need to cast.
6 years ago
Romain Vimont 487cb10cf0 Rename ScrCpyServer to Server
The Server class is in package scrcpy, there is no need to repeat the
name in the classname.
6 years ago
Romain Vimont 0d050d83b4 Add missing .PHONY in portable Makefile
The recipe "build-portable" is also the name of the generated directory.
Add this name to the .PHONY list.
6 years ago
Romain Vimont 089378926b Rename SCRCPY_SERVER_JAR to SCRCPY_SERVER_PATH
The server is currently a JAR, but it may ba an APK or a DEX, so the
variable name should not contain the type.

Rename the environment variable, the Meson options and the C
definitions.
6 years ago
Romain Vimont 60f3185185 Reuse server address
Set SO_REUSEADDR flag to server socket, so that bind() does not fail if
we restart scrcpy immediately after we closed the previous one.
6 years ago
Romain Vimont 6db22ef339 Log socket errors
Do not silently ignore close() and shutdown() errors, and use perror()
to get the errno.
6 years ago
Romain Vimont 37af0c8076 Terminate event controller thread on EOF
No exception was thrown on EOF, so the event controller did not
terminate. This leaded to a further InvocationTargetException.

Instead, terminate the event controller on EOF, so that the process
terminates properly.
6 years ago
Romain Vimont ad6209f6ff Terminate the device process gracefully
Call shutdown() on the device socket to make the device process finish
its execution quickly and gracefully, without killing it.
6 years ago
Romain Vimont a791c272bc Send and recv all data when necessary
Expose net_recv_all() and net_send_all(), equivalent of net_recv() and
net_send(), but that waits/retries until the requested length has been
transferred.

Use these new functions where it was (wrongly) assumed that the
requested length had been transferred.
6 years ago
Romain Vimont d646f95a31 Avoid division by 0
If the frame_size width or height is 0, just return the current size to
avoid calculations involving divison by 0.
6 years ago
Romain Vimont 27b9159b07 Cleanup old code comment 6 years ago
Romain Vimont cf59d49d25 Detect failure of device information read
If the received data is smaller than the device information size, then
something is wrong.
6 years ago
Romain Vimont 9b056f5091 Replace SDL_net by custom implementation
SDL_net is not very suitable for scrcpy.

For example, SDLNet_TCP_Accept() is non-blocking, so we have to wrap it
by calling many SDL_Net-specific functions to make it blocking.

But above all, SDLNet_TCP_Open() is a server socket only when no IP is
provided; otherwise, it's a client socket. Therefore, it is not possible
to create a server socket bound to localhost, so it accepts connections
from anywhere.

This is a problem for scrcpy, because on start, the application listens
for nearly 1 second until it accepts the first connection, supposedly
from the device. If someone on the local network manages to connect to
the server socket first, then they can stream arbitrary H.264 video.
This may be troublesome, for example during a public presentation ;-)

Provide our own simplified API (net.h) instead, implemented for the
different platforms.
6 years ago
Romain Vimont bf41e5479b Improve decoder stopped event
The syntax was correct, but less readable, and it unnecessarily zeroed
the fields other than "type".

Create the event properly, from a separate method.
6 years ago
Romain Vimont 518d6d5dcd Prevent new window opening with CreateProcess()
Executing commands (like "adb push") created a new terminal window on
Windows. Avoid it.
6 years ago
Romain Vimont e8cad790a4 Reword Ctrl+x description
Pressing Ctrl+x resizes the window to remove black borders, "optimal" is
not well-defined.
6 years ago