2018-02-08 13:47:31 +01:00
|
|
|
#ifndef SERVER_H
|
|
|
|
#define SERVER_H
|
|
|
|
|
2020-04-02 19:16:33 +02:00
|
|
|
#include <stdatomic.h>
|
2019-03-02 23:52:22 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
2020-03-28 23:15:15 +01:00
|
|
|
#include <SDL2/SDL_thread.h>
|
2019-03-02 23:52:22 +01:00
|
|
|
|
2019-09-29 22:36:56 +02:00
|
|
|
#include "config.h"
|
2018-01-22 11:22:31 +01:00
|
|
|
#include "command.h"
|
2019-12-09 21:16:09 +01:00
|
|
|
#include "common.h"
|
2020-06-19 22:04:06 +02:00
|
|
|
#include "scrcpy.h"
|
2020-05-24 21:51:40 +02:00
|
|
|
#include "util/log.h"
|
2019-11-24 11:53:00 +01:00
|
|
|
#include "util/net.h"
|
2018-01-22 11:22:31 +01:00
|
|
|
|
2018-02-08 15:16:27 +01:00
|
|
|
struct server {
|
2019-03-03 00:01:16 +01:00
|
|
|
char *serial;
|
2018-02-08 15:16:27 +01:00
|
|
|
process_t process;
|
2020-03-28 23:15:15 +01:00
|
|
|
SDL_Thread *wait_server_thread;
|
2020-04-02 19:16:33 +02:00
|
|
|
atomic_flag server_socket_closed;
|
2018-03-12 08:35:51 +01:00
|
|
|
socket_t server_socket; // only used if !tunnel_forward
|
2019-05-28 21:03:54 +02:00
|
|
|
socket_t video_socket;
|
|
|
|
socket_t control_socket;
|
2020-06-19 22:04:06 +02:00
|
|
|
struct sc_port_range port_range;
|
2019-12-09 21:16:09 +01:00
|
|
|
uint16_t local_port; // selected from port_range
|
2019-03-02 23:52:22 +01:00
|
|
|
bool tunnel_enabled;
|
|
|
|
bool tunnel_forward; // use "adb forward" instead of "adb reverse"
|
2018-02-08 15:16:27 +01:00
|
|
|
};
|
2018-01-23 15:46:34 +01:00
|
|
|
|
2019-12-09 21:16:09 +01:00
|
|
|
#define SERVER_INITIALIZER { \
|
|
|
|
.serial = NULL, \
|
|
|
|
.process = PROCESS_NONE, \
|
2020-03-28 23:15:15 +01:00
|
|
|
.wait_server_thread = NULL, \
|
2020-04-02 19:16:33 +02:00
|
|
|
.server_socket_closed = ATOMIC_FLAG_INIT, \
|
2019-12-09 21:16:09 +01:00
|
|
|
.server_socket = INVALID_SOCKET, \
|
|
|
|
.video_socket = INVALID_SOCKET, \
|
2019-05-28 21:03:54 +02:00
|
|
|
.control_socket = INVALID_SOCKET, \
|
2019-12-09 21:16:09 +01:00
|
|
|
.port_range = { \
|
|
|
|
.first = 0, \
|
|
|
|
.last = 0, \
|
|
|
|
}, \
|
|
|
|
.local_port = 0, \
|
|
|
|
.tunnel_enabled = false, \
|
|
|
|
.tunnel_forward = false, \
|
2018-02-08 15:16:27 +01:00
|
|
|
}
|
|
|
|
|
2019-06-04 23:59:55 +02:00
|
|
|
struct server_params {
|
2020-05-24 21:51:40 +02:00
|
|
|
enum sc_log_level log_level;
|
2019-06-04 23:59:55 +02:00
|
|
|
const char *crop;
|
2020-04-26 15:22:08 +03:00
|
|
|
const char *codec_options;
|
2020-10-12 12:23:06 +03:00
|
|
|
const char *encoder_name;
|
2020-06-19 22:04:06 +02:00
|
|
|
struct sc_port_range port_range;
|
2019-06-04 23:59:55 +02:00
|
|
|
uint16_t max_size;
|
|
|
|
uint32_t bit_rate;
|
2019-11-17 22:07:19 +01:00
|
|
|
uint16_t max_fps;
|
2020-02-16 13:30:36 +02:00
|
|
|
int8_t lock_video_orientation;
|
2019-06-04 21:31:46 +02:00
|
|
|
bool control;
|
2020-02-24 14:16:38 +03:00
|
|
|
uint16_t display_id;
|
2020-05-01 23:49:37 +02:00
|
|
|
bool show_touches;
|
2020-05-02 01:54:48 +02:00
|
|
|
bool stay_awake;
|
2020-05-24 23:27:34 +02:00
|
|
|
bool force_adb_forward;
|
2019-06-04 23:59:55 +02:00
|
|
|
};
|
|
|
|
|
2018-02-08 15:16:27 +01:00
|
|
|
// init default values
|
2019-03-02 20:09:56 +01:00
|
|
|
void
|
|
|
|
server_init(struct server *server);
|
2018-02-08 15:16:27 +01:00
|
|
|
|
|
|
|
// push, enable tunnel et start the server
|
2019-03-02 23:52:22 +01:00
|
|
|
bool
|
2019-03-02 20:09:56 +01:00
|
|
|
server_start(struct server *server, const char *serial,
|
2019-06-04 23:59:55 +02:00
|
|
|
const struct server_params *params);
|
2018-02-08 15:16:27 +01:00
|
|
|
|
|
|
|
// block until the communication with the server is established
|
2019-05-28 13:41:19 +02:00
|
|
|
bool
|
2019-03-02 20:09:56 +01:00
|
|
|
server_connect_to(struct server *server);
|
2018-02-08 15:16:27 +01:00
|
|
|
|
|
|
|
// disconnect and kill the server process
|
2019-03-02 20:09:56 +01:00
|
|
|
void
|
|
|
|
server_stop(struct server *server);
|
2018-02-08 13:47:31 +01:00
|
|
|
|
2018-02-09 12:59:36 +01:00
|
|
|
// close and release sockets
|
2019-03-02 20:09:56 +01:00
|
|
|
void
|
|
|
|
server_destroy(struct server *server);
|
2018-02-09 12:59:36 +01:00
|
|
|
|
2018-02-08 13:47:31 +01:00
|
|
|
#endif
|