From 1cde36b72c2284cc67068dd24e473de6ed37a8ac Mon Sep 17 00:00:00 2001 From: Evgeny Gagua Date: Thu, 7 Sep 2023 17:10:52 +0000 Subject: [PATCH] Fixed Mutex Issue in MEV module (Droping Frames Situation) --- Projects/la_mojo/build | 6 +-- lib/App/common/kernelModuleEmbedVideo.cpp | 48 +++++++++++++++++------ lib/App/common/kernelModuleEmbedVideo.h | 2 + lib/data/media/video/videoAVLIBSource.cpp | 2 +- 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/Projects/la_mojo/build b/Projects/la_mojo/build index e30c9046..0d3905e9 100755 --- a/Projects/la_mojo/build +++ b/Projects/la_mojo/build @@ -1,11 +1,11 @@ #! /bin/sh -#make clean -e "CFG=Debug" -#make -e "CFG=Debug" -j6 +make clean -e "CFG=Debug" +make -e "CFG=Debug" -j6 #make clean -e "CFG=Debug86" -make -e "CFG=Debug86" -j4 +#make -e "CFG=Debug86" -j4 #make clean -e "CFG=Release86" #make -e "CFG=Release86" -j4 diff --git a/lib/App/common/kernelModuleEmbedVideo.cpp b/lib/App/common/kernelModuleEmbedVideo.cpp index 8f87c0f3..347be8fd 100644 --- a/lib/App/common/kernelModuleEmbedVideo.cpp +++ b/lib/App/common/kernelModuleEmbedVideo.cpp @@ -1248,7 +1248,7 @@ bool streamHandler::create( dataBinder *ptr, uint32_t stremID ){ case 'D': { //Check Auth mode if basic - Override and use AVLIB // To Debug LIVE555 ONLY - if ( 0 && tCAM->auth_mode == 0 ) { + if ( 1 || tCAM->auth_mode == 0 ) { m_cSourceType = 'A'; m_pSource = (basicMediaSource *) new videoAVLIBSource( &m_sSourceDesc ); break; } else { @@ -1335,7 +1335,7 @@ bool streamHandler::pushFrame( cv::Mat &Frame, void* src ){ bool SkeepW, SkeepA, SkeepB; if( m_pMaster == NULL ) return false; MEDIA_SOURCE_DESC * tMD = (MEDIA_SOURCE_DESC *) src; - char tBuffer[128]; + char tBuffer[128]; if( tMD ) { float mK, oK; cv::Rect ROI; @@ -1363,6 +1363,7 @@ bool streamHandler::pushFrame( cv::Mat &Frame, void* src ){ cv::FILLED ); }; + #ifdef EVE_ENABLE_EASE_OUTPUT_FPS SkeepW = !((m_bWebFrameSkeepDividerCounter % m_bWebFrameSkeepDivider) == 0 ); m_bWebFrameSkeepDividerCounter = ( ++m_bWebFrameSkeepDividerCounter ) % m_bWebFrameSkeepDivider; @@ -1446,11 +1447,30 @@ bool streamHandler::pushFrame( cv::Mat &Frame, void* src ){ }; #endif +#ifdef EVE_ENABLE_DROP_OUTPUT_FPS + //LOG("T"); + m_mEncodingQueueProtector.lock(); + if( m_qEncodingQueue.size() > 10 ){ + m_mEncodingQueueProtector.unlock(); + m_pMaster->m_mPictureProtector.unlock(); + //LOG("D"); + return true; + }; + m_mEncodingQueueProtector.unlock(); + //LOG("Q"); +#endif + #ifdef EVE_ENABLE_EASE_OUTPUT_FPS #ifdef EVE_ENABLE_VIDEO - if( SkeepW && SkeepA && SkeepB ) return true; + if( SkeepW && SkeepA && SkeepB ) { + m_pMaster->m_mPictureProtector.unlock(); + return true; + }; #else - if( SkeepW ) return true; + if( SkeepW ){ + m_pMaster->m_mPictureProtector.unlock(); + return true; + }; #endif #endif @@ -1773,7 +1793,7 @@ bool streamHandler::pushFrame( cv::Mat &Frame, void* src ){ // break; }; //} while ( 0 ); -#else +#else // !EVE_ENABLE_EASE_OUTPUT_FPS // do { //In Any Case Close Stream if it Long enough if( m_nSegBFrameCounter > m_nHardLimitFrames ){ @@ -2943,9 +2963,9 @@ bool streamHandler::initVideoOutput(){ void streamHandler::m_fThreadProc( void ){ char tB[128]; -#ifdef EVE_ENABLE_EASE_OUTPUT_FPS - uint32_t nQueueSize; -#endif +//#ifdef EVE_ENABLE_EASE_OUTPUT_FPS + size_t nQueueSize; +//#endif #ifndef OPENCV_VIDEO_OUTPUT AVPacket mPacket; int bGotPacket; @@ -2968,8 +2988,10 @@ void streamHandler::m_fThreadProc( void ){ }; m_mEncodingQueueProtector.lock(); -#ifdef EVE_ENABLE_EASE_OUTPUT_FPS nQueueSize = m_qEncodingQueue.size(); + m_mEncodingQueueProtector.unlock(); + +#ifdef EVE_ENABLE_EASE_OUTPUT_FPS if ( nQueueSize > EVE_EASE_FPS_QUEUE_SIZE_MAXIMUM ) { //Just in case allredy applied to a streams if( m_bWebFrameSkeepDivider == m_bAFrameSkeepDivider && m_bWebFrameSkeepDivider == m_bBFrameSkeepDivider ){ @@ -3006,8 +3028,9 @@ void streamHandler::m_fThreadProc( void ){ if ( nQueueSize ) { #else - if ( m_qEncodingQueue.size() ) { + if ( nQueueSize ) { #endif + m_mEncodingQueueProtector.lock(); ENCODING_BUFFER *tData = m_qEncodingQueue.front(); if( tData ){ m_qEncodingQueue.pop(); @@ -3092,9 +3115,8 @@ void streamHandler::m_fThreadProc( void ){ m_nGlobalFrameCounter++; m_mFrameCounterProtector.unlock(); } else m_mEncodingQueueProtector.unlock(); - } else //{ - m_mEncodingQueueProtector.unlock(); - // If No Encode Job -> Test Commands! + }; + // Test Commands! m_mCurrentOperationProtector.lock(); switch ( m_bCOP ) { case 0x01:{ diff --git a/lib/App/common/kernelModuleEmbedVideo.h b/lib/App/common/kernelModuleEmbedVideo.h index 6d3d5371..73e1fae5 100644 --- a/lib/App/common/kernelModuleEmbedVideo.h +++ b/lib/App/common/kernelModuleEmbedVideo.h @@ -190,6 +190,8 @@ typedef map mapSTREAMMAPS; #define EVE_EASE_FPS_DIVIDER_MAXIMUM 5 #define EVE_EASE_FPS_QUEUE_SIZE_MAXIMUM 8 #define EVE_EASE_FPS_QUEUE_SIZE_MINIMUM 2 +#else + //#define EVE_ENABLE_DROP_OUTPUT_FPS #endif #ifdef EVE_ENABLE_VIDEO diff --git a/lib/data/media/video/videoAVLIBSource.cpp b/lib/data/media/video/videoAVLIBSource.cpp index 9b448a53..ba509248 100644 --- a/lib/data/media/video/videoAVLIBSource.cpp +++ b/lib/data/media/video/videoAVLIBSource.cpp @@ -832,7 +832,7 @@ void videoAVLIBSource::m_fThreadProc( void ){ //sprintf( tB, "Try to copy %d[%dx%d] bytes to %d[%dx%d]", pFrameBGR->linesize[0] * m_nHeight, pFrameBGR->width, pFrameBGR->height, mRGB.total() * mRGB.elemSize(), mRGB.cols, mRGB.rows ); //LOG(tB); memcpy( mRGB.data, pFrameBGR->data[0], pFrameBGR->linesize[0] * m_nOutHeight ); - //LOG("13"); + //LOG("P"); if(!m_pMediaDestination->pushFrame( mRGB, m_pOpaque )){ m_pMediaDestination = NULL; LOG_ERROR("Error Consume Frame by Media Destination!");