mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-07-15 07:44:10 +00:00
libobs: Add obs_source_duplicate function
Allows full duplication of sources (with exception of sources that are marked with the OBS_SOURCE_DO_NOT_DUPLICATE output capability flag)
This commit is contained in:
parent
cd97ce2a17
commit
9661ba8142
|
@ -344,6 +344,68 @@ obs_source_t *obs_source_create_private(const char *id, const char *name,
|
|||
return obs_source_create_internal(id, name, settings, NULL, true);
|
||||
}
|
||||
|
||||
static void duplicate_filters(obs_source_t *dst, obs_source_t *src,
|
||||
bool private)
|
||||
{
|
||||
DARRAY(obs_source_t*) filters;
|
||||
|
||||
da_init(filters);
|
||||
|
||||
pthread_mutex_lock(&src->filter_mutex);
|
||||
for (size_t i = 0; i < src->filters.num; i++)
|
||||
obs_source_addref(src->filters.array[i]);
|
||||
da_copy(filters, src->filters);
|
||||
pthread_mutex_unlock(&src->filter_mutex);
|
||||
|
||||
for (size_t i = filters.num; i > 0; i--) {
|
||||
obs_source_t *src_filter = filters.array[i - 1];
|
||||
obs_source_t *dst_filter = obs_source_duplicate(src_filter,
|
||||
src_filter->context.name, private);
|
||||
|
||||
obs_source_filter_add(dst, dst_filter);
|
||||
obs_source_release(dst_filter);
|
||||
obs_source_release(src_filter);
|
||||
}
|
||||
|
||||
da_free(filters);
|
||||
}
|
||||
|
||||
obs_source_t *obs_source_duplicate(obs_source_t *source,
|
||||
const char *new_name, bool create_private)
|
||||
{
|
||||
obs_source_t *new_source;
|
||||
obs_data_t *settings;
|
||||
|
||||
if (!obs_source_valid(source, "obs_source_duplicate"))
|
||||
return NULL;
|
||||
|
||||
if ((source->info.output_flags & OBS_SOURCE_DO_NOT_DUPLICATE) != 0) {
|
||||
obs_source_addref(source);
|
||||
return source;
|
||||
}
|
||||
|
||||
settings = obs_data_create();
|
||||
obs_data_apply(settings, source->context.settings);
|
||||
|
||||
new_source = create_private ?
|
||||
obs_source_create_private(source->info.id, new_name, settings) :
|
||||
obs_source_create(source->info.id, new_name, settings, NULL);
|
||||
|
||||
new_source->audio_mixers = source->audio_mixers;
|
||||
new_source->sync_offset = source->sync_offset;
|
||||
new_source->user_volume = source->user_volume;
|
||||
new_source->user_muted = source->user_muted;
|
||||
new_source->volume = source->volume;
|
||||
new_source->muted = source->muted;
|
||||
new_source->flags = source->flags;
|
||||
|
||||
if (source->info.type != OBS_SOURCE_TYPE_FILTER)
|
||||
duplicate_filters(new_source, source, create_private);
|
||||
|
||||
obs_data_release(settings);
|
||||
return new_source;
|
||||
}
|
||||
|
||||
void obs_source_frame_init(struct obs_source_frame *frame,
|
||||
enum video_format format, uint32_t width, uint32_t height)
|
||||
{
|
||||
|
|
|
@ -650,6 +650,11 @@ EXPORT obs_source_t *obs_source_create(const char *id, const char *name,
|
|||
|
||||
EXPORT obs_source_t *obs_source_create_private(const char *id,
|
||||
const char *name, obs_data_t *settings);
|
||||
|
||||
/* if source has OBS_SOURCE_DO_NOT_DUPLICATE output flag set, only returns a
|
||||
* reference */
|
||||
EXPORT obs_source_t *obs_source_duplicate(obs_source_t *source,
|
||||
const char *desired_name, bool create_private);
|
||||
/**
|
||||
* Adds/releases a reference to a source. When the last reference is
|
||||
* released, the source is destroyed.
|
||||
|
|
Loading…
Reference in a new issue