libobs: Allow object creation if id not found

Allows objects to be created regardless of whether the actual id exists
or not.  This is a precaution that preserves objects/settings if for
some reason the id was removed for whatever reason (plugin removed, or
hardware encoder that disappeared).  This was already added for sources,
but really needs to be added for other libobs objects as well: outputs,
encoders, services.
This commit is contained in:
jp9000
2015-09-13 11:55:06 -07:00
parent a746c8cdd1
commit af310fb556
4 changed files with 62 additions and 21 deletions

View File

@@ -52,15 +52,21 @@ obs_service_t *obs_service_create(const char *id, const char *name,
return NULL;
}
service->info = *info;
if (!info) {
blog(LOG_ERROR, "Service ID '%s' not found", id);
service->context.data = service->info.create(service->context.settings,
service);
if (!service->context.data) {
obs_service_destroy(service);
return NULL;
service->info.id = bstrdup(id);
service->owns_info_id = true;
} else {
service->info = *info;
}
if (info)
service->context.data = service->info.create(
service->context.settings, service);
if (!service->context.data)
blog(LOG_ERROR, "Failed to create service '%s'!", name);
service->control = bzalloc(sizeof(obs_weak_service_t));
service->control->service = service;
@@ -83,6 +89,8 @@ static void actually_destroy_service(struct obs_service *service)
blog(LOG_INFO, "service '%s' destroyed", service->context.name);
obs_context_data_free(&service->context);
if (service->owns_info_id)
bfree((void*)service->info.id);
bfree(service);
}