static void color_grade_filter_update(void *data, obs_data_t *settings)
{
	struct lut_filter_data *filter = data;

	const char *path = obs_data_get_string(settings, SETTING_IMAGE_PATH);
	double clut_amount = obs_data_get_double(settings, SETTING_CLUT_AMOUNT);

	bfree(filter->file);
	if (path)
		filter->file = bstrdup(path);

	obs_enter_graphics();
	gs_image_file_free(&filter->image);
	obs_leave_graphics();

	gs_image_file_init(&filter->image, path);

	obs_enter_graphics();

	gs_image_file_init_texture(&filter->image);

	filter->target = filter->image.texture;
	filter->clut_amount = (float)clut_amount;

	char *effect_path = obs_module_file("color_grade_filter.effect");
	gs_effect_destroy(filter->effect);
	filter->effect = gs_effect_create_from_file(effect_path, NULL);
	bfree(effect_path);

	obs_leave_graphics();
}
Example #2
0
static void image_source_tick(void *data, float seconds)
{
    struct image_source *context = data;
    uint64_t frame_time = obs_get_video_frame_time();

    if (obs_source_active(context->source)) {
        if (!context->active) {
            if (context->image.is_animated_gif)
                context->last_time = frame_time;
            context->active = true;
        }

    } else {
        if (context->active) {
            if (context->image.is_animated_gif) {
                context->image.cur_frame = 0;
                context->image.cur_loop = 0;
                context->image.cur_time = 0;

                obs_enter_graphics();
                gs_image_file_update_texture(&context->image);
                obs_leave_graphics();
            }

            context->active = false;
        }

        return;
    }

    if (context->last_time && context->image.is_animated_gif) {
        uint64_t elapsed = frame_time - context->last_time;
        bool updated = gs_image_file_tick(&context->image, elapsed);

        if (updated) {
            obs_enter_graphics();
            gs_image_file_update_texture(&context->image);
            obs_leave_graphics();
        }
    }

    context->last_time = frame_time;

    context->update_time_elapsed += seconds;

    if (context->update_time_elapsed >= 1.0f) {
        time_t t = get_modified_timestamp(context->file);
        context->update_time_elapsed = 0.0f;

        if (context->file_timestamp != t) {
            image_source_load(context);
        }
    }
}
Example #3
0
void OBSProjector::UpdateMultiviewProjectors()
{
	obs_enter_graphics();
	updatingMultiview = true;
	obs_leave_graphics();

	for (auto &projector : multiviewProjectors)
		projector->UpdateMultiview();

	obs_enter_graphics();
	updatingMultiview = false;
	obs_leave_graphics();
}
static void AddExisting(const char *name, bool visible, bool duplicate)
{
	OBSBasic *main = reinterpret_cast<OBSBasic*>(App()->GetMainWindow());
	OBSScene scene = main->GetCurrentScene();
	if (!scene)
		return;

	obs_source_t *source = obs_get_source_by_name(name);
	if (source) {
		if (duplicate) {
			obs_source_t *from = source;
			char *new_name = get_new_source_name(name);
			source = obs_source_duplicate(from, new_name, false);
			bfree(new_name);
			obs_source_release(from);

			if (!source)
				return;
		}

		AddSourceData data;
		data.source = source;
		data.visible = visible;

		obs_enter_graphics();
		obs_scene_atomic_update(scene, AddSource, &data);
		obs_leave_graphics();

		obs_source_release(source);
	}
}
Example #5
0
static void *color_filter_create(obs_data_t *settings, obs_source_t *context)
{
	struct color_filter_data *filter =
		bzalloc(sizeof(struct color_filter_data));
	char *effect_path = obs_module_file("color_filter.effect");

	filter->context = context;

	obs_enter_graphics();

	filter->effect = gs_effect_create_from_file(effect_path, NULL);
	if (filter) {
		filter->color_param = gs_effect_get_param_by_name(
				filter->effect, "color");
		filter->contrast_param = gs_effect_get_param_by_name(
				filter->effect, "contrast");
		filter->brightness_param = gs_effect_get_param_by_name(
				filter->effect, "brightness");
		filter->gamma_param = gs_effect_get_param_by_name(
				filter->effect, "gamma");
	}

	obs_leave_graphics();

	bfree(effect_path);

	if (!filter->effect) {
		color_filter_destroy(filter);
		return NULL;
	}

	color_filter_update(filter, settings);
	return filter;
}
gs_vertbuffer_t *create_uv_vbuffer(uint32_t num_verts, bool add_color) {
	obs_enter_graphics();

	gs_vertbuffer_t *tmp = NULL;
	struct gs_vb_data *vrect = NULL;

	vrect = gs_vbdata_create();
	vrect->num = num_verts;
	vrect->points = (struct vec3 *)bmalloc(sizeof(struct vec3) * num_verts);
	vrect->num_tex = 1;
	vrect->tvarray =
		(struct gs_tvertarray *)bmalloc(sizeof(struct gs_tvertarray));
	vrect->tvarray[0].width = 2;
	vrect->tvarray[0].array = bmalloc(sizeof(struct vec2) * num_verts);
	if (add_color)
		vrect->colors = (uint32_t *)bmalloc
		(sizeof(uint32_t)* num_verts);

	memset(vrect->points, 0, sizeof(struct vec3) * num_verts);
	memset(vrect->tvarray[0].array, 0, sizeof(struct vec2) * num_verts);
	if (add_color)
		memset(vrect->colors, 0, sizeof(uint32_t)* num_verts);

	tmp = gs_vertexbuffer_create(vrect, GS_DYNAMIC);

	if (tmp == NULL) {
		blog(LOG_WARNING, "Couldn't create UV vertex buffer.");
	}

	obs_leave_graphics();
	
	return tmp;
}
Example #7
0
/**
 * Create the capture
 */
