You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
3.3 KiB
115 lines
3.3 KiB
#include "videoNode.h"
|
|
#include "../storage/storageProvider.h"
|
|
|
|
videoNode::videoNode( config_setting_t * Settings ) : basicMediaDestination(), basicThread(){
|
|
|
|
//m_pSettings = basicSettingsProvider::getInstance()->getSubNode(Settings, "VIDEO_NODE");
|
|
|
|
m_bNewDataArival = false;
|
|
m_pCurrentMat = NULL;
|
|
m_pMatProtector = new basicMutex();
|
|
init();
|
|
};
|
|
|
|
videoNode::~videoNode(){
|
|
stopConveyour();
|
|
};
|
|
void videoNode::stopConveyour(void){
|
|
waitThreadEnd(true);
|
|
if (m_vDestinations.size())m_vDestinations.empty();
|
|
if (m_pMatProtector){
|
|
//m_pMatProtector->unlock();
|
|
delete(m_pMatProtector);
|
|
m_pMatProtector = NULL;
|
|
};
|
|
if (m_pCurrentMat != NULL){
|
|
m_pCurrentMat->release();
|
|
delete m_pCurrentMat;
|
|
m_pCurrentMat = NULL;
|
|
};
|
|
};
|
|
void videoNode::pushFrame(cv::Mat *Frame, void *src ){
|
|
if(m_bThreadStatus != TH_WORKING) return;
|
|
if( m_pMatProtector->try_lock() ){
|
|
if (m_pCurrentMat == NULL){
|
|
m_pCurrentMat = new cv::Mat(Frame->rows, Frame->cols, Frame->type());
|
|
} else {
|
|
if( (m_pCurrentMat->rows != Frame->rows) ||
|
|
(m_pCurrentMat->cols != Frame->cols) ||
|
|
(m_pCurrentMat->type() != Frame->type())){
|
|
delete(m_pCurrentMat);
|
|
m_pCurrentMat = new cv::Mat(Frame->rows, Frame->cols, Frame->type());
|
|
};
|
|
};
|
|
if(m_pCurrentMat != NULL){
|
|
memcpy(m_pCurrentMat->data, Frame->data, Frame->total() * Frame->elemSize());
|
|
m_bNewDataArival = true;
|
|
};
|
|
m_pMatProtector->unlock();
|
|
};
|
|
};
|
|
|
|
void videoNode::m_fThreadProc(){
|
|
m_bThreadStatus = TH_WORKING;
|
|
while( m_bThreadStatus == TH_WORKING ){
|
|
if (m_bNewDataArival){
|
|
if (m_vDestinations.size()){
|
|
m_pMatProtector->lock();
|
|
for (int index = 0; index < m_vDestinations.size(); index++){
|
|
if (m_bThreadStatus == TH_WORKING) if (m_vDestinations.at(index) != NULL) m_vDestinations.at(index)->pushFrame(m_pCurrentMat, this );
|
|
};
|
|
m_pMatProtector->unlock();
|
|
};
|
|
m_bNewDataArival = false;
|
|
} else SLEEP(10);
|
|
};
|
|
};
|
|
|
|
void videoNode::connect(basicMediaDestination *V){
|
|
if (V != NULL){
|
|
m_pMatProtector->lock();
|
|
m_vDestinations.push_back(V);
|
|
m_pMatProtector->unlock();
|
|
};
|
|
};
|
|
|
|
void videoNode::disconnect(basicMediaDestination *V){
|
|
if (V != NULL){
|
|
m_pMatProtector->lock();
|
|
mediaDestinationsCollection::iterator index;
|
|
for (index = m_vDestinations.begin(); index < m_vDestinations.end(); index++){
|
|
if ((*index) == V) break;
|
|
};
|
|
m_vDestinations.erase(index);
|
|
m_pMatProtector->unlock();
|
|
};
|
|
};
|
|
|
|
bool videoNode::attachVideoAnalyzer(basicVideoAnalyzer *BVA){
|
|
|
|
return true;
|
|
};
|
|
|
|
void videoNode::startRecord(void){
|
|
m_pMatProtector->lock();
|
|
mediaDestinationsCollection::iterator index;
|
|
for (index = m_vDestinations.begin(); index < m_vDestinations.end(); index++){
|
|
char tBuffer[MAX_PATH];
|
|
sprintf(tBuffer, "%s.%s", storageProvider::getInstance()->getNewFileName(), VIDEO_OUTPUT_CONTAINER );
|
|
if ((*index)->isRecorder()) (*index)->startRecord(tBuffer);
|
|
};
|
|
m_pMatProtector->unlock();
|
|
};
|
|
|
|
void videoNode::stopRecord(void){
|
|
m_pMatProtector->lock();
|
|
mediaDestinationsCollection::iterator index;
|
|
for (index = m_vDestinations.begin(); index < m_vDestinations.end(); index++){
|
|
if ((*index)->isRecorder()) (*index)->stopRecord();
|
|
};
|
|
m_pMatProtector->unlock();
|
|
};
|
|
|
|
void videoNode::takeSnapshot(CSTR filename){
|
|
|
|
};
|