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

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "videoNode.h"
  2. #include "../storage/storageProvider.h"
  3. videoNode::videoNode( config_setting_t * Settings ) : basicMediaDestination(), basicThread(){
  4. //m_pSettings = basicSettingsProvider::getInstance()->getSubNode(Settings, "VIDEO_NODE");
  5. m_bNewDataArival = false;
  6. m_pCurrentMat = NULL;
  7. m_pMatProtector = new basicMutex();
  8. init();
  9. };
  10. videoNode::~videoNode(){
  11. stopConveyour();
  12. };
  13. void videoNode::stopConveyour(void){
  14. waitThreadEnd();
  15. if (m_vDestinations.size())m_vDestinations.empty();
  16. if (m_pMatProtector){
  17. //m_pMatProtector->unlock();
  18. delete(m_pMatProtector);
  19. m_pMatProtector = NULL;
  20. };
  21. if (m_pCurrentMat != NULL){
  22. m_pCurrentMat->release();
  23. delete m_pCurrentMat;
  24. m_pCurrentMat = NULL;
  25. };
  26. };
  27. void videoNode::pushFrame(cv::Mat *Frame, void *src ){
  28. if(m_bThreadStatus != TH_WORKING) return;
  29. if( m_pMatProtector->try_lock() ){
  30. if (m_pCurrentMat == NULL){
  31. m_pCurrentMat = new cv::Mat(Frame->rows, Frame->cols, Frame->type());
  32. } else {
  33. if( (m_pCurrentMat->rows != Frame->rows) ||
  34. (m_pCurrentMat->cols != Frame->cols) ||
  35. (m_pCurrentMat->type() != Frame->type())){
  36. delete(m_pCurrentMat);
  37. m_pCurrentMat = new cv::Mat(Frame->rows, Frame->cols, Frame->type());
  38. };
  39. };
  40. if(m_pCurrentMat != NULL){
  41. memcpy(m_pCurrentMat->data, Frame->data, Frame->total() * Frame->elemSize());
  42. m_bNewDataArival = true;
  43. };
  44. m_pMatProtector->unlock();
  45. };
  46. };
  47. void videoNode::m_fThreadProc(){
  48. m_bThreadStatus = TH_WORKING;
  49. while( m_bThreadStatus == TH_WORKING ){
  50. if (m_bNewDataArival){
  51. if (m_vDestinations.size()){
  52. m_pMatProtector->lock();
  53. for (int index = 0; index < m_vDestinations.size(); index++){
  54. if (m_bThreadStatus == TH_WORKING) if (m_vDestinations.at(index) != NULL) m_vDestinations.at(index)->pushFrame(m_pCurrentMat, this );
  55. };
  56. m_pMatProtector->unlock();
  57. };
  58. m_bNewDataArival = false;
  59. } else SLEEP(10);
  60. };
  61. };
  62. void videoNode::connect(basicMediaDestination *V){
  63. if (V != NULL){
  64. m_pMatProtector->lock();
  65. m_vDestinations.push_back(V);
  66. m_pMatProtector->unlock();
  67. };
  68. };
  69. void videoNode::disconnect(basicMediaDestination *V){
  70. if (V != NULL){
  71. m_pMatProtector->lock();
  72. mediaDestinationsCollection::iterator index;
  73. for (index = m_vDestinations.begin(); index < m_vDestinations.end(); index++){
  74. if ((*index) == V) break;
  75. };
  76. m_vDestinations.erase(index);
  77. m_pMatProtector->unlock();
  78. };
  79. };
  80. bool videoNode::attachVideoAnalyzer(basicVideoAnalyzer *BVA){
  81. return true;
  82. };
  83. void videoNode::startRecord(void){
  84. m_pMatProtector->lock();
  85. mediaDestinationsCollection::iterator index;
  86. for (index = m_vDestinations.begin(); index < m_vDestinations.end(); index++){
  87. char tBuffer[MAX_PATH];
  88. sprintf(tBuffer, "%s.%s", storageProvider::getInstance()->getNewFileName(), VIDEO_OUTPUT_CONTAINER );
  89. if ((*index)->isRecorder()) (*index)->startRecord(tBuffer);
  90. };
  91. m_pMatProtector->unlock();
  92. };
  93. void videoNode::stopRecord(void){
  94. m_pMatProtector->lock();
  95. mediaDestinationsCollection::iterator index;
  96. for (index = m_vDestinations.begin(); index < m_vDestinations.end(); index++){
  97. if ((*index)->isRecorder()) (*index)->stopRecord();
  98. };
  99. m_pMatProtector->unlock();
  100. };
  101. void videoNode::takeSnapshot(CSTR filename){
  102. };