libobs: Use NV12 textures when available

This commit is contained in:
jp9000
2018-10-05 20:18:15 -07:00
parent 82848d513e
commit 28d0cc8b97
5 changed files with 170 additions and 13 deletions

View File

@@ -164,17 +164,42 @@ static bool obs_init_gpu_conversion(struct obs_video_info *ovi)
calc_gpu_conversion_sizes(ovi);
video->using_nv12_tex = ovi->output_format == VIDEO_FORMAT_NV12
? gs_nv12_available() : false;
if (!video->conversion_height) {
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)
blog(LOG_INFO, "NV12 texture support enabled");
else
blog(LOG_INFO, "NV12 texture support not available");
for (size_t i = 0; i < NUM_TEXTURES; i++) {
video->convert_textures[i] = gs_texture_create(
ovi->output_width, video->conversion_height,
GS_RGBA, 1, NULL, GS_RENDER_TARGET);
#ifdef _WIN32
if (video->using_nv12_tex) {
gs_texture_create_nv12(
&video->convert_textures[i],
&video->convert_uv_textures[i],
ovi->output_width, ovi->output_height,
GS_RENDER_TARGET | GS_SHARED_KM_TEX);
if (!video->convert_uv_textures[i])
return false;
} else {
#endif
video->convert_textures[i] = gs_texture_create(
ovi->output_width,
video->conversion_height,
GS_RGBA, 1, NULL, GS_RENDER_TARGET);
#ifdef _WIN32
}
#endif
if (!video->convert_textures[i])
return false;
@@ -191,11 +216,23 @@ static bool obs_init_textures(struct obs_video_info *ovi)
size_t i;
for (i = 0; i < NUM_TEXTURES; i++) {
video->copy_surfaces[i] = gs_stagesurface_create(
ovi->output_width, output_height, GS_RGBA);
#ifdef _WIN32
if (video->using_nv12_tex) {
video->copy_surfaces[i] = gs_stagesurface_create_nv12(
ovi->output_width, ovi->output_height);
if (!video->copy_surfaces[i])
return false;
if (!video->copy_surfaces[i])
return false;
} else {
#endif
video->copy_surfaces[i] = gs_stagesurface_create(
ovi->output_width, output_height,
GS_RGBA);
if (!video->copy_surfaces[i])
return false;
#ifdef _WIN32
}
#endif
video->render_textures[i] = gs_texture_create(
ovi->base_width, ovi->base_height,
@@ -431,12 +468,14 @@ static void obs_free_video(void)
gs_stagesurface_destroy(video->copy_surfaces[i]);
gs_texture_destroy(video->render_textures[i]);
gs_texture_destroy(video->convert_textures[i]);
gs_texture_destroy(video->convert_uv_textures[i]);
gs_texture_destroy(video->output_textures[i]);
video->copy_surfaces[i] = NULL;
video->render_textures[i] = NULL;
video->convert_textures[i] = NULL;
video->output_textures[i] = NULL;
video->copy_surfaces[i] = NULL;
video->render_textures[i] = NULL;
video->convert_textures[i] = NULL;
video->convert_uv_textures[i] = NULL;
video->output_textures[i] = NULL;
}
gs_leave_context();
@@ -2267,3 +2306,12 @@ bool obs_video_active(void)
return os_atomic_load_long(&video->raw_active) > 0;
}
bool obs_nv12_tex_active(void)
{
struct obs_core_video *video = &obs->video;
if (!obs)
return false;
return video->using_nv12_tex;
}