Skip to content

Commit bc616ca

Browse files
committed
UI: Register the replay buffer save hotkey in the frontend
Existing registering of the save hotkey in obs-ffmpeg makes it impossible for it to trigger a frontend event, and is inconsistent with other existing output hotkeys. This registers the save hotkey in the frontend and removes the registration in obs-ffmpeg, and adds a "due to hotkey" log message, like other output hotkeys.
1 parent 2d3444b commit bc616ca

4 files changed

Lines changed: 33 additions & 23 deletions

File tree

UI/window-basic-main.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2911,6 +2911,35 @@ void OBSBasic::CreateHotkeys()
29112911
LoadHotkeyPair(replayBufHotkeys, "OBSBasic.StartReplayBuffer",
29122912
"OBSBasic.StopReplayBuffer");
29132913

2914+
auto replayBufferCallback = [](void *data, obs_hotkey_id,
2915+
obs_hotkey_t *, bool pressed) {
2916+
OBSBasic *basic = static_cast<OBSBasic *>(data);
2917+
if (basic->outputHandler->ReplayBufferActive() && pressed) {
2918+
blog(LOG_INFO, "Saving replay buffer due to hotkey");
2919+
basic->ReplayBufferSave();
2920+
}
2921+
};
2922+
2923+
replayBufSaveHotkey = obs_hotkey_register_frontend(
2924+
"OBSBasic.SaveReplayBuffer", Str("Basic.Main.SaveReplay"),
2925+
replayBufferCallback, this);
2926+
2927+
const char *exists = config_get_string(basicConfig, "Hotkeys",
2928+
"OBSBasic.SaveReplayBuffer");
2929+
if (exists) {
2930+
LoadHotkey(replayBufSaveHotkey, "OBSBasic.SaveReplayBuffer");
2931+
} else {
2932+
OBSDataArrayAutoRelease array = obs_data_get_array(
2933+
LoadHotkeyData("ReplayBuffer"), "ReplayBuffer.Save");
2934+
obs_hotkey_load(replayBufSaveHotkey, array);
2935+
2936+
OBSDataAutoRelease newData = obs_data_create();
2937+
obs_data_set_array(newData, "bindings", array);
2938+
config_set_string(basicConfig, "Hotkeys",
2939+
"OBSBasic.SaveReplayBuffer",
2940+
obs_data_get_json(newData));
2941+
}
2942+
29142943
if (vcamEnabled) {
29152944
vcamHotkeys = obs_hotkey_pair_register_frontend(
29162945
"OBSBasic.StartVirtualCam",
@@ -3028,6 +3057,7 @@ void OBSBasic::ClearHotkeys()
30283057
obs_hotkey_unregister(splitFileHotkey);
30293058
obs_hotkey_unregister(addChapterHotkey);
30303059
obs_hotkey_pair_unregister(replayBufHotkeys);
3060+
obs_hotkey_unregister(replayBufSaveHotkey);
30313061
obs_hotkey_pair_unregister(vcamHotkeys);
30323062
obs_hotkey_pair_unregister(togglePreviewHotkeys);
30333063
obs_hotkey_pair_unregister(contextBarHotkeys);

UI/window-basic-main.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ class OBSBasic : public OBSMainWindow {
458458
replayBufHotkeys, vcamHotkeys, togglePreviewHotkeys,
459459
contextBarHotkeys;
460460
obs_hotkey_id forceStreamingStopHotkey, splitFileHotkey,
461-
addChapterHotkey;
461+
addChapterHotkey, replayBufSaveHotkey;
462462

463463
void InitDefaultTransitions();
464464
void InitTransition(obs_source_t *transition);

plugins/obs-ffmpeg/data/locale/en-US.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ MediaFileFilter.AudioFiles="Audio Files"
9797
MediaFileFilter.AllFiles="All Files"
9898

9999
ReplayBuffer="Replay Buffer"
100-
ReplayBuffer.Save="Save Replay"
101100

102101
HelperProcessFailed="Unable to start the recording helper process. Check that OBS files have not been blocked or removed by any 3rd party antivirus / security software."
103102
UnableToWritePath="Unable to write to %1. Make sure you're using a recording path which your user account is allowed to write to and that there is sufficient disk space."

plugins/obs-ffmpeg/obs-ffmpeg-mux.c

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -971,32 +971,21 @@ static const char *replay_buffer_getname(void *type)
971971
return obs_module_text("ReplayBuffer");
972972
}
973973

974-
static void replay_buffer_hotkey(void *data, obs_hotkey_id id,
975-
obs_hotkey_t *hotkey, bool pressed)
974+
static void save_replay_proc(void *data, calldata_t *cd)
976975
{
977-
UNUSED_PARAMETER(id);
978-
UNUSED_PARAMETER(hotkey);
979-
980-
if (!pressed)
981-
return;
982976

983977
struct ffmpeg_muxer *stream = data;
984978

985979
if (os_atomic_load_bool(&stream->active)) {
986980
obs_encoder_t *vencoder =
987981
obs_output_get_video_encoder(stream->output);
988982
if (obs_encoder_paused(vencoder)) {
989-
info("Could not save buffer because encoders paused");
983+
info("Could not save buffer because the encoder is paused");
990984
return;
991985
}
992986

993987
stream->save_ts = os_gettime_ns() / 1000LL;
994988
}
995-
}
996-
997-
static void save_replay_proc(void *data, calldata_t *cd)
998-
{
999-
replay_buffer_hotkey(data, 0, NULL, true);
1000989
UNUSED_PARAMETER(cd);
1001990
}
1002991

@@ -1013,11 +1002,6 @@ static void *replay_buffer_create(obs_data_t *settings, obs_output_t *output)
10131002
struct ffmpeg_muxer *stream = bzalloc(sizeof(*stream));
10141003
stream->output = output;
10151004

1016-
stream->hotkey =
1017-
obs_hotkey_register_output(output, "ReplayBuffer.Save",
1018-
obs_module_text("ReplayBuffer.Save"),
1019-
replay_buffer_hotkey, stream);
1020-
10211005
proc_handler_t *ph = obs_output_get_proc_handler(output);
10221006
proc_handler_add(ph, "void save()", save_replay_proc, stream);
10231007
proc_handler_add(ph, "void get_last_replay(out string path)",
@@ -1032,9 +1016,6 @@ static void *replay_buffer_create(obs_data_t *settings, obs_output_t *output)
10321016

10331017
static void replay_buffer_destroy(void *data)
10341018
{
1035-
struct ffmpeg_muxer *stream = data;
1036-
if (stream->hotkey)
1037-
obs_hotkey_unregister(stream->hotkey);
10381019
ffmpeg_mux_destroy(data);
10391020
}
10401021

0 commit comments

Comments
 (0)