Skip to content

Commit eee6a81

Browse files
PenwyRytoEX
authored andcommitted
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.
1 parent 420f9e5 commit eee6a81

4 files changed

Lines changed: 28 additions & 21 deletions

File tree

‎frontend/widgets/OBSBasic.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ private slots:
495495

496496
obs_hotkey_pair_id streamingHotkeys, recordingHotkeys, pauseHotkeys, replayBufHotkeys, vcamHotkeys,
497497
togglePreviewHotkeys, contextBarHotkeys;
498-
obs_hotkey_id forceStreamingStopHotkey, splitFileHotkey, addChapterHotkey;
498+
obs_hotkey_id forceStreamingStopHotkey, splitFileHotkey, addChapterHotkey, saveReplayBufferHotkey;
499499

500500
void InitHotkeys();
501501
void CreateHotkeys();

‎frontend/widgets/OBSBasic_Hotkeys.cpp‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,30 @@ void OBSBasic::CreateHotkeys()
210210
this, this);
211211
LoadHotkeyPair(replayBufHotkeys, "OBSBasic.StartReplayBuffer", "OBSBasic.StopReplayBuffer");
212212

213+
auto replayBufferCallback = [](void *data, obs_hotkey_id, obs_hotkey_t *, bool pressed) {
214+
OBSBasic *basic = static_cast<OBSBasic *>(data);
215+
if (basic->outputHandler->ReplayBufferActive() && pressed) {
216+
blog(LOG_INFO, "Saving replay buffer due to hotkey");
217+
basic->ReplayBufferSave();
218+
}
219+
};
220+
221+
saveReplayBufferHotkey = obs_hotkey_register_frontend("OBSBasic.SaveReplayBuffer", Str("Basic.Main.SaveReplay"),
222+
replayBufferCallback, this);
223+
224+
bool hasSaveReplayHotkey = config_has_user_value(activeConfiguration, "Hotkeys", "OBSBasic.SaveReplayBuffer");
225+
if (hasSaveReplayHotkey) {
226+
LoadHotkey(saveReplayBufferHotkey, "OBSBasic.SaveReplayBuffer");
227+
} else {
228+
OBSDataArrayAutoRelease array = obs_data_get_array(LoadHotkeyData("ReplayBuffer"), "ReplayBuffer.Save");
229+
obs_hotkey_load(saveReplayBufferHotkey, array);
230+
231+
OBSDataAutoRelease newData = obs_data_create();
232+
obs_data_set_array(newData, "bindings", array);
233+
config_set_string(activeConfiguration, "Hotkeys", "OBSBasic.SaveReplayBuffer",
234+
obs_data_get_json(newData));
235+
}
236+
213237
if (vcamEnabled) {
214238
vcamHotkeys = obs_hotkey_pair_register_frontend(
215239
"OBSBasic.StartVirtualCam", Str("Basic.Main.StartVirtualCam"), "OBSBasic.StopVirtualCam",

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

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

102102
ReplayBuffer="Replay Buffer"
103-
ReplayBuffer.Save="Save Replay"
104103

105104
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."
106105
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: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -914,33 +914,23 @@ static const char *replay_buffer_getname(void *type)
914914
return obs_module_text("ReplayBuffer");
915915
}
916916

917-
static void replay_buffer_hotkey(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey, bool pressed)
917+
static void save_replay_proc(void *data, calldata_t *cd)
918918
{
919-
UNUSED_PARAMETER(id);
920-
UNUSED_PARAMETER(hotkey);
921-
922-
if (!pressed)
923-
return;
924919

920+
UNUSED_PARAMETER(cd);
925921
struct ffmpeg_muxer *stream = data;
926922

927923
if (os_atomic_load_bool(&stream->active)) {
928924
obs_encoder_t *vencoder = obs_output_get_video_encoder(stream->output);
929925
if (obs_encoder_paused(vencoder)) {
930-
info("Could not save buffer because encoders paused");
926+
info("Could not save buffer because the encoder is paused");
931927
return;
932928
}
933929

934930
stream->save_ts = os_gettime_ns() / 1000LL;
935931
}
936932
}
937933

938-
static void save_replay_proc(void *data, calldata_t *cd)
939-
{
940-
replay_buffer_hotkey(data, 0, NULL, true);
941-
UNUSED_PARAMETER(cd);
942-
}
943-
944934
static void get_last_replay(void *data, calldata_t *cd)
945935
{
946936
struct ffmpeg_muxer *stream = data;
@@ -954,9 +944,6 @@ static void *replay_buffer_create(obs_data_t *settings, obs_output_t *output)
954944
struct ffmpeg_muxer *stream = bzalloc(sizeof(*stream));
955945
stream->output = output;
956946

957-
stream->hotkey = obs_hotkey_register_output(output, "ReplayBuffer.Save", obs_module_text("ReplayBuffer.Save"),
958-
replay_buffer_hotkey, stream);
959-
960947
proc_handler_t *ph = obs_output_get_proc_handler(output);
961948
proc_handler_add(ph, "void save()", save_replay_proc, stream);
962949
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)
970957

971958
static void replay_buffer_destroy(void *data)
972959
{
973-
struct ffmpeg_muxer *stream = data;
974-
if (stream->hotkey)
975-
obs_hotkey_unregister(stream->hotkey);
976960
ffmpeg_mux_destroy(data);
977961
}
978962

0 commit comments

Comments
 (0)