diff --git a/openglosd.cpp b/openglosd.cpp index b908064..0cd1269 100644 --- a/openglosd.cpp +++ b/openglosd.cpp @@ -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); } /**************************************************************************************** @@ -1921,7 +1926,7 @@ eOsdError cOglOsd::SetAreas(const tArea *Areas, int NumAreas) { //now we know the actuaL osd size, create double buffer frame buffer if (bFb) { - oglThread->DoCmd(new cOglCmdDeleteFb(bFb)); + oglThread->DoCmd(new cOglCmdDeleteFb(bFb)); DestroyPixmap(oglPixmaps[0]); } bFb = new cOglFb(r.Width(), r.Height(), r.Width(), r.Height()); @@ -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)); } diff --git a/openglosd.h b/openglosd.h index aa56910..33adabf 100644 --- a/openglosd.h +++ b/openglosd.h @@ -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; diff --git a/softhdcuvid.cpp b/softhdcuvid.cpp index b4dd84e..31caeb7 100644 --- a/softhdcuvid.cpp +++ b/softhdcuvid.cpp @@ -315,18 +315,18 @@ void cSoftOsd::SetActive(bool on) #endif if (Active() == on) { - return; // already active, no action + return; // already active, no action } cOsd::SetActive(on); if (on) { - Dirty = 1; - // only flush here if there are already bitmaps - if (GetBitmap(0)) { - Flush(); - } + Dirty = 1; + // only flush here if there are already bitmaps + if (GetBitmap(0)) { + Flush(); + } } else { - OsdClose(); + OsdClose(); } } @@ -391,7 +391,7 @@ eOsdError cSoftOsd::SetAreas(const tArea * areas, int n) // clear old OSD, when new areas are set if (!IsTrueColor()) { - cBitmap *bitmap; + cBitmap *bitmap; int i; for (i = 0; (bitmap = GetBitmap(i)); i++) { @@ -399,8 +399,8 @@ eOsdError cSoftOsd::SetAreas(const tArea * areas, int n) } } if (Active()) { - VideoOsdClear(); - Dirty = 1; + VideoOsdClear(); + Dirty = 1; } return cOsd::SetAreas(areas, n); } @@ -1612,12 +1612,12 @@ eOSState cSoftHdControl::ProcessKey(eKeys key) { if (SuspendMode == SUSPEND_NORMAL && (!ISMODELESSKEY(key) || key == kMenu || key == kBack || key == kStop)) { - delete Player; + delete Player; - Player = NULL; - Resume(); - SuspendMode = NOT_SUSPENDED; - return osEnd; + Player = NULL; + Resume(); + SuspendMode = NOT_SUSPENDED; + return osEnd; } return osContinue; } @@ -1640,8 +1640,8 @@ cSoftHdControl::~cSoftHdControl() Player = NULL; // loose control resume if (SuspendMode == SUSPEND_NORMAL) { - Resume(); - SuspendMode = NOT_SUSPENDED; + Resume(); + SuspendMode = NOT_SUSPENDED; } dsyslog("[softhddev]%s: dummy player stopped\n", __FUNCTION__); @@ -3104,14 +3104,14 @@ void cPluginSoftHdDevice::Housekeeping(void) // check if user is inactive, automatic enter suspend mode // FIXME: cControl prevents shutdown, disable this until fixed if (0 && SuspendMode == NOT_SUSPENDED && ShutdownHandler.IsUserInactive()) { - // don't overwrite already suspended suspend mode - cControl::Launch(new cSoftHdControl); - cControl::Attach(); - Suspend(ConfigSuspendClose, ConfigSuspendClose, ConfigSuspendX11); - SuspendMode = SUSPEND_NORMAL; + // don't overwrite already suspended suspend mode + cControl::Launch(new cSoftHdControl); + cControl::Attach(); + Suspend(ConfigSuspendClose, ConfigSuspendClose, ConfigSuspendX11); + SuspendMode = SUSPEND_NORMAL; #ifdef USE_OPENGLOSD - dsyslog("[softhddev]stopping Ogl Thread Housekeeping"); - cSoftOsdProvider::StopOpenGlThread(); + dsyslog("[softhddev]stopping Ogl Thread Housekeeping"); + cSoftOsdProvider::StopOpenGlThread(); #endif } diff --git a/softhddev.c b/softhddev.c index 096a292..0e0d2c4 100644 --- a/softhddev.c +++ b/softhddev.c @@ -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); @@ -1614,10 +1615,10 @@ static void VideoMpegEnqueue(VideoStream * stream, int64_t pts, int64_t dts, // FIXME: not perfect, must split at 0xb3 also if (!p[0] && !p[1] && p[2] == 0x01 && !p[3]) { if (first) { - first = 0; - n -= 4; - p += 4; - continue; + first = 0; + n -= 4; + p += 4; + continue; } // packet has already an picture header /* @@ -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; } @@ -1647,17 +1651,17 @@ static void VideoMpegEnqueue(VideoStream * stream, int64_t pts, int64_t dts, switch (n) { // handle packet border start code case 3: if (!p[0] && !p[1] && p[2] == 0x01) { - stream->StartCodeState = 3; + stream->StartCodeState = 3; } break; case 2: if (!p[0] && !p[1]) { - stream->StartCodeState = 2; + stream->StartCodeState = 2; } break; case 1: if (!p[0]) { - stream->StartCodeState = 1; + stream->StartCodeState = 1; } break; case 0: @@ -1756,9 +1760,9 @@ static void VideoStreamOpen(VideoStream * stream) stream->CodecID = AV_CODEC_ID_NONE; stream->LastCodecID = AV_CODEC_ID_NONE; if ((stream->HwDecoder = VideoNewHwDecoder(stream))) { - stream->Decoder = CodecVideoNewDecoder(stream->HwDecoder); - VideoPacketInit(stream); - stream->SkipStream = 0; + stream->Decoder = CodecVideoNewDecoder(stream->HwDecoder); + VideoPacketInit(stream); + stream->SkipStream = 0; } } @@ -3321,7 +3325,7 @@ void Suspend(int video, int audio, int dox11) { pthread_mutex_lock(&SuspendLockMutex); if (MyVideoStream->SkipStream && SkipAudio) { // already suspended - pthread_mutex_unlock(&SuspendLockMutex); + pthread_mutex_unlock(&SuspendLockMutex); return; } @@ -3337,17 +3341,17 @@ void Suspend(int video, int audio, int dox11) SkipAudio = 1; if (audio) { - AudioExit(); - if (MyAudioDecoder) { - CodecAudioClose(MyAudioDecoder); - CodecAudioDelDecoder(MyAudioDecoder); - MyAudioDecoder = NULL; - } - NewAudioStream = 0; - av_free_packet(AudioAvPkt); + AudioExit(); + if (MyAudioDecoder) { + CodecAudioClose(MyAudioDecoder); + CodecAudioDelDecoder(MyAudioDecoder); + MyAudioDecoder = NULL; + } + NewAudioStream = 0; + av_free_packet(AudioAvPkt); } if (video) { - StopVideo(); + StopVideo(); } if (dox11) { diff --git a/video.c b/video.c index e8f8e57..1a8f7f0 100644 --- a/video.c +++ b/video.c @@ -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__); + 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 @@ -3145,17 +3141,20 @@ static void CuvidDisplayFrame(void) // // add osd to surface // - if (OsdShown) { + if (OsdShown) { #ifndef USE_OPENGLOSD glXMakeCurrent(XlibDisplay, VideoWindow, GlxThreadContext); - GlxRenderTexture(OsdGlTextures[OsdIndex], 0,0, VideoWindowWidth, VideoWindowHeight); + 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); } } @@ -4686,12 +4687,12 @@ void VideoGetVideoSize(VideoHwDecoder * hw_decoder, int *width, int *height, // FIXME: test to check if working, than make module function if (VideoUsedModule == &CuvidModule) { - *width = hw_decoder->Cuvid.InputWidth; - *height = hw_decoder->Cuvid.InputHeight; - av_reduce(aspect_num, aspect_den, - hw_decoder->Cuvid.InputWidth * hw_decoder->Cuvid.InputAspect.num, - hw_decoder->Cuvid.InputHeight * hw_decoder->Cuvid.InputAspect.den, - 1024 * 1024); + *width = hw_decoder->Cuvid.InputWidth; + *height = hw_decoder->Cuvid.InputHeight; + av_reduce(aspect_num, aspect_den, + hw_decoder->Cuvid.InputWidth * hw_decoder->Cuvid.InputAspect.num, + hw_decoder->Cuvid.InputHeight * hw_decoder->Cuvid.InputAspect.den, + 1024 * 1024); } @@ -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); } }