OBS图形及渲染
+ -

GPU格式转换obs_init_gpu_conversion

2024-10-16 9 0

obs_init_gpu_conversion用于对指定输出的格式指定其GPU着色器TECH,并创建其对应的texture

tech

static inline void calc_gpu_conversion_sizes(const struct obs_video_info *ovi)
{
    struct obs_core_video *video = &obs->video;

    video->conversion_needed = false;
    video->conversion_techs[0] = NULL;
    video->conversion_techs[1] = NULL;
    video->conversion_techs[2] = NULL;
    video->conversion_width_i = 0.f;

    switch ((uint32_t)ovi->output_format) {
    case VIDEO_FORMAT_I420:
        video->conversion_needed = true;
        video->conversion_techs[0] = "Planar_Y";
        video->conversion_techs[1] = "Planar_U_Left";
        video->conversion_techs[2] = "Planar_V_Left";
        video->conversion_width_i = 1.f / (float)ovi->output_width;
        break;
    case VIDEO_FORMAT_NV12:
        video->conversion_needed = true;
        video->conversion_techs[0] = "NV12_Y";
        video->conversion_techs[1] = "NV12_UV";
        video->conversion_width_i = 1.f / (float)ovi->output_width;
        break;
    case VIDEO_FORMAT_I444:
        video->conversion_needed = true;
        video->conversion_techs[0] = "Planar_Y";
        video->conversion_techs[1] = "Planar_U";
        video->conversion_techs[2] = "Planar_V";
        break;
    }
}
static bool obs_init_gpu_conversion(struct obs_video_info *ovi)
{
    struct obs_core_video *video = &obs->video;

    calc_gpu_conversion_sizes(ovi);
    video->using_nv12_tex = ovi->output_format == VIDEO_FORMAT_NV12    ? gs_nv12_available(): false;

    if (!video->conversion_needed) {
        blog(LOG_INFO, "GPU conversion not available for format: %u",(unsigned int)ovi->output_format);
        video->gpu_conversion = false;
        video->using_nv12_tex = false;
        blog(LOG_INFO, "NV12 texture support not available");
        return true;
    }

    if (video->using_nv12_tex) {
        gs_texture_create_nv12(&video->convert_textures[0],&video->convert_textures[1],ovi->output_width, ovi->output_height,GS_RENDER_TARGET | GS_SHARED_KM_TEX);
    } 
    else{
        video->convert_textures[0] =gs_texture_create(ovi->output_width, ovi->output_height, GS_R8, 1, NULL, GS_RENDER_TARGET);

        //video_output_open中创建的video_output_info
        const struct video_output_info *info = video_output_get_info(video->video);
        switch (info->format) {
        case VIDEO_FORMAT_I420:
            video->convert_textures[1] = gs_texture_create(ovi->output_width/2, ovi->output_height/2,GS_R8, 1, NULL, GS_RENDER_TARGET);
            video->convert_textures[2] = gs_texture_create(ovi->output_width/2, ovi->output_height/2,GS_R8, 1, NULL, GS_RENDER_TARGET);
            if (!video->convert_textures[2])
                return false;
            break;
        case VIDEO_FORMAT_NV12:
            video->convert_textures[1] = gs_texture_create(ovi->output_width/2, ovi->output_height/2,GS_R8G8, 1, NULL, GS_RENDER_TARGET);
            break;
        case VIDEO_FORMAT_I444:
            video->convert_textures[1] = gs_texture_create(ovi->output_width, ovi->output_height, GS_R8, 1,    NULL, GS_RENDER_TARGET);
            video->convert_textures[2] = gs_texture_create(ovi->output_width, ovi->output_height, GS_R8, 1,    NULL, GS_RENDER_TARGET);
            if (!video->convert_textures[2])
                return false;
            break;
        default:
            break;
        }
    }


    if (!video->convert_textures[0])
        return false;
    if (!video->convert_textures[1])
        return false;

    return true;
}

0 篇笔记 写笔记

GPU格式转换obs_init_gpu_conversion
obs_init_gpu_conversion用于对指定输出的格式指定其GPU着色器TECH,并创建其对应的texturetechstatic inline void calc_gpu_conversion_sizes(const struct obs_video_info *ovi){ ......
作者信息
我爱内核
Windows驱动开发,网站开发
好好学习,天天向上。
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

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

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