Advertisement
Professor-Berni

get_num_of_cameras sourcecode

Jul 30th, 2020
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.62 KB | None | 0 0
  1. /*===========================================================================
  2. * FUNCTION : get_num_of_cameras
  3. *
  4. * DESCRIPTION: get number of cameras
  5. *
  6. * PARAMETERS :
  7. *
  8. * RETURN : number of cameras supported
  9. *==========================================================================*/
  10. uint8_t get_num_of_cameras()
  11. {
  12. int rc = 0;
  13. int dev_fd = -1;
  14. struct media_device_info mdev_info;
  15. int num_media_devices = 0;
  16. int8_t num_cameras = 0;
  17. char subdev_name[32];
  18. int32_t sd_fd = -1;
  19. struct sensor_init_cfg_data cfg;
  20. char prop[PROPERTY_VALUE_MAX];
  21. uint32_t globalLogLevel = 0;
  22.  
  23. property_get("persist.camera.hal.debug", prop, "0");
  24. int val = atoi(prop);
  25. if (0 <= val) {
  26. gMmCameraIntfLogLevel = (uint32_t)val;
  27. }
  28. property_get("persist.camera.global.debug", prop, "0");
  29. val = atoi(prop);
  30. if (0 <= val) {
  31. globalLogLevel = (uint32_t)val;
  32. }
  33.  
  34. /* Highest log level among hal.logs and global.logs is selected */
  35. if (gMmCameraIntfLogLevel < globalLogLevel)
  36. gMmCameraIntfLogLevel = globalLogLevel;
  37.  
  38. CDBG("%s: E", __func__);
  39.  
  40. property_get("vold.decrypt", prop, "0");
  41. int decrypt = atoi(prop);
  42. if (decrypt == 1)
  43. return 0;
  44.  
  45. /* lock the mutex */
  46. pthread_mutex_lock(&g_intf_lock);
  47.  
  48. while (1) {
  49. uint32_t num_entities = 1U;
  50. char dev_name[32];
  51.  
  52. snprintf(dev_name, sizeof(dev_name), "/dev/media%d", num_media_devices);
  53. dev_fd = open(dev_name, O_RDWR | O_NONBLOCK);
  54. CDBG("%s: (bt): line: %d: dev_fd: %d, dev_name: %s", __func__, __LINE__, dev_fd, dev_name);
  55. if (dev_fd < 0) {
  56. CDBG("%s: line: %d: Done discovering media devices", __func__, __LINE__);
  57. break;
  58. }
  59. num_media_devices++;
  60. rc = ioctl(dev_fd, MEDIA_IOC_DEVICE_INFO, &mdev_info);
  61. if (rc < 0) {
  62. CDBG_ERROR("%s: line: %d: Error: ioctl media_dev failed: %s", __func__,
  63. __LINE__, strerror(errno));
  64. close(dev_fd);
  65. dev_fd = -1;
  66. break;
  67. }
  68.  
  69. //(bt): MSM_CONFIGURATION_NAME is "msm_config"
  70. CDBG("%s: (bt): line: %d: mdev_info.model: %s", __func__, __LINE__, mdev_info.model);
  71. if (strncmp(mdev_info.model, MSM_CONFIGURATION_NAME, sizeof(mdev_info.model)) != 0) {
  72. close(dev_fd);
  73. dev_fd = -1;
  74. continue;
  75. }
  76.  
  77. while (1) {
  78. struct media_entity_desc entity;
  79. memset(&entity, 0, sizeof(entity));
  80. entity.id = num_entities++;
  81. CDBG("%s: entity id: %d", __func__, entity.id);
  82. rc = ioctl(dev_fd, MEDIA_IOC_ENUM_ENTITIES, &entity);
  83. if (rc < 0) {
  84. CDBG("%s: line: %d: Done enumerating media entities", __func__, __LINE__);
  85. rc = 0;
  86. break;
  87. }
  88. CDBG("%s: entity name: %s, type: %d, group_id: %d", __func__,
  89. entity.name, entity.type, entity.group_id);
  90. //(bt): MEDIA_ENT_T_V4L2_SUBDEV is 131072
  91. //(bt): MSM_CAMERA_SUBDEV_SENSOR_INIT is 14
  92. if (entity.type == MEDIA_ENT_T_V4L2_SUBDEV &&
  93. entity.group_id == MSM_CAMERA_SUBDEV_SENSOR_INIT) {
  94. snprintf(subdev_name, sizeof(dev_name), "/dev/%s", entity.name);
  95. CDBG("%s: line: %d: Break enumerating media entities", __func__, __LINE__);
  96. break;
  97. }
  98. }
  99. close(dev_fd);
  100. dev_fd = -1;
  101. }
  102.  
  103. /* Open sensor_init subdev */
  104. sd_fd = open(subdev_name, O_RDWR);
  105. if (sd_fd < 0) {
  106. CDBG_ERROR("%s: Open sensor_init subdev failed", __func__);
  107. return FALSE;
  108. }
  109.  
  110. cfg.cfgtype = CFG_SINIT_PROBE_WAIT_DONE;
  111. cfg.cfg.setting = NULL;
  112. if (ioctl(sd_fd, VIDIOC_MSM_SENSOR_INIT_CFG, &cfg) < 0) {
  113. CDBG_ERROR("%s: failed", __func__);
  114. }
  115. close(sd_fd);
  116. dev_fd = -1;
  117.  
  118.  
  119. num_media_devices = 0;
  120. while (1) {
  121. uint32_t num_entities = 1U;
  122. char dev_name[32];
  123.  
  124. snprintf(dev_name, sizeof(dev_name), "/dev/media%d", num_media_devices);
  125. dev_fd = open(dev_name, O_RDWR | O_NONBLOCK);
  126. CDBG("%s: (bt): line: %d: dev_fd: %d, dev_name: %s", __func__, __LINE__, dev_fd, dev_name);
  127. if (dev_fd < 0) {
  128. CDBG("%s: line: %d: Done discovering media devices", __func__, __LINE__);
  129. break;
  130. }
  131. num_media_devices++;
  132. memset(&mdev_info, 0, sizeof(mdev_info));
  133. rc = ioctl(dev_fd, MEDIA_IOC_DEVICE_INFO, &mdev_info);
  134. if (rc < 0) {
  135. CDBG_ERROR("%s: line: %d: Error: ioctl media_dev failed: %s", __func__,
  136. __LINE__, strerror(errno));
  137. close(dev_fd);
  138. dev_fd = -1;
  139. num_cameras = 0;
  140. break;
  141. }
  142.  
  143. //(bt): MSM_CAMERA_NAME is "msm_camera"
  144. CDBG("%s: (bt): line: %d: mdev_info.model: %s", __func__, __LINE__, mdev_info.model);
  145. if(strncmp(mdev_info.model, MSM_CAMERA_NAME, sizeof(mdev_info.model)) != 0) {
  146. close(dev_fd);
  147. dev_fd = -1;
  148. continue;
  149. }
  150.  
  151. while (1) {
  152. struct media_entity_desc entity;
  153. memset(&entity, 0, sizeof(entity));
  154. entity.id = num_entities++;
  155. rc = ioctl(dev_fd, MEDIA_IOC_ENUM_ENTITIES, &entity);
  156. if (rc < 0) {
  157. CDBG("%s: line: %d: Done enumerating media entities", __func__, __LINE__);
  158. rc = 0;
  159. break;
  160. }
  161. //(bt): MEDIA_ENT_T_DEVNODE_V4L is 65537
  162. //(bt): QCAMERA_VNODE_GROUP_ID is 2
  163. CDBG("%s: (bt): line: %d: entity name: %s, type: %d, group_id: %d", __func__,
  164. __LINE__, entity.name, entity.type, entity.group_id);
  165. if(entity.type == MEDIA_ENT_T_DEVNODE_V4L &&
  166. entity.group_id == QCAMERA_VNODE_GROUP_ID) {
  167. strlcpy(g_cam_ctrl.video_dev_name[num_cameras],
  168. entity.name, sizeof(entity.name));
  169. CDBG("%s: line: %d: Break enumerating media entities", __func__, __LINE__);
  170. break;
  171. }
  172. }
  173.  
  174. CDBG("%s: dev_info[id: %d, name: '%s']",
  175. __func__, (int)num_cameras, g_cam_ctrl.video_dev_name[num_cameras]);
  176.  
  177. num_cameras++;
  178. close(dev_fd);
  179. dev_fd = -1;
  180. }
  181. g_cam_ctrl.num_cam = num_cameras;
  182.  
  183. get_sensor_info();
  184. sort_camera_info(g_cam_ctrl.num_cam);
  185. /* unlock the mutex */
  186. pthread_mutex_unlock(&g_intf_lock);
  187. CDBG("%s: num_cameras: %d", __func__, (int)g_cam_ctrl.num_cam);
  188. return(uint8_t)g_cam_ctrl.num_cam;
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement