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"
|
2021-05-09 22:52:22 +08:00
|
|
|
#include "coords.h"
|
2021-10-28 00:43:47 +08:00
|
|
|
#include "options.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
|
|
|
|
2021-10-31 01:07:35 +08:00
|
|
|
#define DEVICE_NAME_FIELD_LENGTH 64
|
|
|
|
struct server_info {
|
|
|
|
char device_name[DEVICE_NAME_FIELD_LENGTH];
|
|
|
|
struct sc_size frame_size;
|
|
|
|
};
|
|
|
|
|
2019-06-05 05:59:55 +08:00
|
|
|
struct server_params {
|
2021-05-17 15:41:22 +08:00
|
|
|
const char *serial;
|
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
|
|
|
};
|
|
|
|
|
2021-10-28 05:20:47 +08:00
|
|
|
struct server {
|
2021-10-28 05:40:52 +08:00
|
|
|
// The internal allocated strings are copies owned by the server
|
|
|
|
struct server_params params;
|
2021-10-28 05:20:47 +08:00
|
|
|
|
|
|
|
sc_pid process;
|
|
|
|
// alive only between start() and stop()
|
|
|
|
struct sc_process_observer observer;
|
|
|
|
|
|
|
|
sc_socket server_socket; // only used if !tunnel_forward
|
|
|
|
sc_socket video_socket;
|
|
|
|
sc_socket control_socket;
|
|
|
|
uint16_t local_port; // selected from port_range
|
|
|
|
bool tunnel_enabled;
|
|
|
|
bool tunnel_forward; // use "adb forward" instead of "adb reverse"
|
|
|
|
};
|
|
|
|
|
2021-10-28 05:40:52 +08:00
|
|
|
// init the server with the given params
|
2021-01-01 23:34:47 +08:00
|
|
|
bool
|
2021-10-28 05:40:52 +08:00
|
|
|
server_init(struct server *server, const struct server_params *params);
|
2018-02-08 22:16:27 +08:00
|
|
|
|
|
|
|
// push, enable tunnel et start the server
|
2019-03-03 06:52:22 +08:00
|
|
|
bool
|
2021-10-28 05:40:52 +08:00
|
|
|
server_start(struct server *server);
|
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
|
2021-10-31 01:07:35 +08:00
|
|
|
server_connect_to(struct server *server, struct server_info *info);
|
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
|