@@ -38,6 +38,7 @@ struct source_record_filter_context {
3838 bool replayBuffer ;
3939 obs_hotkey_pair_id enableHotkey ;
4040 obs_hotkey_pair_id pauseHotkeys ;
41+ obs_hotkey_id splitHotkey ;
4142 int audio_track ;
4243 obs_weak_source_t * audio_source ;
4344 bool closing ;
@@ -263,7 +264,8 @@ static void start_stream_output_task(void *data)
263264 }
264265 context -> starting_stream_output = false;
265266}
266- static void release_encoders (void * param ) {
267+ static void release_encoders (void * param )
268+ {
267269 struct source_record_filter_context * context = param ;
268270 if (obs_source_enabled (context -> source ) && (context -> replayBuffer || context -> record || context -> stream ))
269271 return ;
@@ -974,6 +976,7 @@ static void *source_record_filter_create(obs_data_t *settings, obs_source_t *sou
974976 context -> last_frontend_event = -1 ;
975977 context -> enableHotkey = OBS_INVALID_HOTKEY_PAIR_ID ;
976978 context -> pauseHotkeys = OBS_INVALID_HOTKEY_PAIR_ID ;
979+ context -> splitHotkey = OBS_INVALID_HOTKEY_ID ;
977980 source_record_filter_update (context , settings );
978981 obs_frontend_add_event_callback (frontend_event , context );
979982 return context ;
@@ -1054,6 +1057,9 @@ static void source_record_filter_destroy(void *data)
10541057 if (context -> pauseHotkeys != OBS_INVALID_HOTKEY_PAIR_ID )
10551058 obs_hotkey_pair_unregister (context -> pauseHotkeys );
10561059
1060+ if (context -> splitHotkey != OBS_INVALID_HOTKEY_ID )
1061+ obs_hotkey_unregister (context -> splitHotkey );
1062+
10571063 source_record_delayed_destroy (context );
10581064}
10591065
@@ -1114,6 +1120,21 @@ static bool source_record_unpause_hotkey(void *data, obs_hotkey_pair_id id, obs_
11141120 return true;
11151121}
11161122
1123+ static void source_record_split_hotkey (void * data , obs_hotkey_id id , obs_hotkey_t * hotkey , bool pressed ) {
1124+ UNUSED_PARAMETER (id );
1125+ UNUSED_PARAMETER (hotkey );
1126+ if (!pressed )
1127+ return ;
1128+ struct source_record_filter_context * context = data ;
1129+ if (!context -> fileOutput )
1130+ return ;
1131+ proc_handler_t * ph = obs_output_get_proc_handler (context -> fileOutput );
1132+ struct calldata cd ;
1133+ calldata_init (& cd );
1134+ proc_handler_call (ph , "split_file" , & cd );
1135+ calldata_free (& cd );
1136+ }
1137+
11171138static void source_record_filter_tick (void * data , float seconds )
11181139{
11191140 UNUSED_PARAMETER (seconds );
@@ -1137,6 +1158,11 @@ static void source_record_filter_tick(void *data, float seconds)
11371158 "source_record.UnpauseRecording" , obs_frontend_get_locale_string ("Basic.Main.UnpauseRecording" ),
11381159 source_record_pause_hotkey , source_record_unpause_hotkey , context , context );
11391160
1161+ if (context -> splitHotkey == OBS_INVALID_HOTKEY_ID )
1162+ context -> splitHotkey = obs_hotkey_register_source (parent , "source_record.SplitRecording" ,
1163+ obs_frontend_get_locale_string ("Basic.Main.SplitFile" ),
1164+ source_record_split_hotkey , context );
1165+
11401166 uint32_t width = obs_source_get_width (parent );
11411167 width += (width & 1 );
11421168 uint32_t height = obs_source_get_height (parent );
@@ -1689,10 +1715,10 @@ static bool pause_record_source(obs_source_t *source, obs_data_t *request_data,
16891715 return false;
16901716
16911717 struct source_record_filter_context * context = obs_obj_get_data (filter );
1718+ obs_source_release (filter );
16921719 if (!context -> fileOutput )
16931720 return false;
16941721 obs_output_pause (context -> fileOutput , true);
1695- obs_source_release (filter );
16961722 return true;
16971723}
16981724
@@ -1703,10 +1729,31 @@ static bool unpause_record_source(obs_source_t *source, obs_data_t *request_data
17031729 return false;
17041730
17051731 struct source_record_filter_context * context = obs_obj_get_data (filter );
1732+ obs_source_release (filter );
17061733 if (!context -> fileOutput )
17071734 return false;
17081735 obs_output_pause (context -> fileOutput , false);
1736+ return true;
1737+ }
1738+
1739+ static bool split_record_source (obs_source_t * source , obs_data_t * request_data , obs_data_t * response_data )
1740+ {
1741+ obs_source_t * filter = get_source_record_filter (source , request_data , response_data , false);
1742+ if (!filter )
1743+ return false;
1744+
1745+ struct source_record_filter_context * context = obs_obj_get_data (filter );
17091746 obs_source_release (filter );
1747+ if (!context -> fileOutput )
1748+ return false;
1749+ proc_handler_t * ph = obs_output_get_proc_handler (context -> fileOutput );
1750+ struct calldata cd ;
1751+ calldata_init (& cd );
1752+ if (!proc_handler_call (ph , "split_file" , & cd )) {
1753+ calldata_free (& cd );
1754+ return false;
1755+ }
1756+ calldata_free (& cd );
17101757 return true;
17111758}
17121759
@@ -1819,6 +1866,37 @@ static void websocket_unpause_record(obs_data_t *request_data, obs_data_t *respo
18191866 obs_data_set_bool (response_data , "success" , success );
18201867}
18211868
1869+ static void websocket_split_record (obs_data_t * request_data , obs_data_t * response_data , void * param )
1870+ {
1871+ UNUSED_PARAMETER (param );
1872+ const char * source_name = obs_data_get_string (request_data , "source" );
1873+ bool success = true;
1874+ if (strlen (source_name )) {
1875+ obs_source_t * source = obs_get_source_by_name (source_name );
1876+ if (!source ) {
1877+ obs_data_set_string (response_data , "error" , "source not found" );
1878+ obs_data_set_bool (response_data , "success" , false);
1879+ return ;
1880+ }
1881+ success = split_record_source (source , request_data , response_data );
1882+ obs_source_release (source );
1883+ } else {
1884+ DARRAY (obs_source_t * ) sources = {0 };
1885+ obs_enum_sources (find_source , & sources );
1886+ obs_enum_scenes (find_source , & sources );
1887+ if (!sources .num ) {
1888+ obs_data_set_string (response_data , "error" , "no source found" );
1889+ obs_data_set_bool (response_data , "success" , false);
1890+ return ;
1891+ }
1892+ for (size_t i = 0 ; i < sources .num ; i ++ ) {
1893+ success = split_record_source (sources .array [i ], request_data , response_data ) && success ;
1894+ }
1895+ da_free (sources );
1896+ }
1897+ obs_data_set_bool (response_data , "success" , success );
1898+ }
1899+
18221900static void websocket_stop_record (obs_data_t * request_data , obs_data_t * response_data , void * param )
18231901{
18241902 UNUSED_PARAMETER (param );
@@ -2119,6 +2197,7 @@ bool obs_module_load(void)
21192197 obs_websocket_vendor_register_request (vendor , "record_start" , websocket_start_record , NULL );
21202198 obs_websocket_vendor_register_request (vendor , "record_pause" , websocket_pause_record , NULL );
21212199 obs_websocket_vendor_register_request (vendor , "record_unpause" , websocket_unpause_record , NULL );
2200+ obs_websocket_vendor_register_request (vendor , "record_split" , websocket_split_record , NULL );
21222201 obs_websocket_vendor_register_request (vendor , "record_stop" , websocket_stop_record , NULL );
21232202 obs_websocket_vendor_register_request (vendor , "replay_buffer_start" , websocket_start_replay_buffer , NULL );
21242203 obs_websocket_vendor_register_request (vendor , "replay_buffer_stop" , websocket_stop_replay_buffer , NULL );
0 commit comments