1
0
mirror of https://github.com/jojo61/vdr-plugin-softhdcuvid.git synced 2023-10-10 13:37:41 +02:00

Fix default Gamma in Initial Setup

Prepare für opengl placebo (not working yet)
This commit is contained in:
jojo61 2020-05-01 12:06:04 +02:00
parent c1c345dd4d
commit 2fea2ee69f
3 changed files with 126 additions and 55 deletions

View File

@ -40,41 +40,46 @@ struct mp_mat
struct mp_cmat yuv_bt601 = { {{1.164384, 1.164384, 1.164384}, struct mp_cmat yuv_bt601 = { {{1.164384, 1.164384, 1.164384},
{0.00000, -0.391762, 2.017232}, {0.00000, -0.391762, 2.017232},
{1.596027, -0.812968, 0.000000}}, {1.596027, -0.812968, 0.000000}},
{-0.874202, 0.531668, -1.085631} {-0.874202, 0.531668, -1.085631}
}; };
// ITU-R BT.709 (HD) // ITU-R BT.709 (HD)
struct mp_cmat yuv_bt709 = { {{1.164384, 1.164384, 1.164384}, struct mp_cmat yuv_bt709 = { {{1.164384, 1.164384, 1.164384},
{0.00000, -0.213249, 2.112402}, {0.00000, -0.213249, 2.112402},
{1.792741, -0.532909, 0.000000}}, {1.792741, -0.532909, 0.000000}},
{-0.972945, 0.301483, -1.133402} {-0.972945, 0.301483, -1.133402}
}; };
// ITU-R BT.2020 non-constant luminance system // ITU-R BT.2020 non-constant luminance system
struct mp_cmat yuv_bt2020ncl = { {{1.164384, 1.164384, 1.164384}, struct mp_cmat yuv_bt2020ncl = { {{1.164384, 1.164384, 1.164384},
{0.00000, -0.187326, 2.141772}, {0.00000, -0.187326, 2.141772},
{1.678674, -0.650424, 0.000000}}, {1.678674, -0.650424, 0.000000}},
{-0.915688, 0.347459, -1.148145} {-0.915688, 0.347459, -1.148145}
}; };
// ITU-R BT.2020 constant luminance system // ITU-R BT.2020 constant luminance system
struct mp_cmat yuv_bt2020cl = { {{0.0000, 1.164384, 0.000000}, struct mp_cmat yuv_bt2020cl = { {{0.0000, 1.164384, 0.000000},
{0.00000, 0.000000, 1.138393}, {0.00000, 0.000000, 1.138393},
{1.138393, 0.000000, 0.000000}}, {1.138393, 0.000000, 0.000000}},
{-0.571429, -0.073059, -0.571429} {-0.571429, -0.073059, -0.571429}
}; };
float cms_matrix[3][3] = { {1.660497, -0.124547, -0.018154}, float cms_matrix[3][3] = { {1.660497, -0.124547, -0.018154},
{-0.587657, 1.132895, -0.100597}, {-0.587657, 1.132895, -0.100597},
{-0.072840, -0.008348, 1.118751} {-0.072840, -0.008348, 1.118751}
}; };
// Common constants for SMPTE ST.2084 (PQ) // Common constants for SMPTE ST.2084 (PQ)
static const float PQ_M1 = 2610. / 4096 * 1. / 4, PQ_M2 = 2523. / 4096 * 128, PQ_C1 = 3424. / 4096, PQ_C2 = static const float PQ_M1 = 2610. / 4096 * 1. / 4,
2413. / 4096 * 32, PQ_C3 = 2392. / 4096 * 32; PQ_M2 = 2523. / 4096 * 128,
PQ_C1 = 3424. / 4096,
PQ_C2 = 2413. / 4096 * 32,
PQ_C3 = 2392. / 4096 * 32;
// Common constants for ARIB STD-B67 (HLG) // Common constants for ARIB STD-B67 (HLG)
static const float HLG_A = 0.17883277, HLG_B = 0.28466892, HLG_C = 0.55991073; static const float HLG_A = 0.17883277,
HLG_B = 0.28466892,
HLG_C = 0.55991073;
struct gl_vao_entry struct gl_vao_entry
{ {

View File

@ -106,7 +106,7 @@ static int ConfigVideoBrightness; ///< config video brightness
static int ConfigVideoContrast = 100; ///< config video contrast static int ConfigVideoContrast = 100; ///< config video contrast
static int ConfigVideoSaturation = 100; ///< config video saturation static int ConfigVideoSaturation = 100; ///< config video saturation
static int ConfigVideoHue; ///< config video hue static int ConfigVideoHue; ///< config video hue
static int ConfigGamma; ///< config Gamma static int ConfigGamma=100; ///< config Gamma
static int ConfigTargetColorSpace; ///< config Target Colrospace static int ConfigTargetColorSpace; ///< config Target Colrospace
static int ConfigScalerTest; /// Test for Scalers static int ConfigScalerTest; /// Test for Scalers
static int ConfigColorBlindness; static int ConfigColorBlindness;

140
video.c
View File

@ -38,7 +38,7 @@
/// @todo FIXME: use vaErrorStr for all VA-API errors. /// @todo FIXME: use vaErrorStr for all VA-API errors.
/// ///
//#define PLACEBO //#define PLACEBO_GL
#define USE_XLIB_XCB ///< use xlib/xcb backend #define USE_XLIB_XCB ///< use xlib/xcb backend
#define noUSE_SCREENSAVER ///< support disable screensaver #define noUSE_SCREENSAVER ///< support disable screensaver
@ -175,10 +175,12 @@ typedef void *EGLImageKHR;
#endif #endif
#ifdef PLACEBO #ifdef PLACEBO
#ifdef PLACEBO_GL
#include <libplacebo/opengl.h>
#else
#define VK_USE_PLATFORM_XCB_KHR #define VK_USE_PLATFORM_XCB_KHR
#include <vulkan/vulkan.h>
#include <libplacebo/context.h>
#include <libplacebo/vulkan.h> #include <libplacebo/vulkan.h>
#endif
#include <libplacebo/renderer.h> #include <libplacebo/renderer.h>
#endif #endif
@ -488,6 +490,7 @@ static char DPMSDisabled; ///< flag we have disabled dpms
static char EnableDPMSatBlackScreen; ///< flag we should enable dpms at black screen static char EnableDPMSatBlackScreen; ///< flag we should enable dpms at black screen
#endif #endif
static unsigned int Count;
static int EglEnabled; ///< use EGL static int EglEnabled; ///< use EGL
static int GlxVSyncEnabled = 1; ///< enable/disable v-sync static int GlxVSyncEnabled = 1; ///< enable/disable v-sync
@ -779,8 +782,7 @@ static void VideoUpdateOutput(AVRational input_aspect_ratio, int input_width, in
*output_width = (*crop_width * input_aspect_ratio.num) / input_aspect_ratio.den; // normalize pixel aspect ratio *output_width = (*crop_width * input_aspect_ratio.num) / input_aspect_ratio.den; // normalize pixel aspect ratio
*output_x = video_x + (video_width - *output_width) / 2; *output_x = video_x + (video_width - *output_width) / 2;
*output_y = video_y + (video_height - *output_height) / 2; *output_y = video_y + (video_height - *output_height) / 2;
CuvidMessage(2, "video: original aspect output %dx%d%+d%+d\n", *output_width, *output_height, *output_x, CuvidMessage(2, "video: original aspect output %dx%d%+d%+d\n", *output_width, *output_height, *output_x, *output_y);
*output_y);
return; return;
} }
@ -941,7 +943,7 @@ static void EglInit(void)
XVisualInfo *vi = NULL; XVisualInfo *vi = NULL;
#ifdef PLACEBO #if defined PLACEBO && !defined PLACEBO_GL
return; return;
#endif #endif
@ -1399,9 +1401,14 @@ typedef struct priv
// struct pl_render_target r_target; // struct pl_render_target r_target;
// struct pl_render_params r_params; // struct pl_render_params r_params;
// struct pl_tex final_fbo; // struct pl_tex final_fbo;
#ifndef PLACEBO_GL
VkSurfaceKHR pSurface; VkSurfaceKHR pSurface;
#endif
// VkSemaphore sig_in; // VkSemaphore sig_in;
int has_dma_buf; int has_dma_buf;
#ifdef PLACEBO_GL
struct pl_opengl *gl;
#endif
} priv; } priv;
static priv *p; static priv *p;
static struct pl_overlay osdoverlay; static struct pl_overlay osdoverlay;
@ -2091,7 +2098,7 @@ static int CuvidGlxInit( __attribute__((unused))
const char *display_name) const char *display_name)
{ {
#ifndef PLACEBO #if !defined PLACEBO || defined PLACEBO_GL
EglInit(); EglInit();
if (EglEnabled) { if (EglEnabled) {
@ -2940,7 +2947,7 @@ int get_RGB(CuvidDecoder * decoder)
struct pl_render_params render_params = pl_render_default_params; struct pl_render_params render_params = pl_render_default_params;
struct pl_render_target target = { 0 }; struct pl_render_target target = { 0 };
const struct pl_fmt *fmt; const struct pl_fmt *fmt;
VkImage Image;
int offset, x1, y1, x0, y0; int offset, x1, y1, x0, y0;
float faktorx, faktory; float faktorx, faktory;
#endif #endif
@ -3556,7 +3563,7 @@ static void CuvidMixVideo(CuvidDecoder * decoder, __attribute__((unused))
struct pl_tex_vk *vkp; struct pl_tex_vk *vkp;
struct pl_plane *pl; struct pl_plane *pl;
const struct pl_fmt *fmt; const struct pl_fmt *fmt;
VkImage Image;
struct pl_image *img; struct pl_image *img;
bool ok; bool ok;
@ -3873,13 +3880,14 @@ void make_osd_overlay(int x, int y, int width, int height)
/// ///
/// Display a video frame. /// Display a video frame.
/// ///
static void CuvidDisplayFrame(void) static void CuvidDisplayFrame(void)
{ {
static uint64_t first_time = 0, round_time = 0; static uint64_t first_time = 0, round_time = 0;
static uint64_t last_time = 0; static uint64_t last_time = 0;
int i; int i;
static unsigned int Count;
int filled; int filled;
CuvidDecoder *decoder; CuvidDecoder *decoder;
int RTS_flag; int RTS_flag;
@ -3895,7 +3903,6 @@ static void CuvidDisplayFrame(void)
struct pl_render_target target; struct pl_render_target target;
bool ok; bool ok;
VkImage Image;
const struct pl_fmt *fmt; const struct pl_fmt *fmt;
const float black[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; const float black[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
#endif #endif
@ -3917,6 +3924,18 @@ static void CuvidDisplayFrame(void)
#else // PLACEBO #else // PLACEBO
#ifdef PLACEBO_GL
#ifdef CUVID
glXMakeCurrent(XlibDisplay, VideoWindow, glxThreadContext);
glXWaitVideoSyncSGI(2, (Count + 1) % 2, &Count); // wait for previous frame to swap
last_time = GetusTicks();
#else
eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglThreadContext);
EglCheck();
#endif
glClear(GL_COLOR_BUFFER_BIT);
#endif
if (CuvidDecoderN) { if (CuvidDecoderN) {
ldiff = (float)(GetusTicks() - round_time) / 1000000.0; ldiff = (float)(GetusTicks() - round_time) / 1000000.0;
if (ldiff < 100.0 && ldiff > 0.0) if (ldiff < 100.0 && ldiff > 0.0)
@ -4164,6 +4183,23 @@ static void CuvidDisplayFrame(void)
} }
} }
#ifdef PLACEBO_GL
CuvidSwapBuffer() {
#ifdef CUVID
glXGetVideoSyncSGI(&Count); // get current frame
glXSwapBuffers(XlibDisplay, VideoWindow);
glXMakeCurrent(XlibDisplay, None, NULL);
#else
#ifndef USE_DRM
eglSwapBuffers(eglDisplay, eglSurface);
eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
#else
drm_swap_buffers();
#endif
#endif
}
#endif
/// ///
/// Set CUVID decoder video clock. /// Set CUVID decoder video clock.
/// ///
@ -5172,14 +5208,6 @@ void pl_log_intern(void *stream, enum pl_log_level level, const char *msg)
void InitPlacebo() void InitPlacebo()
{ {
struct pl_vulkan_params params;
struct pl_vk_inst_params iparams = pl_vk_inst_default_params;
VkXcbSurfaceCreateInfoKHR xcbinfo;
char xcbext[] = { "VK_KHR_xcb_surface" };
char surfext[] = { "VK_KHR_surface" };
Debug(3, "Init Placebo mit API %d\n", PL_API_VER); Debug(3, "Init Placebo mit API %d\n", PL_API_VER);
p = calloc(1, sizeof(struct priv)); p = calloc(1, sizeof(struct priv));
@ -5188,13 +5216,32 @@ void InitPlacebo()
// Create context // Create context
p->context.log_cb = &pl_log_intern; p->context.log_cb = &pl_log_intern;
p->context.log_level = PL_LOG_WARN; p->context.log_level = PL_LOG_WARN; // WARN
p->ctx = pl_context_create(PL_API_VER, &p->context); p->ctx = pl_context_create(PL_API_VER, &p->context);
if (!p->ctx) { if (!p->ctx) {
Fatal(_("Failed initializing libplacebo\n")); Fatal(_("Failed initializing libplacebo\n"));
} }
#ifdef PLACEBO_GL
struct pl_opengl_params params = pl_opengl_default_params;
p->gl = pl_opengl_create(p->ctx, &params);
p->swapchain = pl_opengl_create_swapchain(p->gl, &(struct pl_opengl_swapchain_params) {
.swap_buffers = (void (*)(void *)) CuvidSwapBuffer,
.priv = NULL,
});
p->gpu = p->gl->gpu;
#else
struct pl_vulkan_params params;
struct pl_vk_inst_params iparams = pl_vk_inst_default_params;
VkXcbSurfaceCreateInfoKHR xcbinfo;
char xcbext[] = { "VK_KHR_xcb_surface" };
char surfext[] = { "VK_KHR_surface" };
// create Vulkan instance // create Vulkan instance
memcpy(&iparams, &pl_vk_inst_default_params, sizeof(iparams)); memcpy(&iparams, &pl_vk_inst_default_params, sizeof(iparams));
// iparams.debug = true; // iparams.debug = true;
@ -5234,15 +5281,6 @@ void InitPlacebo()
p->gpu = p->vk->gpu; p->gpu = p->vk->gpu;
if (!(p->gpu->import_caps.tex & PL_HANDLE_DMA_BUF)) {
p->has_dma_buf = 0;
Debug(3, "No support for dma_buf import in Vulkan\n");
} else {
p->has_dma_buf = 1;
Debug(3, "dma_buf support in Vulkan available\n");
}
#if 1
// Create initial swapchain // Create initial swapchain
p->swapchain = pl_vulkan_create_swapchain(p->vk, &(struct pl_vulkan_swapchain_params) { p->swapchain = pl_vulkan_create_swapchain(p->vk, &(struct pl_vulkan_swapchain_params) {
.surface = p->pSurface, .surface = p->pSurface,
@ -5250,16 +5288,32 @@ void InitPlacebo()
.swapchain_depth = SWAP_BUFFER_SIZE, .swapchain_depth = SWAP_BUFFER_SIZE,
}); });
#endif
if (!p->swapchain) { if (!p->swapchain) {
Fatal(_("Failed creating vulkan swapchain!")); Fatal(_("Failed creating vulkan swapchain!"));
} }
if (!(p->gpu->import_caps.tex & PL_HANDLE_DMA_BUF)) {
p->has_dma_buf = 0;
Debug(3, "No support for dma_buf import \n");
} else {
p->has_dma_buf = 1;
Debug(3, "dma_buf support available\n");
}
#ifdef PLACEBO_GL
if (!pl_swapchain_resize(p->swapchain, &VideoWindowWidth, &VideoWindowHeight)) {
Fatal(_( "libplacebo: failed initializing swapchain\n"));
}
#endif
// create renderer // create renderer
p->renderer = pl_renderer_create(p->ctx, p->gpu); p->renderer = pl_renderer_create(p->ctx, p->gpu);
if (!p->renderer) { if (!p->renderer) {
Fatal(_("Failed initializing libplacebo renderer\n")); Fatal(_("Failed initializing libplacebo renderer\n"));
} }
#endif
Debug(3, "Placebo: init ok"); Debug(3, "Placebo: init ok");
} }
@ -5313,10 +5367,15 @@ void exit_display()
p->renderertest = NULL; p->renderertest = NULL;
} }
pl_swapchain_destroy(&p->swapchain); pl_swapchain_destroy(&p->swapchain);
#ifdef PLACEBO_GL
pl_opengl_destroy(&p->gl);
#else
// pl_vulkan_destroy(&p->vk);
vkDestroySurfaceKHR(p->vk_inst->instance, p->pSurface, NULL); vkDestroySurfaceKHR(p->vk_inst->instance, p->pSurface, NULL);
pl_vk_inst_destroy(&p->vk_inst); pl_vk_inst_destroy(&p->vk_inst);
// pl_vulkan_destroy(&p->vk); #endif
pl_context_destroy(&p->ctx); pl_context_destroy(&p->ctx);
free(p); free(p);
p = NULL; p = NULL;
@ -5352,16 +5411,14 @@ static void *VideoHandlerThread(void *dummy)
Set_Gamma(0.0, 6500); Set_Gamma(0.0, 6500);
#endif #endif
#ifdef PLACEBO
InitPlacebo(); #if (defined CUVID && !defined PLACEBO) || (defined CUVID && defined PLACEBO_GL)
#else
#ifdef CUVID
if (EglEnabled) { if (EglEnabled) {
glxThreadContext = glXCreateContext(XlibDisplay, GlxVisualInfo, glxSharedContext, GL_TRUE); glxThreadContext = glXCreateContext(XlibDisplay, GlxVisualInfo, glxSharedContext, GL_TRUE);
GlxSetupWindow(VideoWindow, VideoWindowWidth, VideoWindowHeight, glxThreadContext); GlxSetupWindow(VideoWindow, VideoWindowWidth, VideoWindowHeight, glxThreadContext);
} }
#endif #endif
#ifdef VAAPI #if (defined VAAPI && !defined PLACEBO) || (defined VAAPI && defined PLACEBO_GL)
eglThreadContext = eglCreateContext(eglDisplay, eglConfig, eglSharedContext, contextAttrs); eglThreadContext = eglCreateContext(eglDisplay, eglConfig, eglSharedContext, contextAttrs);
if (!eglThreadContext) { if (!eglThreadContext) {
EglCheck(); EglCheck();
@ -5370,7 +5427,11 @@ static void *VideoHandlerThread(void *dummy)
} }
eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglThreadContext); eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglThreadContext);
#endif #endif
#ifdef PLACEBO
InitPlacebo();
#endif #endif
pthread_cleanup_push(exit_display, NULL); pthread_cleanup_push(exit_display, NULL);
for (;;) { for (;;) {
@ -6343,6 +6404,11 @@ void VideoSetVideoMode( __attribute__((unused))
VideoWindowHeight = height; VideoWindowHeight = height;
#ifdef PLACEBO #ifdef PLACEBO
VideoSetOsdSize(width, height); VideoSetOsdSize(width, height);
#ifdef PLACEBO_GL
if (!pl_swapchain_resize(p->swapchain, &width, &height)) {
Fatal(_( "libplacebo: failed initializing swapchain\n"));
}
#endif
#endif #endif
VideoUsedModule->SetVideoMode(); VideoUsedModule->SetVideoMode();
VideoThreadUnlock(); VideoThreadUnlock();