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();
}
#if 0
/****************************************************************************************
* cOpenGLCmd
****************************************************************************************/
@ -686,7 +686,7 @@ bool cOglCmdInitOutputFb::Execute(void) {
oFb->Unbind();
return ok;
}
#endif
//------------------ cOglCmdInitFb --------------------
cOglCmdInitFb::cOglCmdInitFb(cOglFb *fb, cCondWait *wait) : cOglCmd(fb) {
this->wait = wait;
@ -1649,13 +1649,18 @@ void cOglThread::DeleteVertexBuffers(void) {
void cOglThread::Cleanup(void) {
esyslog("[softhddev]OglThread cleanup\n");
pthread_mutex_lock(&OSDMutex);
OsdClose();
DeleteVertexBuffers();
// delete cOglOsd::oFb;
cOglOsd::oFb = NULL;
DeleteShaders();
// glVDPAUFiniNV();
cOglFont::Cleanup();
// glutExit();
pthread_mutex_unlock(&OSDMutex);
}
/****************************************************************************************
@ -1995,6 +2000,8 @@ void cOglOsd::Flush(void) {
//clear buffer
//uint64_t start = cTimeMs::Now();
//dsyslog("[softhddev]Start Flush at %" PRIu64 "", cTimeMs::Now());
pthread_mutex_lock(&OSDMutex);
oglThread->DoCmd(new cOglCmdFill(bFb, clrTransparent));
//render pixmap textures blended to buffer
@ -2015,6 +2022,7 @@ void cOglOsd::Flush(void) {
}
}
ActivateOsd(bFb->texture,Left(), Top() , bFb->Width(), bFb->Height());
pthread_mutex_unlock(&OSDMutex);
// oglThread->DoCmd(new cOglCmdCopyBufferToOutputFb(bFb, oFb, Left(), Top()));
//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 "video.h"
#include "codec.h"
}
extern "C" pthread_mutex_t OSDMutex;
struct sOglImage {
GLuint texture;
GLint width;

View File

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