Ensure names are valid

Ensure that a source has a valid name.  Duplicates aren't a big deal
internally, but sources without a name are probably something that
should be avoided.  Made is so that if a source is programmatically
created without a name, it's assigned an index based name.

In the main basic-mode window, made it check to make sure the name was
valid as well.
This commit is contained in:
jp9000
2014-03-10 13:39:51 -07:00
parent 35e7a2a9fe
commit 5288467aeb
5 changed files with 37 additions and 4 deletions

View File

@@ -141,6 +141,8 @@ struct obs_core_data {
struct obs_view main_view;
long long unnamed_index;
volatile bool valid;
};

View File

@@ -202,7 +202,7 @@ static const char *obs_scene_signals[] = {
NULL
};
void source_init_name(struct obs_source *source, const char *name);
obs_scene_t obs_scene_create(const char *name)
{
@@ -229,7 +229,7 @@ obs_scene_t obs_scene_create(const char *name)
return NULL;
}
source->name = bstrdup(name);
source_init_name(source, name);
scene->source = source;
obs_source_init(source, &scene_info);

View File

@@ -151,6 +151,18 @@ static inline void obs_source_dosignal(struct obs_source *source,
calldata_free(&data);
}
void source_init_name(struct obs_source *source, const char *name)
{
if (!name || !*name) {
struct dstr unnamed = {0};
dstr_printf(&unnamed, "__unnamed%004lld",
obs->data.unnamed_index++);
source->name = unnamed.array;
} else {
source->name = bstrdup(name);
}
}
obs_source_t obs_source_create(enum obs_source_type type, const char *id,
const char *name, obs_data_t settings)
{
@@ -167,7 +179,8 @@ obs_source_t obs_source_create(enum obs_source_type type, const char *id,
if (!obs_source_init_handlers(source))
goto fail;
source->name = bstrdup(name);
source_init_name(source, name);
source->settings = obs_data_newref(settings);
source->data = info->create(source->settings, source);