Skip to content

Commit ae525d3

Browse files
committed
fix visibility action option
add visibility action none add extra null checks remove warnings
1 parent 1844bb3 commit ae525d3

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

replay-source.c

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define VISIBILITY_ACTION_RESTART 0
2222
#define VISIBILITY_ACTION_PAUSE 1
2323
#define VISIBILITY_ACTION_CONTINUE 2
24+
#define VISIBILITY_ACTION_NONE 3
2425

2526
#define END_ACTION_HIDE 0
2627
#define END_ACTION_PAUSE 1
@@ -100,11 +101,11 @@ static void replay_source_update(void *data, obs_data_t *settings)
100101
context->source_name = bstrdup(source_name);
101102
}
102103

103-
context->duration = obs_data_get_int(settings, "duration");
104-
context->visibility_action = obs_data_get_int(settings, "visibility_action");
105-
context->end_action = obs_data_get_int(settings, "end_action");
104+
context->duration = (long)obs_data_get_int(settings, "duration");
105+
context->visibility_action = (int)obs_data_get_int(settings, "visibility_action");
106+
context->end_action = (int)obs_data_get_int(settings, "end_action");
106107

107-
context->speed_percent = obs_data_get_int(settings, "speed_percent");
108+
context->speed_percent = (int)obs_data_get_int(settings, "speed_percent");
108109
if (context->speed_percent < 1 || context->speed_percent > 200)
109110
context->speed_percent = 100;
110111

@@ -147,7 +148,7 @@ static void replay_source_hide(void *data)
147148
static void replay_source_active(void *data)
148149
{
149150
struct replay_source *context = data;
150-
if(context->visibility_action == VISIBILITY_ACTION_PAUSE)
151+
if(context->visibility_action == VISIBILITY_ACTION_PAUSE || context->visibility_action == VISIBILITY_ACTION_CONTINUE)
151152
{
152153
context->play = true;
153154
}
@@ -229,7 +230,10 @@ static void replay_hotkey(void *data, obs_hotkey_id id,
229230
while (c->video_frames.size) {
230231
circlebuf_pop_front(&c->video_frames, &frame, sizeof(struct obs_source_frame*));
231232
//obs_source_release_frame(c->source, frame);
232-
os_atomic_dec_long(&frame->refs);
233+
if (os_atomic_dec_long(&frame->refs) <= 0) {
234+
obs_source_frame_destroy(frame);
235+
frame = NULL;
236+
}
233237
}
234238
c->start_timestamp = obs_get_video_frame_time();
235239
if(d->video_frames.size){
@@ -244,7 +248,7 @@ static void replay_hotkey(void *data, obs_hotkey_id id,
244248
circlebuf_push_back(&c->video_frames, &frame, sizeof(struct obs_source_frame*));
245249
}
246250
pthread_mutex_unlock(&parent->async_mutex);
247-
if(c->visibility_action == VISIBILITY_ACTION_CONTINUE || c->active)
251+
if(c->active || c->visibility_action == VISIBILITY_ACTION_CONTINUE || c->visibility_action == VISIBILITY_ACTION_NONE)
248252
{
249253
c->play = true;
250254
}
@@ -319,8 +323,8 @@ static void replay_source_tick(void *data, float seconds)
319323
return;
320324
}
321325
context->end = false;
322-
struct obs_source_frame *frame;
323-
struct obs_source_frame *peek_frame;
326+
struct obs_source_frame *frame = NULL;
327+
struct obs_source_frame *peek_frame = NULL;
324328
circlebuf_peek_front(&context->video_frames, &peek_frame, sizeof(struct obs_source_frame*));
325329
const uint64_t timestamp = obs_get_video_frame_time();
326330
if(context->first_frame_timestamp == peek_frame->timestamp)
@@ -344,14 +348,6 @@ static void replay_source_tick(void *data, float seconds)
344348
context->restart = false;
345349
context->start_timestamp = timestamp;
346350
}
347-
if(context->last_frame_timestamp == peek_frame->timestamp)
348-
{
349-
if(context->end_action != END_ACTION_LOOP)
350-
{
351-
context->play = false;
352-
context->end = true;
353-
}
354-
}
355351
uint64_t video_duration = timestamp - context->start_timestamp;
356352
uint64_t source_duration = (peek_frame->timestamp - context->first_frame_timestamp) * 100 / context->speed_percent ;
357353
if(video_duration < source_duration)
@@ -382,17 +378,18 @@ static void replay_source_tick(void *data, float seconds)
382378
video_duration = timestamp - context->start_timestamp;
383379
}
384380
}
385-
if(context->speed_percent != 100)
386-
{
387-
frame->timestamp = frame->timestamp * 100 / context->speed_percent;
381+
if(frame){
382+
if(context->speed_percent != 100)
383+
{
384+
frame->timestamp = frame->timestamp * 100 / context->speed_percent;
385+
}
386+
context->previous_frame_timestamp = frame->timestamp;
387+
obs_source_output_video(context->source, frame);
388388
}
389-
context->previous_frame_timestamp = frame->timestamp;
390-
obs_source_output_video(context->source, frame);
391-
392389
}
393390
static bool EnumSources(void *data, obs_source_t *source)
394391
{
395-
obs_properties_t *prop = data;
392+
obs_property_t *prop = data;
396393
if((source->info.output_flags | OBS_SOURCE_ASYNC) != 0)
397394
obs_property_list_add_string(prop,obs_source_get_name(source),obs_source_get_name(source));
398395
return true;
@@ -404,16 +401,17 @@ static obs_properties_t *replay_source_properties(void *data)
404401

405402
obs_properties_t *props = obs_properties_create();
406403
//obs_properties_add_text(props,"source","Source",OBS_TEXT_DEFAULT);
407-
obs_properties_t* prop = obs_properties_add_list(props,SETTING_SOURCE,TEXT_SOURCE, OBS_COMBO_TYPE_EDITABLE,OBS_COMBO_FORMAT_STRING);
404+
obs_property_t* prop = obs_properties_add_list(props,SETTING_SOURCE,TEXT_SOURCE, OBS_COMBO_TYPE_EDITABLE,OBS_COMBO_FORMAT_STRING);
408405
obs_enum_sources(EnumSources, prop);
409406

410407
obs_properties_add_int(props,SETTING_DURATION,TEXT_DURATION,1,200,1);
411408

412-
prop = obs_properties_add_list(props, "visibilty_action", "Visibility Action",
409+
prop = obs_properties_add_list(props, "visibility_action", "Visibility Action",
413410
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
414411
obs_property_list_add_int(prop, "Restart", VISIBILITY_ACTION_RESTART);
415412
obs_property_list_add_int(prop, "Pause", VISIBILITY_ACTION_PAUSE);
416413
obs_property_list_add_int(prop, "Continue", VISIBILITY_ACTION_CONTINUE);
414+
obs_property_list_add_int(prop, "None", VISIBILITY_ACTION_NONE);
417415

418416
prop = obs_properties_add_list(props, "end_action", "End Action",
419417
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);

0 commit comments

Comments
 (0)