2019-05-31 20:55:11 +08:00
|
|
|
#ifndef CONTROLLER_H
|
|
|
|
#define CONTROLLER_H
|
2017-12-14 18:38:44 +08:00
|
|
|
|
2021-01-09 02:24:51 +08:00
|
|
|
#include "common.h"
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
#include <stdbool.h>
|
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.
2018-02-16 05:59:21 +08:00
|
|
|
|
2019-05-31 20:55:11 +08:00
|
|
|
#include "control_msg.h"
|
2019-05-30 06:25:37 +08:00
|
|
|
#include "receiver.h"
|
Wait SET_CLIPBOARD ack before Ctrl+v via HID
To allow seamless copy-paste, on Ctrl+v, a SET_CLIPBOARD request is
performed before injecting Ctrl+v.
But when HID keyboard is enabled, the Ctrl+v injection is not sent on
the same channel as the clipboard request, so they are not serialized,
and may occur in any order. If Ctrl+v happens to be injected before the
new clipboard content is set, then the old content is pasted instead,
which is incorrect.
To minimize the probability of occurrence of the wrong order, a delay of
2 milliseconds was added before injecting Ctrl+v. Then 5ms. But even
with 5ms, the wrong behavior sometimes happens.
To handle it properly, add an acknowledgement mechanism, so that Ctrl+v
is injected over AOA only after the SET_CLIPBOARD request has been
performed and acknowledged by the server.
Refs e4163321f00bb3830c6049bdb6c1515e7cc668a0
Refs 45b0f8123a52f5c73a5860d616f4ceba2766ca6a
PR #2814 <https://github.com/Genymobile/scrcpy/pull/2814>
2021-11-22 00:40:11 +08:00
|
|
|
#include "util/acksync.h"
|
2019-11-24 18:53:00 +08:00
|
|
|
#include "util/cbuf.h"
|
|
|
|
#include "util/net.h"
|
2021-02-01 01:24:35 +08:00
|
|
|
#include "util/thread.h"
|
2017-12-14 18:38:44 +08:00
|
|
|
|
2022-01-15 05:17:30 +08:00
|
|
|
struct sc_control_msg_queue CBUF(struct control_msg, 64);
|
2019-05-30 03:24:30 +08:00
|
|
|
|
2022-01-15 05:17:30 +08:00
|
|
|
struct sc_controller {
|
2021-10-27 04:49:45 +08:00
|
|
|
sc_socket control_socket;
|
2021-02-01 01:24:35 +08:00
|
|
|
sc_thread thread;
|
|
|
|
sc_mutex mutex;
|
|
|
|
sc_cond msg_cond;
|
2019-03-03 06:52:22 +08:00
|
|
|
bool stopped;
|
2022-01-15 05:17:30 +08:00
|
|
|
struct sc_control_msg_queue queue;
|
2019-05-30 06:25:37 +08:00
|
|
|
struct receiver receiver;
|
2017-12-14 18:38:44 +08:00
|
|
|
};
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
bool
|
2022-01-15 05:17:30 +08:00
|
|
|
sc_controller_init(struct sc_controller *controller, sc_socket control_socket,
|
|
|
|
struct sc_acksync *acksync);
|
2017-12-14 18:38:44 +08:00
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
2022-01-15 05:17:30 +08:00
|
|
|
sc_controller_destroy(struct sc_controller *controller);
|
2019-03-03 03:09:56 +08:00
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
bool
|
2022-01-15 05:17:30 +08:00
|
|
|
sc_controller_start(struct sc_controller *controller);
|
2019-03-03 03:09:56 +08:00
|
|
|
|
|
|
|
void
|
2022-01-15 05:17:30 +08:00
|
|
|
sc_controller_stop(struct sc_controller *controller);
|
2019-03-03 03:09:56 +08:00
|
|
|
|
|
|
|
void
|
2022-01-15 05:17:30 +08:00
|
|
|
sc_controller_join(struct sc_controller *controller);
|
2017-12-14 18:38:44 +08:00
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
bool
|
2022-01-15 05:17:30 +08:00
|
|
|
sc_controller_push_msg(struct sc_controller *controller,
|
|
|
|
const struct control_msg *msg);
|
2017-12-14 18:38:44 +08:00
|
|
|
|
|
|
|
#endif
|