For *_update, apply settings instead of replacing

Make it so obs_data settings input in to *_update are applied to the
existing settings rather than fully replace the existing settings.  That
way you can update with only certain specific settings, leaving other
settings untouched.  Of course if you're already using the original
settings pointer in the first place then you've already done that, so
it'll just ignore it because you've already applied them.
This commit is contained in:
jp9000 2014-02-21 21:05:21 -07:00
parent 4f4652040c
commit 7fcec77351
6 changed files with 30 additions and 16 deletions

View File

@ -689,7 +689,7 @@ static inline void mul_vol_u8bit(void *array, float volume, size_t total_num)
int32_t vol = (int32_t)(volume * 127.0f);
for (size_t i = 0; i < total_num; i++) {
int32_t val = (int32_t)(vals[i] ^ 0x80) << 8;
int32_t val = (int32_t)vals[i] - 128;
int32_t output = val * vol / 127;
vals[i] = (uint8_t)(CLAMP(output, MIN_S8, MAX_S8) + 128);
}

View File

@ -274,6 +274,7 @@ void obs_data_release(obs_data_t data)
const char *obs_data_getjson(obs_data_t data)
{
/* TODO */
#pragma message ("TODO: implement obs_data_getjson")
return data->json;
}
@ -340,6 +341,29 @@ static inline void set_item_def(struct obs_data *data, const char *name,
set_item_data(data, item, name, ptr, size, type);
}
static inline void copy_item(struct obs_data *data, struct obs_data_item *item)
{
const char *name = get_item_name(item);
void *ptr = get_item_data(item);
set_item(data, name, ptr, item->data_len, item->type);
}
void obs_data_apply(obs_data_t target, obs_data_t apply_data)
{
struct obs_data_item *item;
if (!target || !apply_data || target == apply_data)
return;
item = apply_data->first_item;
while (item) {
copy_item(target, item);
item = item->next;
}
}
void obs_data_erase(obs_data_t data, const char *name)
{
struct obs_data_item *item = get_item(data, name);

View File

@ -56,6 +56,8 @@ EXPORT void obs_data_release(obs_data_t data);
EXPORT const char *obs_data_getjson(obs_data_t data);
EXPORT void obs_data_apply(obs_data_t target, obs_data_t apply_data);
EXPORT void obs_data_erase(obs_data_t data, const char *name);
/* Set functions */
@ -150,18 +152,6 @@ static inline obs_data_t obs_data_newref(obs_data_t data)
return data;
}
static inline void obs_data_replace(obs_data_t *current, obs_data_t replacement)
{
if (!current)
return;
if (*current != replacement) {
replacement = obs_data_newref(replacement);
obs_data_release(*current);
*current = replacement;
}
}
#ifdef __cplusplus
}
#endif

View File

@ -100,7 +100,7 @@ void obs_encoder_update(obs_encoder_t encoder, obs_data_t settings)
{
if (!encoder) return;
obs_data_replace(&encoder->settings, settings);
obs_data_apply(encoder->settings, settings);
encoder->info.update(encoder->data, encoder->settings);
}

View File

@ -102,7 +102,7 @@ obs_properties_t obs_output_properties(const char *id, const char *locale)
void obs_output_update(obs_output_t output, obs_data_t settings)
{
obs_data_replace(&output->settings, settings);
obs_data_apply(output->settings, settings);
if (output->info.update)
output->info.update(output->data, output->settings);

View File

@ -292,7 +292,7 @@ uint32_t obs_source_get_output_flags(obs_source_t source)
void obs_source_update(obs_source_t source, obs_data_t settings)
{
obs_data_replace(&source->settings, settings);
obs_data_apply(source->settings, settings);
if (source->info.update)
source->info.update(source->data, source->settings);