frontend: 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.
This commit is contained in:
Penwywern
2026-09-01 15:44:00 -04:00
committed by Ryan Foster
parent 420f9e5490
commit eee6a81ddc
4 changed files with 28 additions and 21 deletions
+1 -1
View File
@@ -495,7 +495,7 @@ private:
obs_hotkey_pair_id streamingHotkeys, recordingHotkeys, pauseHotkeys, replayBufHotkeys, vcamHotkeys,
togglePreviewHotkeys, contextBarHotkeys;
obs_hotkey_id forceStreamingStopHotkey, splitFileHotkey, addChapterHotkey;
obs_hotkey_id forceStreamingStopHotkey, splitFileHotkey, addChapterHotkey, saveReplayBufferHotkey;
void InitHotkeys();
void CreateHotkeys();
+24
View File
@@ -210,6 +210,30 @@ void OBSBasic::CreateHotkeys()
this, this);
LoadHotkeyPair(replayBufHotkeys, "OBSBasic.StartReplayBuffer", "OBSBasic.StopReplayBuffer");
auto replayBufferCallback = [](void *data, obs_hotkey_id, obs_hotkey_t *, bool pressed) {
OBSBasic *basic = static_cast<OBSBasic *>(data);
if (basic->outputHandler->ReplayBufferActive() && pressed) {
blog(LOG_INFO, "Saving replay buffer due to hotkey");
basic->ReplayBufferSave();
}
};
saveReplayBufferHotkey = obs_hotkey_register_frontend("OBSBasic.SaveReplayBuffer", Str("Basic.Main.SaveReplay"),
replayBufferCallback, this);
bool hasSaveReplayHotkey = config_has_user_value(activeConfiguration, "Hotkeys", "OBSBasic.SaveReplayBuffer");
if (hasSaveReplayHotkey) {
LoadHotkey(saveReplayBufferHotkey, "OBSBasic.SaveReplayBuffer");
} else {
OBSDataArrayAutoRelease array = obs_data_get_array(LoadHotkeyData("ReplayBuffer"), "ReplayBuffer.Save");
obs_hotkey_load(saveReplayBufferHotkey, array);
OBSDataAutoRelease newData = obs_data_create();
obs_data_set_array(newData, "bindings", array);
config_set_string(activeConfiguration, "Hotkeys", "OBSBasic.SaveReplayBuffer",
obs_data_get_json(newData));
}
if (vcamEnabled) {
vcamHotkeys = obs_hotkey_pair_register_frontend(
"OBSBasic.StartVirtualCam", Str("Basic.Main.StartVirtualCam"), "OBSBasic.StopVirtualCam",
-1
View File
@@ -100,7 +100,6 @@ MediaFileFilter.AudioFiles="Audio Files"
MediaFileFilter.AllFiles="All Files"
ReplayBuffer="Replay Buffer"
ReplayBuffer.Save="Save Replay"
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."
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."
+3 -19
View File
@@ -914,20 +914,16 @@ static const char *replay_buffer_getname(void *type)
return obs_module_text("ReplayBuffer");
}
static void replay_buffer_hotkey(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey, bool pressed)
static void save_replay_proc(void *data, calldata_t *cd)
{
UNUSED_PARAMETER(id);
UNUSED_PARAMETER(hotkey);
if (!pressed)
return;
UNUSED_PARAMETER(cd);
struct ffmpeg_muxer *stream = data;
if (os_atomic_load_bool(&stream->active)) {
obs_encoder_t *vencoder = obs_output_get_video_encoder(stream->output);
if (obs_encoder_paused(vencoder)) {
info("Could not save buffer because encoders paused");
info("Could not save buffer because the encoder is paused");
return;
}
@@ -935,12 +931,6 @@ static void replay_buffer_hotkey(void *data, obs_hotkey_id id, obs_hotkey_t *hot
}
}
static void save_replay_proc(void *data, calldata_t *cd)
{
replay_buffer_hotkey(data, 0, NULL, true);
UNUSED_PARAMETER(cd);
}
static void get_last_replay(void *data, calldata_t *cd)
{
struct ffmpeg_muxer *stream = data;
@@ -954,9 +944,6 @@ static void *replay_buffer_create(obs_data_t *settings, obs_output_t *output)
struct ffmpeg_muxer *stream = bzalloc(sizeof(*stream));
stream->output = output;
stream->hotkey = obs_hotkey_register_output(output, "ReplayBuffer.Save", obs_module_text("ReplayBuffer.Save"),
replay_buffer_hotkey, stream);
proc_handler_t *ph = obs_output_get_proc_handler(output);
proc_handler_add(ph, "void save()", save_replay_proc, stream);
proc_handler_add(ph, "void get_last_replay(out string path)", get_last_replay, stream);
@@ -970,9 +957,6 @@ static void *replay_buffer_create(obs_data_t *settings, obs_output_t *output)
static void replay_buffer_destroy(void *data)
{
struct ffmpeg_muxer *stream = data;
if (stream->hotkey)
obs_hotkey_unregister(stream->hotkey);
ffmpeg_mux_destroy(data);
}