mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-07-14 23:34:08 +00:00
add obs_source functions to allow name manipulation and lookup based upon name, and a few other functions related to getting/setting source information
This commit is contained in:
parent
95a7da2d4c
commit
9218627892
|
@ -68,6 +68,8 @@ struct obs_audio {
|
|||
|
||||
/* user sources, output channels, and displays */
|
||||
struct obs_data {
|
||||
/* arrays of pointers jim? you should really stop being lazy and use
|
||||
* linked lists. */
|
||||
DARRAY(struct obs_display*) displays;
|
||||
DARRAY(struct obs_source*) sources;
|
||||
|
||||
|
|
|
@ -144,6 +144,7 @@ obs_source_t obs_source_create(enum obs_source_type type, const char *id,
|
|||
memset(source, 0, sizeof(struct obs_source));
|
||||
|
||||
source->name = bstrdup(name);
|
||||
source->type = type;
|
||||
source->data = info->create(settings, source);
|
||||
if (!source->data)
|
||||
goto fail;
|
||||
|
@ -618,12 +619,12 @@ void obs_source_filter_setorder(obs_source_t source, obs_source_t filter,
|
|||
}
|
||||
}
|
||||
|
||||
const char *obs_source_get_settings(obs_source_t source)
|
||||
const char *obs_source_getsettings(obs_source_t source)
|
||||
{
|
||||
return source->settings.array;
|
||||
}
|
||||
|
||||
void obs_source_save_settings(obs_source_t source, const char *settings)
|
||||
void obs_source_savesettings(obs_source_t source, const char *settings)
|
||||
{
|
||||
dstr_copy(&source->settings, settings);
|
||||
}
|
||||
|
@ -873,3 +874,21 @@ void obs_source_releaseframe(obs_source_t source, struct source_frame *frame)
|
|||
obs_source_release(source);
|
||||
}
|
||||
}
|
||||
|
||||
const char *obs_source_getname(obs_source_t source)
|
||||
{
|
||||
return source->name;
|
||||
}
|
||||
|
||||
void obs_source_setname(obs_source_t source, const char *name)
|
||||
{
|
||||
bfree(source->name);
|
||||
source->name = bstrdup(name);
|
||||
}
|
||||
|
||||
void obs_source_getid(obs_source_t source, enum obs_source_type *type,
|
||||
const char **id)
|
||||
{
|
||||
*type = source->type;
|
||||
*id = source->callbacks.id;
|
||||
}
|
||||
|
|
|
@ -205,6 +205,7 @@ struct obs_source {
|
|||
|
||||
/* source-specific data */
|
||||
char *name; /* user-defined name */
|
||||
enum obs_source_type type;
|
||||
struct dstr settings;
|
||||
void *data;
|
||||
struct source_info callbacks;
|
||||
|
|
28
libobs/obs.c
28
libobs/obs.c
|
@ -450,15 +450,37 @@ void obs_set_output_source(uint32_t channel, obs_source_t source)
|
|||
obs_source_release(prev_source);
|
||||
}
|
||||
|
||||
void obs_enum_sources(ENUM_SOURCES_PROC enum_proc, void *param)
|
||||
void obs_enum_sources(bool (*enum_proc)(obs_source_t, void*), void *param)
|
||||
{
|
||||
struct obs_data *data = &obs->data;
|
||||
size_t i;
|
||||
|
||||
pthread_mutex_lock(&data->sources_mutex);
|
||||
|
||||
for (i = 0; i < data->sources.num; i++)
|
||||
enum_proc(data->sources.array[i], param);
|
||||
for (i = 0; i < data->sources.num; i++) {
|
||||
if (!enum_proc(data->sources.array[i], param))
|
||||
break;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&data->sources_mutex);
|
||||
}
|
||||
|
||||
obs_source_t obs_get_source_by_name(const char *name)
|
||||
{
|
||||
struct obs_data *data = &obs->data;
|
||||
struct obs_source *source = NULL;
|
||||
size_t i;
|
||||
|
||||
pthread_mutex_lock(&data->sources_mutex);
|
||||
|
||||
for (i = 0; i < data->sources.num; i++) {
|
||||
struct obs_source *cur_source = data->sources.array[i];
|
||||
if (strcmp(cur_source->name, name) == 0) {
|
||||
source = cur_source;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&data->sources_mutex);
|
||||
return source;
|
||||
}
|
||||
|
|
37
libobs/obs.h
37
libobs/obs.h
|
@ -142,9 +142,6 @@ typedef struct obs_scene_item *obs_sceneitem_t;
|
|||
typedef struct obs_output *obs_output_t;
|
||||
typedef struct obs_service *obs_service_t;
|
||||
|
||||
/* typedefs */
|
||||
typedef void (*ENUM_SOURCES_PROC)(obs_source_t source, void *param);
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* OBS context */
|
||||
|
||||
|
@ -242,8 +239,22 @@ EXPORT void obs_set_output_source(uint32_t channel, obs_source_t source);
|
|||
*/
|
||||
EXPORT obs_source_t obs_get_output_source(uint32_t channel);
|
||||
|
||||
/** Enumerates user sources */
|
||||
EXPORT void obs_enum_sources(ENUM_SOURCES_PROC enum_proc, void *param);
|
||||
/**
|
||||
* Enumerates user sources
|
||||
*
|
||||
* Callback function returns true to continue enumeration, or false to end
|
||||
* enumeration.
|
||||
*/
|
||||
EXPORT void obs_enum_sources(bool (*enum_proc)(obs_source_t, void*),
|
||||
void *param);
|
||||
|
||||
/**
|
||||
* Gets a source by its name.
|
||||
*
|
||||
* Increments the source reference counter, use obs_source_release to
|
||||
* release it when complete.
|
||||
*/
|
||||
EXPORT obs_source_t obs_get_source_by_name(const char *name);
|
||||
|
||||
/**
|
||||
* Returns the location of a plugin data file.
|
||||
|
@ -287,7 +298,7 @@ EXPORT const char *obs_source_getdisplayname(enum obs_source_type type,
|
|||
* Creates a source of the specified type with the specified settings.
|
||||
*
|
||||
* The "source" context is used for anything related to presenting
|
||||
* or modifying video/audio.
|
||||
* or modifying video/audio. Use obs_source_release to release it.
|
||||
*/
|
||||
EXPORT obs_source_t obs_source_create(enum obs_source_type type,
|
||||
const char *id, const char *name, const char *settings);
|
||||
|
@ -359,13 +370,23 @@ EXPORT void obs_source_filter_setorder(obs_source_t source, obs_source_t filter,
|
|||
enum order_movement movement);
|
||||
|
||||
/** Gets the settings string for a source */
|
||||
EXPORT const char *obs_source_get_settings(obs_source_t source);
|
||||
EXPORT const char *obs_source_getsettings(obs_source_t source);
|
||||
|
||||
/** Gets the name of a source */
|
||||
EXPORT const char *obs_source_getname(obs_source_t source);
|
||||
|
||||
/** Sets the name of a source */
|
||||
EXPORT void obs_source_setname(obs_source_t source, const char *name);
|
||||
|
||||
/** Gets the source type and identifier */
|
||||
EXPORT void obs_source_getid(obs_source_t source, enum obs_source_type *type,
|
||||
const char **id);
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Functions used by sources */
|
||||
|
||||
/** Saves the settings string for a source */
|
||||
EXPORT void obs_source_save_settings(obs_source_t source, const char *settings);
|
||||
EXPORT void obs_source_savesettings(obs_source_t source, const char *settings);
|
||||
|
||||
/** Outputs asynchronous video data */
|
||||
EXPORT void obs_source_output_video(obs_source_t source,
|
||||
|
|
Loading…
Reference in a new issue