diff --git a/lib/components/base/basicLIBAV.h b/lib/components/base/basicLIBAV.h index 6af167f8..4af19394 100644 --- a/lib/components/base/basicLIBAV.h +++ b/lib/components/base/basicLIBAV.h @@ -65,6 +65,11 @@ extern "C" { #define VIDEO_PICTURE_QUEUE_SIZE 30 #define BUFFER_ALIGN 32 +#define AVLIB_SOURCE_NOTDEF 0 +#define AVLIB_SOURCE_DDSHOW 1 +#define AVLIB_SOURCE_V4L2 2 +#define AVLIB_SOURCE_IPSTREAM 3 + //#define PROCESS_YUV420P #define PROCESS_BGR24 diff --git a/lib/data/media/video/videoAVLIBSource.cpp b/lib/data/media/video/videoAVLIBSource.cpp index 0e3dc4cc..218abf77 100644 --- a/lib/data/media/video/videoAVLIBSource.cpp +++ b/lib/data/media/video/videoAVLIBSource.cpp @@ -27,8 +27,8 @@ videoAVLIBSource::videoAVLIBSource( void *opaque ): basicMediaSource(), basicThread() { m_pLog = basicLogCollection::getInstance(); m_bSizeIsAutomatic = true; - m_nWidth = 640; - m_nHeight = 360; + m_nWidth = -1; + m_nHeight = -1; if( opaque ) { m_pOpaque = opaque; @@ -69,8 +69,8 @@ videoAVLIBSource::videoAVLIBSource(char *Source, void *opaque ) : basicMediaSour m_pLog = basicLogCollection::getInstance(); m_bStreamingSource = true; m_bSizeIsAutomatic = true; - m_nWidth = 640; - m_nHeight = 360; + m_nWidth = -1; + m_nHeight = -1; if( opaque ) { m_pOpaque = opaque; } else { @@ -137,22 +137,47 @@ videoAVLIBSource::~videoAVLIBSource(){ }; }; -bool videoAVLIBSource::setSize(int Width, int Height){ - m_bSizeIsAutomatic = false; - return true; +bool videoAVLIBSource::setSize( int Width, int Height ){ + if( m_pVideoState ){ + if( m_pVideoState->m_bStatus == MS_INIT ) { + if( Width && Height ) { + m_bSizeIsAutomatic = false; + m_nWidth = Width; + m_nHeight = Height; + return true; + }; + }; + }; + return false; }; bool videoAVLIBSource::setProportionalByWidth(int Width){ - m_bSizeIsAutomatic = false; - return true; + if( m_pVideoState ){ + if( m_pVideoState->m_bStatus == MS_INIT ) { + if( Width > 0 ) { + m_bSizeIsAutomatic = true; + m_nWidth = Width; + return true; + }; + }; + }; + return false; }; bool videoAVLIBSource::setProportionalByHeight(int Height){ - m_bSizeIsAutomatic = false; - return true; + if( m_pVideoState ){ + if( m_pVideoState->m_bStatus == MS_INIT ) { + if( Height > 0 ) { + m_bSizeIsAutomatic = true; + m_nHeight = Height; + return true; + }; + }; + }; + return false; }; -bool videoAVLIBSource::setFrameAspectRatio(FrameAspectRatio AspectRatio){ +bool videoAVLIBSource::setFrameAspectRatio( FrameAspectRatio AspectRatio ){ return true; }; @@ -208,9 +233,12 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in if (m_pVideoState->m_bStatus == MS_INIT){ char Buffer[1024] = {0}; char tChar[128] = {0}; - sprintf(m_pCookie, "%s", MD5String(URI)); + sprintf( m_pCookie, "%s", MD5String(URI) ); m_pVideoState->m_bStatus = MS_OPENING; + uint8_t bSrcType = AVLIB_SOURCE_NOTDEF; + if( strncmp( URI, "video=", 6 ) == 0 ){ + bSrcType = AVLIB_SOURCE_DDSHOW; #ifdef DEBUG LOG("MS-Video Device"); #endif @@ -285,21 +313,32 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in AVOption *mpOption = NULL; } else { -#ifdef DEBUG - LOG("Linux Video Device Or IP Stream Source"); -#endif + if( strncmp( URI, "/dev/video", 10 ) == 0 ) { + bSrcType = AVLIB_SOURCE_V4L2; + } else { + bSrcType = AVLIB_SOURCE_IPSTREAM; + }; AVDictionary *options = NULL; - if( width != -1 && height != -1 ){ - m_bSizeIsAutomatic = false; - sprintf(tChar, "%dx%d", width, height); - av_dict_set(&options, "video_size", tChar, 0); - } else { - m_bSizeIsAutomatic = true; - }; //av_dict_set(&options, "movflags", "faststart", 0); - av_dict_set(&options, "rtsp_transport", "tcp", 0); + if( bSrcType == AVLIB_SOURCE_IPSTREAM ) { +#ifdef DEBUG + LOG("IP Stream Source"); +#endif + av_dict_set(&options, "rtsp_transport", "tcp", 0); + av_dict_set(&options, "stimeout", "1000000", 0); + } else { +#ifdef DEBUG + LOG("Linux Video Device"); +#endif + if( width != -1 && height != -1 ){ + m_bSizeIsAutomatic = false; + sprintf(tChar, "%dx%d", width, height); + av_dict_set(&options, "video_size", tChar, 0); + } else { + m_bSizeIsAutomatic = true; + }; + }; av_dict_set(&options, "max_delay", "300000", 0); - av_dict_set(&options, "stimeout", "1000000", 0); av_dict_set(&options, "fflags", "nobuffer", 0); //av_dict_set(&options, "analyzeduration", "1000000", 0); if( framerate != -1 ){ @@ -336,9 +375,8 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in }; #if ( LIBAVCODEC_VERSION_MAJOR < 58 ) // && ( LIBAVCODEC_VERSION_MINOR < 50 ) - //LOG("YABABA-1!"); 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]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ){ if( m_pVideoState->m_pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO ){ LOG( "VIDEO stream detected." ); if( m_pVideoState->m_iVideoStreamID <0 ){ @@ -439,18 +477,43 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in #ifdef PROCESS_BGR24 m_pFrameBGR = av_frame_alloc(); #endif + char tB[128]; + sprintf( tB, "Setting Frame [%dx%d]", m_nWidth, m_nHeight ); + LOG( tB ); + sprintf( tB, "Source Frame [%dx%d]", m_pVideoState->m_pCodecCtx->width, m_pVideoState->m_pCodecCtx->height ); + LOG( tB ); if( scaled ){ + LOG("Size is Scaled"); m_nWidth = s_width; m_nHeight = s_height; } else { - if (m_bSizeIsAutomatic){ - m_nWidth = m_pVideoState->m_pCodecCtx->width; - m_nHeight = m_pVideoState->m_pCodecCtx->height; + if( m_bSizeIsAutomatic ){ + LOG("Size is Automatic"); + if(( m_nWidth == -1 )&&( m_nHeight == -1 )){ + m_nWidth = m_pVideoState->m_pCodecCtx->width; + m_nHeight = m_pVideoState->m_pCodecCtx->height; + } else { + // Proportional + if( m_nHeight == -1 ){ + float k = ((float)m_pVideoState->m_pCodecCtx->height) / ((float)m_pVideoState->m_pCodecCtx->width); + m_nHeight = (int)(((float)m_nWidth ) * k ); + } else { + float k = ((float)m_pVideoState->m_pCodecCtx->width) / ((float)m_pVideoState->m_pCodecCtx->height); + m_nWidth = (int)(((float)m_nHeight ) * k ); + }; + }; } else { - m_nWidth = width; - m_nHeight = height; + LOG("Size is Manual"); + if( width > 0 ){ + m_nWidth = width; + }; + if( height > 0 ){ + m_nHeight = height; + }; }; }; + sprintf( tB, "Actual Frame [%dx%d]", m_nWidth, m_nHeight ); + LOG( tB ); #ifdef PROCESS_YUV420P m_pOut_buffer = (uint8_t *) av_malloc( av_image_get_buffer_size( AV_PIX_FMT_YUV420P, m_nWidth , m_nHeight , BUFFER_ALIGN )); //avpicture_fill((AVPicture *) m_pFrameYUV, m_pOut_buffer, AV_PIX_FMT_YUV420P, m_nWidth, m_nHeight ); diff --git a/lib/rgoose/rgooseCamera.cpp b/lib/rgoose/rgooseCamera.cpp index 3ebefc60..9a30bc21 100644 --- a/lib/rgoose/rgooseCamera.cpp +++ b/lib/rgoose/rgooseCamera.cpp @@ -751,62 +751,81 @@ bool ARGUS_Camera::captureFrame( CSTR fileName, uint8_t compression ){ bool ARGUS_Camera::connectToStream( uint32_t id ){ if( id ){ - argusKernelModule * tKM = NULL; - argusKernel *tKRNL = NULL; + argusKernelModule * tKM = NULL; + argusKernel * tKRNL = NULL; + argusModuleFactory * tMF = NULL; if( m_pDBC == NULL ) { LOG_ERROR("No Database Connector!"); return false; }; tKRNL = argusKernel::getInstance(); if( tKRNL ) { - argusModuleFactory *tMF = NULL; tMF = tKRNL->getModuleFactory(); if( tMF ) { tKM = tMF->getModule( ARGUS_MODULE_EMBED_VIDEO ); + } else { + LOG_ERROR("No ModuleFactory Instance!"); + return false; }; + } else { + LOG_ERROR("No Kernel Instance!"); + return false; }; if( tKM ) { DBC_MEDIA_STREAM_DATA *tDATA = m_pDBC->getMediaStreamData( id ); - LOG("Module && DB OK"); if( tDATA ) { LOG( tDATA->mrl_proto ); - if( strncmp( tDATA->mrl_proto, "v4l2", 4 ) == 0 ){ - LOG( tDATA->mrl ); - m_sMediaSource.mediaStreamId = id; - m_pSource = new videoAVLIBSource( tDATA->mrl, &m_sMediaSource ); - } else { + m_sMediaSource.mediaStreamId = id; + m_pSource = new videoAVLIBSource( &m_sMediaSource ); + if( m_pSource != NULL ) { char tMRL[1024]; - DBC_CAM_DATA *tCAM = m_pDBC->getCamData( tDATA->source_id ); - if( tCAM ) { - sprintf( tMRL, "%s://%s:%s@%s:%d%s", tDATA->mrl_proto, tCAM->username, tCAM->password, tCAM->ip, tDATA->mrl_port, tDATA->mrl ); - free( tCAM ); - LOG( tMRL ); - m_sMediaSource.mediaStreamId = id; - m_pSource = new videoAVLIBSource( tMRL, &m_sMediaSource ); +#ifdef DEBUG + LOG("Source OK"); +#endif + int tW = ((argusModuleEmbedVideo*)tKM)->getWidh(); + //int tH = ((argusModuleEmbedVideo*)tKM)->getHeight(); + if( tW > 0 ) { + m_pSource->setProportionalByWidth( tW ); + //m_pSource->setSize( tW, tH ); + }; + if( strncmp( tDATA->mrl_proto, "v4l2", 4 ) == 0 ){ + sprintf( tMRL, tDATA->mrl ); } else { - LOG_ERROR("Error Getting CAM Data!"); + DBC_CAM_DATA *tCAM = m_pDBC->getCamData( tDATA->source_id ); + if( tCAM ) { + sprintf( tMRL, "%s://%s:%s@%s:%d%s", tDATA->mrl_proto, tCAM->username, tCAM->password, tCAM->ip, tDATA->mrl_port, tDATA->mrl ); + free( tCAM ); + } else { + LOG_ERROR("Error Getting CAM Data!"); + delete( m_pSource ); + m_pSource = NULL; + return false; + }; + }; + LOG( tMRL ); + if( m_pSource->_open( tMRL ) ) { + m_pSource->attachDestination( (argusModuleEmbedVideo*) tKM ); +#ifdef DEBUG + LOG("Finish!"); +#endif + m_bSourceConnected = true; + } else { + LOG_ERROR("Can not Open Video Source!"); + delete( m_pSource ); + m_pSource = NULL; }; - }; - if( m_pSource != NULL ) { - LOG("Source OK"); - m_pSource->attachDestination( (argusModuleEmbedVideo*) tKM ); - LOG("Finish!"); - m_bSourceConnected = true; - free( tDATA ); - return true; } else { LOG_ERROR("Video Source Stream Failure!"); }; free( tDATA ); }; - } else { + } #ifdef DEBUG - LOG("No Video Module!"); + else LOG("No Video Module!") #endif - //return true; - }; + ; }; - return false; + return m_bSourceConnected; }; bool ARGUS_Camera::disconnectFromStream( void ){ diff --git a/lib/rgoose/rgooseDBConnector.cpp b/lib/rgoose/rgooseDBConnector.cpp index 3389e5a4..122e326c 100644 --- a/lib/rgoose/rgooseDBConnector.cpp +++ b/lib/rgoose/rgooseDBConnector.cpp @@ -2817,12 +2817,12 @@ uint32_t argusDBC::addVideoRecord( uint32_t streamID, CSTR md5, uint32_t partID return tID; }; -DBC_KRNL_CMD *argusDBC::getActiveCommand( uint32_t SiteID ){ +DBC_KRNL_CMD *argusDBC::getActiveSiteCommand( uint32_t SiteID ){ DBC_KRNL_CMD *tPtr = NULL; if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; AAssoc *result; - sprintf( tQBuf, "SELECT * FROM `cmd_queue` WHERE `status`=0 AND `site_id`=%d", SiteID ); + sprintf( tQBuf, "SELECT * FROM `cmd_queue` WHERE `status`=0 AND `site_id`=%d LIMIT 1", SiteID ); #ifdef DEBUG_ALL LOG(tQBuf); #endif @@ -2859,7 +2859,50 @@ DBC_KRNL_CMD *argusDBC::getActiveCommand( uint32_t SiteID ){ return tPtr; }; -bool argusDBC::updateCommand( uint32_t CMD_ID, uint8_t STATUS ){ +DBC_KRNL_CMD *argusDBC::getActiveServerCommand( uint32_t ServerID ){ + DBC_KRNL_CMD *tPtr = NULL; + if( m_bIsConnected ) { + char tQBuf[MAX_PATH_LEN]; + AAssoc *result; + sprintf( tQBuf, "SELECT * FROM `servers_queue` WHERE `status`=0 AND `server_id`=%d LIMIT 1", ServerID ); +#ifdef DEBUG_ALL + LOG(tQBuf); +#endif + result = m_pDatabase->Query( tQBuf ); + if( result != NULL ) { + if( result->size() > 0 ) { + Assoc *cArr; + tPtr = (DBC_KRNL_CMD*)malloc(sizeof(DBC_KRNL_CMD)); + if( tPtr!= NULL ) { + Assoc::iterator it; + memset(tPtr,0,sizeof(DBC_KRNL_CMD)); + cArr = result->at(0); + it = cArr->find("id"); + if( it != cArr->end() ){ + tPtr->id = atoi( it->second.c_str() ); + }; + it = cArr->find("cmd"); + if( it != cArr->end() ){ + tPtr->cmd = atoi( it->second.c_str() ); + }; + it = cArr->find("param"); + if( it != cArr->end() ){ + strncpy( tPtr->param, it->second.c_str(), 255 ); + }; + it = cArr->find("aux_param"); + if( it != cArr->end() ){ + strncpy( tPtr->aux_param, it->second.c_str(), 255 ); + }; + }; + }; + }; + deleteResult( result ); + }; + return tPtr; +}; + + +bool argusDBC::updateSiteCommand( uint32_t CMD_ID, uint8_t STATUS ){ if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "UPDATE `cmd_queue` SET `status`=%d WHERE id=%d", STATUS, CMD_ID ); @@ -2872,6 +2915,19 @@ bool argusDBC::updateCommand( uint32_t CMD_ID, uint8_t STATUS ){ return false; }; +bool argusDBC::updateServerCommand( uint32_t CMD_ID, uint8_t STATUS ){ + if( m_bIsConnected ) { + char tQBuf[MAX_PATH_LEN]; + sprintf( tQBuf, "UPDATE `servers_queue` SET `status`=%d WHERE id=%d", STATUS, CMD_ID ); +#ifdef DEBUG_ALL + LOG(tQBuf); +#endif + m_pDatabase->SilentQuery( tQBuf ); + return true; + }; + return false; +}; + bool argusDBC::updateLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master, uint16_t nOrder, uint16_t nOffset, uint16_t nDelta, uint16_t nWidth, uint16_t nFlip, uint16_t nSun, uint8_t bSST, uint32_t GP, uint32_t spikes ){ if( m_bIsConnected ) { @@ -3046,10 +3102,6 @@ DBC_MODULE_EMBED_VIDEO_DATA *argusDBC::getEmbedVideoData( uint32_t ID ){ if( it != cArr->end() ){ tPtr->port = atoi( it->second.c_str() ); }; - it = cArr->find("show_ts"); - if( it != cArr->end() ){ - tPtr->show_ts = (bool)atoi( it->second.c_str() ); - }; it = cArr->find("width"); if( it != cArr->end() ){ tPtr->width = atoi( it->second.c_str() ); @@ -3062,6 +3114,10 @@ DBC_MODULE_EMBED_VIDEO_DATA *argusDBC::getEmbedVideoData( uint32_t ID ){ if( it != cArr->end() ){ tPtr->compression_quality = atoi( it->second.c_str() ); }; + it = cArr->find("show_ts"); + if( it != cArr->end() ){ + tPtr->show_ts = (bool)atoi( it->second.c_str() ); + }; it = cArr->find("ts_x"); if( it != cArr->end() ){ tPtr->ts_x = atoi( it->second.c_str() ); @@ -3088,7 +3144,7 @@ DBC_MODULE_EMBED_VIDEO_DATA *argusDBC::getEmbedVideoData( uint32_t ID ){ }; it = cArr->find("ts_transperant"); if( it != cArr->end() ){ - tPtr->ts_y = (bool)atoi( it->second.c_str() ); + tPtr->ts_transperant = (bool)atoi( it->second.c_str() ); }; it = cArr->find("show_label"); if( it != cArr->end() ){ diff --git a/lib/rgoose/rgooseDBConnector.h b/lib/rgoose/rgooseDBConnector.h index a5520c76..9cff90ba 100644 --- a/lib/rgoose/rgooseDBConnector.h +++ b/lib/rgoose/rgooseDBConnector.h @@ -61,7 +61,8 @@ class argusDBC{ //DBC_INT_LIST * listSockets( uint32_t NodeID ); DBC_INT_LIST * listResources( uint32_t NodeID = 0 ); - DBC_KRNL_CMD * getActiveCommand( uint32_t SiteID ); + DBC_KRNL_CMD * getActiveServerCommand( uint32_t ServerID ); + DBC_KRNL_CMD * getActiveSiteCommand( uint32_t SiteID ); bool getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ); DBC_APF_DATA * getAPFData( uint32_t APFID ); DBC_CAM_DATA * getCamData( uint32_t CamID ); @@ -120,7 +121,8 @@ class argusDBC{ bool setLRFAltVerison( uint32_t lrfID, CSTR version ); bool setStreamValid( uint32_t streamID ); bool updateAFPBox( uint32_t filterID, CSTR Tag, float x, float y, float z ); - bool updateCommand( uint32_t CMD_ID, uint8_t STATUS ); + bool updateServerCommand( uint32_t CMD_ID, uint8_t STATUS ); + bool updateSiteCommand( uint32_t CMD_ID, uint8_t STATUS ); bool updateIPCam( uint32_t SiteID, CSTR uuid, CSTR Addr ); bool updateIPCam( uint32_t SiteID, uint32_t CamID, CSTR Addr ); bool updateLRFSerial( uint32_t lrfID, CSTR Serial ); diff --git a/lib/rgoose/rgooseHardwareManager.cpp b/lib/rgoose/rgooseHardwareManager.cpp index d8eee030..434a4ef4 100644 --- a/lib/rgoose/rgooseHardwareManager.cpp +++ b/lib/rgoose/rgooseHardwareManager.cpp @@ -575,7 +575,7 @@ DBC_INT_LIST *argusHardwareManager::requestResourcesByType( ARGUS_HARDWARE_PROVI #endif for( VECTOR_HW_RESOURCES::iterator idx = m_vResources.begin(); idx < m_vResources.end(); idx++ ) { #ifdef DEBUG_EXTRA - sprintf( tBuffer, "Have Resource type: %d", (*idx)->getType() ); + sprintf( tBuffer, "Have Resource type: %d", (*idx)->getHardwareType() ); LOG( tBuffer ); #endif if( (*idx)->getProviderType() == type ) { diff --git a/lib/rgoose/rgooseKernel.cpp b/lib/rgoose/rgooseKernel.cpp index 6d0d69f7..bc32f625 100644 --- a/lib/rgoose/rgooseKernel.cpp +++ b/lib/rgoose/rgooseKernel.cpp @@ -195,13 +195,15 @@ bool argusKernel::create( void ){ if( !m_pModuleFactory ) { LOG_ERROR("Failure to get Module Factory Instance!"); return false; - } + } else { #ifdef DEBUG - else { LOG( "Module Factory Created" ); - } #endif - ; + while( !m_pModuleFactory->isValidationDone() ) SLEEP( 10 ); +#ifdef DEBUG + LOG( "Module Factory Validated" ); +#endif + }; #ifdef DEBUG LOG( "Load Filters" ); @@ -389,21 +391,26 @@ void argusKernel::m_fThreadProc( void ){ if( !m_pDBC->updateServerUtilisation( m_nServerID, cCORES, cpu1, cpu5, cpu15, mem, disk, tMEM, cMEM, tDISK, cDISK ) ) LOG_ERROR("Cannot update System Utilisation Stats!"); //Get Queued Commands DBC_KRNL_CMD *tCMD = NULL; - tCMD = m_pDBC->getActiveCommand( m_nSiteID ); + tCMD = m_pDBC->getActiveServerCommand( m_nServerID ); + //tCMD = m_pDBC->getActiveSiteCommand( m_nSiteID ); if( tCMD != NULL ){ switch( tCMD->cmd ) { case ARGUS_CMD_KRNL_RELOAD:{ LOG("Reload ARGUS SERVER!"); m_bThreadStatus = TH_ENDED; m_bExitCause = 1; - m_pDBC->updateCommand( tCMD->id, ARGUS_CMD_STATUS_FINISHED ); + break; + }; + case ARGUS_CMD_KRNL_RESTART:{ + LOG("Restart ARGUS SERVER!"); + m_bThreadStatus = TH_ENDED; + m_bExitCause = 0; break; }; case ARGUS_CMD_NODES_RELOAD:{ if( m_pNodeFactory != NULL ) { m_pNodeFactory->reloadNodes( m_nSiteID ); }; - m_pDBC->updateCommand( tCMD->id, ARGUS_CMD_STATUS_FINISHED ); break; }; case ARGUS_CMD_NODE_RELOAD:{ @@ -411,20 +418,21 @@ void argusKernel::m_fThreadProc( void ){ if( m_pNodeFactory != NULL ) { m_pNodeFactory->reloadNode( tNodeID ); }; - m_pDBC->updateCommand( tCMD->id, ARGUS_CMD_STATUS_FINISHED ); break; }; - case ARGUS_CMD_HARDWARE_DETECT:{ + case ARGUS_CMD_KRNL_PNP:{ if( m_pHardwareManager!= NULL ) { LOG_ERROR( "Restart and Detect HardWare!" ); // Must be shutdowned all service that uses hardware prior to detection! - //m_pHardwareManager->enumerateHardware(); + // m_pHardwareManager->enumerateHardware(); m_bThreadStatus = TH_ENDED; m_bExitCause = 4; // Go -> Detect Hardware in BACKEND }; - m_pDBC->updateCommand( tCMD->id, ARGUS_CMD_STATUS_FINISHED ); + break; }; }; + m_pDBC->updateServerCommand( tCMD->id, ARGUS_CMD_STATUS_FINISHED ); + //m_pDBC->updateSiteCommand( tCMD->id, ARGUS_CMD_STATUS_FINISHED ); free( tCMD ); }; // Validate Hardware diff --git a/lib/rgoose/rgooseKernel.h b/lib/rgoose/rgooseKernel.h index 7e0d1d3b..d6540e9e 100644 --- a/lib/rgoose/rgooseKernel.h +++ b/lib/rgoose/rgooseKernel.h @@ -96,7 +96,8 @@ struct serial_struct { #define ARGUS_CMD_KRNL_RELOAD 128 #define ARGUS_CMD_KRNL_RESTART 250 -#define ARGUS_CMD_KRNL_SHUTDOWN 251 +#define ARGUS_CMD_KRNL_PNP 251 +#define ARGUS_CMD_KRNL_SHUTDOWN 255 #define ARGUS_CMD_MODULES_RELOAD 60 #define ARGUS_CMD_MODULE_ENABLE 61 #define ARGUS_CMD_MODULE_DISABLE 62 diff --git a/lib/rgoose/rgooseModuleEmbedVideo.cpp b/lib/rgoose/rgooseModuleEmbedVideo.cpp index dbf25389..ee610242 100644 --- a/lib/rgoose/rgooseModuleEmbedVideo.cpp +++ b/lib/rgoose/rgooseModuleEmbedVideo.cpp @@ -597,6 +597,7 @@ bool argusModuleEmbedVideo::reloadSettings(){ }; bool argusModuleEmbedVideo::validate(){ + return true; }; @@ -614,9 +615,6 @@ void argusModuleEmbedVideo::pushFrame( cv::Mat &Frame, void* src ){ cv::Rect ROI; //if( !m_mPictureProtector.try_lock() ) return; m_mPictureProtector.lock(); - oK = ((float)m_sEmbedVideoData.height )/ ((float)m_sEmbedVideoData.width); - mK = ((float)Frame.rows )/ ((float)Frame.cols); - //sprintf( tBuffer, "INP: [%dx%d] IK:%0.3f OK:%0.3f", Frame.cols, Frame.rows, mK, oK ); if( m_mapMATS[tMD->mediaStreamId].cols == 0 ) { LOG("First Frame Enqueued"); sprintf( tBuffer, "INP: [%dx%d] SrcID:%d StreamID:%d", Frame.cols, Frame.rows, tMD->mediaSourceId, tMD->mediaStreamId ); @@ -625,6 +623,10 @@ void argusModuleEmbedVideo::pushFrame( cv::Mat &Frame, void* src ){ m_mapMATS[tMD->mediaStreamId].create( m_sEmbedVideoData.height, m_sEmbedVideoData.width, CV_8UC3 ); cv::rectangle( m_mapMATS[tMD->mediaStreamId], cv::Point( 0, 0 ), cv::Point( m_sEmbedVideoData.height, m_sEmbedVideoData.width ), cv::Scalar( 0, 0, 0 ), cv::FILLED ); }; +#ifdef USE_SCALING_IN + oK = ((float)m_sEmbedVideoData.height )/ ((float)m_sEmbedVideoData.width); + mK = ((float)Frame.rows )/ ((float)Frame.cols); + //sprintf( tBuffer, "INP: [%dx%d] IK:%0.3f OK:%0.3f", Frame.cols, Frame.rows, mK, oK ); if( ( fabsf( mK - oK ) < 0.1f ) || ( fabsf( oK - mK ) < 0.1f ) ) { ROI.width = (int) m_sEmbedVideoData.width; ROI.height = (int) m_sEmbedVideoData.height; @@ -642,32 +644,126 @@ void argusModuleEmbedVideo::pushFrame( cv::Mat &Frame, void* src ){ ROI.y = (int) 0; ROI.x = (int) ( m_sEmbedVideoData.width - ROI.width ) >> 1; }; - } + }; cv::Mat mROI = m_mapMATS[tMD->mediaStreamId]( ROI ); cv::resize( Frame, mROI , mROI.size(), 0, 0, cv::INTER_LINEAR ); - /* - cv::putText( m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point( 30, 45 ), - (cv::HersheyFonts) m_sEmbedVideoData.ts_font_face, - m_sEmbedVideoData.ts_font_scale, cv::Scalar( 0, 255, 255 ), - m_sEmbedVideoData.ts_font_thickness, - m_sEmbedVideoData.ts_line_type - ); - */ - if( m_sEmbedVideoData.show_ts ){ - char DateStr[200]; +#else + if(( m_sEmbedVideoData.height==Frame.rows )&&( m_sEmbedVideoData.width==Frame.cols )){ + Frame.copyTo( m_mapMATS[tMD->mediaStreamId] ); + } else { + if( m_sEmbedVideoData.height < Frame.rows ) { + ROI.x = 0; + ROI.width = m_sEmbedVideoData.width; + ROI.y = ( Frame.rows - m_sEmbedVideoData.height ) >> 1; + ROI.height = m_sEmbedVideoData.height; + cv::Mat mROI = Frame( ROI ); + mROI.copyTo(m_mapMATS[tMD->mediaStreamId]); + } else { + ROI.x = 0; + ROI.width = m_sEmbedVideoData.width; + ROI.y = ( m_sEmbedVideoData.height - Frame.rows ) >> 1; + ROI.height = Frame.rows; + cv::Mat mROI = m_mapMATS[tMD->mediaStreamId]( ROI ); + Frame.copyTo( mROI ); + }; + }; +#endif + if( m_sEmbedVideoData.show_label ){ time_t t = time( NULL ); struct tm * tmp = gmtime( &t ); if( tmp ){ - if( strftime( DateStr, sizeof(DateStr), "%F %T GMT", tmp )!=0 ){ - cv::rectangle( m_mapMATS[tMD->mediaStreamId], cv::Point( 10, 10 ), cv::Point( 490, 60 ), cv::Scalar( 0, 0, 0 ), cv::FILLED ); - cv::putText( m_mapMATS[tMD->mediaStreamId], DateStr, cv::Point( 30, 45 ), - (cv::HersheyFonts) m_sEmbedVideoData.ts_font_face, - m_sEmbedVideoData.ts_font_scale, cv::Scalar( 0, 255, 255 ), - m_sEmbedVideoData.ts_font_thickness, - m_sEmbedVideoData.ts_line_type + char tsb[64]; + if( strftime( tsb, sizeof(tsb), "%F %T GMT", tmp )!=0 ){ + + sprintf( tBuffer, ">>%d>%d>%s>%s>", tMD->mediaSourceId, tMD->mediaStreamId, tMD->mediaName, tsb ); + int baseline=0; + cv::Size textSize = cv::getTextSize( tBuffer, + m_sEmbedVideoData.label_font_face, + m_sEmbedVideoData.label_font_scale, + m_sEmbedVideoData.label_font_thickness, + &baseline + ); + int x = m_sEmbedVideoData.label_x; + int y = m_sEmbedVideoData.label_y; + if( x < 0 ) { + x = m_sEmbedVideoData.width+x-textSize.width; + }; + if( y < 0 ) { + y = m_sEmbedVideoData.height+y-baseline;// + }; + if( !m_sEmbedVideoData.label_transperant ) { + cv::rectangle( m_mapMATS[tMD->mediaStreamId], cv::Rect( x, y-textSize.height-4, textSize.width, textSize.height+baseline+4 ), cv::Scalar( 0, 0, 0 ), cv::FILLED ); + }; + cv::putText( m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point( x, y ), + (cv::HersheyFonts) m_sEmbedVideoData.label_font_face, + m_sEmbedVideoData.label_font_scale, cv::Scalar( 0, 255, 0 ), + m_sEmbedVideoData.label_font_thickness, + m_sEmbedVideoData.label_line_type ); }; }; + } else { + if( m_sEmbedVideoData.show_ts ){ + time_t t = time( NULL ); + struct tm * tmp = gmtime( &t ); + if( tmp ){ + if( strftime( tBuffer, sizeof(tBuffer), "%F %T GMT", tmp )!=0 ){ + uint8_t shift_x = 0; + uint8_t shift_y = 15; + if( !m_sEmbedVideoData.ts_transperant ) { + if( m_sEmbedVideoData.ts_font_face ) { + shift_y = 15; + cv::rectangle( m_mapMATS[tMD->mediaStreamId], cv::Point( m_sEmbedVideoData.ts_x, m_sEmbedVideoData.ts_y ), cv::Point( 490, 60 ), cv::Scalar( 0, 0, 0 ), cv::FILLED ); + } else { + shift_y = 23; + cv::rectangle( m_mapMATS[tMD->mediaStreamId], cv::Point( m_sEmbedVideoData.ts_x, m_sEmbedVideoData.ts_y ), cv::Point( 490, 60 ), cv::Scalar( 0, 0, 0 ), cv::FILLED ); + }; + cv::putText( m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point( m_sEmbedVideoData.ts_x + shift_x, m_sEmbedVideoData.ts_y + shift_y ), + (cv::HersheyFonts) m_sEmbedVideoData.ts_font_face, + m_sEmbedVideoData.ts_font_scale, cv::Scalar( 0, 255, 255 ), + m_sEmbedVideoData.ts_font_thickness, + m_sEmbedVideoData.ts_line_type + ); + } else { + if( m_sEmbedVideoData.ts_font_face ) { + shift_y = 15; + } else { + shift_y = 23; + }; + cv::putText( m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point( m_sEmbedVideoData.ts_x + shift_x - 1, m_sEmbedVideoData.ts_y + shift_y - 1 ), + (cv::HersheyFonts) m_sEmbedVideoData.ts_font_face, + m_sEmbedVideoData.ts_font_scale, cv::Scalar( 0, 0, 0 ), + m_sEmbedVideoData.ts_font_thickness, + m_sEmbedVideoData.ts_line_type + ); + cv::putText( m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point( m_sEmbedVideoData.ts_x + shift_x + 1, m_sEmbedVideoData.ts_y + shift_y - 1 ), + (cv::HersheyFonts) m_sEmbedVideoData.ts_font_face, + m_sEmbedVideoData.ts_font_scale, cv::Scalar( 0, 0, 0 ), + m_sEmbedVideoData.ts_font_thickness, + m_sEmbedVideoData.ts_line_type + ); + cv::putText( m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point( m_sEmbedVideoData.ts_x + shift_x - 1, m_sEmbedVideoData.ts_y + shift_y + 1 ), + (cv::HersheyFonts) m_sEmbedVideoData.ts_font_face, + m_sEmbedVideoData.ts_font_scale, cv::Scalar( 0, 0, 0 ), + m_sEmbedVideoData.ts_font_thickness, + m_sEmbedVideoData.ts_line_type + ); + cv::putText( m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point( m_sEmbedVideoData.ts_x + shift_x - 1, m_sEmbedVideoData.ts_y + shift_y + 2 ), + (cv::HersheyFonts) m_sEmbedVideoData.ts_font_face, + m_sEmbedVideoData.ts_font_scale, cv::Scalar( 0, 0, 0 ), + m_sEmbedVideoData.ts_font_thickness, + m_sEmbedVideoData.ts_line_type + ); + cv::putText( m_mapMATS[tMD->mediaStreamId], tBuffer, cv::Point( m_sEmbedVideoData.ts_x + shift_x, m_sEmbedVideoData.ts_y + shift_y ), + (cv::HersheyFonts) m_sEmbedVideoData.ts_font_face, + m_sEmbedVideoData.ts_font_scale, cv::Scalar( 0, 255, 255 ), + m_sEmbedVideoData.ts_font_thickness, + m_sEmbedVideoData.ts_line_type + ); + } + }; + }; + }; }; if( m_sEmbedVideoData.show_logo ){ cv::Rect roi( cv::Point( m_sEmbedVideoData.logo_x, m_sEmbedVideoData.logo_y ), cv::Size( m_sEmbedVideoData.logo_w, m_sEmbedVideoData.logo_h )); @@ -683,9 +779,13 @@ void argusModuleEmbedVideo::pushFrame( cv::Mat &Frame, void* src ){ //vector buf; uint32_t DataSize; //m_mPictureProtector.lock(); + m_mEncodedProtector.lock(); m_mapCAPTURES[tMD->mediaStreamId].clear(); cv::imencode( ".jpg", m_mapMATS[tMD->mediaStreamId], m_mapCAPTURES[tMD->mediaStreamId], compression_params ); + m_mEncodedProtector.unlock(); + /*ToDo: Move Broadcast Pic From Push Frame Procedure */ DataSize = m_mapCAPTURES[tMD->mediaStreamId].size(); //buf.size(); + if( DataSize ) { uint8_t *pData = m_mapCAPTURES[tMD->mediaStreamId].data(); //buf.data(); if( m_vHandlersPool.size() ) { @@ -763,6 +863,19 @@ bool argusModuleEmbedVideo::saveStreamPicture( uint32_t id, CSTR *MD5 ){ }; return false; }; +int argusModuleEmbedVideo::getWidh( void ){ + if( m_sEmbedVideoData.width ){ + return m_sEmbedVideoData.width; + }; + return -1; +}; + +int argusModuleEmbedVideo::getHeight( void ){ + if( m_sEmbedVideoData.height ) { + return m_sEmbedVideoData.height; + }; + return -1; +}; #undef LOG #undef LOG_ERROR diff --git a/lib/rgoose/rgooseModuleEmbedVideo.h b/lib/rgoose/rgooseModuleEmbedVideo.h index cdd22698..53571441 100644 --- a/lib/rgoose/rgooseModuleEmbedVideo.h +++ b/lib/rgoose/rgooseModuleEmbedVideo.h @@ -11,6 +11,8 @@ class argusModuleEmbedVideo; #define FILESTREAMBUFFERSZ 1048576 +//#define USE_SCALING_IN + /* Video CODECS */ #define VC_VPX 0 #define VC_X264 1 @@ -138,6 +140,7 @@ class argusModuleEmbedVideo: public argusKernelModule, public basicMediaDestinat int m_nSocketDescriptor; basicMutex m_mHandlersProtector; basicMutex m_mPictureProtector; + basicMutex m_mEncodedProtector; vectorHANDLERS m_vHandlersPool; DBC_MODULE_EMBED_VIDEO_DATA m_sEmbedVideoData; mapSTREAMCAPS m_mapCAPTURES; @@ -164,5 +167,8 @@ class argusModuleEmbedVideo: public argusKernelModule, public basicMediaDestinat virtual void pushFrame(AVFrame *Frame, void* src = NULL); //virtual void pushFrame(cv::Mat* Frame, void* src = NULL); virtual void pushFrame( cv::Mat &Frame, void* src = NULL); + /* Module Specific Functionality */ + int getWidh( void ); + int getHeight( void ); }; #endif diff --git a/lib/rgoose/rgooseModuleFactory.cpp b/lib/rgoose/rgooseModuleFactory.cpp index a808a222..ab61380f 100644 --- a/lib/rgoose/rgooseModuleFactory.cpp +++ b/lib/rgoose/rgooseModuleFactory.cpp @@ -30,6 +30,7 @@ argusModuleFactory* argusModuleFactory::getInstance( uint32_t ServerID ) { argusModuleFactory::argusModuleFactory( uint32_t ServerID ):basicThread(){ m_nServerID = ServerID; + m_bInitialValidatioonDone = false; m_pLog = basicLogCollection::getInstance(); m_pDBC = argusDBC::getInstance(); init(); @@ -359,6 +360,7 @@ void argusModuleFactory::m_fThreadProc( void ){ sprintf(MEM_MSG,"MEM START: %d MEM DIF2: %d", memStart, memDiff ); LOG( MEM_MSG ); #endif + if( !m_bInitialValidatioonDone ) m_bInitialValidatioonDone = true; for( int i = ( 5000 / DEFAULT_THREAD_SLEEP_TIME ); i && ( m_bThreadStatus < TH_ENDED ); i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME ); }; }; diff --git a/lib/rgoose/rgooseModuleFactory.h b/lib/rgoose/rgooseModuleFactory.h index 5a529d36..cf1e8810 100644 --- a/lib/rgoose/rgooseModuleFactory.h +++ b/lib/rgoose/rgooseModuleFactory.h @@ -15,6 +15,7 @@ class argusModuleFactory: public basicThread{ uint32_t m_nServerID; vectorKernelModules m_vKernelModules; basicMutex m_mModulesProtector; + bool m_bInitialValidatioonDone; void deleteModule( argusKernelModule * ); public: static argusModuleFactory * getInstance( uint32_t ServerID = 0 ); @@ -28,6 +29,7 @@ class argusModuleFactory: public basicThread{ bool loadModules( uint32_t ServerID = 0 ); bool validate( void ); void shutdownServices( bool force = false ); + bool isValidationDone( void ){ return m_bInitialValidatioonDone; }; protected: explicit argusModuleFactory( uint32_t ServerID ); virtual void m_fThreadProc( void ); diff --git a/lib/rgoose/rgooseNodeFactory.cpp b/lib/rgoose/rgooseNodeFactory.cpp index 6d16f132..2cbad326 100644 --- a/lib/rgoose/rgooseNodeFactory.cpp +++ b/lib/rgoose/rgooseNodeFactory.cpp @@ -526,9 +526,10 @@ void argusNodeFactory::m_fThreadProc( void ){ }; } #ifdef DEBUG - else { - LOG("No Nodes to Validate"); - } + //else { + // LOG("No Nodes to Validate"); + //} + ; #ifdef MEM_DEBUG memEnd = getCurrentRSS(); memDiff = memEnd - memStart; diff --git a/lib/rgoose/rgooseNodePTZCamControl.cpp b/lib/rgoose/rgooseNodePTZCamControl.cpp index f5251876..abe3effe 100644 --- a/lib/rgoose/rgooseNodePTZCamControl.cpp +++ b/lib/rgoose/rgooseNodePTZCamControl.cpp @@ -41,6 +41,8 @@ ARGUS_PTZCAM::ARGUS_PTZCAM( DBC_NODE_DATA *Data ): basicEventHandler(), argusNet ARGUS_PTZCAM::ARGUS_PTZCAM( uint32_t id ): basicEventHandler(), argusNetNode( id ), ARGUS_Camera(){ m_pLog = basicLogCollection::getInstance(); m_sMediaSource.mediaSourceId = m_sNodeData.aux_id; + strncpy( m_sMediaSource.mediaName, m_sNodeData.name, 128 ); + m_sMediaSource.mediaName[127] = (char)0; memset( &m_sCtrlData, 0, sizeof( CAMERA_CTRL_DATA )); }; @@ -180,19 +182,13 @@ bool ARGUS_PTZCAM::validate(){ }*/ // Validate Stream { - if( m_sNodeData.aux_parameter ) { // Has Choosed Stream - DBC_MEDIA_STREAM_DATA *tDATA = argusNetNode::m_pDBC->getMediaStreamData( m_sNodeData.aux_parameter ); - if( tDATA ){ - if( tDATA->valid ) { - if( !m_bSourceConnected ) { - if(!connectToStream( m_sNodeData.aux_parameter ) ) return false; - }; - } else { - if( m_bSourceConnected ) { - if( disconnectFromStream() ) return false; - }; + if( !m_bSourceConnected ) { + if( m_sNodeData.aux_parameter ) { // Has Choosed Stream + if( connectToStream( m_sNodeData.aux_parameter ) ){ + //DBC_MEDIA_STREAM_DATA *tDATA = argusNetNode::m_pDBC->getMediaStreamData( m_sNodeData.aux_parameter ); + m_bSourceConnected = true; + return argusNetNode::m_pDBC->setStreamValid( m_sNodeData.aux_parameter ); }; - free( tDATA ); }; }; } diff --git a/lib/rgoose/rgooseTypes.h b/lib/rgoose/rgooseTypes.h index f43ef3e6..13af7198 100644 --- a/lib/rgoose/rgooseTypes.h +++ b/lib/rgoose/rgooseTypes.h @@ -66,6 +66,7 @@ typedef struct S_OBSERVER_RESULT{ typedef struct S_MEDIA_SOURCE_DESC{ uint32_t mediaStreamId; uint32_t mediaSourceId; + char mediaName[128]; }MEDIA_SOURCE_DESC; typedef enum E_ARGUS_NODE_TYPE{