static void *xshm_create(obs_data_t settings, obs_source_t source)
{
	UNUSED_PARAMETER(source);

	struct xshm_data *data = bzalloc(sizeof(struct xshm_data));

	data->dpy = XOpenDisplay(NULL);
	if (!data->dpy) {
		blog(LOG_ERROR, "xshm-input: Unable to open X display !");
		goto fail;
	}

	if (!XShmQueryExtension(data->dpy)) {
		blog(LOG_ERROR, "xshm-input: XShm extension not found !");
		goto fail;
	}

	data->use_xinerama = xinerama_is_active(data->dpy) ? true : false;

	obs_enter_graphics();
	data->cursor = xcursor_init(data->dpy);
	obs_leave_graphics();

	xshm_update(data, settings);

	return data;
fail:
	xshm_destroy(data);
	return NULL;
}
Example #8
0
static void image_source_tick(void *data, float seconds)
{
	struct image_source *context = data;
	uint64_t frame_time = obs_get_video_frame_time();

	if (context->last_time && context->image.is_animated_gif) {
		uint64_t elapsed = frame_time - context->last_time;
		bool updated = gs_image_file_tick(&context->image, elapsed);

		if (updated) {
			obs_enter_graphics();
			gs_image_file_update_texture(&context->image);
			obs_leave_graphics();
		}
	}

	context->last_time = frame_time;

	if (!obs_source_showing(context->source)) return;

	context->update_time_elapsed += seconds;

	if (context->update_time_elapsed >= 1.0f) {
		time_t t = get_modified_timestamp(context->file);
		context->update_time_elapsed = 0.0f;

		if (context->file_timestamp < t) {
			image_source_load(context);
		}
	}
}
Example #9
0
/**
 * Stop the capture
 */
