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>
|
|
|
|
|
2022-02-04 05:46:24 +08:00
|
|
|
#include "adb/adb_tunnel.h"
|
2021-05-09 22:52:22 +08:00
|
|
|
#include "coords.h"
|
2021-10-28 00:43:47 +08:00
|
|
|
#include "options.h"
|
2021-11-13 01:50:50 +08:00
|
|
|
#include "util/intr.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-11-13 06:24:12 +08:00
|
|
|
#define SC_DEVICE_NAME_FIELD_LENGTH 64
|
|
|
|
struct sc_server_info {
|
|
|
|
char device_name[SC_DEVICE_NAME_FIELD_LENGTH];
|
2021-10-31 01:07:35 +08:00
|
|
|
};
|
|
|
|
|
2021-11-13 06:24:12 +08:00
|
|
|
struct sc_server_params {
|
2023-02-11 16:52:31 +08:00
|
|
|
uint32_t scid;
|
2022-02-05 03:49:35 +08:00
|
|
|
const char *req_serial;
|
2020-05-25 03:51:40 +08:00
|
|
|
enum sc_log_level log_level;
|
2023-02-21 04:19:36 +08:00
|
|
|
enum sc_codec video_codec;
|
2023-02-19 02:05:43 +08:00
|
|
|
enum sc_codec audio_codec;
|
2019-06-05 05:59:55 +08:00
|
|
|
const char *crop;
|
2023-02-22 04:46:34 +08:00
|
|
|
const char *video_codec_options;
|
2023-02-23 05:48:23 +08:00
|
|
|
const char *audio_codec_options;
|
2023-02-23 05:44:01 +08:00
|
|
|
const char *video_encoder;
|
2023-02-20 03:20:29 +08:00
|
|
|
const char *audio_encoder;
|
2020-06-20 04:04:06 +08:00
|
|
|
struct sc_port_range port_range;
|
2021-11-18 08:02:53 +08:00
|
|
|
uint32_t tunnel_host;
|
|
|
|
uint16_t tunnel_port;
|
2019-06-05 05:59:55 +08:00
|
|
|
uint16_t max_size;
|
2023-02-22 02:56:44 +08:00
|
|
|
uint32_t video_bit_rate;
|
2023-02-19 01:32:43 +08:00
|
|
|
uint32_t audio_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;
|
2023-02-03 23:27:34 +08:00
|
|
|
bool audio;
|
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;
|
2021-11-22 15:49:10 +08:00
|
|
|
bool clipboard_autosync;
|
2022-01-16 06:01:14 +08:00
|
|
|
bool downsize_on_error;
|
2021-11-26 05:22:49 +08:00
|
|
|
bool tcpip;
|
|
|
|
const char *tcpip_dst;
|
2022-02-07 01:40:18 +08:00
|
|
|
bool select_usb;
|
|
|
|
bool select_tcpip;
|
2022-02-14 00:17:01 +08:00
|
|
|
bool cleanup;
|
2022-04-23 21:08:30 +08:00
|
|
|
bool power_on;
|
2023-02-23 06:15:15 +08:00
|
|
|
bool list_encoders;
|
2023-02-24 06:10:15 +08:00
|
|
|
bool list_displays;
|
2019-06-05 05:59:55 +08:00
|
|
|
};
|
|
|
|
|
2021-11-13 06:24:12 +08:00
|
|
|
struct sc_server {
|
2021-10-28 05:40:52 +08:00
|
|
|
// The internal allocated strings are copies owned by the server
|
2021-11-13 06:24:12 +08:00
|
|
|
struct sc_server_params params;
|
2022-02-05 03:49:35 +08:00
|
|
|
char *serial;
|
2023-01-28 04:48:54 +08:00
|
|
|
char *device_socket_name;
|
2021-10-28 05:20:47 +08:00
|
|
|
|
2021-10-30 21:33:23 +08:00
|
|
|
sc_thread thread;
|
2021-11-13 06:24:12 +08:00
|
|
|
struct sc_server_info info; // initialized once connected
|
2021-10-28 05:20:47 +08:00
|
|
|
|
2021-10-31 21:56:37 +08:00
|
|
|
sc_mutex mutex;
|
|
|
|
sc_cond cond_stopped;
|
|
|
|
bool stopped;
|
|
|
|
|
2021-11-13 01:50:50 +08:00
|
|
|
struct sc_intr intr;
|
2021-11-13 05:32:29 +08:00
|
|
|
struct sc_adb_tunnel tunnel;
|
2021-11-13 01:50:50 +08:00
|
|
|
|
2021-10-28 05:20:47 +08:00
|
|
|
sc_socket video_socket;
|
2023-02-03 23:50:42 +08:00
|
|
|
sc_socket audio_socket;
|
2021-10-28 05:20:47 +08:00
|
|
|
sc_socket control_socket;
|
2021-10-30 21:33:23 +08:00
|
|
|
|
2021-11-13 06:24:12 +08:00
|
|
|
const struct sc_server_callbacks *cbs;
|
2021-10-30 21:33:23 +08:00
|
|
|
void *cbs_userdata;
|
|
|
|
};
|
|
|
|
|
2021-11-13 06:24:12 +08:00
|
|
|
struct sc_server_callbacks {
|
2021-10-30 21:33:23 +08:00
|
|
|
/**
|
|
|
|
* Called when the server failed to connect
|
|
|
|
*
|
|
|
|
* If it is called, then on_connected() and on_disconnected() will never be
|
|
|
|
* called.
|
|
|
|
*/
|
2021-11-13 06:24:12 +08:00
|
|
|
void (*on_connection_failed)(struct sc_server *server, void *userdata);
|
2021-10-30 21:33:23 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called on server connection
|
|
|
|
*/
|
2021-11-13 06:24:12 +08:00
|
|
|
void (*on_connected)(struct sc_server *server, void *userdata);
|
2021-10-30 21:33:23 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called on server disconnection (after it has been connected)
|
|
|
|
*/
|
2021-11-13 06:24:12 +08:00
|
|
|
void (*on_disconnected)(struct sc_server *server, void *userdata);
|
2021-10-28 05:20:47 +08:00
|
|
|
};
|
|
|
|
|
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-11-13 06:24:12 +08:00
|
|
|
sc_server_init(struct sc_server *server, const struct sc_server_params *params,
|
|
|
|
const struct sc_server_callbacks *cbs, void *cbs_userdata);
|
2018-02-08 22:16:27 +08:00
|
|
|
|
2021-10-30 21:33:23 +08:00
|
|
|
// start the server asynchronously
|
2019-03-03 06:52:22 +08:00
|
|
|
bool
|
2021-11-13 06:24:12 +08:00
|
|
|
sc_server_start(struct sc_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
|
2021-11-13 06:24:12 +08:00
|
|
|
sc_server_stop(struct sc_server *server);
|
2018-02-08 20:47:31 +08:00
|
|
|
|
2023-02-23 01:41:22 +08:00
|
|
|
// join the server thread
|
|
|
|
void
|
|
|
|
sc_server_join(struct sc_server *server);
|
|
|
|
|
2018-02-09 19:59:36 +08:00
|
|
|
// close and release sockets
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
2021-11-13 06:24:12 +08:00
|
|
|
sc_server_destroy(struct sc_server *server);
|
2018-02-09 19:59:36 +08:00
|
|
|
|
2018-02-08 20:47:31 +08:00
|
|
|
#endif
|