Esempio n. 1
0
void XCompcapMain::tick(float seconds)
{
	UNUSED_PARAMETER(seconds);

	PLock lock(&p->lock, true);

	if (!lock.isLocked())
		return;

	XCompcap::processEvents();

	if (XCompcap::windowWasReconfigured(p->win))
		updateSettings(0);

	if (!p->tex || !p->gltex)
		return;

	gs_entercontext(obs_graphics());

	if (p->lockX) {
		XLockDisplay(xdisp);
		XSync(xdisp, 0);
	}

	gs_copy_texture_region(p->tex, 0, 0, p->gltex, p->cur_cut_left,
			p->cur_cut_top, width(), height());

	if (p->lockX)
		XUnlockDisplay(xdisp);

	gs_leavecontext();
}
Esempio n. 2
0
static void image_source_update(void *data, obs_data_t settings)
{
	struct image_source *context = data;
	const char *file = obs_data_getstring(settings, "file");

	gs_entercontext(obs_graphics());

	if (context->tex) {
		texture_destroy(context->tex);
		context->tex = NULL;
	}

	if (file) {
		context->tex = gs_create_texture_from_file(file);
		if (context->tex) {
			context->cx = texture_getwidth(context->tex);
			context->cy = texture_getheight(context->tex);
		} else {
			warn("failed to load texture '%s'", file);
			context->cx = 0;
			context->cy = 0;
		}
	}

	gs_leavecontext();
}
Esempio n. 3
0
static void *random_create(obs_data_t settings, obs_source_t source)
{
	struct random_tex *rt = bzalloc(sizeof(struct random_tex));
	uint32_t *pixels = bmalloc(20*20*4);
	size_t x, y;

	for (y = 0; y < 20; y++) {
		for (x = 0; x < 20; x++) {
			uint32_t pixel = 0xFF000000;
			pixel |= (rand()%256);
			pixel |= (rand()%256) << 8;
			pixel |= (rand()%256) << 16;
			//pixel |= 0xFFFFFFFF;
			pixels[y*20 + x] = pixel;
		}
	}

	gs_entercontext(obs_graphics());

	rt->texture = gs_create_texture(20, 20, GS_RGBA, 1,
			(const void**)&pixels, 0);
	bfree(pixels);

	if (!rt->texture) {
		random_destroy(rt);
		return NULL;
	}

	gs_leavecontext();

	UNUSED_PARAMETER(settings);
	UNUSED_PARAMETER(source);
	return rt;
}
Esempio n. 4
0
effect_t create_opaque_effect(void)
{
	effect_t opaque_effect;
	char *effect_file;
	char *error_string = NULL;

	effect_file = obs_find_plugin_file("win-capture/opaque.effect");
	if (!effect_file) {
		blog(LOG_ERROR, "[create_opaque_effect] Could not find "
		                "opaque effect file");
		return false;
	}

	gs_entercontext(obs_graphics());

	opaque_effect = gs_create_effect_from_file(effect_file, &error_string);

	if (!opaque_effect) {
		if (error_string)
			blog(LOG_ERROR, "[create_opaque_effect] Failed to "
			                "create opaque effect:\n%s",
			                error_string);
		else
			blog(LOG_ERROR, "[create_opaque_effect] Failed to "
			                "create opaque effect");
	}

	bfree(effect_file);
	bfree(error_string);

	gs_leavecontext();

	return opaque_effect;
}
Esempio n. 5
0
static void monitor_capture_tick(void *data, float seconds)
{
	struct monitor_capture *capture = data;

	gs_entercontext(obs_graphics());
	dc_capture_capture(&capture->data, NULL);
	gs_leavecontext();

	UNUSED_PARAMETER(seconds);
}
Esempio n. 6
0
static void image_source_destroy(void *data)
{
	struct image_source *context = data;

	gs_entercontext(obs_graphics());
	texture_destroy(context->tex);
	gs_leavecontext();

	bfree(context);
}
Esempio n. 7
0
void test_destroy(struct test_filter *tf)
{
	if (tf) {
		gs_entercontext(obs_graphics());

		effect_destroy(tf->whatever);
		texrender_destroy(tf->texrender);
		bfree(tf);

		gs_leavecontext();
	}
}
Esempio n. 8
0
static void monitor_capture_destroy(void *data)
{
	struct monitor_capture *capture = data;

	gs_entercontext(obs_graphics());

	dc_capture_free(&capture->data);
	effect_destroy(capture->opaque_effect);

	gs_leavecontext();

	bfree(capture);
}
Esempio n. 9
0
static void filter_destroy(void *data)
{
	struct test_filter *tf = data;

	if (tf) {
		gs_entercontext(obs_graphics());

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

		gs_leavecontext();
	}
}
Esempio n. 10
0
static void random_destroy(void *data)
{
	struct random_tex *rt = data;

	if (rt) {
		gs_entercontext(obs_graphics());

		texture_destroy(rt->texture);
		bfree(rt);

		gs_leavecontext();
	}
}
Esempio n. 11
0
void dc_capture_free(struct dc_capture *capture)
{
	if (capture->hdc) {
		SelectObject(capture->hdc, capture->old_bmp);
		DeleteDC(capture->hdc);
		DeleteObject(capture->bmp);
	}

	gs_entercontext(obs_graphics());

	for (size_t i = 0; i < capture->num_textures; i++)
		texture_destroy(capture->textures[i]);

	gs_leavecontext();

	memset(capture, 0, sizeof(struct dc_capture));
}
Esempio n. 12
0
void *obs_video_thread(void *param)
{
	uint64_t last_time = 0;

	while (video_output_wait(obs->video.video)) {
		uint64_t cur_time = video_gettime(obs->video.video);

		gs_entercontext(obs_graphics());

		tick_sources(cur_time, &last_time);
		render_displays();
		swap_frame(cur_time);

		gs_leavecontext();
	}

	return NULL;
}
Esempio n. 13
0
static inline void render_displays(void)
{
	if (!obs->data.valid)
		return;

	gs_entercontext(obs_graphics());

	/* render extra displays/swaps */
	pthread_mutex_lock(&obs->data.displays_mutex);

	for (size_t i = 0; i < obs->data.displays.num; i++)
		render_display(obs->data.displays.array[i]);

	pthread_mutex_unlock(&obs->data.displays_mutex);

	/* render main display */
	render_display(&obs->video.main_display);

	gs_leavecontext();
}
Esempio n. 14
0
void dc_capture_init(struct dc_capture *capture, int x, int y,
		uint32_t width, uint32_t height, bool cursor,
		bool compatibility)
{
	capture->x              = x;
	capture->y              = y;
	capture->width          = width;
	capture->height         = height;
	capture->capture_cursor = cursor;

	gs_entercontext(obs_graphics());

	if (!gs_gdi_texture_available())
		compatibility = true;

	capture->compatibility = compatibility;
	capture->num_textures  = compatibility ? 1 : 2;

	init_textures(capture);

	gs_leavecontext();

	if (!capture->valid)
		return;

	if (compatibility) {
		BITMAPINFO bi = {0};
		BITMAPINFOHEADER *bih = &bi.bmiHeader;
		bih->biSize     = sizeof(BITMAPINFOHEADER);
		bih->biBitCount = 32;
		bih->biWidth    = width;
		bih->biHeight   = height;
		bih->biPlanes   = 1;

		capture->hdc = CreateCompatibleDC(NULL);
		capture->bmp = CreateDIBSection(capture->hdc, &bi,
				DIB_RGB_COLORS, (void**)&capture->bits,
				NULL, 0);
		capture->old_bmp = SelectObject(capture->hdc, capture->bmp);
	}
}
Esempio n. 15
0
static void *filter_create(obs_data_t settings, obs_source_t source)
{
	struct test_filter *tf = bzalloc(sizeof(struct test_filter));
	char *effect_file;

	gs_entercontext(obs_graphics());

	effect_file = obs_find_plugin_file("test-input/test.effect");

	tf->source = source;
	tf->whatever = gs_create_effect_from_file(effect_file, NULL);
	bfree(effect_file);
	if (!tf->whatever) {
		filter_destroy(tf);
		return NULL;
	}

	gs_leavecontext();

	UNUSED_PARAMETER(settings);
	return tf;
}
Esempio n. 16
0
struct test_filter *test_create(const char *settings, obs_source_t source)
{
	struct test_filter *tf = bmalloc(sizeof(struct test_filter));
	char *effect_file;
	memset(tf, 0, sizeof(struct test_filter));

	gs_entercontext(obs_graphics());

	effect_file = obs_find_plugin_file("test-input/test.effect");

	tf->source = source;
	tf->whatever = gs_create_effect_from_file(effect_file, NULL);
	bfree(effect_file);
	if (!tf->whatever) {
		test_destroy(tf);
		return NULL;
	}

	tf->texrender = texrender_create(GS_RGBA, GS_ZS_NONE);

	gs_leavecontext();

	return tf;
}
Esempio n. 17
0
static inline void output_frame(uint64_t timestamp)
{
	struct obs_core_video *video = &obs->video;
	int cur_texture  = video->cur_texture;
	int prev_texture = cur_texture == 0 ? NUM_TEXTURES-1 : cur_texture-1;
	struct video_data frame;
	bool frame_ready;

	memset(&frame, 0, sizeof(struct video_data));
	frame.timestamp = timestamp;

	gs_entercontext(obs_graphics());

	render_video(video, cur_texture, prev_texture);
	frame_ready = download_frame(video, prev_texture, &frame);

	gs_leavecontext();

	if (frame_ready)
		output_video_data(video, &frame, cur_texture);

	if (++video->cur_texture == NUM_TEXTURES)
		video->cur_texture = 0;
}