mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-07-15 07:44:10 +00:00
implement signal/procedure handling into libobs and individual sources
This commit is contained in:
parent
3b48f79442
commit
6edcd456fe
|
@ -20,6 +20,7 @@
|
|||
|
||||
struct proc_info {
|
||||
char *name;
|
||||
void *data;
|
||||
void (*proc)(calldata_t, void*);
|
||||
};
|
||||
|
||||
|
@ -29,16 +30,13 @@ static inline void proc_info_free(struct proc_info *pi)
|
|||
}
|
||||
|
||||
struct proc_handler {
|
||||
void *data;
|
||||
|
||||
/* TODO: replace with hash table lookup? */
|
||||
DARRAY(struct proc_info) procs;
|
||||
};
|
||||
|
||||
proc_handler_t proc_handler_create(void *data)
|
||||
proc_handler_t proc_handler_create(void)
|
||||
{
|
||||
struct proc_handler *handler = bmalloc(sizeof(struct proc_handler));
|
||||
handler->data = data;
|
||||
da_init(handler->procs);
|
||||
return handler;
|
||||
}
|
||||
|
@ -54,9 +52,9 @@ void proc_handler_destroy(proc_handler_t handler)
|
|||
}
|
||||
|
||||
void proc_handler_add(proc_handler_t handler, const char *name,
|
||||
void (*proc)(calldata_t, void*))
|
||||
void (*proc)(calldata_t, void*), void *data)
|
||||
{
|
||||
struct proc_info pi = {bstrdup(name), proc};
|
||||
struct proc_info pi = {bstrdup(name), data, proc};
|
||||
da_push_back(handler->procs, &pi);
|
||||
}
|
||||
|
||||
|
@ -67,7 +65,7 @@ bool proc_handler_call(proc_handler_t handler, const char *name,
|
|||
struct proc_info *info = handler->procs.array+i;
|
||||
|
||||
if (strcmp(info->name, name) == 0) {
|
||||
info->proc(params, handler->data);
|
||||
info->proc(params, info->data);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,18 +24,22 @@
|
|||
* Dynamic procedure handler
|
||||
*
|
||||
* This handler is used to allow dynamic access to one or more procedures
|
||||
* that can be called without having to have direct access to declarations
|
||||
* or procedure callback pointers.
|
||||
* that can be dynamically added and called without having to have direct
|
||||
* access to declarations or procedure callback pointers.
|
||||
*/
|
||||
|
||||
struct proc_handler;
|
||||
typedef struct proc_handler *proc_handler_t;
|
||||
|
||||
proc_handler_t proc_handler_create(void *data);
|
||||
void proc_handler_destroy(proc_handler_t handler);
|
||||
EXPORT proc_handler_t proc_handler_create(void);
|
||||
EXPORT void proc_handler_destroy(proc_handler_t handler);
|
||||
|
||||
void proc_handler_add(proc_handler_t handler, const char *name,
|
||||
void (*proc)(calldata_t, void*));
|
||||
EXPORT void proc_handler_add(proc_handler_t handler, const char *name,
|
||||
void (*proc)(calldata_t, void*), void *data);
|
||||
|
||||
bool proc_handler_call(proc_handler_t handler, const char *name,
|
||||
/**
|
||||
* Calls a function in a procedure handler. Returns false if the named
|
||||
* procedure is not found.
|
||||
*/
|
||||
EXPORT bool proc_handler_call(proc_handler_t handler, const char *name,
|
||||
calldata_t params);
|
||||
|
|
|
@ -88,6 +88,9 @@ struct obs_subsystem {
|
|||
|
||||
media_t media;
|
||||
|
||||
signal_handler_t signals;
|
||||
proc_handler_t procs;
|
||||
|
||||
/* segmented into multiple sub-structures to keep things a bit more
|
||||
* clean and organized */
|
||||
struct obs_video video;
|
||||
|
|
|
@ -85,6 +85,16 @@ static inline const struct source_info *find_source(struct darray *list,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static inline bool obs_source_init_handlers(struct obs_source *source)
|
||||
{
|
||||
source->signals = signal_handler_create();
|
||||
if (!source->signals)
|
||||
return false;
|
||||
|
||||
source->procs = proc_handler_create();
|
||||
return (source->procs != NULL);
|
||||
}
|
||||
|
||||
/* internal initialization */
|
||||
bool obs_source_init(struct obs_source *source, const char *settings,
|
||||
const struct source_info *info)
|
||||
|
@ -143,6 +153,9 @@ obs_source_t obs_source_create(enum obs_source_type type, const char *id,
|
|||
source = bmalloc(sizeof(struct obs_source));
|
||||
memset(source, 0, sizeof(struct obs_source));
|
||||
|
||||
if (!obs_source_init_handlers(source))
|
||||
goto fail;
|
||||
|
||||
source->name = bstrdup(name);
|
||||
source->type = type;
|
||||
source->data = info->create(settings, source);
|
||||
|
@ -186,6 +199,9 @@ static void obs_source_destroy(obs_source_t source)
|
|||
audio_line_destroy(source->audio_line);
|
||||
audio_resampler_destroy(source->resampler);
|
||||
|
||||
proc_handler_destroy(source->procs);
|
||||
signal_handler_destroy(source->signals);
|
||||
|
||||
da_free(source->video_frames);
|
||||
da_free(source->audio_wait_buffer);
|
||||
da_free(source->filters);
|
||||
|
@ -1004,3 +1020,13 @@ void obs_source_process_filter(obs_source_t filter, texrender_t texrender,
|
|||
render_filter_tex(texrender_gettexture(texrender), effect,
|
||||
width, height, yuv);
|
||||
}
|
||||
|
||||
signal_handler_t obs_source_signalhandler(obs_source_t source)
|
||||
{
|
||||
return source->signals;
|
||||
}
|
||||
|
||||
proc_handler_t obs_source_prochandler(obs_source_t source)
|
||||
{
|
||||
return source->procs;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include "util/threading.h"
|
||||
#include "media-io/media-io.h"
|
||||
#include "media-io/audio-resampler.h"
|
||||
#include "callback/signal.h"
|
||||
#include "callback/proc.h"
|
||||
|
||||
/*
|
||||
* ===========================================
|
||||
|
@ -210,6 +212,9 @@ struct obs_source {
|
|||
void *data;
|
||||
struct source_info callbacks;
|
||||
|
||||
signal_handler_t signals;
|
||||
proc_handler_t procs;
|
||||
|
||||
/* used to indicate that the source has been removed and all
|
||||
* references to it should be released (not exactly how I would prefer
|
||||
* to handle things but it's the best option) */
|
||||
|
|
25
libobs/obs.c
25
libobs/obs.c
|
@ -252,6 +252,16 @@ static void obs_free_data(void)
|
|||
pthread_mutex_unlock(&obs->data.sources_mutex);
|
||||
}
|
||||
|
||||
static inline bool obs_init_handlers(void)
|
||||
{
|
||||
obs->signals = signal_handler_create();
|
||||
if (!obs->signals)
|
||||
return false;
|
||||
|
||||
obs->procs = proc_handler_create();
|
||||
return (obs->procs != NULL);
|
||||
}
|
||||
|
||||
static bool obs_init(void)
|
||||
{
|
||||
obs = bmalloc(sizeof(struct obs_subsystem));
|
||||
|
@ -259,6 +269,9 @@ static bool obs_init(void)
|
|||
memset(obs, 0, sizeof(struct obs_subsystem));
|
||||
obs_init_data();
|
||||
|
||||
if (!obs_init_handlers())
|
||||
return false;
|
||||
|
||||
obs->media = media_open();
|
||||
if (!obs->media)
|
||||
return false;
|
||||
|
@ -300,6 +313,8 @@ void obs_shutdown(void)
|
|||
obs_free_graphics();
|
||||
obs_free_audio();
|
||||
media_close(obs->media);
|
||||
proc_handler_destroy(obs->procs);
|
||||
signal_handler_destroy(obs->signals);
|
||||
|
||||
for (i = 0; i < obs->modules.num; i++)
|
||||
free_module(obs->modules.array+i);
|
||||
|
@ -489,3 +504,13 @@ effect_t obs_get_default_effect(void)
|
|||
{
|
||||
return obs->video.default_effect;
|
||||
}
|
||||
|
||||
signal_handler_t obs_signalhandler(void)
|
||||
{
|
||||
return obs->signals;
|
||||
}
|
||||
|
||||
proc_handler_t obs_prochandler(void)
|
||||
{
|
||||
return obs->procs;
|
||||
}
|
||||
|
|
14
libobs/obs.h
14
libobs/obs.h
|
@ -21,6 +21,8 @@
|
|||
#include "graphics/graphics.h"
|
||||
#include "graphics/vec2.h"
|
||||
#include "media-io/media-io.h"
|
||||
#include "callback/signal.h"
|
||||
#include "callback/proc.h"
|
||||
|
||||
#include "obs-defs.h"
|
||||
|
||||
|
@ -272,6 +274,12 @@ EXPORT char *obs_find_plugin_file(const char *file);
|
|||
/** Returns the default effect for generic RGB/YUV drawing */
|
||||
EXPORT effect_t obs_get_default_effect(void);
|
||||
|
||||
/** Returns the primary obs signal handler */
|
||||
EXPORT signal_handler_t obs_signalhandler(void);
|
||||
|
||||
/** Returns the primary obs procedure handler */
|
||||
EXPORT proc_handler_t obs_prochandler(void);
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Display context */
|
||||
|
@ -393,6 +401,12 @@ EXPORT void obs_source_setname(obs_source_t source, const char *name);
|
|||
EXPORT void obs_source_getid(obs_source_t source, enum obs_source_type *type,
|
||||
const char **id);
|
||||
|
||||
/** Returns the signal handler for a source */
|
||||
EXPORT signal_handler_t obs_source_signalhandler(obs_source_t source);
|
||||
|
||||
/** Returns the procedure handler for a source */
|
||||
EXPORT proc_handler_t obs_source_prochandler(obs_source_t source);
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Functions used by sources */
|
||||
|
||||
|
|
Loading…
Reference in a new issue