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.

199 lines
5.5 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "mediaVideoSourceManager.h"
  2. mediaVideoSourceManager* mediaVideoSourceManager::_instance = 0;
  3. /**
  4. * Returns the single instance of the object.
  5. */
  6. mediaVideoSourceManager* mediaVideoSourceManager::getInstance() {
  7. // check if the instance has been created yet
  8. if (0 == _instance) {
  9. // if not, then create it
  10. _instance = new mediaVideoSourceManager;
  11. }
  12. // return the single instance
  13. return _instance;
  14. };
  15. // Constructor implementation
  16. mediaVideoSourceManager::mediaVideoSourceManager(){
  17. m_pLog = basicLogCollection::getInstance();
  18. m_pSettings = basicSettingsProvider::getInstance()->getSubNode(NULL, "VIDEO_SOURCE_MANAGER");
  19. #ifdef __linux__
  20. enumerateDevices(&m_vLocalDevices, "video");
  21. #else
  22. enumerateDevices(&m_vLocalDevices, CLSID_VideoInputDeviceCategory);//CLSID_AudioInputDeviceCategory
  23. #endif
  24. loadAssignedSources();
  25. };
  26. // Destructor implementation
  27. mediaVideoSourceManager::~mediaVideoSourceManager(){
  28. shutdownAllVideoSources();
  29. };
  30. void mediaVideoSourceManager::shutdownAllVideoSources(void){
  31. if (m_vCameras.size()){
  32. for (vectorCamerasInterator index = m_vCameras.begin(); index < m_vCameras.end(); index++){
  33. (*index)->stop();
  34. switch ((*index)->getType()){
  35. case 0:
  36. delete ((objectStaticCamera *)*index);
  37. break;
  38. #ifndef NO_PTZ_CAMERAS
  39. case 3:
  40. delete ((objectCameraPTZ *)*index);
  41. break;
  42. #endif
  43. default:
  44. break;
  45. };
  46. };
  47. m_vCameras.clear();
  48. };
  49. };
  50. bool mediaVideoSourceManager::isUsed(int id){
  51. for( sourcePool::iterator index = m_vUsedDevices.begin(); index < m_vUsedDevices.end(); index++ ){
  52. if (id == (*index)->deviceId) return true;
  53. };
  54. return false;
  55. };
  56. bool mediaVideoSourceManager::loadAssignedSources(void){
  57. int index, count, tType, tSType;
  58. config_setting_t *tRec;
  59. config_setting_t *ttRec;
  60. count = config_setting_length(m_pSettings);
  61. if (count){
  62. for (index = 0; index < count; index++){
  63. tRec = config_setting_get_elem(m_pSettings, index);
  64. if (tRec != NULL){
  65. ttRec = config_setting_get_elem(tRec, 0);
  66. if (!config_setting_lookup_int(ttRec, BCI_TAG_CAMERA_TYPE, &tType)) continue;
  67. if (!config_setting_lookup_int(ttRec, BCI_TAG_SOURCE_TYPE, &tSType)) continue;
  68. switch (tType){
  69. case 0: {
  70. objectStaticCamera *tCamera;
  71. tCamera = new objectStaticCamera(ttRec);
  72. if (tCamera->create()) m_vCameras.push_back((basicCamera *)tCamera);
  73. break;
  74. };
  75. #ifndef NO_PTZ_CAMERAS
  76. case 1:
  77. case 2:
  78. case 3:{
  79. objectCameraPTZ *tCamera;
  80. tCamera = new objectCameraPTZ(ttRec);
  81. if (tCamera->create()) m_vCameras.push_back((basicCamera *)tCamera);
  82. break;
  83. };
  84. #endif
  85. };
  86. };
  87. };
  88. };
  89. return true;
  90. };
  91. basicCamera *mediaVideoSourceManager::addSource(SOURCE_INFO *SRC){
  92. basicCamera *RetVal = NULL;
  93. if( SRC != NULL ){
  94. char Buffer[64];
  95. config_setting_t *tSettingsNode;
  96. basicCamera *ttCamera = NULL;
  97. sprintf(Buffer, "VIDEO_SOURCE_%d", m_vCameras.size());
  98. tSettingsNode = basicSettingsProvider::getInstance()->getSubNode(m_pSettings, Buffer);
  99. switch ( SRC->type ){
  100. case 0:{
  101. objectStaticCamera *tCamera;
  102. tCamera = new objectStaticCamera(basicSettingsProvider::getInstance()->getSubNode(tSettingsNode, "CAMERA"));
  103. if(tCamera->create(SRC)) ttCamera = (basicCamera*)tCamera;
  104. break;
  105. };
  106. case 1:{
  107. break;
  108. };
  109. case 2:{
  110. break;
  111. };
  112. #ifndef NO_PTZ_CAMERAS
  113. case 3:{
  114. objectCameraPTZ *tCamera;
  115. tCamera = new objectCameraPTZ(basicSettingsProvider::getInstance()->getSubNode(tSettingsNode, "CAMERA"));
  116. if(tCamera->create(SRC))ttCamera = (basicCamera*)tCamera;
  117. break;
  118. };
  119. #endif
  120. };
  121. if (ttCamera != NULL){
  122. m_vCameras.push_back(ttCamera);
  123. RetVal = ttCamera;
  124. //ToDo: Make Metod to abadon added config node in case camera failure
  125. basicSettingsProvider::getInstance()->compromise();
  126. };
  127. };
  128. basicSettingsProvider::getInstance()->validate();
  129. return RetVal;
  130. };
  131. bool mediaVideoSourceManager::removeSource(basicCamera *ptr){
  132. for (vectorCameras::iterator index = m_vCameras.begin(); index < m_vCameras.end(); index++){
  133. if ((*index) == ptr){
  134. (*index)->stop();
  135. };
  136. };
  137. return false;
  138. };
  139. size_t mediaVideoSourceManager::getLocalSourceCount( void ){
  140. return m_vLocalDevices.size();
  141. };
  142. DeviceInfo *mediaVideoSourceManager::getLocalSourceInfo( size_t sourceId ){
  143. if( sourceId < m_vLocalDevices.size() ) {
  144. return m_vLocalDevices[sourceId];
  145. };
  146. return NULL;
  147. };
  148. basicMediaSource *mediaVideoSourceManager::getVideoSource( int sourceId ){
  149. if( sourceId < m_vSourceCollection.size() ) {
  150. return m_vSourceCollection[sourceId];
  151. };
  152. return NULL;
  153. };
  154. const char *mediaVideoSourceManager::getStandardSize(bool wide, int id){
  155. if( wide ){
  156. return g_aFrameSizeStandardNames_16_9[id%g_iStandardFrameSizesCount];
  157. } else {
  158. return g_aFrameSizeStandardNames_4_3[id%g_iStandardFrameSizesCount];
  159. };
  160. };
  161. const int mediaVideoSourceManager::getStandardWidth(bool wide, int id){
  162. if (wide){
  163. return g_aFrameWidthStandard_16_9[id%g_iStandardFrameSizesCount];
  164. }
  165. else {
  166. return g_aFrameWidthStandard_4_3[id%g_iStandardFrameSizesCount];
  167. };
  168. };
  169. const int mediaVideoSourceManager::getStandardHeight(bool wide, int id){
  170. if (wide){
  171. return g_aFrameHeightStandard_16_9[id % g_iStandardFrameSizesCount];
  172. }
  173. else {
  174. return g_aFrameHeightStandard_4_3[id % g_iStandardFrameSizesCount];
  175. };
  176. };