Simplify and extend callback/signalling system
- Signals and dynamic callbacks now require declarations to be made before being used. What this does is allows us to get information about the functions dynamically which can be relayed to the user and plugins for future extended usage (this should have big implications later for scripting in particular, hopefully). - Reduced the number of types calldata uses from "everything I could think of" to simply integer, float, bool, pointer/object, string. Integer data is now stored as long long. Floats are now stored as doubles (check em). - Use a more consistent naming scheme for lexer error/warning macros. - Fixed a rather nasty bug where switching to an existing scene would cause it to increment sourceSceneRefs, which would mean that it would never end up never properly removing the source when the user clicks removed (stayed in limbo, obs_source_remove never got called)
This commit is contained in:
32
libobs/obs.c
32
libobs/obs.c
@@ -407,6 +407,23 @@ static void obs_free_data(void)
|
||||
pthread_mutex_destroy(&data->encoders_mutex);
|
||||
}
|
||||
|
||||
static const char *obs_signals[] = {
|
||||
"void source_create(ptr source)",
|
||||
"void source_destroy(ptr source)",
|
||||
"void source_add(ptr source)",
|
||||
"void source_remove(ptr source)",
|
||||
"void source_activate(ptr source)",
|
||||
"void source_deactivate(ptr source)",
|
||||
"void source_show(ptr source)",
|
||||
"void source_hide(ptr source)",
|
||||
"void source_volume(ptr source, in out float volume)",
|
||||
|
||||
"void channel_change(int channel, in out ptr source, ptr prev_source)",
|
||||
"void master_volume(in out float volume)",
|
||||
|
||||
NULL
|
||||
};
|
||||
|
||||
static inline bool obs_init_handlers(void)
|
||||
{
|
||||
obs->signals = signal_handler_create();
|
||||
@@ -414,7 +431,10 @@ static inline bool obs_init_handlers(void)
|
||||
return false;
|
||||
|
||||
obs->procs = proc_handler_create();
|
||||
return (obs->procs != NULL);
|
||||
if (!obs->procs)
|
||||
return false;
|
||||
|
||||
return signal_handler_add_array(obs->signals, obs_signals);
|
||||
}
|
||||
|
||||
static bool obs_init(void)
|
||||
@@ -682,7 +702,7 @@ bool obs_add_source(obs_source_t source)
|
||||
pthread_mutex_unlock(&obs->data.sources_mutex);
|
||||
|
||||
calldata_setptr(¶ms, "source", source);
|
||||
signal_handler_signal(obs->signals, "source-add", ¶ms);
|
||||
signal_handler_signal(obs->signals, "source_add", ¶ms);
|
||||
calldata_free(¶ms);
|
||||
|
||||
return true;
|
||||
@@ -709,10 +729,10 @@ void obs_set_output_source(uint32_t channel, obs_source_t source)
|
||||
|
||||
prev_source = view->channels[channel];
|
||||
|
||||
calldata_setuint32(¶ms, "channel", channel);
|
||||
calldata_setint(¶ms, "channel", channel);
|
||||
calldata_setptr(¶ms, "prev_source", prev_source);
|
||||
calldata_setptr(¶ms, "source", source);
|
||||
signal_handler_signal(obs->signals, "channel-change", ¶ms);
|
||||
signal_handler_signal(obs->signals, "channel_change", ¶ms);
|
||||
calldata_getptr(¶ms, "source", &source);
|
||||
calldata_free(¶ms);
|
||||
|
||||
@@ -854,8 +874,8 @@ void obs_set_master_volume(float volume)
|
||||
if (!obs) return;
|
||||
|
||||
calldata_setfloat(&data, "volume", volume);
|
||||
signal_handler_signal(obs->signals, "master-volume", &data);
|
||||
volume = calldata_float(&data, "volume");
|
||||
signal_handler_signal(obs->signals, "master_volume", &data);
|
||||
volume = (float)calldata_float(&data, "volume");
|
||||
calldata_free(&data);
|
||||
|
||||
obs->audio.user_volume = volume;
|
||||
|
Reference in New Issue
Block a user