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.

211 lines
6.1 KiB

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