static void xshm_capture_stop(struct xshm_data *data)
{
	obs_enter_graphics();

	if (data->texture) {
		gs_texture_destroy(data->texture);
		data->texture = NULL;
	}
	if (data->cursor) {
		xcursor_destroy(data->cursor);
		data->cursor = NULL;
	}

	obs_leave_graphics();

	if (data->xshm) {
		xshm_detach(data->xshm);
		data->xshm = NULL;
	}

	if (data->dpy) {
		XSync(data->dpy, true);
		XCloseDisplay(data->dpy);
		data->dpy = NULL;
	}

	if (data->server) {
		bfree(data->server);
		data->server = NULL;
	}
}
Example #10
0
void *fade_create(obs_data_t *settings, obs_source_t *source)
{
    struct fade_info *fade;
    char *file = obs_module_file("fade_transition.effect");
    gs_effect_t *effect;

    obs_enter_graphics();
    effect = gs_effect_create_from_file(file, NULL);
    obs_leave_graphics();
    bfree(file);

    if (!effect) {
        blog(LOG_ERROR, "Could not find fade_transition.effect");
        return NULL;
    }

    fade = bmalloc(sizeof(*fade));
    fade->source = source;
    fade->effect = effect;
    fade->a_param = gs_effect_get_param_by_name(effect, "tex_a");
    fade->b_param = gs_effect_get_param_by_name(effect, "tex_b");
    fade->fade_param = gs_effect_get_param_by_name(effect, "fade_val");

    UNUSED_PARAMETER(settings);
    return fade;
}
void set_up_vertex_buffer(struct ft2_source *srcdata)
{
	FT_UInt glyph_index = 0;
	uint32_t x = 0, space_pos = 0, word_width = 0;
	size_t len;

	if (!srcdata->text)
		return;

	if (srcdata->custom_width >= 100)
		srcdata->cx = srcdata->custom_width;
	else
		srcdata->cx = get_ft2_text_width(srcdata->text, srcdata);
	srcdata->cy = srcdata->max_h;

	obs_enter_graphics();
	if (srcdata->vbuf != NULL) {
		gs_vertbuffer_t *tmpvbuf = srcdata->vbuf;
		srcdata->vbuf = NULL;
		gs_vertexbuffer_destroy(tmpvbuf);
	}
	srcdata->vbuf = create_uv_vbuffer((uint32_t)wcslen(srcdata->text) * 6,
			true);

	if (srcdata->custom_width <= 100) goto skip_word_wrap;
	if (!srcdata->word_wrap) goto skip_word_wrap;

	len = wcslen(srcdata->text);

	for (uint32_t i = 0; i <= len; i++) {
		if (i == wcslen(srcdata->text)) goto eos_check;

		if (srcdata->text[i] != L' ' && srcdata->text[i] != L'\n')
			goto next_char;

	eos_check:;
		if (x + word_width > srcdata->custom_width) {
			if (space_pos != 0)
				srcdata->text[space_pos] = L'\n';
			x = 0;
		}
		if (i == wcslen(srcdata->text)) goto eos_skip;

		x += word_width;
		word_width = 0;
		if (srcdata->text[i] == L'\n')
			x = 0;
		if (srcdata->text[i] == L' ')
			space_pos = i;
	next_char:;
		glyph_index = FT_Get_Char_Index(srcdata->font_face,
			srcdata->text[i]);
		word_width += src_glyph->xadv;
	eos_skip:;
	}

skip_word_wrap:;
	fill_vertex_buffer(srcdata);
	obs_leave_graphics();
}
Example #12
0
OBSProjector::~OBSProjector()
{
	bool isMultiview = type == ProjectorType::Multiview;
	obs_display_remove_draw_callback(GetDisplay(),
			isMultiview ? OBSRenderMultiview : OBSRender, this);

	if (source)
		obs_source_dec_showing(source);

	if (isMultiview) {
		for (OBSWeakSource &weakSrc : multiviewScenes) {
			OBSSource src = OBSGetStrongRef(weakSrc);
			if (src)
				obs_source_dec_showing(src);
		}

		obs_enter_graphics();
		gs_vertexbuffer_destroy(actionSafeMargin);
		gs_vertexbuffer_destroy(graphicsSafeMargin);
		gs_vertexbuffer_destroy(fourByThreeSafeMargin);
		gs_vertexbuffer_destroy(leftLine);
		gs_vertexbuffer_destroy(topLine);
		gs_vertexbuffer_destroy(rightLine);
		obs_leave_graphics();
	}

	if (type == ProjectorType::Multiview)
		multiviewProjectors.removeAll(this);

	if (isWindow)
		windowedProjectors.removeAll(this);

	App()->DecrementSleepInhibition();
}
Example #13
0
/**
 * Stop the capture
 */
