mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-09-19 20:32:15 +02:00
libobs: Use UUIDs for all contexts
This adds UUIDs to outputs, encoders and services.
This commit is contained in:
parent
07dd32ad14
commit
1b727e8d1d
@ -382,6 +382,15 @@ Libobs Objects
|
||||
|
||||
---------------------
|
||||
|
||||
.. function:: obs_output_t *obs_get_output_by_uuid(const char *uuid)
|
||||
|
||||
Gets an output by its UUID.
|
||||
|
||||
Increments the output reference counter, use
|
||||
:c:func:`obs_output_release()` to release it when complete.
|
||||
|
||||
---------------------
|
||||
|
||||
.. function:: obs_encoder_t *obs_get_encoder_by_name(const char *name)
|
||||
|
||||
Gets an encoder by its name.
|
||||
@ -391,6 +400,15 @@ Libobs Objects
|
||||
|
||||
---------------------
|
||||
|
||||
.. function:: obs_encoder_t *obs_get_encoder_by_uuid(const char *uuid)
|
||||
|
||||
Gets an encoder by its UUID.
|
||||
|
||||
Increments the encoder reference counter, use
|
||||
:c:func:`obs_encoder_release()` to release it when complete.
|
||||
|
||||
---------------------
|
||||
|
||||
.. function:: obs_service_t *obs_get_service_by_name(const char *name)
|
||||
|
||||
Gets an service by its name.
|
||||
@ -400,6 +418,15 @@ Libobs Objects
|
||||
|
||||
---------------------
|
||||
|
||||
.. function:: obs_service_t *obs_get_service_by_uuid(const char *uuid)
|
||||
|
||||
Gets an service by its UUID.
|
||||
|
||||
Increments the service reference counter, use
|
||||
:c:func:`obs_service_release()` to release it when complete.
|
||||
|
||||
---------------------
|
||||
|
||||
.. function:: obs_data_t *obs_save_source(obs_source_t *source)
|
||||
|
||||
:return: A new reference to a source's saved data. Use
|
||||
|
@ -378,6 +378,12 @@ General Encoder Functions
|
||||
|
||||
---------------------
|
||||
|
||||
.. function:: const char *obs_encoder_get_uuid(const obs_encoder_t *encoder)
|
||||
|
||||
:return: The UUID of the encoder
|
||||
|
||||
---------------------
|
||||
|
||||
.. function:: const char *obs_encoder_get_codec(const obs_encoder_t *encoder)
|
||||
const char *obs_get_encoder_codec(const char *id)
|
||||
|
||||
|
@ -397,6 +397,12 @@ General Output Functions
|
||||
|
||||
---------------------
|
||||
|
||||
.. function:: const char *obs_output_get_uuid(const obs_output_t *output)
|
||||
|
||||
:return: The UUID of the output
|
||||
|
||||
---------------------
|
||||
|
||||
.. function:: const char *obs_output_get_id(const obs_output_t *output)
|
||||
|
||||
:return: The output's type identifier string
|
||||
|
@ -287,6 +287,12 @@ General Service Functions
|
||||
|
||||
---------------------
|
||||
|
||||
.. function:: const char *obs_service_get_uuid(const obs_service_t *service)
|
||||
|
||||
:return: The UUID of the service
|
||||
|
||||
---------------------
|
||||
|
||||
.. function:: obs_data_t *obs_service_defaults(const char *id)
|
||||
|
||||
:return: An incremented reference to the service's default settings.
|
||||
|
@ -431,6 +431,13 @@ void obs_encoder_set_name(obs_encoder_t *encoder, const char *name)
|
||||
obs_context_data_setname(&encoder->context, name);
|
||||
}
|
||||
|
||||
const char *obs_encoder_get_uuid(const obs_encoder_t *encoder)
|
||||
{
|
||||
return obs_encoder_valid(encoder, "obs_encoder_get_uuid")
|
||||
? encoder->context.uuid
|
||||
: NULL;
|
||||
}
|
||||
|
||||
static inline obs_data_t *get_defaults(const struct obs_encoder_info *info)
|
||||
{
|
||||
obs_data_t *settings = obs_data_create();
|
||||
|
@ -316,6 +316,13 @@ const char *obs_output_get_name(const obs_output_t *output)
|
||||
: NULL;
|
||||
}
|
||||
|
||||
const char *obs_output_get_uuid(const obs_output_t *output)
|
||||
{
|
||||
return obs_output_valid(output, "obs_output_get_uuid")
|
||||
? output->context.uuid
|
||||
: NULL;
|
||||
}
|
||||
|
||||
bool obs_output_actual_start(obs_output_t *output)
|
||||
{
|
||||
bool success = false;
|
||||
|
@ -123,6 +123,13 @@ const char *obs_service_get_name(const obs_service_t *service)
|
||||
: NULL;
|
||||
}
|
||||
|
||||
const char *obs_service_get_uuid(const obs_service_t *service)
|
||||
{
|
||||
return obs_service_valid(service, "obs_service_get_uuid")
|
||||
? service->context.uuid
|
||||
: NULL;
|
||||
}
|
||||
|
||||
static inline obs_data_t *get_defaults(const struct obs_service_info *info)
|
||||
{
|
||||
obs_data_t *settings = obs_data_create();
|
||||
|
43
libobs/obs.c
43
libobs/obs.c
@ -1998,16 +1998,29 @@ static inline void *get_context_by_name(void *vfirst, const char *name,
|
||||
return context;
|
||||
}
|
||||
|
||||
static void *get_context_by_uuid(void *ptable, const char *uuid,
|
||||
static void *get_context_by_uuid(void *vfirst, const char *uuid,
|
||||
pthread_mutex_t *mutex,
|
||||
void *(*addref)(void *))
|
||||
{
|
||||
struct obs_context_data **ht = ptable;
|
||||
struct obs_context_data **first = vfirst;
|
||||
struct obs_context_data *context;
|
||||
|
||||
pthread_mutex_lock(mutex);
|
||||
|
||||
HASH_FIND_UUID(*ht, uuid, context);
|
||||
/* If context list head has a hash table, look the uuid up in there */
|
||||
if (*first && (*first)->hh.tbl) {
|
||||
HASH_FIND_UUID(*first, uuid, context);
|
||||
} else {
|
||||
context = *first;
|
||||
while (context) {
|
||||
if (strcmp(context->uuid, uuid) == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
context = context->next;
|
||||
}
|
||||
}
|
||||
|
||||
if (context)
|
||||
addref(context);
|
||||
|
||||
@ -2096,6 +2109,13 @@ obs_output_t *obs_get_output_by_name(const char *name)
|
||||
obs_output_addref_safe_);
|
||||
}
|
||||
|
||||
obs_output_t *obs_get_output_by_uuid(const char *uuid)
|
||||
{
|
||||
return get_context_by_uuid(&obs->data.first_output, uuid,
|
||||
&obs->data.outputs_mutex,
|
||||
obs_output_addref_safe_);
|
||||
}
|
||||
|
||||
obs_encoder_t *obs_get_encoder_by_name(const char *name)
|
||||
{
|
||||
return get_context_by_name(&obs->data.first_encoder, name,
|
||||
@ -2103,6 +2123,13 @@ obs_encoder_t *obs_get_encoder_by_name(const char *name)
|
||||
obs_encoder_addref_safe_);
|
||||
}
|
||||
|
||||
obs_encoder_t *obs_get_encoder_by_uuid(const char *uuid)
|
||||
{
|
||||
return get_context_by_uuid(&obs->data.first_encoder, uuid,
|
||||
&obs->data.encoders_mutex,
|
||||
obs_encoder_addref_safe_);
|
||||
}
|
||||
|
||||
obs_service_t *obs_get_service_by_name(const char *name)
|
||||
{
|
||||
return get_context_by_name(&obs->data.first_service, name,
|
||||
@ -2110,6 +2137,13 @@ obs_service_t *obs_get_service_by_name(const char *name)
|
||||
obs_service_addref_safe_);
|
||||
}
|
||||
|
||||
obs_service_t *obs_get_service_by_uuid(const char *uuid)
|
||||
{
|
||||
return get_context_by_uuid(&obs->data.first_service, uuid,
|
||||
&obs->data.services_mutex,
|
||||
obs_service_addref_safe_);
|
||||
}
|
||||
|
||||
gs_effect_t *obs_get_base_effect(enum obs_base_effect effect)
|
||||
{
|
||||
switch (effect) {
|
||||
@ -2645,8 +2679,7 @@ obs_context_data_init_wrap(struct obs_context_data *context,
|
||||
|
||||
if (uuid && strlen(uuid) == UUID_STR_LENGTH)
|
||||
context->uuid = bstrdup(uuid);
|
||||
/* Only automatically generate UUIDs for sources */
|
||||
else if (type == OBS_OBJ_TYPE_SOURCE)
|
||||
else
|
||||
context->uuid = os_generate_uuid();
|
||||
|
||||
context->name = dup_name(name, private);
|
||||
|
12
libobs/obs.h
12
libobs/obs.h
@ -722,12 +722,21 @@ EXPORT obs_source_t *obs_get_transition_by_uuid(const char *uuid);
|
||||
/** Gets an output by its name. */
|
||||
EXPORT obs_output_t *obs_get_output_by_name(const char *name);
|
||||
|
||||
/** Gets an output by its UUID. */
|
||||
EXPORT obs_output_t *obs_get_output_by_uuid(const char *uuid);
|
||||
|
||||
/** Gets an encoder by its name. */
|
||||
EXPORT obs_encoder_t *obs_get_encoder_by_name(const char *name);
|
||||
|
||||
/** Gets an output by its UUID. */
|
||||
EXPORT obs_encoder_t *obs_get_encoder_by_uuid(const char *uuid);
|
||||
|
||||
/** Gets an service by its name. */
|
||||
EXPORT obs_service_t *obs_get_service_by_name(const char *name);
|
||||
|
||||
/** Gets a service by its UUID. */
|
||||
EXPORT obs_service_t *obs_get_service_by_uuid(const char *uuid);
|
||||
|
||||
enum obs_base_effect {
|
||||
OBS_EFFECT_DEFAULT, /**< RGB/YUV */
|
||||
OBS_EFFECT_DEFAULT_RECT, /**< RGB/YUV (using texture_rect) */
|
||||
@ -2059,6 +2068,7 @@ EXPORT bool obs_weak_output_references_output(obs_weak_output_t *weak,
|
||||
obs_output_t *output);
|
||||
|
||||
EXPORT const char *obs_output_get_name(const obs_output_t *output);
|
||||
EXPORT const char *obs_output_get_uuid(const obs_output_t *output);
|
||||
|
||||
/** Starts the output. */
|
||||
EXPORT bool obs_output_start(obs_output_t *output);
|
||||
@ -2417,6 +2427,7 @@ EXPORT bool obs_weak_encoder_references_encoder(obs_weak_encoder_t *weak,
|
||||
|
||||
EXPORT void obs_encoder_set_name(obs_encoder_t *encoder, const char *name);
|
||||
EXPORT const char *obs_encoder_get_name(const obs_encoder_t *encoder);
|
||||
EXPORT const char *obs_encoder_get_uuid(const obs_encoder_t *encoder);
|
||||
|
||||
/** Returns the codec of an encoder by the id */
|
||||
EXPORT const char *obs_get_encoder_codec(const char *id);
|
||||
@ -2605,6 +2616,7 @@ EXPORT bool obs_weak_service_references_service(obs_weak_service_t *weak,
|
||||
obs_service_t *service);
|
||||
|
||||
EXPORT const char *obs_service_get_name(const obs_service_t *service);
|
||||
EXPORT const char *obs_service_get_uuid(const obs_service_t *service);
|
||||
|
||||
/** Gets the default settings for a service */
|
||||
EXPORT obs_data_t *obs_service_defaults(const char *id);
|
||||
|
Loading…
Reference in New Issue
Block a user