OBS image-source插件
+ -

OBS色源插件

2024-06-05 24 0

OBS色源使用

OBS色源插件提供纯色幕布。
150631809113
其在使用上就是一个纯色的背景色。
150749661471

OBS色源结构体

OBS色源结构体使用color_source表示,其会存于void *const data = source->context.data;

struct color_source {
    struct vec4 color;
    struct vec4 color_srgb;

    uint32_t width;
    uint32_t height;

    obs_source_t *src;
};

色源插件注册结构体

color-source.c提供了三个类别的色源,其区别也只是默认的颜色和大小不一样而已。


struct obs_source_info color_source_info_v1 = {
    .id = "color_source",
    .type = OBS_SOURCE_TYPE_INPUT,
    .output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_CUSTOM_DRAW |OBS_SOURCE_CAP_OBSOLETE,
    .create = color_source_create,
    .destroy = color_source_destroy,
    .update = color_source_update,
    .get_name = color_source_get_name,
    .get_defaults = color_source_defaults_v1,
    .get_width = color_source_getwidth,
    .get_height = color_source_getheight,
    .video_render = color_source_render,
    .get_properties = color_source_properties,
    .icon_type = OBS_ICON_TYPE_COLOR,
};

struct obs_source_info color_source_info_v2 = {
    .id = "color_source",
    .version = 2,
    .type = OBS_SOURCE_TYPE_INPUT,
    .output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_CUSTOM_DRAW |OBS_SOURCE_CAP_OBSOLETE,
    .create = color_source_create,
    .destroy = color_source_destroy,
    .update = color_source_update,
    .get_name = color_source_get_name,
    .get_defaults = color_source_defaults_v2,
    .get_width = color_source_getwidth,
    .get_height = color_source_getheight,
    .video_render = color_source_render,
    .get_properties = color_source_properties,
    .icon_type = OBS_ICON_TYPE_COLOR,
};

struct obs_source_info color_source_info_v3 = {
    .id = "color_source",
    .version = 3,
    .type = OBS_SOURCE_TYPE_INPUT,
    .output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_CUSTOM_DRAW |OBS_SOURCE_SRGB,
    .create = color_source_create,
    .destroy = color_source_destroy,
    .update = color_source_update,
    .get_name = color_source_get_name,
    .get_defaults = color_source_defaults_v3,
    .get_width = color_source_getwidth,
    .get_height = color_source_getheight,
    .video_render = color_source_render,
    .get_properties = color_source_properties,
    .icon_type = OBS_ICON_TYPE_COLOR,
};

OBS色源创建与销毁

static void *color_source_create(obs_data_t *settings, obs_source_t *source)
{
    struct color_source *context = bzalloc(sizeof(struct color_source));
    context->src = source;

    color_source_update(context, settings);

    return context;
}

static void color_source_destroy(void *data)
{
    bfree(data);
}

OBS色源属性

名称属性:

/*
    zh-cn.ini中的属性名称为:
    ColorSource="色源"
*/
static const char *color_source_get_name(void *unused)
{
    UNUSED_PARAMETER(unused);
    return obs_module_text("ColorSource");
}

长宽和颜色的默认及更新:

static void color_source_update(void *data, obs_data_t *settings)
{
    struct color_source *context = data;
    uint32_t color = (uint32_t)obs_data_get_int(settings, "color");
    uint32_t width = (uint32_t)obs_data_get_int(settings, "width");
    uint32_t height = (uint32_t)obs_data_get_int(settings, "height");

    vec4_from_rgba(&context->color, color);
    vec4_from_rgba_srgb(&context->color_srgb, color);
    context->width = width;
    context->height = height;
}

static void color_source_defaults_v1(obs_data_t *settings)
{
    obs_data_set_default_int(settings, "color", 0xFFFFFFFF);
    obs_data_set_default_int(settings, "width", 400);
    obs_data_set_default_int(settings, "height", 400);
}

static void color_source_defaults_v2(obs_data_t *settings)
{
    obs_data_set_default_int(settings, "color", 0xFFFFFFFF);
    obs_data_set_default_int(settings, "width", 1920);
    obs_data_set_default_int(settings, "height", 1080);
}

static void color_source_defaults_v3(obs_data_t *settings)
{
    obs_data_set_default_int(settings, "color", 0xFFD1D1D1);//实际测试用的是这个颜色
    obs_data_set_default_int(settings, "width", 1920);
    obs_data_set_default_int(settings, "height", 1080);
}

色源属性

色源具有3个属性,分别为颜色值,长和宽。

static obs_properties_t *color_source_properties(void *unused)
{
    UNUSED_PARAMETER(unused);
/*
    zh-cn.ini中的属性名称为:
    ColorSource.Color="色彩"
    ColorSource.Width="宽度"
    ColorSource.Height="高度"
*/
    obs_properties_t *props = obs_properties_create();
    obs_properties_add_color_alpha(props, "color",   obs_module_text("ColorSource.Color"));
    obs_properties_add_int(props, "width",  obs_module_text("ColorSource.Width"), 0, 4096,1);
    obs_properties_add_int(props, "height",obs_module_text("ColorSource.Height"), 0, 4096,1);

    return props;
}

画布的长和宽属性的获取:

static uint32_t color_source_getwidth(void *data)
{
    struct color_source *context = data;
    return context->width;
}

static uint32_t color_source_getheight(void *data)
{
    struct color_source *context = data;
    return context->height;
}

0 篇笔记 写笔记

作者信息
我爱内核
Windows驱动开发,网站开发
好好学习,天天向上。
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

您的支持,是我们前进的动力!