static void xshm_capture_stop(struct xshm_data *data)
{
	obs_enter_graphics();

	if (data->texture) {
		gs_texture_destroy(data->texture);
		data->texture = NULL;
	}
	if (data->cursor) {
		xcb_xcursor_destroy(data->cursor);
		data->cursor = NULL;
	}

	obs_leave_graphics();

	if (data->xshm) {
		xshm_xcb_detach(data->xshm);
		data->xshm = NULL;
	}

	if (data->xcb) {
		xcb_disconnect(data->xcb);
		data->xcb = NULL;
	}

	if (data->server) {
		bfree(data->server);
		data->server = NULL;
	}
}
Example #14
0
static void *sharpness_create(obs_data_t *settings, obs_source_t *context)
{
	struct sharpness_data *filter =
		bzalloc(sizeof(struct sharpness_data));
	char *effect_path = obs_module_file("sharpness.effect");

	filter->context = context;

	obs_enter_graphics();

	filter->effect = gs_effect_create_from_file(effect_path, NULL);
	if (filter) {
		filter->sharpness_param = gs_effect_get_param_by_name(
			filter->effect, "sharpness");
		filter->texture_width = gs_effect_get_param_by_name(
			filter->effect, "texture_width");
		filter->texture_height = gs_effect_get_param_by_name(
			filter->effect, "texture_height");
	}

	obs_leave_graphics();

	bfree(effect_path);

	if (!filter->effect) {
		sharpness_destroy(filter);
		return NULL;
	}

	sharpness_update(filter, settings);
	return filter;
}
Example #15
0
static void *crop_filter_create(obs_data_t *settings, obs_source_t *context)
{
	struct crop_filter_data *filter = bzalloc(sizeof(*filter));
	char *effect_path = obs_module_file("crop_filter.effect");

	filter->context = context;

	obs_enter_graphics();
	filter->effect = gs_effect_create_from_file(effect_path, NULL);
	obs_leave_graphics();

	bfree(effect_path);

	if (!filter->effect) {
		bfree(filter);
		return NULL;
	}

	filter->param_mul = gs_effect_get_param_by_name(filter->effect,
			"mul_val");
	filter->param_add = gs_effect_get_param_by_name(filter->effect,
			"add_val");

	obs_source_update(context, settings);
	return filter;
}
Example #16
0
static void scale_filter_destroy(void *data)
{
	struct scale_filter_data *filter = data;

	obs_enter_graphics();
	gs_samplerstate_destroy(filter->point_sampler);
	obs_leave_graphics();
	bfree(data);
}
Example #17
0
	inline void DestroyTextures()
	{
		if (texture) {
			obs_enter_graphics();
			gs_texture_destroy(texture);
			texture = nullptr;
			obs_leave_graphics();
		}
	}
