Aspect fix for SD and more mutex for OSD

This commit is contained in:
jojo61 2018-09-25 16:29:03 +02:00
parent cca1022528
commit 580ab6dc42
5 changed files with 96 additions and 79 deletions

View File

@ -672,7 +672,7 @@ void cOglVb::DrawArrays(int count) {
glFlush(); glFlush();
} }
#if 0
/**************************************************************************************** /****************************************************************************************
* cOpenGLCmd * cOpenGLCmd
****************************************************************************************/ ****************************************************************************************/
@ -686,7 +686,7 @@ bool cOglCmdInitOutputFb::Execute(void) {
oFb->Unbind(); oFb->Unbind();
return ok; return ok;
} }
#endif
//------------------ cOglCmdInitFb -------------------- //------------------ cOglCmdInitFb --------------------
cOglCmdInitFb::cOglCmdInitFb(cOglFb *fb, cCondWait *wait) : cOglCmd(fb) { cOglCmdInitFb::cOglCmdInitFb(cOglFb *fb, cCondWait *wait) : cOglCmd(fb) {
this->wait = wait; this->wait = wait;
@ -1649,13 +1649,18 @@ void cOglThread::DeleteVertexBuffers(void) {
void cOglThread::Cleanup(void) { void cOglThread::Cleanup(void) {
esyslog("[softhddev]OglThread cleanup\n"); esyslog("[softhddev]OglThread cleanup\n");
pthread_mutex_lock(&OSDMutex);
OsdClose();
DeleteVertexBuffers(); DeleteVertexBuffers();
// delete cOglOsd::oFb; // delete cOglOsd::oFb;
cOglOsd::oFb = NULL; cOglOsd::oFb = NULL;
DeleteShaders(); DeleteShaders();
// glVDPAUFiniNV(); // glVDPAUFiniNV();
cOglFont::Cleanup(); cOglFont::Cleanup();
// glutExit(); // glutExit();
pthread_mutex_unlock(&OSDMutex);
} }
/**************************************************************************************** /****************************************************************************************
@ -1995,6 +2000,8 @@ void cOglOsd::Flush(void) {
//clear buffer //clear buffer
//uint64_t start = cTimeMs::Now(); //uint64_t start = cTimeMs::Now();
//dsyslog("[softhddev]Start Flush at %" PRIu64 "", cTimeMs::Now()); //dsyslog("[softhddev]Start Flush at %" PRIu64 "", cTimeMs::Now());
pthread_mutex_lock(&OSDMutex);
oglThread->DoCmd(new cOglCmdFill(bFb, clrTransparent)); oglThread->DoCmd(new cOglCmdFill(bFb, clrTransparent));
//render pixmap textures blended to buffer //render pixmap textures blended to buffer
@ -2015,6 +2022,7 @@ void cOglOsd::Flush(void) {
} }
} }
ActivateOsd(bFb->texture,Left(), Top() , bFb->Width(), bFb->Height()); ActivateOsd(bFb->texture,Left(), Top() , bFb->Width(), bFb->Height());
pthread_mutex_unlock(&OSDMutex);
// oglThread->DoCmd(new cOglCmdCopyBufferToOutputFb(bFb, oFb, Left(), Top())); // oglThread->DoCmd(new cOglCmdCopyBufferToOutputFb(bFb, oFb, Left(), Top()));
//dsyslog("[softhddev]End Flush at %" PRIu64 ", duration %d", cTimeMs::Now(), (int)(cTimeMs::Now()-start)); //dsyslog("[softhddev]End Flush at %" PRIu64 ", duration %d", cTimeMs::Now(), (int)(cTimeMs::Now()-start));
} }

View File

@ -44,8 +44,11 @@ extern "C"
#include "audio.h" #include "audio.h"
#include "video.h" #include "video.h"
#include "codec.h" #include "codec.h"
} }
extern "C" pthread_mutex_t OSDMutex;
struct sOglImage { struct sOglImage {
GLuint texture; GLuint texture;
GLint width; GLint width;

View File

@ -1556,7 +1556,7 @@ static void VideoMpegEnqueue(VideoStream * stream, int64_t pts, int64_t dts,
#endif #endif
if (!p[0] || p[0] == 0xb3) { if (!p[0] || p[0] == 0xb3) {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "last: %d start\n", stream->StartCodeState); printf("last: %d start aspect %02x\n", stream->StartCodeState,p[4]);
#endif #endif
stream->PacketRb[stream->PacketWrite].stream_index -= 3; stream->PacketRb[stream->PacketWrite].stream_index -= 3;
VideoNextPacket(stream, AV_CODEC_ID_MPEG2VIDEO); VideoNextPacket(stream, AV_CODEC_ID_MPEG2VIDEO);
@ -1566,6 +1566,7 @@ static void VideoMpegEnqueue(VideoStream * stream, int64_t pts, int64_t dts,
n--; n--;
pts = AV_NOPTS_VALUE; pts = AV_NOPTS_VALUE;
} }
break; break;
case 2: // 0x00 0x00 seen case 2: // 0x00 0x00 seen
#ifdef DEBUG #ifdef DEBUG
@ -1573,7 +1574,7 @@ static void VideoMpegEnqueue(VideoStream * stream, int64_t pts, int64_t dts,
#endif #endif
if (p[0] == 0x01 && (!p[1] || p[1] == 0xb3)) { if (p[0] == 0x01 && (!p[1] || p[1] == 0xb3)) {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "last: %d start\n", stream->StartCodeState); printf( "last: %d start aspect %02x\n", stream->StartCodeState,p[5]);
#endif #endif
stream->PacketRb[stream->PacketWrite].stream_index -= 2; stream->PacketRb[stream->PacketWrite].stream_index -= 2;
VideoNextPacket(stream, AV_CODEC_ID_MPEG2VIDEO); VideoNextPacket(stream, AV_CODEC_ID_MPEG2VIDEO);
@ -1590,7 +1591,7 @@ static void VideoMpegEnqueue(VideoStream * stream, int64_t pts, int64_t dts,
#endif #endif
if (!p[0] && p[1] == 0x01 && (!p[2] || p[2] == 0xb3)) { if (!p[0] && p[1] == 0x01 && (!p[2] || p[2] == 0xb3)) {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "last: %d start\n", stream->StartCodeState); printf( "last: %d start aspect %02x\n", stream->StartCodeState,p[6]);
#endif #endif
stream->PacketRb[stream->PacketWrite].stream_index -= 1; stream->PacketRb[stream->PacketWrite].stream_index -= 1;
VideoNextPacket(stream, AV_CODEC_ID_MPEG2VIDEO); VideoNextPacket(stream, AV_CODEC_ID_MPEG2VIDEO);
@ -1639,6 +1640,9 @@ static void VideoMpegEnqueue(VideoStream * stream, int64_t pts, int64_t dts,
p += 4; p += 4;
continue; continue;
} }
if (!p[0] && !p[1] && p[2] == 0x01 && p[3] == 0xb3) {
// printf("aspectratio %02x\n",p[7]>>4);
}
--n; --n;
++p; ++p;
} }

42
video.c
View File

@ -416,7 +416,7 @@ 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 static pthread_mutex_t VideoLockMutex; ///< video lock mutex
pthread_mutex_t OSDMutex; ///< OSD update mutex
#endif #endif
#ifdef USE_VIDEO_THREAD2 #ifdef USE_VIDEO_THREAD2
@ -601,9 +601,7 @@ static void VideoUpdateOutput(AVRational input_aspect_ratio, int input_width,
tmp_ratio.num = 4; tmp_ratio.num = 4;
tmp_ratio.den = 3; tmp_ratio.den = 3;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "ratio: %d:%d %d:%d\n", input_aspect_ratio.num, Debug(4, "ratio: %d:%d %d:%d\n", input_aspect_ratio.num, input_aspect_ratio.den, display_aspect_ratio.num, display_aspect_ratio.den);
input_aspect_ratio.den, display_aspect_ratio.num,
display_aspect_ratio.den);
#endif #endif
if (!av_cmp_q(input_aspect_ratio, tmp_ratio)) { if (!av_cmp_q(input_aspect_ratio, tmp_ratio)) {
switch (Video4to3ZoomMode) { switch (Video4to3ZoomMode) {
@ -635,12 +633,7 @@ static void VideoUpdateOutput(AVRational input_aspect_ratio, int input_width,
*output_y = video_y; *output_y = video_y;
*output_width = (video_height * display_aspect_ratio.num + display_aspect_ratio.den -1 ) / display_aspect_ratio.den; *output_width = (video_height * display_aspect_ratio.num + display_aspect_ratio.den -1 ) / display_aspect_ratio.den;
*output_height = (video_width * display_aspect_ratio.den + display_aspect_ratio.num -1 ) / display_aspect_ratio.num; *output_height = (video_width * display_aspect_ratio.den + display_aspect_ratio.num -1 ) / display_aspect_ratio.num;
// JOJO hier stimmt was nicht // JOJO
#if DEBUG
*output_width = video_width;
*output_height = video_height;
#endif
if (*output_width > video_width) { if (*output_width > video_width) {
*output_width = video_width; *output_width = video_width;
*output_y += (video_height - *output_height) / 2; *output_y += (video_height - *output_height) / 2;
@ -988,14 +981,17 @@ static void GlxOsdClear(void)
{ {
void *texbuf; void *texbuf;
#ifdef USE_OPENGLOSD
return;
#endif
#ifdef DEBUG #ifdef DEBUG
if (!GlxEnabled) { if (!GlxEnabled) {
Debug(3, "video/glx: %s called without glx enabled\n", __FUNCTION__); Debug(3, "video/glx: %s called without glx enabled\n", __FUNCTION__);
return; return;
} }
Debug(3, "video/glx: osd context %p <-> %p\n", glXGetCurrentContext(), Debug(3, "video/glx: osd context %p <-> %p\n", glXGetCurrentContext(), GlxContext);
GlxContext);
#endif #endif
// FIXME: any opengl function to clear an area? // FIXME: any opengl function to clear an area?
@ -1011,7 +1007,6 @@ static void GlxOsdClear(void)
texbuf = calloc(OsdWidth * OsdHeight, 4); texbuf = calloc(OsdWidth * OsdHeight, 4);
GlxUploadOsdTexture(0, 0, OsdWidth, OsdHeight, texbuf); GlxUploadOsdTexture(0, 0, OsdWidth, OsdHeight, texbuf);
glXMakeCurrent(XlibDisplay, None, NULL); glXMakeCurrent(XlibDisplay, None, NULL);
free(texbuf); free(texbuf);
} }
@ -1327,7 +1322,6 @@ static void GlxExit(void)
} }
if (GlxSharedContext) { if (GlxSharedContext) {
glXDestroyContext(XlibDisplay, GlxSharedContext); glXDestroyContext(XlibDisplay, GlxSharedContext);
GlxSharedContext=0;
} }
if (GlxContext) { if (GlxContext) {
glXDestroyContext(XlibDisplay, GlxContext); glXDestroyContext(XlibDisplay, GlxContext);
@ -1998,6 +1992,7 @@ Debug(3,"cuvid del hw decoder\n");
decoder->cuda_ctx = NULL; decoder->cuda_ctx = NULL;
} }
#endif #endif
glXMakeCurrent(XlibDisplay, None, NULL);
for (i = 0; i < CuvidDecoderN; ++i) { for (i = 0; i < CuvidDecoderN; ++i) {
if (CuvidDecoders[i] == decoder) { if (CuvidDecoders[i] == decoder) {
CuvidDecoders[i] = NULL; CuvidDecoders[i] = NULL;
@ -2819,7 +2814,7 @@ static void CuvidRenderFrame(CuvidDecoder * decoder,
int surface; int surface;
VideoDecoder *ist = video_ctx->opaque; VideoDecoder *ist = video_ctx->opaque;
#if 0
// update aspect ratio changes // update aspect ratio changes
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,60,100) #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,60,100)
if (decoder->InputWidth && decoder->InputHeight if (decoder->InputWidth && decoder->InputHeight
@ -2827,6 +2822,7 @@ static void CuvidRenderFrame(CuvidDecoder * decoder,
Debug(3, "video/vdpau: aspect ratio changed\n"); Debug(3, "video/vdpau: aspect ratio changed\n");
decoder->InputAspect = frame->sample_aspect_ratio; decoder->InputAspect = frame->sample_aspect_ratio;
printf("new aspect %d:%d\n",frame->sample_aspect_ratio.num,frame->sample_aspect_ratio.den);
CuvidUpdateOutput(decoder); CuvidUpdateOutput(decoder);
} }
#else #else
@ -2838,7 +2834,7 @@ static void CuvidRenderFrame(CuvidDecoder * decoder,
CuvidUpdateOutput(decoder); CuvidUpdateOutput(decoder);
} }
#endif #endif
#endif
// //
// Check image, format, size // Check image, format, size
@ -3150,12 +3146,15 @@ static void CuvidDisplayFrame(void)
glXMakeCurrent(XlibDisplay, VideoWindow, GlxThreadContext); glXMakeCurrent(XlibDisplay, VideoWindow, GlxThreadContext);
GlxRenderTexture(OsdGlTextures[OsdIndex], 0,0, VideoWindowWidth, VideoWindowHeight); GlxRenderTexture(OsdGlTextures[OsdIndex], 0,0, VideoWindowWidth, VideoWindowHeight);
#else #else
pthread_mutex_lock(&OSDMutex);
glXMakeCurrent(XlibDisplay, VideoWindow, GlxContext ); glXMakeCurrent(XlibDisplay, VideoWindow, GlxContext );
GlxRenderTexture(OSDtexture, OSDx, OSDy, OSDxsize, OSDysize); GlxRenderTexture(OSDtexture, OSDx, OSDy, OSDxsize, OSDysize);
pthread_mutex_unlock(&OSDMutex);
#endif #endif
glXMakeCurrent(XlibDisplay, VideoWindow, GlxSharedContext); glXMakeCurrent(XlibDisplay, VideoWindow, GlxSharedContext);
// FIXME: toggle osd
} }
glXGetVideoSyncSGI (&Count); // get current frame glXGetVideoSyncSGI (&Count); // get current frame
glXSwapBuffers(XlibDisplay, VideoWindow); glXSwapBuffers(XlibDisplay, VideoWindow);
@ -4238,6 +4237,7 @@ static void VideoThreadInit(void)
pthread_mutex_init(&VideoMutex, NULL); pthread_mutex_init(&VideoMutex, NULL);
pthread_mutex_init(&VideoLockMutex, NULL); pthread_mutex_init(&VideoLockMutex, NULL);
pthread_mutex_init(&OSDMutex, NULL);
pthread_cond_init(&VideoWakeupCond, NULL); pthread_cond_init(&VideoWakeupCond, NULL);
pthread_create(&VideoThread, NULL, VideoDisplayHandlerThread, NULL); pthread_create(&VideoThread, NULL, VideoDisplayHandlerThread, NULL);
} }
@ -4264,6 +4264,7 @@ static void VideoThreadExit(void)
pthread_cond_destroy(&VideoWakeupCond); pthread_cond_destroy(&VideoWakeupCond);
pthread_mutex_destroy(&VideoLockMutex); pthread_mutex_destroy(&VideoLockMutex);
pthread_mutex_destroy(&VideoMutex); pthread_mutex_destroy(&VideoMutex);
pthread_mutex_destroy(&OSDMutex);
} }
} }
@ -4881,7 +4882,7 @@ static void VideoCreateWindow(xcb_window_t parent, xcb_visualid_t visual,
#endif #endif
// FIXME: size hints // FIXME: size hints
#if 0
// register interest in the delete window message // register interest in the delete window message
if ((reply = if ((reply =
xcb_intern_atom_reply(Connection, xcb_intern_atom(Connection, 0, sizeof("WM_DELETE_WINDOW") - 1, "WM_DELETE_WINDOW"),NULL))) { xcb_intern_atom_reply(Connection, xcb_intern_atom(Connection, 0, sizeof("WM_DELETE_WINDOW") - 1, "WM_DELETE_WINDOW"),NULL))) {
@ -4898,7 +4899,7 @@ static void VideoCreateWindow(xcb_window_t parent, xcb_visualid_t visual,
free(reply); free(reply);
} }
} }
#endif
// //
// prepare fullscreen. // prepare fullscreen.
// //
@ -5611,7 +5612,7 @@ void VideoExit(void)
// FIXME: cleanup. // FIXME: cleanup.
// //
//RandrExit(); //RandrExit();
pthread_mutex_lock(&OSDMutex);
// //
// X11/xcb cleanup // X11/xcb cleanup
// //
@ -5638,6 +5639,7 @@ void VideoExit(void)
} }
XlibDisplay = NULL; XlibDisplay = NULL;
Connection = 0; Connection = 0;
pthread_mutex_unlock(&OSDMutex);
} }
} }