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