static void disable_deinterlacing(obs_source_t *source)
{
	obs_enter_graphics();
	gs_texture_destroy(source->async_prev_texture);
	gs_texrender_destroy(source->async_prev_texrender);
	source->deinterlace_mode = OBS_DEINTERLACE_MODE_DISABLE;
	source->async_prev_texture = NULL;
	source->async_prev_texrender = NULL;
	obs_leave_graphics();
}
Example #19
0
static void monitor_capture_tick(void *data, float seconds)
{
	struct monitor_capture *capture = data;

	obs_enter_graphics();
	dc_capture_capture(&capture->data, NULL);
	obs_leave_graphics();

	UNUSED_PARAMETER(seconds);
}
Example #20
0
static void monitor_capture_destroy(void *data)
{
    struct monitor_capture *capture = data;

    obs_enter_graphics();
    dc_capture_free(&capture->data);
    obs_leave_graphics();

    bfree(capture);
}
Example #21
0
static void crop_filter_destroy(void *data)
{
	struct crop_filter_data *filter = data;

	obs_enter_graphics();
	gs_effect_destroy(filter->effect);
	obs_leave_graphics();

	bfree(filter);
}
void BrowserSource::Impl::Listener::DestroySurface(
		BrowserSurfaceHandle surfaceHandle)
{
	if (textureSet.count(surfaceHandle) == 1) {
		obs_enter_graphics();
		textureSet.erase(surfaceHandle);
		gs_texture_destroy(surfaceHandle);
		browserSource->activeTexture = nullptr;
		obs_leave_graphics();
	}
}
Example #23
0
XCompcapMain::XCompcapMain(obs_data_t *settings, obs_source_t *source)
{
	p = new XCompcapMain_private;
	p->source = source;

	obs_enter_graphics();
	p->cursor = xcursor_init(xdisp);
	obs_leave_graphics();

	updateSettings(settings);
}
Example #24
0
/**
 * Resize the texture
 *
 * This will automatically create the texture if it does not exist
 */
static void xshm_resize_texture(struct xshm_data *data)
{
	obs_enter_graphics();

	if (data->texture)
		gs_texture_destroy(data->texture);
	data->texture = gs_texture_create(data->width, data->height,
		GS_BGRA, 1, NULL, GS_DYNAMIC);

	obs_leave_graphics();
}
Example #25
0
static void color_grade_filter_destroy(void *data)
{
	struct lut_filter_data *filter = data;

	obs_enter_graphics();
	gs_effect_destroy(filter->effect);
	gs_image_file_free(&filter->image);
	obs_leave_graphics();

	bfree(filter->file);
	bfree(filter);
}
Example #26
0
static void sharpness_destroy(void *data)
{
	struct sharpness_data *filter = data;

	if (filter->effect) {
		obs_enter_graphics();
		gs_effect_destroy(filter->effect);
		obs_leave_graphics();
	}

	bfree(data);
}
Example #27
0
static void chroma_key_destroy(void *data)
{
	struct chroma_key_filter_data *filter = data;

	if (filter->effect) {
		obs_enter_graphics();
		gs_effect_destroy(filter->effect);
		obs_leave_graphics();
	}

	bfree(data);
}
Example #28
0
static void filter_destroy(void *data)
{
	struct test_filter *tf = data;

	if (tf) {
		obs_enter_graphics();

		gs_effect_destroy(tf->whatever);
		bfree(tf);

		obs_leave_graphics();
	}
}
Example #29
0
static void image_source_load(struct image_source *context)
{
	char *file = context->file;

	obs_enter_graphics();
	gs_image_file_free(&context->image);
	obs_leave_graphics();

	if (file && *file) {
		debug("loading texture '%s'", file);
		context->file_timestamp = get_modified_timestamp(file);
		gs_image_file_init(&context->image, file);
		context->update_time_elapsed = 0;

		obs_enter_graphics();
		gs_image_file_init_texture(&context->image);
		obs_leave_graphics();

		if (!context->image.loaded)
			warn("failed to load texture '%s'", file);
	}
}
Example #30
0
static void monitor_capture_tick(void *data, float seconds)
{
    struct monitor_capture *capture = data;

    if (!obs_source_showing(capture->source))
        return;

    obs_enter_graphics();
    dc_capture_capture(&capture->data, NULL);
    obs_leave_graphics();

    UNUSED_PARAMETER(seconds);
}