libobs: Allow "private" contexts
The intention of this is to allow sources/outputs/etc to be created without being visible to the UI or save/load functions.
This commit is contained in:
parent
669da7ba36
commit
bccd3b0b0a
@ -55,7 +55,7 @@ static bool init_encoder(struct obs_encoder *encoder, const char *name,
|
||||
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
|
||||
return false;
|
||||
if (!obs_context_data_init(&encoder->context, settings, name,
|
||||
hotkey_data))
|
||||
hotkey_data, false))
|
||||
return false;
|
||||
if (pthread_mutex_init(&encoder->init_mutex, &attr) != 0)
|
||||
return false;
|
||||
|
@ -396,13 +396,16 @@ struct obs_context_data {
|
||||
pthread_mutex_t *mutex;
|
||||
struct obs_context_data *next;
|
||||
struct obs_context_data **prev_next;
|
||||
|
||||
bool private;
|
||||
};
|
||||
|
||||
extern bool obs_context_data_init(
|
||||
struct obs_context_data *context,
|
||||
obs_data_t *settings,
|
||||
const char *name,
|
||||
obs_data_t *hotkey_data);
|
||||
obs_data_t *hotkey_data,
|
||||
bool private);
|
||||
extern void obs_context_data_free(struct obs_context_data *context);
|
||||
|
||||
extern void obs_context_data_insert(struct obs_context_data *context,
|
||||
|
@ -54,7 +54,7 @@ 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))
|
||||
hotkey_data, false))
|
||||
return false;
|
||||
|
||||
signal_handler_add_array(output->context.signals, output_signals);
|
||||
|
@ -47,7 +47,7 @@ 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)) {
|
||||
hotkey_data, false)) {
|
||||
bfree(service);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ bool obs_source_init_context(struct obs_source *source,
|
||||
obs_data_t *settings, const char *name, obs_data_t *hotkey_data)
|
||||
{
|
||||
if (!obs_context_data_init(&source->context, settings, name,
|
||||
hotkey_data))
|
||||
hotkey_data, false))
|
||||
return false;
|
||||
|
||||
return signal_handler_add_array(source->context.signals,
|
||||
|
31
libobs/obs.c
31
libobs/obs.c
@ -1258,9 +1258,11 @@ obs_source_t *obs_get_source_by_name(const char *name)
|
||||
source = data->first_source;
|
||||
|
||||
while (source) {
|
||||
if (strcmp(source->context.name, name) == 0) {
|
||||
obs_source_addref(source);
|
||||
break;
|
||||
if (!source->context.private) {
|
||||
if (strcmp(source->context.name, name) == 0) {
|
||||
obs_source_addref(source);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
source = (struct obs_source*)source->context.next;
|
||||
@ -1280,7 +1282,7 @@ static inline void *get_context_by_name(void *vfirst, const char *name,
|
||||
|
||||
context = *first;
|
||||
while (context) {
|
||||
if (strcmp(context->name, name) == 0) {
|
||||
if (!context->private && strcmp(context->name, name) == 0) {
|
||||
context = addref(context);
|
||||
break;
|
||||
}
|
||||
@ -1615,7 +1617,7 @@ obs_data_array_t *obs_save_sources_filtered(obs_save_source_filter_cb cb,
|
||||
|
||||
while (source) {
|
||||
if ((source->info.type != OBS_SOURCE_TYPE_FILTER) != 0 &&
|
||||
cb(data_, source)) {
|
||||
!source->context.private && cb(data_, source)) {
|
||||
obs_data_t *source_data = obs_save_source(source);
|
||||
|
||||
obs_data_array_push_back(array, source_data);
|
||||
@ -1643,8 +1645,11 @@ obs_data_array_t *obs_save_sources(void)
|
||||
}
|
||||
|
||||
/* ensures that names are never blank */
|
||||
static inline char *dup_name(const char *name)
|
||||
static inline char *dup_name(const char *name, bool private)
|
||||
{
|
||||
if (private && !name)
|
||||
return NULL;
|
||||
|
||||
if (!name || !*name) {
|
||||
struct dstr unnamed = {0};
|
||||
dstr_printf(&unnamed, "__unnamed%04lld",
|
||||
@ -1660,10 +1665,12 @@ static inline bool obs_context_data_init_wrap(
|
||||
struct obs_context_data *context,
|
||||
obs_data_t *settings,
|
||||
const char *name,
|
||||
obs_data_t *hotkey_data)
|
||||
obs_data_t *hotkey_data,
|
||||
bool private)
|
||||
{
|
||||
assert(context);
|
||||
memset(context, 0, sizeof(*context));
|
||||
context->private = private;
|
||||
|
||||
pthread_mutex_init_value(&context->rename_cache_mutex);
|
||||
if (pthread_mutex_init(&context->rename_cache_mutex, NULL) < 0)
|
||||
@ -1677,7 +1684,7 @@ static inline bool obs_context_data_init_wrap(
|
||||
if (!context->procs)
|
||||
return false;
|
||||
|
||||
context->name = dup_name(name);
|
||||
context->name = dup_name(name, private);
|
||||
context->settings = obs_data_newref(settings);
|
||||
context->hotkey_data = obs_data_newref(hotkey_data);
|
||||
return true;
|
||||
@ -1687,9 +1694,11 @@ bool obs_context_data_init(
|
||||
struct obs_context_data *context,
|
||||
obs_data_t *settings,
|
||||
const char *name,
|
||||
obs_data_t *hotkey_data)
|
||||
obs_data_t *hotkey_data,
|
||||
bool private)
|
||||
{
|
||||
if (obs_context_data_init_wrap(context, settings, name, hotkey_data)) {
|
||||
if (obs_context_data_init_wrap(context, settings, name, hotkey_data,
|
||||
private)) {
|
||||
return true;
|
||||
} else {
|
||||
obs_context_data_free(context);
|
||||
@ -1755,7 +1764,7 @@ void obs_context_data_setname(struct obs_context_data *context,
|
||||
|
||||
if (context->name)
|
||||
da_push_back(context->rename_cache, &context->name);
|
||||
context->name = dup_name(name);
|
||||
context->name = dup_name(name, context->private);
|
||||
|
||||
pthread_mutex_unlock(&context->rename_cache_mutex);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user