Skip to content

Commit

Permalink
Various, see comment
Browse files Browse the repository at this point in the history
Add hotkey toggler and logic to keymon (Menu+A) (disabled by default)
Add logic for countdown and indicator (disabled by default)
Add indicator resource
Add fresh compile of ffmpeg with everything stripped apart from whats needed for this feature (but does contain NEON)
Add libx264 for ffmpeg
Don't add as tool but add to tools menu
Move define to settings.h
Update shell script for controlling screen recorder with better structure
Change cmdline of ffmpeg to a faster encode (still CPU bound)

TODO:
maybe integrate indicator into source instead of using imgpop (but still use imgpop for mainUI) to stop the flickering in UI's of the indicator dot
  • Loading branch information
XK9274 committed Nov 30, 2023
1 parent 4c46656 commit aa86e95
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 62 deletions.
16 changes: 15 additions & 1 deletion src/common/system/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define HISTORY_PATH \
"/mnt/SDCARD/Saves/CurrentProfile/lists/content_history.lpl"
#define DEFAULT_THEME_PATH "/mnt/SDCARD/Themes/Silky by DiMo/"
#define RECORDED_DIR "/mnt/SDCARD/Media/Videos/Recorded"

typedef struct settings_s {
int volume;
Expand Down Expand Up @@ -51,6 +52,9 @@ typedef struct settings_s {
int ingame_double_press;
bool disable_standby;
bool enable_logging;
bool rec_countdown;
bool rec_indicator;
bool rec_hotkey;

char mainui_button_x[JSON_STRING_LEN];
char mainui_button_y[JSON_STRING_LEN];
Expand Down Expand Up @@ -97,7 +101,11 @@ static settings_s __default_settings = (settings_s){
.disable_standby = false,
.enable_logging = false,
.mainui_button_x = "",
.mainui_button_y = ""};
.mainui_button_y = "",
//utility
.rec_countdown = false,
.rec_indicator = false,
.rec_hotkey = false};

void _settings_clone(settings_s *dst, settings_s *src)
{
Expand Down Expand Up @@ -174,6 +182,9 @@ void settings_load(void)
settings.mute = config_flag_get(".muteVolume");
settings.disable_standby = config_flag_get(".disableStandby");
settings.enable_logging = config_flag_get(".logging");
settings.rec_countdown = config_flag_get(".recCountdown");
settings.rec_indicator = config_flag_get(".recIndicator");
settings.rec_hotkey = config_flag_get(".recHotkey");

if (config_flag_get(".noLowBatteryAutoSave")) // flag is deprecated, but keep compatibility
settings.low_battery_autosave_at = 0;
Expand Down Expand Up @@ -304,6 +315,9 @@ void settings_save(void)
config_flag_set(".muteVolume", settings.mute);
config_flag_set(".disableStandby", settings.disable_standby);
config_flag_set(".logging", settings.enable_logging);
config_flag_set(".recCountdown", settings.rec_countdown);
config_flag_set(".recIndicator", settings.rec_indicator);
config_flag_set(".recHotkey", settings.rec_hotkey);
config_setNumber("battery/warnAt", settings.low_battery_warn_at);
config_setNumber("battery/exitAt", settings.low_battery_autosave_at);
config_setNumber("startup/app", settings.startup_application);
Expand Down
8 changes: 7 additions & 1 deletion src/keymon/keymon.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ int main(void)
bool comboKey_volume = false;
bool comboKey_menu = false;
bool comboKey_select = false;

int ticks = getMilliseconds();
int hibernate_start = ticks;
int hibernate_time;
Expand Down Expand Up @@ -563,6 +563,12 @@ int main(void)
applyExtraButtonShortcut(1);
break;
case HW_BTN_A:
if (comboKey_menu) {
if (exists("/mnt/SDCARD/.tmp_update/config/.recHotkey")) {
system("/mnt/SDCARD/.tmp_update/script/screen_recorder.sh toggle &");
}
}
break;
case HW_BTN_B:
if (val == PRESSED && system_state == MODE_MAIN_UI)
temp_flag_set("launch_alt", false);
Expand Down
22 changes: 16 additions & 6 deletions src/tweaks/actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,19 @@ void action_setAltBrightness(void *pt)
config_flag_set(".altBrightness", ((ListItem *)pt)->value);
}

void action_toggleScreenRecIndicator() {
return; // not built yet
void action_toggleScreenRecIndicator(void *pt) {
config_flag_set(".recIndicator", ((ListItem *)pt)->value);
settings.rec_indicator = ((ListItem *)pt)->value == 1;
}

void action_toggleScreenRecCountdown() {
return; // not built yet
void action_toggleScreenRecCountdown(void *pt) {
config_flag_set(".recCountdown", ((ListItem *)pt)->value);
settings.rec_countdown = ((ListItem *)pt)->value == 1;
}

void action_toggleScreenRecHotkey(void *pt) {
config_flag_set(".recHotkey", ((ListItem *)pt)->value);
settings.rec_hotkey = ((ListItem *)pt)->value == 1;
}

void action_hardKillFFmpeg(void *pt) {
Expand All @@ -311,13 +318,16 @@ void action_hardKillFFmpeg(void *pt) {
if (status != 0) {
list_updateStickyNote(item, "Status: Error occurred.");
} else {
list_updateStickyNote(item, "Status: Killed");
list_updateStickyNote(item, "Status: FFmpeg processed stopped");
}
list_changed = true;
}

void action_deleteAllRecordings() {
void action_deleteAllRecordings(void *pt) {
ListItem *item = (ListItem *)pt;
system("rm -f /mnt/SDCARD/Media/Videos/Recorded/*");
list_updateStickyNote(item, "Recorded directory emptied!");
list_changed = true;
}

void action_advancedSetLcdVoltage(void *pt)
Expand Down
25 changes: 16 additions & 9 deletions src/tweaks/menus.h
Original file line number Diff line number Diff line change
Expand Up @@ -663,12 +663,11 @@ void menu_advanced(void *_)
}

void menu_screen_recorder(void *pt) {
const char *recordingActiveFile = "/tmp/recorder_active";
int isRecordingActive = exists(recordingActiveFile);
int isRecordingActive = exists("/tmp/recorder_active");
const char *recordingStatus = isRecordingActive ? "Status: Now recording..." : "Status: Idle.";

if (!_menu_screen_recorder._created) {
_menu_screen_recorder = list_createWithSticky(6, "Screen recorder setup");
_menu_screen_recorder = list_createWithSticky(7, "Screen recorder setup");
list_addItemWithInfoNote(&_menu_screen_recorder,
(ListItem){
.label = "Start/stop recorder",
Expand All @@ -678,26 +677,35 @@ void menu_screen_recorder(void *pt) {
list_addItemWithInfoNote(&_menu_screen_recorder,
(ListItem){
.label = "Toggle indicator icon",
.sticky_note = "Turn the \"recording\" indicator on/off",
.sticky_note = "Turn the indicator on/off",
.item_type = TOGGLE,
.value = (int)settings.enable_logging,
.value = (int)settings.rec_indicator,
.action = action_toggleScreenRecIndicator},
"Toggles the display of a\n"
"a flashing icon to remind you\n"
"that you're still recording.");
list_addItemWithInfoNote(&_menu_screen_recorder,
(ListItem){
.label = "Toggle countdown",
.sticky_note = "Turn the \"countdown\" on/off",
.sticky_note = "Turn the countdown on/off",
.item_type = TOGGLE,
.value = (int)settings.enable_logging,
.value = (int)settings.rec_countdown,
.action = action_toggleScreenRecCountdown},
"Countdown when starting recording");
list_addItemWithInfoNote(&_menu_screen_recorder,
(ListItem){
.label = "Toggle hotkey",
.sticky_note = "Turn the hotkey (Menu+A) on/off ",
.item_type = TOGGLE,
.value = (int)settings.rec_hotkey,
.action = action_toggleScreenRecHotkey},
"Enable the hotkey function.\n\n"
"Recording can be started/stopped\n"
"with Menu+A");
list_addItemWithInfoNote(&_menu_screen_recorder,
(ListItem){
.label = "Reset screen recorder",
.sticky_note = "Hard kill ffmpeg if it's crashed",
.value = (int)settings.enable_logging,
.action = action_hardKillFFmpeg},
"Performs a hard kill of ffmpeg\n"
"WARNING: If you're currently\n"
Expand All @@ -706,7 +714,6 @@ void menu_screen_recorder(void *pt) {
(ListItem){
.label = "Delete all recordings",
.sticky_note = "Empties the recordings directory",
.value = (int)settings.enable_logging,
.action = action_deleteAllRecordings},
"Deletes all recorded videos\n"
"WARNING: This action cannot\n"
Expand Down
25 changes: 11 additions & 14 deletions src/tweaks/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#include "./appstate.h"
#include "./tools_defs.h"

#define RECORDED_DIR "/mnt/SDCARD/Media/Videos/Recorded"

static pthread_t thread_pt;
static bool thread_active = false;
static bool thread_success = false;
Expand Down Expand Up @@ -54,14 +52,14 @@ void _toolDialog(const char *title_str, const char *message_str,
SDL_Flip(video);
}

void _runCommandPopup(const char *tool_name, const char *_cmd, const char *msg)
void _runCommandPopup(const char *tool_name, const char *_cmd)
{
// static char msg_apply[] = "Applying tool...\n \n \n ";
static char msg_apply[] = "Applying tool...\n \n \n ";

keys_enabled = false;
char full_title[STR_MAX];
sprintf(full_title, "Tool: %s", tool_name);
_toolDialog(full_title, msg, false);
_toolDialog(full_title, msg_apply, false);

char cmd[STR_MAX];
strncpy(cmd, _cmd, STR_MAX - 1);
Expand All @@ -78,7 +76,7 @@ void _runCommandPopup(const char *tool_name, const char *_cmd, const char *msg)
msleep(300);
if (!thread_active)
break;
_toolDialog(full_title, msg, true);
_toolDialog(full_title, msg_apply, true);
}

if (video != NULL)
Expand All @@ -97,34 +95,34 @@ void _runCommandPopup(const char *tool_name, const char *_cmd, const char *msg)

void tool_generateCueFiles(void *pt)
{
_runCommandPopup(tools_short_names[0], "/mnt/SDCARD/.tmp_update/script/cue_gen.sh", "Applying tool...\n \n \n " );
_runCommandPopup(tools_short_names[0], "/mnt/SDCARD/.tmp_update/script/cue_gen.sh");
}

void tool_buildShortRomGameList(void *pt)
{
_runCommandPopup(tools_short_names[1], "./bin/gameNameList /mnt/SDCARD /mnt/SDCARD/BIOS/arcade_lists", "Applying tool...\n \n \n ");
_runCommandPopup(tools_short_names[1], "./bin/gameNameList /mnt/SDCARD /mnt/SDCARD/BIOS/arcade_lists");
}

void tool_generateMiyoogamelists(void *pt)
{
_runCommandPopup(tools_short_names[2], "/mnt/SDCARD/.tmp_update/script/miyoogamelist_gen.sh", "Applying tool...\n \n \n ");
_runCommandPopup(tools_short_names[2], "/mnt/SDCARD/.tmp_update/script/miyoogamelist_gen.sh");
}

void tool_screenRecorder(void *pt) {
ListItem *item = (ListItem *)pt;
char cmd[STR_MAX];
char newestFile[STR_MAX / 2];
snprintf(cmd, sizeof(cmd), "/mnt/SDCARD/.tmp_update/script/screen_recorder.sh toggle");
snprintf(cmd, sizeof(cmd), "/mnt/SDCARD/.tmp_update/script/screen_recorder.sh toggle &");
int fileCheck;
fileCheck = exists("/tmp/recorder_active");

if (!fileCheck) {
_runCommandPopup("Screen recorder started", cmd, "Screen recorder");
list_updateStickyNote(item, "Status: Now recording...");
system(cmd);
} else {
_runCommandPopup("Screen recorder stopped", cmd, "Screen recorder");
if (file_findNewest(RECORDED_DIR, newestFile, sizeof(newestFile))) {
char note[STR_MAX];
system(cmd);
snprintf(note, sizeof(note), "Stopped, saved as: %s", newestFile);
list_updateStickyNote(item, note);
} else {
Expand All @@ -137,7 +135,6 @@ void tool_screenRecorder(void *pt) {
static void (*tools_pt[NUM_TOOLS])(void *) = {
tool_generateCueFiles,
tool_buildShortRomGameList,
tool_generateMiyoogamelists,
tool_screenRecorder};
tool_generateMiyoogamelists};

#endif // TWEAKS_TOOLS_H__
3 changes: 1 addition & 2 deletions src/tweaks/tools_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
static char tools_short_names[NUM_TOOLS][STR_MAX] = {
"cue_gen",
"build_short_rom_game_list",
"miyoogamelist_gen",
"screen_recorder"};
"miyoogamelist_gen"};

#endif // TWEAKS_TOOLS_DEFS_H__
Binary file added static/build/.tmp_update/bin/ffmpeg
Binary file not shown.
Binary file added static/build/.tmp_update/lib/libx264.so.155
Binary file not shown.
Binary file added static/build/.tmp_update/res/rec.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

4 comments on commit aa86e95

@belmix
Copy link

@belmix belmix commented on aa86e95 Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not working...
Status: Now recording...
When pressing B (exit in tools) Status: Idle
The directory with Recorded is empty
Toggle indicator icon - not working.
Toggle hotkey - not t working.
Toggle countdown - not t working.

@XK9274
Copy link
Member Author

@XK9274 XK9274 commented on aa86e95 Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not working... Status: Now recording... When pressing B (exit in tools) Status: Idle The directory with Recorded is empty Toggle indicator icon - not working. Toggle hotkey - not t working. Toggle countdown - not t working.

This is on a branch that is not marked as complete, has no PR raised for it and has not been communicated outside you digging through open branches.

You've made no effort to contact me to ask if it's ready, nor have you specified if you've even built the branch and what position you're in to be actively testing this feature

When a PR is raised then we can discuss what problems you're having.

@belmix
Copy link

@belmix belmix commented on aa86e95 Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry thanks for the work, it really works, my mistake

@XK9274
Copy link
Member Author

@XK9274 XK9274 commented on aa86e95 Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry thanks for the work, it really works, my mistake

That's ok, no problem.

When the PR goes up i'll be happy to discuss any issues you face with it and take any suggestions on board πŸ‘

Please sign in to comment.