Skip to content

Commit

Permalink
add load switch scene option
Browse files Browse the repository at this point in the history
  • Loading branch information
exeldro committed Sep 2, 2019
1 parent d863507 commit 3916b13
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 52 deletions.
35 changes: 33 additions & 2 deletions replay-source.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct replay_source {
int end_action;
char *next_scene_name;
bool next_scene_disabled;
char *load_switch_scene_name;
obs_hotkey_id replay_hotkey;
obs_hotkey_id next_hotkey;
obs_hotkey_id previous_hotkey;
Expand Down Expand Up @@ -704,7 +705,7 @@ static void replay_source_update(void *data, obs_data_t *settings)
context->source_audio_name = bstrdup(source_audio_name);
}
const char *next_scene_name =
obs_data_get_string(settings, "next_scene");
obs_data_get_string(settings, SETTING_NEXT_SCENE);
if (context->next_scene_name) {
if (strcmp(context->next_scene_name, next_scene_name) != 0) {
bfree(context->next_scene_name);
Expand All @@ -714,6 +715,20 @@ static void replay_source_update(void *data, obs_data_t *settings)
context->next_scene_name = bstrdup(next_scene_name);
}

const char *load_switch_scene_name =
obs_data_get_string(settings, SETTING_LOAD_SWITCH_SCENE);
if (context->load_switch_scene_name) {
if (strcmp(context->load_switch_scene_name,
load_switch_scene_name) != 0) {
bfree(context->load_switch_scene_name);
context->load_switch_scene_name =
bstrdup(load_switch_scene_name);
}
} else {
context->load_switch_scene_name =
bstrdup(load_switch_scene_name);
}

context->visibility_action =
(int)obs_data_get_int(settings, SETTING_VISIBILITY_ACTION);
context->end_action =
Expand Down Expand Up @@ -1349,7 +1364,6 @@ void replay_save(struct replay_source *context)

static void replay_retrieve(struct replay_source *context)
{

obs_source_t *s = obs_get_source_by_name(context->source_name);
context->source_filter = NULL;
bool dswow_video = false;
Expand Down Expand Up @@ -1509,6 +1523,13 @@ static void replay_retrieve(struct replay_source *context)
replay_update_position(context, true);
}
replay_purge_replays(context);
if (context->load_switch_scene_name) {
s = obs_get_source_by_name(context->load_switch_scene_name);
if (s) {
obs_frontend_set_current_scene(s);
obs_source_release(s);
}
}
}

static void replay_hotkey(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey,
Expand Down Expand Up @@ -2172,6 +2193,9 @@ static void replay_source_destroy(void *data)
if (context->next_scene_name)
bfree(context->next_scene_name);

if (context->load_switch_scene_name)
bfree(context->load_switch_scene_name);

if (context->directory)
bfree(context->directory);

Expand Down Expand Up @@ -3173,6 +3197,13 @@ static obs_properties_t *replay_source_properties(void *data)
SETTING_AUDIO_THRESHOLD_MIN,
SETTING_AUDIO_THRESHOLD_MAX, 0.1);

prop = obs_properties_add_list(props, SETTING_LOAD_SWITCH_SCENE,
"Load replay switch scene",
OBS_COMBO_TYPE_EDITABLE,
OBS_COMBO_FORMAT_STRING);
obs_property_list_add_string(prop, "", "");
obs_enum_scenes(EnumScenes, prop);

obs_properties_add_button(props, "replay_button", "Load replay",
replay_button);

Expand Down
102 changes: 52 additions & 50 deletions replay.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@
struct replay_filter {

/* contains struct obs_source_frame* */
struct circlebuf video_frames;
struct circlebuf video_frames;

/* stores the audio data */
struct circlebuf audio_frames;
struct circlebuf audio_frames;

struct obs_video_info ovi;
struct audio_convert_info oai;

gs_texrender_t* texrender;
gs_stagesurf_t* stagesurface;
gs_texrender_t *texrender;
gs_stagesurf_t *stagesurface;

uint32_t known_width;
uint32_t known_height;

uint8_t* video_data;
uint8_t *video_data;
uint32_t video_linesize;
video_t* video_output;
video_t *video_output;

uint64_t duration;
obs_source_t *src;
pthread_mutex_t mutex;
pthread_mutex_t mutex;
int64_t timing_adjust;
bool internal_frames;
float threshold;
Expand All @@ -36,52 +36,54 @@ struct replay_filter {
};

void free_audio_packet(struct obs_audio_data *audio);
struct obs_audio_data *replay_filter_audio(void *data,struct obs_audio_data *audio);
struct obs_audio_data *replay_filter_audio(void *data,
struct obs_audio_data *audio);
void free_video_data(struct replay_filter *filter);
void free_audio_data(struct replay_filter *filter);
void replay_trigger_threshold(void *data);
void replay_filter_check(struct replay_filter* filter);
void replay_filter_check(struct replay_filter *filter);

#define REPLAY_FILTER_ID "replay_filter"
#define TEXT_FILTER_NAME "Replay filter"
#define REPLAY_FILTER_AUDIO_ID "replay_filter_audio"
#define TEXT_FILTER_AUDIO_NAME "Replay filter audio"
#define REPLAY_FILTER_ASYNC_ID "replay_filter_async"
#define TEXT_FILTER_ASYNC_NAME "Replay filter async"
#define REPLAY_SOURCE_ID "replay_source"
#define SETTING_DURATION "duration"
#define SETTING_DURATION_MIN 1
#define SETTING_DURATION_MAX 200000
#define TEXT_DURATION "Duration (ms)"
#define SETTING_RETRIEVE_DELAY "retrieve_delay"
#define TEXT_RETRIEVE_DELAY "Load delay (ms)"
#define SETTING_REPLAYS "replays"
#define TEXT_REPLAYS "Maximum replays"
#define SETTING_SPEED "speed_percent"
#define SETTING_SPEED_MIN 0.01f
#define SETTING_SPEED_MAX 400.0f
#define SETTING_BACKWARD "backward"
#define SETTING_VISIBILITY_ACTION "visibility_action"
#define SETTING_START_DELAY "start_delay"
#define TEXT_START_DELAY "Start delay (ms)"
#define SETTING_END_ACTION "end_action"
#define SETTING_SOURCE "source"
#define TEXT_SOURCE "Video source"
#define SETTING_SOURCE_AUDIO "source_audio"
#define TEXT_SOURCE_AUDIO "Audio source"
#define SETTING_NEXT_SCENE "next_scene"
#define TEXT_NEXT_SCENE "Next scene"
#define SETTING_DIRECTORY "directory"
#define SETTING_FILE_FORMAT "file_format"
#define SETTING_LOSSLESS "lossless"
#define SETTING_PROGRESS_SOURCE "progress_source"
#define SETTING_TEXT_SOURCE "text_source"
#define SETTING_TEXT "text"
#define SETTING_INTERNAL_FRAMES "internal_frames"
#define SETTING_SOUND_TRIGGER "sound_trigger"
#define SETTING_AUDIO_THRESHOLD "threshold"
#define SETTING_AUDIO_THRESHOLD_MIN -60.0
#define SETTING_AUDIO_THRESHOLD_MAX 0.0f
#define REPLAY_FILTER_ID "replay_filter"
#define TEXT_FILTER_NAME "Replay filter"
#define REPLAY_FILTER_AUDIO_ID "replay_filter_audio"
#define TEXT_FILTER_AUDIO_NAME "Replay filter audio"
#define REPLAY_FILTER_ASYNC_ID "replay_filter_async"
#define TEXT_FILTER_ASYNC_NAME "Replay filter async"
#define REPLAY_SOURCE_ID "replay_source"
#define SETTING_DURATION "duration"
#define SETTING_DURATION_MIN 1
#define SETTING_DURATION_MAX 200000
#define TEXT_DURATION "Duration (ms)"
#define SETTING_RETRIEVE_DELAY "retrieve_delay"
#define TEXT_RETRIEVE_DELAY "Load delay (ms)"
#define SETTING_REPLAYS "replays"
#define TEXT_REPLAYS "Maximum replays"
#define SETTING_SPEED "speed_percent"
#define SETTING_SPEED_MIN 0.01f
#define SETTING_SPEED_MAX 400.0f
#define SETTING_BACKWARD "backward"
#define SETTING_VISIBILITY_ACTION "visibility_action"
#define SETTING_START_DELAY "start_delay"
#define TEXT_START_DELAY "Start delay (ms)"
#define SETTING_END_ACTION "end_action"
#define SETTING_SOURCE "source"
#define TEXT_SOURCE "Video source"
#define SETTING_SOURCE_AUDIO "source_audio"
#define TEXT_SOURCE_AUDIO "Audio source"
#define SETTING_NEXT_SCENE "next_scene"
#define TEXT_NEXT_SCENE "Next scene"
#define SETTING_DIRECTORY "directory"
#define SETTING_FILE_FORMAT "file_format"
#define SETTING_LOSSLESS "lossless"
#define SETTING_PROGRESS_SOURCE "progress_source"
#define SETTING_TEXT_SOURCE "text_source"
#define SETTING_TEXT "text"
#define SETTING_INTERNAL_FRAMES "internal_frames"
#define SETTING_SOUND_TRIGGER "sound_trigger"
#define SETTING_AUDIO_THRESHOLD "threshold"
#define SETTING_AUDIO_THRESHOLD_MIN -60.0
#define SETTING_AUDIO_THRESHOLD_MAX 0.0f
#define SETTING_LOAD_SWITCH_SCENE "load_switch_scene"

#ifndef SEC_TO_NSEC
#define SEC_TO_NSEC 1000000000ULL
Expand All @@ -90,5 +92,5 @@ void replay_filter_check(struct replay_filter* filter);
#define MSEC_TO_NSEC 1000000ULL
#endif
#ifndef MAX_TS_VAR
#define MAX_TS_VAR 2000000000ULL
#define MAX_TS_VAR 2000000000ULL
#endif

0 comments on commit 3916b13

Please sign in to comment.