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.
148 lines
4.0 KiB
148 lines
4.0 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_bRecording = false;
|
|
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;
|
|
};
|
|
};
|
|
bool videoNode::pushFrame(cv::Mat *Frame, void *src ){
|
|
if(m_bThreadStatus != TH_WORKING) return false;
|
|
if( m_pMatProtector->try_lock() ){
|
|
if (m_nRecorderCounter) {
|
|
m_nRecorderCounter--;
|
|
};
|
|
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();
|
|
return true;
|
|
};
|
|
return false;
|
|
};
|
|
|
|
|
|
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();
|
|
if (m_nRecorderCounter == 1) stopRecord();
|
|
};
|
|
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;
|
|
};
|
|
|
|
int videoNode::startRecord(uint32_t framesToRecord){
|
|
m_pMatProtector->lock();
|
|
if (!m_bRecording) {
|
|
char tNAME[CTEXT];
|
|
CSTR tVAL = storageProvider::getInstance()->getNewFileName(tNAME);
|
|
if (tVAL == NULL) {
|
|
return -1;
|
|
};
|
|
sprintf(m_sCurrentRecordName, "%s.%s", tNAME, VIDEO_OUTPUT_CONTAINER);
|
|
sprintf(m_sCurrentRecordPath, "%s.%s", tVAL, VIDEO_OUTPUT_CONTAINER);
|
|
free(tVAL);
|
|
m_nRecordedFramesCount = 0;
|
|
mediaDestinationsCollection::iterator index;
|
|
uint8_t cnt = 0;
|
|
for (index = m_vDestinations.begin(); index < m_vDestinations.end(); index++) {
|
|
if ((*index)->isRecorder()) {
|
|
(*index)->startRecord(m_sCurrentRecordPath);
|
|
cnt++;
|
|
};
|
|
};
|
|
if (cnt) {
|
|
m_bRecording = true;
|
|
} else {
|
|
m_nRecorderCounter = 0;
|
|
m_pMatProtector->unlock();
|
|
return -1;
|
|
};
|
|
};
|
|
m_nRecorderCounter += framesToRecord;
|
|
m_pMatProtector->unlock();
|
|
return m_nRecordedFramesCount;
|
|
};
|
|
|
|
int videoNode::stopRecord(void){
|
|
if (!m_bRecording) return -1;
|
|
m_pMatProtector->lock();
|
|
mediaDestinationsCollection::iterator index;
|
|
for (index = m_vDestinations.begin(); index < m_vDestinations.end(); index++){
|
|
if ((*index)->isRecorder()) (*index)->stopRecord();
|
|
};
|
|
m_bRecording = false;
|
|
m_pMatProtector->unlock();
|
|
return m_nRecordedFramesCount;
|
|
};
|
|
|
|
CSTR videoNode::takeSnapshot(void){
|
|
return NULL;
|
|
};
|