Rk3288 Android7.1 usb摄像头CameraHal支持热插拔补丁

diff --git a/CameraHal/CameraHal_board_xml_parse.cpp b/CameraHal/CameraHal_board_xml_parse.cpp
index 89ecdf4..552f295 100755
--- a/CameraHal/CameraHal_board_xml_parse.cpp
+++ b/CameraHal/CameraHal_board_xml_parse.cpp
@@ -2395,7 +2395,7 @@ int camera_board_profiles::ProduceNewXml(camera_board_profiles* profiles)
     int fileexit = access(RK_DST_MEDIA_PROFILES_XML_PATH, 0);
     ALOGD("judge the media profile xml fileexit = %d\n", fileexit);    
     //if((int)nCamNum>=1){ 
-    if((int)nCamNum>=1 && fileexit == -1){
+    if((int)nCamNum>=1){^M
         LOG1("enter produce new xml\n");
         //new xml file name
         strlcpy(default_file, RK_DEFAULT_MEDIA_PROFILES_XML_PATH, sizeof(default_file));
@@ -2444,6 +2444,8 @@ int camera_board_profiles::LoadSensor(camera_board_profiles* profiles)
     if(!fp){
         ALOGE(" is not exist, register all\n");
         goto err_end;
+    } else {^M
+        goto err_end;^M
     }
 
     //read sensor name
        

diff --git a/CameraHal/CameraHal_Module.cpp b/CameraHal/CameraHal_Module.cpp
index 01afa0d..07380f2 100755
--- a/CameraHal/CameraHal_Module.cpp
+++ b/CameraHal/CameraHal_Module.cpp
@@ -712,6 +712,7 @@ int camera_get_number_of_cameras(void)
     int cam_cnt=0,fd=-1,rk29_cam[CAMERAS_SUPPORT_MAX];
     struct v4l2_capability capability;
     rk_cam_info_t camInfoTmp[CAMERAS_SUPPORT_MAX];
+    char usbcameraPlug[PROPERTY_VALUE_MAX];
     char *ptr,**ptrr;
     char version[PROPERTY_VALUE_MAX];
     char property[PROPERTY_VALUE_MAX];
@@ -722,7 +723,10 @@ int camera_get_number_of_cameras(void)
     struct timeval t0, t1;
     ::gettimeofday(&t0, NULL);
     
-    if (gCamerasNumber > 0)
+    property_get("persist.sys.usbcamera.status", usbcameraPlug, "");
+    bool plugstate = (strcmp(usbcameraPlug, "add") == 0)
+        || (strcmp(usbcameraPlug, "remove") == 0);
+    if (gCamerasNumber > 0 && !plugstate)
         goto camera_get_number_of_cameras_end;
 
     {
@@ -835,7 +839,7 @@ int camera_get_number_of_cameras(void)
             fd = open(cam_path, O_RDONLY);
             if (fd < 0) {
                 LOGE("Open %s failed! strr: %s",cam_path,strerror(errno));
-                break;
+                continue;
             } 
             LOGD("Open %s success!",cam_path);
 
@@ -849,13 +853,13 @@ int camera_get_number_of_cameras(void)
                 LOGD("Video device(%s): video capture not supported.\n",cam_path);
             } else {
                 rk_cam_total_info* pNewCamInfo = new rk_cam_total_info();
-                memset(camInfoTmp[cam_cnt&0x01].device_path,0x00, sizeof(camInfoTmp[cam_cnt&0x01].device_path));
-                strcat(camInfoTmp[cam_cnt&0x01].device_path,cam_path);
-                memset(camInfoTmp[cam_cnt&0x01].fival_list,0x00, sizeof(camInfoTmp[cam_cnt&0x01].fival_list));
-                memcpy(camInfoTmp[cam_cnt&0x01].driver,capability.driver, sizeof(camInfoTmp[cam_cnt&0x01].driver));
-                camInfoTmp[cam_cnt&0x01].version = capability.version;
+                memset(camInfoTmp[cam_cnt].device_path,0x00, sizeof(camInfoTmp[cam_cnt].device_path));
+                strcat(camInfoTmp[cam_cnt].device_path,cam_path);
+                memset(camInfoTmp[cam_cnt].fival_list,0x00, sizeof(camInfoTmp[cam_cnt].fival_list));
+                memcpy(camInfoTmp[cam_cnt].driver,capability.driver, sizeof(camInfoTmp[cam_cnt].driver));
+                camInfoTmp[cam_cnt].version = capability.version;
                 if (strstr((char*)&capability.card[0], "front") != NULL) {
-                    camInfoTmp[cam_cnt&0x01].facing_info.facing = CAMERA_FACING_FRONT;
+                    camInfoTmp[cam_cnt].facing_info.facing = CAMERA_FACING_FRONT;
 #ifdef LAPTOP
                 } else if (strstr((char*)&capability.card[0], "HP HD") != NULL
                     || strstr((char*)&capability.card[0], "HP IR")) {
@@ -866,14 +870,14 @@ int camera_get_number_of_cameras(void)
                     LOGD("Camera %d name: %s", (cam_cnt&0x01), gUsbCameraNames[cam_cnt&0x01].string());
 #endif
                 } else {
-                    camInfoTmp[cam_cnt&0x01].facing_info.facing = CAMERA_FACING_BACK;
+                    camInfoTmp[cam_cnt].facing_info.facing = CAMERA_FACING_BACK;
                 }  
                 ptr = strstr((char*)&capability.card[0],"-");
                 if (ptr != NULL) {
                     ptr++;
-                    camInfoTmp[cam_cnt&0x01].facing_info.orientation = atoi(ptr);
+                    camInfoTmp[cam_cnt].facing_info.orientation = atoi(ptr);
                 } else {
-                    camInfoTmp[cam_cnt&0x01].facing_info.orientation = 0;
+                    camInfoTmp[cam_cnt].facing_info.orientation = 0;
                 }
 
                 memset(version,0x00,sizeof(version));
@@ -1207,8 +1211,11 @@ int camera_get_number_of_cameras(void)
     }
     #endif
     
-    memcpy(&gCamInfos[0], &camInfoTmp[0], sizeof(rk_cam_info_t));
-    memcpy(&gCamInfos[1], &camInfoTmp[1], sizeof(rk_cam_info_t));
+    for (int i = 0; i < gCamerasNumber; i++) {
+        memcpy(&gCamInfos[i], &camInfoTmp[i], sizeof(rk_cam_info_t));
+    }
+    //memcpy(&gCamInfos[0], &camInfoTmp[0], sizeof(rk_cam_info_t));
+    //memcpy(&gCamInfos[1], &camInfoTmp[1], sizeof(rk_cam_info_t));
 
 
     property_get("ro.sf.hwrotation", property, "0");
@@ -1235,6 +1235,8 @@ int camera_get_number_of_cameras(void)
 camera_get_number_of_cameras_end:
     LOGD("%s(%d): Current board have %d cameras attached.",__FUNCTION__, __LINE__, gCamerasNumber);
 
+    property_set("persist.sys.usbcamera.status", "");
+
        ::gettimeofday(&t1, NULL);
        LOGD("meida_profiles_xml_control time (%ld)us\n", (t1.tv_sec*1000000 + t1.tv_usec) - (t0.tv_sec*1000000 + t0.tv_usec));
 #ifdef LAPTOP
diff --git a/CameraHal/CameraHal_Module.h b/CameraHal/CameraHal_Module.h
index 45c81ec..69be491 100755
--- a/CameraHal/CameraHal_Module.h
+++ b/CameraHal/CameraHal_Module.h
@@ -11,11 +11,11 @@ using namespace android;
 #define CAMERA_DEFAULT_PREVIEW_FPS_MIN    8000        //8 fps
 #define CAMERA_DEFAULT_PREVIEW_FPS_MAX    15000
 #endif
-#define CAMERAS_SUPPORT_MAX             2
+#define CAMERAS_SUPPORT_MAX             10
 #if defined(TARGET_RK3399)
-    #define CAMERAS_SUPPORTED_SIMUL_MAX     2
+    #define CAMERAS_SUPPORTED_SIMUL_MAX     10
 #else
-    #define CAMERAS_SUPPORTED_SIMUL_MAX     1
+    #define CAMERAS_SUPPORTED_SIMUL_MAX     10
 #endif
 #define CAMERA_DEVICE_NAME              "/dev/video"
 #define CAMERA_MODULE_NAME              "RK29_ICS_CameraHal_Module"

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页