2018-02-08 12:47:31 +00:00
|
|
|
#ifndef SERVER_H
|
|
|
|
#define SERVER_H
|
|
|
|
|
2019-03-02 22:52:22 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2018-01-22 10:22:31 +00:00
|
|
|
#include "command.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-15 21:59:21 +00:00
|
|
|
#include "net.h"
|
2018-01-22 10:22:31 +00:00
|
|
|
|
2018-02-08 14:16:27 +00:00
|
|
|
struct server {
|
2019-03-02 23:01:16 +00:00
|
|
|
char *serial;
|
2018-02-08 14:16:27 +00:00
|
|
|
process_t process;
|
2018-03-12 07:35:51 +00:00
|
|
|
socket_t server_socket; // only used if !tunnel_forward
|
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-15 21:59:21 +00:00
|
|
|
socket_t device_socket;
|
2019-03-02 22:52:22 +00:00
|
|
|
uint16_t local_port;
|
|
|
|
bool tunnel_enabled;
|
|
|
|
bool tunnel_forward; // use "adb forward" instead of "adb reverse"
|
|
|
|
bool send_frame_meta; // request frame PTS to be able to record properly
|
2018-02-08 14:16:27 +00:00
|
|
|
};
|
2018-01-23 14:46:34 +00:00
|
|
|
|
2019-05-28 11:37:27 +00:00
|
|
|
#define SERVER_INITIALIZER { \
|
|
|
|
.serial = NULL, \
|
|
|
|
.process = PROCESS_NONE, \
|
|
|
|
.server_socket = INVALID_SOCKET, \
|
|
|
|
.device_socket = INVALID_SOCKET, \
|
|
|
|
.local_port = 0, \
|
2019-03-02 22:52:22 +00:00
|
|
|
.tunnel_enabled = false, \
|
|
|
|
.tunnel_forward = false, \
|
|
|
|
.send_frame_meta = false, \
|
2018-02-08 14:16:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// init default values
|
2019-03-02 19:09:56 +00:00
|
|
|
void
|
|
|
|
server_init(struct server *server);
|
2018-02-08 14:16:27 +00:00
|
|
|
|
|
|
|
// push, enable tunnel et start the server
|
2019-03-02 22:52:22 +00:00
|
|
|
bool
|
2019-03-02 19:09:56 +00:00
|
|
|
server_start(struct server *server, const char *serial,
|
2019-05-28 11:37:27 +00:00
|
|
|
uint16_t local_port, uint16_t max_size, uint32_t bit_rate,
|
|
|
|
const char *crop, bool send_frame_meta);
|
2018-02-08 14:16:27 +00:00
|
|
|
|
|
|
|
// block until the communication with the server is established
|
2019-05-28 11:41:19 +00:00
|
|
|
bool
|
2019-03-02 19:09:56 +00:00
|
|
|
server_connect_to(struct server *server);
|
2018-02-08 14:16:27 +00:00
|
|
|
|
|
|
|
// disconnect and kill the server process
|
2019-03-02 19:09:56 +00:00
|
|
|
void
|
|
|
|
server_stop(struct server *server);
|
2018-02-08 12:47:31 +00:00
|
|
|
|
2018-02-09 11:59:36 +00:00
|
|
|
// close and release sockets
|
2019-03-02 19:09:56 +00:00
|
|
|
void
|
|
|
|
server_destroy(struct server *server);
|
2018-02-09 11:59:36 +00:00
|
|
|
|
2018-02-08 12:47:31 +00:00
|
|
|
#endif
|