@@ -42,6 +42,7 @@ struct replay_source {
4242 uint64_t start_timestamp ;
4343 uint64_t last_frame_timestamp ;
4444 uint64_t previous_frame_timestamp ;
45+ uint64_t pause_timestamp ;
4546
4647 bool play ;
4748 bool restart ;
@@ -150,7 +151,13 @@ static void replay_source_active(void *data)
150151 struct replay_source * context = data ;
151152 if (context -> visibility_action == VISIBILITY_ACTION_PAUSE || context -> visibility_action == VISIBILITY_ACTION_CONTINUE )
152153 {
153- context -> play = true;
154+ if (!context -> play ){
155+ context -> play = true;
156+ if (context -> pause_timestamp )
157+ {
158+ context -> start_timestamp += obs_get_video_frame_time () - context -> pause_timestamp ;
159+ }
160+ }
154161 }
155162 else if (context -> visibility_action == VISIBILITY_ACTION_RESTART )
156163 {
@@ -165,7 +172,10 @@ static void replay_source_deactive(void *data)
165172 struct replay_source * context = data ;
166173 if (context -> visibility_action == VISIBILITY_ACTION_PAUSE )
167174 {
168- context -> play = false;
175+ if (context -> play ){
176+ context -> play = false;
177+ context -> pause_timestamp = obs_get_video_frame_time ();
178+ }
169179 }
170180 else if (context -> visibility_action == VISIBILITY_ACTION_RESTART )
171181 {
@@ -198,27 +208,30 @@ static void replay_pause_hotkey(void *data, obs_hotkey_id id,
198208 struct replay_source * c = data ;
199209
200210 if (pressed ){
201- c -> play = !c -> play ;
211+ if (c -> play )
212+ {
213+ c -> play = false;
214+ c -> pause_timestamp = obs_get_video_frame_time ();
215+ }else
216+ {
217+ c -> play = true;
218+ if (c -> pause_timestamp )
219+ {
220+ c -> start_timestamp += obs_get_video_frame_time () - c -> pause_timestamp ;
221+ }
222+ }
202223 }
203224}
204225
205- static void replay_hotkey (void * data , obs_hotkey_id id ,
206- obs_hotkey_t * hotkey , bool pressed )
226+ static void replay_retrive (struct replay_source * c )
207227{
208- UNUSED_PARAMETER (id );
209- UNUSED_PARAMETER (hotkey );
210-
211- struct replay_source * c = data ;
212-
213- if (!pressed || !c -> source_name )
214- return ;
215228
216229 obs_source_t * s = obs_get_source_by_name (c -> source_name );
217230 if (!s )
218231 return ;
219232
220233 c -> source_filter = NULL ;
221- obs_source_enum_filters (s , EnumFilter , data );
234+ obs_source_enum_filters (s , EnumFilter , c );
222235 if (c -> source_filter )
223236 {
224237 struct replay_filter * d = c -> source_filter -> context .data ;
@@ -236,6 +249,7 @@ static void replay_hotkey(void *data, obs_hotkey_id id,
236249 }
237250 }
238251 c -> start_timestamp = obs_get_video_frame_time ();
252+ c -> pause_timestamp = 0 ;
239253 if (d -> video_frames .size ){
240254 circlebuf_peek_front (& d -> video_frames , & frame , sizeof (struct obs_source_frame * ));
241255 c -> first_frame_timestamp = frame -> timestamp ;
@@ -257,6 +271,19 @@ static void replay_hotkey(void *data, obs_hotkey_id id,
257271 obs_source_release (s );
258272}
259273
274+ static void replay_hotkey (void * data , obs_hotkey_id id ,
275+ obs_hotkey_t * hotkey , bool pressed )
276+ {
277+ UNUSED_PARAMETER (id );
278+ UNUSED_PARAMETER (hotkey );
279+
280+ struct replay_source * c = data ;
281+ if (!pressed || !c -> source_name )
282+ return ;
283+
284+ replay_retrive (c );
285+ }
286+
260287
261288static void * replay_source_create (obs_data_t * settings , obs_source_t * source )
262289{
@@ -330,6 +357,7 @@ static void replay_source_tick(void *data, float seconds)
330357 if (context -> first_frame_timestamp == peek_frame -> timestamp )
331358 {
332359 context -> start_timestamp = timestamp ;
360+ context -> pause_timestamp = 0 ;
333361 context -> restart = false;
334362 }
335363 else if (context -> restart )
@@ -347,6 +375,7 @@ static void replay_source_tick(void *data, float seconds)
347375 }
348376 context -> restart = false;
349377 context -> start_timestamp = timestamp ;
378+ context -> pause_timestamp = 0 ;
350379 }
351380 uint64_t video_duration = timestamp - context -> start_timestamp ;
352381 uint64_t source_duration = (peek_frame -> timestamp - context -> first_frame_timestamp ) * 100 / context -> speed_percent ;
@@ -375,6 +404,7 @@ static void replay_source_tick(void *data, float seconds)
375404 if (context -> first_frame_timestamp == peek_frame -> timestamp )
376405 {
377406 context -> start_timestamp = timestamp ;
407+ context -> pause_timestamp = 0 ;
378408 video_duration = timestamp - context -> start_timestamp ;
379409 }
380410 }
@@ -395,6 +425,13 @@ static bool EnumSources(void *data, obs_source_t *source)
395425 return true;
396426}
397427
428+ static bool replay_button (obs_properties_t * props , obs_property_t * property , void * data )
429+ {
430+ struct replay_source * s = data ;
431+ replay_retrive (s );
432+ return false; // no properties changed
433+ }
434+
398435static obs_properties_t * replay_source_properties (void * data )
399436{
400437 struct replay_source * s = data ;
@@ -422,6 +459,8 @@ static obs_properties_t *replay_source_properties(void *data)
422459 obs_properties_add_int_slider (props , "speed_percent" ,
423460 obs_module_text ("SpeedPercentage" ), 1 , 200 , 1 );
424461
462+ obs_properties_add_button (props ,"replay_button" ,"Get replay" , replay_button );
463+
425464 return props ;
426465}
427466
0 commit comments