Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
5e8fa56e7a | |||
60bf133ac2 | |||
1c71bd16be | |||
afa4a1b728 | |||
3a4d5c7f18 | |||
5f7ddff8ae | |||
2a0c2e5e99 | |||
a6644e831b | |||
75655194fb |
@ -343,8 +343,8 @@ run_aoa_thread(void *data) {
|
||||
|
||||
if (ack_to_wait != SC_SEQUENCE_INVALID) {
|
||||
LOGD("Waiting ack from server sequence=%" PRIu64_, ack_to_wait);
|
||||
// Do not block the loop indefinitely if the ack never comes (it should
|
||||
// never happen)
|
||||
// Do not block the loop indefinitely if the ack never comes (it
|
||||
// should never happen)
|
||||
sc_tick deadline = sc_tick_now() + SC_TICK_FROM_MS(500);
|
||||
enum sc_acksync_wait_result result =
|
||||
sc_acksync_wait(aoa->acksync, ack_to_wait, deadline);
|
||||
|
@ -89,7 +89,7 @@ to_fixed_point_16(float f) {
|
||||
}
|
||||
|
||||
size_t
|
||||
control_msg_serialize(const struct control_msg *msg, unsigned char *buf) {
|
||||
sc_control_msg_serialize(const struct sc_control_msg *msg, unsigned char *buf) {
|
||||
buf[0] = msg->type;
|
||||
switch (msg->type) {
|
||||
case CONTROL_MSG_TYPE_INJECT_KEYCODE:
|
||||
@ -151,7 +151,7 @@ control_msg_serialize(const struct control_msg *msg, unsigned char *buf) {
|
||||
}
|
||||
|
||||
void
|
||||
control_msg_log(const struct control_msg *msg) {
|
||||
sc_control_msg_log(const struct sc_control_msg *msg) {
|
||||
#define LOG_CMSG(fmt, ...) LOGV("input: " fmt, ## __VA_ARGS__)
|
||||
switch (msg->type) {
|
||||
case CONTROL_MSG_TYPE_INJECT_KEYCODE:
|
||||
@ -237,7 +237,7 @@ control_msg_log(const struct control_msg *msg) {
|
||||
}
|
||||
|
||||
void
|
||||
control_msg_destroy(struct control_msg *msg) {
|
||||
sc_control_msg_destroy(struct sc_control_msg *msg) {
|
||||
switch (msg->type) {
|
||||
case CONTROL_MSG_TYPE_INJECT_TEXT:
|
||||
free(msg->inject_text.text);
|
||||
|
@ -20,7 +20,7 @@
|
||||
#define POINTER_ID_MOUSE UINT64_C(-1)
|
||||
#define POINTER_ID_VIRTUAL_FINGER UINT64_C(-2)
|
||||
|
||||
enum control_msg_type {
|
||||
enum sc_control_msg_type {
|
||||
CONTROL_MSG_TYPE_INJECT_KEYCODE,
|
||||
CONTROL_MSG_TYPE_INJECT_TEXT,
|
||||
CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
||||
@ -47,8 +47,8 @@ enum get_clipboard_copy_key {
|
||||
GET_CLIPBOARD_COPY_KEY_CUT,
|
||||
};
|
||||
|
||||
struct control_msg {
|
||||
enum control_msg_type type;
|
||||
struct sc_control_msg {
|
||||
enum sc_control_msg_type type;
|
||||
union {
|
||||
struct {
|
||||
enum android_keyevent_action action;
|
||||
@ -93,12 +93,12 @@ struct control_msg {
|
||||
// buf size must be at least CONTROL_MSG_MAX_SIZE
|
||||
// return the number of bytes written
|
||||
size_t
|
||||
control_msg_serialize(const struct control_msg *msg, unsigned char *buf);
|
||||
sc_control_msg_serialize(const struct sc_control_msg *msg, unsigned char *buf);
|
||||
|
||||
void
|
||||
control_msg_log(const struct control_msg *msg);
|
||||
sc_control_msg_log(const struct sc_control_msg *msg);
|
||||
|
||||
void
|
||||
control_msg_destroy(struct control_msg *msg);
|
||||
sc_control_msg_destroy(struct sc_control_msg *msg);
|
||||
|
||||
#endif
|
||||
|
@ -5,8 +5,8 @@
|
||||
#include "util/log.h"
|
||||
|
||||
bool
|
||||
controller_init(struct controller *controller, sc_socket control_socket,
|
||||
struct sc_acksync *acksync) {
|
||||
sc_controller_init(struct sc_controller *controller, sc_socket control_socket,
|
||||
struct sc_acksync *acksync) {
|
||||
cbuf_init(&controller->queue);
|
||||
|
||||
bool ok = receiver_init(&controller->receiver, control_socket, acksync);
|
||||
@ -34,23 +34,23 @@ controller_init(struct controller *controller, sc_socket control_socket,
|
||||
}
|
||||
|
||||
void
|
||||
controller_destroy(struct controller *controller) {
|
||||
sc_controller_destroy(struct sc_controller *controller) {
|
||||
sc_cond_destroy(&controller->msg_cond);
|
||||
sc_mutex_destroy(&controller->mutex);
|
||||
|
||||
struct control_msg msg;
|
||||
struct sc_control_msg msg;
|
||||
while (cbuf_take(&controller->queue, &msg)) {
|
||||
control_msg_destroy(&msg);
|
||||
sc_control_msg_destroy(&msg);
|
||||
}
|
||||
|
||||
receiver_destroy(&controller->receiver);
|
||||
}
|
||||
|
||||
bool
|
||||
controller_push_msg(struct controller *controller,
|
||||
const struct control_msg *msg) {
|
||||
sc_controller_push_msg(struct sc_controller *controller,
|
||||
const struct sc_control_msg *msg) {
|
||||
if (sc_get_log_level() <= SC_LOG_LEVEL_VERBOSE) {
|
||||
control_msg_log(msg);
|
||||
sc_control_msg_log(msg);
|
||||
}
|
||||
|
||||
sc_mutex_lock(&controller->mutex);
|
||||
@ -64,9 +64,10 @@ controller_push_msg(struct controller *controller,
|
||||
}
|
||||
|
||||
static bool
|
||||
process_msg(struct controller *controller, const struct control_msg *msg) {
|
||||
process_msg(struct sc_controller *controller,
|
||||
const struct sc_control_msg *msg) {
|
||||
static unsigned char serialized_msg[CONTROL_MSG_MAX_SIZE];
|
||||
size_t length = control_msg_serialize(msg, serialized_msg);
|
||||
size_t length = sc_control_msg_serialize(msg, serialized_msg);
|
||||
if (!length) {
|
||||
return false;
|
||||
}
|
||||
@ -77,7 +78,7 @@ process_msg(struct controller *controller, const struct control_msg *msg) {
|
||||
|
||||
static int
|
||||
run_controller(void *data) {
|
||||
struct controller *controller = data;
|
||||
struct sc_controller *controller = data;
|
||||
|
||||
for (;;) {
|
||||
sc_mutex_lock(&controller->mutex);
|
||||
@ -89,14 +90,14 @@ run_controller(void *data) {
|
||||
sc_mutex_unlock(&controller->mutex);
|
||||
break;
|
||||
}
|
||||
struct control_msg msg;
|
||||
struct sc_control_msg msg;
|
||||
bool non_empty = cbuf_take(&controller->queue, &msg);
|
||||
assert(non_empty);
|
||||
(void) non_empty;
|
||||
sc_mutex_unlock(&controller->mutex);
|
||||
|
||||
bool ok = process_msg(controller, &msg);
|
||||
control_msg_destroy(&msg);
|
||||
sc_control_msg_destroy(&msg);
|
||||
if (!ok) {
|
||||
LOGD("Could not write msg to socket");
|
||||
break;
|
||||
@ -106,7 +107,7 @@ run_controller(void *data) {
|
||||
}
|
||||
|
||||
bool
|
||||
controller_start(struct controller *controller) {
|
||||
sc_controller_start(struct sc_controller *controller) {
|
||||
LOGD("Starting controller thread");
|
||||
|
||||
bool ok = sc_thread_create(&controller->thread, run_controller,
|
||||
@ -117,7 +118,7 @@ controller_start(struct controller *controller) {
|
||||
}
|
||||
|
||||
if (!receiver_start(&controller->receiver)) {
|
||||
controller_stop(controller);
|
||||
sc_controller_stop(controller);
|
||||
sc_thread_join(&controller->thread, NULL);
|
||||
return false;
|
||||
}
|
||||
@ -126,7 +127,7 @@ controller_start(struct controller *controller) {
|
||||
}
|
||||
|
||||
void
|
||||
controller_stop(struct controller *controller) {
|
||||
sc_controller_stop(struct sc_controller *controller) {
|
||||
sc_mutex_lock(&controller->mutex);
|
||||
controller->stopped = true;
|
||||
sc_cond_signal(&controller->msg_cond);
|
||||
@ -134,7 +135,7 @@ controller_stop(struct controller *controller) {
|
||||
}
|
||||
|
||||
void
|
||||
controller_join(struct controller *controller) {
|
||||
sc_controller_join(struct sc_controller *controller) {
|
||||
sc_thread_join(&controller->thread, NULL);
|
||||
receiver_join(&controller->receiver);
|
||||
}
|
||||
|
@ -12,36 +12,36 @@
|
||||
#include "util/net.h"
|
||||
#include "util/thread.h"
|
||||
|
||||
struct control_msg_queue CBUF(struct control_msg, 64);
|
||||
struct sc_control_msg_queue CBUF(struct sc_control_msg, 64);
|
||||
|
||||
struct controller {
|
||||
struct sc_controller {
|
||||
sc_socket control_socket;
|
||||
sc_thread thread;
|
||||
sc_mutex mutex;
|
||||
sc_cond msg_cond;
|
||||
bool stopped;
|
||||
struct control_msg_queue queue;
|
||||
struct sc_control_msg_queue queue;
|
||||
struct receiver receiver;
|
||||
};
|
||||
|
||||
bool
|
||||
controller_init(struct controller *controller, sc_socket control_socket,
|
||||
struct sc_acksync *acksync);
|
||||
sc_controller_init(struct sc_controller *controller, sc_socket control_socket,
|
||||
struct sc_acksync *acksync);
|
||||
|
||||
void
|
||||
controller_destroy(struct controller *controller);
|
||||
sc_controller_destroy(struct sc_controller *controller);
|
||||
|
||||
bool
|
||||
controller_start(struct controller *controller);
|
||||
sc_controller_start(struct sc_controller *controller);
|
||||
|
||||
void
|
||||
controller_stop(struct controller *controller);
|
||||
sc_controller_stop(struct sc_controller *controller);
|
||||
|
||||
void
|
||||
controller_join(struct controller *controller);
|
||||
sc_controller_join(struct sc_controller *controller);
|
||||
|
||||
bool
|
||||
controller_push_msg(struct controller *controller,
|
||||
const struct control_msg *msg);
|
||||
sc_controller_push_msg(struct sc_controller *controller,
|
||||
const struct sc_control_msg *msg);
|
||||
|
||||
#endif
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "trait/packet_sink.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
|
||||
#define DECODER_MAX_SINKS 2
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
#include <libavutil/pixdesc.h>
|
||||
#include <libavutil/pixfmt.h>
|
||||
@ -85,7 +86,7 @@ decode_image(const char *path) {
|
||||
|
||||
AVCodecParameters *params = ctx->streams[stream]->codecpar;
|
||||
|
||||
AVCodec *codec = avcodec_find_decoder(params->codec_id);
|
||||
const AVCodec *codec = avcodec_find_decoder(params->codec_id);
|
||||
if (!codec) {
|
||||
LOGE("Could not find image decoder");
|
||||
goto close_input;
|
||||
|
@ -106,7 +106,7 @@ to_sdl_mod(unsigned shortcut_mod) {
|
||||
}
|
||||
|
||||
static bool
|
||||
is_shortcut_mod(struct input_manager *im, uint16_t sdl_mod) {
|
||||
is_shortcut_mod(struct sc_input_manager *im, uint16_t sdl_mod) {
|
||||
// keep only the relevant modifier keys
|
||||
sdl_mod &= SC_SDL_SHORTCUT_MODS_MASK;
|
||||
|
||||
@ -122,8 +122,8 @@ is_shortcut_mod(struct input_manager *im, uint16_t sdl_mod) {
|
||||
}
|
||||
|
||||
void
|
||||
input_manager_init(struct input_manager *im,
|
||||
const struct input_manager_params *params) {
|
||||
sc_input_manager_init(struct sc_input_manager *im,
|
||||
const struct sc_input_manager_params *params) {
|
||||
assert(!params->control || (params->kp && params->kp->ops));
|
||||
assert(!params->control || (params->mp && params->mp->ops));
|
||||
|
||||
@ -157,10 +157,10 @@ input_manager_init(struct input_manager *im,
|
||||
}
|
||||
|
||||
static void
|
||||
send_keycode(struct controller *controller, enum android_keycode keycode,
|
||||
send_keycode(struct sc_controller *controller, enum android_keycode keycode,
|
||||
enum sc_action action, const char *name) {
|
||||
// send DOWN event
|
||||
struct control_msg msg;
|
||||
struct sc_control_msg msg;
|
||||
msg.type = CONTROL_MSG_TYPE_INJECT_KEYCODE;
|
||||
msg.inject_keycode.action = action == SC_ACTION_DOWN
|
||||
? AKEY_EVENT_ACTION_DOWN
|
||||
@ -169,100 +169,100 @@ send_keycode(struct controller *controller, enum android_keycode keycode,
|
||||
msg.inject_keycode.metastate = 0;
|
||||
msg.inject_keycode.repeat = 0;
|
||||
|
||||
if (!controller_push_msg(controller, &msg)) {
|
||||
if (!sc_controller_push_msg(controller, &msg)) {
|
||||
LOGW("Could not request 'inject %s'", name);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
action_home(struct controller *controller, enum sc_action action) {
|
||||
action_home(struct sc_controller *controller, enum sc_action action) {
|
||||
send_keycode(controller, AKEYCODE_HOME, action, "HOME");
|
||||
}
|
||||
|
||||
static inline void
|
||||
action_back(struct controller *controller, enum sc_action action) {
|
||||
action_back(struct sc_controller *controller, enum sc_action action) {
|
||||
send_keycode(controller, AKEYCODE_BACK, action, "BACK");
|
||||
}
|
||||
|
||||
static inline void
|
||||
action_app_switch(struct controller *controller, enum sc_action action) {
|
||||
action_app_switch(struct sc_controller *controller, enum sc_action action) {
|
||||
send_keycode(controller, AKEYCODE_APP_SWITCH, action, "APP_SWITCH");
|
||||
}
|
||||
|
||||
static inline void
|
||||
action_power(struct controller *controller, enum sc_action action) {
|
||||
action_power(struct sc_controller *controller, enum sc_action action) {
|
||||
send_keycode(controller, AKEYCODE_POWER, action, "POWER");
|
||||
}
|
||||
|
||||
static inline void
|
||||
action_volume_up(struct controller *controller, enum sc_action action) {
|
||||
action_volume_up(struct sc_controller *controller, enum sc_action action) {
|
||||
send_keycode(controller, AKEYCODE_VOLUME_UP, action, "VOLUME_UP");
|
||||
}
|
||||
|
||||
static inline void
|
||||
action_volume_down(struct controller *controller, enum sc_action action) {
|
||||
action_volume_down(struct sc_controller *controller, enum sc_action action) {
|
||||
send_keycode(controller, AKEYCODE_VOLUME_DOWN, action, "VOLUME_DOWN");
|
||||
}
|
||||
|
||||
static inline void
|
||||
action_menu(struct controller *controller, enum sc_action action) {
|
||||
action_menu(struct sc_controller *controller, enum sc_action action) {
|
||||
send_keycode(controller, AKEYCODE_MENU, action, "MENU");
|
||||
}
|
||||
|
||||
// turn the screen on if it was off, press BACK otherwise
|
||||
// If the screen is off, it is turned on only on ACTION_DOWN
|
||||
static void
|
||||
press_back_or_turn_screen_on(struct controller *controller,
|
||||
press_back_or_turn_screen_on(struct sc_controller *controller,
|
||||
enum sc_action action) {
|
||||
struct control_msg msg;
|
||||
struct sc_control_msg msg;
|
||||
msg.type = CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON;
|
||||
msg.back_or_screen_on.action = action == SC_ACTION_DOWN
|
||||
? AKEY_EVENT_ACTION_DOWN
|
||||
: AKEY_EVENT_ACTION_UP;
|
||||
|
||||
if (!controller_push_msg(controller, &msg)) {
|
||||
if (!sc_controller_push_msg(controller, &msg)) {
|
||||
LOGW("Could not request 'press back or turn screen on'");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
expand_notification_panel(struct controller *controller) {
|
||||
struct control_msg msg;
|
||||
expand_notification_panel(struct sc_controller *controller) {
|
||||
struct sc_control_msg msg;
|
||||
msg.type = CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL;
|
||||
|
||||
if (!controller_push_msg(controller, &msg)) {
|
||||
if (!sc_controller_push_msg(controller, &msg)) {
|
||||
LOGW("Could not request 'expand notification panel'");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
expand_settings_panel(struct controller *controller) {
|
||||
struct control_msg msg;
|
||||
expand_settings_panel(struct sc_controller *controller) {
|
||||
struct sc_control_msg msg;
|
||||
msg.type = CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL;
|
||||
|
||||
if (!controller_push_msg(controller, &msg)) {
|
||||
if (!sc_controller_push_msg(controller, &msg)) {
|
||||
LOGW("Could not request 'expand settings panel'");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
collapse_panels(struct controller *controller) {
|
||||
struct control_msg msg;
|
||||
collapse_panels(struct sc_controller *controller) {
|
||||
struct sc_control_msg msg;
|
||||
msg.type = CONTROL_MSG_TYPE_COLLAPSE_PANELS;
|
||||
|
||||
if (!controller_push_msg(controller, &msg)) {
|
||||
if (!sc_controller_push_msg(controller, &msg)) {
|
||||
LOGW("Could not request 'collapse notification panel'");
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
get_device_clipboard(struct controller *controller,
|
||||
get_device_clipboard(struct sc_controller *controller,
|
||||
enum get_clipboard_copy_key copy_key) {
|
||||
struct control_msg msg;
|
||||
struct sc_control_msg msg;
|
||||
msg.type = CONTROL_MSG_TYPE_GET_CLIPBOARD;
|
||||
msg.get_clipboard.copy_key = copy_key;
|
||||
|
||||
if (!controller_push_msg(controller, &msg)) {
|
||||
if (!sc_controller_push_msg(controller, &msg)) {
|
||||
LOGW("Could not request 'get device clipboard'");
|
||||
return false;
|
||||
}
|
||||
@ -271,7 +271,7 @@ get_device_clipboard(struct controller *controller,
|
||||
}
|
||||
|
||||
static bool
|
||||
set_device_clipboard(struct controller *controller, bool paste,
|
||||
set_device_clipboard(struct sc_controller *controller, bool paste,
|
||||
uint64_t sequence) {
|
||||
char *text = SDL_GetClipboardText();
|
||||
if (!text) {
|
||||
@ -286,13 +286,13 @@ set_device_clipboard(struct controller *controller, bool paste,
|
||||
return false;
|
||||
}
|
||||
|
||||
struct control_msg msg;
|
||||
struct sc_control_msg msg;
|
||||
msg.type = CONTROL_MSG_TYPE_SET_CLIPBOARD;
|
||||
msg.set_clipboard.sequence = sequence;
|
||||
msg.set_clipboard.text = text_dup;
|
||||
msg.set_clipboard.paste = paste;
|
||||
|
||||
if (!controller_push_msg(controller, &msg)) {
|
||||
if (!sc_controller_push_msg(controller, &msg)) {
|
||||
free(text_dup);
|
||||
LOGW("Could not request 'set device clipboard'");
|
||||
return false;
|
||||
@ -302,13 +302,13 @@ set_device_clipboard(struct controller *controller, bool paste,
|
||||
}
|
||||
|
||||
static void
|
||||
set_screen_power_mode(struct controller *controller,
|
||||
set_screen_power_mode(struct sc_controller *controller,
|
||||
enum screen_power_mode mode) {
|
||||
struct control_msg msg;
|
||||
struct sc_control_msg msg;
|
||||
msg.type = CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE;
|
||||
msg.set_screen_power_mode.mode = mode;
|
||||
|
||||
if (!controller_push_msg(controller, &msg)) {
|
||||
if (!sc_controller_push_msg(controller, &msg)) {
|
||||
LOGW("Could not request 'set screen power mode'");
|
||||
}
|
||||
}
|
||||
@ -330,7 +330,7 @@ switch_fps_counter_state(struct fps_counter *fps_counter) {
|
||||
}
|
||||
|
||||
static void
|
||||
clipboard_paste(struct controller *controller) {
|
||||
clipboard_paste(struct sc_controller *controller) {
|
||||
char *text = SDL_GetClipboardText();
|
||||
if (!text) {
|
||||
LOGW("Could not get clipboard text: %s", SDL_GetError());
|
||||
@ -349,40 +349,40 @@ clipboard_paste(struct controller *controller) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct control_msg msg;
|
||||
struct sc_control_msg msg;
|
||||
msg.type = CONTROL_MSG_TYPE_INJECT_TEXT;
|
||||
msg.inject_text.text = text_dup;
|
||||
if (!controller_push_msg(controller, &msg)) {
|
||||
if (!sc_controller_push_msg(controller, &msg)) {
|
||||
free(text_dup);
|
||||
LOGW("Could not request 'paste clipboard'");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
rotate_device(struct controller *controller) {
|
||||
struct control_msg msg;
|
||||
rotate_device(struct sc_controller *controller) {
|
||||
struct sc_control_msg msg;
|
||||
msg.type = CONTROL_MSG_TYPE_ROTATE_DEVICE;
|
||||
|
||||
if (!controller_push_msg(controller, &msg)) {
|
||||
if (!sc_controller_push_msg(controller, &msg)) {
|
||||
LOGW("Could not request device rotation");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
rotate_client_left(struct screen *screen) {
|
||||
rotate_client_left(struct sc_screen *screen) {
|
||||
unsigned new_rotation = (screen->rotation + 1) % 4;
|
||||
screen_set_rotation(screen, new_rotation);
|
||||
sc_screen_set_rotation(screen, new_rotation);
|
||||
}
|
||||
|
||||
static void
|
||||
rotate_client_right(struct screen *screen) {
|
||||
rotate_client_right(struct sc_screen *screen) {
|
||||
unsigned new_rotation = (screen->rotation + 3) % 4;
|
||||
screen_set_rotation(screen, new_rotation);
|
||||
sc_screen_set_rotation(screen, new_rotation);
|
||||
}
|
||||
|
||||
static void
|
||||
input_manager_process_text_input(struct input_manager *im,
|
||||
const SDL_TextInputEvent *event) {
|
||||
sc_input_manager_process_text_input(struct sc_input_manager *im,
|
||||
const SDL_TextInputEvent *event) {
|
||||
if (!im->kp->ops->process_text) {
|
||||
// The key processor does not support text input
|
||||
return;
|
||||
@ -401,12 +401,12 @@ input_manager_process_text_input(struct input_manager *im,
|
||||
}
|
||||
|
||||
static bool
|
||||
simulate_virtual_finger(struct input_manager *im,
|
||||
simulate_virtual_finger(struct sc_input_manager *im,
|
||||
enum android_motionevent_action action,
|
||||
struct sc_point point) {
|
||||
bool up = action == AMOTION_EVENT_ACTION_UP;
|
||||
|
||||
struct control_msg msg;
|
||||
struct sc_control_msg msg;
|
||||
msg.type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT;
|
||||
msg.inject_touch_event.action = action;
|
||||
msg.inject_touch_event.position.screen_size = im->screen->frame_size;
|
||||
@ -415,7 +415,7 @@ simulate_virtual_finger(struct input_manager *im,
|
||||
msg.inject_touch_event.pressure = up ? 0.0f : 1.0f;
|
||||
msg.inject_touch_event.buttons = 0;
|
||||
|
||||
if (!controller_push_msg(im->controller, &msg)) {
|
||||
if (!sc_controller_push_msg(im->controller, &msg)) {
|
||||
LOGW("Could not request 'inject virtual finger event'");
|
||||
return false;
|
||||
}
|
||||
@ -431,12 +431,12 @@ inverse_point(struct sc_point point, struct sc_size size) {
|
||||
}
|
||||
|
||||
static void
|
||||
input_manager_process_key(struct input_manager *im,
|
||||
const SDL_KeyboardEvent *event) {
|
||||
sc_input_manager_process_key(struct sc_input_manager *im,
|
||||
const SDL_KeyboardEvent *event) {
|
||||
// control: indicates the state of the command-line option --no-control
|
||||
bool control = im->control;
|
||||
|
||||
struct controller *controller = im->controller;
|
||||
struct sc_controller *controller = im->controller;
|
||||
|
||||
SDL_Keycode keycode = event->keysym.sym;
|
||||
uint16_t mod = event->keysym.mod;
|
||||
@ -544,17 +544,17 @@ input_manager_process_key(struct input_manager *im,
|
||||
return;
|
||||
case SDLK_f:
|
||||
if (!shift && !repeat && down) {
|
||||
screen_switch_fullscreen(im->screen);
|
||||
sc_screen_switch_fullscreen(im->screen);
|
||||
}
|
||||
return;
|
||||
case SDLK_w:
|
||||
if (!shift && !repeat && down) {
|
||||
screen_resize_to_fit(im->screen);
|
||||
sc_screen_resize_to_fit(im->screen);
|
||||
}
|
||||
return;
|
||||
case SDLK_g:
|
||||
if (!shift && !repeat && down) {
|
||||
screen_resize_to_pixel_perfect(im->screen);
|
||||
sc_screen_resize_to_pixel_perfect(im->screen);
|
||||
}
|
||||
return;
|
||||
case SDLK_i:
|
||||
@ -629,8 +629,8 @@ input_manager_process_key(struct input_manager *im,
|
||||
}
|
||||
|
||||
static void
|
||||
input_manager_process_mouse_motion(struct input_manager *im,
|
||||
const SDL_MouseMotionEvent *event) {
|
||||
sc_input_manager_process_mouse_motion(struct sc_input_manager *im,
|
||||
const SDL_MouseMotionEvent *event) {
|
||||
|
||||
if (event->which == SDL_TOUCH_MOUSEID) {
|
||||
// simulated from touch events, so it's a duplicate
|
||||
@ -640,8 +640,9 @@ input_manager_process_mouse_motion(struct input_manager *im,
|
||||
struct sc_mouse_motion_event evt = {
|
||||
.position = {
|
||||
.screen_size = im->screen->frame_size,
|
||||
.point = screen_convert_window_to_frame_coords(im->screen,
|
||||
event->x, event->y),
|
||||
.point = sc_screen_convert_window_to_frame_coords(im->screen,
|
||||
event->x,
|
||||
event->y),
|
||||
},
|
||||
.xrel = event->xrel,
|
||||
.yrel = event->yrel,
|
||||
@ -659,16 +660,16 @@ input_manager_process_mouse_motion(struct input_manager *im,
|
||||
if (im->vfinger_down) {
|
||||
assert(!im->mp->relative_mode); // assert one more time
|
||||
struct sc_point mouse =
|
||||
screen_convert_window_to_frame_coords(im->screen, event->x,
|
||||
event->y);
|
||||
sc_screen_convert_window_to_frame_coords(im->screen, event->x,
|
||||
event->y);
|
||||
struct sc_point vfinger = inverse_point(mouse, im->screen->frame_size);
|
||||
simulate_virtual_finger(im, AMOTION_EVENT_ACTION_MOVE, vfinger);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
input_manager_process_touch(struct input_manager *im,
|
||||
const SDL_TouchFingerEvent *event) {
|
||||
sc_input_manager_process_touch(struct sc_input_manager *im,
|
||||
const SDL_TouchFingerEvent *event) {
|
||||
if (!im->mp->ops->process_touch) {
|
||||
// The mouse processor does not support touch events
|
||||
return;
|
||||
@ -685,7 +686,8 @@ input_manager_process_touch(struct input_manager *im,
|
||||
struct sc_touch_event evt = {
|
||||
.position = {
|
||||
.screen_size = im->screen->frame_size,
|
||||
.point = screen_convert_drawable_to_frame_coords(im->screen, x, y),
|
||||
.point =
|
||||
sc_screen_convert_drawable_to_frame_coords(im->screen, x, y),
|
||||
},
|
||||
.action = sc_touch_action_from_sdl(event->type),
|
||||
.pointer_id = event->fingerId,
|
||||
@ -696,8 +698,8 @@ input_manager_process_touch(struct input_manager *im,
|
||||
}
|
||||
|
||||
static void
|
||||
input_manager_process_mouse_button(struct input_manager *im,
|
||||
const SDL_MouseButtonEvent *event) {
|
||||
sc_input_manager_process_mouse_button(struct sc_input_manager *im,
|
||||
const SDL_MouseButtonEvent *event) {
|
||||
bool control = im->control;
|
||||
|
||||
if (event->which == SDL_TOUCH_MOUSEID) {
|
||||
@ -734,13 +736,13 @@ input_manager_process_mouse_button(struct input_manager *im,
|
||||
if (event->button == SDL_BUTTON_LEFT && event->clicks == 2) {
|
||||
int32_t x = event->x;
|
||||
int32_t y = event->y;
|
||||
screen_hidpi_scale_coords(im->screen, &x, &y);
|
||||
sc_screen_hidpi_scale_coords(im->screen, &x, &y);
|
||||
SDL_Rect *r = &im->screen->rect;
|
||||
bool outside = x < r->x || x >= r->x + r->w
|
||||
|| y < r->y || y >= r->y + r->h;
|
||||
if (outside) {
|
||||
if (down) {
|
||||
screen_resize_to_fit(im->screen);
|
||||
sc_screen_resize_to_fit(im->screen);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -757,8 +759,9 @@ input_manager_process_mouse_button(struct input_manager *im,
|
||||
struct sc_mouse_click_event evt = {
|
||||
.position = {
|
||||
.screen_size = im->screen->frame_size,
|
||||
.point = screen_convert_window_to_frame_coords(im->screen, event->x,
|
||||
event->y),
|
||||
.point = sc_screen_convert_window_to_frame_coords(im->screen,
|
||||
event->x,
|
||||
event->y),
|
||||
},
|
||||
.action = sc_action_from_sdl_mousebutton_type(event->type),
|
||||
.button = sc_mouse_button_from_sdl(event->button),
|
||||
@ -790,8 +793,8 @@ input_manager_process_mouse_button(struct input_manager *im,
|
||||
((down && !im->vfinger_down && CTRL_PRESSED) ||
|
||||
(!down && im->vfinger_down))) {
|
||||
struct sc_point mouse =
|
||||
screen_convert_window_to_frame_coords(im->screen, event->x,
|
||||
event->y);
|
||||
sc_screen_convert_window_to_frame_coords(im->screen, event->x,
|
||||
event->y);
|
||||
struct sc_point vfinger = inverse_point(mouse, im->screen->frame_size);
|
||||
enum android_motionevent_action action = down
|
||||
? AMOTION_EVENT_ACTION_DOWN
|
||||
@ -804,8 +807,8 @@ input_manager_process_mouse_button(struct input_manager *im,
|
||||
}
|
||||
|
||||
static void
|
||||
input_manager_process_mouse_wheel(struct input_manager *im,
|
||||
const SDL_MouseWheelEvent *event) {
|
||||
sc_input_manager_process_mouse_wheel(struct sc_input_manager *im,
|
||||
const SDL_MouseWheelEvent *event) {
|
||||
if (!im->mp->ops->process_mouse_scroll) {
|
||||
// The mouse processor does not support scroll events
|
||||
return;
|
||||
@ -819,8 +822,8 @@ input_manager_process_mouse_wheel(struct input_manager *im,
|
||||
struct sc_mouse_scroll_event evt = {
|
||||
.position = {
|
||||
.screen_size = im->screen->frame_size,
|
||||
.point = screen_convert_window_to_frame_coords(im->screen,
|
||||
mouse_x, mouse_y),
|
||||
.point = sc_screen_convert_window_to_frame_coords(im->screen,
|
||||
mouse_x, mouse_y),
|
||||
},
|
||||
.hscroll = event->x,
|
||||
.vscroll = event->y,
|
||||
@ -832,42 +835,42 @@ input_manager_process_mouse_wheel(struct input_manager *im,
|
||||
}
|
||||
|
||||
bool
|
||||
input_manager_handle_event(struct input_manager *im, SDL_Event *event) {
|
||||
sc_input_manager_handle_event(struct sc_input_manager *im, SDL_Event *event) {
|
||||
switch (event->type) {
|
||||
case SDL_TEXTINPUT:
|
||||
if (!im->control) {
|
||||
return true;
|
||||
}
|
||||
input_manager_process_text_input(im, &event->text);
|
||||
sc_input_manager_process_text_input(im, &event->text);
|
||||
return true;
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
// some key events do not interact with the device, so process the
|
||||
// event even if control is disabled
|
||||
input_manager_process_key(im, &event->key);
|
||||
sc_input_manager_process_key(im, &event->key);
|
||||
return true;
|
||||
case SDL_MOUSEMOTION:
|
||||
if (!im->control) {
|
||||
break;
|
||||
}
|
||||
input_manager_process_mouse_motion(im, &event->motion);
|
||||
sc_input_manager_process_mouse_motion(im, &event->motion);
|
||||
return true;
|
||||
case SDL_MOUSEWHEEL:
|
||||
if (!im->control) {
|
||||
break;
|
||||
}
|
||||
input_manager_process_mouse_wheel(im, &event->wheel);
|
||||
sc_input_manager_process_mouse_wheel(im, &event->wheel);
|
||||
return true;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
// some mouse events do not interact with the device, so process
|
||||
// the event even if control is disabled
|
||||
input_manager_process_mouse_button(im, &event->button);
|
||||
sc_input_manager_process_mouse_button(im, &event->button);
|
||||
return true;
|
||||
case SDL_FINGERMOTION:
|
||||
case SDL_FINGERDOWN:
|
||||
case SDL_FINGERUP:
|
||||
input_manager_process_touch(im, &event->tfinger);
|
||||
sc_input_manager_process_touch(im, &event->tfinger);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,9 @@
|
||||
#include "trait/key_processor.h"
|
||||
#include "trait/mouse_processor.h"
|
||||
|
||||
struct input_manager {
|
||||
struct controller *controller;
|
||||
struct screen *screen;
|
||||
struct sc_input_manager {
|
||||
struct sc_controller *controller;
|
||||
struct sc_screen *screen;
|
||||
|
||||
struct sc_key_processor *kp;
|
||||
struct sc_mouse_processor *mp;
|
||||
@ -42,9 +42,9 @@ struct input_manager {
|
||||
uint64_t next_sequence; // used for request acknowledgements
|
||||
};
|
||||
|
||||
struct input_manager_params {
|
||||
struct controller *controller;
|
||||
struct screen *screen;
|
||||
struct sc_input_manager_params {
|
||||
struct sc_controller *controller;
|
||||
struct sc_screen *screen;
|
||||
struct sc_key_processor *kp;
|
||||
struct sc_mouse_processor *mp;
|
||||
|
||||
@ -56,10 +56,10 @@ struct input_manager_params {
|
||||
};
|
||||
|
||||
void
|
||||
input_manager_init(struct input_manager *im,
|
||||
const struct input_manager_params *params);
|
||||
sc_input_manager_init(struct sc_input_manager *im,
|
||||
const struct sc_input_manager_params *params);
|
||||
|
||||
bool
|
||||
input_manager_handle_event(struct input_manager *im, SDL_Event *event);
|
||||
sc_input_manager_handle_event(struct sc_input_manager *im, SDL_Event *event);
|
||||
|
||||
#endif
|
||||
|
@ -246,7 +246,7 @@ convert_meta_state(uint16_t mod) {
|
||||
}
|
||||
|
||||
static bool
|
||||
convert_input_key(const struct sc_key_event *event, struct control_msg *msg,
|
||||
convert_input_key(const struct sc_key_event *event, struct sc_control_msg *msg,
|
||||
enum sc_key_inject_mode key_inject_mode, uint32_t repeat) {
|
||||
msg->type = CONTROL_MSG_TYPE_INJECT_KEYCODE;
|
||||
|
||||
@ -282,9 +282,9 @@ sc_key_processor_process_key(struct sc_key_processor *kp,
|
||||
ki->repeat = 0;
|
||||
}
|
||||
|
||||
struct control_msg msg;
|
||||
struct sc_control_msg msg;
|
||||
if (convert_input_key(event, &msg, ki->key_inject_mode, ki->repeat)) {
|
||||
if (!controller_push_msg(ki->controller, &msg)) {
|
||||
if (!sc_controller_push_msg(ki->controller, &msg)) {
|
||||
LOGW("Could not request 'inject keycode'");
|
||||
}
|
||||
}
|
||||
@ -309,14 +309,14 @@ sc_key_processor_process_text(struct sc_key_processor *kp,
|
||||
}
|
||||
}
|
||||
|
||||
struct control_msg msg;
|
||||
struct sc_control_msg msg;
|
||||
msg.type = CONTROL_MSG_TYPE_INJECT_TEXT;
|
||||
msg.inject_text.text = strdup(event->text);
|
||||
if (!msg.inject_text.text) {
|
||||
LOGW("Could not strdup input text");
|
||||
return;
|
||||
}
|
||||
if (!controller_push_msg(ki->controller, &msg)) {
|
||||
if (!sc_controller_push_msg(ki->controller, &msg)) {
|
||||
free(msg.inject_text.text);
|
||||
LOGW("Could not request 'inject text'");
|
||||
}
|
||||
@ -324,11 +324,12 @@ sc_key_processor_process_text(struct sc_key_processor *kp,
|
||||
|
||||
void
|
||||
sc_keyboard_inject_init(struct sc_keyboard_inject *ki,
|
||||
struct controller *controller,
|
||||
const struct scrcpy_options *options) {
|
||||
struct sc_controller *controller,
|
||||
enum sc_key_inject_mode key_inject_mode,
|
||||
bool forward_key_repeat) {
|
||||
ki->controller = controller;
|
||||
ki->key_inject_mode = options->key_inject_mode;
|
||||
ki->forward_key_repeat = options->forward_key_repeat;
|
||||
ki->key_inject_mode = key_inject_mode;
|
||||
ki->forward_key_repeat = forward_key_repeat;
|
||||
|
||||
ki->repeat = 0;
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
struct sc_keyboard_inject {
|
||||
struct sc_key_processor key_processor; // key processor trait
|
||||
|
||||
struct controller *controller;
|
||||
struct sc_controller *controller;
|
||||
|
||||
// SDL reports repeated events as a boolean, but Android expects the actual
|
||||
// number of repetitions. This variable keeps track of the count.
|
||||
@ -24,7 +24,8 @@ struct sc_keyboard_inject {
|
||||
|
||||
void
|
||||
sc_keyboard_inject_init(struct sc_keyboard_inject *ki,
|
||||
struct controller *controller,
|
||||
const struct scrcpy_options *options);
|
||||
struct sc_controller *controller,
|
||||
enum sc_key_inject_mode key_inject_mode,
|
||||
bool forward_key_repeat);
|
||||
|
||||
#endif
|
||||
|
@ -65,7 +65,7 @@ sc_mouse_processor_process_mouse_motion(struct sc_mouse_processor *mp,
|
||||
|
||||
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
||||
|
||||
struct control_msg msg = {
|
||||
struct sc_control_msg msg = {
|
||||
.type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
||||
.inject_touch_event = {
|
||||
.action = AMOTION_EVENT_ACTION_MOVE,
|
||||
@ -76,7 +76,7 @@ sc_mouse_processor_process_mouse_motion(struct sc_mouse_processor *mp,
|
||||
},
|
||||
};
|
||||
|
||||
if (!controller_push_msg(mi->controller, &msg)) {
|
||||
if (!sc_controller_push_msg(mi->controller, &msg)) {
|
||||
LOGW("Could not request 'inject mouse motion event'");
|
||||
}
|
||||
}
|
||||
@ -86,7 +86,7 @@ sc_mouse_processor_process_mouse_click(struct sc_mouse_processor *mp,
|
||||
const struct sc_mouse_click_event *event) {
|
||||
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
||||
|
||||
struct control_msg msg = {
|
||||
struct sc_control_msg msg = {
|
||||
.type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
||||
.inject_touch_event = {
|
||||
.action = convert_mouse_action(event->action),
|
||||
@ -97,7 +97,7 @@ sc_mouse_processor_process_mouse_click(struct sc_mouse_processor *mp,
|
||||
},
|
||||
};
|
||||
|
||||
if (!controller_push_msg(mi->controller, &msg)) {
|
||||
if (!sc_controller_push_msg(mi->controller, &msg)) {
|
||||
LOGW("Could not request 'inject mouse click event'");
|
||||
}
|
||||
}
|
||||
@ -107,7 +107,7 @@ sc_mouse_processor_process_mouse_scroll(struct sc_mouse_processor *mp,
|
||||
const struct sc_mouse_scroll_event *event) {
|
||||
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
||||
|
||||
struct control_msg msg = {
|
||||
struct sc_control_msg msg = {
|
||||
.type = CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT,
|
||||
.inject_scroll_event = {
|
||||
.position = event->position,
|
||||
@ -117,7 +117,7 @@ sc_mouse_processor_process_mouse_scroll(struct sc_mouse_processor *mp,
|
||||
},
|
||||
};
|
||||
|
||||
if (!controller_push_msg(mi->controller, &msg)) {
|
||||
if (!sc_controller_push_msg(mi->controller, &msg)) {
|
||||
LOGW("Could not request 'inject mouse scroll event'");
|
||||
}
|
||||
}
|
||||
@ -127,7 +127,7 @@ sc_mouse_processor_process_touch(struct sc_mouse_processor *mp,
|
||||
const struct sc_touch_event *event) {
|
||||
struct sc_mouse_inject *mi = DOWNCAST(mp);
|
||||
|
||||
struct control_msg msg = {
|
||||
struct sc_control_msg msg = {
|
||||
.type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
||||
.inject_touch_event = {
|
||||
.action = convert_touch_action(event->action),
|
||||
@ -138,14 +138,14 @@ sc_mouse_processor_process_touch(struct sc_mouse_processor *mp,
|
||||
},
|
||||
};
|
||||
|
||||
if (!controller_push_msg(mi->controller, &msg)) {
|
||||
if (!sc_controller_push_msg(mi->controller, &msg)) {
|
||||
LOGW("Could not request 'inject touch event'");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
sc_mouse_inject_init(struct sc_mouse_inject *mi,
|
||||
struct controller *controller) {
|
||||
struct sc_controller *controller) {
|
||||
mi->controller = controller;
|
||||
|
||||
static const struct sc_mouse_processor_ops ops = {
|
||||
|
@ -12,10 +12,11 @@
|
||||
struct sc_mouse_inject {
|
||||
struct sc_mouse_processor mouse_processor; // mouse processor trait
|
||||
|
||||
struct controller *controller;
|
||||
struct sc_controller *controller;
|
||||
};
|
||||
|
||||
void
|
||||
sc_mouse_inject_init(struct sc_mouse_inject *mi, struct controller *controller);
|
||||
sc_mouse_inject_init(struct sc_mouse_inject *mi,
|
||||
struct sc_controller *controller);
|
||||
|
||||
#endif
|
||||
|
@ -36,14 +36,14 @@
|
||||
|
||||
struct scrcpy {
|
||||
struct sc_server server;
|
||||
struct screen screen;
|
||||
struct sc_screen screen;
|
||||
struct stream stream;
|
||||
struct decoder decoder;
|
||||
struct recorder recorder;
|
||||
#ifdef HAVE_V4L2
|
||||
struct sc_v4l2_sink v4l2_sink;
|
||||
#endif
|
||||
struct controller controller;
|
||||
struct sc_controller controller;
|
||||
struct file_handler file_handler;
|
||||
#ifdef HAVE_AOA_HID
|
||||
struct sc_aoa aoa;
|
||||
@ -192,7 +192,7 @@ handle_event(struct scrcpy *s, const struct scrcpy_options *options,
|
||||
}
|
||||
}
|
||||
|
||||
bool consumed = screen_handle_event(&s->screen, event);
|
||||
bool consumed = sc_screen_handle_event(&s->screen, event);
|
||||
(void) consumed;
|
||||
|
||||
end:
|
||||
@ -535,7 +535,8 @@ aoa_hid_end:
|
||||
// keyboard_input_mode may have been reset if HID mode failed
|
||||
if (options->keyboard_input_mode == SC_KEYBOARD_INPUT_MODE_INJECT) {
|
||||
sc_keyboard_inject_init(&s->keyboard_inject, &s->controller,
|
||||
options);
|
||||
options->key_inject_mode,
|
||||
options->forward_key_repeat);
|
||||
kp = &s->keyboard_inject.key_processor;
|
||||
}
|
||||
|
||||
@ -545,23 +546,23 @@ aoa_hid_end:
|
||||
mp = &s->mouse_inject.mouse_processor;
|
||||
}
|
||||
|
||||
if (!controller_init(&s->controller, s->server.control_socket,
|
||||
acksync)) {
|
||||
if (!sc_controller_init(&s->controller, s->server.control_socket,
|
||||
acksync)) {
|
||||
goto end;
|
||||
}
|
||||
controller_initialized = true;
|
||||
|
||||
if (!controller_start(&s->controller)) {
|
||||
if (!sc_controller_start(&s->controller)) {
|
||||
goto end;
|
||||
}
|
||||
controller_started = true;
|
||||
|
||||
if (options->turn_screen_off) {
|
||||
struct control_msg msg;
|
||||
struct sc_control_msg msg;
|
||||
msg.type = CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE;
|
||||
msg.set_screen_power_mode.mode = SCREEN_POWER_MODE_OFF;
|
||||
|
||||
if (!controller_push_msg(&s->controller, &msg)) {
|
||||
if (!sc_controller_push_msg(&s->controller, &msg)) {
|
||||
LOGW("Could not request 'set screen power mode'");
|
||||
}
|
||||
}
|
||||
@ -572,7 +573,7 @@ aoa_hid_end:
|
||||
const char *window_title =
|
||||
options->window_title ? options->window_title : info->device_name;
|
||||
|
||||
struct screen_params screen_params = {
|
||||
struct sc_screen_params screen_params = {
|
||||
.controller = &s->controller,
|
||||
.kp = kp,
|
||||
.mp = mp,
|
||||
@ -595,7 +596,7 @@ aoa_hid_end:
|
||||
.buffering_time = options->display_buffer,
|
||||
};
|
||||
|
||||
if (!screen_init(&s->screen, &screen_params)) {
|
||||
if (!sc_screen_init(&s->screen, &screen_params)) {
|
||||
goto end;
|
||||
}
|
||||
screen_initialized = true;
|
||||
@ -628,7 +629,7 @@ aoa_hid_end:
|
||||
|
||||
// Close the window immediately on closing, because screen_destroy() may
|
||||
// only be called once the stream thread is joined (it may take time)
|
||||
screen_hide_window(&s->screen);
|
||||
sc_screen_hide_window(&s->screen);
|
||||
|
||||
end:
|
||||
// The stream is not stopped explicitly, because it will stop by itself on
|
||||
@ -645,13 +646,13 @@ end:
|
||||
}
|
||||
#endif
|
||||
if (controller_started) {
|
||||
controller_stop(&s->controller);
|
||||
sc_controller_stop(&s->controller);
|
||||
}
|
||||
if (file_handler_initialized) {
|
||||
file_handler_stop(&s->file_handler);
|
||||
}
|
||||
if (screen_initialized) {
|
||||
screen_interrupt(&s->screen);
|
||||
sc_screen_interrupt(&s->screen);
|
||||
}
|
||||
|
||||
if (server_started) {
|
||||
@ -681,15 +682,15 @@ end:
|
||||
// Destroy the screen only after the stream is guaranteed to be finished,
|
||||
// because otherwise the screen could receive new frames after destruction
|
||||
if (screen_initialized) {
|
||||
screen_join(&s->screen);
|
||||
screen_destroy(&s->screen);
|
||||
sc_screen_join(&s->screen);
|
||||
sc_screen_destroy(&s->screen);
|
||||
}
|
||||
|
||||
if (controller_started) {
|
||||
controller_join(&s->controller);
|
||||
sc_controller_join(&s->controller);
|
||||
}
|
||||
if (controller_initialized) {
|
||||
controller_destroy(&s->controller);
|
||||
sc_controller_destroy(&s->controller);
|
||||
}
|
||||
|
||||
if (recorder_initialized) {
|
||||
|
129
app/src/screen.c
129
app/src/screen.c
@ -12,7 +12,7 @@
|
||||
|
||||
#define DISPLAY_MARGINS 96
|
||||
|
||||
#define DOWNCAST(SINK) container_of(SINK, struct screen, frame_sink)
|
||||
#define DOWNCAST(SINK) container_of(SINK, struct sc_screen, frame_sink)
|
||||
|
||||
static inline struct sc_size
|
||||
get_rotated_size(struct sc_size size, int rotation) {
|
||||
@ -29,7 +29,7 @@ get_rotated_size(struct sc_size size, int rotation) {
|
||||
|
||||
// get the window size in a struct sc_size
|
||||
static struct sc_size
|
||||
get_window_size(const struct screen *screen) {
|
||||
get_window_size(const struct sc_screen *screen) {
|
||||
int width;
|
||||
int height;
|
||||
SDL_GetWindowSize(screen->window, &width, &height);
|
||||
@ -41,7 +41,7 @@ get_window_size(const struct screen *screen) {
|
||||
}
|
||||
|
||||
static struct sc_point
|
||||
get_window_position(const struct screen *screen) {
|
||||
get_window_position(const struct sc_screen *screen) {
|
||||
int x;
|
||||
int y;
|
||||
SDL_GetWindowPosition(screen->window, &x, &y);
|
||||
@ -54,7 +54,7 @@ get_window_position(const struct screen *screen) {
|
||||
|
||||
// set the window size to be applied when fullscreen is disabled
|
||||
static void
|
||||
set_window_size(struct screen *screen, struct sc_size new_size) {
|
||||
set_window_size(struct sc_screen *screen, struct sc_size new_size) {
|
||||
assert(!screen->fullscreen);
|
||||
assert(!screen->maximized);
|
||||
SDL_SetWindowSize(screen->window, new_size.width, new_size.height);
|
||||
@ -157,7 +157,7 @@ get_initial_optimal_size(struct sc_size content_size, uint16_t req_width,
|
||||
}
|
||||
|
||||
static inline void
|
||||
screen_capture_mouse(struct screen *screen, bool capture) {
|
||||
sc_screen_capture_mouse(struct sc_screen *screen, bool capture) {
|
||||
if (SDL_SetRelativeMouseMode(capture)) {
|
||||
LOGE("Could not set relative mouse mode to %s: %s",
|
||||
capture ? "true" : "false", SDL_GetError());
|
||||
@ -168,7 +168,7 @@ screen_capture_mouse(struct screen *screen, bool capture) {
|
||||
}
|
||||
|
||||
static void
|
||||
screen_update_content_rect(struct screen *screen) {
|
||||
sc_screen_update_content_rect(struct sc_screen *screen) {
|
||||
int dw;
|
||||
int dh;
|
||||
SDL_GL_GetDrawableSize(screen->window, &dw, &dh);
|
||||
@ -205,7 +205,7 @@ screen_update_content_rect(struct screen *screen) {
|
||||
}
|
||||
|
||||
static inline SDL_Texture *
|
||||
create_texture(struct screen *screen) {
|
||||
create_texture(struct sc_screen *screen) {
|
||||
SDL_Renderer *renderer = screen->renderer;
|
||||
struct sc_size size = screen->frame_size;
|
||||
SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12,
|
||||
@ -236,9 +236,9 @@ create_texture(struct screen *screen) {
|
||||
// Set the update_content_rect flag if the window or content size may have
|
||||
// changed, so that the content rectangle is recomputed
|
||||
static void
|
||||
screen_render(struct screen *screen, bool update_content_rect) {
|
||||
sc_screen_render(struct sc_screen *screen, bool update_content_rect) {
|
||||
if (update_content_rect) {
|
||||
screen_update_content_rect(screen);
|
||||
sc_screen_update_content_rect(screen);
|
||||
}
|
||||
|
||||
SDL_RenderClear(screen->renderer);
|
||||
@ -282,20 +282,20 @@ screen_render(struct screen *screen, bool update_content_rect) {
|
||||
// <https://stackoverflow.com/a/40693139/1987178>
|
||||
static int
|
||||
event_watcher(void *data, SDL_Event *event) {
|
||||
struct screen *screen = data;
|
||||
struct sc_screen *screen = data;
|
||||
if (event->type == SDL_WINDOWEVENT
|
||||
&& event->window.event == SDL_WINDOWEVENT_RESIZED) {
|
||||
// In practice, it seems to always be called from the same thread in
|
||||
// that specific case. Anyway, it's just a workaround.
|
||||
screen_render(screen, true);
|
||||
sc_screen_render(screen, true);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool
|
||||
screen_frame_sink_open(struct sc_frame_sink *sink) {
|
||||
struct screen *screen = DOWNCAST(sink);
|
||||
sc_screen_frame_sink_open(struct sc_frame_sink *sink) {
|
||||
struct sc_screen *screen = DOWNCAST(sink);
|
||||
(void) screen;
|
||||
#ifndef NDEBUG
|
||||
screen->open = true;
|
||||
@ -306,8 +306,8 @@ screen_frame_sink_open(struct sc_frame_sink *sink) {
|
||||
}
|
||||
|
||||
static void
|
||||
screen_frame_sink_close(struct sc_frame_sink *sink) {
|
||||
struct screen *screen = DOWNCAST(sink);
|
||||
sc_screen_frame_sink_close(struct sc_frame_sink *sink) {
|
||||
struct sc_screen *screen = DOWNCAST(sink);
|
||||
(void) screen;
|
||||
#ifndef NDEBUG
|
||||
screen->open = false;
|
||||
@ -317,8 +317,8 @@ screen_frame_sink_close(struct sc_frame_sink *sink) {
|
||||
}
|
||||
|
||||
static bool
|
||||
screen_frame_sink_push(struct sc_frame_sink *sink, const AVFrame *frame) {
|
||||
struct screen *screen = DOWNCAST(sink);
|
||||
sc_screen_frame_sink_push(struct sc_frame_sink *sink, const AVFrame *frame) {
|
||||
struct sc_screen *screen = DOWNCAST(sink);
|
||||
return sc_video_buffer_push(&screen->vb, frame);
|
||||
}
|
||||
|
||||
@ -326,7 +326,7 @@ static void
|
||||
sc_video_buffer_on_new_frame(struct sc_video_buffer *vb, bool previous_skipped,
|
||||
void *userdata) {
|
||||
(void) vb;
|
||||
struct screen *screen = userdata;
|
||||
struct sc_screen *screen = userdata;
|
||||
|
||||
// event_failed implies previous_skipped (the previous frame may not have
|
||||
// been consumed if the event was not sent)
|
||||
@ -359,7 +359,8 @@ sc_video_buffer_on_new_frame(struct sc_video_buffer *vb, bool previous_skipped,
|
||||
}
|
||||
|
||||
bool
|
||||
screen_init(struct screen *screen, const struct screen_params *params) {
|
||||
sc_screen_init(struct sc_screen *screen,
|
||||
const struct sc_screen_params *params) {
|
||||
screen->resize_pending = false;
|
||||
screen->has_frame = false;
|
||||
screen->fullscreen = false;
|
||||
@ -483,7 +484,7 @@ screen_init(struct screen *screen, const struct screen_params *params) {
|
||||
goto error_destroy_texture;
|
||||
}
|
||||
|
||||
struct input_manager_params im_params = {
|
||||
struct sc_input_manager_params im_params = {
|
||||
.controller = params->controller,
|
||||
.screen = screen,
|
||||
.kp = params->kp,
|
||||
@ -495,17 +496,17 @@ screen_init(struct screen *screen, const struct screen_params *params) {
|
||||
.shortcut_mods = params->shortcut_mods,
|
||||
};
|
||||
|
||||
input_manager_init(&screen->im, &im_params);
|
||||
sc_input_manager_init(&screen->im, &im_params);
|
||||
|
||||
// Reset the window size to trigger a SIZE_CHANGED event, to workaround
|
||||
// HiDPI issues with some SDL renderers when several displays having
|
||||
// different HiDPI scaling are connected
|
||||
SDL_SetWindowSize(screen->window, window_size.width, window_size.height);
|
||||
|
||||
screen_update_content_rect(screen);
|
||||
sc_screen_update_content_rect(screen);
|
||||
|
||||
if (params->fullscreen) {
|
||||
screen_switch_fullscreen(screen);
|
||||
sc_screen_switch_fullscreen(screen);
|
||||
}
|
||||
|
||||
#ifdef CONTINUOUS_RESIZING_WORKAROUND
|
||||
@ -513,9 +514,9 @@ screen_init(struct screen *screen, const struct screen_params *params) {
|
||||
#endif
|
||||
|
||||
static const struct sc_frame_sink_ops ops = {
|
||||
.open = screen_frame_sink_open,
|
||||
.close = screen_frame_sink_close,
|
||||
.push = screen_frame_sink_push,
|
||||
.open = sc_screen_frame_sink_open,
|
||||
.close = sc_screen_frame_sink_close,
|
||||
.push = sc_screen_frame_sink_push,
|
||||
};
|
||||
|
||||
screen->frame_sink.ops = &ops;
|
||||
@ -544,29 +545,29 @@ error_destroy_video_buffer:
|
||||
}
|
||||
|
||||
static void
|
||||
screen_show_window(struct screen *screen) {
|
||||
sc_screen_show_window(struct sc_screen *screen) {
|
||||
SDL_ShowWindow(screen->window);
|
||||
}
|
||||
|
||||
void
|
||||
screen_hide_window(struct screen *screen) {
|
||||
sc_screen_hide_window(struct sc_screen *screen) {
|
||||
SDL_HideWindow(screen->window);
|
||||
}
|
||||
|
||||
void
|
||||
screen_interrupt(struct screen *screen) {
|
||||
sc_screen_interrupt(struct sc_screen *screen) {
|
||||
sc_video_buffer_stop(&screen->vb);
|
||||
fps_counter_interrupt(&screen->fps_counter);
|
||||
}
|
||||
|
||||
void
|
||||
screen_join(struct screen *screen) {
|
||||
sc_screen_join(struct sc_screen *screen) {
|
||||
sc_video_buffer_join(&screen->vb);
|
||||
fps_counter_join(&screen->fps_counter);
|
||||
}
|
||||
|
||||
void
|
||||
screen_destroy(struct screen *screen) {
|
||||
sc_screen_destroy(struct sc_screen *screen) {
|
||||
#ifndef NDEBUG
|
||||
assert(!screen->open);
|
||||
#endif
|
||||
@ -579,7 +580,7 @@ screen_destroy(struct screen *screen) {
|
||||
}
|
||||
|
||||
static void
|
||||
resize_for_content(struct screen *screen, struct sc_size old_content_size,
|
||||
resize_for_content(struct sc_screen *screen, struct sc_size old_content_size,
|
||||
struct sc_size new_content_size) {
|
||||
struct sc_size window_size = get_window_size(screen);
|
||||
struct sc_size target_size = {
|
||||
@ -593,7 +594,7 @@ resize_for_content(struct screen *screen, struct sc_size old_content_size,
|
||||
}
|
||||
|
||||
static void
|
||||
set_content_size(struct screen *screen, struct sc_size new_content_size) {
|
||||
set_content_size(struct sc_screen *screen, struct sc_size new_content_size) {
|
||||
if (!screen->fullscreen && !screen->maximized) {
|
||||
resize_for_content(screen, screen->content_size, new_content_size);
|
||||
} else if (!screen->resize_pending) {
|
||||
@ -607,7 +608,7 @@ set_content_size(struct screen *screen, struct sc_size new_content_size) {
|
||||
}
|
||||
|
||||
static void
|
||||
apply_pending_resize(struct screen *screen) {
|
||||
apply_pending_resize(struct sc_screen *screen) {
|
||||
assert(!screen->fullscreen);
|
||||
assert(!screen->maximized);
|
||||
if (screen->resize_pending) {
|
||||
@ -618,7 +619,7 @@ apply_pending_resize(struct screen *screen) {
|
||||
}
|
||||
|
||||
void
|
||||
screen_set_rotation(struct screen *screen, unsigned rotation) {
|
||||
sc_screen_set_rotation(struct sc_screen *screen, unsigned rotation) {
|
||||
assert(rotation < 4);
|
||||
if (rotation == screen->rotation) {
|
||||
return;
|
||||
@ -632,12 +633,12 @@ screen_set_rotation(struct screen *screen, unsigned rotation) {
|
||||
screen->rotation = rotation;
|
||||
LOGI("Display rotation set to %u", rotation);
|
||||
|
||||
screen_render(screen, true);
|
||||
sc_screen_render(screen, true);
|
||||
}
|
||||
|
||||
// recreate the texture and resize the window if the frame size has changed
|
||||
static bool
|
||||
prepare_for_frame(struct screen *screen, struct sc_size new_frame_size) {
|
||||
prepare_for_frame(struct sc_screen *screen, struct sc_size new_frame_size) {
|
||||
if (screen->frame_size.width != new_frame_size.width
|
||||
|| screen->frame_size.height != new_frame_size.height) {
|
||||
// frame dimension changed, destroy texture
|
||||
@ -649,7 +650,7 @@ prepare_for_frame(struct screen *screen, struct sc_size new_frame_size) {
|
||||
get_rotated_size(new_frame_size, screen->rotation);
|
||||
set_content_size(screen, new_content_size);
|
||||
|
||||
screen_update_content_rect(screen);
|
||||
sc_screen_update_content_rect(screen);
|
||||
|
||||
LOGI("New texture: %" PRIu16 "x%" PRIu16,
|
||||
screen->frame_size.width, screen->frame_size.height);
|
||||
@ -665,7 +666,7 @@ prepare_for_frame(struct screen *screen, struct sc_size new_frame_size) {
|
||||
|
||||
// write the frame into the texture
|
||||
static void
|
||||
update_texture(struct screen *screen, const AVFrame *frame) {
|
||||
update_texture(struct sc_screen *screen, const AVFrame *frame) {
|
||||
SDL_UpdateYUVTexture(screen->texture, NULL,
|
||||
frame->data[0], frame->linesize[0],
|
||||
frame->data[1], frame->linesize[1],
|
||||
@ -679,7 +680,7 @@ update_texture(struct screen *screen, const AVFrame *frame) {
|
||||
}
|
||||
|
||||
static bool
|
||||
screen_update_frame(struct screen *screen) {
|
||||
sc_screen_update_frame(struct sc_screen *screen) {
|
||||
av_frame_unref(screen->frame);
|
||||
sc_video_buffer_consume(&screen->vb, screen->frame);
|
||||
AVFrame *frame = screen->frame;
|
||||
@ -692,12 +693,12 @@ screen_update_frame(struct screen *screen) {
|
||||
}
|
||||
update_texture(screen, frame);
|
||||
|
||||
screen_render(screen, false);
|
||||
sc_screen_render(screen, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
screen_switch_fullscreen(struct screen *screen) {
|
||||
sc_screen_switch_fullscreen(struct sc_screen *screen) {
|
||||
uint32_t new_mode = screen->fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
if (SDL_SetWindowFullscreen(screen->window, new_mode)) {
|
||||
LOGW("Could not switch fullscreen mode: %s", SDL_GetError());
|
||||
@ -710,11 +711,11 @@ screen_switch_fullscreen(struct screen *screen) {
|
||||
}
|
||||
|
||||
LOGD("Switched to %s mode", screen->fullscreen ? "fullscreen" : "windowed");
|
||||
screen_render(screen, true);
|
||||
sc_screen_render(screen, true);
|
||||
}
|
||||
|
||||
void
|
||||
screen_resize_to_fit(struct screen *screen) {
|
||||
sc_screen_resize_to_fit(struct sc_screen *screen) {
|
||||
if (screen->fullscreen || screen->maximized) {
|
||||
return;
|
||||
}
|
||||
@ -738,7 +739,7 @@ screen_resize_to_fit(struct screen *screen) {
|
||||
}
|
||||
|
||||
void
|
||||
screen_resize_to_pixel_perfect(struct screen *screen) {
|
||||
sc_screen_resize_to_pixel_perfect(struct sc_screen *screen) {
|
||||
if (screen->fullscreen) {
|
||||
return;
|
||||
}
|
||||
@ -755,20 +756,20 @@ screen_resize_to_pixel_perfect(struct screen *screen) {
|
||||
}
|
||||
|
||||
static inline bool
|
||||
screen_is_mouse_capture_key(SDL_Keycode key) {
|
||||
sc_screen_is_mouse_capture_key(SDL_Keycode key) {
|
||||
return key == SDLK_LALT || key == SDLK_LGUI || key == SDLK_RGUI;
|
||||
}
|
||||
|
||||
bool
|
||||
screen_handle_event(struct screen *screen, SDL_Event *event) {
|
||||
sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event) {
|
||||
switch (event->type) {
|
||||
case EVENT_NEW_FRAME:
|
||||
if (!screen->has_frame) {
|
||||
screen->has_frame = true;
|
||||
// this is the very first frame, show the window
|
||||
screen_show_window(screen);
|
||||
sc_screen_show_window(screen);
|
||||
}
|
||||
bool ok = screen_update_frame(screen);
|
||||
bool ok = sc_screen_update_frame(screen);
|
||||
if (!ok) {
|
||||
LOGW("Frame update failed\n");
|
||||
}
|
||||
@ -780,10 +781,10 @@ screen_handle_event(struct screen *screen, SDL_Event *event) {
|
||||
}
|
||||
switch (event->window.event) {
|
||||
case SDL_WINDOWEVENT_EXPOSED:
|
||||
screen_render(screen, true);
|
||||
sc_screen_render(screen, true);
|
||||
break;
|
||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||
screen_render(screen, true);
|
||||
sc_screen_render(screen, true);
|
||||
break;
|
||||
case SDL_WINDOWEVENT_MAXIMIZED:
|
||||
screen->maximized = true;
|
||||
@ -799,11 +800,11 @@ screen_handle_event(struct screen *screen, SDL_Event *event) {
|
||||
}
|
||||
screen->maximized = false;
|
||||
apply_pending_resize(screen);
|
||||
screen_render(screen, true);
|
||||
sc_screen_render(screen, true);
|
||||
break;
|
||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||
if (screen->im.mp->relative_mode) {
|
||||
screen_capture_mouse(screen, false);
|
||||
sc_screen_capture_mouse(screen, false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -811,7 +812,7 @@ screen_handle_event(struct screen *screen, SDL_Event *event) {
|
||||
case SDL_KEYDOWN:
|
||||
if (screen->im.mp->relative_mode) {
|
||||
SDL_Keycode key = event->key.keysym.sym;
|
||||
if (screen_is_mouse_capture_key(key)) {
|
||||
if (sc_screen_is_mouse_capture_key(key)) {
|
||||
if (!screen->mouse_capture_key_pressed) {
|
||||
screen->mouse_capture_key_pressed = key;
|
||||
return true;
|
||||
@ -833,7 +834,7 @@ screen_handle_event(struct screen *screen, SDL_Event *event) {
|
||||
if (key == cap) {
|
||||
// A mouse capture key has been pressed then released:
|
||||
// toggle the capture mouse mode
|
||||
screen_capture_mouse(screen, !screen->mouse_captured);
|
||||
sc_screen_capture_mouse(screen, !screen->mouse_captured);
|
||||
return true;
|
||||
}
|
||||
// Do not return, the event must be forwarded to the input
|
||||
@ -860,17 +861,17 @@ screen_handle_event(struct screen *screen, SDL_Event *event) {
|
||||
break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
if (screen->im.mp->relative_mode && !screen->mouse_captured) {
|
||||
screen_capture_mouse(screen, true);
|
||||
sc_screen_capture_mouse(screen, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return input_manager_handle_event(&screen->im, event);
|
||||
return sc_input_manager_handle_event(&screen->im, event);
|
||||
}
|
||||
|
||||
struct sc_point
|
||||
screen_convert_drawable_to_frame_coords(struct screen *screen,
|
||||
int32_t x, int32_t y) {
|
||||
sc_screen_convert_drawable_to_frame_coords(struct sc_screen *screen,
|
||||
int32_t x, int32_t y) {
|
||||
unsigned rotation = screen->rotation;
|
||||
assert(rotation < 4);
|
||||
|
||||
@ -906,14 +907,14 @@ screen_convert_drawable_to_frame_coords(struct screen *screen,
|
||||
}
|
||||
|
||||
struct sc_point
|
||||
screen_convert_window_to_frame_coords(struct screen *screen,
|
||||
int32_t x, int32_t y) {
|
||||
screen_hidpi_scale_coords(screen, &x, &y);
|
||||
return screen_convert_drawable_to_frame_coords(screen, x, y);
|
||||
sc_screen_convert_window_to_frame_coords(struct sc_screen *screen,
|
||||
int32_t x, int32_t y) {
|
||||
sc_screen_hidpi_scale_coords(screen, &x, &y);
|
||||
return sc_screen_convert_drawable_to_frame_coords(screen, x, y);
|
||||
}
|
||||
|
||||
void
|
||||
screen_hidpi_scale_coords(struct screen *screen, int32_t *x, int32_t *y) {
|
||||
sc_screen_hidpi_scale_coords(struct sc_screen *screen, int32_t *x, int32_t *y) {
|
||||
// take the HiDPI scaling (dw/ww and dh/wh) into account
|
||||
int ww, wh, dw, dh;
|
||||
SDL_GetWindowSize(screen->window, &ww, &wh);
|
||||
|
@ -17,14 +17,14 @@
|
||||
#include "trait/mouse_processor.h"
|
||||
#include "video_buffer.h"
|
||||
|
||||
struct screen {
|
||||
struct sc_screen {
|
||||
struct sc_frame_sink frame_sink; // frame sink trait
|
||||
|
||||
#ifndef NDEBUG
|
||||
bool open; // track the open/close state to assert correct behavior
|
||||
#endif
|
||||
|
||||
struct input_manager im;
|
||||
struct sc_input_manager im;
|
||||
struct sc_video_buffer vb;
|
||||
struct fps_counter fps_counter;
|
||||
|
||||
@ -59,8 +59,8 @@ struct screen {
|
||||
AVFrame *frame;
|
||||
};
|
||||
|
||||
struct screen_params {
|
||||
struct controller *controller;
|
||||
struct sc_screen_params {
|
||||
struct sc_controller *controller;
|
||||
struct sc_key_processor *kp;
|
||||
struct sc_mouse_processor *mp;
|
||||
|
||||
@ -91,65 +91,65 @@ struct screen_params {
|
||||
|
||||
// initialize screen, create window, renderer and texture (window is hidden)
|
||||
bool
|
||||
screen_init(struct screen *screen, const struct screen_params *params);
|
||||
sc_screen_init(struct sc_screen *screen, const struct sc_screen_params *params);
|
||||
|
||||
// request to interrupt any inner thread
|
||||
// must be called before screen_join()
|
||||
void
|
||||
screen_interrupt(struct screen *screen);
|
||||
sc_screen_interrupt(struct sc_screen *screen);
|
||||
|
||||
// join any inner thread
|
||||
void
|
||||
screen_join(struct screen *screen);
|
||||
sc_screen_join(struct sc_screen *screen);
|
||||
|
||||
// destroy window, renderer and texture (if any)
|
||||
void
|
||||
screen_destroy(struct screen *screen);
|
||||
sc_screen_destroy(struct sc_screen *screen);
|
||||
|
||||
// hide the window
|
||||
//
|
||||
// It is used to hide the window immediately on closing without waiting for
|
||||
// screen_destroy()
|
||||
void
|
||||
screen_hide_window(struct screen *screen);
|
||||
sc_screen_hide_window(struct sc_screen *screen);
|
||||
|
||||
// switch the fullscreen mode
|
||||
void
|
||||
screen_switch_fullscreen(struct screen *screen);
|
||||
sc_screen_switch_fullscreen(struct sc_screen *screen);
|
||||
|
||||
// resize window to optimal size (remove black borders)
|
||||
void
|
||||
screen_resize_to_fit(struct screen *screen);
|
||||
sc_screen_resize_to_fit(struct sc_screen *screen);
|
||||
|
||||
// resize window to 1:1 (pixel-perfect)
|
||||
void
|
||||
screen_resize_to_pixel_perfect(struct screen *screen);
|
||||
sc_screen_resize_to_pixel_perfect(struct sc_screen *screen);
|
||||
|
||||
// set the display rotation (0, 1, 2 or 3, x90 degrees counterclockwise)
|
||||
void
|
||||
screen_set_rotation(struct screen *screen, unsigned rotation);
|
||||
sc_screen_set_rotation(struct sc_screen *screen, unsigned rotation);
|
||||
|
||||
// react to SDL events
|
||||
bool
|
||||
screen_handle_event(struct screen *screen, SDL_Event *event);
|
||||
sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event);
|
||||
|
||||
// convert point from window coordinates to frame coordinates
|
||||
// x and y are expressed in pixels
|
||||
struct sc_point
|
||||
screen_convert_window_to_frame_coords(struct screen *screen,
|
||||
int32_t x, int32_t y);
|
||||
sc_screen_convert_window_to_frame_coords(struct sc_screen *screen,
|
||||
int32_t x, int32_t y);
|
||||
|
||||
// convert point from drawable coordinates to frame coordinates
|
||||
// x and y are expressed in pixels
|
||||
struct sc_point
|
||||
screen_convert_drawable_to_frame_coords(struct screen *screen,
|
||||
int32_t x, int32_t y);
|
||||
sc_screen_convert_drawable_to_frame_coords(struct sc_screen *screen,
|
||||
int32_t x, int32_t y);
|
||||
|
||||
// Convert coordinates from window to drawable.
|
||||
// Events are expressed in window coordinates, but content is expressed in
|
||||
// drawable coordinates. They are the same if HiDPI scaling is 1, but differ
|
||||
// otherwise.
|
||||
void
|
||||
screen_hidpi_scale_coords(struct screen *screen, int32_t *x, int32_t *y);
|
||||
sc_screen_hidpi_scale_coords(struct sc_screen *screen, int32_t *x, int32_t *y);
|
||||
|
||||
#endif
|
||||
|
@ -188,7 +188,6 @@ execute_server(struct sc_server *server,
|
||||
} \
|
||||
cmd[count++] = p; \
|
||||
}
|
||||
#define STRBOOL(v) (v ? "true" : "false")
|
||||
|
||||
ADD_PARAM("log_level=%s", log_level_to_server_string(params->log_level));
|
||||
ADD_PARAM("bit_rate=%" PRIu32, params->bit_rate);
|
||||
@ -204,23 +203,23 @@ execute_server(struct sc_server *server,
|
||||
params->lock_video_orientation);
|
||||
}
|
||||
if (server->tunnel.forward) {
|
||||
ADD_PARAM("tunnel_forward=%s", STRBOOL(server->tunnel.forward));
|
||||
ADD_PARAM("tunnel_forward=true");
|
||||
}
|
||||
if (params->crop) {
|
||||
ADD_PARAM("crop=%s", params->crop);
|
||||
}
|
||||
if (!params->control) {
|
||||
// By default, control is true
|
||||
ADD_PARAM("control=%s", STRBOOL(params->control));
|
||||
ADD_PARAM("control=false");
|
||||
}
|
||||
if (params->display_id) {
|
||||
ADD_PARAM("display_id=%" PRIu32, params->display_id);
|
||||
}
|
||||
if (params->show_touches) {
|
||||
ADD_PARAM("show_touches=%s", STRBOOL(params->show_touches));
|
||||
ADD_PARAM("show_touches=true");
|
||||
}
|
||||
if (params->stay_awake) {
|
||||
ADD_PARAM("stay_awake=%s", STRBOOL(params->stay_awake));
|
||||
ADD_PARAM("stay_awake=true");
|
||||
}
|
||||
if (params->codec_options) {
|
||||
ADD_PARAM("codec_options=%s", params->codec_options);
|
||||
@ -229,11 +228,11 @@ execute_server(struct sc_server *server,
|
||||
ADD_PARAM("encoder_name=%s", params->encoder_name);
|
||||
}
|
||||
if (params->power_off_on_close) {
|
||||
ADD_PARAM("power_off_on_close=%s", STRBOOL(params->power_off_on_close));
|
||||
ADD_PARAM("power_off_on_close=true");
|
||||
}
|
||||
if (!params->clipboard_autosync) {
|
||||
// By default, clipboard_autosync is true
|
||||
ADD_PARAM("clipboard_autosync=%s", STRBOOL(params->clipboard_autosync));
|
||||
ADD_PARAM("clipboard_autosync=false");
|
||||
}
|
||||
|
||||
#undef ADD_PARAM
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "stream.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <libavformat/avformat.h>
|
||||
#include <libavutil/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -192,7 +191,7 @@ static int
|
||||
run_stream(void *data) {
|
||||
struct stream *stream = data;
|
||||
|
||||
AVCodec *codec = avcodec_find_decoder(AV_CODEC_ID_H264);
|
||||
const AVCodec *codec = avcodec_find_decoder(AV_CODEC_ID_H264);
|
||||
if (!codec) {
|
||||
LOGE("H.264 decoder not found");
|
||||
goto end;
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
|
||||
#include "trait/packet_sink.h"
|
||||
|
@ -3,13 +3,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
|
||||
#include "coords.h"
|
||||
#include "trait/frame_sink.h"
|
||||
#include "video_buffer.h"
|
||||
#include "util/tick.h"
|
||||
|
||||
#include <libavformat/avformat.h>
|
||||
|
||||
struct sc_v4l2_sink {
|
||||
struct sc_frame_sink frame_sink; // frame sink trait
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "control_msg.h"
|
||||
|
||||
static void test_serialize_inject_keycode(void) {
|
||||
struct control_msg msg = {
|
||||
struct sc_control_msg msg = {
|
||||
.type = CONTROL_MSG_TYPE_INJECT_KEYCODE,
|
||||
.inject_keycode = {
|
||||
.action = AKEY_EVENT_ACTION_UP,
|
||||
@ -17,7 +17,7 @@ static void test_serialize_inject_keycode(void) {
|
||||
};
|
||||
|
||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
||||
size_t size = control_msg_serialize(&msg, buf);
|
||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||
assert(size == 14);
|
||||
|
||||
const unsigned char expected[] = {
|
||||
@ -31,7 +31,7 @@ static void test_serialize_inject_keycode(void) {
|
||||
}
|
||||
|
||||
static void test_serialize_inject_text(void) {
|
||||
struct control_msg msg = {
|
||||
struct sc_control_msg msg = {
|
||||
.type = CONTROL_MSG_TYPE_INJECT_TEXT,
|
||||
.inject_text = {
|
||||
.text = "hello, world!",
|
||||
@ -39,7 +39,7 @@ static void test_serialize_inject_text(void) {
|
||||
};
|
||||
|
||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
||||
size_t size = control_msg_serialize(&msg, buf);
|
||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||
assert(size == 18);
|
||||
|
||||
const unsigned char expected[] = {
|
||||
@ -51,7 +51,7 @@ static void test_serialize_inject_text(void) {
|
||||
}
|
||||
|
||||
static void test_serialize_inject_text_long(void) {
|
||||
struct control_msg msg;
|
||||
struct sc_control_msg msg;
|
||||
msg.type = CONTROL_MSG_TYPE_INJECT_TEXT;
|
||||
char text[CONTROL_MSG_INJECT_TEXT_MAX_LENGTH + 1];
|
||||
memset(text, 'a', CONTROL_MSG_INJECT_TEXT_MAX_LENGTH);
|
||||
@ -59,7 +59,7 @@ static void test_serialize_inject_text_long(void) {
|
||||
msg.inject_text.text = text;
|
||||
|
||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
||||
size_t size = control_msg_serialize(&msg, buf);
|
||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||
assert(size == 5 + CONTROL_MSG_INJECT_TEXT_MAX_LENGTH);
|
||||
|
||||
unsigned char expected[5 + CONTROL_MSG_INJECT_TEXT_MAX_LENGTH];
|
||||
@ -74,7 +74,7 @@ static void test_serialize_inject_text_long(void) {
|
||||
}
|
||||
|
||||
static void test_serialize_inject_touch_event(void) {
|
||||
struct control_msg msg = {
|
||||
struct sc_control_msg msg = {
|
||||
.type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
||||
.inject_touch_event = {
|
||||
.action = AMOTION_EVENT_ACTION_DOWN,
|
||||
@ -95,7 +95,7 @@ static void test_serialize_inject_touch_event(void) {
|
||||
};
|
||||
|
||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
||||
size_t size = control_msg_serialize(&msg, buf);
|
||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||
assert(size == 28);
|
||||
|
||||
const unsigned char expected[] = {
|
||||
@ -111,7 +111,7 @@ static void test_serialize_inject_touch_event(void) {
|
||||
}
|
||||
|
||||
static void test_serialize_inject_scroll_event(void) {
|
||||
struct control_msg msg = {
|
||||
struct sc_control_msg msg = {
|
||||
.type = CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT,
|
||||
.inject_scroll_event = {
|
||||
.position = {
|
||||
@ -131,7 +131,7 @@ static void test_serialize_inject_scroll_event(void) {
|
||||
};
|
||||
|
||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
||||
size_t size = control_msg_serialize(&msg, buf);
|
||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||
assert(size == 25);
|
||||
|
||||
const unsigned char expected[] = {
|
||||
@ -146,7 +146,7 @@ static void test_serialize_inject_scroll_event(void) {
|
||||
}
|
||||
|
||||
static void test_serialize_back_or_screen_on(void) {
|
||||
struct control_msg msg = {
|
||||
struct sc_control_msg msg = {
|
||||
.type = CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON,
|
||||
.back_or_screen_on = {
|
||||
.action = AKEY_EVENT_ACTION_UP,
|
||||
@ -154,7 +154,7 @@ static void test_serialize_back_or_screen_on(void) {
|
||||
};
|
||||
|
||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
||||
size_t size = control_msg_serialize(&msg, buf);
|
||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||
assert(size == 2);
|
||||
|
||||
const unsigned char expected[] = {
|
||||
@ -165,12 +165,12 @@ static void test_serialize_back_or_screen_on(void) {
|
||||
}
|
||||
|
||||
static void test_serialize_expand_notification_panel(void) {
|
||||
struct control_msg msg = {
|
||||
struct sc_control_msg msg = {
|
||||
.type = CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL,
|
||||
};
|
||||
|
||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
||||
size_t size = control_msg_serialize(&msg, buf);
|
||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||
assert(size == 1);
|
||||
|
||||
const unsigned char expected[] = {
|
||||
@ -180,12 +180,12 @@ static void test_serialize_expand_notification_panel(void) {
|
||||
}
|
||||
|
||||
static void test_serialize_expand_settings_panel(void) {
|
||||
struct control_msg msg = {
|
||||
struct sc_control_msg msg = {
|
||||
.type = CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL,
|
||||
};
|
||||
|
||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
||||
size_t size = control_msg_serialize(&msg, buf);
|
||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||
assert(size == 1);
|
||||
|
||||
const unsigned char expected[] = {
|
||||
@ -195,12 +195,12 @@ static void test_serialize_expand_settings_panel(void) {
|
||||
}
|
||||
|
||||
static void test_serialize_collapse_panels(void) {
|
||||
struct control_msg msg = {
|
||||
struct sc_control_msg msg = {
|
||||
.type = CONTROL_MSG_TYPE_COLLAPSE_PANELS,
|
||||
};
|
||||
|
||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
||||
size_t size = control_msg_serialize(&msg, buf);
|
||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||
assert(size == 1);
|
||||
|
||||
const unsigned char expected[] = {
|
||||
@ -210,7 +210,7 @@ static void test_serialize_collapse_panels(void) {
|
||||
}
|
||||
|
||||
static void test_serialize_get_clipboard(void) {
|
||||
struct control_msg msg = {
|
||||
struct sc_control_msg msg = {
|
||||
.type = CONTROL_MSG_TYPE_GET_CLIPBOARD,
|
||||
.get_clipboard = {
|
||||
.copy_key = GET_CLIPBOARD_COPY_KEY_COPY,
|
||||
@ -218,7 +218,7 @@ static void test_serialize_get_clipboard(void) {
|
||||
};
|
||||
|
||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
||||
size_t size = control_msg_serialize(&msg, buf);
|
||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||
assert(size == 2);
|
||||
|
||||
const unsigned char expected[] = {
|
||||
@ -229,7 +229,7 @@ static void test_serialize_get_clipboard(void) {
|
||||
}
|
||||
|
||||
static void test_serialize_set_clipboard(void) {
|
||||
struct control_msg msg = {
|
||||
struct sc_control_msg msg = {
|
||||
.type = CONTROL_MSG_TYPE_SET_CLIPBOARD,
|
||||
.set_clipboard = {
|
||||
.sequence = UINT64_C(0x0102030405060708),
|
||||
@ -239,7 +239,7 @@ static void test_serialize_set_clipboard(void) {
|
||||
};
|
||||
|
||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
||||
size_t size = control_msg_serialize(&msg, buf);
|
||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||
assert(size == 27);
|
||||
|
||||
const unsigned char expected[] = {
|
||||
@ -253,7 +253,7 @@ static void test_serialize_set_clipboard(void) {
|
||||
}
|
||||
|
||||
static void test_serialize_set_clipboard_long(void) {
|
||||
struct control_msg msg = {
|
||||
struct sc_control_msg msg = {
|
||||
.type = CONTROL_MSG_TYPE_SET_CLIPBOARD,
|
||||
.set_clipboard = {
|
||||
.sequence = UINT64_C(0x0102030405060708),
|
||||
@ -268,7 +268,7 @@ static void test_serialize_set_clipboard_long(void) {
|
||||
msg.set_clipboard.text = text;
|
||||
|
||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
||||
size_t size = control_msg_serialize(&msg, buf);
|
||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||
assert(size == CONTROL_MSG_MAX_SIZE);
|
||||
|
||||
unsigned char expected[CONTROL_MSG_MAX_SIZE] = {
|
||||
@ -287,7 +287,7 @@ static void test_serialize_set_clipboard_long(void) {
|
||||
}
|
||||
|
||||
static void test_serialize_set_screen_power_mode(void) {
|
||||
struct control_msg msg = {
|
||||
struct sc_control_msg msg = {
|
||||
.type = CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE,
|
||||
.set_screen_power_mode = {
|
||||
.mode = SCREEN_POWER_MODE_NORMAL,
|
||||
@ -295,7 +295,7 @@ static void test_serialize_set_screen_power_mode(void) {
|
||||
};
|
||||
|
||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
||||
size_t size = control_msg_serialize(&msg, buf);
|
||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||
assert(size == 2);
|
||||
|
||||
const unsigned char expected[] = {
|
||||
@ -306,12 +306,12 @@ static void test_serialize_set_screen_power_mode(void) {
|
||||
}
|
||||
|
||||
static void test_serialize_rotate_device(void) {
|
||||
struct control_msg msg = {
|
||||
struct sc_control_msg msg = {
|
||||
.type = CONTROL_MSG_TYPE_ROTATE_DEVICE,
|
||||
};
|
||||
|
||||
unsigned char buf[CONTROL_MSG_MAX_SIZE];
|
||||
size_t size = control_msg_serialize(&msg, buf);
|
||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||
assert(size == 1);
|
||||
|
||||
const unsigned char expected[] = {
|
||||
|
@ -30,11 +30,11 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||
private final AtomicBoolean rotationChanged = new AtomicBoolean();
|
||||
private final ByteBuffer headerBuffer = ByteBuffer.allocate(12);
|
||||
|
||||
private String encoderName;
|
||||
private List<CodecOption> codecOptions;
|
||||
private int bitRate;
|
||||
private int maxFps;
|
||||
private boolean sendFrameMeta;
|
||||
private final String encoderName;
|
||||
private final List<CodecOption> codecOptions;
|
||||
private final int bitRate;
|
||||
private final int maxFps;
|
||||
private final boolean sendFrameMeta;
|
||||
private long ptsOrigin;
|
||||
|
||||
public ScreenEncoder(boolean sendFrameMeta, int bitRate, int maxFps, List<CodecOption> codecOptions, String encoderName) {
|
||||
|
Reference in New Issue
Block a user