RPC: Screen streaming & Input injection (#794)
* RPC: Screen stream * Move callback to rpc_screen, implement graceful stop * RPC: Implement input injection * Update protobuf submodule * Gui: thread safe frame buffer callback setter. * RPC: Keep gui record open Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -258,8 +258,7 @@ void gui_cli_screen_stream_callback(uint8_t* data, size_t size, void* context) {
|
||||
void gui_cli_screen_stream(Cli* cli, string_t args, void* context) {
|
||||
furi_assert(context);
|
||||
Gui* gui = context;
|
||||
gui_set_framebuffer_callback_context(gui, gui);
|
||||
gui_set_framebuffer_callback(gui, gui_cli_screen_stream_callback);
|
||||
gui_set_framebuffer_callback(gui, gui_cli_screen_stream_callback, gui);
|
||||
gui_redraw(gui);
|
||||
|
||||
// Wait for control events
|
||||
@@ -279,8 +278,7 @@ void gui_cli_screen_stream(Cli* cli, string_t args, void* context) {
|
||||
}
|
||||
}
|
||||
|
||||
gui_set_framebuffer_callback(gui, NULL);
|
||||
gui_set_framebuffer_callback_context(gui, NULL);
|
||||
gui_set_framebuffer_callback(gui, NULL, NULL);
|
||||
}
|
||||
|
||||
void gui_add_view_port(Gui* gui, ViewPort* view_port, GuiLayer layer) {
|
||||
@@ -387,14 +385,12 @@ void gui_view_port_send_to_back(Gui* gui, ViewPort* view_port) {
|
||||
gui_unlock(gui);
|
||||
}
|
||||
|
||||
void gui_set_framebuffer_callback(Gui* gui, GuiCanvasCommitCallback callback) {
|
||||
void gui_set_framebuffer_callback(Gui* gui, GuiCanvasCommitCallback callback, void* context) {
|
||||
furi_assert(gui);
|
||||
gui_lock(gui);
|
||||
gui->canvas_callback = callback;
|
||||
}
|
||||
|
||||
void gui_set_framebuffer_callback_context(Gui* gui, void* context) {
|
||||
furi_assert(gui);
|
||||
gui->canvas_callback_context = context;
|
||||
gui_unlock(gui);
|
||||
}
|
||||
|
||||
Gui* gui_alloc() {
|
||||
|
@@ -73,15 +73,9 @@ void gui_view_port_send_to_back(Gui* gui, ViewPort* view_port);
|
||||
*
|
||||
* @param gui Gui instance
|
||||
* @param callback GuiCanvasCommitCallback
|
||||
* @param context GuiCanvasCommitCallback context
|
||||
*/
|
||||
void gui_set_framebuffer_callback(Gui* gui, GuiCanvasCommitCallback callback);
|
||||
|
||||
/** Set gui canvas commit callback context
|
||||
*
|
||||
* @param gui Gui instance
|
||||
* @param context pointer to context
|
||||
*/
|
||||
void gui_set_framebuffer_callback_context(Gui* gui, void* context);
|
||||
void gui_set_framebuffer_callback(Gui* gui, GuiCanvasCommitCallback callback, void* context);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@@ -45,6 +45,10 @@ static RpcSystemCallbacks rpc_systems[] = {
|
||||
.alloc = rpc_system_app_alloc,
|
||||
.free = NULL,
|
||||
},
|
||||
{
|
||||
.alloc = rpc_system_gui_alloc,
|
||||
.free = rpc_system_gui_free,
|
||||
},
|
||||
};
|
||||
|
||||
struct RpcSession {
|
||||
@@ -161,10 +165,10 @@ void rpc_print_message(const PB_Main* message) {
|
||||
case PB_Main_stop_session_tag:
|
||||
string_cat_printf(str, "\tstop_session {\r\n");
|
||||
break;
|
||||
case PB_Main_app_start_tag: {
|
||||
case PB_Main_app_start_request_tag: {
|
||||
string_cat_printf(str, "\tapp_start {\r\n");
|
||||
const char* name = message->content.app_start.name;
|
||||
const char* args = message->content.app_start.args;
|
||||
const char* name = message->content.app_start_request.name;
|
||||
const char* args = message->content.app_start_request.args;
|
||||
if(name) {
|
||||
string_cat_printf(str, "\t\tname: %s\r\n", name);
|
||||
}
|
||||
@@ -260,6 +264,22 @@ void rpc_print_message(const PB_Main* message) {
|
||||
string_cat_printf(str, "\tlist_response {\r\n");
|
||||
rpc_sprintf_msg_file(str, "\t\t", msg_file, msg_file_count);
|
||||
}
|
||||
case PB_Main_gui_start_screen_stream_request_tag:
|
||||
string_cat_printf(str, "\tstart_screen_stream {\r\n");
|
||||
break;
|
||||
case PB_Main_gui_stop_screen_stream_request_tag:
|
||||
string_cat_printf(str, "\tstop_screen_stream {\r\n");
|
||||
break;
|
||||
case PB_Main_gui_screen_stream_frame_tag:
|
||||
string_cat_printf(str, "\tscreen_stream_frame {\r\n");
|
||||
break;
|
||||
case PB_Main_gui_send_input_event_request_tag:
|
||||
string_cat_printf(str, "\tsend_input_event {\r\n");
|
||||
string_cat_printf(
|
||||
str, "\t\tkey: %d\r\n", message->content.gui_send_input_event_request.key);
|
||||
string_cat_printf(
|
||||
str, "\t\type: %d\r\n", message->content.gui_send_input_event_request.type);
|
||||
break;
|
||||
}
|
||||
string_cat_printf(str, "\t}\r\n}\r\n");
|
||||
printf("%s", string_get_cstr(str));
|
||||
|
@@ -9,13 +9,13 @@ void rpc_system_app_start_process(const PB_Main* request, void* context) {
|
||||
Rpc* rpc = context;
|
||||
furi_assert(rpc);
|
||||
furi_assert(request);
|
||||
furi_assert(request->which_content == PB_Main_app_start_tag);
|
||||
furi_assert(request->which_content == PB_Main_app_start_request_tag);
|
||||
PB_CommandStatus result = PB_CommandStatus_ERROR_APP_CANT_START;
|
||||
|
||||
Loader* loader = furi_record_open("loader");
|
||||
const char* app_name = request->content.app_start.name;
|
||||
const char* app_name = request->content.app_start_request.name;
|
||||
if(app_name) {
|
||||
const char* app_args = request->content.app_start.args;
|
||||
const char* app_args = request->content.app_start_request.args;
|
||||
LoaderStatus status = loader_start(loader, app_name, app_args);
|
||||
if(status == LoaderStatusErrorAppStarted) {
|
||||
result = PB_CommandStatus_ERROR_APP_SYSTEM_LOCKED;
|
||||
@@ -70,7 +70,7 @@ void* rpc_system_app_alloc(Rpc* rpc) {
|
||||
};
|
||||
|
||||
rpc_handler.message_handler = rpc_system_app_start_process;
|
||||
rpc_add_handler(rpc, PB_Main_app_start_tag, &rpc_handler);
|
||||
rpc_add_handler(rpc, PB_Main_app_start_request_tag, &rpc_handler);
|
||||
|
||||
rpc_handler.message_handler = rpc_system_app_lock_status_process;
|
||||
rpc_add_handler(rpc, PB_Main_app_lock_status_request_tag, &rpc_handler);
|
||||
|
153
applications/rpc/rpc_gui.c
Normal file
153
applications/rpc/rpc_gui.c
Normal file
@@ -0,0 +1,153 @@
|
||||
#include "flipper.pb.h"
|
||||
#include "rpc_i.h"
|
||||
#include "gui.pb.h"
|
||||
#include <gui/gui_i.h>
|
||||
|
||||
typedef struct {
|
||||
Rpc* rpc;
|
||||
Gui* gui;
|
||||
} RpcGuiSystem;
|
||||
|
||||
void rpc_system_gui_screen_frame_callback(uint8_t* data, size_t size, void* context) {
|
||||
furi_assert(data);
|
||||
furi_assert(size == 1024);
|
||||
furi_assert(context);
|
||||
|
||||
RpcGuiSystem* rpc_gui = context;
|
||||
|
||||
PB_Main* frame = furi_alloc(sizeof(PB_Main));
|
||||
|
||||
frame->which_content = PB_Main_gui_screen_stream_frame_tag;
|
||||
frame->command_status = PB_CommandStatus_OK;
|
||||
frame->content.gui_screen_stream_frame.data = furi_alloc(PB_BYTES_ARRAY_T_ALLOCSIZE(size));
|
||||
uint8_t* buffer = frame->content.gui_screen_stream_frame.data->bytes;
|
||||
uint16_t* frame_size_msg = &frame->content.gui_screen_stream_frame.data->size;
|
||||
*frame_size_msg = size;
|
||||
memcpy(buffer, data, size);
|
||||
|
||||
rpc_send_and_release(rpc_gui->rpc, frame);
|
||||
|
||||
free(frame);
|
||||
}
|
||||
|
||||
void rpc_system_gui_start_screen_stream_process(const PB_Main* request, void* context) {
|
||||
furi_assert(request);
|
||||
furi_assert(context);
|
||||
RpcGuiSystem* rpc_gui = context;
|
||||
|
||||
rpc_send_and_release_empty(rpc_gui->rpc, request->command_id, PB_CommandStatus_OK);
|
||||
|
||||
gui_set_framebuffer_callback(rpc_gui->gui, rpc_system_gui_screen_frame_callback, context);
|
||||
}
|
||||
|
||||
void rpc_system_gui_stop_screen_stream_process(const PB_Main* request, void* context) {
|
||||
furi_assert(request);
|
||||
furi_assert(context);
|
||||
RpcGuiSystem* rpc_gui = context;
|
||||
|
||||
rpc_send_and_release_empty(rpc_gui->rpc, request->command_id, PB_CommandStatus_OK);
|
||||
|
||||
gui_set_framebuffer_callback(rpc_gui->gui, NULL, NULL);
|
||||
}
|
||||
|
||||
void rpc_system_gui_send_input_event_request_process(const PB_Main* request, void* context) {
|
||||
furi_assert(request);
|
||||
furi_assert(request->which_content == PB_Main_gui_send_input_event_request_tag);
|
||||
furi_assert(context);
|
||||
RpcGuiSystem* rpc_gui = context;
|
||||
|
||||
InputEvent event;
|
||||
|
||||
bool invalid = false;
|
||||
|
||||
switch(request->content.gui_send_input_event_request.key) {
|
||||
case PB_Gui_InputKey_UP:
|
||||
event.key = InputKeyUp;
|
||||
break;
|
||||
case PB_Gui_InputKey_DOWN:
|
||||
event.key = InputKeyDown;
|
||||
break;
|
||||
case PB_Gui_InputKey_RIGHT:
|
||||
event.key = InputKeyRight;
|
||||
break;
|
||||
case PB_Gui_InputKey_LEFT:
|
||||
event.key = InputKeyLeft;
|
||||
break;
|
||||
case PB_Gui_InputKey_OK:
|
||||
event.key = InputKeyOk;
|
||||
break;
|
||||
case PB_Gui_InputKey_BACK:
|
||||
event.key = InputKeyBack;
|
||||
break;
|
||||
default:
|
||||
// Invalid key
|
||||
invalid = true;
|
||||
break;
|
||||
}
|
||||
|
||||
switch(request->content.gui_send_input_event_request.type) {
|
||||
case PB_Gui_InputType_PRESS:
|
||||
event.type = InputTypePress;
|
||||
break;
|
||||
case PB_Gui_InputType_RELEASE:
|
||||
event.type = InputTypeRelease;
|
||||
break;
|
||||
case PB_Gui_InputType_SHORT:
|
||||
event.type = InputTypeShort;
|
||||
break;
|
||||
case PB_Gui_InputType_LONG:
|
||||
event.type = InputTypeLong;
|
||||
break;
|
||||
case PB_Gui_InputType_REPEAT:
|
||||
event.type = InputTypeRepeat;
|
||||
break;
|
||||
default:
|
||||
// Invalid type
|
||||
invalid = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(invalid) {
|
||||
rpc_send_and_release_empty(
|
||||
rpc_gui->rpc, request->command_id, PB_CommandStatus_ERROR_INVALID_PARAMETERS);
|
||||
return;
|
||||
}
|
||||
|
||||
PubSub* input_events = furi_record_open("input_events");
|
||||
furi_check(input_events);
|
||||
notify_pubsub(input_events, &event);
|
||||
furi_record_close("input_events");
|
||||
rpc_send_and_release_empty(rpc_gui->rpc, request->command_id, PB_CommandStatus_OK);
|
||||
}
|
||||
|
||||
void* rpc_system_gui_alloc(Rpc* rpc) {
|
||||
furi_assert(rpc);
|
||||
|
||||
RpcGuiSystem* rpc_gui = furi_alloc(sizeof(RpcGuiSystem));
|
||||
rpc_gui->gui = furi_record_open("gui");
|
||||
rpc_gui->rpc = rpc;
|
||||
|
||||
RpcHandler rpc_handler = {
|
||||
.message_handler = NULL,
|
||||
.decode_submessage = NULL,
|
||||
.context = rpc_gui,
|
||||
};
|
||||
|
||||
rpc_handler.message_handler = rpc_system_gui_start_screen_stream_process;
|
||||
rpc_add_handler(rpc, PB_Main_gui_start_screen_stream_request_tag, &rpc_handler);
|
||||
|
||||
rpc_handler.message_handler = rpc_system_gui_stop_screen_stream_process;
|
||||
rpc_add_handler(rpc, PB_Main_gui_stop_screen_stream_request_tag, &rpc_handler);
|
||||
|
||||
rpc_handler.message_handler = rpc_system_gui_send_input_event_request_process;
|
||||
rpc_add_handler(rpc, PB_Main_gui_send_input_event_request_tag, &rpc_handler);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void rpc_system_gui_free(void* ctx) {
|
||||
RpcGuiSystem* rpc_gui = ctx;
|
||||
gui_set_framebuffer_callback(rpc_gui->gui, NULL, NULL);
|
||||
furi_record_close("gui");
|
||||
free(rpc_gui);
|
||||
}
|
@@ -24,6 +24,8 @@ void* rpc_system_status_alloc(Rpc* rpc);
|
||||
void* rpc_system_storage_alloc(Rpc* rpc);
|
||||
void rpc_system_storage_free(void* ctx);
|
||||
void* rpc_system_app_alloc(Rpc* rpc);
|
||||
void* rpc_system_gui_alloc(Rpc* rpc);
|
||||
void rpc_system_gui_free(void* ctx);
|
||||
|
||||
void rpc_print_message(const PB_Main* message);
|
||||
void rpc_cli_command_start_session(Cli* cli, string_t args, void* context);
|
||||
|
@@ -1158,23 +1158,23 @@ static void test_app_create_request(
|
||||
request->command_id = command_id;
|
||||
request->command_status = PB_CommandStatus_OK;
|
||||
request->cb_content.funcs.encode = NULL;
|
||||
request->which_content = PB_Main_app_start_tag;
|
||||
request->which_content = PB_Main_app_start_request_tag;
|
||||
request->has_next = false;
|
||||
|
||||
if(app_name) {
|
||||
char* msg_app_name = furi_alloc(strlen(app_name) + 1);
|
||||
strcpy(msg_app_name, app_name);
|
||||
request->content.app_start.name = msg_app_name;
|
||||
request->content.app_start_request.name = msg_app_name;
|
||||
} else {
|
||||
request->content.app_start.name = NULL;
|
||||
request->content.app_start_request.name = NULL;
|
||||
}
|
||||
|
||||
if(app_args) {
|
||||
char* msg_app_args = furi_alloc(strlen(app_args) + 1);
|
||||
strcpy(msg_app_args, app_args);
|
||||
request->content.app_start.args = msg_app_args;
|
||||
request->content.app_start_request.args = msg_app_args;
|
||||
} else {
|
||||
request->content.app_start.args = NULL;
|
||||
request->content.app_start_request.args = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user