|
|
@ -125,9 +125,13 @@ argusModuleEmbedVideo::~argusModuleEmbedVideo(){ |
|
|
#ifdef DEBUG
|
|
|
#ifdef DEBUG
|
|
|
LOG("No More Client Handlers!"); |
|
|
LOG("No More Client Handlers!"); |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
if( m_mapHANDLERS.size() ){ |
|
|
|
|
|
for( mapSTREAMHANDLERS::iterator idx = m_mapHANDLERS.begin(); idx != m_mapHANDLERS.end(); idx++ ) delete( (*idx).second ); |
|
|
|
|
|
m_mapHANDLERS.clear(); |
|
|
|
|
|
}; |
|
|
if( m_mapCAPTURES.size() ) m_mapCAPTURES.clear(); |
|
|
if( m_mapCAPTURES.size() ) m_mapCAPTURES.clear(); |
|
|
if( m_mapMATS.size() ) m_mapMATS.clear(); |
|
|
if( m_mapMATS.size() ) m_mapMATS.clear(); |
|
|
if(n_pNoSignalData) free(n_pNoSignalData); |
|
|
|
|
|
|
|
|
if( n_pNoSignalData ) free(n_pNoSignalData); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
static const char * ht_head = "HTTP/1.1 200 OK\r\n" |
|
|
static const char * ht_head = "HTTP/1.1 200 OK\r\n" |
|
|
@ -711,6 +715,13 @@ bool argusModuleEmbedVideo::validate(){ |
|
|
delete ( tList ); |
|
|
delete ( tList ); |
|
|
}; |
|
|
}; |
|
|
}; |
|
|
}; |
|
|
|
|
|
if ( RetVal ) { |
|
|
|
|
|
for( mapSTREAMHANDLERS::iterator idx = m_mapHANDLERS.begin(); idx != m_mapHANDLERS.end(); idx++ ) { |
|
|
|
|
|
if ( !(*idx).second->validate() ) { |
|
|
|
|
|
RetVal = false; |
|
|
|
|
|
}; |
|
|
|
|
|
}; |
|
|
|
|
|
}; |
|
|
} else { |
|
|
} else { |
|
|
LOG_ERROR( "DB Error!" ); |
|
|
LOG_ERROR( "DB Error!" ); |
|
|
RetVal = false; |
|
|
RetVal = false; |
|
|
@ -796,68 +807,88 @@ void argusModuleEmbedVideo::dispatchEvent( EVENT_CONTAINER *Evt ){ |
|
|
//https://www.mikekohn.net/software/playstation2.php
|
|
|
//https://www.mikekohn.net/software/playstation2.php
|
|
|
|
|
|
|
|
|
bool argusModuleEmbedVideo::saveStreamPicture( DBC_SNAPSHOT_DATA *ptr ){ |
|
|
bool argusModuleEmbedVideo::saveStreamPicture( DBC_SNAPSHOT_DATA *ptr ){ |
|
|
|
|
|
|
|
|
if( ptr == NULL ) return false; |
|
|
if( ptr == NULL ) return false; |
|
|
if( ptr->assoc_event_ids.size() ){ |
|
|
|
|
|
if( m_mapCAPTURES.find( ptr->stream_id ) != m_mapCAPTURES.end() ){ |
|
|
|
|
|
m_mPictureProtector.lock(); |
|
|
|
|
|
ptr->data = (uint8_t *) malloc( m_mapCAPTURES[ptr->stream_id].size() ); |
|
|
|
|
|
if( ptr->data ){ |
|
|
|
|
|
ptr->data_size = m_mapCAPTURES[ptr->stream_id].size(); |
|
|
|
|
|
memcpy( ptr->data, m_mapCAPTURES[ptr->stream_id].data(), ptr->data_size ); |
|
|
|
|
|
m_mPictureProtector.unlock(); |
|
|
|
|
|
CSTR MD5 = MD5Binary( ptr->data, ptr->data_size ); |
|
|
|
|
|
if( MD5 ){ |
|
|
|
|
|
strncpy( ptr->md5, MD5, 32 ); |
|
|
|
|
|
free( MD5 ); |
|
|
|
|
|
if( !m_pDBC->addPicture( ptr, "jpg" ) ) LOG_ERROR("Database Error to consume capture!"); |
|
|
|
|
|
} else LOG_ERROR("no MD5 Hash!"); |
|
|
|
|
|
free( ptr->data ); |
|
|
|
|
|
} else { |
|
|
|
|
|
m_mPictureProtector.unlock(); |
|
|
|
|
|
LOG_ERROR("No memory to allocate!"); |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( m_sEmbedVideoData.output_mode & EVE_OUTPUT_PICTURES ){ |
|
|
|
|
|
LOG("Saving Picture!"); |
|
|
|
|
|
if( ptr->assoc_event_ids.size() ){ |
|
|
|
|
|
if( m_mapCAPTURES.find( ptr->stream_id ) != m_mapCAPTURES.end() ){ |
|
|
|
|
|
m_mPictureProtector.lock(); |
|
|
|
|
|
ptr->data = (uint8_t *) malloc( m_mapCAPTURES[ptr->stream_id].size() ); |
|
|
|
|
|
if( ptr->data ){ |
|
|
|
|
|
ptr->data_size = m_mapCAPTURES[ptr->stream_id].size(); |
|
|
|
|
|
memcpy( ptr->data, m_mapCAPTURES[ptr->stream_id].data(), ptr->data_size ); |
|
|
|
|
|
m_mPictureProtector.unlock(); |
|
|
|
|
|
CSTR MD5 = MD5Binary( ptr->data, ptr->data_size ); |
|
|
|
|
|
if( MD5 ){ |
|
|
|
|
|
strncpy( ptr->md5, MD5, 32 ); |
|
|
|
|
|
free( MD5 ); |
|
|
|
|
|
if( !m_pDBC->addPicture( ptr, "jpg" ) ) LOG_ERROR("Database Error to consume capture!"); |
|
|
|
|
|
} else LOG_ERROR("no MD5 Hash!"); |
|
|
|
|
|
free( ptr->data ); |
|
|
|
|
|
} else { |
|
|
|
|
|
m_mPictureProtector.unlock(); |
|
|
|
|
|
LOG_ERROR("No memory to allocate!"); |
|
|
|
|
|
}; |
|
|
#ifdef DEBUG
|
|
|
#ifdef DEBUG
|
|
|
else { |
|
|
|
|
|
LOG("No apropriate Stream Found!"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
LOG("No apropriate Stream Found!"); |
|
|
#endif
|
|
|
#endif
|
|
|
; |
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
}; |
|
|
|
|
|
}; |
|
|
|
|
|
if( m_sEmbedVideoData.output_mode & EVE_OUTPUT_VIDEO ){ |
|
|
|
|
|
LOG("Saving Video!"); |
|
|
|
|
|
if( ptr->assoc_event_ids.size() ){ |
|
|
|
|
|
mapSTREAMHANDLERS::iterator hnd = m_mapHANDLERS.find( ptr->stream_id ); |
|
|
|
|
|
if( hnd != m_mapHANDLERS.end() ){ |
|
|
|
|
|
uint32_t db_id; |
|
|
|
|
|
uint32_t cfrm; |
|
|
|
|
|
if( (*hnd).second->triggerEvent( db_id, cfrm ) ){ |
|
|
|
|
|
for( DBC_INT_LIST::iterator idx = ptr->assoc_event_ids.begin(); idx < ptr->assoc_event_ids.end(); idx++ ){ |
|
|
|
|
|
m_pDBC->addVideoEvent( (*idx), db_id, cfrm ); |
|
|
|
|
|
}; |
|
|
|
|
|
}; |
|
|
|
|
|
}; |
|
|
|
|
|
}; |
|
|
}; |
|
|
}; |
|
|
return true; |
|
|
return true; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
bool argusModuleEmbedVideo::saveStreamPicture( uint32_t id ){ |
|
|
bool argusModuleEmbedVideo::saveStreamPicture( uint32_t id ){ |
|
|
uint32_t retVal = 0; |
|
|
|
|
|
if( m_mapCAPTURES.find( id ) != m_mapCAPTURES.end() ){ |
|
|
|
|
|
FILE *tFD; |
|
|
|
|
|
m_mPictureProtector.lock(); |
|
|
|
|
|
size_t tBufferSize = m_mapCAPTURES[id].size(); |
|
|
|
|
|
uint8_t * tBuffer = (uint8_t *) malloc( tBufferSize ); |
|
|
|
|
|
if( tBuffer ){ |
|
|
|
|
|
memcpy( tBuffer, m_mapCAPTURES[id].data(), tBufferSize ); |
|
|
|
|
|
m_mPictureProtector.unlock(); |
|
|
|
|
|
CSTR MD5 = MD5Binary( tBuffer, tBufferSize ); |
|
|
|
|
|
if( MD5 ){ |
|
|
|
|
|
char tFileName[MAX_PATH]; |
|
|
|
|
|
if( generateSavePicPath( MD5, tFileName ) ){ |
|
|
|
|
|
FILE *fd = fopen( tFileName, "wb+" ); |
|
|
|
|
|
if( fd ){ |
|
|
|
|
|
fwrite(tBuffer, 1, tBufferSize, fd ); |
|
|
|
|
|
fclose(fd); |
|
|
|
|
|
chown( tFileName, "nobody", "nogroup" ); |
|
|
|
|
|
//retVal = m_pDBC->addPicture( id, MD5, "jpg" );
|
|
|
|
|
|
} else LOG_ERROR("Can not open picture file!"); |
|
|
|
|
|
} else LOG_ERROR("Can not generate file name!"); |
|
|
|
|
|
free(MD5); |
|
|
|
|
|
} else LOG_ERROR("no MD5 Hash!"); |
|
|
|
|
|
free(tBuffer); |
|
|
|
|
|
} else { |
|
|
|
|
|
m_mPictureProtector.unlock(); |
|
|
|
|
|
LOG_ERROR("no memory to allocate!"); |
|
|
|
|
|
|
|
|
if( !id ) return false; |
|
|
|
|
|
if( m_sEmbedVideoData.output_mode & EVE_OUTPUT_PICTURES ){ |
|
|
|
|
|
if( m_mapCAPTURES.find(id) != m_mapCAPTURES.end() ){ |
|
|
|
|
|
FILE * tFD; |
|
|
|
|
|
m_mPictureProtector.lock(); |
|
|
|
|
|
size_t tBufferSize = m_mapCAPTURES[id].size(); |
|
|
|
|
|
uint8_t * tBuffer = (uint8_t *) malloc( tBufferSize ); |
|
|
|
|
|
if( tBuffer ){ |
|
|
|
|
|
memcpy( tBuffer, m_mapCAPTURES[id].data(), tBufferSize ); |
|
|
|
|
|
m_mPictureProtector.unlock(); |
|
|
|
|
|
CSTR MD5 = MD5Binary( tBuffer, tBufferSize ); |
|
|
|
|
|
if( MD5 ){ |
|
|
|
|
|
char tFileName[MAX_PATH]; |
|
|
|
|
|
if( generateSavePicPath( MD5, tFileName ) ){ |
|
|
|
|
|
FILE *fd = fopen( tFileName, "wb+" ); |
|
|
|
|
|
if( fd ){ |
|
|
|
|
|
fwrite(tBuffer, 1, tBufferSize, fd ); |
|
|
|
|
|
fclose(fd); |
|
|
|
|
|
chown( tFileName, "nobody", "nogroup" ); |
|
|
|
|
|
//retVal = m_pDBC->addPicture( id, MD5, "jpg" );
|
|
|
|
|
|
} else LOG_ERROR("Can not open picture file!"); |
|
|
|
|
|
} else LOG_ERROR("Can not generate file name!"); |
|
|
|
|
|
free(MD5); |
|
|
|
|
|
} else LOG_ERROR("no MD5 Hash!"); |
|
|
|
|
|
free(tBuffer); |
|
|
|
|
|
} else { |
|
|
|
|
|
m_mPictureProtector.unlock(); |
|
|
|
|
|
LOG_ERROR("no memory to allocate!"); |
|
|
|
|
|
}; |
|
|
}; |
|
|
}; |
|
|
}; |
|
|
|
|
|
return retVal; |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
int argusModuleEmbedVideo::getWidh( void ){ |
|
|
int argusModuleEmbedVideo::getWidh( void ){ |
|
|
@ -948,13 +979,17 @@ streamHandler::streamHandler( argusModuleEmbedVideo *ptr, MS_WORK_MODE M ): m_pM |
|
|
m_nSegBFrameCounter = 0; |
|
|
m_nSegBFrameCounter = 0; |
|
|
m_nGlobalFrameCounter = 0; |
|
|
m_nGlobalFrameCounter = 0; |
|
|
m_nVideoRegisteredDBID = 0; |
|
|
m_nVideoRegisteredDBID = 0; |
|
|
m_nAlarmShiftFrames = 0; |
|
|
|
|
|
m_nNoAlarmSegmentFrames = 0; |
|
|
|
|
|
|
|
|
m_nSegAShiftFrames = 0; |
|
|
|
|
|
m_nSegBShiftFrames = 0; |
|
|
|
|
|
m_nSegASkippedFrames = m_nSegBSkippedFrames = 0; |
|
|
|
|
|
m_nSegmentLimitFrames = 0; |
|
|
m_nHardLimitFrames = 0; |
|
|
m_nHardLimitFrames = 0; |
|
|
m_bActiveEncoderStream = 0; |
|
|
m_bActiveEncoderStream = 0; |
|
|
m_bActiveSegmentNoDelete = false; |
|
|
|
|
|
m_bSegAActive = false; |
|
|
m_bSegAActive = false; |
|
|
|
|
|
m_bSegADelete = true; |
|
|
m_bSegBActive = false; |
|
|
m_bSegBActive = false; |
|
|
|
|
|
m_bSegBDelete = true; |
|
|
|
|
|
m_bCOP = 0; |
|
|
#endif //EVE_ENABLE_VIDEO
|
|
|
#endif //EVE_ENABLE_VIDEO
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
@ -1349,38 +1384,56 @@ bool streamHandler::pushFrame( cv::Mat &Frame, void* src ){ |
|
|
//m_nPreAlarmFrames
|
|
|
//m_nPreAlarmFrames
|
|
|
//m_nPostAlarmFrames
|
|
|
//m_nPostAlarmFrames
|
|
|
//m_nNoAlarmSegmentFrames
|
|
|
//m_nNoAlarmSegmentFrames
|
|
|
|
|
|
//m_nSegmentLimitFrames
|
|
|
//m_nHardLimitFrames
|
|
|
//m_nHardLimitFrames
|
|
|
|
|
|
|
|
|
if ( m_bSegAActive || m_bSegBActive ) { |
|
|
if ( m_bSegAActive || m_bSegBActive ) { |
|
|
|
|
|
|
|
|
m_mFrameCounterProtector.lock(); |
|
|
m_mFrameCounterProtector.lock(); |
|
|
//if ( ( m_nGlobalFrameCounter % 15 ) == 0 ) {
|
|
|
|
|
|
// char tB[64];
|
|
|
|
|
|
// m_mEncodingQueueProtector.lock();
|
|
|
|
|
|
// sprintf( tB, "in Queue %d Frames", m_qEncodingQueue.size() );
|
|
|
|
|
|
// m_mEncodingQueueProtector.unlock();
|
|
|
|
|
|
// LOG( tB );
|
|
|
|
|
|
//};
|
|
|
|
|
|
if (m_bSegAActive) { |
|
|
|
|
|
if( m_nSegAFrameCounter > m_nHardLimitFrames ){ |
|
|
|
|
|
closeSegmentA(); |
|
|
|
|
|
} else { |
|
|
|
|
|
int vCNT = m_nSegAFrameCounter - m_nAlarmShiftFrames; |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( m_bSegAActive ){ |
|
|
|
|
|
do { |
|
|
|
|
|
//In Any Case Close Stream if it Long enough
|
|
|
|
|
|
if( m_nSegAFrameCounter > m_nHardLimitFrames ){ |
|
|
|
|
|
LOG("HardLimit Reached!(A)"); |
|
|
|
|
|
closeSegmentA(); |
|
|
|
|
|
break; |
|
|
|
|
|
}; |
|
|
|
|
|
if( m_nSegAFrameCounter > ( m_nSegmentLimitFrames - ( m_nPostAlarmFrames + m_nPreAlarmFrames ))){ |
|
|
|
|
|
if ( !m_bSegBActive ){ |
|
|
|
|
|
LOG("Start Alt!(A)"); |
|
|
|
|
|
openSegmentB(); |
|
|
|
|
|
}; |
|
|
|
|
|
}; |
|
|
|
|
|
if( m_nSegAFrameCounter > ( m_nSegmentLimitFrames - m_nPostAlarmFrames ) && !m_bActiveEncoderStream ){ |
|
|
|
|
|
LOG("Swap Active!(A)"); |
|
|
|
|
|
swapActiveStreams(); |
|
|
|
|
|
break; |
|
|
|
|
|
}; |
|
|
|
|
|
} while ( 0 ); |
|
|
}; |
|
|
}; |
|
|
if( m_bSegBActive ) { |
|
|
|
|
|
if ( m_nSegBFrameCounter > m_nHardLimitFrames ) { |
|
|
|
|
|
closeSegmentB(); |
|
|
|
|
|
} else { |
|
|
|
|
|
int vCNT = m_nSegBFrameCounter - m_nAlarmShiftFrames; |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( m_bSegBActive ) { |
|
|
|
|
|
do { |
|
|
|
|
|
//In Any Case Close Stream if it Long enough
|
|
|
|
|
|
if( m_nSegBFrameCounter > m_nHardLimitFrames ){ |
|
|
|
|
|
LOG("HardLimit Reached!(B)"); |
|
|
|
|
|
closeSegmentB(); |
|
|
|
|
|
break; |
|
|
|
|
|
}; |
|
|
|
|
|
if( m_nSegBFrameCounter > ( m_nSegmentLimitFrames - ( m_nPostAlarmFrames + m_nPreAlarmFrames ))){ |
|
|
|
|
|
if ( !m_bSegAActive ){ |
|
|
|
|
|
LOG("Start Alt!(B)"); |
|
|
|
|
|
openSegmentA(); |
|
|
|
|
|
}; |
|
|
|
|
|
}; |
|
|
|
|
|
if( m_nSegBFrameCounter > ( m_nSegmentLimitFrames - m_nPostAlarmFrames ) && m_bActiveEncoderStream ){ |
|
|
|
|
|
LOG("Swap Active!(B)"); |
|
|
|
|
|
swapActiveStreams(); |
|
|
|
|
|
break; |
|
|
|
|
|
}; |
|
|
|
|
|
} while ( 0 ); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
m_mFrameCounterProtector.unlock(); |
|
|
m_mFrameCounterProtector.unlock(); |
|
|
|
|
|
|
|
|
ENCODING_BUFFER *tData = (ENCODING_BUFFER *) malloc( sizeof(ENCODING_BUFFER)); |
|
|
ENCODING_BUFFER *tData = (ENCODING_BUFFER *) malloc( sizeof(ENCODING_BUFFER)); |
|
|
@ -1397,88 +1450,11 @@ bool streamHandler::pushFrame( cv::Mat &Frame, void* src ){ |
|
|
m_qEncodingQueue.push( tData ); |
|
|
m_qEncodingQueue.push( tData ); |
|
|
m_mEncodingQueueProtector.unlock(); |
|
|
m_mEncodingQueueProtector.unlock(); |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
LOG_ERROR("MAT_CPY malloc Error!"); |
|
|
free( tData ); |
|
|
free( tData ); |
|
|
}; |
|
|
}; |
|
|
}; |
|
|
|
|
|
/*
|
|
|
|
|
|
const uint8_t* dataPTR[2]; |
|
|
|
|
|
dataPTR[0] = (uint8_t *) m_pMaster->m_mapMATS[tMD->mediaStreamId].data; |
|
|
|
|
|
dataPTR[1] = NULL; |
|
|
|
|
|
sws_scale( m_pConvertCtx, |
|
|
|
|
|
dataPTR, |
|
|
|
|
|
linesize, |
|
|
|
|
|
0, |
|
|
|
|
|
m_pMaster->m_mapMATS[tMD->mediaStreamId].rows, |
|
|
|
|
|
m_pAVFrame->data, |
|
|
|
|
|
m_pAVFrame->linesize |
|
|
|
|
|
); |
|
|
|
|
|
int bGotPacket; |
|
|
|
|
|
|
|
|
|
|
|
if ( ( m_nGlobalFrameCounter % m_sStreamData.fps ) == 0 ) { |
|
|
|
|
|
m_pAVFrame->key_frame = 1; |
|
|
|
|
|
m_pAVFrame->pict_type = AVPictureType::AV_PICTURE_TYPE_I; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
m_pAVFrame->pts = m_nGlobalFrameCounter + 1;//( m_nCurrentSegmentFrames % m_sStreamData.fps ) + 1;
|
|
|
|
|
|
|
|
|
|
|
|
AVPacket mPacket; |
|
|
|
|
|
|
|
|
|
|
|
av_init_packet( &mPacket ); |
|
|
|
|
|
/ * |
|
|
|
|
|
int ret = 0; |
|
|
|
|
|
do { |
|
|
|
|
|
if( ret == AVERROR(EAGAIN) ){ |
|
|
|
|
|
av_packet_unref( &mPacket ); |
|
|
|
|
|
ret = avcodec_receive_packet( m_pCodecCtx, &mPacket ); |
|
|
|
|
|
if( ret ) break; // deal with error
|
|
|
|
|
|
av_write_frame( m_pFormatCtxA, &mPacket ); |
|
|
|
|
|
} //else if(ret) deal with error
|
|
|
|
|
|
ret = avcodec_send_frame( m_pCodecCtx, m_pAVFrame ); |
|
|
|
|
|
} while(ret); |
|
|
|
|
|
* / |
|
|
|
|
|
//*
|
|
|
|
|
|
mPacket.data = NULL; |
|
|
|
|
|
mPacket.size = 0; |
|
|
|
|
|
avcodec_encode_video2( m_pCodecCtx, &mPacket, m_pAVFrame, &bGotPacket ); |
|
|
|
|
|
if( bGotPacket ){ |
|
|
|
|
|
//char bobo[64];
|
|
|
|
|
|
//if( m_pCodecCtx->coded_frame->key_frame ) {
|
|
|
|
|
|
// mPacket.flags |= AV_PKT_FLAG_KEY;
|
|
|
|
|
|
// sprintf( bobo, "k-frame [%d]", m_nCurrentSegmentFrames );
|
|
|
|
|
|
// LOG( bobo );
|
|
|
|
|
|
//} else {
|
|
|
|
|
|
// sprintf( bobo, "n-frame [%d]", m_nCurrentSegmentFrames );
|
|
|
|
|
|
// LOG( bobo );
|
|
|
|
|
|
//};
|
|
|
|
|
|
// write packet
|
|
|
|
|
|
if ( m_bSegAActive ) { |
|
|
|
|
|
mPacket.stream_index = m_pVideoStrA->index; |
|
|
|
|
|
mPacket.duration = 1; |
|
|
|
|
|
mPacket.pts = av_rescale_q( m_nSegAFrameCounter, m_pCodecCtx->time_base, m_pVideoStrA->time_base ); |
|
|
|
|
|
mPacket.dts = mPacket.pts; |
|
|
|
|
|
//av_packet_rescale_ts( &mPacket, m_pCodecCtx->time_base, m_pVideoStrA->time_base );
|
|
|
|
|
|
//if( av_interleaved_write_frame( m_pFormatCtxA, &mPacket ) < 0 ) LOG_ERROR( "Trouble with Video Output!" );
|
|
|
|
|
|
if( av_write_frame( m_pFormatCtxA, &mPacket ) < 0 ) LOG_ERROR("Trouble with Video Output A!"); |
|
|
|
|
|
m_nSegAFrameCounter++; |
|
|
|
|
|
}; |
|
|
|
|
|
if ( m_bSegBActive ) { |
|
|
|
|
|
mPacket.stream_index = m_pVideoStrB->index; |
|
|
|
|
|
mPacket.duration = 1; |
|
|
|
|
|
mPacket.pts = av_rescale_q( m_nSegBFrameCounter, m_pCodecCtx->time_base, m_pVideoStrB->time_base ); |
|
|
|
|
|
mPacket.dts = mPacket.pts; |
|
|
|
|
|
//av_packet_rescale_ts( &mPacket, m_pCodecCtx->time_base, m_pVideoStrB->time_base );
|
|
|
|
|
|
//if( av_interleaved_write_frame( m_pFormatCtxB, &mPacket ) < 0 ) LOG_ERROR( "Trouble with Video Output!" );
|
|
|
|
|
|
if( av_write_frame( m_pFormatCtxB, &mPacket) < 0 ) LOG_ERROR("Trouble with Video Output B!"); |
|
|
|
|
|
m_nSegBFrameCounter++; |
|
|
|
|
|
}; |
|
|
|
|
|
av_packet_unref( &mPacket ); |
|
|
|
|
|
m_nGlobalFrameCounter++; |
|
|
|
|
|
}; |
|
|
|
|
|
// av_free_packet(&mPacket);
|
|
|
|
|
|
//*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else LOG_ERROR("ENC_BUF malloc Error!"); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
#endif // EVE_ENABLE_VIDEO
|
|
|
#endif // EVE_ENABLE_VIDEO
|
|
|
m_pMaster->m_mPictureProtector.unlock(); |
|
|
m_pMaster->m_mPictureProtector.unlock(); |
|
|
} else { |
|
|
} else { |
|
|
@ -1531,41 +1507,93 @@ void streamHandler::closeAll(){ |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
bool streamHandler::openSegmentA( void ){ |
|
|
bool streamHandler::openSegmentA( void ){ |
|
|
CSTR tAM = getUniqID_MD5(); |
|
|
|
|
|
m_bSegAActive = false; |
|
|
|
|
|
if ( tAM ) { |
|
|
|
|
|
sprintf( m_cSegNameA, "%s.%s", tAM, VIDEO_OUTPUT_CONTAINER ); |
|
|
|
|
|
free( tAM ); |
|
|
|
|
|
if ( avio_open( &m_pFormatCtxA->pb, m_cSegNameA, AVIO_FLAG_WRITE ) < 0 ){ |
|
|
|
|
|
LOG_ERROR("Could not open output file."); |
|
|
|
|
|
return m_bSegAActive; |
|
|
|
|
|
}; |
|
|
|
|
|
if ( avformat_write_header( m_pFormatCtxA, &m_pFormatOpts ) < 0 ){ |
|
|
|
|
|
LOG_ERROR("Error occurred when writing header to output file."); |
|
|
|
|
|
return m_bSegAActive; |
|
|
|
|
|
|
|
|
if( !m_bSegAActive ){ |
|
|
|
|
|
CSTR tAM = getUniqID_MD5(); |
|
|
|
|
|
if ( tAM ) { |
|
|
|
|
|
sprintf( m_cSegNameA, "data/reports/%s.%s", tAM, VIDEO_OUTPUT_CONTAINER ); |
|
|
|
|
|
strncpy( m_cSegMD5A, tAM, 32 ); |
|
|
|
|
|
m_cSegMD5A[32] = (char)0; |
|
|
|
|
|
free( tAM ); |
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
LOG("Opening Stream A"); |
|
|
|
|
|
LOG(m_cSegNameA); |
|
|
|
|
|
char tB[128]; |
|
|
|
|
|
sprintf( tB, "FFPTS:%llu FNUM:%llu S2KF:%llu", m_pVideoStrA->start_time, m_pVideoStrA->nb_frames, m_pVideoStrA->first_dts ); |
|
|
|
|
|
LOG( tB ); |
|
|
|
|
|
sprintf( tB, "CON ST:%llu DUR:%llu", m_pFormatCtxA->start_time, m_pFormatCtxA->duration ); |
|
|
|
|
|
LOG( tB ); |
|
|
|
|
|
#endif
|
|
|
|
|
|
m_nSegASkippedFrames = m_pVideoStrA->nb_frames + 1; |
|
|
|
|
|
//if (m_pVideoStrA->nb_frames) {
|
|
|
|
|
|
// m_pVideoStrA->nb_frames = 0;
|
|
|
|
|
|
// m_pVideoStrA->start_time = 0;
|
|
|
|
|
|
// m_pVideoStrA->first_dts = 0;
|
|
|
|
|
|
// m_pFormatCtxA->start_time = 0;
|
|
|
|
|
|
//};
|
|
|
|
|
|
if (avio_open(&m_pFormatCtxA->pb, m_cSegNameA, AVIO_FLAG_WRITE) < 0) { |
|
|
|
|
|
LOG_ERROR("Could not open output file."); |
|
|
|
|
|
return m_bSegAActive; |
|
|
|
|
|
}; |
|
|
|
|
|
if ( avformat_write_header( m_pFormatCtxA, &m_pFormatOpts ) < 0 ){ |
|
|
|
|
|
LOG_ERROR("Error occurred when writing header to output file."); |
|
|
|
|
|
return m_bSegAActive; |
|
|
|
|
|
}; |
|
|
|
|
|
//m_mFrameCounterProtector.lock();
|
|
|
|
|
|
m_nSegAFrameCounter = 0; |
|
|
|
|
|
m_nSegAShiftFrames = 0; |
|
|
|
|
|
m_bSegAActive = true; |
|
|
|
|
|
m_bSegADelete = true; |
|
|
|
|
|
//m_mFrameCounterProtector.unlock();
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
LOG("Stream A Opened"); |
|
|
|
|
|
#endif
|
|
|
}; |
|
|
}; |
|
|
m_nSegAFrameCounter = 0; |
|
|
|
|
|
m_bSegAActive = true; |
|
|
|
|
|
}; |
|
|
}; |
|
|
return m_bSegAActive; |
|
|
return m_bSegAActive; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
bool streamHandler::openSegmentB( void ){ |
|
|
bool streamHandler::openSegmentB( void ){ |
|
|
CSTR tAM = getUniqID_MD5(); |
|
|
|
|
|
m_bSegBActive = false; |
|
|
|
|
|
if ( tAM ) { |
|
|
|
|
|
sprintf( m_cSegNameB, "%s.%s", tAM, VIDEO_OUTPUT_CONTAINER ); |
|
|
|
|
|
free( tAM ); |
|
|
|
|
|
if ( avio_open( &m_pFormatCtxB->pb, m_cSegNameB, AVIO_FLAG_WRITE ) < 0 ){ |
|
|
|
|
|
LOG_ERROR("Could not open output file."); |
|
|
|
|
|
return m_bSegBActive; |
|
|
|
|
|
}; |
|
|
|
|
|
if ( avformat_write_header( m_pFormatCtxB, &m_pFormatOpts ) < 0 ){ |
|
|
|
|
|
LOG_ERROR("Error occurred when writing header to output file."); |
|
|
|
|
|
return m_bSegBActive; |
|
|
|
|
|
|
|
|
if( !m_bSegBActive ){ |
|
|
|
|
|
CSTR tAM = getUniqID_MD5(); |
|
|
|
|
|
if ( tAM ) { |
|
|
|
|
|
sprintf( m_cSegNameB, "data/reports/%s.%s", tAM, VIDEO_OUTPUT_CONTAINER ); |
|
|
|
|
|
strncpy( m_cSegMD5B, tAM, 32 ); |
|
|
|
|
|
m_cSegMD5B[32] = (char)0; |
|
|
|
|
|
free( tAM ); |
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
LOG("Opening Stream B"); |
|
|
|
|
|
LOG(m_cSegNameB); |
|
|
|
|
|
char tB[128]; |
|
|
|
|
|
sprintf( tB, "FFPTS:%llu FNUM:%llu S2KF:%llu", m_pVideoStrB->start_time, m_pVideoStrB->nb_frames, m_pVideoStrB->first_dts ); |
|
|
|
|
|
LOG( tB ); |
|
|
|
|
|
sprintf( tB, "CON ST:%llu DUR:%llu", m_pFormatCtxB->start_time, m_pFormatCtxB->duration ); |
|
|
|
|
|
LOG( tB ); |
|
|
|
|
|
#endif
|
|
|
|
|
|
m_nSegBSkippedFrames = m_pVideoStrB->nb_frames + 1; |
|
|
|
|
|
//if (m_pVideoStrB->nb_frames) {
|
|
|
|
|
|
// m_pVideoStrB->nb_frames = 0;
|
|
|
|
|
|
// m_pVideoStrB->start_time = 0;
|
|
|
|
|
|
// m_pVideoStrB->first_dts = 0;
|
|
|
|
|
|
// m_pFormatCtxB->start_time = 0;
|
|
|
|
|
|
//};
|
|
|
|
|
|
if ( avio_open( &m_pFormatCtxB->pb, m_cSegNameB, AVIO_FLAG_WRITE ) < 0 ){ |
|
|
|
|
|
LOG_ERROR("Could not open output file."); |
|
|
|
|
|
return m_bSegBActive; |
|
|
|
|
|
}; |
|
|
|
|
|
if ( avformat_write_header( m_pFormatCtxB, &m_pFormatOpts ) < 0 ){ |
|
|
|
|
|
LOG_ERROR("Error occurred when writing header to output file."); |
|
|
|
|
|
return m_bSegBActive; |
|
|
|
|
|
}; |
|
|
|
|
|
//m_mFrameCounterProtector.lock();
|
|
|
|
|
|
m_nSegBFrameCounter = 0; |
|
|
|
|
|
m_nSegBShiftFrames = 0; |
|
|
|
|
|
m_bSegBActive = true; |
|
|
|
|
|
m_bSegBDelete = true; |
|
|
|
|
|
//m_mFrameCounterProtector.unlock();
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
LOG("Stream B Opened"); |
|
|
|
|
|
#endif
|
|
|
}; |
|
|
}; |
|
|
m_nSegBFrameCounter = 0; |
|
|
|
|
|
m_bSegBActive = true; |
|
|
|
|
|
}; |
|
|
}; |
|
|
return m_bSegBActive; |
|
|
return m_bSegBActive; |
|
|
}; |
|
|
}; |
|
|
@ -1573,7 +1601,7 @@ bool streamHandler::openSegmentB( void ){ |
|
|
bool streamHandler::initVideoOutput(){ |
|
|
bool streamHandler::initVideoOutput(){ |
|
|
m_nPreAlarmFrames = ( PRE_ALARM_TIME_MILSECONDS * m_sStreamData.fps ) / 1000; |
|
|
m_nPreAlarmFrames = ( PRE_ALARM_TIME_MILSECONDS * m_sStreamData.fps ) / 1000; |
|
|
m_nPostAlarmFrames = ( POST_ALARM_TIME_MILSECONDS * m_sStreamData.fps ) / 1000; |
|
|
m_nPostAlarmFrames = ( POST_ALARM_TIME_MILSECONDS * m_sStreamData.fps ) / 1000; |
|
|
m_nNoAlarmSegmentFrames = ( ENCODING_SEGMENT_MILSECONDS * m_sStreamData.fps ) / 1000; |
|
|
|
|
|
|
|
|
m_nSegmentLimitFrames = ( ENCODING_SEGMENT_MILSECONDS * m_sStreamData.fps ) / 1000; |
|
|
m_nHardLimitFrames = ( ENCODING_SEGMENT_LIMIT_MILSECONDS * m_sStreamData.fps ) / 1000; |
|
|
m_nHardLimitFrames = ( ENCODING_SEGMENT_LIMIT_MILSECONDS * m_sStreamData.fps ) / 1000; |
|
|
|
|
|
|
|
|
if( !initLibAV() ) return false; |
|
|
if( !initLibAV() ) return false; |
|
|
@ -1583,9 +1611,11 @@ bool streamHandler::initVideoOutput(){ |
|
|
if ( m_pFormat == NULL ) { |
|
|
if ( m_pFormat == NULL ) { |
|
|
LOG_ERROR("Out VideoFormat Not Found!"); |
|
|
LOG_ERROR("Out VideoFormat Not Found!"); |
|
|
return false; |
|
|
return false; |
|
|
|
|
|
#ifdef DEBUG
|
|
|
} else { |
|
|
} else { |
|
|
LOG("Output video Format"); |
|
|
LOG("Output video Format"); |
|
|
LOG( VIDEO_OUTPUT_CONTAINER ); |
|
|
LOG( VIDEO_OUTPUT_CONTAINER ); |
|
|
|
|
|
#endif
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
if ( avformat_alloc_output_context2( &m_pFormatCtxA, m_pFormat, NULL, "test." VIDEO_OUTPUT_CONTAINER ) < 0 ) { |
|
|
if ( avformat_alloc_output_context2( &m_pFormatCtxA, m_pFormat, NULL, "test." VIDEO_OUTPUT_CONTAINER ) < 0 ) { |
|
|
@ -1600,7 +1630,7 @@ bool streamHandler::initVideoOutput(){ |
|
|
if ( avformat_alloc_output_context2( &m_pFormatCtxB, m_pFormat, NULL, "test." VIDEO_OUTPUT_CONTAINER ) < 0 ) { |
|
|
if ( avformat_alloc_output_context2( &m_pFormatCtxB, m_pFormat, NULL, "test." VIDEO_OUTPUT_CONTAINER ) < 0 ) { |
|
|
LOG_ERROR("Format CTX B alloc error!"); |
|
|
LOG_ERROR("Format CTX B alloc error!"); |
|
|
avformat_free_context( m_pFormatCtxA ); |
|
|
avformat_free_context( m_pFormatCtxA ); |
|
|
av_free( m_pFormat ); |
|
|
|
|
|
|
|
|
//av_free( m_pFormat );
|
|
|
return false; |
|
|
return false; |
|
|
} else { |
|
|
} else { |
|
|
av_dict_set( &m_pFormatCtxB->metadata, "Author", "Argus Sec. System", 0 ); |
|
|
av_dict_set( &m_pFormatCtxB->metadata, "Author", "Argus Sec. System", 0 ); |
|
|
@ -1612,10 +1642,12 @@ bool streamHandler::initVideoOutput(){ |
|
|
LOG_ERROR("Out VideoCodec Not Found!"); |
|
|
LOG_ERROR("Out VideoCodec Not Found!"); |
|
|
avformat_free_context( m_pFormatCtxA ); |
|
|
avformat_free_context( m_pFormatCtxA ); |
|
|
avformat_free_context( m_pFormatCtxB ); |
|
|
avformat_free_context( m_pFormatCtxB ); |
|
|
av_free( m_pFormat ); |
|
|
|
|
|
|
|
|
//av_free( m_pFormat );
|
|
|
return false; |
|
|
return false; |
|
|
|
|
|
#ifdef DEBUG
|
|
|
} else { |
|
|
} else { |
|
|
LOG("Out Video Codec Found"); |
|
|
LOG("Out Video Codec Found"); |
|
|
|
|
|
#endif
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
m_pCodecCtx = avcodec_alloc_context3( m_pVideoCodec ); |
|
|
m_pCodecCtx = avcodec_alloc_context3( m_pVideoCodec ); |
|
|
@ -1624,10 +1656,12 @@ bool streamHandler::initVideoOutput(){ |
|
|
av_free( m_pVideoCodec ); |
|
|
av_free( m_pVideoCodec ); |
|
|
avformat_free_context( m_pFormatCtxA ); |
|
|
avformat_free_context( m_pFormatCtxA ); |
|
|
avformat_free_context( m_pFormatCtxB ); |
|
|
avformat_free_context( m_pFormatCtxB ); |
|
|
av_free( m_pFormat ); |
|
|
|
|
|
|
|
|
//av_free( m_pFormat );
|
|
|
return false; |
|
|
return false; |
|
|
|
|
|
#ifdef DEBUG
|
|
|
} else { |
|
|
} else { |
|
|
LOG("Out Codec Context3 Allocated"); |
|
|
LOG("Out Codec Context3 Allocated"); |
|
|
|
|
|
#endif
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
m_pVideoStrA = avformat_new_stream( m_pFormatCtxA, m_pVideoCodec ); |
|
|
m_pVideoStrA = avformat_new_stream( m_pFormatCtxA, m_pVideoCodec ); |
|
|
@ -1638,10 +1672,12 @@ bool streamHandler::initVideoOutput(){ |
|
|
av_free( m_pVideoCodec ); |
|
|
av_free( m_pVideoCodec ); |
|
|
avformat_free_context( m_pFormatCtxA ); |
|
|
avformat_free_context( m_pFormatCtxA ); |
|
|
avformat_free_context( m_pFormatCtxB ); |
|
|
avformat_free_context( m_pFormatCtxB ); |
|
|
av_free( m_pFormat ); |
|
|
|
|
|
|
|
|
//av_free( m_pFormat );
|
|
|
return false; |
|
|
return false; |
|
|
}else{ |
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
} else { |
|
|
LOG("VideoStream A is Created"); |
|
|
LOG("VideoStream A is Created"); |
|
|
|
|
|
#endif
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
m_pVideoStrB = avformat_new_stream( m_pFormatCtxB, m_pVideoCodec ); |
|
|
m_pVideoStrB = avformat_new_stream( m_pFormatCtxB, m_pVideoCodec ); |
|
|
@ -1654,8 +1690,10 @@ bool streamHandler::initVideoOutput(){ |
|
|
avformat_free_context( m_pFormatCtxB ); |
|
|
avformat_free_context( m_pFormatCtxB ); |
|
|
av_free( m_pFormat ); |
|
|
av_free( m_pFormat ); |
|
|
return false; |
|
|
return false; |
|
|
|
|
|
#ifdef DEBUG
|
|
|
} else { |
|
|
} else { |
|
|
LOG("VideoStream B is Created"); |
|
|
LOG("VideoStream B is Created"); |
|
|
|
|
|
#endif
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
m_pCodecCtx->codec_id = VIDEO_OUTPUT_CODEC; |
|
|
m_pCodecCtx->codec_id = VIDEO_OUTPUT_CODEC; |
|
|
@ -1687,7 +1725,9 @@ bool streamHandler::initVideoOutput(){ |
|
|
// https://stackoverflow.com/questions/70060148/libav-producing-mp4-file-with-extremely-high-frame-rate
|
|
|
// https://stackoverflow.com/questions/70060148/libav-producing-mp4-file-with-extremely-high-frame-rate
|
|
|
|
|
|
|
|
|
if( ( m_pCodecCtx->codec_id == AV_CODEC_ID_H264 ) || ( m_pCodecCtx->codec_id == AV_CODEC_ID_H265 ) ){ |
|
|
if( ( m_pCodecCtx->codec_id == AV_CODEC_ID_H264 ) || ( m_pCodecCtx->codec_id == AV_CODEC_ID_H265 ) ){ |
|
|
|
|
|
#ifdef DEBUG
|
|
|
LOG("Begin Options!"); |
|
|
LOG("Begin Options!"); |
|
|
|
|
|
#endif
|
|
|
//Reference for AvFormatContext options : https://ffmpeg.org/doxygen/2.8/movenc_8c_source.html
|
|
|
//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()
|
|
|
//Set format's privater options, to be passed to avformat_write_header()
|
|
|
|
|
|
|
|
|
@ -1703,6 +1743,7 @@ bool streamHandler::initVideoOutput(){ |
|
|
isml E..... Create a live smooth streaming feed (for pushing to a publishing point) |
|
|
isml E..... Create a live smooth streaming feed (for pushing to a publishing point) |
|
|
faststart E..... Run a second pass to put the index (moov atom) at the beginning of the file |
|
|
faststart E..... Run a second pass to put the index (moov atom) at the beginning of the file |
|
|
omit_tfhd_offset E..... Omit the base data offset in tfhd atoms |
|
|
omit_tfhd_offset E..... Omit the base data offset in tfhd atoms |
|
|
|
|
|
delay_moov ?? |
|
|
-moov_size E..... maximum moov size so it can be placed at the begin (from 0 to INT_MAX) (default 0) |
|
|
-moov_size E..... maximum moov size so it can be placed at the begin (from 0 to INT_MAX) (default 0) |
|
|
-rtpflags E..... RTP muxer flags (default 0) |
|
|
-rtpflags E..... RTP muxer flags (default 0) |
|
|
latm E..... Use MP4A-LATM packetization instead of MPEG4-GENERIC for AAC |
|
|
latm E..... Use MP4A-LATM packetization instead of MPEG4-GENERIC for AAC |
|
|
@ -1722,12 +1763,18 @@ bool streamHandler::initVideoOutput(){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
if( av_dict_set( &m_pFormatOpts, "movflags", "frag_keyframe+empty_moov", 0 ) < 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!"); |
|
|
LOG_ERROR( "av_dict_set movflags!"); |
|
|
|
|
|
#ifdef DEBUG
|
|
|
} else { |
|
|
} else { |
|
|
LOG("MOV FLAG SET!"); |
|
|
LOG("MOV FLAG SET!"); |
|
|
|
|
|
#endif
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
//if( av_dict_set( &m_pFormatOpts, "live", "1", 0 ) < 0 ){
|
|
|
|
|
|
// LOG_ERROR( "av_dict_set live!" );
|
|
|
|
|
|
//};
|
|
|
|
|
|
|
|
|
//default brand is "isom", which fails on some devices
|
|
|
//default brand is "isom", which fails on some devices
|
|
|
if( av_dict_set( &m_pFormatOpts, "brand", "mp42", 0) < 0 ){ |
|
|
if( av_dict_set( &m_pFormatOpts, "brand", "mp42", 0) < 0 ){ |
|
|
LOG_ERROR( "av_dict_set brand!" ); |
|
|
LOG_ERROR( "av_dict_set brand!" ); |
|
|
@ -1765,8 +1812,9 @@ bool streamHandler::initVideoOutput(){ |
|
|
/// Disable b-pyramid. CLI options for this is "-b-pyramid 0"
|
|
|
/// Disable b-pyramid. CLI options for this is "-b-pyramid 0"
|
|
|
/// Because Quicktime (ie. iOS) doesn't support this option
|
|
|
/// Because Quicktime (ie. iOS) doesn't support this option
|
|
|
av_opt_set( m_pCodecCtx->priv_data, "b-pyramid", "0", 0 ); |
|
|
av_opt_set( m_pCodecCtx->priv_data, "b-pyramid", "0", 0 ); |
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
LOG("End Options!"); |
|
|
LOG("End Options!"); |
|
|
|
|
|
#endif
|
|
|
} else { |
|
|
} else { |
|
|
if( m_pFormat->flags & AVFMT_GLOBALHEADER ) m_pCodecCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; |
|
|
if( m_pFormat->flags & AVFMT_GLOBALHEADER ) m_pCodecCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; |
|
|
}; |
|
|
}; |
|
|
@ -1776,9 +1824,16 @@ bool streamHandler::initVideoOutput(){ |
|
|
|
|
|
|
|
|
const AVRational dst_fps = { m_sStreamData.fps, 1 }; |
|
|
const AVRational dst_fps = { m_sStreamData.fps, 1 }; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
char TB[129]; |
|
|
|
|
|
sprintf(TB, "TimeBase: num[%d]/den[%d]", m_pCodecCtx->time_base.num, m_pCodecCtx->time_base.den ); |
|
|
|
|
|
LOG(TB); |
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
m_pVideoStrA->time_base = m_pCodecCtx->time_base; |
|
|
m_pVideoStrA->time_base = m_pCodecCtx->time_base; |
|
|
m_pVideoStrB->time_base = m_pCodecCtx->time_base; |
|
|
m_pVideoStrB->time_base = m_pCodecCtx->time_base; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//avcodec_get_context_defaults3( m_pVideoStrA->codec, m_pVideoCodec );
|
|
|
//avcodec_get_context_defaults3( m_pVideoStrA->codec, m_pVideoCodec );
|
|
|
|
|
|
|
|
|
//m_pVideoStrA->codec->width = m_pMaster->m_sEmbedVideoData.width;
|
|
|
//m_pVideoStrA->codec->width = m_pMaster->m_sEmbedVideoData.width;
|
|
|
@ -1813,9 +1868,15 @@ bool streamHandler::initVideoOutput(){ |
|
|
if ( avcodec_open2( m_pCodecCtx, m_pVideoCodec, NULL) < 0 ) { |
|
|
if ( avcodec_open2( m_pCodecCtx, m_pVideoCodec, NULL) < 0 ) { |
|
|
LOG_ERROR("Error opening2 encoder"); |
|
|
LOG_ERROR("Error opening2 encoder"); |
|
|
return false; |
|
|
return false; |
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
} else { |
|
|
|
|
|
LOG("output codec context is opened"); |
|
|
}; |
|
|
}; |
|
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
} else { |
|
|
} else { |
|
|
LOG("output codec context is opened"); |
|
|
|
|
|
|
|
|
LOG("output codec context is already opened"); |
|
|
|
|
|
#endif
|
|
|
}; |
|
|
}; |
|
|
m_pConvertCtx = sws_getContext( |
|
|
m_pConvertCtx = sws_getContext( |
|
|
m_pMaster->m_sEmbedVideoData.width, |
|
|
m_pMaster->m_sEmbedVideoData.width, |
|
|
@ -1843,9 +1904,10 @@ bool streamHandler::initVideoOutput(){ |
|
|
m_pAVFrame->width = m_pMaster->m_sEmbedVideoData.width; |
|
|
m_pAVFrame->width = m_pMaster->m_sEmbedVideoData.width; |
|
|
m_pAVFrame->height = m_pMaster->m_sEmbedVideoData.height; |
|
|
m_pAVFrame->height = m_pMaster->m_sEmbedVideoData.height; |
|
|
m_pAVFrame->format = VIDEO_OUTPUT_PIX_FMT; |
|
|
m_pAVFrame->format = VIDEO_OUTPUT_PIX_FMT; |
|
|
//avpicture_fill ((AVPicture *) picture, picture_buf, pix_fmt, width, height);
|
|
|
|
|
|
|
|
|
//av_frame_get_buffer( m_pAVFrame, 0 );
|
|
|
av_image_fill_arrays ( m_pAVFrame->data, m_pAVFrame->linesize, m_pOutBuffer, VIDEO_OUTPUT_PIX_FMT, m_pMaster->m_sEmbedVideoData.width, m_pMaster->m_sEmbedVideoData.height, 1 ); |
|
|
av_image_fill_arrays ( m_pAVFrame->data, m_pAVFrame->linesize, m_pOutBuffer, VIDEO_OUTPUT_PIX_FMT, m_pMaster->m_sEmbedVideoData.width, m_pMaster->m_sEmbedVideoData.height, 1 ); |
|
|
//avpicture_fill((AVPicture *)m_pAVFrame, m_pOutBuffer, VIDEO_OUTPUT_PIX_FMT, m_pMaster->m_sEmbedVideoData.width, m_pMaster->m_sEmbedVideoData.height );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//av_frame_make_writable( m_pAVFrame );
|
|
|
|
|
|
|
|
|
return init(); |
|
|
return init(); |
|
|
}; |
|
|
}; |
|
|
@ -1856,6 +1918,7 @@ void streamHandler::m_fThreadProc( void ){ |
|
|
AVPacket mPacket; |
|
|
AVPacket mPacket; |
|
|
int bGotPacket; |
|
|
int bGotPacket; |
|
|
int rVal = 0; |
|
|
int rVal = 0; |
|
|
|
|
|
char tB[128]; |
|
|
|
|
|
|
|
|
av_init_packet( &mPacket ); |
|
|
av_init_packet( &mPacket ); |
|
|
while( m_bThreadStatus != TH_ENDED ){ |
|
|
while( m_bThreadStatus != TH_ENDED ){ |
|
|
@ -1865,163 +1928,160 @@ void streamHandler::m_fThreadProc( void ){ |
|
|
m_bThreadStatus = TH_ENDED; |
|
|
m_bThreadStatus = TH_ENDED; |
|
|
continue; |
|
|
continue; |
|
|
}; |
|
|
}; |
|
|
if( !openSegmentB() ){ |
|
|
|
|
|
m_bThreadStatus = TH_ENDED; |
|
|
|
|
|
continue; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
//if( !openSegmentB() ){
|
|
|
|
|
|
// m_bThreadStatus = TH_ENDED;
|
|
|
|
|
|
// continue;
|
|
|
|
|
|
//};
|
|
|
m_bThreadStatus = TH_WORKING; |
|
|
m_bThreadStatus = TH_WORKING; |
|
|
continue; |
|
|
continue; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
m_mCurrentOperationProtector.lock(); |
|
|
|
|
|
switch ( m_bCOP ) { |
|
|
|
|
|
case 0x01:{ |
|
|
|
|
|
m_bSegAActive = false; |
|
|
|
|
|
av_write_trailer( m_pFormatCtxA ); |
|
|
|
|
|
avio_close( m_pFormatCtxA->pb ); |
|
|
|
|
|
|
|
|
|
|
|
LOG("Stream A is Closed"); |
|
|
|
|
|
//m_bThreadStatus = TH_ENDED;
|
|
|
|
|
|
//m_mCurrentOperationProtector.unlock();
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
}; |
|
|
|
|
|
case 0x02:{ |
|
|
|
|
|
m_bSegBActive = false; |
|
|
|
|
|
av_write_trailer( m_pFormatCtxB ); |
|
|
|
|
|
avio_close( m_pFormatCtxB->pb ); |
|
|
|
|
|
|
|
|
|
|
|
LOG("Stream B is Closed"); |
|
|
|
|
|
//m_bThreadStatus = TH_ENDED;
|
|
|
|
|
|
//m_mCurrentOperationProtector.unlock();
|
|
|
|
|
|
//continue;
|
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
}; |
|
|
|
|
|
}; |
|
|
|
|
|
m_bCOP = 0; |
|
|
|
|
|
m_mCurrentOperationProtector.unlock(); |
|
|
|
|
|
|
|
|
|
|
|
m_mEncodingQueueProtector.lock(); |
|
|
m_mEncodingQueueProtector.lock(); |
|
|
if ( m_qEncodingQueue.size() ) { |
|
|
if ( m_qEncodingQueue.size() ) { |
|
|
ENCODING_BUFFER *tData = m_qEncodingQueue.front(); |
|
|
ENCODING_BUFFER *tData = m_qEncodingQueue.front(); |
|
|
if( tData ){ |
|
|
if( tData ){ |
|
|
|
|
|
//av_frame_make_writable( m_pAVFrame );
|
|
|
sws_scale( m_pConvertCtx, tData->data, tData->linesize, 0, tData->rows, m_pAVFrame->data, m_pAVFrame->linesize ); |
|
|
sws_scale( m_pConvertCtx, tData->data, tData->linesize, 0, tData->rows, m_pAVFrame->data, m_pAVFrame->linesize ); |
|
|
free( tData->data[0] ); |
|
|
free( tData->data[0] ); |
|
|
free( tData ); |
|
|
free( tData ); |
|
|
m_qEncodingQueue.pop(); |
|
|
m_qEncodingQueue.pop(); |
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AV_PICTURE_TYPE_NONE Undefined. |
|
|
|
|
|
AV_PICTURE_TYPE_I Intra. |
|
|
|
|
|
AV_PICTURE_TYPE_P Predicted. |
|
|
|
|
|
AV_PICTURE_TYPE_B Bi-dir predicted. |
|
|
|
|
|
AV_PICTURE_TYPE_S S(GMC)-VOP MPEG4. |
|
|
|
|
|
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 ) { |
|
|
if ( ( m_nGlobalFrameCounter % m_sStreamData.fps ) == 0 ) { |
|
|
m_pAVFrame->key_frame = 1; |
|
|
m_pAVFrame->key_frame = 1; |
|
|
m_pAVFrame->pict_type = AVPictureType::AV_PICTURE_TYPE_I; |
|
|
m_pAVFrame->pict_type = AVPictureType::AV_PICTURE_TYPE_I; |
|
|
|
|
|
} else { |
|
|
|
|
|
m_pAVFrame->key_frame = 0; |
|
|
|
|
|
m_pAVFrame->pict_type = AVPictureType::AV_PICTURE_TYPE_NONE; |
|
|
}; |
|
|
}; |
|
|
m_pAVFrame->pts = m_nGlobalFrameCounter + 1; |
|
|
m_pAVFrame->pts = m_nGlobalFrameCounter + 1; |
|
|
|
|
|
|
|
|
rVal = avcodec_send_frame( m_pCodecCtx, m_pAVFrame ); |
|
|
rVal = avcodec_send_frame( m_pCodecCtx, m_pAVFrame ); |
|
|
|
|
|
m_mFrameCounterProtector.lock(); |
|
|
|
|
|
m_nGlobalFrameCounter++; |
|
|
|
|
|
if ( m_bSegAActive ) m_nSegAFrameCounter++; |
|
|
|
|
|
if ( m_bSegBActive ) m_nSegBFrameCounter++; |
|
|
|
|
|
m_mFrameCounterProtector.unlock(); |
|
|
|
|
|
}; |
|
|
|
|
|
m_mEncodingQueueProtector.unlock(); |
|
|
|
|
|
} else { |
|
|
|
|
|
m_mEncodingQueueProtector.unlock(); |
|
|
|
|
|
// If No Encode Job -> Test Commands!
|
|
|
|
|
|
m_mCurrentOperationProtector.lock(); |
|
|
|
|
|
switch ( m_bCOP ) { |
|
|
|
|
|
case 0x01:{ |
|
|
|
|
|
m_bSegAActive = false; |
|
|
|
|
|
if ( !m_bSegADelete ) { |
|
|
|
|
|
av_write_trailer( m_pFormatCtxA ); |
|
|
|
|
|
avio_close( m_pFormatCtxA->pb ); |
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
LOG("Stream A is Closed"); |
|
|
|
|
|
#endif
|
|
|
|
|
|
} else { |
|
|
|
|
|
#ifdef EVE_DONT_DELETE_SEGMENTS
|
|
|
|
|
|
av_write_trailer( m_pFormatCtxA ); |
|
|
|
|
|
#endif
|
|
|
|
|
|
avio_close( m_pFormatCtxA->pb ); |
|
|
|
|
|
#ifndef EVE_DONT_DELETE_SEGMENTS
|
|
|
|
|
|
unlink( m_cSegNameA ); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
LOG("Stream A is Deleted!"); |
|
|
|
|
|
#endif
|
|
|
|
|
|
}; |
|
|
|
|
|
break; |
|
|
|
|
|
}; |
|
|
|
|
|
case 0x02:{ |
|
|
|
|
|
m_bSegBActive = false; |
|
|
|
|
|
if ( !m_bSegBDelete ) { |
|
|
|
|
|
av_write_trailer( m_pFormatCtxB ); |
|
|
|
|
|
avio_close( m_pFormatCtxB->pb ); |
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
LOG("Stream B is Closed"); |
|
|
|
|
|
#endif
|
|
|
|
|
|
} else { |
|
|
|
|
|
#ifdef EVE_DONT_DELETE_SEGMENTS
|
|
|
|
|
|
av_write_trailer( m_pFormatCtxB ); |
|
|
|
|
|
#endif
|
|
|
|
|
|
avio_close( m_pFormatCtxB->pb ); |
|
|
|
|
|
#ifndef EVE_DONT_DELETE_SEGMENTS
|
|
|
|
|
|
unlink( m_cSegNameB ); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
LOG("Stream B is Deleted!"); |
|
|
|
|
|
#endif
|
|
|
|
|
|
}; |
|
|
|
|
|
break; |
|
|
|
|
|
}; |
|
|
}; |
|
|
}; |
|
|
|
|
|
m_bCOP = 0; |
|
|
|
|
|
m_mCurrentOperationProtector.unlock(); |
|
|
}; |
|
|
}; |
|
|
m_mEncodingQueueProtector.unlock(); |
|
|
|
|
|
|
|
|
|
|
|
if ( rVal == AVERROR(EAGAIN) ) { |
|
|
|
|
|
|
|
|
do { |
|
|
mPacket.data = NULL; |
|
|
mPacket.data = NULL; |
|
|
mPacket.size = 0; |
|
|
mPacket.size = 0; |
|
|
rVal = avcodec_receive_packet( m_pCodecCtx, &mPacket ); |
|
|
rVal = avcodec_receive_packet( m_pCodecCtx, &mPacket ); |
|
|
if ( !rVal ){ |
|
|
|
|
|
|
|
|
if( rVal == AVERROR(EAGAIN) || rVal == AVERROR_EOF ){ |
|
|
|
|
|
break; |
|
|
|
|
|
} else if( rVal < 0 ){ |
|
|
|
|
|
LOG_ERROR( "Error during encoding " ); |
|
|
|
|
|
m_bThreadStatus = TH_ENDED; |
|
|
|
|
|
break; |
|
|
|
|
|
}; |
|
|
|
|
|
if( !rVal ){ |
|
|
if ( m_bSegAActive ) { |
|
|
if ( m_bSegAActive ) { |
|
|
mPacket.stream_index = m_pVideoStrA->index; |
|
|
mPacket.stream_index = m_pVideoStrA->index; |
|
|
mPacket.duration = 1; |
|
|
mPacket.duration = 1; |
|
|
mPacket.pts = av_rescale_q( m_nSegAFrameCounter, m_pCodecCtx->time_base, m_pVideoStrA->time_base ); |
|
|
|
|
|
|
|
|
mPacket.pts = av_rescale_q( m_nGlobalFrameCounter, m_pCodecCtx->time_base, m_pVideoStrA->time_base ); |
|
|
|
|
|
//mPacket.pts = AV_NOPTS_VALUE;
|
|
|
|
|
|
//mPacket.pts = av_rescale_q( m_nSegASkippedFrames + m_nSegAFrameCounter, m_pCodecCtx->time_base, m_pVideoStrA->time_base );
|
|
|
mPacket.dts = mPacket.pts; |
|
|
mPacket.dts = mPacket.pts; |
|
|
if( av_write_frame( m_pFormatCtxA, &mPacket ) < 0 ){ |
|
|
|
|
|
|
|
|
int rc = av_write_frame( m_pFormatCtxA, &mPacket ); |
|
|
|
|
|
if( rc < 0 ){ |
|
|
|
|
|
//if( av_interleaved_write_frame( m_pFormatCtxA, &mPacket) < 0 ) {
|
|
|
m_bThreadStatus = TH_ENDED; |
|
|
m_bThreadStatus = TH_ENDED; |
|
|
LOG_ERROR("Trouble with Video Output A!"); |
|
|
LOG_ERROR("Trouble with Video Output A!"); |
|
|
continue; |
|
|
|
|
|
|
|
|
av_strerror( rc, tB, 128 ); |
|
|
|
|
|
LOG_ERROR( tB ); |
|
|
|
|
|
break; //continue (changed since embed into do-while)
|
|
|
}; |
|
|
}; |
|
|
m_nSegAFrameCounter++; |
|
|
|
|
|
}; |
|
|
}; |
|
|
if ( m_bSegBActive ) { |
|
|
if ( m_bSegBActive ) { |
|
|
mPacket.stream_index = m_pVideoStrB->index; |
|
|
mPacket.stream_index = m_pVideoStrB->index; |
|
|
mPacket.duration = 1; |
|
|
mPacket.duration = 1; |
|
|
mPacket.pts = av_rescale_q( m_nSegBFrameCounter, m_pCodecCtx->time_base, m_pVideoStrB->time_base ); |
|
|
|
|
|
|
|
|
mPacket.pts = av_rescale_q( m_nGlobalFrameCounter, m_pCodecCtx->time_base, m_pVideoStrA->time_base ); |
|
|
|
|
|
//mPacket.pts = AV_NOPTS_VALUE;
|
|
|
|
|
|
//mPacket.pts = av_rescale_q( m_nSegBSkippedFrames + m_nSegBFrameCounter, m_pCodecCtx->time_base, m_pVideoStrB->time_base );
|
|
|
mPacket.dts = mPacket.pts; |
|
|
mPacket.dts = mPacket.pts; |
|
|
if( av_write_frame( m_pFormatCtxB, &mPacket) < 0 ) { |
|
|
|
|
|
|
|
|
int rc = av_write_frame( m_pFormatCtxB, &mPacket); |
|
|
|
|
|
if( rc < 0 ) { |
|
|
|
|
|
//if( av_interleaved_write_frame( m_pFormatCtxB, &mPacket) < 0 ) {
|
|
|
m_bThreadStatus = TH_ENDED; |
|
|
m_bThreadStatus = TH_ENDED; |
|
|
LOG_ERROR("Trouble with Video Output B!"); |
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
LOG_ERROR( "Trouble with Video Output B!" ); |
|
|
|
|
|
av_strerror( rc, tB, 128 ); |
|
|
|
|
|
LOG_ERROR( tB ); |
|
|
|
|
|
break; //continue (changed since embed into do-while)
|
|
|
}; |
|
|
}; |
|
|
m_nSegBFrameCounter++; |
|
|
|
|
|
}; |
|
|
}; |
|
|
av_packet_unref( &mPacket ); |
|
|
av_packet_unref( &mPacket ); |
|
|
|
|
|
|
|
|
m_mFrameCounterProtector.lock(); |
|
|
|
|
|
m_nGlobalFrameCounter++; |
|
|
|
|
|
m_mFrameCounterProtector.unlock(); |
|
|
|
|
|
}; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
//int ret = 0;
|
|
|
|
|
|
//do {
|
|
|
|
|
|
// if( ret == AVERROR(EAGAIN) ){
|
|
|
|
|
|
// av_packet_unref( &mPacket );
|
|
|
|
|
|
// ret = avcodec_receive_packet( m_pCodecCtx, &mPacket );
|
|
|
|
|
|
// if( ret ) break; // deal with error
|
|
|
|
|
|
// av_write_frame( m_pFormatCtxA, &mPacket );
|
|
|
|
|
|
// } //else if(ret) deal with error
|
|
|
|
|
|
// ret = avcodec_send_frame( m_pCodecCtx, m_pAVFrame );
|
|
|
|
|
|
//} while(ret);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
avcodec_encode_video2( m_pCodecCtx, &mPacket, m_pAVFrame, &bGotPacket ); |
|
|
|
|
|
if( bGotPacket ){ |
|
|
|
|
|
//char bobo[64];
|
|
|
|
|
|
//if( m_pCodecCtx->coded_frame->key_frame ) {
|
|
|
|
|
|
// mPacket.flags |= AV_PKT_FLAG_KEY;
|
|
|
|
|
|
// sprintf( bobo, "k-frame [%d]", m_nCurrentSegmentFrames );
|
|
|
|
|
|
// LOG( bobo );
|
|
|
|
|
|
//} else {
|
|
|
|
|
|
// sprintf( bobo, "n-frame [%d]", m_nCurrentSegmentFrames );
|
|
|
|
|
|
// LOG( bobo );
|
|
|
|
|
|
//};
|
|
|
|
|
|
// write packet
|
|
|
|
|
|
if ( m_bSegAActive ) { |
|
|
|
|
|
mPacket.stream_index = m_pVideoStrA->index; |
|
|
|
|
|
mPacket.duration = 1; |
|
|
|
|
|
mPacket.pts = av_rescale_q( m_nSegAFrameCounter, m_pCodecCtx->time_base, m_pVideoStrA->time_base ); |
|
|
|
|
|
mPacket.dts = mPacket.pts; |
|
|
|
|
|
//av_packet_rescale_ts( &mPacket, m_pCodecCtx->time_base, m_pVideoStrA->time_base );
|
|
|
|
|
|
//if( av_interleaved_write_frame( m_pFormatCtxA, &mPacket ) < 0 ) LOG_ERROR( "Trouble with Video Output!" );
|
|
|
|
|
|
if( av_write_frame( m_pFormatCtxA, &mPacket ) < 0 ){ |
|
|
|
|
|
m_bThreadStatus = TH_ENDED; |
|
|
|
|
|
LOG_ERROR("Trouble with Video Output A!"); |
|
|
|
|
|
continue; |
|
|
|
|
|
}; |
|
|
|
|
|
m_nSegAFrameCounter++; |
|
|
|
|
|
}; |
|
|
}; |
|
|
if ( m_bSegBActive ) { |
|
|
|
|
|
mPacket.stream_index = m_pVideoStrB->index; |
|
|
|
|
|
mPacket.duration = 1; |
|
|
|
|
|
mPacket.pts = av_rescale_q( m_nSegBFrameCounter, m_pCodecCtx->time_base, m_pVideoStrB->time_base ); |
|
|
|
|
|
mPacket.dts = mPacket.pts; |
|
|
|
|
|
//av_packet_rescale_ts( &mPacket, m_pCodecCtx->time_base, m_pVideoStrB->time_base );
|
|
|
|
|
|
//if( av_interleaved_write_frame( m_pFormatCtxB, &mPacket ) < 0 ) LOG_ERROR( "Trouble with Video Output!" );
|
|
|
|
|
|
if( av_write_frame( m_pFormatCtxB, &mPacket) < 0 ) { |
|
|
|
|
|
m_bThreadStatus = TH_ENDED; |
|
|
|
|
|
LOG_ERROR("Trouble with Video Output B!"); |
|
|
|
|
|
continue; |
|
|
|
|
|
}; |
|
|
|
|
|
m_nSegBFrameCounter++; |
|
|
|
|
|
}; |
|
|
|
|
|
av_packet_unref( &mPacket ); |
|
|
|
|
|
|
|
|
|
|
|
m_mFrameCounterProtector.lock(); |
|
|
|
|
|
m_nGlobalFrameCounter++; |
|
|
|
|
|
m_mFrameCounterProtector.unlock(); |
|
|
|
|
|
}; |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
} while ( rVal >= 0 && m_bThreadStatus != TH_ENDED ); |
|
|
}; |
|
|
}; |
|
|
|
|
|
#ifdef DEBUG
|
|
|
LOG("Encoder Loop Ended!"); |
|
|
LOG("Encoder Loop Ended!"); |
|
|
|
|
|
#endif
|
|
|
if ( m_bSegAActive ) { |
|
|
if ( m_bSegAActive ) { |
|
|
m_bSegAActive = false; |
|
|
m_bSegAActive = false; |
|
|
av_write_trailer( m_pFormatCtxA ); |
|
|
av_write_trailer( m_pFormatCtxA ); |
|
|
@ -2032,9 +2092,73 @@ void streamHandler::m_fThreadProc( void ){ |
|
|
av_write_trailer( m_pFormatCtxB ); |
|
|
av_write_trailer( m_pFormatCtxB ); |
|
|
avio_close( m_pFormatCtxB->pb ); |
|
|
avio_close( m_pFormatCtxB->pb ); |
|
|
}; |
|
|
}; |
|
|
|
|
|
#ifdef DEBUG
|
|
|
LOG("Encoder Streams are Closed!"); |
|
|
LOG("Encoder Streams are Closed!"); |
|
|
|
|
|
#endif
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
void streamHandler::swapActiveStreams( void ){ |
|
|
|
|
|
//m_mFrameCounterProtector.lock();
|
|
|
|
|
|
if ( !m_bActiveEncoderStream ) { |
|
|
|
|
|
m_bActiveEncoderStream = 1; |
|
|
|
|
|
m_nVideoRegisteredDBID = 0; |
|
|
|
|
|
// No need to continue Stream A if no Events
|
|
|
|
|
|
if ( m_bSegADelete ) closeSegmentA(); |
|
|
|
|
|
} else { |
|
|
|
|
|
m_bActiveEncoderStream = 0; |
|
|
|
|
|
m_nVideoRegisteredDBID = 0; |
|
|
|
|
|
// No need to continue Stream B if no Events
|
|
|
|
|
|
if ( m_bSegBDelete ) closeSegmentB(); |
|
|
|
|
|
}; |
|
|
|
|
|
//m_mFrameCounterProtector.unlock();
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
bool streamHandler::triggerEvent( uint32_t &dbid, uint32_t &frame ){ |
|
|
|
|
|
m_mFrameCounterProtector.lock(); |
|
|
|
|
|
if ( m_nVideoRegisteredDBID == 0 ) { |
|
|
|
|
|
LOG("New Event!"); |
|
|
|
|
|
PF_TIMESTAMP ts; |
|
|
|
|
|
getPFTS( &ts ); |
|
|
|
|
|
if ( !m_bActiveEncoderStream ) { // Stream A is Active
|
|
|
|
|
|
m_nVideoRegisteredDBID = argusDBC::getInstance()->addVideoRecord( |
|
|
|
|
|
m_sStreamData.id, |
|
|
|
|
|
m_cSegMD5A, |
|
|
|
|
|
VIDEO_OUTPUT_CONTAINER, |
|
|
|
|
|
ts.seconds, |
|
|
|
|
|
ts.milliseconds, |
|
|
|
|
|
m_sStreamData.fps |
|
|
|
|
|
); |
|
|
|
|
|
m_bSegADelete = false; |
|
|
|
|
|
m_nSegAShiftFrames = frame = m_nSegAFrameCounter; |
|
|
|
|
|
} else { // Stream B is Active
|
|
|
|
|
|
m_nVideoRegisteredDBID = argusDBC::getInstance()->addVideoRecord( |
|
|
|
|
|
m_sStreamData.id, |
|
|
|
|
|
m_cSegMD5B, |
|
|
|
|
|
VIDEO_OUTPUT_CONTAINER, |
|
|
|
|
|
ts.seconds, |
|
|
|
|
|
ts.milliseconds, |
|
|
|
|
|
m_sStreamData.fps |
|
|
|
|
|
); |
|
|
|
|
|
m_bSegBDelete = false; |
|
|
|
|
|
m_nSegBShiftFrames = frame = m_nSegBFrameCounter; |
|
|
|
|
|
}; |
|
|
|
|
|
}; |
|
|
|
|
|
if ( m_nVideoRegisteredDBID == 0 ) return false; |
|
|
|
|
|
dbid = m_nVideoRegisteredDBID; |
|
|
|
|
|
LOG("Event Registered!"); |
|
|
|
|
|
m_mFrameCounterProtector.unlock(); |
|
|
|
|
|
return true; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
bool streamHandler::validate( void ){ |
|
|
|
|
|
if ( m_pSource ) |
|
|
|
|
|
#ifdef EVE_ENABLE_VIDEO
|
|
|
|
|
|
if( m_bThreadStatus < TH_ENDED ) |
|
|
|
|
|
#endif
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
#undef LOG
|
|
|
#undef LOG
|
|
|
#undef LOG_ERROR
|
|
|
#undef LOG_ERROR
|
|
|
|