From 370c798689c7cb0bc702db9fb58643fee8a49c12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Charette?= Date: Mon, 9 Feb 2026 20:24:39 -0800 Subject: [PATCH] added several comments with Valgrind information on memory leaks --- lib/App/common/SQLite_dataBinder.cpp | 16 ++ lib/App/common/hardwareManager.cpp | 35 +++ lib/App/common/kernelModuleEmbedVideo.cpp | 291 ++++++++++++---------- lib/alg/generic/md5.cpp | 18 ++ lib/components/base/basicPosition.cpp | 21 +- lib/data/media/video/videoAVLIBSource.cpp | 142 +++++++---- 6 files changed, 327 insertions(+), 196 deletions(-) diff --git a/lib/App/common/SQLite_dataBinder.cpp b/lib/App/common/SQLite_dataBinder.cpp index 45407f39..39ed9d19 100644 --- a/lib/App/common/SQLite_dataBinder.cpp +++ b/lib/App/common/SQLite_dataBinder.cpp @@ -2950,6 +2950,22 @@ uint32_t sqliteDBC::getResourceID( uint32_t NodeID, uint8_t type, uint32_t auxID return RetVal; }; DBC_SITE_DATA *sqliteDBC::getSiteData( uint32_t ID ){ + + /** @todo Valgrind is reporting an important memory leak in this method. + * See these details: + * + * ~~~~ + ==00:00:04:04.218 26021== 28,304 bytes in 122 blocks are definitely lost in loss record 3,966 of 3,972 + ==00:00:04:04.218 26021== at 0x483877F: malloc (vg_replace_malloc.c:307) + ==00:00:04:04.218 26021== by 0x23452A: sqliteDBC::getSiteData(unsigned int) (SQLite_dataBinder.cpp:2981) + ==00:00:04:04.218 26021== by 0x1DA681: mojoKernel::validateReports() (mojoKernel.cpp:1347) + ==00:00:04:04.218 26021== by 0x1D7D16: mojoKernel::m_fThreadProc() (mojoKernel.cpp:511) + ==00:00:04:04.218 26021== by 0x131B54: basicThread::m_fThreadEntryPoint(void*) (basicThread.cpp:62) + ==00:00:04:04.218 26021== by 0x49B7EA6: start_thread (pthread_create.c:477) + ==00:00:04:04.218 26021== by 0x7874ADE: clone (clone.S:95) + * ~~~~ + */ + DBC_SITE_DATA * tVal = NULL; if( m_bStoIsConnected ){ char tQBuf[CTEXT]; diff --git a/lib/App/common/hardwareManager.cpp b/lib/App/common/hardwareManager.cpp index d4d053d5..cb9ea20b 100644 --- a/lib/App/common/hardwareManager.cpp +++ b/lib/App/common/hardwareManager.cpp @@ -215,6 +215,41 @@ void hardwareManager::unloadResources( void ){ }; void hardwareManager::loadResources( void ){ + + /** @todo Valgrind is showing several memory leaks from this function. + * + * ~~~~ + ==00:00:04:04.207 26021== 513 (480 direct, 33 indirect) bytes in 1 blocks are definitely lost in loss record 3,863 of 3,972 + ==00:00:04:04.207 26021== at 0x4838DEF: operator new(unsigned long) (vg_replace_malloc.c:342) + ==00:00:04:04.207 26021== by 0x16D0EF: hardwareManager::loadResources() (hardwareManager.cpp:318) + ==00:00:04:04.207 26021== by 0x16C9CE: hardwareManager::hardwareManager(bool) (hardwareManager.cpp:174) + ==00:00:04:04.207 26021== by 0x16C470: hardwareManager::getInstance(bool) (hardwareManager.cpp:55) + ==00:00:04:04.207 26021== by 0x1D6E89: mojoKernel::create() (mojoKernel.cpp:264) + ==00:00:04:04.207 26021== by 0x1D5C60: main (mojoBackend.cpp:476) + ==00:00:04:04.207 26021== by 0x779CD79: __libc_start_main (libc-start.c:308) + ==00:00:04:04.207 26021== by 0x124CF9: _start (in /home/stephane/src/argus/Projects/la_mojo/Debug86/mojo_d) + ==00:00:04:04.207 26021== by 0x1FFF000497: ??? + ==00:00:04:04.207 26021== by 0x1B: ??? + * ~~~~ + * + * And: + * + * ~~~~ + ==00:00:04:04.198 26021== 240 bytes in 3 blocks are definitely lost in loss record 3,796 of 3,972 + ==00:00:04:04.198 26021== at 0x483877F: malloc (vg_replace_malloc.c:307) + ==00:00:04:04.198 26021== by 0x233EAA: sqliteDBC::getResourceData(unsigned int) (SQLite_dataBinder.cpp:2897) + ==00:00:04:04.198 26021== by 0x16CD43: hardwareManager::loadResources() (hardwareManager.cpp:260) + ==00:00:04:04.198 26021== by 0x16C9CE: hardwareManager::hardwareManager(bool) (hardwareManager.cpp:174) + ==00:00:04:04.198 26021== by 0x16C470: hardwareManager::getInstance(bool) (hardwareManager.cpp:55) + ==00:00:04:04.198 26021== by 0x1D6E89: mojoKernel::create() (mojoKernel.cpp:264) + ==00:00:04:04.198 26021== by 0x1D5C60: main (mojoBackend.cpp:476) + ==00:00:04:04.198 26021== by 0x779CD79: __libc_start_main (libc-start.c:308) + ==00:00:04:04.198 26021== by 0x124CF9: _start (in /home/stephane/src/argus/Projects/la_mojo/Debug86/mojo_d) + ==00:00:04:04.198 26021== by 0x1FFF000497: ??? + ==00:00:04:04.198 26021== by 0x1B: ??? + * ~~~~ + */ + if( m_pDBC == NULL ) return; DBC_INT_LIST *tVal; tVal = m_pDBC->listResources( );//load whole site resources diff --git a/lib/App/common/kernelModuleEmbedVideo.cpp b/lib/App/common/kernelModuleEmbedVideo.cpp index 09e670be..14a2faea 100644 --- a/lib/App/common/kernelModuleEmbedVideo.cpp +++ b/lib/App/common/kernelModuleEmbedVideo.cpp @@ -147,7 +147,7 @@ kernelModuleEmbedVideo::~kernelModuleEmbedVideo(){ //Sanity check LOG("Sanity check in Destructor!"); - waitThreadAEnd( true ); + waitThreadAEnd( true ); if( m_vHandlersPool.size() ) { // Kill-Wait Started Probes #ifdef DEBUG char tB[200]; @@ -177,7 +177,7 @@ kernelModuleEmbedVideo::~kernelModuleEmbedVideo(){ LOG("No More Viewers Left"); #endif - + #ifdef DEBUG_EXTRA LOG("Deleting CAPS"); #endif @@ -209,7 +209,7 @@ static const char * ht_head = "HTTP/1.1 200 OK\r\n" "Pragma: no-cache\r\n" "Expires: 0\r\n" "MIME-version: 1.0\r\n" - "Connection: close\r\n" + "Connection: close\r\n" //"Keep-Alive: timeout=5, max=1\r\n" //"Connection: Keep-Alive\r\n" //"Content-Type: video/mp4\r\n" @@ -245,7 +245,7 @@ uint8_t kernelModuleEmbedVideo::getMediaMode( void ){ }; void *kernelModuleEmbedVideo::webClientProc( void *ptr ){ - + WEB_CLIENT_CTX * CTX = (WEB_CLIENT_CTX *) ptr; kernelModuleEmbedVideo * MODULE = CTX->ModulePtr; @@ -274,7 +274,7 @@ void *kernelModuleEmbedVideo::webClientProc( void *ptr ){ pfd->fd = CTX->m_iSocketFID; pfd->events = POLLIN | POLLHUP; - + while( CTX->bValid && w ) { if( !CTX->initDone ){ int RetVal; @@ -332,7 +332,7 @@ void *kernelModuleEmbedVideo::webClientProc( void *ptr ){ if( strncmp( cGetURI, "/video_feed", 11 ) == 0 ) { uint32_t tStreamID = 0; CSTR tP; -#ifdef HAVE_SMAL_PREVIEW_STREAMS +#ifdef HAVE_SMAL_PREVIEW_STREAMS if( tP = strstr( cGetURI, "/preview" ) ) CTX->bPreviewMode = true; #endif if( tP = strstr( cGetURI, "?" ) ) { @@ -409,7 +409,7 @@ void *kernelModuleEmbedVideo::webClientProc( void *ptr ){ TLOG_ERROR("Pipe Communication Error[1]!"); CTX->bValid = false; continue; - }; + }; if( msgSize < FILESTREAMBUFFERSZ ) { retVal = read( CTX->m_iEncoderPipe[0], tBuf, msgSize ); } else { @@ -425,7 +425,7 @@ void *kernelModuleEmbedVideo::webClientProc( void *ptr ){ TLOG_ERROR("Pipe Communication Error[2]!"); CTX->bValid = false; continue; - }; + }; */ /**************/ CTX->ModulePtr->m_mEncodedProtector.lock(); @@ -517,7 +517,7 @@ void *kernelModuleEmbedVideo::webClientProc( void *ptr ){ close( CTX->m_iEncoderPipe[0] ); shutdown( CTX->m_iSocketFID, SHUT_RDWR); SLEEP( 3 ); - close( CTX->m_iSocketFID ); + close( CTX->m_iSocketFID ); CTX->bValid = false; #ifdef DEBUG_EXTRA TLOG("WEB Client Handler Ended!"); @@ -528,7 +528,7 @@ void *kernelModuleEmbedVideo::webClientProc( void *ptr ){ void *kernelModuleEmbedVideo::viewClientProc( void *ptr ){ - + WEB_CLIENT_CTX * CTX = (WEB_CLIENT_CTX *) ptr; kernelModuleEmbedVideo * MODULE = CTX->ModulePtr; @@ -571,7 +571,7 @@ void *kernelModuleEmbedVideo::viewClientProc( void *ptr ){ pfd->fd = CTX->m_iSocketFID; pfd->events = POLLIN | POLLHUP; - + while( CTX->bValid && w ) { if( !CTX->initDone ){ int RetVal; @@ -626,7 +626,7 @@ void *kernelModuleEmbedVideo::viewClientProc( void *ptr ){ #endif }; - if( ( strncmp( cGetURI, "/stream", 7 ) == 0 ) || ( strncmp( cGetURI, "/video_view", 11 ) == 0 ) ) { + if( ( strncmp( cGetURI, "/stream", 7 ) == 0 ) || ( strncmp( cGetURI, "/video_view", 11 ) == 0 ) ) { CSTR tP; if( tP = strstr( cGetURI, "?" ) ) { CSTR tB; @@ -771,7 +771,7 @@ void *kernelModuleEmbedVideo::viewClientProc( void *ptr ){ }; }; #ifdef DEBUG_EXTRA - TLOG("Shut Down Socket"); + TLOG("Shut Down Socket"); #endif shutdown( CTX->m_iSocketFID, SHUT_RDWR); #ifdef DEBUG_EXTRA @@ -894,13 +894,13 @@ void kernelModuleEmbedVideo::m_fThreadAProc( void ){ close( (*idx)->CTX->m_iEncoderPipe[1] ); free( (*idx)->CTX ); free( (*idx) ); - m_vHandlersPool.erase(idx); + m_vHandlersPool.erase(idx); #ifdef DEBUG_EXTRA LOG("Web Handler Ripped!"); #endif } else idx++; - }; - }; + }; + }; m_mWebHandlersProtector.unlock(); // validate active streams ? @@ -1018,8 +1018,8 @@ void kernelModuleEmbedVideo::m_fThreadBProc( void ){ #endif } else idx++; }; - - }; + + }; m_mViewHandlersProtector.unlock(); // validate active streams ? @@ -1068,8 +1068,8 @@ bool kernelModuleEmbedVideo::startService(){ cv::split( T, layers); // seperate channels cv::Mat rgb[3] = { layers[0], layers[1], layers[2] }; mask = layers[3]; // png's alpha channel used as mask - cv::merge( rgb, 3, T ); // put together the RGB channels, now transp insn't transparent - + cv::merge( rgb, 3, T ); // put together the RGB channels, now transp insn't transparent + cv::resize( T, m_mLogoPic, cv::Size( m_sEmbedVideoData.logo_w, m_sEmbedVideoData.logo_h ), cv::INTER_CUBIC ); cv::resize( mask, m_mLogoMask, cv::Size( m_sEmbedVideoData.logo_w, m_sEmbedVideoData.logo_h ), cv::INTER_CUBIC ); @@ -1210,7 +1210,7 @@ bool kernelModuleEmbedVideo::stopService( bool force ){ m_bEnabled = false; //Stop Conveyor m_bDetached = uninit(); -#ifdef DEBUG_EXTRA +#ifdef DEBUG_EXTRA LOG("StopService!"); #endif @@ -1230,7 +1230,7 @@ bool kernelModuleEmbedVideo::stopService( bool force ){ m_mStreamHandlersProtector.unlock(); if( m_vHandlersPool.size() ) { // Kill-Wait Started Probes -#ifdef DEBUG_EXTRA +#ifdef DEBUG_EXTRA char tB[200]; sprintf(tB, "Have to Wait Client Handlers[%d]!", m_vHandlersPool.size() ); LOG( tB ); @@ -1238,12 +1238,12 @@ bool kernelModuleEmbedVideo::stopService( bool force ){ #endif for( vectorHANDLERS::iterator index = m_vHandlersPool.begin(); index != m_vHandlersPool.end(); index++ ) { if( force ) { -#ifdef DEBUG_EXTRA +#ifdef DEBUG_EXTRA LOG("Force Client Handler to Stop!"); #endif pthread_cancel( (*index)->m_hThreadHandle ); } else { -#ifdef DEBUG_EXTRA +#ifdef DEBUG_EXTRA LOG("Waiting Client Handler to End!"); #endif pthread_join( (*index)->m_hThreadHandle, NULL ); @@ -1357,7 +1357,7 @@ bool kernelModuleEmbedVideo::validate(){ LOG("No Camera Defined/Enabled In the system!"); #endif }; - if ( RetVal ) { + if ( RetVal ) { DBC_INT_LIST tInvalidList; m_mStreamHandlersProtector.lock(); for( mapSTREAMHANDLERS::iterator idx = m_mapHANDLERS.begin(); idx != m_mapHANDLERS.end(); idx++ ) { @@ -1407,7 +1407,7 @@ bool kernelModuleEmbedVideo::validate(){ #endif }; }; - if ( RetVal ) { + if ( RetVal ) { DBC_INT_LIST tInvalidList; m_mStreamHandlersProtector.lock(); for( mapSTREAMHANDLERS::iterator idx = m_mapHANDLERS.begin(); idx != m_mapHANDLERS.end(); idx++ ) { @@ -1496,7 +1496,7 @@ bool kernelModuleEmbedVideo::dispatchEvent( EVENT_CONTAINER *Evt ){ #ifdef DEBUG_EXTRA LOG("Mutex Locked!"); #endif - mapSTREAMHANDLERS::iterator hnd = m_mapHANDLERS.find( sid ); + mapSTREAMHANDLERS::iterator hnd = m_mapHANDLERS.find( sid ); if( hnd != m_mapHANDLERS.end() ) #ifdef DEBUG_EXTRA { @@ -1575,8 +1575,8 @@ bool kernelModuleEmbedVideo::saveStreamPicture( DBC_SNAPSHOT_DATA *ptr ){ LOG("No apropriate Stream Found!"); #endif }; - }; - //*/ + }; + //*/ #ifdef DEBUG_EXTRA } else { LOG("No Pic Mode!"); @@ -1694,7 +1694,7 @@ bool kernelModuleEmbedVideo::registerStream( uint32_t streamID, uint8_t flip_mod try { m_mStreamHandlersProtector.lock(); streamHandler * tData = m_mapHANDLERS.at( streamID ); - //If SH allready exists + //If SH allready exists if( tData!= NULL ){ m_mStreamHandlersProtector.unlock(); return true; @@ -1780,7 +1780,7 @@ bool kernelModuleEmbedVideo::unregisterStream( uint32_t streamID ){ #endif -streamHandler::streamHandler( kernelModuleEmbedVideo *ptr, MS_WORK_MODE M, uint8_t flip_mode ): m_pMaster( ptr ), m_eWM( M ), basicMediaDestination() +streamHandler::streamHandler( kernelModuleEmbedVideo *ptr, MS_WORK_MODE M, uint8_t flip_mode ): m_pMaster( ptr ), m_eWM( M ), basicMediaDestination() #ifdef EVE_ENABLE_VIDEO ,basicThread() #endif @@ -1798,7 +1798,7 @@ streamHandler::streamHandler( kernelModuleEmbedVideo *ptr, MS_WORK_MODE M, uint8 m_bAFrameSkeepDividerCounter = 0; m_bAOutputFPS = VIDEO_OUTPUT_FPS; - m_bBFrameSkeepDivider = 1; + m_bBFrameSkeepDivider = 1; m_bBFrameSkeepDividerCounter = 0; m_bBOutputFPS = VIDEO_OUTPUT_FPS; #endif @@ -1807,7 +1807,7 @@ streamHandler::streamHandler( kernelModuleEmbedVideo *ptr, MS_WORK_MODE M, uint8 m_bInitialOutputFPS = m_bCurrentOutputFPS = VIDEO_OUTPUT_FPS; #endif -#ifdef EVE_ENABLE_VIDEO +#ifdef EVE_ENABLE_VIDEO #ifdef EVE_ENABLE_EASE_OUTPUT_FPS m_nAPreAlarmFrames = 0; m_nAPostAlarmFrames = 0; @@ -1832,7 +1832,7 @@ streamHandler::streamHandler( kernelModuleEmbedVideo *ptr, MS_WORK_MODE M, uint8 m_nSegAShiftFrames = 0; m_nSegBShiftFrames = 0; m_nSegASkippedFrames = m_nSegBSkippedFrames = 0; - + m_bActiveEncoderStream = 0; m_bSegAActive = false; m_bSegADelete = true; @@ -1882,7 +1882,7 @@ bool streamHandler::create( dataBinder *ptr, uint32_t stremID ){ m_sSourceDesc.mediaStreamId = stremID; - m_sSourceDesc.mediaSourceId = m_sStreamData.source_id; + m_sSourceDesc.mediaSourceId = m_sStreamData.source_id; uint32_t tNID = m_pDBC->getNodeIdByTypeAndAux( tCAM->type, m_sStreamData.source_id ); //ToDo: Check Camera Addition // Just Work around to handle Wrong tyoe 12 instead of 13 @@ -1890,7 +1890,7 @@ bool streamHandler::create( dataBinder *ptr, uint32_t stremID ){ tNID = m_pDBC->getNodeIdByTypeAndAux( 13, m_sStreamData.source_id ); }; if (tNID) { - CSTR tNAM = m_pDBC->getNodeName( tNID ); + CSTR tNAM = m_pDBC->getNodeName( tNID ); if ( tNAM!= NULL ) { strncpy(m_sSourceDesc.mediaName, tNAM, 127 ); m_sSourceDesc.mediaName[127] = (char)0; @@ -1925,7 +1925,7 @@ bool streamHandler::create( dataBinder *ptr, uint32_t stremID ){ #endif int tW = m_pMaster->getWidh(); int tH = m_pMaster->getHeight(); - int pix = -1; + int pix = -1; bool in_16_9 = (((m_sStreamData.width*100) / m_sStreamData.height ) > 140 ); bool out_16_9 = (((tW*100) / tH ) > 140 ); //if( tW > 0 ){ @@ -1942,7 +1942,7 @@ bool streamHandler::create( dataBinder *ptr, uint32_t stremID ){ //export PATH=/usr/sbin:$PATH if (strncmp( m_sStreamData.mrl_proto, "v4l2", 4) == 0) { sprintf( tMRL, m_sStreamData.mrl ); - pix = atoi( m_sStreamData.c_type ); + pix = atoi( m_sStreamData.c_type ); } else { sprintf( tMRL, "%s://%s:%s@%s:%d%s", m_sStreamData.mrl_proto, tCAM->username, tCAM->password, tCAM->ip, m_sStreamData.mrl_port, m_sStreamData.mrl ); }; @@ -1998,10 +1998,25 @@ bool streamHandler::pushFrame( AVFrame *Frame, void* src){ }; bool streamHandler::pushFrame( cv::Mat &Frame, void* src ){ + + /** @todo Valgrind is reporting an important memory leak in this method. The @p malloc() call on line 2568 (and others, such as 2576). + * The details are as follows: + * + * ~~~~ + = =00:00:04:04.219 26021== 8,805,208 (4,416 direct, 8,800,792 *indirect) bytes in 184 blocks are definitely lost in loss record 3,972 of 3,972 + ==00:00:04:04.219 26021== at 0x483877F: malloc (vg_replace_malloc.c:307) + ==00:00:04:04.219 26021== by 0x1B0FF9: streamHandler::pushFrame(cv::Mat&, void*) (kernelModuleEmbedVideo.cpp:2568) + ==00:00:04:04.219 26021== by 0x2490CB: videoAVLIBSource::m_fThreadProc() (videoAVLIBSource.cpp:874) + ==00:00:04:04.219 26021== by 0x131B54: basicThread::m_fThreadEntryPoint(void*) (basicThread.cpp:62) + ==00:00:04:04.219 26021== by 0x49B7EA6: start_thread (pthread_create.c:477) + ==00:00:04:04.219 26021== by 0x7874ADE: clone (clone.S:95) + * ~~~~ + */ + 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; @@ -2018,7 +2033,7 @@ bool streamHandler::pushFrame( cv::Mat &Frame, void* src ){ m_pMaster->m_sEmbedVideoData.width, CV_8UC3 ); - cv::rectangle( + cv::rectangle( m_pMaster->m_mapMATS[tMD->mediaStreamId], cv::Point( 0, 0 ), cv::Point( @@ -2030,12 +2045,12 @@ bool streamHandler::pushFrame( cv::Mat &Frame, void* src ){ ); }; -#ifdef EVE_ENABLE_EASE_OUTPUT_FPS +#ifdef EVE_ENABLE_EASE_OUTPUT_FPS SkeepW = !((m_bWebFrameSkeepDividerCounter % m_bWebFrameSkeepDivider) == 0 ); m_bWebFrameSkeepDividerCounter = ( ++m_bWebFrameSkeepDividerCounter ) % m_bWebFrameSkeepDivider; - #ifdef EVE_ENABLE_VIDEO - SkeepA = !((m_bAFrameSkeepDividerCounter % m_bAFrameSkeepDivider) == 0 ); - //m_bAFrameSkeepDividerCounter++; + #ifdef EVE_ENABLE_VIDEO + SkeepA = !((m_bAFrameSkeepDividerCounter % m_bAFrameSkeepDivider) == 0 ); + //m_bAFrameSkeepDividerCounter++; m_bAFrameSkeepDividerCounter = ( ++m_bAFrameSkeepDividerCounter ) % m_bAFrameSkeepDivider; SkeepB = !((m_bBFrameSkeepDividerCounter % m_bBFrameSkeepDivider) == 0 ); //m_bBFrameSkeepDividerCounter++; @@ -2168,20 +2183,20 @@ bool streamHandler::pushFrame( cv::Mat &Frame, void* src ){ //LOG("Q"); #endif -#ifdef EVE_ENABLE_EASE_OUTPUT_FPS - #ifdef EVE_ENABLE_VIDEO +#ifdef EVE_ENABLE_EASE_OUTPUT_FPS + #ifdef EVE_ENABLE_VIDEO if( SkeepW && SkeepA && SkeepB ) { m_pMaster->m_mPictureProtector.unlock(); return true; }; - #else + #else if( SkeepW ){ m_pMaster->m_mPictureProtector.unlock(); return true; }; #endif #endif - + if ( m_bCamMoveCounter > m_bEvtMarkerCounter ) { cv::rectangle( m_pMaster->m_mapMATS[tMD->mediaStreamId], @@ -2212,12 +2227,12 @@ bool streamHandler::pushFrame( cv::Mat &Frame, void* src ){ char tsb[64]; //if( strftime( tsb, sizeof(tsb), "%F %T GMT", tmp )!=0 ){ if( strftime( tsb, sizeof(tsb), "%F %T", tmp )!=0 ){ - + //sprintf( tBuffer, ">>%d>%d>%s>%s>", tMD->mediaSourceId, tMD->mediaStreamId, tMD->mediaName, tsb ); sprintf( tBuffer, ">>>%s>%s>", tMD->mediaName, tsb ); int baseline=0; cv::Size textSize = cv::getTextSize( tBuffer, - m_pMaster->m_sEmbedVideoData.label_font_face, + m_pMaster->m_sEmbedVideoData.label_font_face, m_pMaster->m_sEmbedVideoData.label_font_scale, m_pMaster->m_sEmbedVideoData.label_font_thickness, &baseline @@ -2237,12 +2252,12 @@ bool streamHandler::pushFrame( cv::Mat &Frame, void* src ){ cv::Scalar( 0, 0, 0 ), cv::FILLED ); - }; + }; cv::putText( m_pMaster->m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point( x, y ), - (cv::HersheyFonts) m_pMaster->m_sEmbedVideoData.label_font_face, + (cv::HersheyFonts) m_pMaster->m_sEmbedVideoData.label_font_face, m_pMaster->m_sEmbedVideoData.label_font_scale, cv::Scalar( 0, 255, 0 ), m_pMaster->m_sEmbedVideoData.label_font_thickness, @@ -2262,9 +2277,9 @@ bool streamHandler::pushFrame( cv::Mat &Frame, void* src ){ if( !m_pMaster->m_sEmbedVideoData.ts_transperant ) { if( m_pMaster->m_sEmbedVideoData.ts_font_face ) { shift_y = 15; - cv::rectangle( + cv::rectangle( m_pMaster->m_mapMATS[tMD->mediaStreamId], - cv::Point( + cv::Point( m_pMaster->m_sEmbedVideoData.ts_x, m_pMaster->m_sEmbedVideoData.ts_y ), @@ -2413,7 +2428,7 @@ bool streamHandler::pushFrame( cv::Mat &Frame, void* src ){ m_pMaster->m_mapPREVIEWS[tMD->mediaStreamId].clear(); cv::imencode( ".jpg", dst, m_pMaster->m_mapPREVIEWS[tMD->mediaStreamId], compression_params ); -#endif +#endif m_pMaster->m_mEncodedProtector.unlock(); #ifdef EVE_ENABLE_EASE_OUTPUT_FPS }; @@ -2426,12 +2441,12 @@ bool streamHandler::pushFrame( cv::Mat &Frame, void* src ){ return true; }; // encode Video Stream - + //m_nPreAlarmFrames //m_nPostAlarmFrames //m_nNoAlarmSegmentFrames //m_nSegmentLimitFrames - //m_nHardLimitFrames + //m_nHardLimitFrames if ( m_bSegAActive || m_bSegBActive ) { m_mFrameCounterProtector.lock(); @@ -2461,7 +2476,7 @@ bool streamHandler::pushFrame( cv::Mat &Frame, void* src ){ #endif swapActiveStreams(); //break; - }; + }; // } while ( 0 ); #else //do { @@ -2487,7 +2502,7 @@ bool streamHandler::pushFrame( cv::Mat &Frame, void* src ){ #endif swapActiveStreams(); //break; - }; + }; // } while ( 0 ); #endif// !EVE_ENABLE_EASE_OUTPUT_FPS }; @@ -2517,7 +2532,7 @@ bool streamHandler::pushFrame( cv::Mat &Frame, void* src ){ #endif swapActiveStreams(); // break; - }; + }; //} while ( 0 ); #else // !EVE_ENABLE_EASE_OUTPUT_FPS // do { @@ -2543,7 +2558,7 @@ bool streamHandler::pushFrame( cv::Mat &Frame, void* src ){ #endif swapActiveStreams(); // break; - }; + }; //} while ( 0 ); #endif // !EVE_ENABLE_EASE_OUTPUT_FPS }; @@ -2621,7 +2636,7 @@ void streamHandler::closeSegmentB( void ){ void streamHandler::closeAll(){ waitThreadEnd( true ); #ifdef OPENCV_VIDEO_OUTPUT - + if( m_pEncoderA ){ if ( m_pEncoderA->isOpened() ) { m_pEncoderA->release(); @@ -2724,7 +2739,7 @@ void streamHandler::closeAll(){ //if( m_pFormat != NULL ) { //av_free( m_pFormat ); //}; -#endif // OPENCV_VIDEO_OUTPUT +#endif // OPENCV_VIDEO_OUTPUT }; bool streamHandler::openSegmentA( void ){ @@ -2875,7 +2890,7 @@ bool streamHandler::openSegmentA( void ){ m_bSegAActive = true; m_bSegADelete = true; //m_mFrameCounterProtector.unlock(); - #endif // SEPARATED_VIDEO_ENCODERS + #endif // SEPARATED_VIDEO_ENCODERS #ifdef DEBUG_EXTRA LOG("Stream A Opened"); #endif @@ -2988,7 +3003,7 @@ bool streamHandler::openSegmentB( void ){ sprintf( tB, "CON ST:%llu DUR:%llu", m_pFormatCtxB->start_time, m_pFormatCtxB->duration ); LOG( tB ); #endif - + //if ( avio_open( &m_pFormatCtxB->pb, m_cSegNameB, AVIO_FLAG_WRITE ) < 0 ){ if ( avio_open( &m_pFormatCtxB->pb, m_sStreamSegmentInfo[1].scratchPath, AVIO_FLAG_WRITE ) < 0 ){ LOG_ERROR("Could not open output file."); @@ -3083,7 +3098,7 @@ bool streamHandler::initVideoOutput(){ m_pEncoderB->set( cv::VIDEOWRITER_PROP_QUALITY, 10.0 ); m_pEncoderB->set( cv::VIDEOWRITER_PROP_NSTRIPES, -1.0 ); - #else + #else if( !initLibAV() ) return false; m_pFormat = av_guess_format( VIDEO_OUTPUT_CONTAINER, "test." VIDEO_OUTPUT_CONTAINER, NULL ); @@ -3144,7 +3159,7 @@ bool streamHandler::initVideoOutput(){ LOG("Video Encoder Context B Allocated"); #endif }; - + m_pCodecACtx->codec_id = VIDEO_OUTPUT_CODEC; m_pCodecACtx->codec_type = AVMEDIA_TYPE_VIDEO; m_pCodecACtx->pix_fmt = VIDEO_OUTPUT_PIX_FMT; @@ -3168,12 +3183,12 @@ bool streamHandler::initVideoOutput(){ m_pCodecBCtx->time_base.den = m_sStreamData.fps; m_pCodecBCtx->framerate.num = m_sStreamData.fps; m_pCodecBCtx->framerate.den = 1; - + //https://pastebin.com/yG37YhWW //https://stackoverflow.com/questions/49276997/raw-h264-frames-in-mp4-container-using-libavcodec //G@ avcodec encode NALU mp4 - + #if (LIBAVCODEC_VERSION_MAJOR > 54) ////m_pCodecACtx->codec_tag = av_codec_get_tag( m_pFormatCtxA->oformat->codec_tag, VIDEO_OUTPUT_CODEC ); #endif @@ -3191,9 +3206,9 @@ bool streamHandler::initVideoOutput(){ #endif //Reference for AvFormatContext options : https://ffmpeg.org/doxygen/2.8/movenc_8c_source.html //Set format's privater options, to be passed to avformat_write_header() - + /* - + mp4 muxer AVOptions: -movflags E..... MOV muxer flags (default 0) rtphint E..... Add RTP hint tracks @@ -3220,9 +3235,9 @@ bool streamHandler::initVideoOutput(){ -frag_size E..... Maximum fragment size (from 0 to INT_MAX) (default 0) -ism_lookahead E..... Number of lookahead entries for ISM files (from 0 to INT_MAX) (default 0) -use_editlist E..... use edit list (from -1 to 1) (default -1) - -video_track_timescale E..... set timescale of all video tracks (from 0 to INT_MAX) (default 0) - - + -video_track_timescale E..... set timescale of all video tracks (from 0 to INT_MAX) (default 0) + + */ if( av_dict_set( &m_pFormatOpts, "movflags", "isml+faststart+frag_keyframe+empty_moov+omit_tfhd_offset", 0 ) < 0 ){ LOG_ERROR( "av_dict_set movflags!"); @@ -3250,7 +3265,7 @@ bool streamHandler::initVideoOutput(){ m_pCodecACtx->max_b_frames = 5; /// Can be used by a P-frame(predictive, partial frame) to help define a future frame in a compressed video. - /// [use 3–5 ref per P] + /// [use 3„1¤75 ref per P] m_pCodecACtx->refs = 3; /// Compression efficiency (slower -> better quality + higher cpu%) @@ -3259,8 +3274,8 @@ bool streamHandler::initVideoOutput(){ av_opt_set( m_pCodecACtx->priv_data, "preset", "ultrafast", 0); //av_opt_set( m_pCodecCtx->priv_data, "preset", "fast", 0 ); //av_opt_set( m_pCodecCtx->priv_data, "preset", "slow", 0 ); - - + + /// Compression rate (lower -> higher compression) compress to lower size, makes decoded image more noisy /// Range: [0; 51], sane range: [18; 26]. I used 35 as good compression/quality compromise. This option also critical for realtime encoding av_opt_set( m_pCodecACtx->priv_data, "crf", "32", 0); @@ -3287,9 +3302,9 @@ bool streamHandler::initVideoOutput(){ #endif //Reference for AvFormatContext options : https://ffmpeg.org/doxygen/2.8/movenc_8c_source.html //Set format's privater options, to be passed to avformat_write_header() - + /* - + mp4 muxer AVOptions: -movflags E..... MOV muxer flags (default 0) rtphint E..... Add RTP hint tracks @@ -3316,10 +3331,10 @@ bool streamHandler::initVideoOutput(){ -frag_size E..... Maximum fragment size (from 0 to INT_MAX) (default 0) -ism_lookahead E..... Number of lookahead entries for ISM files (from 0 to INT_MAX) (default 0) -use_editlist E..... use edit list (from -1 to 1) (default -1) - -video_track_timescale E..... set timescale of all video tracks (from 0 to INT_MAX) (default 0) - - - */ + -video_track_timescale E..... set timescale of all video tracks (from 0 to INT_MAX) (default 0) + + + */ //m_pCodecCtx->max_b_frames = 1; //m_pCodecCtx->level = 31; @@ -3330,7 +3345,7 @@ bool streamHandler::initVideoOutput(){ m_pCodecBCtx->max_b_frames = 5; /// Can be used by a P-frame(predictive, partial frame) to help define a future frame in a compressed video. - /// [use 3–5 ref per P] + /// [use 3„1¤75 ref per P] m_pCodecBCtx->refs = 3; /// Compression efficiency (slower -> better quality + higher cpu%) @@ -3339,8 +3354,8 @@ bool streamHandler::initVideoOutput(){ av_opt_set( m_pCodecBCtx->priv_data, "preset", "ultrafast", 0); //av_opt_set( m_pCodecCtx->priv_data, "preset", "fast", 0 ); //av_opt_set( m_pCodecCtx->priv_data, "preset", "slow", 0 ); - - + + /// Compression rate (lower -> higher compression) compress to lower size, makes decoded image more noisy /// Range: [0; 51], sane range: [18; 26]. I used 35 as good compression/quality compromise. This option also critical for realtime encoding av_opt_set( m_pCodecBCtx->priv_data, "crf", "32", 0); @@ -3360,11 +3375,11 @@ bool streamHandler::initVideoOutput(){ if( m_pFormat->flags & AVFMT_GLOBALHEADER ) m_pCodecBCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; }; - - - + + + const AVRational dst_fps = { m_sStreamData.fps, 1 }; - + #ifdef DEBUG_EXTRA char TB[129]; sprintf(TB, "TimeBaseA: num[%d]/den[%d]", m_pCodecACtx->time_base.num, m_pCodecACtx->time_base.den ); @@ -3375,16 +3390,16 @@ bool streamHandler::initVideoOutput(){ ////m_pVideoStrA->time_base = m_pCodecACtx->time_base; ////m_pVideoStrB->time_base = m_pCodecBCtx->time_base; - + //avcodec_get_context_defaults3( m_pVideoStrA->codec, m_pVideoCodec ); - + //m_pVideoStrA->codec->width = m_pMaster->m_sEmbedVideoData.width; //m_pVideoStrA->codec->height = m_pMaster->m_sEmbedVideoData.height; //m_pVideoStrA->codec->pix_fmt = VIDEO_OUTPUT_PIX_FMT; //m_pVideoStrA->codec->time_base = m_pVideoStrB->time_base = av_inv_q(dst_fps); - //// m_pVideoStrA->r_frame_rate = m_pVideoStrA->avg_frame_rate = - ////dst_fps; + //// m_pVideoStrA->r_frame_rate = m_pVideoStrA->avg_frame_rate = + ////dst_fps; //avcodec_get_context_defaults3( m_pVideoStrB->codec, m_pVideoCodec ); @@ -3392,20 +3407,20 @@ bool streamHandler::initVideoOutput(){ //m_pVideoStrB->codec->height = m_pMaster->m_sEmbedVideoData.height; //m_pVideoStrB->codec->pix_fmt = VIDEO_OUTPUT_PIX_FMT; //m_pVideoStrB->codec->time_base = m_pVideoStrB->time_base = av_inv_q(dst_fps); - //// m_pVideoStrB->r_frame_rate = m_pVideoStrB->avg_frame_rate = - ////dst_fps; + //// m_pVideoStrB->r_frame_rate = m_pVideoStrB->avg_frame_rate = + ////dst_fps; //if ( m_pFormatCtxA->oformat->flags & AVFMT_GLOBALHEADER ) m_pVideoStrA->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; //if ( m_pFormatCtxB->oformat->flags & AVFMT_GLOBALHEADER ) m_pVideoStrB->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; - //// avcodec_parameters_from_context( m_pVideoStrA->codecpar, - ////m_pCodecACtx ); + //// avcodec_parameters_from_context( m_pVideoStrA->codecpar, + ////m_pCodecACtx ); //m_pVideoStrA->codecpar->format = VIDEO_OUTPUT_PIX_FMT; //m_pVideoStrA->codecpar->extradata = m_pCodecCtx->extradata; //m_pVideoStrA->codecpar->extradata_size = m_pCodecCtx->extradata_size; - //// avcodec_parameters_from_context( m_pVideoStrB->codecpar, - ////m_pCodecBCtx ); + //// avcodec_parameters_from_context( m_pVideoStrB->codecpar, + ////m_pCodecBCtx ); //m_pVideoStrB->codecpar->format = VIDEO_OUTPUT_PIX_FMT; //m_pVideoStrB->codecpar->extradata = m_pCodecCtx->extradata; //m_pVideoStrB->codecpar->extradata_size = m_pCodecCtx->extradata_size; @@ -3420,7 +3435,7 @@ bool streamHandler::initVideoOutput(){ LOG("output codec context is opened"); #endif }; - + #ifdef DEBUG_EXTRA } else { LOG("output codec context is already opened"); @@ -3437,7 +3452,7 @@ bool streamHandler::initVideoOutput(){ LOG("output codec context is opened"); #endif }; - + #ifdef DEBUG_EXTRA } else { LOG("output codec context is already opened"); @@ -3504,7 +3519,7 @@ bool streamHandler::initVideoOutput(){ m_pVideoStrB = avformat_new_stream( m_pFormatCtxB, m_pVideoCodec ); if ( m_pVideoStrB == NULL){ LOG_ERROR("VideoStream B Not Created!"); - + avcodec_free_context( &m_pCodecCtx ); av_free( m_pCodecCtx ); av_free( m_pVideoCodec ); @@ -3533,12 +3548,12 @@ bool streamHandler::initVideoOutput(){ m_pCodecCtx->time_base.den = m_sStreamData.fps; m_pCodecCtx->framerate.num = m_sStreamData.fps; m_pCodecCtx->framerate.den = 1; - + //https://pastebin.com/yG37YhWW //https://stackoverflow.com/questions/49276997/raw-h264-frames-in-mp4-container-using-libavcodec //G@ avcodec encode NALU mp4 - + #if (LIBAVCODEC_VERSION_MAJOR > 54) m_pCodecCtx->codec_tag = av_codec_get_tag( m_pFormatCtxA->oformat->codec_tag, VIDEO_OUTPUT_CODEC ); #endif @@ -3552,9 +3567,9 @@ bool streamHandler::initVideoOutput(){ #endif //Reference for AvFormatContext options : https://ffmpeg.org/doxygen/2.8/movenc_8c_source.html //Set format's privater options, to be passed to avformat_write_header() - + /* - + mp4 muxer AVOptions: -movflags E..... MOV muxer flags (default 0) rtphint E..... Add RTP hint tracks @@ -3581,9 +3596,9 @@ bool streamHandler::initVideoOutput(){ -frag_size E..... Maximum fragment size (from 0 to INT_MAX) (default 0) -ism_lookahead E..... Number of lookahead entries for ISM files (from 0 to INT_MAX) (default 0) -use_editlist E..... use edit list (from -1 to 1) (default -1) - -video_track_timescale E..... set timescale of all video tracks (from 0 to INT_MAX) (default 0) - - + -video_track_timescale E..... set timescale of all video tracks (from 0 to INT_MAX) (default 0) + + */ if( av_dict_set( &m_pFormatOpts, "movflags", "isml+faststart+frag_keyframe+empty_moov+omit_tfhd_offset", 0 ) < 0 ){ LOG_ERROR( "av_dict_set movflags!"); @@ -3611,7 +3626,7 @@ bool streamHandler::initVideoOutput(){ m_pCodecCtx->max_b_frames = 5; /// Can be used by a P-frame(predictive, partial frame) to help define a future frame in a compressed video. - /// [use 3–5 ref per P] + /// [use 3„1¤75 ref per P] m_pCodecCtx->refs = 3; /// Compression efficiency (slower -> better quality + higher cpu%) @@ -3620,8 +3635,8 @@ bool streamHandler::initVideoOutput(){ av_opt_set( m_pCodecCtx->priv_data, "preset", "ultrafast", 0); //av_opt_set( m_pCodecCtx->priv_data, "preset", "fast", 0 ); //av_opt_set( m_pCodecCtx->priv_data, "preset", "slow", 0 ); - - + + /// Compression rate (lower -> higher compression) compress to lower size, makes decoded image more noisy /// Range: [0; 51], sane range: [18; 26]. I used 35 as good compression/quality compromise. This option also critical for realtime encoding av_opt_set( m_pCodecCtx->priv_data, "crf", "32", 0); @@ -3641,11 +3656,11 @@ bool streamHandler::initVideoOutput(){ if( m_pFormat->flags & AVFMT_GLOBALHEADER ) m_pCodecCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; }; - - - + + + const AVRational dst_fps = { m_sStreamData.fps, 1 }; - + #ifdef DEBUG_EXTRA char TB[129]; sprintf(TB, "TimeBase: num[%d]/den[%d]", m_pCodecCtx->time_base.num, m_pCodecCtx->time_base.den ); @@ -3654,10 +3669,10 @@ bool streamHandler::initVideoOutput(){ m_pVideoStrA->time_base = m_pCodecCtx->time_base; m_pVideoStrB->time_base = m_pCodecCtx->time_base; - + //avcodec_get_context_defaults3( m_pVideoStrA->codec, m_pVideoCodec ); - + //m_pVideoStrA->codec->width = m_pMaster->m_sEmbedVideoData.width; //m_pVideoStrA->codec->height = m_pMaster->m_sEmbedVideoData.height; //m_pVideoStrA->codec->pix_fmt = VIDEO_OUTPUT_PIX_FMT; @@ -3695,7 +3710,7 @@ bool streamHandler::initVideoOutput(){ LOG("output codec context is opened"); #endif }; - + #ifdef DEBUG_EXTRA } else { LOG("output codec context is already opened"); @@ -3705,10 +3720,10 @@ bool streamHandler::initVideoOutput(){ m_pConvertCtx = sws_getContext( m_pMaster->m_sEmbedVideoData.width, m_pMaster->m_sEmbedVideoData.height, - AV_PIX_FMT_BGR24, + AV_PIX_FMT_BGR24, m_pMaster->m_sEmbedVideoData.width, - m_pMaster->m_sEmbedVideoData.height, - VIDEO_OUTPUT_PIX_FMT, + m_pMaster->m_sEmbedVideoData.height, + VIDEO_OUTPUT_PIX_FMT, SWS_FAST_BILINEAR, NULL, NULL, @@ -3739,7 +3754,7 @@ bool streamHandler::initVideoOutput(){ //encoding thread -void streamHandler::m_fThreadProc( void ){ +void streamHandler::m_fThreadProc( void ){ char tB[128]; //#ifdef EVE_ENABLE_EASE_OUTPUT_FPS size_t nQueueSize; @@ -3772,7 +3787,7 @@ void streamHandler::m_fThreadProc( void ){ nQueueSize = m_qEncodingQueue.size(); m_mEncodingQueueProtector.unlock(); -#ifdef EVE_ENABLE_EASE_OUTPUT_FPS +#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 ){ @@ -3848,7 +3863,7 @@ void streamHandler::m_fThreadProc( void ){ cv::Mat image( tData->rows, tData->cols, CV_8UC3 ); memcpy( image.data, tData->data, tData->size ); free( tData->data ); - free( tData ); + free( tData ); #ifdef EVE_ENABLE_EASE_OUTPUT_FPS if( !bSkeepA ) #endif @@ -3873,10 +3888,10 @@ void streamHandler::m_fThreadProc( void ){ //m_mEncodingQueueProtector.unlock(); sws_scale( m_pConvertCtx, tData->data, tData->linesize, 0, tData->rows, m_pAVFrame->data, m_pAVFrame->linesize ); free( tData->data[0] ); - free( tData ); + free( tData ); /* - - + + AV_PICTURE_TYPE_NONE Undefined. AV_PICTURE_TYPE_I Intra. AV_PICTURE_TYPE_P Predicted. @@ -3885,8 +3900,8 @@ void streamHandler::m_fThreadProc( void ){ AV_PICTURE_TYPE_SI Switching Intra. AV_PICTURE_TYPE_SP Switching Predicted. AV_PICTURE_TYPE_BI BI type. - - + + */ if ( ( m_nGlobalFrameCounter % m_sStreamData.fps ) == 0 ) { m_pAVFrame->key_frame = 1; @@ -3907,8 +3922,8 @@ void streamHandler::m_fThreadProc( void ){ m_mFrameCounterProtector.lock(); m_nGlobalFrameCounter++; m_mFrameCounterProtector.unlock(); - } else m_mEncodingQueueProtector.unlock(); - }; + } else m_mEncodingQueueProtector.unlock(); + }; // Test Commands! m_mCurrentOperationProtector.lock(); switch ( m_bCOP ) { @@ -3917,7 +3932,7 @@ void streamHandler::m_fThreadProc( void ){ LOG("Actual Closing Video Stream A!"); LOG( m_sStreamSegmentInfo[0].scratchPath ); #endif - m_bSegAActive = false; + m_bSegAActive = false; if ( !m_bSegADelete ) { #ifdef DIRECT_MJPEG_COMPOSING if ( m_pOutputFD[0] ) { @@ -4022,7 +4037,7 @@ void streamHandler::m_fThreadProc( void ){ } else LOG_ERROR( "Event Creation failure!"); #ifdef DEBUG_EXTRA LOG("Stream B is Saved"); - + #endif } else { #ifdef DIRECT_MJPEG_COMPOSING @@ -4192,7 +4207,7 @@ void streamHandler::swapActiveStreams( void ){ if ( m_bSegADelete ) closeSegmentA(); } else { if ( m_bSegBDelete ) closeSegmentB(); - }; + }; //m_mFrameCounterProtector.unlock(); }; @@ -4207,13 +4222,13 @@ bool streamHandler::triggerEvent( uint32_t eid, uint32_t &dbid, uint32_t &frame #ifdef EVE_ENABLE_VIDEO m_mFrameCounterProtector.lock(); // To Mark Events Frames - m_bEvtMarkerCounter = 255; + m_bEvtMarkerCounter = 255; PF_TIMESTAMP ts; getPFTS( &ts ); /* if ( m_nVideoRegisteredDBID == 0 ) { LOG("New Event!"); - + if ( !m_bActiveEncoderStream ) { // Stream A is Active m_nVideoRegisteredDBID = m_pDBC->addVideoRecord( m_sStreamData.id, diff --git a/lib/alg/generic/md5.cpp b/lib/alg/generic/md5.cpp index 164e7ea9..ed68f131 100644 --- a/lib/alg/generic/md5.cpp +++ b/lib/alg/generic/md5.cpp @@ -81,6 +81,24 @@ char* PrintMD5(u_char md5Digest[16]) strncat(chBuffer, chEach, sizeof(chEach)); }; #ifdef __linux__ + /** @todo Valgrind tells us this @p strdup() called from @ref videoAVLIBSource is never freed. + * + * ~~~~ + = =00:00:04:04.006 26021== 33 bytes in 1 blocks are definitely* lost in loss record 2,412 of 3,972 + ==00:00:04:04.006 26021== at 0x483877F: malloc (vg_replace_malloc.c:307) + ==00:00:04:04.006 26021== by 0x7802C3A: strdup (strdup.c:42) [now line 102 since I've inserted this comment] + ==00:00:04:04.006 26021== by 0x1D20BD: PrintMD5(unsigned char*) (md5.cpp:84) + ==00:00:04:04.006 26021== by 0x1D212A: MD5String(char*) (md5.cpp:100) + ==00:00:04:04.006 26021== by 0x2476EA: videoAVLIBSource::_open(char*, bool, float, int, int, int, int, int) (videoAVLIBSource.cpp:388) + ==00:00:04:04.006 26021== by 0x1AE949: streamHandler::create(dataBinder*, unsigned int) (kernelModuleEmbedVideo.cpp:1949) + ==00:00:04:04.006 26021== by 0x1ADA24: kernelModuleEmbedVideo::registerStream(unsigned int, unsigned char) (kernelModuleEmbedVideo.cpp:1731) + ==00:00:04:04.006 26021== by 0x1AC2A9: kernelModuleEmbedVideo::validate() (kernelModuleEmbedVideo.cpp:1347) + ==00:00:04:04.006 26021== by 0x1BB1E7: kernelModuleFactory::m_fThreadProc() (kernelModuleFactory.cpp:397) + ==00:00:04:04.006 26021== by 0x131B54: basicThread::m_fThreadEntryPoint(void*) (basicThread.cpp:62) + ==00:00:04:04.006 26021== by 0x49B7EA6: start_thread (pthread_create.c:477) + ==00:00:04:04.006 26021== by 0x7874ADE: clone (clone.S:95) + * ~~~~ + */ return strdup(chBuffer); #else return _strdup(chBuffer); diff --git a/lib/components/base/basicPosition.cpp b/lib/components/base/basicPosition.cpp index ed5badbb..f4eb165a 100644 --- a/lib/components/base/basicPosition.cpp +++ b/lib/components/base/basicPosition.cpp @@ -205,6 +205,21 @@ void basicPosition::setPositionDeg(float Lat, float Lon, float Alt, float h_lat, updateMatrix(); }; void basicPosition::updateMatrix( void ){ + + /** @todo Valgrind is showing several memory leaks from this function. + * + * ~~~~ + ==00:00:04:04.173 26021== 176 bytes in 2 blocks are definitely lost in loss record 3,541 of 3,972 + ==00:00:04:04.173 26021== at 0x4838DEF: operator new(unsigned long) (vg_replace_malloc.c:342) + ==00:00:04:04.173 26021== by 0x130F5C: basicPosition::updateMatrix() (basicPosition.cpp:232) + ==00:00:04:04.173 26021== by 0x167C58: deviceNodeSensor::reloadDeviceNodeFromDB() (deviceNodeSensor.cpp:298) + ==00:00:04:04.173 26021== by 0x169DE2: deviceNodeSensor::m_fThreadProc() (deviceNodeSensor.cpp:1075) + ==00:00:04:04.173 26021== by 0x131B54: basicThread::m_fThreadEntryPoint(void*) (basicThread.cpp:62) + ==00:00:04:04.173 26021== by 0x49B7EA6: start_thread (pthread_create.c:477) + ==00:00:04:04.173 26021== by 0x7874ADE: clone (clone.S:95) + * ~~~~ + */ + //Tait-Bryan angles //X1Y2Z3 // C2C3 -C2S3 S2 @@ -217,7 +232,7 @@ void basicPosition::updateMatrix( void ){ m_pTransform = new transform_3( x, y, z, rot_x, rot_y, rot_z ); /* float X, Z, Y; - + X = rot_x; Y = rot_y; Z = rot_z; @@ -229,7 +244,7 @@ void basicPosition::updateMatrix( void ){ m_sMatrix.AB = -sinf(Z); m_sMatrix.AC = sinf(Y); m_sMatrix.AD = x; - + //m_sMatrix.BA = sinf(P)*cosf(Y) + cosf(P)*cosf(R)*sinf(Y); //m_sMatrix.BB = -sinf(P)*sinf(Y) + cosf(P)*cosf(R)*cosf(Y); //m_sMatrix.BC = -cosf(P)*sinf(R); @@ -237,7 +252,7 @@ void basicPosition::updateMatrix( void ){ m_sMatrix.BB = cosf(Z)*cosf(X); m_sMatrix.BC = -sinf(X); m_sMatrix.BD = y; - + //m_sMatrix.CA = sinf(R)*sinf(Y); //m_sMatrix.CB = sinf(R)*cosf(Y); //m_sMatrix.CC = cosf(R); diff --git a/lib/data/media/video/videoAVLIBSource.cpp b/lib/data/media/video/videoAVLIBSource.cpp index f9d1e373..bc031957 100644 --- a/lib/data/media/video/videoAVLIBSource.cpp +++ b/lib/data/media/video/videoAVLIBSource.cpp @@ -12,13 +12,13 @@ #define LOG_ERROR( X ) m_pLog->Log( "LIBAV_SRC", this, _LOG_ERROR, X ); #endif -static int interrupt_cb( void *ctx ){ +static int interrupt_cb( void *ctx ){ basicLogCollection::getInstance()->Log( "LibAV_CB", NULL, "INTERUPT!" ); - // do something + // do something return 0; -} +} -static const AVIOInterruptCB int_cb = { interrupt_cb, NULL }; +static const AVIOInterruptCB int_cb = { interrupt_cb, NULL }; //https://ffmpeg.org/doxygen/3.4/ffplay_8c_source.html#l02732 videoAVLIBSource::videoAVLIBSource( void *opaque ): basicMediaSource(), basicThread() { @@ -40,11 +40,11 @@ videoAVLIBSource::videoAVLIBSource( void *opaque ): basicMediaSource(), basicThr return; }; m_eMediaStatus = m_pVideoState->m_bStatus = MS_UNDEFINED; - + m_pVideoState->m_iVideoStreamID = -1; #ifndef _NOAUDIO_ m_pVideoState->m_iAudioStreamID = -1; -#endif +#endif m_pVideoState->m_bStatus = MS_INIT; }; @@ -69,7 +69,7 @@ videoAVLIBSource::videoAVLIBSource( char *Source, void *opaque ) : basicMediaSou m_eMediaStatus = m_pVideoState->m_bStatus = MS_UNDEFINED; m_pVideoState->m_pFormatCtx = avformat_alloc_context(); - + if (m_pVideoState->m_pFormatCtx == NULL){ LOG_ERROR("Video Format Context Memory Allocation Error"); return; @@ -77,9 +77,9 @@ videoAVLIBSource::videoAVLIBSource( char *Source, void *opaque ) : basicMediaSou m_pVideoState->m_iVideoStreamID = -1; #ifndef _NOAUDIO_ m_pVideoState->m_iAudioStreamID = -1; -#endif +#endif m_pVideoState->m_bStatus = MS_INIT; - + _open( Source ); }; @@ -93,7 +93,7 @@ videoAVLIBSource::~videoAVLIBSource(){ }; bool videoAVLIBSource::setOutputSize( int Width, int Height ){ - if( m_pVideoState ){ + if( m_pVideoState ){ if( m_pVideoState->m_bStatus == MS_INIT ) { if( Width && Height ) { m_bSizeIsAutomatic = false; @@ -107,7 +107,7 @@ bool videoAVLIBSource::setOutputSize( int Width, int Height ){ }; bool videoAVLIBSource::setProportionalByWidth(int Width){ - if( m_pVideoState ){ + if( m_pVideoState ){ if( m_pVideoState->m_bStatus == MS_INIT ) { if( Width > 0 ) { m_bSizeIsAutomatic = true; @@ -120,7 +120,7 @@ bool videoAVLIBSource::setProportionalByWidth(int Width){ }; bool videoAVLIBSource::setProportionalByHeight(int Height){ - if( m_pVideoState ){ + if( m_pVideoState ){ if( m_pVideoState->m_bStatus == MS_INIT ) { if( Height > 0 ) { m_bSizeIsAutomatic = true; @@ -157,7 +157,7 @@ bool videoAVLIBSource::_close(void){ m_pVideoState->m_iVideoStreamID = -1; }; - if( m_pVideoState->m_bStatus > MS_INIT ){ + if( m_pVideoState->m_bStatus > MS_INIT ){ #if ( LIBAVCODEC_VERSION_MAJOR < 58 ) // && ( LIBAVCODEC_VERSION_MINOR < 50 ) #ifndef _NOAUDIO_ @@ -181,7 +181,7 @@ bool videoAVLIBSource::_close(void){ avcodec_close(m_pVideoState->m_pCodecCtx); avcodec_free_context(&m_pVideoState->m_pCodecCtx); }; -#endif +#endif m_eMediaStatus = m_pVideoState->m_bStatus = MS_INIT; }; @@ -217,7 +217,7 @@ bool videoAVLIBSource::_restart( void ){ switch( m_bSrcType ){ case AVLIB_SOURCE_DDSHOW:{ AVInputFormat *iformat = av_find_input_format("dshow"); - if( ( RetVal = avformat_open_input(&m_pVideoState->m_pFormatCtx, m_pVideoState->m_pFileName, iformat, &m_pVideoState->m_pFormatOpts) ) != 0 ){ + if( ( RetVal = avformat_open_input(&m_pVideoState->m_pFormatCtx, m_pVideoState->m_pFileName, iformat, &m_pVideoState->m_pFormatOpts) ) != 0 ){ char tB[1024]; //av_free( iformat ); char tBuffer[1024]; @@ -248,7 +248,7 @@ bool videoAVLIBSource::_restart( void ){ LOG("DataStream Opened"); #endif m_eMediaStatus = m_pVideoState->m_bStatus = MS_OPENED; - + if( avformat_find_stream_info( m_pVideoState->m_pFormatCtx, NULL )<0 ){ char tB[1024]; sprintf( tB, "Couldn't find stream information: %s", m_pVideoState->m_pFileName ); @@ -257,7 +257,7 @@ bool videoAVLIBSource::_restart( void ){ }; #if ( LIBAVCODEC_VERSION_MAJOR < 58 ) // && ( LIBAVCODEC_VERSION_MINOR < 50 ) - for( unsigned int i=0; i < m_pVideoState->m_pFormatCtx->nb_streams; i++ ){ + for( unsigned int i=0; i < m_pVideoState->m_pFormatCtx->nb_streams; i++ ){ //if( m_pVideoState->m_pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ){ if( m_pVideoState->m_pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO ){ LOG( "VIDEO stream detected." ); @@ -324,17 +324,17 @@ bool videoAVLIBSource::_restart( void ){ }; #endif - + if( m_pVideoState->m_pVideoCodec == NULL ){ char tB[1024]; //sprintf(Buffer, "Codec [%d] not found for %s", m_pVideoState->m_pCodecCtx->codec_id, m_pVideoState->m_pFileName); sprintf( tB, "Codec [%d] not found for %s", m_pVideoState->m_pCodecCtx->codec_id, m_pVideoState->m_pFileName ); LOG_ERROR( tB ); return false; - }; + }; /* - End-user application may configure the number of threads to utilize (via AVCodecContext::thread_count property set before avcodec_open2()) - and threaded mode (AVCodecContext::thread_type set to FF_THREAD_FRAME or FF_THREAD_SLICE). + End-user application may configure the number of threads to utilize (via AVCodecContext::thread_count property set before avcodec_open2()) + and threaded mode (AVCodecContext::thread_type set to FF_THREAD_FRAME or FF_THREAD_SLICE). Thread pool will be managed by FFmpeg itself, although some answers say that it is also possible using application-provided pool. */ m_pVideoState->m_pCodecCtx->thread_count = 4; @@ -354,10 +354,10 @@ bool videoAVLIBSource::_restart( void ){ }; /* we do not send complete frames */ - //if( m_pVideoState->m_pVideoCodec->capabilities & AV_CODEC_CAP_TRUNCATED ) m_pVideoState->m_pCodecCtx->flags |= AV_CODEC_CAP_TRUNCATED; + //if( m_pVideoState->m_pVideoCodec->capabilities & AV_CODEC_CAP_TRUNCATED ) m_pVideoState->m_pCodecCtx->flags |= AV_CODEC_CAP_TRUNCATED; #ifndef _NOAUDIO_ - m_pVideoState->m_pAudioCtx = m_pVideoState->m_pFormatCtx->streams[m_pVideoState->m_iAudioStreamID]->codec; + m_pVideoState->m_pAudioCtx = m_pVideoState->m_pFormatCtx->streams[m_pVideoState->m_iAudioStreamID]->codec; m_pVideoState->m_pAudioCodec = avcodec_find_decoder( m_pVideoState->m_pAudioCtx->codec_id ); if( !m_pVideoState->m_pAudioCodec ){ LOG_ERROR( "Unsupported Audio codec!" ); @@ -376,7 +376,7 @@ bool videoAVLIBSource::_open( char *URI, bool ShowDeviceMenu, float framerate, i if (URI == NULL) return false; if (m_pVideoState == NULL) return false; if (m_bThreadStatus > TH_PRE_INIT ) return false; - m_pVideoState->m_pFormatCtx = avformat_alloc_context(); + m_pVideoState->m_pFormatCtx = avformat_alloc_context(); if (m_pVideoState->m_pFormatCtx == NULL){ LOG_ERROR("Video Format Context Memory Allocation Error"); return false; @@ -428,10 +428,10 @@ bool videoAVLIBSource::_open( char *URI, bool ShowDeviceMenu, float framerate, i //if (!fileExist(Buffer)) av_dict_set(&m_pVideoState->m_pFormatOpts, "video_device_load", Buffer, 0); }; //av_dict_set(&m_pVideoState->m_pFormatOpts, "crossbar_video_input_pin_number", "1", 0); - + //av_dict_set(&m_pVideoState->m_pFormatOpts, "show_audio_crossbar_connection_dialog", "true", 0); //av_dict_set(&m_pVideoState->m_pFormatOpts, "show_video_crossbar_connection_dialog", "true", 0); - + //AVInputFormat * is Internal Const in CoDec Lib AVInputFormat *iformat = av_find_input_format("dshow"); //av_dict_set(&options, "pixel_format", "bgr24", 0); @@ -489,10 +489,10 @@ bool videoAVLIBSource::_open( char *URI, bool ShowDeviceMenu, float framerate, i av_dict_set(&opts, "rtsp_transport", "tcp", 0); av_dict_set(&opts, "rtsp_flags", "prefer_tcp", 0); av_dict_set_int(&opts, "buffer_size", BUFSIZE, 0); - + pFormatCtx->flags |= AVFMT_FLAG_NONBLOCK; pFormatCtx->flags |= AVFMT_FLAG_DISCARD_CORRUPT; - pFormatCtx->flags |= AVFMT_FLAG_NOBUFFER; + pFormatCtx->flags |= AVFMT_FLAG_NOBUFFER; */ } else { #ifdef DEBUG @@ -502,8 +502,8 @@ bool videoAVLIBSource::_open( char *URI, bool ShowDeviceMenu, float framerate, i m_bSizeIsAutomatic = false; sprintf(tChar, "%dx%d", width, height); av_dict_set(&m_pVideoState->m_pFormatOpts, "video_size", tChar, 0); - switch ( inputPin ) { - case 0: LOG("PIX YUYV"); av_dict_set(&m_pVideoState->m_pFormatOpts, "pixel_format", "yuv420p", 0); break; + switch ( inputPin ) { + case 0: LOG("PIX YUYV"); av_dict_set(&m_pVideoState->m_pFormatOpts, "pixel_format", "yuv420p", 0); break; case 1: LOG("PIX MJPG"); av_dict_set(&m_pVideoState->m_pFormatOpts, "pixel_format", "mjpeg", 0); break; default: av_dict_set(&m_pVideoState->m_pFormatOpts, "pixel_format", "rgb24", 0); break; }; @@ -512,7 +512,7 @@ bool videoAVLIBSource::_open( char *URI, bool ShowDeviceMenu, float framerate, i }; av_dict_set(&m_pVideoState->m_pFormatOpts, "fflags", "nobuffer", 0); }; - av_dict_set(&m_pVideoState->m_pFormatOpts, "max_delay", "100", 0); + av_dict_set(&m_pVideoState->m_pFormatOpts, "max_delay", "100", 0); //av_dict_set(&options, "analyzeduration", "1000000", 0); if( framerate != -1 ){ sprintf(tChar, "%0.2f", framerate); @@ -520,9 +520,9 @@ bool videoAVLIBSource::_open( char *URI, bool ShowDeviceMenu, float framerate, i av_dict_set(&m_pVideoState->m_pFormatOpts, "framerate", tChar, 0); //av_dict_set(&options, "frame_rate", tChar, 0); }; - + //av_dict_set(&options, "timeout", "8000", 0); - int RetVal = 0; + int RetVal = 0; //LOG("Before Open1"); if( ( RetVal = avformat_open_input(&m_pVideoState->m_pFormatCtx, m_pVideoState->m_pFileName, NULL, &m_pVideoState->m_pFormatOpts) ) != 0 ){ av_dict_free( &m_pVideoState->m_pFormatOpts); @@ -547,7 +547,7 @@ bool videoAVLIBSource::_open( char *URI, bool ShowDeviceMenu, float framerate, i LOG("DataStream Opened"); #endif m_eMediaStatus = m_pVideoState->m_bStatus = MS_OPENED; - + if( avformat_find_stream_info( m_pVideoState->m_pFormatCtx, NULL )<0 ){ sprintf(Buffer, "Couldn't find stream information: %s", URI); LOG_ERROR(Buffer); @@ -555,7 +555,7 @@ bool videoAVLIBSource::_open( char *URI, bool ShowDeviceMenu, float framerate, i }; #if ( LIBAVCODEC_VERSION_MAJOR < 58 ) // && ( LIBAVCODEC_VERSION_MINOR < 50 ) - for( unsigned int i=0; i < m_pVideoState->m_pFormatCtx->nb_streams; i++ ){ + for( unsigned int i=0; i < m_pVideoState->m_pFormatCtx->nb_streams; i++ ){ //if( m_pVideoState->m_pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ){ if( m_pVideoState->m_pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO ){ LOG( "VIDEO stream detected." ); @@ -591,8 +591,8 @@ bool videoAVLIBSource::_open( char *URI, bool ShowDeviceMenu, float framerate, i }; //ToDo: Bind Audio Codec # endif - - + + #else # ifdef DEBUG_EXTRA LOG("YABABA-2!"); @@ -624,16 +624,16 @@ bool videoAVLIBSource::_open( char *URI, bool ShowDeviceMenu, float framerate, i }; #endif - + if( m_pVideoState->m_pVideoCodec == NULL ){ //sprintf(Buffer, "Codec [%d] not found for %s", m_pVideoState->m_pCodecCtx->codec_id, URI); sprintf(Buffer, "Codec [%d] not found for %s", m_pVideoState->m_pCodecCtx->codec_id, URI); LOG_ERROR( Buffer ); return false; - }; + }; /* - End-user application may configure the number of threads to utilize (via AVCodecContext::thread_count property set before avcodec_open2()) - and threaded mode (AVCodecContext::thread_type set to FF_THREAD_FRAME or FF_THREAD_SLICE). + End-user application may configure the number of threads to utilize (via AVCodecContext::thread_count property set before avcodec_open2()) + and threaded mode (AVCodecContext::thread_type set to FF_THREAD_FRAME or FF_THREAD_SLICE). Thread pool will be managed by FFmpeg itself, although some answers say that it is also possible using application-provided pool. */ m_pVideoState->m_pCodecCtx->thread_count = 4; @@ -652,10 +652,10 @@ bool videoAVLIBSource::_open( char *URI, bool ShowDeviceMenu, float framerate, i }; /* we do not send complete frames */ - if( m_pVideoState->m_pVideoCodec->capabilities & AV_CODEC_CAP_TRUNCATED ) m_pVideoState->m_pCodecCtx->flags |= AV_CODEC_CAP_TRUNCATED; + if( m_pVideoState->m_pVideoCodec->capabilities & AV_CODEC_CAP_TRUNCATED ) m_pVideoState->m_pCodecCtx->flags |= AV_CODEC_CAP_TRUNCATED; #ifndef _NOAUDIO_ - m_pVideoState->m_pAudioCtx = m_pVideoState->m_pFormatCtx->streams[m_pVideoState->m_iAudioStreamID]->codec; + m_pVideoState->m_pAudioCtx = m_pVideoState->m_pFormatCtx->streams[m_pVideoState->m_iAudioStreamID]->codec; m_pVideoState->m_pAudioCodec = avcodec_find_decoder( m_pVideoState->m_pAudioCtx->codec_id ); if( !m_pVideoState->m_pAudioCodec ){ LOG_ERROR( "Unsupported Audio codec!" ); @@ -708,7 +708,7 @@ bool videoAVLIBSource::_open( char *URI, bool ShowDeviceMenu, float framerate, i }; }; }; - + #ifdef DEBUG_EXTRA sprintf( tB, "Using Size [%dx%d]", m_nOutWidth, m_nOutHeight ); LOG( tB ); @@ -720,7 +720,7 @@ bool videoAVLIBSource::_open( char *URI, bool ShowDeviceMenu, float framerate, i AV_PIX_FMT_BGR24, SWS_BICUBIC ); LOG( tB ); -#endif +#endif m_pVideoState->m_pSwsCtx = sws_getContext( m_pVideoState->m_pCodecCtx->width, m_pVideoState->m_pCodecCtx->height, @@ -747,7 +747,7 @@ bool videoAVLIBSource::_open( char *URI, bool ShowDeviceMenu, float framerate, i }; void videoAVLIBSource::m_fThreadProc( void ){ - AVPacket * pPacket = NULL; + AVPacket * pPacket = NULL; cv::Mat mRGB( m_nOutHeight, m_nOutWidth, CV_8UC3, cv::Scalar( 255, 0, 255 ) ); AVFrame * pFrame = NULL; AVFrame * pFrameBGR = NULL; @@ -755,6 +755,38 @@ void videoAVLIBSource::m_fThreadProc( void ){ int dec_ret; char tB[256]; + /** @todo Valgrind is reporting several important memory leaks in this method. + * + * The first one has to do with @p av_frame_alloc(): + * + * ~~~~ + ==00:00:04:04.219 26021== 2,074,168 (536 direct, 2,073,632 indirect) bytes in 1 blocks are definitely lost in loss record 3,970 of 3,972 + ==00:00:04:04.219 26021== at 0x483AEB8: memalign (vg_replace_malloc.c:906) + ==00:00:04:04.219 26021== by 0x483AFCE: posix_memalign (vg_replace_malloc.c:1070) + ==00:00:04:04.219 26021== by 0x66E2244: av_malloc (in /usr/lib/x86_64-linux-gnu/libavutil.so.56.70.100) + ==00:00:04:04.219 26021== by 0x66E25FD: av_mallocz (in /usr/lib/x86_64-linux-gnu/libavutil.so.56.70.100) + ==00:00:04:04.219 26021== by 0x66BF6BF: av_frame_alloc (in /usr/lib/x86_64-linux-gnu/libavutil.so.56.70.100) + ==00:00:04:04.219 26021== by 0x248B0E: videoAVLIBSource::m_fThreadProc() (videoAVLIBSource.cpp:802) + ==00:00:04:04.219 26021== by 0x131B54: basicThread::m_fThreadEntryPoint(void*) (basicThread.cpp:62) + ==00:00:04:04.219 26021== by 0x49B7EA6: start_thread (pthread_create.c:477) + ==00:00:04:04.219 26021== by 0x7874ADE: clone (clone.S:95) + * ~~~~ + * + * The next one has to do with @p av_image_alloc(): + * + * ~~~~ + ==00:00:04:04.219 26021== 2,073,632 bytes in 1 blocks are indirectly lost in loss record 3,969 of 3,972 + ==00:00:04:04.219 26021== at 0x483AEB8: memalign (vg_replace_malloc.c:906) + ==00:00:04:04.219 26021== by 0x483AFCE: posix_memalign (vg_replace_malloc.c:1070) + ==00:00:04:04.219 26021== by 0x66E2244: av_malloc (in /usr/lib/x86_64-linux-gnu/libavutil.so.56.70.100) + ==00:00:04:04.219 26021== by 0x66DCEB5: av_image_alloc (in /usr/lib/x86_64-linux-gnu/libavutil.so.56.70.100) + ==00:00:04:04.219 26021== by 0x248BCB: videoAVLIBSource::m_fThreadProc() (videoAVLIBSource.cpp:807) + ==00:00:04:04.219 26021== by 0x131B54: basicThread::m_fThreadEntryPoint(void*) (basicThread.cpp:62) + ==00:00:04:04.219 26021== by 0x49B7EA6: start_thread (pthread_create.c:477) + ==00:00:04:04.219 26021== by 0x7874ADE: clone (clone.S:95) + * ~~~~ + */ + m_bThreadStatus = TH_WORKING; pPacket = (AVPacket *) av_malloc( sizeof(AVPacket) ); if ( pPacket == NULL ) { @@ -785,11 +817,11 @@ void videoAVLIBSource::m_fThreadProc( void ){ // LOG_ERROR("Error allocating BGR AVFrame Buffer!"); //} else { // av_image_fill_arrays ( pFrameBGR->data, pFrameBGR->linesize, pBGRbuffer, AV_PIX_FMT_BGR24, m_nWidth, m_nHeight, BUFFER_ALIGN ); - // + // // pFrameBGR->width = m_nWidth; // pFrameBGR->height = m_nHeight; // m_pVideoState->m_bStatus = MS_ALOCATED; - + #ifdef DEBUG LOG("Video Reader Thread Started."); #endif @@ -797,7 +829,7 @@ void videoAVLIBSource::m_fThreadProc( void ){ }; }; }; - + //cv::setBreakOnError( true ); m_eMediaStatus = m_pVideoState->m_bStatus = MS_STOPED; while( m_pMediaDestination == NULL && m_bThreadStatus == TH_WORKING ){ @@ -895,16 +927,16 @@ void videoAVLIBSource::m_fThreadProc( void ){ av_free( pBGRbuffer ); }; m_bThreadStatus = TH_ENDED; - m_eMediaStatus = m_pVideoState->m_bStatus = MS_STOPED; + m_eMediaStatus = m_pVideoState->m_bStatus = MS_STOPED; #ifdef DEBUG LOG("Video Structures Cleared!"); #endif }; -/* - -JPEG2000 isn't jpeg. To encode JPEG images, use AV_CODEC_ID_MJPEG. MJPEG stands for "motion JPEG", which is how a sequence of JPEG pictures making up a video stream is typically called. - +/* + +JPEG2000 isn't jpeg. To encode JPEG images, use AV_CODEC_ID_MJPEG. MJPEG stands for "motion JPEG", which is how a sequence of JPEG pictures making up a video stream is typically called. + int save_frame_as_jpeg( AVCodecContext *pCodecCtx, AVFrame *pFrame, int FrameNo) { AVCodec *jpegCodec = avcodec_find_encoder(AV_CODEC_ID_JPEG2000); if (!jpegCodec) { @@ -949,7 +981,7 @@ MediaStateStatus videoAVLIBSource::getStatus( void ){ return MS_UNDEFINED; }; -bool videoAVLIBSource::isFinished( void ){ +bool videoAVLIBSource::isFinished( void ){ if( m_pVideoState ) if( m_pVideoState->m_bStatus < MS_CLOSING ) return false; return true; };