1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| struct obs_core *obs = NULL;
/* internal initialization */ bool obs_source_init(struct obs_source *source, const struct obs_source_info *info) { pthread_mutexattr_t attr;
source->user_volume = 1.0f; source->present_volume = 1.0f; source->base_volume = 0.0f; source->sync_offset = 0; pthread_mutex_init_value(&source->filter_mutex); pthread_mutex_init_value(&source->async_mutex); pthread_mutex_init_value(&source->audio_mutex);
if (pthread_mutexattr_init(&attr) != 0) return false; if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) return false; if (pthread_mutex_init(&source->filter_mutex, &attr) != 0) return false; if (pthread_mutex_init(&source->audio_mutex, NULL) != 0) return false; if (pthread_mutex_init(&source->async_mutex, NULL) != 0) return false;
if (info && info->output_flags & OBS_SOURCE_AUDIO) { source->audio_line = audio_output_create_line(obs->audio.audio, source->context.name, 0xF); if (!source->audio_line) { blog(LOG_ERROR, "Failed to create audio line for " "source '%s'", source->context.name); return false; } }
source->control = bzalloc(sizeof(obs_weak_source_t)); source->control->source = source;
obs_context_data_insert(&source->context, &obs->data.sources_mutex, &obs->data.first_source); return true; }
obs_source_t *obs_source_create(enum obs_source_type type, const char *id, const char *name, obs_data_t *settings, obs_data_t *hotkey_data) { struct obs_source *source = bzalloc(sizeof(struct obs_source));
const struct obs_source_info *info = get_source_info(type, id); if (!info) { blog(LOG_ERROR, "Source ID '%s' not found", id);
source->info.id = bstrdup(id); source->info.type = type; source->owns_info_id = true; } else { source->info = *info; }
source->mute_unmute_key = OBS_INVALID_HOTKEY_PAIR_ID; source->push_to_mute_key = OBS_INVALID_HOTKEY_ID; source->push_to_talk_key = OBS_INVALID_HOTKEY_ID;
if (!obs_source_init_context(source, settings, name, hotkey_data)) goto fail;
if (info && info->get_defaults) info->get_defaults(source->context.settings);
if (!obs_source_init(source, info)) goto fail;
obs_source_init_audio_hotkeys(source);
/* allow the source to be created even if creation fails so that the * user's data doesn't become lost */ if (info) source->context.data = info->create(source->context.settings, source); if (!source->context.data) blog(LOG_ERROR, "Failed to create source '%s'!", name);
blog(LOG_INFO, "source '%s' (%s) created", name, id); obs_source_dosignal(source, "source_create", NULL);
source->flags = source->default_flags; source->enabled = true;
if (info && info->type == OBS_SOURCE_TYPE_TRANSITION) os_atomic_inc_long(&obs->data.active_transitions); return source;
fail: blog(LOG_ERROR, "obs_source_create failed"); obs_source_destroy(source); return NULL; }
|