Skip to content

Commit 0b741f2

Browse files
committed
Add chapter marker support
1 parent 68622d9 commit 0b741f2

File tree

3 files changed

+86
-4
lines changed

3 files changed

+86
-4
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ else()
66
cmake_minimum_required(VERSION 3.18)
77
endif()
88

9-
project(source-record VERSION 0.4.0)
9+
project(source-record VERSION 0.4.1)
1010
set(PROJECT_FULL_NAME "Source Record")
1111

1212
# Set new UUIDs when you start to create a new plugin.

buildspec.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,5 @@
7979
}
8080
},
8181
"name": "source-record",
82-
"version": "0.4.0"
82+
"version": "0.4.1"
8383
}

source-record.c

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct source_record_filter_context {
3939
obs_hotkey_pair_id enableHotkey;
4040
obs_hotkey_pair_id pauseHotkeys;
4141
obs_hotkey_id splitHotkey;
42+
obs_hotkey_id chapterHotkey;
4243
int audio_track;
4344
obs_weak_source_t *audio_source;
4445
bool closing;
@@ -614,7 +615,8 @@ static void set_encoder_defaults(obs_data_t *settings)
614615
obs_data_release(enc_defaults);
615616
}
616617

617-
static void update_encoder(struct source_record_filter_context *filter, obs_data_t *settings) {
618+
static void update_encoder(struct source_record_filter_context *filter, obs_data_t *settings)
619+
{
618620
const char *enc_id = get_encoder_id(settings);
619621
if (!filter->encoder || strcmp(obs_encoder_get_id(filter->encoder), enc_id) != 0) {
620622
obs_encoder_release(filter->encoder);
@@ -975,6 +977,7 @@ static void *source_record_filter_create(obs_data_t *settings, obs_source_t *sou
975977
context->enableHotkey = OBS_INVALID_HOTKEY_PAIR_ID;
976978
context->pauseHotkeys = OBS_INVALID_HOTKEY_PAIR_ID;
977979
context->splitHotkey = OBS_INVALID_HOTKEY_ID;
980+
context->chapterHotkey = OBS_INVALID_HOTKEY_ID;
978981
source_record_filter_update(context, settings);
979982
obs_frontend_add_event_callback(frontend_event, context);
980983
return context;
@@ -1058,6 +1061,9 @@ static void source_record_filter_destroy(void *data)
10581061
if (context->splitHotkey != OBS_INVALID_HOTKEY_ID)
10591062
obs_hotkey_unregister(context->splitHotkey);
10601063

1064+
if (context->chapterHotkey != OBS_INVALID_HOTKEY_ID)
1065+
obs_hotkey_unregister(context->chapterHotkey);
1066+
10611067
source_record_delayed_destroy(context);
10621068
}
10631069

@@ -1118,7 +1124,8 @@ static bool source_record_unpause_hotkey(void *data, obs_hotkey_pair_id id, obs_
11181124
return true;
11191125
}
11201126

1121-
static void source_record_split_hotkey(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey, bool pressed) {
1127+
static void source_record_split_hotkey(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey, bool pressed)
1128+
{
11221129
UNUSED_PARAMETER(id);
11231130
UNUSED_PARAMETER(hotkey);
11241131
if (!pressed)
@@ -1133,6 +1140,22 @@ static void source_record_split_hotkey(void *data, obs_hotkey_id id, obs_hotkey_
11331140
calldata_free(&cd);
11341141
}
11351142

1143+
static void source_record_chapter_hotkey(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey, bool pressed)
1144+
{
1145+
UNUSED_PARAMETER(id);
1146+
UNUSED_PARAMETER(hotkey);
1147+
if (!pressed)
1148+
return;
1149+
struct source_record_filter_context *context = data;
1150+
if (!context->fileOutput)
1151+
return;
1152+
proc_handler_t *ph = obs_output_get_proc_handler(context->fileOutput);
1153+
struct calldata cd;
1154+
calldata_init(&cd);
1155+
proc_handler_call(ph, "add_chapter", &cd);
1156+
calldata_free(&cd);
1157+
}
1158+
11361159
static void source_record_filter_tick(void *data, float seconds)
11371160
{
11381161
UNUSED_PARAMETER(seconds);
@@ -1161,6 +1184,11 @@ static void source_record_filter_tick(void *data, float seconds)
11611184
obs_frontend_get_locale_string("Basic.Main.SplitFile"),
11621185
source_record_split_hotkey, context);
11631186

1187+
if (context->chapterHotkey == OBS_INVALID_HOTKEY_ID)
1188+
context->chapterHotkey = obs_hotkey_register_source(parent, "source_record.AddChapterMarker",
1189+
obs_frontend_get_locale_string("Basic.Main.AddChapterMarker"),
1190+
source_record_chapter_hotkey, context);
1191+
11641192
uint32_t width = obs_source_get_width(parent);
11651193
width += (width & 1);
11661194
uint32_t height = obs_source_get_height(parent);
@@ -1756,6 +1784,28 @@ static bool split_record_source(obs_source_t *source, obs_data_t *request_data,
17561784
return true;
17571785
}
17581786

1787+
static bool add_chapter_record_source(obs_source_t *source, obs_data_t *request_data, obs_data_t *response_data)
1788+
{
1789+
obs_source_t *filter = get_source_record_filter(source, request_data, response_data, false);
1790+
if (!filter)
1791+
return false;
1792+
1793+
struct source_record_filter_context *context = obs_obj_get_data(filter);
1794+
obs_source_release(filter);
1795+
if (!context->fileOutput)
1796+
return false;
1797+
proc_handler_t *ph = obs_output_get_proc_handler(context->fileOutput);
1798+
struct calldata cd;
1799+
calldata_init(&cd);
1800+
calldata_set_string(&cd, "chapter_name", obs_data_get_string(request_data, "chapter_name"));
1801+
if (!proc_handler_call(ph, "add_chapter", &cd)) {
1802+
calldata_free(&cd);
1803+
return false;
1804+
}
1805+
calldata_free(&cd);
1806+
return true;
1807+
}
1808+
17591809
static bool stop_record_source(obs_source_t *source, obs_data_t *request_data, obs_data_t *response_data)
17601810
{
17611811
obs_source_t *filter = get_source_record_filter(source, request_data, response_data, false);
@@ -1896,6 +1946,37 @@ static void websocket_split_record(obs_data_t *request_data, obs_data_t *respons
18961946
obs_data_set_bool(response_data, "success", success);
18971947
}
18981948

1949+
static void websocket_add_chapter_record(obs_data_t *request_data, obs_data_t *response_data, void *param)
1950+
{
1951+
UNUSED_PARAMETER(param);
1952+
const char *source_name = obs_data_get_string(request_data, "source");
1953+
bool success = true;
1954+
if (strlen(source_name)) {
1955+
obs_source_t *source = obs_get_source_by_name(source_name);
1956+
if (!source) {
1957+
obs_data_set_string(response_data, "error", "source not found");
1958+
obs_data_set_bool(response_data, "success", false);
1959+
return;
1960+
}
1961+
success = add_chapter_record_source(source, request_data, response_data);
1962+
obs_source_release(source);
1963+
} else {
1964+
DARRAY(obs_source_t *) sources = {0};
1965+
obs_enum_sources(find_source, &sources);
1966+
obs_enum_scenes(find_source, &sources);
1967+
if (!sources.num) {
1968+
obs_data_set_string(response_data, "error", "no source found");
1969+
obs_data_set_bool(response_data, "success", false);
1970+
return;
1971+
}
1972+
for (size_t i = 0; i < sources.num; i++) {
1973+
success = add_chapter_record_source(sources.array[i], request_data, response_data) && success;
1974+
}
1975+
da_free(sources);
1976+
}
1977+
obs_data_set_bool(response_data, "success", success);
1978+
}
1979+
18991980
static void websocket_stop_record(obs_data_t *request_data, obs_data_t *response_data, void *param)
19001981
{
19011982
UNUSED_PARAMETER(param);
@@ -2197,6 +2278,7 @@ bool obs_module_load(void)
21972278
obs_websocket_vendor_register_request(vendor, "record_pause", websocket_pause_record, NULL);
21982279
obs_websocket_vendor_register_request(vendor, "record_unpause", websocket_unpause_record, NULL);
21992280
obs_websocket_vendor_register_request(vendor, "record_split", websocket_split_record, NULL);
2281+
obs_websocket_vendor_register_request(vendor, "record_add_chapter", websocket_add_chapter_record, NULL);
22002282
obs_websocket_vendor_register_request(vendor, "record_stop", websocket_stop_record, NULL);
22012283
obs_websocket_vendor_register_request(vendor, "replay_buffer_start", websocket_start_replay_buffer, NULL);
22022284
obs_websocket_vendor_register_request(vendor, "replay_buffer_stop", websocket_stop_replay_buffer, NULL);

0 commit comments

Comments
 (0)