2016-05-24 07:31:48 -07:00
|
|
|
#include <obs-module.h>
|
|
|
|
#include <util/threading.h>
|
2016-06-15 16:20:12 -07:00
|
|
|
#include <util/platform.h>
|
2016-05-24 07:31:48 -07:00
|
|
|
#include <util/darray.h>
|
|
|
|
#include <util/dstr.h>
|
|
|
|
|
|
|
|
#define do_log(level, format, ...) \
|
|
|
|
blog(level, "[slideshow: '%s'] " format, \
|
|
|
|
obs_source_get_name(ss->source), ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#define warn(format, ...) do_log(LOG_WARNING, format, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#define S_TR_SPEED "transition_speed"
|
2017-05-14 20:53:55 -07:00
|
|
|
#define S_CUSTOM_SIZE "use_custom_size"
|
2016-05-24 07:31:48 -07:00
|
|
|
#define S_SLIDE_TIME "slide_time"
|
|
|
|
#define S_TRANSITION "transition"
|
2016-05-26 11:35:29 -07:00
|
|
|
#define S_RANDOMIZE "randomize"
|
2017-07-22 19:40:36 -07:00
|
|
|
#define S_LOOP "loop"
|
|
|
|
#define S_HIDE "hide"
|
2016-05-24 07:31:48 -07:00
|
|
|
#define S_FILES "files"
|
2017-08-04 20:39:13 -07:00
|
|
|
#define S_BEHAVIOR "playback_behavior"
|
|
|
|
#define S_BEHAVIOR_STOP_RESTART "stop_restart"
|
|
|
|
#define S_BEHAVIOR_PAUSE_UNPAUSE "pause_unpause"
|
|
|
|
#define S_BEHAVIOR_ALWAYS_PLAY "always_play"
|
2017-08-04 21:10:05 -07:00
|
|
|
#define S_MODE "slide_mode"
|
|
|
|
#define S_MODE_AUTO "mode_auto"
|
|
|
|
#define S_MODE_MANUAL "mode_manual"
|
2016-05-24 07:31:48 -07:00
|
|
|
|
|
|
|
#define TR_CUT "cut"
|
|
|
|
#define TR_FADE "fade"
|
|
|
|
#define TR_SWIPE "swipe"
|
|
|
|
#define TR_SLIDE "slide"
|
|
|
|
|
|
|
|
#define T_(text) obs_module_text("SlideShow." text)
|
|
|
|
#define T_TR_SPEED T_("TransitionSpeed")
|
2017-05-14 20:53:55 -07:00
|
|
|
#define T_CUSTOM_SIZE T_("CustomSize")
|
|
|
|
#define T_CUSTOM_SIZE_AUTO T_("CustomSize.Auto")
|
2016-05-24 07:31:48 -07:00
|
|
|
#define T_SLIDE_TIME T_("SlideTime")
|
|
|
|
#define T_TRANSITION T_("Transition")
|
2016-05-26 11:35:29 -07:00
|
|
|
#define T_RANDOMIZE T_("Randomize")
|
2017-07-22 19:40:36 -07:00
|
|
|
#define T_LOOP T_("Loop")
|
|
|
|
#define T_HIDE T_("HideWhenDone")
|
2016-05-24 07:31:48 -07:00
|
|
|
#define T_FILES T_("Files")
|
2017-08-04 20:39:13 -07:00
|
|
|
#define T_BEHAVIOR T_("PlaybackBehavior")
|
|
|
|
#define T_BEHAVIOR_STOP_RESTART T_("PlaybackBehavior.StopRestart")
|
|
|
|
#define T_BEHAVIOR_PAUSE_UNPAUSE T_("PlaybackBehavior.PauseUnpause")
|
|
|
|
#define T_BEHAVIOR_ALWAYS_PLAY T_("PlaybackBehavior.AlwaysPlay")
|
2017-08-04 21:10:05 -07:00
|
|
|
#define T_MODE T_("SlideMode")
|
|
|
|
#define T_MODE_AUTO T_("SlideMode.Auto")
|
|
|
|
#define T_MODE_MANUAL T_("SlideMode.Manual")
|
2016-05-24 07:31:48 -07:00
|
|
|
|
|
|
|
#define T_TR_(text) obs_module_text("SlideShow.Transition." text)
|
|
|
|
#define T_TR_CUT T_TR_("Cut")
|
|
|
|
#define T_TR_FADE T_TR_("Fade")
|
|
|
|
#define T_TR_SWIPE T_TR_("Swipe")
|
|
|
|
#define T_TR_SLIDE T_TR_("Slide")
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
2018-08-26 02:54:32 -07:00
|
|
|
#define MOD(a,b) ((((a)%(b))+(b))%(b))
|
2019-02-25 05:56:22 -08:00
|
|
|
#define MAX_LOADED 21 /* needs to be an odd number */
|
2018-08-26 02:54:32 -07:00
|
|
|
|
2016-05-24 07:31:48 -07:00
|
|
|
struct image_file_data {
|
|
|
|
char *path;
|
|
|
|
obs_source_t *source;
|
|
|
|
};
|
|
|
|
|
2017-08-04 20:39:13 -07:00
|
|
|
enum behavior {
|
|
|
|
BEHAVIOR_STOP_RESTART,
|
|
|
|
BEHAVIOR_PAUSE_UNPAUSE,
|
|
|
|
BEHAVIOR_ALWAYS_PLAY,
|
|
|
|
};
|
|
|
|
|
2016-05-24 07:31:48 -07:00
|
|
|
struct slideshow {
|
|
|
|
obs_source_t *source;
|
|
|
|
|
2016-05-26 11:35:29 -07:00
|
|
|
bool randomize;
|
2017-07-22 19:40:36 -07:00
|
|
|
bool loop;
|
2017-08-04 20:39:13 -07:00
|
|
|
bool restart_on_activate;
|
|
|
|
bool pause_on_deactivate;
|
2017-08-04 21:10:05 -07:00
|
|
|
bool manual;
|
2017-07-22 19:40:36 -07:00
|
|
|
bool hide;
|
2017-08-04 20:39:13 -07:00
|
|
|
bool use_cut;
|
|
|
|
bool paused;
|
|
|
|
bool stop;
|
2016-05-24 07:31:48 -07:00
|
|
|
float slide_time;
|
|
|
|
uint32_t tr_speed;
|
|
|
|
const char *tr_name;
|
|
|
|
obs_source_t *transition;
|
|
|
|
|
|
|
|
float elapsed;
|
2018-08-26 02:54:32 -07:00
|
|
|
int cur_item;
|
2016-05-24 07:31:48 -07:00
|
|
|
|
|
|
|
uint32_t cx;
|
|
|
|
uint32_t cy;
|
|
|
|
|
|
|
|
pthread_mutex_t mutex;
|
|
|
|
DARRAY(struct image_file_data) files;
|
2018-08-26 02:54:32 -07:00
|
|
|
DARRAY(char*) paths;
|
2017-08-04 20:39:13 -07:00
|
|
|
|
|
|
|
enum behavior behavior;
|
2017-08-04 21:10:05 -07:00
|
|
|
|
|
|
|
obs_hotkey_id play_pause_hotkey;
|
|
|
|
obs_hotkey_id restart_hotkey;
|
|
|
|
obs_hotkey_id stop_hotkey;
|
|
|
|
obs_hotkey_id next_hotkey;
|
|
|
|
obs_hotkey_id prev_hotkey;
|
2016-05-24 07:31:48 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static obs_source_t *get_transition(struct slideshow *ss)
|
|
|
|
{
|
|
|
|
obs_source_t *tr;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&ss->mutex);
|
|
|
|
tr = ss->transition;
|
|
|
|
obs_source_addref(tr);
|
|
|
|
pthread_mutex_unlock(&ss->mutex);
|
|
|
|
|
|
|
|
return tr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static obs_source_t *get_source(struct darray *array, const char *path)
|
|
|
|
{
|
|
|
|
DARRAY(struct image_file_data) files;
|
|
|
|
obs_source_t *source = NULL;
|
|
|
|
|
|
|
|
files.da = *array;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < files.num; i++) {
|
|
|
|
const char *cur_path = files.array[i].path;
|
|
|
|
|
|
|
|
if (strcmp(path, cur_path) == 0) {
|
|
|
|
source = files.array[i].source;
|
|
|
|
obs_source_addref(source);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
|
|
|
static obs_source_t *create_source_from_file(const char *file)
|
|
|
|
{
|
|
|
|
obs_data_t *settings = obs_data_create();
|
|
|
|
obs_source_t *source;
|
|
|
|
|
|
|
|
obs_data_set_string(settings, "file", file);
|
|
|
|
obs_data_set_bool(settings, "unload", false);
|
|
|
|
source = obs_source_create_private("image_source", NULL, settings);
|
|
|
|
|
|
|
|
obs_data_release(settings);
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_files(struct darray *array)
|
|
|
|
{
|
|
|
|
DARRAY(struct image_file_data) files;
|
|
|
|
files.da = *array;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < files.num; i++) {
|
|
|
|
bfree(files.array[i].path);
|
|
|
|
obs_source_release(files.array[i].source);
|
|
|
|
}
|
|
|
|
|
|
|
|
da_free(files);
|
|
|
|
}
|
|
|
|
|
2016-05-26 11:35:29 -07:00
|
|
|
static inline size_t random_file(struct slideshow *ss)
|
|
|
|
{
|
2018-08-26 02:54:32 -07:00
|
|
|
return (size_t)rand() % ss->paths.num;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_paths(struct darray *array)
|
|
|
|
{
|
|
|
|
DARRAY(char*) paths;
|
|
|
|
paths.da = *array;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < paths.num; i++)
|
|
|
|
bfree(paths.array[i]);
|
|
|
|
|
|
|
|
da_free(paths);
|
2016-05-26 11:35:29 -07:00
|
|
|
}
|
|
|
|
|
2016-05-24 07:31:48 -07:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static const char *ss_getname(void *unused)
|
|
|
|
{
|
|
|
|
UNUSED_PARAMETER(unused);
|
|
|
|
return obs_module_text("SlideShow");
|
|
|
|
}
|
|
|
|
|
2016-06-15 16:20:12 -07:00
|
|
|
static void add_file(struct slideshow *ss, struct darray *array,
|
2018-08-26 02:54:32 -07:00
|
|
|
const char *path, uint32_t *cx, uint32_t *cy, bool next)
|
2016-06-15 16:20:12 -07:00
|
|
|
{
|
|
|
|
DARRAY(struct image_file_data) new_files;
|
|
|
|
struct image_file_data data;
|
|
|
|
obs_source_t *new_source;
|
|
|
|
|
|
|
|
new_files.da = *array;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&ss->mutex);
|
|
|
|
new_source = get_source(&ss->files.da, path);
|
|
|
|
pthread_mutex_unlock(&ss->mutex);
|
|
|
|
|
|
|
|
if (!new_source)
|
|
|
|
new_source = get_source(&new_files.da, path);
|
|
|
|
if (!new_source)
|
|
|
|
new_source = create_source_from_file(path);
|
|
|
|
|
|
|
|
if (new_source) {
|
|
|
|
uint32_t new_cx = obs_source_get_width(new_source);
|
|
|
|
uint32_t new_cy = obs_source_get_height(new_source);
|
|
|
|
|
|
|
|
data.path = bstrdup(path);
|
|
|
|
data.source = new_source;
|
2018-08-26 02:54:32 -07:00
|
|
|
|
|
|
|
if (next)
|
|
|
|
da_push_back(new_files, &data);
|
|
|
|
else
|
|
|
|
da_insert(new_files, 0, &data);
|
2016-06-15 16:20:12 -07:00
|
|
|
|
|
|
|
if (new_cx > *cx) *cx = new_cx;
|
|
|
|
if (new_cy > *cy) *cy = new_cy;
|
|
|
|
}
|
|
|
|
|
|
|
|
*array = new_files.da;
|
|
|
|
}
|
|
|
|
|
2018-08-26 02:54:32 -07:00
|
|
|
static void clear_buffer(struct slideshow *ss, bool next)
|
|
|
|
{
|
|
|
|
if (ss->paths.num <= MAX_LOADED || !ss->paths.num || !ss->files.num)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (next) {
|
|
|
|
bfree(ss->files.array[0].path);
|
|
|
|
obs_source_release(ss->files.array[0].source);
|
|
|
|
da_erase(ss->files, 0);
|
|
|
|
} else {
|
|
|
|
bfree(ss->files.array[ss->files.num - 1].path);
|
|
|
|
obs_source_release(ss->files.array[ss->files.num - 1].source);
|
|
|
|
da_pop_back(ss->files);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t index = 0;
|
|
|
|
|
|
|
|
if (ss->randomize)
|
|
|
|
index = random_file(ss);
|
|
|
|
else if (!ss->randomize && next)
|
|
|
|
index = MOD((ss->cur_item + ((MAX_LOADED / 2) + 1)),
|
|
|
|
ss->paths.num);
|
|
|
|
else if (!ss->randomize && !next)
|
|
|
|
index = MOD((ss->cur_item - ((MAX_LOADED / 2) + 1)),
|
|
|
|
ss->paths.num);
|
|
|
|
|
|
|
|
uint32_t cx, cy;
|
|
|
|
add_file(ss, &ss->files.da, ss->paths.array[index], &cx, &cy,
|
|
|
|
next);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_path(struct darray *array, const char *path)
|
|
|
|
{
|
|
|
|
DARRAY(char*) new_paths;
|
|
|
|
new_paths.da = *array;
|
|
|
|
|
|
|
|
const char *new_path = bstrdup(path);
|
|
|
|
da_push_back(new_paths, &new_path);
|
|
|
|
|
|
|
|
*array = new_paths.da;
|
|
|
|
}
|
|
|
|
|
2016-06-15 16:20:12 -07:00
|
|
|
static bool valid_extension(const char *ext)
|
|
|
|
{
|
|
|
|
if (!ext)
|
|
|
|
return false;
|
|
|
|
return astrcmpi(ext, ".bmp") == 0 ||
|
|
|
|
astrcmpi(ext, ".tga") == 0 ||
|
|
|
|
astrcmpi(ext, ".png") == 0 ||
|
|
|
|
astrcmpi(ext, ".jpeg") == 0 ||
|
|
|
|
astrcmpi(ext, ".jpg") == 0 ||
|
|
|
|
astrcmpi(ext, ".gif") == 0;
|
|
|
|
}
|
|
|
|
|
2017-08-10 21:21:58 -07:00
|
|
|
static inline bool item_valid(struct slideshow *ss)
|
|
|
|
{
|
2018-08-26 02:54:32 -07:00
|
|
|
return ss->files.num && ss->paths.num &&
|
|
|
|
(size_t)ss->cur_item < ss->paths.num;
|
2017-08-10 21:21:58 -07:00
|
|
|
}
|
|
|
|
|
2018-08-26 02:54:32 -07:00
|
|
|
static void do_transition(void *data, bool to_null, bool next)
|
2017-07-22 19:40:36 -07:00
|
|
|
{
|
|
|
|
struct slideshow *ss = data;
|
2017-08-10 21:21:58 -07:00
|
|
|
bool valid = item_valid(ss);
|
2017-07-22 19:40:36 -07:00
|
|
|
|
2018-08-26 02:54:32 -07:00
|
|
|
if (to_null) {
|
|
|
|
obs_transition_start(ss->transition, OBS_TRANSITION_MODE_AUTO,
|
2017-07-22 19:40:36 -07:00
|
|
|
ss->tr_speed,
|
2018-08-26 02:54:32 -07:00
|
|
|
NULL);
|
|
|
|
return;
|
|
|
|
}
|
2017-08-10 21:21:58 -07:00
|
|
|
|
2018-08-26 02:54:32 -07:00
|
|
|
if (!valid)
|
|
|
|
return;
|
|
|
|
|
|
|
|
clear_buffer(ss, next);
|
|
|
|
|
|
|
|
obs_source_t *source;
|
|
|
|
|
|
|
|
if (next && ss->paths.num > MAX_LOADED)
|
|
|
|
source = ss->files.array[(MAX_LOADED / 2) + 1].source;
|
|
|
|
else if (!next && ss->paths.num > MAX_LOADED)
|
|
|
|
source = ss->files.array[(MAX_LOADED / 2) - 1].source;
|
|
|
|
else if (ss->paths.num <= MAX_LOADED)
|
|
|
|
source = ss->files.array[(size_t)ss->cur_item].source;
|
|
|
|
|
|
|
|
if (!source)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ss->use_cut)
|
|
|
|
obs_transition_set(ss->transition, source);
|
|
|
|
|
|
|
|
else if (!to_null)
|
2017-07-22 19:40:36 -07:00
|
|
|
obs_transition_start(ss->transition,
|
|
|
|
OBS_TRANSITION_MODE_AUTO,
|
2018-08-26 02:54:32 -07:00
|
|
|
ss->tr_speed, source);
|
2017-07-22 19:40:36 -07:00
|
|
|
}
|
|
|
|
|
2016-05-24 07:31:48 -07:00
|
|
|
static void ss_update(void *data, obs_data_t *settings)
|
|
|
|
{
|
|
|
|
DARRAY(struct image_file_data) new_files;
|
|
|
|
DARRAY(struct image_file_data) old_files;
|
2018-08-26 02:54:32 -07:00
|
|
|
DARRAY(char*) new_paths;
|
|
|
|
DARRAY(char*) old_paths;
|
2016-05-24 07:31:48 -07:00
|
|
|
obs_source_t *new_tr = NULL;
|
|
|
|
obs_source_t *old_tr = NULL;
|
|
|
|
struct slideshow *ss = data;
|
|
|
|
obs_data_array_t *array;
|
|
|
|
const char *tr_name;
|
|
|
|
uint32_t new_duration;
|
|
|
|
uint32_t new_speed;
|
|
|
|
uint32_t cx = 0;
|
|
|
|
uint32_t cy = 0;
|
2018-08-26 02:54:32 -07:00
|
|
|
uint32_t last_cx = 0;
|
|
|
|
uint32_t last_cy = 0;
|
2016-05-24 07:31:48 -07:00
|
|
|
size_t count;
|
2017-08-04 20:39:13 -07:00
|
|
|
const char *behavior;
|
2017-08-04 21:10:05 -07:00
|
|
|
const char *mode;
|
2016-05-24 07:31:48 -07:00
|
|
|
|
|
|
|
/* ------------------------------------- */
|
|
|
|
/* get settings data */
|
|
|
|
|
|
|
|
da_init(new_files);
|
2018-08-26 02:54:32 -07:00
|
|
|
da_init(new_paths);
|
2016-05-24 07:31:48 -07:00
|
|
|
|
2017-08-04 20:39:13 -07:00
|
|
|
behavior = obs_data_get_string(settings, S_BEHAVIOR);
|
|
|
|
|
|
|
|
if (astrcmpi(behavior, S_BEHAVIOR_PAUSE_UNPAUSE) == 0)
|
|
|
|
ss->behavior = BEHAVIOR_PAUSE_UNPAUSE;
|
|
|
|
else if (astrcmpi(behavior, S_BEHAVIOR_ALWAYS_PLAY) == 0)
|
|
|
|
ss->behavior = BEHAVIOR_ALWAYS_PLAY;
|
|
|
|
else /* S_BEHAVIOR_STOP_RESTART */
|
|
|
|
ss->behavior = BEHAVIOR_STOP_RESTART;
|
|
|
|
|
2017-08-04 21:10:05 -07:00
|
|
|
mode = obs_data_get_string(settings, S_MODE);
|
|
|
|
|
|
|
|
ss->manual = (astrcmpi(mode, S_MODE_MANUAL) == 0);
|
|
|
|
|
2016-05-24 07:31:48 -07:00
|
|
|
tr_name = obs_data_get_string(settings, S_TRANSITION);
|
|
|
|
if (astrcmpi(tr_name, TR_CUT) == 0)
|
|
|
|
tr_name = "cut_transition";
|
|
|
|
else if (astrcmpi(tr_name, TR_SWIPE) == 0)
|
|
|
|
tr_name = "swipe_transition";
|
|
|
|
else if (astrcmpi(tr_name, TR_SLIDE) == 0)
|
|
|
|
tr_name = "slide_transition";
|
|
|
|
else
|
|
|
|
tr_name = "fade_transition";
|
|
|
|
|
2016-05-26 11:35:29 -07:00
|
|
|
ss->randomize = obs_data_get_bool(settings, S_RANDOMIZE);
|
2017-07-22 19:40:36 -07:00
|
|
|
ss->loop = obs_data_get_bool(settings, S_LOOP);
|
|
|
|
ss->hide = obs_data_get_bool(settings, S_HIDE);
|
2016-05-26 11:35:29 -07:00
|
|
|
|
2016-05-24 07:31:48 -07:00
|
|
|
if (!ss->tr_name || strcmp(tr_name, ss->tr_name) != 0)
|
|
|
|
new_tr = obs_source_create_private(tr_name, NULL, NULL);
|
|
|
|
|
|
|
|
new_duration = (uint32_t)obs_data_get_int(settings, S_SLIDE_TIME);
|
|
|
|
new_speed = (uint32_t)obs_data_get_int(settings, S_TR_SPEED);
|
|
|
|
|
|
|
|
array = obs_data_get_array(settings, S_FILES);
|
|
|
|
count = obs_data_array_count(array);
|
|
|
|
|
|
|
|
/* ------------------------------------- */
|
|
|
|
/* create new list of sources */
|
|
|
|
|
|
|
|
for (size_t i = 0; i < count; i++) {
|
|
|
|
obs_data_t *item = obs_data_array_item(array, i);
|
|
|
|
const char *path = obs_data_get_string(item, "value");
|
2016-06-15 16:20:12 -07:00
|
|
|
os_dir_t *dir = os_opendir(path);
|
|
|
|
|
|
|
|
if (dir) {
|
|
|
|
struct dstr dir_path = {0};
|
|
|
|
struct os_dirent *ent;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
const char *ext;
|
|
|
|
|
|
|
|
ent = os_readdir(dir);
|
|
|
|
if (!ent)
|
|
|
|
break;
|
|
|
|
if (ent->directory)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ext = os_get_path_extension(ent->d_name);
|
|
|
|
if (!valid_extension(ext))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dstr_copy(&dir_path, path);
|
|
|
|
dstr_cat_ch(&dir_path, '/');
|
|
|
|
dstr_cat(&dir_path, ent->d_name);
|
2018-08-26 02:54:32 -07:00
|
|
|
add_path(&new_paths.da, dir_path.array);
|
2016-06-15 16:20:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
dstr_free(&dir_path);
|
|
|
|
os_closedir(dir);
|
|
|
|
} else {
|
2018-08-26 02:54:32 -07:00
|
|
|
add_path(&new_paths.da, path);
|
2016-05-24 07:31:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
obs_data_release(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------- */
|
|
|
|
/* update settings data */
|
|
|
|
|
|
|
|
pthread_mutex_lock(&ss->mutex);
|
|
|
|
|
|
|
|
old_files.da = ss->files.da;
|
|
|
|
ss->files.da = new_files.da;
|
2018-08-26 02:54:32 -07:00
|
|
|
old_paths.da = ss->paths.da;
|
|
|
|
ss->paths.da = new_paths.da;
|
2016-05-24 07:31:48 -07:00
|
|
|
if (new_tr) {
|
|
|
|
old_tr = ss->transition;
|
|
|
|
ss->transition = new_tr;
|
|
|
|
}
|
|
|
|
|
2019-02-24 14:28:58 -08:00
|
|
|
if (strcmp(tr_name, "cut_transition") != 0) {
|
|
|
|
if (new_duration < 100)
|
|
|
|
new_duration = 100;
|
|
|
|
|
|
|
|
new_duration += new_speed;
|
|
|
|
} else {
|
|
|
|
if (new_duration < 50)
|
|
|
|
new_duration = 50;
|
|
|
|
}
|
2016-05-24 07:31:48 -07:00
|
|
|
|
|
|
|
ss->tr_speed = new_speed;
|
|
|
|
ss->tr_name = tr_name;
|
|
|
|
ss->slide_time = (float)new_duration / 1000.0f;
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&ss->mutex);
|
|
|
|
|
2018-08-26 02:54:32 -07:00
|
|
|
if (ss->paths.num > MAX_LOADED && !ss->randomize) {
|
|
|
|
for (int i = -(MAX_LOADED / 2); i <= (MAX_LOADED / 2); i++) {
|
|
|
|
size_t index = MOD(i, ss->paths.num);
|
|
|
|
add_file(ss, &ss->files.da, ss->paths.array[index],
|
|
|
|
&cx, &cy, true);
|
|
|
|
}
|
|
|
|
} else if (ss->paths.num > MAX_LOADED && ss->randomize) {
|
|
|
|
for (size_t i = 0; i < MAX_LOADED; i++) {
|
|
|
|
size_t index = random_file(ss);
|
|
|
|
add_file(ss, &ss->files.da, ss->paths.array[index],
|
|
|
|
&cx, &cy, true);
|
|
|
|
}
|
|
|
|
} else if (ss->paths.num <= MAX_LOADED) {
|
|
|
|
for (size_t i = 0; i < ss->paths.num; i++)
|
|
|
|
add_file(ss, &ss->files.da, ss->paths.array[i],
|
|
|
|
&cx, &cy, true);
|
|
|
|
}
|
|
|
|
|
2016-05-24 07:31:48 -07:00
|
|
|
/* ------------------------------------- */
|
|
|
|
/* clean up and restart transition */
|
|
|
|
|
|
|
|
if (old_tr)
|
|
|
|
obs_source_release(old_tr);
|
|
|
|
free_files(&old_files.da);
|
2018-08-26 02:54:32 -07:00
|
|
|
free_paths(&old_paths.da);
|
2016-05-24 07:31:48 -07:00
|
|
|
|
2017-05-14 20:53:55 -07:00
|
|
|
/* ------------------------- */
|
|
|
|
|
|
|
|
const char *res_str = obs_data_get_string(settings, S_CUSTOM_SIZE);
|
|
|
|
bool aspect_only = false, use_auto = true;
|
|
|
|
int cx_in = 0, cy_in = 0;
|
|
|
|
|
|
|
|
if (strcmp(res_str, T_CUSTOM_SIZE_AUTO) != 0) {
|
|
|
|
int ret = sscanf(res_str, "%dx%d", &cx_in, &cy_in);
|
|
|
|
if (ret == 2) {
|
|
|
|
aspect_only = false;
|
|
|
|
use_auto = false;
|
|
|
|
} else {
|
|
|
|
ret = sscanf(res_str, "%d:%d", &cx_in, &cy_in);
|
|
|
|
if (ret == 2) {
|
|
|
|
aspect_only = true;
|
|
|
|
use_auto = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!use_auto) {
|
|
|
|
double cx_f = (double)cx;
|
|
|
|
double cy_f = (double)cy;
|
|
|
|
|
|
|
|
double old_aspect = cx_f / cy_f;
|
|
|
|
double new_aspect = (double)cx_in / (double)cy_in;
|
|
|
|
|
|
|
|
if (aspect_only) {
|
|
|
|
if (fabs(old_aspect - new_aspect) > EPSILON) {
|
|
|
|
if (new_aspect > old_aspect)
|
|
|
|
cx = (uint32_t)(cy_f * new_aspect);
|
|
|
|
else
|
|
|
|
cy = (uint32_t)(cx_f / new_aspect);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cx = (uint32_t)cx_in;
|
|
|
|
cy = (uint32_t)cy_in;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------- */
|
|
|
|
|
2018-08-26 02:54:32 -07:00
|
|
|
obs_data_t *priv_settings = obs_source_get_private_settings(ss->source);
|
|
|
|
last_cx = (uint32_t)obs_data_get_int(priv_settings, "last_cx");
|
|
|
|
last_cy = (uint32_t)obs_data_get_int(priv_settings, "last_cy");
|
|
|
|
|
|
|
|
if (ss->randomize && last_cx > 0 && last_cy > 0) {
|
|
|
|
cx = last_cx;
|
|
|
|
cy = last_cy;
|
|
|
|
}
|
|
|
|
|
|
|
|
obs_data_set_int(priv_settings, "last_cx", cx);
|
|
|
|
obs_data_set_int(priv_settings, "last_cy", cy);
|
|
|
|
obs_data_release(priv_settings);
|
|
|
|
|
2016-05-24 07:31:48 -07:00
|
|
|
ss->cx = cx;
|
|
|
|
ss->cy = cy;
|
|
|
|
ss->elapsed = 0.0f;
|
2018-08-26 02:54:32 -07:00
|
|
|
ss->cur_item = 0;
|
2016-05-24 07:31:48 -07:00
|
|
|
obs_transition_set_size(ss->transition, cx, cy);
|
|
|
|
obs_transition_set_alignment(ss->transition, OBS_ALIGN_CENTER);
|
|
|
|
obs_transition_set_scale_type(ss->transition,
|
|
|
|
OBS_TRANSITION_SCALE_ASPECT);
|
|
|
|
|
|
|
|
if (new_tr)
|
|
|
|
obs_source_add_active_child(ss->source, new_tr);
|
|
|
|
if (ss->files.num)
|
2018-08-26 02:54:32 -07:00
|
|
|
do_transition(ss, false, true);
|
2016-05-24 07:31:48 -07:00
|
|
|
|
|
|
|
obs_data_array_release(array);
|
|
|
|
}
|
|
|
|
|
2017-08-04 21:10:05 -07:00
|
|
|
static void ss_play_pause(void *data)
|
|
|
|
{
|
|
|
|
struct slideshow *ss = data;
|
|
|
|
|
|
|
|
ss->paused = !ss->paused;
|
|
|
|
ss->manual = ss->paused;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ss_restart(void *data)
|
|
|
|
{
|
|
|
|
struct slideshow *ss = data;
|
|
|
|
|
2018-08-26 02:54:32 -07:00
|
|
|
ss->stop = false;
|
|
|
|
ss->use_cut = true;
|
|
|
|
ss->restart_on_activate = false;
|
2017-08-04 21:10:05 -07:00
|
|
|
|
2018-08-26 02:54:32 -07:00
|
|
|
obs_data_t *settings = obs_source_get_settings(ss->source);
|
|
|
|
ss_update(ss, settings);
|
|
|
|
obs_data_release(settings);
|
2017-08-04 21:10:05 -07:00
|
|
|
|
2018-08-26 02:54:32 -07:00
|
|
|
ss->use_cut = false;
|
2017-08-04 21:10:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ss_stop(void *data)
|
|
|
|
{
|
|
|
|
struct slideshow *ss = data;
|
|
|
|
|
|
|
|
ss->elapsed = 0.0f;
|
|
|
|
ss->cur_item = 0;
|
|
|
|
|
2018-08-26 02:54:32 -07:00
|
|
|
do_transition(ss, true, true);
|
2017-08-04 21:10:05 -07:00
|
|
|
ss->stop = true;
|
|
|
|
ss->paused = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ss_next_slide(void *data)
|
|
|
|
{
|
|
|
|
struct slideshow *ss = data;
|
|
|
|
|
2019-02-24 14:28:58 -08:00
|
|
|
if (!ss->paths.num || obs_transition_get_time(ss->transition) < 1.0f)
|
2017-08-04 21:10:05 -07:00
|
|
|
return;
|
|
|
|
|
2018-08-26 02:54:32 -07:00
|
|
|
if (++ss->cur_item >= (int)ss->paths.num)
|
2017-08-04 21:10:05 -07:00
|
|
|
ss->cur_item = 0;
|
|
|
|
|
2018-08-26 02:54:32 -07:00
|
|
|
do_transition(ss, false, true);
|
2017-08-04 21:10:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ss_previous_slide(void *data)
|
|
|
|
{
|
|
|
|
struct slideshow *ss = data;
|
|
|
|
|
2019-02-24 14:28:58 -08:00
|
|
|
if (!ss->paths.num || obs_transition_get_time(ss->transition) < 1.0f)
|
2017-08-04 21:10:05 -07:00
|
|
|
return;
|
|
|
|
|
2018-08-26 02:54:32 -07:00
|
|
|
if (--ss->cur_item < 0)
|
|
|
|
ss->cur_item = (int)(ss->paths.num - 1);
|
2017-08-04 21:10:05 -07:00
|
|
|
|
2018-08-26 02:54:32 -07:00
|
|
|
do_transition(ss, false, false);
|
2017-08-04 21:10:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void play_pause_hotkey(void *data, obs_hotkey_id id,
|
|
|
|
obs_hotkey_t *hotkey, bool pressed)
|
|
|
|
{
|
|
|
|
UNUSED_PARAMETER(id);
|
|
|
|
UNUSED_PARAMETER(hotkey);
|
|
|
|
|
|
|
|
struct slideshow *ss = data;
|
|
|
|
|
|
|
|
if (pressed && obs_source_active(ss->source))
|
|
|
|
ss_play_pause(ss);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void restart_hotkey(void *data, obs_hotkey_id id,
|
|
|
|
obs_hotkey_t *hotkey, bool pressed)
|
|
|
|
{
|
|
|
|
UNUSED_PARAMETER(id);
|
|
|
|
UNUSED_PARAMETER(hotkey);
|
|
|
|
|
|
|
|
struct slideshow *ss = data;
|
|
|
|
|
|
|
|
if (pressed && obs_source_active(ss->source))
|
|
|
|
ss_restart(ss);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stop_hotkey(void *data, obs_hotkey_id id,
|
|
|
|
obs_hotkey_t *hotkey, bool pressed)
|
|
|
|
{
|
|
|
|
UNUSED_PARAMETER(id);
|
|
|
|
UNUSED_PARAMETER(hotkey);
|
|
|
|
|
|
|
|
struct slideshow *ss = data;
|
|
|
|
|
|
|
|
if (pressed && obs_source_active(ss->source))
|
|
|
|
ss_stop(ss);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void next_slide_hotkey(void *data, obs_hotkey_id id,
|
|
|
|
obs_hotkey_t *hotkey, bool pressed)
|
|
|
|
{
|
|
|
|
UNUSED_PARAMETER(id);
|
|
|
|
UNUSED_PARAMETER(hotkey);
|
|
|
|
|
|
|
|
struct slideshow *ss = data;
|
|
|
|
|
|
|
|
if (!ss->manual)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (pressed && obs_source_active(ss->source))
|
|
|
|
ss_next_slide(ss);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void previous_slide_hotkey(void *data, obs_hotkey_id id,
|
|
|
|
obs_hotkey_t *hotkey, bool pressed)
|
|
|
|
{
|
|
|
|
UNUSED_PARAMETER(id);
|
|
|
|
UNUSED_PARAMETER(hotkey);
|
|
|
|
|
|
|
|
struct slideshow *ss = data;
|
|
|
|
|
|
|
|
if (!ss->manual)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (pressed && obs_source_active(ss->source))
|
|
|
|
ss_previous_slide(ss);
|
|
|
|
}
|
|
|
|
|
2016-05-24 07:31:48 -07:00
|
|
|
static void ss_destroy(void *data)
|
|
|
|
{
|
|
|
|
struct slideshow *ss = data;
|
|
|
|
|
|
|
|
obs_source_release(ss->transition);
|
|
|
|
free_files(&ss->files.da);
|
2018-08-26 02:54:32 -07:00
|
|
|
free_paths(&ss->paths.da);
|
2016-05-24 07:31:48 -07:00
|
|
|
pthread_mutex_destroy(&ss->mutex);
|
|
|
|
bfree(ss);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *ss_create(obs_data_t *settings, obs_source_t *source)
|
|
|
|
{
|
|
|
|
struct slideshow *ss = bzalloc(sizeof(*ss));
|
2017-08-04 20:39:13 -07:00
|
|
|
|
2016-05-24 07:31:48 -07:00
|
|
|
ss->source = source;
|
|
|
|
|
2017-08-04 21:10:05 -07:00
|
|
|
ss->manual = false;
|
2017-08-04 20:39:13 -07:00
|
|
|
ss->paused = false;
|
|
|
|
ss->stop = false;
|
|
|
|
|
2017-08-04 21:10:05 -07:00
|
|
|
ss->play_pause_hotkey = obs_hotkey_register_source(source,
|
|
|
|
"SlideShow.PlayPause",
|
|
|
|
obs_module_text("SlideShow.PlayPause"),
|
|
|
|
play_pause_hotkey, ss);
|
|
|
|
|
|
|
|
ss->restart_hotkey = obs_hotkey_register_source(source,
|
|
|
|
"SlideShow.Restart",
|
|
|
|
obs_module_text("SlideShow.Restart"),
|
|
|
|
restart_hotkey, ss);
|
|
|
|
|
|
|
|
ss->stop_hotkey = obs_hotkey_register_source(source,
|
|
|
|
"SlideShow.Stop",
|
|
|
|
obs_module_text("SlideShow.Stop"),
|
|
|
|
stop_hotkey, ss);
|
|
|
|
|
|
|
|
ss->prev_hotkey = obs_hotkey_register_source(source,
|
|
|
|
"SlideShow.NextSlide",
|
|
|
|
obs_module_text("SlideShow.NextSlide"),
|
|
|
|
next_slide_hotkey, ss);
|
|
|
|
|
|
|
|
ss->prev_hotkey = obs_hotkey_register_source(source,
|
|
|
|
"SlideShow.PreviousSlide",
|
|
|
|
obs_module_text("SlideShow.PreviousSlide"),
|
|
|
|
previous_slide_hotkey, ss);
|
|
|
|
|
2016-05-24 07:31:48 -07:00
|
|
|
pthread_mutex_init_value(&ss->mutex);
|
|
|
|
if (pthread_mutex_init(&ss->mutex, NULL) != 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
obs_source_update(source, NULL);
|
|
|
|
|
|
|
|
UNUSED_PARAMETER(settings);
|
|
|
|
return ss;
|
|
|
|
|
|
|
|
error:
|
|
|
|
ss_destroy(ss);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ss_video_render(void *data, gs_effect_t *effect)
|
|
|
|
{
|
|
|
|
struct slideshow *ss = data;
|
|
|
|
obs_source_t *transition = get_transition(ss);
|
|
|
|
|
|
|
|
if (transition) {
|
|
|
|
obs_source_video_render(transition);
|
|
|
|
obs_source_release(transition);
|
|
|
|
}
|
|
|
|
|
|
|
|
UNUSED_PARAMETER(effect);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ss_video_tick(void *data, float seconds)
|
|
|
|
{
|
|
|
|
struct slideshow *ss = data;
|
|
|
|
|
|
|
|
if (!ss->transition || !ss->slide_time)
|
|
|
|
return;
|
|
|
|
|
2018-08-26 02:54:32 -07:00
|
|
|
if (ss->restart_on_activate && ss->use_cut) {
|
|
|
|
ss_restart(ss);
|
2017-08-04 20:39:13 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-04 21:10:05 -07:00
|
|
|
if (ss->pause_on_deactivate || ss->manual || ss->stop || ss->paused)
|
2017-08-04 20:39:13 -07:00
|
|
|
return;
|
|
|
|
|
2018-02-23 19:24:26 -08:00
|
|
|
/* ----------------------------------------------------- */
|
|
|
|
/* fade to transparency when the file list becomes empty */
|
2018-08-26 02:54:32 -07:00
|
|
|
if (!ss->paths.num) {
|
2018-02-23 19:24:26 -08:00
|
|
|
obs_source_t* active_transition_source =
|
|
|
|
obs_transition_get_active_source(ss->transition);
|
|
|
|
|
|
|
|
if (active_transition_source) {
|
|
|
|
obs_source_release(active_transition_source);
|
2018-08-26 02:54:32 -07:00
|
|
|
do_transition(ss, true, true);
|
2018-02-23 19:24:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------- */
|
|
|
|
/* do transition when slide time reached */
|
2016-05-24 07:31:48 -07:00
|
|
|
ss->elapsed += seconds;
|
2017-08-04 20:39:13 -07:00
|
|
|
|
2016-05-24 07:31:48 -07:00
|
|
|
if (ss->elapsed > ss->slide_time) {
|
|
|
|
ss->elapsed -= ss->slide_time;
|
|
|
|
|
2018-08-26 02:54:32 -07:00
|
|
|
if (!ss->loop && ss->cur_item == (int)ss->paths.num - 1 &&
|
|
|
|
!ss->randomize) {
|
2017-07-22 19:40:36 -07:00
|
|
|
if (ss->hide)
|
2018-08-26 02:54:32 -07:00
|
|
|
do_transition(ss, true, true);
|
2017-07-22 19:40:36 -07:00
|
|
|
else
|
2018-08-26 02:54:32 -07:00
|
|
|
do_transition(ss, false, true);
|
2017-07-22 19:40:36 -07:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-26 02:54:32 -07:00
|
|
|
ss_next_slide(ss);
|
2016-05-24 07:31:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool ss_audio_render_(obs_source_t *transition, uint64_t *ts_out,
|
|
|
|
struct obs_source_audio_mix *audio_output,
|
|
|
|
uint32_t mixers, size_t channels, size_t sample_rate)
|
|
|
|
{
|
|
|
|
struct obs_source_audio_mix child_audio;
|
|
|
|
uint64_t source_ts;
|
|
|
|
|
|
|
|
if (obs_source_audio_pending(transition))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
source_ts = obs_source_get_audio_timestamp(transition);
|
|
|
|
if (!source_ts)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
obs_source_get_audio_mix(transition, &child_audio);
|
|
|
|
for (size_t mix = 0; mix < MAX_AUDIO_MIXES; mix++) {
|
|
|
|
if ((mixers & (1 << mix)) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (size_t ch = 0; ch < channels; ch++) {
|
|
|
|
float *out = audio_output->output[mix].data[ch];
|
|
|
|
float *in = child_audio.output[mix].data[ch];
|
|
|
|
|
|
|
|
memcpy(out, in, AUDIO_OUTPUT_FRAMES *
|
|
|
|
MAX_AUDIO_CHANNELS * sizeof(float));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*ts_out = source_ts;
|
|
|
|
|
|
|
|
UNUSED_PARAMETER(sample_rate);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool ss_audio_render(void *data, uint64_t *ts_out,
|
|
|
|
struct obs_source_audio_mix *audio_output,
|
|
|
|
uint32_t mixers, size_t channels, size_t sample_rate)
|
|
|
|
{
|
|
|
|
struct slideshow *ss = data;
|
|
|
|
obs_source_t *transition = get_transition(ss);
|
|
|
|
bool success;
|
|
|
|
|
|
|
|
if (!transition)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
success = ss_audio_render_(transition, ts_out, audio_output, mixers,
|
|
|
|
channels, sample_rate);
|
|
|
|
|
|
|
|
obs_source_release(transition);
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ss_enum_sources(void *data, obs_source_enum_proc_t cb, void *param)
|
|
|
|
{
|
|
|
|
struct slideshow *ss = data;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&ss->mutex);
|
|
|
|
if (ss->transition)
|
|
|
|
cb(ss->source, ss->transition, param);
|
|
|
|
pthread_mutex_unlock(&ss->mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t ss_width(void *data)
|
|
|
|
{
|
|
|
|
struct slideshow *ss = data;
|
|
|
|
return ss->transition ? ss->cx : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t ss_height(void *data)
|
|
|
|
{
|
|
|
|
struct slideshow *ss = data;
|
|
|
|
return ss->transition ? ss->cy : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ss_defaults(obs_data_t *settings)
|
|
|
|
{
|
|
|
|
obs_data_set_default_string(settings, S_TRANSITION, "fade");
|
|
|
|
obs_data_set_default_int(settings, S_SLIDE_TIME, 8000);
|
|
|
|
obs_data_set_default_int(settings, S_TR_SPEED, 700);
|
2017-05-14 20:53:55 -07:00
|
|
|
obs_data_set_default_string(settings, S_CUSTOM_SIZE, T_CUSTOM_SIZE_AUTO);
|
2017-08-04 20:39:13 -07:00
|
|
|
obs_data_set_default_string(settings, S_BEHAVIOR,
|
|
|
|
S_BEHAVIOR_ALWAYS_PLAY);
|
2017-08-04 21:10:05 -07:00
|
|
|
obs_data_set_default_string(settings, S_MODE, S_MODE_AUTO);
|
2017-07-22 19:40:36 -07:00
|
|
|
obs_data_set_default_bool(settings, S_LOOP, true);
|
2016-05-24 07:31:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *file_filter =
|
|
|
|
"Image files (*.bmp *.tga *.png *.jpeg *.jpg *.gif)";
|
|
|
|
|
2017-05-14 20:53:55 -07:00
|
|
|
static const char *aspects[] = {
|
|
|
|
"16:9",
|
|
|
|
"16:10",
|
|
|
|
"4:3",
|
|
|
|
"1:1"
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NUM_ASPECTS (sizeof(aspects) / sizeof(const char *))
|
|
|
|
|
2016-05-24 07:31:48 -07:00
|
|
|
static obs_properties_t *ss_properties(void *data)
|
|
|
|
{
|
|
|
|
obs_properties_t *ppts = obs_properties_create();
|
|
|
|
struct slideshow *ss = data;
|
2017-05-14 20:53:55 -07:00
|
|
|
struct obs_video_info ovi;
|
2016-05-24 07:31:48 -07:00
|
|
|
struct dstr path = {0};
|
|
|
|
obs_property_t *p;
|
2017-05-14 20:53:55 -07:00
|
|
|
int cx;
|
|
|
|
int cy;
|
|
|
|
|
|
|
|
/* ----------------- */
|
|
|
|
|
2019-02-19 11:59:46 -08:00
|
|
|
obs_properties_set_flags(ppts, OBS_PROPERTIES_DEFER_UPDATE);
|
|
|
|
|
2017-05-14 20:53:55 -07:00
|
|
|
obs_get_video_info(&ovi);
|
|
|
|
cx = (int)ovi.base_width;
|
|
|
|
cy = (int)ovi.base_height;
|
|
|
|
|
|
|
|
/* ----------------- */
|
2016-05-24 07:31:48 -07:00
|
|
|
|
2017-08-04 20:39:13 -07:00
|
|
|
p = obs_properties_add_list(ppts, S_BEHAVIOR, T_BEHAVIOR,
|
|
|
|
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
|
|
|
|
obs_property_list_add_string(p, T_BEHAVIOR_ALWAYS_PLAY,
|
|
|
|
S_BEHAVIOR_ALWAYS_PLAY);
|
|
|
|
obs_property_list_add_string(p, T_BEHAVIOR_STOP_RESTART,
|
|
|
|
S_BEHAVIOR_STOP_RESTART);
|
|
|
|
obs_property_list_add_string(p, T_BEHAVIOR_PAUSE_UNPAUSE,
|
|
|
|
S_BEHAVIOR_PAUSE_UNPAUSE);
|
|
|
|
|
2017-08-04 21:10:05 -07:00
|
|
|
p = obs_properties_add_list(ppts, S_MODE, T_MODE,
|
|
|
|
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
|
|
|
|
obs_property_list_add_string(p, T_MODE_AUTO, S_MODE_AUTO);
|
|
|
|
obs_property_list_add_string(p, T_MODE_MANUAL, S_MODE_MANUAL);
|
|
|
|
|
2016-05-24 07:31:48 -07:00
|
|
|
p = obs_properties_add_list(ppts, S_TRANSITION, T_TRANSITION,
|
|
|
|
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
|
|
|
|
obs_property_list_add_string(p, T_TR_CUT, TR_CUT);
|
|
|
|
obs_property_list_add_string(p, T_TR_FADE, TR_FADE);
|
|
|
|
obs_property_list_add_string(p, T_TR_SWIPE, TR_SWIPE);
|
|
|
|
obs_property_list_add_string(p, T_TR_SLIDE, TR_SLIDE);
|
|
|
|
|
|
|
|
obs_properties_add_int(ppts, S_SLIDE_TIME, T_SLIDE_TIME,
|
|
|
|
50, 3600000, 50);
|
|
|
|
obs_properties_add_int(ppts, S_TR_SPEED, T_TR_SPEED,
|
|
|
|
0, 3600000, 50);
|
2017-07-22 19:40:36 -07:00
|
|
|
obs_properties_add_bool(ppts, S_LOOP, T_LOOP);
|
|
|
|
obs_properties_add_bool(ppts, S_HIDE, T_HIDE);
|
2016-05-26 11:35:29 -07:00
|
|
|
obs_properties_add_bool(ppts, S_RANDOMIZE, T_RANDOMIZE);
|
2016-05-24 07:31:48 -07:00
|
|
|
|
2017-05-14 20:53:55 -07:00
|
|
|
p = obs_properties_add_list(ppts, S_CUSTOM_SIZE, T_CUSTOM_SIZE,
|
|
|
|
OBS_COMBO_TYPE_EDITABLE, OBS_COMBO_FORMAT_STRING);
|
|
|
|
|
|
|
|
obs_property_list_add_string(p, T_CUSTOM_SIZE_AUTO, T_CUSTOM_SIZE_AUTO);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < NUM_ASPECTS; i++)
|
|
|
|
obs_property_list_add_string(p, aspects[i], aspects[i]);
|
|
|
|
|
|
|
|
char str[32];
|
|
|
|
snprintf(str, 32, "%dx%d", cx, cy);
|
|
|
|
obs_property_list_add_string(p, str, str);
|
|
|
|
|
2016-05-24 07:31:48 -07:00
|
|
|
if (ss) {
|
|
|
|
pthread_mutex_lock(&ss->mutex);
|
2018-08-26 02:54:32 -07:00
|
|
|
if (ss->paths.num) {
|
|
|
|
char **p_last_path = da_end(ss->paths);
|
|
|
|
const char *last_path;
|
2016-05-24 07:31:48 -07:00
|
|
|
const char *slash;
|
|
|
|
|
2018-08-26 02:54:32 -07:00
|
|
|
last_path = p_last_path ? *p_last_path : "";
|
|
|
|
|
|
|
|
dstr_copy(&path, last_path);
|
2016-05-24 07:31:48 -07:00
|
|
|
dstr_replace(&path, "\\", "/");
|
|
|
|
slash = strrchr(path.array, '/');
|
|
|
|
if (slash)
|
|
|
|
dstr_resize(&path, slash - path.array + 1);
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&ss->mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
obs_properties_add_editable_list(ppts, S_FILES, T_FILES,
|
|
|
|
OBS_EDITABLE_LIST_TYPE_FILES, file_filter, path.array);
|
|
|
|
dstr_free(&path);
|
|
|
|
|
|
|
|
return ppts;
|
|
|
|
}
|
|
|
|
|
2017-08-04 20:39:13 -07:00
|
|
|
static void ss_activate(void *data)
|
|
|
|
{
|
|
|
|
struct slideshow *ss = data;
|
|
|
|
|
|
|
|
if (ss->behavior == BEHAVIOR_STOP_RESTART) {
|
|
|
|
ss->restart_on_activate = true;
|
|
|
|
ss->use_cut = true;
|
|
|
|
} else if (ss->behavior == BEHAVIOR_PAUSE_UNPAUSE) {
|
|
|
|
ss->pause_on_deactivate = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ss_deactivate(void *data)
|
|
|
|
{
|
|
|
|
struct slideshow *ss = data;
|
|
|
|
|
|
|
|
if (ss->behavior == BEHAVIOR_PAUSE_UNPAUSE)
|
|
|
|
ss->pause_on_deactivate = true;
|
|
|
|
}
|
|
|
|
|
2016-05-24 07:31:48 -07:00
|
|
|
struct obs_source_info slideshow_info = {
|
|
|
|
.id = "slideshow",
|
|
|
|
.type = OBS_SOURCE_TYPE_INPUT,
|
|
|
|
.output_flags = OBS_SOURCE_VIDEO |
|
|
|
|
OBS_SOURCE_CUSTOM_DRAW |
|
|
|
|
OBS_SOURCE_COMPOSITE,
|
|
|
|
.get_name = ss_getname,
|
|
|
|
.create = ss_create,
|
|
|
|
.destroy = ss_destroy,
|
|
|
|
.update = ss_update,
|
2017-08-04 20:39:13 -07:00
|
|
|
.activate = ss_activate,
|
|
|
|
.deactivate = ss_deactivate,
|
2016-05-24 07:31:48 -07:00
|
|
|
.video_render = ss_video_render,
|
|
|
|
.video_tick = ss_video_tick,
|
|
|
|
.audio_render = ss_audio_render,
|
|
|
|
.enum_active_sources = ss_enum_sources,
|
|
|
|
.get_width = ss_width,
|
|
|
|
.get_height = ss_height,
|
|
|
|
.get_defaults = ss_defaults,
|
|
|
|
.get_properties = ss_properties
|
|
|
|
};
|