示例#1
0
obs_source_t obs_source_create(enum obs_source_type type, const char *id,
                               const char *name, const char *settings)
{
    struct obs_source *source;

    const struct source_info *info = get_source_info(type, id);
    if (!info) {
        blog(LOG_WARNING, "Source '%s' not found", id);
        return NULL;
    }

    source = bmalloc(sizeof(struct obs_source));
    memset(source, 0, sizeof(struct obs_source));

    if (!obs_source_init_handlers(source))
        goto fail;

    source->name = bstrdup(name);
    source->type = type;
    source->data = info->create(settings, source);
    if (!source->data)
        goto fail;

    if (!obs_source_init(source, settings, info))
        goto fail;

    obs_source_dosignal(source, "source-create");
    return source;

fail:
    blog(LOG_ERROR, "obs_source_create failed");
    obs_source_destroy(source);
    return NULL;
}
示例#2
0
obs_source_t obs_source_create(enum obs_source_type type, const char *id,
		const char *name, obs_data_t settings)
{
	struct obs_source *source;

	const struct obs_source_info *info = get_source_info(type, id);
	if (!info) {
		blog(LOG_ERROR, "Source '%s' not found", id);
		return NULL;
	}

	source = bzalloc(sizeof(struct obs_source));

	if (!obs_source_init_context(source, settings, name))
		goto fail;

	if (info->defaults)
		info->defaults(source->context.settings);

	source->context.data = info->create(source->context.settings, source);
	if (!source->context.data)
		goto fail;

	if (!obs_source_init(source, info))
		goto fail;

	obs_source_dosignal(source, "source_create", NULL);
	return source;

fail:
	blog(LOG_ERROR, "obs_source_create failed");
	obs_source_destroy(source);
	return NULL;
}
示例#3
0
obs_scene_t obs_scene_create(const char *name)
{
	struct obs_source *source = bmalloc(sizeof(struct obs_source));
	struct obs_scene  *scene;

	memset(source, 0, sizeof(struct obs_source));
	if (!obs_source_init_handlers(source)) {
		bfree(source);
		return NULL;
	}

	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;
	}

	source->name  = bstrdup(name);
	source->type  = SOURCE_SCENE;

	scene->source = source;
	obs_source_init(source, &scene_info);
	memcpy(&source->callbacks, &scene_info, sizeof(struct source_info));
	return scene;
}
示例#4
0
obs_source_t obs_source_create(enum obs_source_type type, const char *name,
		const char *settings)
{
	const struct source_info *info = NULL;
	struct darray *list = NULL;
	struct obs_source *source;

	switch (type) {
	case SOURCE_INPUT:      list = &obs->input_types.da; break;
	case SOURCE_FILTER:     list = &obs->filter_types.da; break;
	case SOURCE_TRANSITION: list = &obs->transition_types.da; break;
	case SOURCE_SCENE:
	default:
		return NULL;
	}

	info = find_source(list, name);
	if (!info) {
		blog(LOG_WARNING, "Source '%s' not found", name);
		return NULL;
	}

	source = bmalloc(sizeof(struct obs_source));
	memset(source, 0, sizeof(struct obs_source));

	source->data = info->create(settings, source);
	if (!source->data)
		goto fail;

	if (!obs_source_init(source, settings, info))
		goto fail;

	return source;

fail:
	blog(LOG_ERROR, "obs_source_create failed");
	obs_source_destroy(source);
	return NULL;
}