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.

219 lines
6.4 KiB

7 years ago
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
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)){
  115. if(tCamera->create()){
  116. ttCamera = (basicCamera*)tCamera;
  117. };
  118. };
  119. break;
  120. };
  121. case 1:{
  122. break;
  123. };
  124. case 2:{
  125. break;
  126. };
  127. #ifndef NO_PTZ_CAMERAS
  128. case 3:{
  129. objectCameraPTZ *tCamera;
  130. tCamera = new objectCameraPTZ(basicSettingsProvider::getInstance()->getSubNode(tSettingsNode, "CAMERA"));
  131. if(tCamera->create(SRC)){
  132. if( tCamera->create() ){
  133. ttCamera = (basicCamera*)tCamera;
  134. };
  135. };
  136. break;
  137. };
  138. #endif
  139. };
  140. if (ttCamera != NULL){
  141. m_vCameras.push_back(ttCamera);
  142. RetVal = ttCamera;
  143. //ToDo: Make Metod to abadon added config node in case camera failure
  144. basicSettingsProvider::getInstance()->compromise();
  145. };
  146. };
  147. basicSettingsProvider::getInstance()->validate();
  148. return RetVal;
  149. };
  150. bool mediaVideoSourceManager::removeSource(basicCamera *ptr){
  151. for (vectorCameras::iterator index = m_vCameras.begin(); index < m_vCameras.end(); index++){
  152. if ((*index) == ptr){
  153. (*index)->stop();
  154. };
  155. };
  156. return false;
  157. };
  158. size_t mediaVideoSourceManager::getLocalSourceCount( void ){
  159. return m_vLocalDevices.size();
  160. };
  161. DeviceInfo *mediaVideoSourceManager::getLocalSourceInfo( size_t sourceId ){
  162. if( sourceId < m_vLocalDevices.size() ) {
  163. return m_vLocalDevices[sourceId];
  164. };
  165. return NULL;
  166. };
  167. basicMediaSource *mediaVideoSourceManager::getVideoSource( int sourceId ){
  168. if( sourceId < m_vSourceCollection.size() ) {
  169. return m_vSourceCollection[sourceId];
  170. };
  171. return NULL;
  172. };
  173. const char *mediaVideoSourceManager::getStandardSize(bool wide, int id){
  174. if( wide ){
  175. return g_aFrameSizeStandardNames_16_9[id%g_iStandardFrameSizesCount];
  176. } else {
  177. return g_aFrameSizeStandardNames_4_3[id%g_iStandardFrameSizesCount];
  178. };
  179. };
  180. const int mediaVideoSourceManager::getStandardWidth(bool wide, int id){
  181. if (wide){
  182. return g_aFrameWidthStandard_16_9[id%g_iStandardFrameSizesCount];
  183. }
  184. else {
  185. return g_aFrameWidthStandard_4_3[id%g_iStandardFrameSizesCount];
  186. };
  187. };
  188. const int mediaVideoSourceManager::getStandardHeight(bool wide, int id){
  189. if (wide){
  190. return g_aFrameHeightStandard_16_9[id % g_iStandardFrameSizesCount];
  191. }
  192. else {
  193. return g_aFrameHeightStandard_4_3[id % g_iStandardFrameSizesCount];
  194. };
  195. };
  196. #undef LOG
  197. #undef LOG_ERROR