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