obs-studio/plugins/win-capture/monitor-capture.c

173 lines
4.1 KiB
C
Raw Normal View History

#include <util/dstr.h>
#include "dc-capture.h"
struct monitor_capture {
obs_source_t source;
int monitor;
bool capture_cursor;
bool compatibility;
struct dc_capture data;
effect_t opaque_effect;
};
struct monitor_info {
int cur_id;
int desired_id;
int id;
RECT rect;
};
/* ------------------------------------------------------------------------- */
static inline void do_log(int level, const char *msg, ...)
{
va_list args;
struct dstr str = {0};
va_start(args, msg);
dstr_copy(&str, "[GDI monitor capture]: ");
dstr_vcatf(&str, msg, args);
blog(level, "%s", str.array);
dstr_free(&str);
va_end(args);
}
static BOOL CALLBACK enum_monitor(HMONITOR handle, HDC hdc, LPRECT rect,
LPARAM param)
{
struct monitor_info *monitor = (struct monitor_info *)param;
if (monitor->cur_id == 0 || monitor->desired_id == monitor->cur_id) {
monitor->rect = *rect;
monitor->id = monitor->cur_id;
}
UNUSED_PARAMETER(hdc);
UNUSED_PARAMETER(handle);
return (monitor->desired_id < monitor->cur_id++);
}
static void update_monitor(struct monitor_capture *capture,
obs_data_t settings)
{
struct monitor_info monitor = {0};
uint32_t width, height;
monitor.desired_id = (int)obs_data_getint(settings, "monitor");
EnumDisplayMonitors(NULL, NULL, enum_monitor, (LPARAM)&monitor);
capture->monitor = monitor.id;
width = monitor.rect.right - monitor.rect.left;
height = monitor.rect.bottom - monitor.rect.top;
dc_capture_init(&capture->data, monitor.rect.left, monitor.rect.top,
width, height, capture->capture_cursor,
capture->compatibility);
}
static inline void update_settings(struct monitor_capture *capture,
obs_data_t settings)
{
capture->capture_cursor = obs_data_getbool(settings, "capture_cursor");
capture->compatibility = obs_data_getbool(settings, "compatibility");
dc_capture_free(&capture->data);
update_monitor(capture, settings);
}
/* ------------------------------------------------------------------------- */
static const char *monitor_capture_getname(void)
{
2014-07-09 22:12:57 -07:00
return obs_module_text("MonitorCapture");
}
static void monitor_capture_destroy(void *data)
{
struct monitor_capture *capture = data;
obs_enter_graphics();
dc_capture_free(&capture->data);
effect_destroy(capture->opaque_effect);
obs_leave_graphics();
bfree(capture);
}
static void monitor_capture_defaults(obs_data_t settings)
{
obs_data_set_default_int(settings, "monitor", 0);
obs_data_set_default_bool(settings, "capture_cursor", true);
obs_data_set_default_bool(settings, "compatibility", false);
}
static void *monitor_capture_create(obs_data_t settings, obs_source_t source)
{
struct monitor_capture *capture;
effect_t opaque_effect = create_opaque_effect();
if (!opaque_effect)
return NULL;
capture = bzalloc(sizeof(struct monitor_capture));
capture->opaque_effect = opaque_effect;
update_settings(capture, settings);
UNUSED_PARAMETER(source);
return capture;
}
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);
}
static void monitor_capture_render(void *data, effect_t effect)
{
struct monitor_capture *capture = data;
dc_capture_render(&capture->data, capture->opaque_effect);
UNUSED_PARAMETER(effect);
}
Add source properties window (very preliminary) - Add a properties window for sources so that you can now actually edit the settings for sources. Also, display the source by itself in the window (Note: not working on mac, and possibly not working on linux). When changing the settings for a source, it will call obs_source_update on that source when you have modified any values automatically. - Add a properties 'widget', eventually I want to turn this in to a regular nice properties view like you'd see in the designer, but right now it just uses a form layout in a QScrollArea with regular controls to display the properties. It's clunky but works for the time being. - Make it so that swap chains and the main graphics subsystem will automatically use at least one backbuffer if none was specified - Fix bug where displays weren't added to the main display array - Make it so that you can get the properties of a source via the actual pointer of a source/encoder/output in addition to being able to look up properties via identifier. - When registering source types, check for required functions (wasn't doing it before). getheight/getwidth should not be optional if it's a video source as well. - Add an RAII OBSObj wrapper to obs.hpp for non-reference-counted libobs pointers - Add an RAII OBSSignal wrapper to obs.hpp for libobs signals to automatically disconnect them on destruction - Move the "scale and center" calculation in window-basic-main.cpp to its own function and in its own source file - Add an 'update' callback to WASAPI audio sources
2014-03-23 01:07:54 -07:00
static uint32_t monitor_capture_width(void *data)
{
struct monitor_capture *capture = data;
return capture->data.width;
}
static uint32_t monitor_capture_height(void *data)
{
struct monitor_capture *capture = data;
return capture->data.height;
}
struct obs_source_info monitor_capture_info = {
.id = "monitor_capture",
.type = OBS_SOURCE_TYPE_INPUT,
.output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_CUSTOM_DRAW,
.get_name = monitor_capture_getname,
.create = monitor_capture_create,
.destroy = monitor_capture_destroy,
.get_width = monitor_capture_width,
.get_height = monitor_capture_height,
.defaults = monitor_capture_defaults,
.video_render = monitor_capture_render,
.video_tick = monitor_capture_tick
};