From 219fabfb2b80f8d37636b74631f46b7a3ed8bfc8 Mon Sep 17 00:00:00 2001 From: derrod Date: Thu, 2 May 2024 07:04:49 +0200 Subject: [PATCH] UI: Add chapter frontend API and hotkey --- UI/api-interface.cpp | 17 +++++++++++++++++ UI/data/locale/en-US.ini | 1 + UI/obs-frontend-api/obs-frontend-api.cpp | 6 ++++++ UI/obs-frontend-api/obs-frontend-api.h | 1 + UI/obs-frontend-api/obs-frontend-internal.hpp | 1 + UI/window-basic-main.cpp | 18 ++++++++++++++++++ UI/window-basic-main.hpp | 3 ++- 7 files changed, 46 insertions(+), 1 deletion(-) diff --git a/UI/api-interface.cpp b/UI/api-interface.cpp index e150511b99a8c5..39f260277db305 100644 --- a/UI/api-interface.cpp +++ b/UI/api-interface.cpp @@ -337,6 +337,23 @@ struct OBSStudioAPI : obs_frontend_callbacks { } } + bool obs_frontend_recording_add_chapter(const char *name) override + { + if (!os_atomic_load_bool(&recording_active) || + os_atomic_load_bool(&recording_paused)) + return false; + + proc_handler_t *ph = obs_output_get_proc_handler( + main->outputHandler->fileOutput); + + calldata cd; + calldata_init(&cd); + calldata_set_string(&cd, "chapter_name", name); + bool result = proc_handler_call(ph, "add_chapter", &cd); + calldata_free(&cd); + return result; + } + void obs_frontend_replay_buffer_start(void) override { QMetaObject::invokeMethod(main, "StartReplayBuffer"); diff --git a/UI/data/locale/en-US.ini b/UI/data/locale/en-US.ini index b0681b67099fb3..5a9cc0d62fa5e6 100644 --- a/UI/data/locale/en-US.ini +++ b/UI/data/locale/en-US.ini @@ -732,6 +732,7 @@ Basic.Main.StopRecording="Stop Recording" Basic.Main.PauseRecording="Pause Recording" Basic.Main.UnpauseRecording="Unpause Recording" Basic.Main.SplitFile="Split Recording File" +Basic.Main.AddChapterMarker="Add Chapter Marker" Basic.Main.StoppingRecording="Stopping Recording..." Basic.Main.StopReplayBuffer="Stop Replay Buffer" Basic.Main.StoppingReplayBuffer="Stopping Replay Buffer..." diff --git a/UI/obs-frontend-api/obs-frontend-api.cpp b/UI/obs-frontend-api/obs-frontend-api.cpp index df753551b10e05..7a98d5b0fdbe3c 100644 --- a/UI/obs-frontend-api/obs-frontend-api.cpp +++ b/UI/obs-frontend-api/obs-frontend-api.cpp @@ -285,6 +285,12 @@ bool obs_frontend_recording_split_file(void) : false; } +bool obs_frontend_recording_add_chapter(const char *name) +{ + return !!callbacks_valid() ? c->obs_frontend_recording_add_chapter(name) + : false; +} + void obs_frontend_replay_buffer_start(void) { if (callbacks_valid()) diff --git a/UI/obs-frontend-api/obs-frontend-api.h b/UI/obs-frontend-api/obs-frontend-api.h index a0913e683359f1..063aa4aa184a18 100644 --- a/UI/obs-frontend-api/obs-frontend-api.h +++ b/UI/obs-frontend-api/obs-frontend-api.h @@ -190,6 +190,7 @@ EXPORT bool obs_frontend_recording_active(void); EXPORT void obs_frontend_recording_pause(bool pause); EXPORT bool obs_frontend_recording_paused(void); EXPORT bool obs_frontend_recording_split_file(void); +EXPORT bool obs_frontend_recording_add_chapter(const char *name); EXPORT void obs_frontend_replay_buffer_start(void); EXPORT void obs_frontend_replay_buffer_save(void); diff --git a/UI/obs-frontend-api/obs-frontend-internal.hpp b/UI/obs-frontend-api/obs-frontend-internal.hpp index 90a0e06ea9dd5b..1e600619962f15 100644 --- a/UI/obs-frontend-api/obs-frontend-internal.hpp +++ b/UI/obs-frontend-api/obs-frontend-internal.hpp @@ -53,6 +53,7 @@ struct obs_frontend_callbacks { virtual void obs_frontend_recording_pause(bool pause) = 0; virtual bool obs_frontend_recording_paused(void) = 0; virtual bool obs_frontend_recording_split_file(void) = 0; + virtual bool obs_frontend_recording_add_chapter(const char *name) = 0; virtual void obs_frontend_replay_buffer_start(void) = 0; virtual void obs_frontend_replay_buffer_save(void) = 0; diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index 2519f8e2cfcb19..92ddae13e0aadb 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -2796,6 +2796,23 @@ void OBSBasic::CreateHotkeys() this); LoadHotkey(splitFileHotkey, "OBSBasic.SplitFile"); + /* Adding chapters is only supported by the native MP4 output */ + const string_view output_id = + obs_output_get_id(outputHandler->fileOutput); + if (output_id == "mp4_output") { + addChapterHotkey = obs_hotkey_register_frontend( + "OBSBasic.AddChapterMarker", + Str("Basic.Main.AddChapterMarker"), + [](void *, obs_hotkey_id, obs_hotkey_t *, + bool pressed) { + if (pressed) + obs_frontend_recording_add_chapter( + nullptr); + }, + this); + LoadHotkey(addChapterHotkey, "OBSBasic.AddChapterMarker"); + } + replayBufHotkeys = obs_hotkey_pair_register_frontend( "OBSBasic.StartReplayBuffer", Str("Basic.Main.StartReplayBuffer"), @@ -2924,6 +2941,7 @@ void OBSBasic::ClearHotkeys() obs_hotkey_pair_unregister(recordingHotkeys); obs_hotkey_pair_unregister(pauseHotkeys); obs_hotkey_unregister(splitFileHotkey); + obs_hotkey_unregister(addChapterHotkey); obs_hotkey_pair_unregister(replayBufHotkeys); obs_hotkey_pair_unregister(vcamHotkeys); obs_hotkey_pair_unregister(togglePreviewHotkeys); diff --git a/UI/window-basic-main.hpp b/UI/window-basic-main.hpp index 7a15f13f990b31..cbd61459854186 100644 --- a/UI/window-basic-main.hpp +++ b/UI/window-basic-main.hpp @@ -460,7 +460,8 @@ class OBSBasic : public OBSMainWindow { obs_hotkey_pair_id streamingHotkeys, recordingHotkeys, pauseHotkeys, replayBufHotkeys, vcamHotkeys, togglePreviewHotkeys, contextBarHotkeys; - obs_hotkey_id forceStreamingStopHotkey, splitFileHotkey; + obs_hotkey_id forceStreamingStopHotkey, splitFileHotkey, + addChapterHotkey; void InitDefaultTransitions(); void InitTransition(obs_source_t *transition);