mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-07-14 23:34:08 +00:00
libobs: Add private settings to scene items/sources
Allows setting and sharing of user data for sources and scene items.
This commit is contained in:
parent
db1da73647
commit
2ef00ecec4
|
@ -680,6 +680,8 @@ struct obs_source {
|
|||
|
||||
struct audio_monitor *monitor;
|
||||
enum obs_monitoring_type monitoring_type;
|
||||
|
||||
obs_data_t *private_settings;
|
||||
};
|
||||
|
||||
extern const struct obs_source_info *get_source_info(const char *id);
|
||||
|
|
|
@ -624,6 +624,12 @@ static void scene_load_item(struct obs_scene *scene, obs_data_t *item_data)
|
|||
obs_data_get_vec2(item_data, "pos", &item->pos);
|
||||
obs_data_get_vec2(item_data, "scale", &item->scale);
|
||||
|
||||
obs_data_release(item->private_settings);
|
||||
item->private_settings =
|
||||
obs_data_get_obj(item_data, "private_settings");
|
||||
if (!item->private_settings)
|
||||
item->private_settings = obs_data_create();
|
||||
|
||||
set_visibility(item, visible);
|
||||
obs_sceneitem_set_locked(item, lock);
|
||||
|
||||
|
@ -730,6 +736,9 @@ static void scene_save_item(obs_data_array_t *array,
|
|||
|
||||
obs_data_set_string(item_data, "scale_filter", scale_filter);
|
||||
|
||||
obs_data_set_obj(item_data, "private_settings",
|
||||
item->private_settings);
|
||||
|
||||
obs_data_array_push_back(array, item_data);
|
||||
obs_data_release(item_data);
|
||||
}
|
||||
|
@ -1366,6 +1375,7 @@ obs_sceneitem_t *obs_scene_add(obs_scene_t *scene, obs_source_t *source)
|
|||
item->actions_mutex = mutex;
|
||||
item->user_visible = true;
|
||||
item->locked = false;
|
||||
item->private_settings = obs_data_create();
|
||||
os_atomic_set_long(&item->active_refs, 1);
|
||||
vec2_set(&item->scale, 1.0f, 1.0f);
|
||||
matrix4_identity(&item->draw_transform);
|
||||
|
@ -1421,6 +1431,7 @@ static void obs_sceneitem_destroy(obs_sceneitem_t *item)
|
|||
gs_texrender_destroy(item->item_render);
|
||||
obs_leave_graphics();
|
||||
}
|
||||
obs_data_release(item->private_settings);
|
||||
obs_hotkey_pair_unregister(item->toggle_visibility);
|
||||
pthread_mutex_destroy(&item->actions_mutex);
|
||||
if (item->source)
|
||||
|
@ -2002,3 +2013,12 @@ int64_t obs_sceneitem_get_id(const obs_sceneitem_t *item)
|
|||
|
||||
return item->id;
|
||||
}
|
||||
|
||||
obs_data_t *obs_sceneitem_get_private_settings(obs_sceneitem_t *item)
|
||||
{
|
||||
if (!obs_ptr_valid(item, "obs_sceneitem_get_private_settings"))
|
||||
return NULL;
|
||||
|
||||
obs_data_addref(item->private_settings);
|
||||
return item->private_settings;
|
||||
}
|
||||
|
|
|
@ -68,6 +68,8 @@ struct obs_scene_item {
|
|||
|
||||
obs_hotkey_pair_id toggle_visibility;
|
||||
|
||||
obs_data_t *private_settings;
|
||||
|
||||
pthread_mutex_t actions_mutex;
|
||||
DARRAY(struct item_action) audio_actions;
|
||||
|
||||
|
|
|
@ -190,6 +190,8 @@ bool obs_source_init(struct obs_source *source)
|
|||
pthread_mutex_unlock(&obs->data.audio_sources_mutex);
|
||||
}
|
||||
|
||||
source->private_settings = obs_data_create();
|
||||
|
||||
obs_context_data_insert(&source->context,
|
||||
&obs->data.sources_mutex,
|
||||
&obs->data.first_source);
|
||||
|
@ -582,6 +584,7 @@ void obs_source_destroy(struct obs_source *source)
|
|||
pthread_mutex_destroy(&source->audio_cb_mutex);
|
||||
pthread_mutex_destroy(&source->audio_mutex);
|
||||
pthread_mutex_destroy(&source->async_mutex);
|
||||
obs_data_release(source->private_settings);
|
||||
obs_context_data_free(&source->context);
|
||||
|
||||
if (source->owns_info_id)
|
||||
|
@ -4050,3 +4053,12 @@ bool obs_source_async_unbuffered(const obs_source_t *source)
|
|||
return obs_source_valid(source, "obs_source_async_unbuffered") ?
|
||||
source->async_unbuffered : false;
|
||||
}
|
||||
|
||||
obs_data_t *obs_source_get_private_settings(obs_source_t *source)
|
||||
{
|
||||
if (!obs_ptr_valid(source, "obs_source_get_private_settings"))
|
||||
return NULL;
|
||||
|
||||
obs_data_addref(source->private_settings);
|
||||
return source->private_settings;
|
||||
}
|
||||
|
|
|
@ -1519,6 +1519,12 @@ static obs_source_t *obs_load_source_type(obs_data_t *source_data)
|
|||
obs_source_set_monitoring_type(source,
|
||||
(enum obs_monitoring_type)monitoring_type);
|
||||
|
||||
obs_data_release(source->private_settings);
|
||||
source->private_settings =
|
||||
obs_data_get_obj(source_data, "private_settings");
|
||||
if (!source->private_settings)
|
||||
source->private_settings = obs_data_create();
|
||||
|
||||
if (filters) {
|
||||
size_t count = obs_data_array_count(filters);
|
||||
|
||||
|
@ -1647,6 +1653,9 @@ obs_data_t *obs_save_source(obs_source_t *source)
|
|||
obs_data_set_int (source_data, "deinterlace_field_order", di_order);
|
||||
obs_data_set_int (source_data, "monitoring_type", m_type);
|
||||
|
||||
obs_data_set_obj(source_data, "private_settings",
|
||||
source->private_settings);
|
||||
|
||||
if (source->info.type == OBS_SOURCE_TYPE_TRANSITION)
|
||||
obs_transition_save(source, source_data);
|
||||
|
||||
|
|
|
@ -957,6 +957,10 @@ EXPORT void obs_source_set_monitoring_type(obs_source_t *source,
|
|||
EXPORT enum obs_monitoring_type obs_source_get_monitoring_type(
|
||||
const obs_source_t *source);
|
||||
|
||||
/** Gets private front-end settings data. This data is saved/loaded
|
||||
* automatically. Returns an incremented reference. */
|
||||
EXPORT obs_data_t *obs_source_get_private_settings(obs_source_t *item);
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Functions used by sources */
|
||||
|
||||
|
@ -1338,6 +1342,10 @@ EXPORT enum obs_scale_type obs_sceneitem_get_scale_filter(
|
|||
EXPORT void obs_sceneitem_defer_update_begin(obs_sceneitem_t *item);
|
||||
EXPORT void obs_sceneitem_defer_update_end(obs_sceneitem_t *item);
|
||||
|
||||
/** Gets private front-end settings data. This data is saved/loaded
|
||||
* automatically. Returns an incremented reference. */
|
||||
EXPORT obs_data_t *obs_sceneitem_get_private_settings(obs_sceneitem_t *item);
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Outputs */
|
||||
|
|
Loading…
Reference in a new issue