Changed OSD Interface without Placebo

This commit is contained in:
jojo61 2019-11-05 22:06:54 +01:00
parent 499731fc1f
commit 6acd2feb3f
3 changed files with 79 additions and 107 deletions

View File

@ -243,14 +243,14 @@ LIBS += -L/usr/lib64
LIBS += -L/usr/local/cuda/lib64
ifeq ($(LIBPLACEBO),1)
LIBS += -lplacebo -lglut
LIBS += -lplacebo
endif
ifeq ($(CUVID),1)
LIBS += -lcuda -L/usr/local/cuda/targets/x86_64-linux/lib -lcudart -lnvcuvid
endif
LIBS += -lGLEW -lGLU -ldl
LIBS += -lGLEW -lGLU -ldl -lglut
### Includes and Defines (add further entries here):
INCLUDES +=

View File

@ -14,9 +14,7 @@ void ConvertColor(const GLint &colARGB, glm::vec4 &col) {
col.b = ((colARGB & 0x000000FF) ) / 255.0;
}
extern "C" void OSD_get_context();
extern "C" void OSD_get_shared_context();
extern "C" void OSD_release_context();
/****************************************************************************************
* cShader
@ -374,10 +372,7 @@ void cOglGlyph::BindTexture(void) {
void cOglGlyph::LoadTexture(FT_BitmapGlyph ftGlyph) {
// Disable byte-alignment restriction
#if defined (VAAPI) && !defined (PLACEBO)
OSD_release_context();
OSD_get_shared_context();
#endif
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
@ -399,10 +394,7 @@ void cOglGlyph::LoadTexture(FT_BitmapGlyph ftGlyph) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
#if defined (VAAPI) && !defined (PLACEBO)
OSD_release_context();
OSD_get_context();
#endif
}
@ -568,10 +560,7 @@ cOglFb::~cOglFb(void) {
bool cOglFb::Init(void) {
initiated = true;
#if defined (VAAPI) && !defined (PLACEBO)
OSD_release_context();
OSD_get_shared_context();
#endif
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
@ -587,16 +576,10 @@ bool cOglFb::Init(void) {
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
esyslog("[softhddev]ERROR: %d Framebuffer is not complete!\n",__LINE__);
#if defined (VAAPI) && !defined (PLACEBO)
OSD_release_context();
OSD_get_context();
#endif
return false;
}
#if defined (VAAPI) && !defined (PLACEBO)
OSD_release_context();
OSD_get_context();
#endif
return true;
}
@ -905,32 +888,26 @@ cOglCmdCopyBufferToOutputFb::cOglCmdCopyBufferToOutputFb(cOglFb *fb, cOglOutputF
this->y = y;
}
#ifdef PLACEBO
//extern "C" {
extern unsigned char *posd;
//}
#endif
bool cOglCmdCopyBufferToOutputFb::Execute(void) {
int i;
pthread_mutex_lock(&OSDMutex);
fb->BindRead();
oFb->BindWrite();
glClear(GL_COLOR_BUFFER_BIT);
// glClear(GL_COLOR_BUFFER_BIT);
#ifdef PLACEBO
//#ifdef PLACEBO
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
if (posd)
glReadPixels(0, 0 ,fb->Width(), fb->Height(),GL_BGRA,GL_UNSIGNED_BYTE,posd);
#else
glReadPixels(0, 0 ,fb->Width(), fb->Height(),GL_RGBA,GL_UNSIGNED_BYTE,posd);
//#else
#if 0
fb->Blit(x, y + fb->Height(), x + fb->Width(), y);
glFlush();
#endif
ActivateOsd(oFb->texture,x, y, fb->Width() ,fb->Height());
oFb->Unbind();
pthread_mutex_unlock(&OSDMutex);
@ -1355,10 +1332,7 @@ cOglCmdDrawImage::~cOglCmdDrawImage(void) {
bool cOglCmdDrawImage::Execute(void) {
GLuint texture;
#if defined (VAAPI) && !defined (PLACEBO)
OSD_release_context();
OSD_get_shared_context();
#endif
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(
@ -1377,10 +1351,7 @@ bool cOglCmdDrawImage::Execute(void) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
#if defined (VAAPI) && !defined (PLACEBO)
OSD_release_context();
OSD_get_context();
#endif
GLfloat x1 = x; //left
GLfloat y1 = y; //top
@ -1470,10 +1441,7 @@ cOglCmdStoreImage::~cOglCmdStoreImage(void) {
}
bool cOglCmdStoreImage::Execute(void) {
#if defined (VAAPI) && !defined (PLACEBO)
OSD_release_context();
OSD_get_shared_context();
#endif
glGenTextures(1, &imageRef->texture);
glBindTexture(GL_TEXTURE_2D, imageRef->texture);
glTexImage2D(
@ -1492,10 +1460,7 @@ bool cOglCmdStoreImage::Execute(void) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
#if defined (VAAPI) && !defined (PLACEBO)
OSD_release_context();
OSD_get_context();
#endif
return true;
}
@ -1567,6 +1532,7 @@ void cOglThread::DoCmd(cOglCmd* cmd) {
}
int cOglThread::StoreImage(const cImage &image) {
if (image.Width() > maxTextureSize || image.Height() > maxTextureSize) {
esyslog("[softhddev] cannot store image of %dpx x %dpx "
"(maximum size is %dpx x %dpx) - falling back to "
@ -1734,8 +1700,6 @@ extern "C" int GlxInitopengl();
bool cOglThread::InitOpenGL(void) {
#ifdef PLACEBO
const char *displayName = X11DisplayName;
if (!displayName) {
displayName = getenv("DISPLAY");
@ -1768,11 +1732,7 @@ bool cOglThread::InitOpenGL(void) {
esyslog("[softhddev]glewInit failed, aborting\n");
return false;
}
#else
if (!GlxInitopengl())
return false;
#endif
VertexBuffers[vbText]->EnableBlending();
glDisable(GL_DEPTH_TEST);
return true;
@ -1834,9 +1794,8 @@ void cOglThread::Cleanup(void) {
DeleteShaders();
// glVDPAUFiniNV();
cOglFont::Cleanup();
#ifdef PLACEBO
glutExit();
#endif
pthread_mutex_unlock(&OSDMutex);
}
@ -2084,34 +2043,29 @@ cOglOsd::cOglOsd(int Left, int Top, uint Level, std::shared_ptr<cOglThread> oglT
// osdHeight = 1080;
dsyslog("[softhddev]cOglOsd osdLeft %d osdTop %d screenWidth %d screenHeight %d", Left, Top, osdWidth, osdHeight);
#ifdef PLACEBO
if (posd)
free(posd);
posd = MALLOC(unsigned char, osdWidth * osdHeight * 4);
#endif
// create output framebuffer
#if defined (VAAPI) && !defined (PLACEBO)
OSD_release_context();
OSD_get_shared_context();
#endif
if (!oFb) {
oFb = new cOglOutputFb(osdWidth, osdHeight);
oglThread->DoCmd(new cOglCmdInitOutputFb(oFb));
}
#if defined (VAAPI) && !defined (PLACEBO)
OSD_release_context();
#endif
pthread_mutex_unlock(&OSDMutex);
}
cOglOsd::~cOglOsd() {
OsdClose();
SetActive(false);
#ifdef PLACEBO
if (posd)
free(posd);
posd = 0;
#endif
oglThread->DoCmd(new cOglCmdDeleteFb(bFb));
}

90
video.c
View File

@ -848,13 +848,13 @@ char *eglErrorString(EGLint error)
void OSD_get_shared_context()
{
eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, eglSharedContext);
// EglCheck();
EglCheck();
}
void OSD_get_context()
{
eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, OSDcontext);
// EglCheck();
EglCheck();
}
void OSD_release_context()
@ -2811,7 +2811,6 @@ int get_RGB(CuvidDecoder * decoder)
#ifndef PLACEBO
// eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, eglSharedContext);
glGenTextures(1, &texture);
GlxCheck();
glBindTexture(GL_TEXTURE_2D, texture);
@ -2856,12 +2855,27 @@ int get_RGB(CuvidDecoder * decoder)
glActiveTexture(GL_TEXTURE0);
if (OsdShown && decoder->grab == 2) {
int x,y,h,w;
GLint texLoc;
if (OsdShown == 1) {
if (OSDtexture)
glDeleteTextures(1,&OSDtexture);
#ifdef CUVID
// glXMakeCurrent(XlibDisplay, VideoWindow, glxSharedContext);
GlxCheck();
#endif
glGenTextures(1, &OSDtexture);
glBindTexture(GL_TEXTURE_2D, OSDtexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, OSDxsize, OSDysize, 0, GL_RGBA, GL_UNSIGNED_BYTE, posd);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
OsdShown = 2;
}
y = OSDy*height/VideoWindowHeight;
x = OSDx*width/VideoWindowWidth;
h = OSDysize*height/VideoWindowHeight;
w = OSDxsize*width/VideoWindowWidth;
glViewport(x,(height - h - y) , w, h);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -2877,16 +2891,12 @@ int get_RGB(CuvidDecoder * decoder)
pthread_mutex_lock(&OSDMutex);
glBindTexture(GL_TEXTURE_2D, OSDtexture);
glBindFramebuffer(GL_FRAMEBUFFER, fb);
render_pass_quad(1, 0.0, 0.0);
render_pass_quad(0, 0.0, 0.0);
pthread_mutex_unlock(&OSDMutex);
glUseProgram(0);
glActiveTexture(GL_TEXTURE0);
#ifdef CUVID
// glXMakeCurrent(XlibDisplay, VideoWindow, glxThreadContext);
#else
// eglMakeCurrent(eglDisplay, eglSurface,eglSurface, eglThreadContext);
#endif
}
glFlush();
Debug(3, "Read pixels %d %d\n", width, height);
@ -3652,9 +3662,9 @@ void make_osd_overlay(int x, int y, int width, int height)
pl->plane.components = 4;
pl->plane.shift_x = 0.0f;
pl->plane.shift_y = 0.0f;
pl->plane.component_mapping[0] = PL_CHANNEL_B;
pl->plane.component_mapping[0] = PL_CHANNEL_R;
pl->plane.component_mapping[1] = PL_CHANNEL_G;
pl->plane.component_mapping[2] = PL_CHANNEL_R;
pl->plane.component_mapping[2] = PL_CHANNEL_B;
pl->plane.component_mapping[3] = PL_CHANNEL_A;
pl->mode = PL_OVERLAY_NORMAL;
pl->repr.sys = PL_COLOR_SYSTEM_RGB;
@ -3864,22 +3874,31 @@ static void CuvidDisplayFrame(void)
#ifndef PLACEBO
// add osd to surface
if (OsdShown && valid_frame) {
GLint texLoc;
#ifdef CUVID
glXMakeCurrent(XlibDisplay, VideoWindow, glxSharedContext);
GlxCheck();
#endif
#ifdef VAAPI
// eglMakeCurrent(eglDisplay, eglSurface, eglSurface, OSDcontext);
#endif
glBindTexture(GL_TEXTURE_2D, 0);
if (OsdShown == 1) {
if (OSDtexture)
glDeleteTextures(1,&OSDtexture);
glGenTextures(1, &OSDtexture);
glBindTexture(GL_TEXTURE_2D, OSDtexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, OSDxsize, OSDysize, 0, GL_RGBA, GL_UNSIGNED_BYTE, posd);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
OsdShown = 2;
}
glBindTexture(GL_TEXTURE_2D, 0);
glEnable(GL_BLEND);
GlxCheck();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GlxCheck();
glViewport(0, 0, VideoWindowWidth, VideoWindowHeight);
GlxCheck();
glViewport(OSDx,(VideoWindowHeight - OSDysize - OSDy) , OSDxsize, OSDysize);
if (gl_prog_osd == 0)
gl_prog_osd = sc_generate_osd(gl_prog_osd); // generate shader programm
@ -3891,18 +3910,13 @@ static void CuvidDisplayFrame(void)
pthread_mutex_lock(&OSDMutex);
glBindTexture(GL_TEXTURE_2D, OSDtexture);
render_pass_quad(0, 0, 0);
render_pass_quad(1, 0, 0);
pthread_mutex_unlock(&OSDMutex);
glUseProgram(0);
glActiveTexture(GL_TEXTURE0);
#ifdef CUVID
glXMakeCurrent(XlibDisplay, VideoWindow, glxThreadContext);
#endif
#ifdef VAAPI
// eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglThreadContext);
#endif
}
#endif
#ifdef PLACEBO
@ -4675,13 +4689,14 @@ void VideoOsdDrawARGB(int xi, int yi, int width, int height, int pitch, const ui
void ActivateOsd(GLuint texture, int x, int y, int xsize, int ysize)
{
//printf("OSD open %d %d %d %d\n",x,y,xsize,ysize);
OsdShown = 1;
OSDfb = texture;
OSDtexture = texture;
// OSDtexture = texture;
OSDx = x;
OSDy = y;
OSDxsize = xsize;
OSDysize = ysize;
OsdShown = 1;
}
///
@ -5192,7 +5207,10 @@ static void VideoThreadExit(void)
pthread_mutex_destroy(&VideoLockMutex);
pthread_mutex_destroy(&VideoMutex);
pthread_mutex_destroy(&OSDMutex);
#ifndef PLACEBO
if (OSDtexture)
glDeleteTextures(1,&OSDtexture);
if (gl_prog_osd) {
glDeleteProgram(gl_prog_osd);
gl_prog_osd = 0;
@ -6625,8 +6643,8 @@ int GlxInitopengl()
}
Debug(3, "Create OSD egl context\n");
#ifdef VAAPI
eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, OSDcontext);
EglCheck();
// eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, OSDcontext);
// EglCheck();
#else
glXMakeCurrent(XlibDisplay, VideoWindow, OSDcontext);
GlxCheck();