mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-07-15 07:44:10 +00:00
libobs: Add function to get obs object type
This commit is contained in:
parent
826d5c08d7
commit
d069302b2e
|
@ -54,8 +54,8 @@ static bool init_encoder(struct obs_encoder *encoder, const char *name,
|
|||
return false;
|
||||
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
|
||||
return false;
|
||||
if (!obs_context_data_init(&encoder->context, settings, name,
|
||||
hotkey_data, false))
|
||||
if (!obs_context_data_init(&encoder->context, OBS_OBJ_TYPE_ENCODER,
|
||||
settings, name, hotkey_data, false))
|
||||
return false;
|
||||
if (pthread_mutex_init(&encoder->init_mutex, &attr) != 0)
|
||||
return false;
|
||||
|
|
|
@ -385,6 +385,7 @@ struct obs_context_data {
|
|||
obs_data_t *settings;
|
||||
signal_handler_t *signals;
|
||||
proc_handler_t *procs;
|
||||
enum obs_obj_type type;
|
||||
|
||||
DARRAY(obs_hotkey_id) hotkeys;
|
||||
DARRAY(obs_hotkey_pair_id) hotkey_pairs;
|
||||
|
@ -402,6 +403,7 @@ struct obs_context_data {
|
|||
|
||||
extern bool obs_context_data_init(
|
||||
struct obs_context_data *context,
|
||||
enum obs_obj_type type,
|
||||
obs_data_t *settings,
|
||||
const char *name,
|
||||
obs_data_t *hotkey_data,
|
||||
|
|
|
@ -53,8 +53,8 @@ static const char *output_signals[] = {
|
|||
static bool init_output_handlers(struct obs_output *output, const char *name,
|
||||
obs_data_t *settings, obs_data_t *hotkey_data)
|
||||
{
|
||||
if (!obs_context_data_init(&output->context, settings, name,
|
||||
hotkey_data, false))
|
||||
if (!obs_context_data_init(&output->context, OBS_OBJ_TYPE_OUTPUT,
|
||||
settings, name, hotkey_data, false))
|
||||
return false;
|
||||
|
||||
signal_handler_add_array(output->context.signals, output_signals);
|
||||
|
|
|
@ -46,8 +46,8 @@ obs_service_t *obs_service_create(const char *id, const char *name,
|
|||
|
||||
service = bzalloc(sizeof(struct obs_service));
|
||||
|
||||
if (!obs_context_data_init(&service->context, settings, name,
|
||||
hotkey_data, false)) {
|
||||
if (!obs_context_data_init(&service->context, OBS_OBJ_TYPE_SERVICE,
|
||||
settings, name, hotkey_data, false)) {
|
||||
bfree(service);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -79,8 +79,8 @@ bool obs_source_init_context(struct obs_source *source,
|
|||
obs_data_t *settings, const char *name, obs_data_t *hotkey_data,
|
||||
bool private)
|
||||
{
|
||||
if (!obs_context_data_init(&source->context, settings, name,
|
||||
hotkey_data, private))
|
||||
if (!obs_context_data_init(&source->context, OBS_OBJ_TYPE_SOURCE,
|
||||
settings, name, hotkey_data, private))
|
||||
return false;
|
||||
|
||||
return signal_handler_add_array(source->context.signals,
|
||||
|
|
13
libobs/obs.c
13
libobs/obs.c
|
@ -1650,6 +1650,7 @@ static inline char *dup_name(const char *name, bool private)
|
|||
|
||||
static inline bool obs_context_data_init_wrap(
|
||||
struct obs_context_data *context,
|
||||
enum obs_obj_type type,
|
||||
obs_data_t *settings,
|
||||
const char *name,
|
||||
obs_data_t *hotkey_data,
|
||||
|
@ -1658,6 +1659,7 @@ static inline bool obs_context_data_init_wrap(
|
|||
assert(context);
|
||||
memset(context, 0, sizeof(*context));
|
||||
context->private = private;
|
||||
context->type = type;
|
||||
|
||||
pthread_mutex_init_value(&context->rename_cache_mutex);
|
||||
if (pthread_mutex_init(&context->rename_cache_mutex, NULL) < 0)
|
||||
|
@ -1679,13 +1681,14 @@ static inline bool obs_context_data_init_wrap(
|
|||
|
||||
bool obs_context_data_init(
|
||||
struct obs_context_data *context,
|
||||
enum obs_obj_type type,
|
||||
obs_data_t *settings,
|
||||
const char *name,
|
||||
obs_data_t *hotkey_data,
|
||||
bool private)
|
||||
{
|
||||
if (obs_context_data_init_wrap(context, settings, name, hotkey_data,
|
||||
private)) {
|
||||
if (obs_context_data_init_wrap(context, type, settings, name,
|
||||
hotkey_data, private)) {
|
||||
return true;
|
||||
} else {
|
||||
obs_context_data_free(context);
|
||||
|
@ -1768,3 +1771,9 @@ uint64_t obs_get_video_frame_time(void)
|
|||
{
|
||||
return obs ? obs->video.video_time : 0;
|
||||
}
|
||||
|
||||
enum obs_obj_type obs_obj_get_type(void *obj)
|
||||
{
|
||||
struct obs_context_data *context = obj;
|
||||
return context ? context->type : OBS_OBJ_TYPE_INVALID;
|
||||
}
|
||||
|
|
10
libobs/obs.h
10
libobs/obs.h
|
@ -560,6 +560,16 @@ typedef bool (*obs_save_source_filter_cb)(void *data, obs_source_t *source);
|
|||
EXPORT obs_data_array_t *obs_save_sources_filtered(obs_save_source_filter_cb cb,
|
||||
void *data);
|
||||
|
||||
enum obs_obj_type {
|
||||
OBS_OBJ_TYPE_INVALID,
|
||||
OBS_OBJ_TYPE_SOURCE,
|
||||
OBS_OBJ_TYPE_OUTPUT,
|
||||
OBS_OBJ_TYPE_ENCODER,
|
||||
OBS_OBJ_TYPE_SERVICE
|
||||
};
|
||||
|
||||
EXPORT enum obs_obj_type obs_obj_get_type(void *obj);
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* View context */
|
||||
|
|
Loading…
Reference in a new issue