Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*===========================================================================
- * FUNCTION : get_num_of_cameras
- *
- * DESCRIPTION: get number of cameras
- *
- * PARAMETERS :
- *
- * RETURN : number of cameras supported
- *==========================================================================*/
- uint8_t get_num_of_cameras()
- {
- int rc = 0;
- int dev_fd = -1;
- struct media_device_info mdev_info;
- int num_media_devices = 0;
- int8_t num_cameras = 0;
- char subdev_name[32];
- int32_t sd_fd = -1;
- struct sensor_init_cfg_data cfg;
- char prop[PROPERTY_VALUE_MAX];
- uint32_t globalLogLevel = 0;
- property_get("persist.camera.hal.debug", prop, "0");
- int val = atoi(prop);
- if (0 <= val) {
- gMmCameraIntfLogLevel = (uint32_t)val;
- }
- property_get("persist.camera.global.debug", prop, "0");
- val = atoi(prop);
- if (0 <= val) {
- globalLogLevel = (uint32_t)val;
- }
- /* Highest log level among hal.logs and global.logs is selected */
- if (gMmCameraIntfLogLevel < globalLogLevel)
- gMmCameraIntfLogLevel = globalLogLevel;
- CDBG("%s: E", __func__);
- property_get("vold.decrypt", prop, "0");
- int decrypt = atoi(prop);
- if (decrypt == 1)
- return 0;
- /* lock the mutex */
- pthread_mutex_lock(&g_intf_lock);
- while (1) {
- uint32_t num_entities = 1U;
- char dev_name[32];
- snprintf(dev_name, sizeof(dev_name), "/dev/media%d", num_media_devices);
- dev_fd = open(dev_name, O_RDWR | O_NONBLOCK);
- CDBG("%s: (bt): line: %d: dev_fd: %d, dev_name: %s", __func__, __LINE__, dev_fd, dev_name);
- if (dev_fd < 0) {
- CDBG("%s: line: %d: Done discovering media devices", __func__, __LINE__);
- break;
- }
- num_media_devices++;
- rc = ioctl(dev_fd, MEDIA_IOC_DEVICE_INFO, &mdev_info);
- if (rc < 0) {
- CDBG_ERROR("%s: line: %d: Error: ioctl media_dev failed: %s", __func__,
- __LINE__, strerror(errno));
- close(dev_fd);
- dev_fd = -1;
- break;
- }
- //(bt): MSM_CONFIGURATION_NAME is "msm_config"
- CDBG("%s: (bt): line: %d: mdev_info.model: %s", __func__, __LINE__, mdev_info.model);
- if (strncmp(mdev_info.model, MSM_CONFIGURATION_NAME, sizeof(mdev_info.model)) != 0) {
- close(dev_fd);
- dev_fd = -1;
- continue;
- }
- while (1) {
- struct media_entity_desc entity;
- memset(&entity, 0, sizeof(entity));
- entity.id = num_entities++;
- CDBG("%s: entity id: %d", __func__, entity.id);
- rc = ioctl(dev_fd, MEDIA_IOC_ENUM_ENTITIES, &entity);
- if (rc < 0) {
- CDBG("%s: line: %d: Done enumerating media entities", __func__, __LINE__);
- rc = 0;
- break;
- }
- CDBG("%s: entity name: %s, type: %d, group_id: %d", __func__,
- entity.name, entity.type, entity.group_id);
- //(bt): MEDIA_ENT_T_V4L2_SUBDEV is 131072
- //(bt): MSM_CAMERA_SUBDEV_SENSOR_INIT is 14
- if (entity.type == MEDIA_ENT_T_V4L2_SUBDEV &&
- entity.group_id == MSM_CAMERA_SUBDEV_SENSOR_INIT) {
- snprintf(subdev_name, sizeof(dev_name), "/dev/%s", entity.name);
- CDBG("%s: line: %d: Break enumerating media entities", __func__, __LINE__);
- break;
- }
- }
- close(dev_fd);
- dev_fd = -1;
- }
- /* Open sensor_init subdev */
- sd_fd = open(subdev_name, O_RDWR);
- if (sd_fd < 0) {
- CDBG_ERROR("%s: Open sensor_init subdev failed", __func__);
- return FALSE;
- }
- cfg.cfgtype = CFG_SINIT_PROBE_WAIT_DONE;
- cfg.cfg.setting = NULL;
- if (ioctl(sd_fd, VIDIOC_MSM_SENSOR_INIT_CFG, &cfg) < 0) {
- CDBG_ERROR("%s: failed", __func__);
- }
- close(sd_fd);
- dev_fd = -1;
- num_media_devices = 0;
- while (1) {
- uint32_t num_entities = 1U;
- char dev_name[32];
- snprintf(dev_name, sizeof(dev_name), "/dev/media%d", num_media_devices);
- dev_fd = open(dev_name, O_RDWR | O_NONBLOCK);
- CDBG("%s: (bt): line: %d: dev_fd: %d, dev_name: %s", __func__, __LINE__, dev_fd, dev_name);
- if (dev_fd < 0) {
- CDBG("%s: line: %d: Done discovering media devices", __func__, __LINE__);
- break;
- }
- num_media_devices++;
- memset(&mdev_info, 0, sizeof(mdev_info));
- rc = ioctl(dev_fd, MEDIA_IOC_DEVICE_INFO, &mdev_info);
- if (rc < 0) {
- CDBG_ERROR("%s: line: %d: Error: ioctl media_dev failed: %s", __func__,
- __LINE__, strerror(errno));
- close(dev_fd);
- dev_fd = -1;
- num_cameras = 0;
- break;
- }
- //(bt): MSM_CAMERA_NAME is "msm_camera"
- CDBG("%s: (bt): line: %d: mdev_info.model: %s", __func__, __LINE__, mdev_info.model);
- if(strncmp(mdev_info.model, MSM_CAMERA_NAME, sizeof(mdev_info.model)) != 0) {
- close(dev_fd);
- dev_fd = -1;
- continue;
- }
- while (1) {
- struct media_entity_desc entity;
- memset(&entity, 0, sizeof(entity));
- entity.id = num_entities++;
- rc = ioctl(dev_fd, MEDIA_IOC_ENUM_ENTITIES, &entity);
- if (rc < 0) {
- CDBG("%s: line: %d: Done enumerating media entities", __func__, __LINE__);
- rc = 0;
- break;
- }
- //(bt): MEDIA_ENT_T_DEVNODE_V4L is 65537
- //(bt): QCAMERA_VNODE_GROUP_ID is 2
- CDBG("%s: (bt): line: %d: entity name: %s, type: %d, group_id: %d", __func__,
- __LINE__, entity.name, entity.type, entity.group_id);
- if(entity.type == MEDIA_ENT_T_DEVNODE_V4L &&
- entity.group_id == QCAMERA_VNODE_GROUP_ID) {
- strlcpy(g_cam_ctrl.video_dev_name[num_cameras],
- entity.name, sizeof(entity.name));
- CDBG("%s: line: %d: Break enumerating media entities", __func__, __LINE__);
- break;
- }
- }
- CDBG("%s: dev_info[id: %d, name: '%s']",
- __func__, (int)num_cameras, g_cam_ctrl.video_dev_name[num_cameras]);
- num_cameras++;
- close(dev_fd);
- dev_fd = -1;
- }
- g_cam_ctrl.num_cam = num_cameras;
- get_sensor_info();
- sort_camera_info(g_cam_ctrl.num_cam);
- /* unlock the mutex */
- pthread_mutex_unlock(&g_intf_lock);
- CDBG("%s: num_cameras: %d", __func__, (int)g_cam_ctrl.num_cam);
- return(uint8_t)g_cam_ctrl.num_cam;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement