Fix Thread locking for softhddrm Version with placebo

This commit is contained in:
jojo61 2023-07-14 09:13:09 +02:00
parent 7f054f8320
commit 4837f7fa35
2 changed files with 36 additions and 16 deletions

View File

@ -1263,7 +1263,8 @@ bool cOglCmdDrawImage::Execute(void) {
GLuint texture; GLuint texture;
#ifdef USE_DRM #ifdef USE_DRM
// pthread_mutex_lock(&OSDMutex); //esyslog("upload Image\n");
pthread_mutex_lock(&OSDMutex);
GlxDrawopengl(); // here we need the Shared Context for upload GlxDrawopengl(); // here we need the Shared Context for upload
GlxCheck(); GlxCheck();
#endif #endif
@ -1276,10 +1277,10 @@ bool cOglCmdDrawImage::Execute(void) {
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);
glFlush(); glFlush();
#ifdef USE_DRM #ifdef USE_DRM
GlxInitopengl(); // Reset Context GlxInitopengl(); // Reset Context
GlxCheck(); GlxCheck();
// pthread_mutex_unlock(&OSDMutex); pthread_mutex_unlock(&OSDMutex);
#endif #endif
GLfloat x1 = x; // left GLfloat x1 = x; // left
@ -1369,7 +1370,8 @@ cOglCmdStoreImage::~cOglCmdStoreImage(void) { free(data); }
bool cOglCmdStoreImage::Execute(void) { bool cOglCmdStoreImage::Execute(void) {
#ifdef USE_DRM #ifdef USE_DRM
// pthread_mutex_lock(&OSDMutex); return false;
pthread_mutex_lock(&OSDMutex);
GlxDrawopengl(); // here we need the Shared Context for upload GlxDrawopengl(); // here we need the Shared Context for upload
GlxCheck(); GlxCheck();
#endif #endif
@ -1386,7 +1388,7 @@ bool cOglCmdStoreImage::Execute(void) {
#ifdef USE_DRM #ifdef USE_DRM
GlxInitopengl(); // Reset Context GlxInitopengl(); // Reset Context
GlxCheck(); GlxCheck();
// pthread_mutex_lock(&OSDMutex); pthread_mutex_lock(&OSDMutex);
#endif #endif
return true; return true;
} }
@ -1466,7 +1468,9 @@ int cOglThread::StoreImage(const cImage &image) {
if (!maxCacheSize) { if (!maxCacheSize) {
return 0; return 0;
} }
#ifdef USE_DRM
return 0;
#endif
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 "
@ -1646,6 +1650,7 @@ void cOglThread::Action(void) {
bool cOglThread::InitOpenGL(void) { bool cOglThread::InitOpenGL(void) {
#ifdef USE_DRM #ifdef USE_DRM
esyslog("InitOpenGL\n");
GlxInitopengl(); GlxInitopengl();
#else #else
const char *displayName = X11DisplayName; const char *displayName = X11DisplayName;
@ -1657,7 +1662,7 @@ bool cOglThread::InitOpenGL(void) {
} }
} }
dsyslog("[softhddev]OpenGL using display %s", displayName); esyslog("[softhddev]OpenGL using display %s", displayName);
int argc = 3; int argc = 3;
char *buffer[3]; char *buffer[3];

33
video.c
View File

@ -464,7 +464,7 @@ extern void AudioVideoReady(int64_t); ///< tell audio video is ready
static pthread_t VideoThread; ///< video decode thread static pthread_t VideoThread; ///< video decode thread
static pthread_cond_t VideoWakeupCond; ///< wakeup condition variable static pthread_cond_t VideoWakeupCond; ///< wakeup condition variable
static pthread_mutex_t VideoMutex; ///< video condition mutex static pthread_mutex_t VideoMutex; ///< video condition mutex
static pthread_mutex_t VideoLockMutex; ///< video lock mutex pthread_mutex_t VideoLockMutex; ///< video lock mutex
pthread_mutex_t OSDMutex; ///< OSD update mutex pthread_mutex_t OSDMutex; ///< OSD update mutex
#endif #endif
@ -825,6 +825,8 @@ static uint64_t test_time = 0;
#define Lock_and_SharedContext \ #define Lock_and_SharedContext \
{ \ { \
VideoThreadLock(); \ VideoThreadLock(); \
Debug(4,"Lock OSDMutex %s %d\n",__FILE__, __LINE__); \
pthread_mutex_lock(&OSDMutex); \
eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, eglSharedContext); \ eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, eglSharedContext); \
EglCheck(); \ EglCheck(); \
} }
@ -832,10 +834,14 @@ static uint64_t test_time = 0;
{ \ { \
eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); \ eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); \
EglCheck(); \ EglCheck(); \
Debug(4,"UnLock OSDMutex %s %d\n",__FILE__, __LINE__); \
pthread_mutex_unlock(&OSDMutex); \
VideoThreadUnlock(); \ VideoThreadUnlock(); \
} }
#define SharedContext \ #define SharedContext \
{ \ { \
Debug(4,"Lock OSDMutex %s %d\n",__FILE__, __LINE__); \
pthread_mutex_lock(&OSDMutex); \
eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, eglSharedContext); \ eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, eglSharedContext); \
EglCheck(); \ EglCheck(); \
} }
@ -843,6 +849,8 @@ static uint64_t test_time = 0;
{ \ { \
eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); \ eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); \
EglCheck(); \ EglCheck(); \
Debug(4,"UnLock OSDMutex %s %d\n",__FILE__, __LINE__); \
pthread_mutex_unlock(&OSDMutex); \
} }
#else #else
#ifdef PLACEBO #ifdef PLACEBO
@ -2576,7 +2584,7 @@ void generateVAAPIImage(CuvidDecoder *decoder, VASurfaceID index, const AVFrame
// vaSyncSurface(decoder->VaDisplay, (VASurfaceID) (uintptr_t) // vaSyncSurface(decoder->VaDisplay, (VASurfaceID) (uintptr_t)
// frame->data[3]); // frame->data[3]);
#endif #endif
pthread_mutex_lock(&OSDMutex);
eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, eglSharedContext); eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, eglSharedContext);
EglCheck(); EglCheck();
@ -2612,6 +2620,7 @@ void generateVAAPIImage(CuvidDecoder *decoder, VASurfaceID index, const AVFrame
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
EglCheck(); EglCheck();
pthread_mutex_unlock(&OSDMutex);
return; return;
esh_failed: esh_failed:
@ -2620,6 +2629,7 @@ esh_failed:
close(desc.objects[n].fd); close(desc.objects[n].fd);
eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
EglCheck(); EglCheck();
pthread_mutex_unlock(&OSDMutex);
} }
#endif #endif
#endif #endif
@ -4410,8 +4420,9 @@ static void CuvidDisplayFrame(void) {
} }
valid_frame = 1; valid_frame = 1;
#ifdef PLACEBO #ifdef PLACEBO
//pthread_mutex_lock(&OSDMutex);
if (OsdShown == 1) { // New OSD opened if (OsdShown == 1) { // New OSD opened
pthread_mutex_lock(&OSDMutex);
make_osd_overlay(OSDx, OSDy, OSDxsize, OSDysize); make_osd_overlay(OSDx, OSDy, OSDxsize, OSDysize);
if (posd) { if (posd) {
pl_tex_upload(p->gpu, &(struct pl_tex_transfer_params){ pl_tex_upload(p->gpu, &(struct pl_tex_transfer_params){
@ -4425,7 +4436,7 @@ static void CuvidDisplayFrame(void) {
}); });
} }
OsdShown = 2; OsdShown = 2;
pthread_mutex_unlock(&OSDMutex);
} }
if (OsdShown == 2) { if (OsdShown == 2) {
@ -4433,7 +4444,7 @@ static void CuvidDisplayFrame(void) {
} else { } else {
CuvidMixVideo(decoder, i, &target, NULL); CuvidMixVideo(decoder, i, &target, NULL);
} }
//pthread_mutex_unlock(&OSDMutex);
#else #else
CuvidMixVideo(decoder, i); CuvidMixVideo(decoder, i);
#endif #endif
@ -4518,7 +4529,11 @@ static void CuvidDisplayFrame(void) {
Fatal(_("Failed to submit swapchain buffer\n")); Fatal(_("Failed to submit swapchain buffer\n"));
VideoThreadUnlock(); VideoThreadUnlock();
pl_swapchain_swap_buffers(p->swapchain); // swap buffers pl_swapchain_swap_buffers(p->swapchain); // swap buffers
NoContext; #ifdef PLACEBO_GL
eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
EglCheck();
#endif
#else // not PLACEBO #else // not PLACEBO
#ifdef CUVID #ifdef CUVID
@ -7267,16 +7282,16 @@ int GlxInitopengl() {
if (!eglOSDContext) { if (!eglOSDContext) {
EglCheck(); EglCheck();
Fatal(_("video/egl: can't create thread egl context\n")); Fatal(_("video/egl: can't create thread egl context\n"));
return NULL; return 1;
} }
} }
eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, eglOSDContext); eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, eglOSDContext);
return; return 0;
} }
int GlxDrawopengl() { int GlxDrawopengl() {
eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, eglSharedContext); eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, eglSharedContext);
return; return 0;
} }
void GlxDestroy() { void GlxDestroy() {