scrcpy/app/src/server.h

127 lines
2.9 KiB
C
Raw Normal View History

#ifndef SERVER_H
#define SERVER_H
#include "common.h"
#include <stdatomic.h>
#include <stdbool.h>
#include <stdint.h>
2022-02-04 05:46:24 +08:00
#include "adb/adb_tunnel.h"
#include "coords.h"
#include "options.h"
#include "util/intr.h"
#include "util/log.h"
2019-11-24 18:53:00 +08:00
#include "util/net.h"
#include "util/thread.h"
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-11-13 06:24:12 +08:00
struct sc_server_params {
uint32_t scid;
const char *req_serial;
enum sc_log_level log_level;
enum sc_codec video_codec;
enum sc_codec audio_codec;
const char *crop;
const char *video_codec_options;
const char *audio_codec_options;
const char *video_encoder;
const char *audio_encoder;
struct sc_port_range port_range;
uint32_t tunnel_host;
uint16_t tunnel_port;
uint16_t max_size;
uint32_t video_bit_rate;
uint32_t audio_bit_rate;
uint16_t max_fps;
int8_t lock_video_orientation;
bool control;
uint32_t display_id;
bool audio;
bool show_touches;
bool stay_awake;
bool force_adb_forward;
bool power_off_on_close;
bool clipboard_autosync;
bool downsize_on_error;
bool tcpip;
const char *tcpip_dst;
bool select_usb;
bool select_tcpip;
bool cleanup;
bool power_on;
bool list_encoders;
bool list_displays;
};
2021-11-13 06:24:12 +08:00
struct sc_server {
// The internal allocated strings are copies owned by the server
2021-11-13 06:24:12 +08:00
struct sc_server_params params;
char *serial;
char *device_socket_name;
sc_thread thread;
2021-11-13 06:24:12 +08:00
struct sc_server_info info; // initialized once connected
sc_mutex mutex;
sc_cond cond_stopped;
bool stopped;
struct sc_intr intr;
struct sc_adb_tunnel tunnel;
sc_socket video_socket;
sc_socket audio_socket;
sc_socket control_socket;
2021-11-13 06:24:12 +08:00
const struct sc_server_callbacks *cbs;
void *cbs_userdata;
};
2021-11-13 06:24:12 +08:00
struct sc_server_callbacks {
/**
* 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);
/**
* Called on server connection
*/
2021-11-13 06:24:12 +08:00
void (*on_connected)(struct sc_server *server, void *userdata);
/**
* 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);
};
// init the server with the given params
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);
// start the server asynchronously
bool
2021-11-13 06:24:12 +08:00
sc_server_start(struct sc_server *server);
// disconnect and kill the server process
void
2021-11-13 06:24:12 +08:00
sc_server_stop(struct sc_server *server);
// join the server thread
void
sc_server_join(struct sc_server *server);
// close and release sockets
void
2021-11-13 06:24:12 +08:00
sc_server_destroy(struct sc_server *server);
#endif