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

View File

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

90
video.c
View File

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