Improve safety for settings usage

- Add 'set_default' functions to obs-data.*.  These functions ensure
  that a paramter exists and that the parameter is of a specific type.
  If not, it will create or overwrite the value with the default setting
  instead.

  These functions are meant to be explicitly called before using any of
  the 'get' functions.  The reason why it was designed this way is to
  encourage defaults to be set in a single place/function.

  For example, ideal usage is to create one function for your data,
  "set_my_defaults(obs_data_t data)", set all the default values within
  that function, and then call that function on create/update, that way
  all defaults are centralized to a single place.

- Ensure that data passed to sources/encoders/outputs/etc is always
  valid, and not a null value.

- While I'm remembering, fix a few defaults of the main program config
  file data.
This commit is contained in:
jp9000
2014-01-28 18:41:24 -07:00
parent c6300d0956
commit 9116be8d9c
9 changed files with 127 additions and 64 deletions

View File

@@ -163,11 +163,13 @@ obs_scene_t obs_scene_create(const char *name)
return NULL;
}
scene = scene_create(NULL, source);
source->settings = obs_data_create();
scene = scene_create(source->settings, source);
source->data = scene;
assert(scene);
if (!scene) {
obs_data_release(source->settings);
bfree(source);
return NULL;
}
@@ -176,7 +178,7 @@ obs_scene_t obs_scene_create(const char *name)
source->type = SOURCE_SCENE;
scene->source = source;
obs_source_init(source, NULL, &scene_info);
obs_source_init(source, &scene_info);
memcpy(&source->callbacks, &scene_info, sizeof(struct source_info));
return scene;
}