[RK3399][Android7.1] 调试笔记 --- 三颗以上USB Camera的支持

Platform: RK3399
OS: Android 7.1
Kernel: v4.4.83

需求

需要支持三个USB Camera,系统默认支持的是两颗。


解决方法:

以下是rockchip给的patch,不过是有缺失的:

diff --git a/CameraHal/CameraHal_Module.cpp b/CameraHal/CameraHal_Module.cpp
index 27e0f54..fa99a38 100755
--- a/CameraHal/CameraHal_Module.cpp
+++ b/CameraHal/CameraHal_Module.cpp
@@ -684,6 +684,7 @@ int camera_get_number_of_cameras(void)
     
     memset(&camInfoTmp[0],0x00,sizeof(rk_cam_info_t));
     memset(&camInfoTmp[1],0x00,sizeof(rk_cam_info_t));
+    memset(&camInfoTmp[2],0x00,sizeof(rk_cam_info_t));
 
     profiles = camera_board_profiles::getInstance();
     nCamDev = profiles->mDevieVector.size();
@@ -691,25 +692,25 @@ int camera_get_number_of_cameras(void)
     if (nCamDev>0) {
         camera_board_profiles::LoadSensor(profiles);
         char sensor_ver[32];
-		
+
         for (i=0; (i<nCamDev); i++) 
         {  
         	LOGE("load sensor name(%s) connect %d\n", profiles->mDevieVector[i]->mHardInfo.mSensorInfo.mSensorName, profiles->mDevieVector[i]->mIsConnect);
         	if(profiles->mDevieVector[i]->mIsConnect==1){
     	        rk_sensor_info *pSensorInfo = &(profiles->mDevieVector[i]->mHardInfo.mSensorInfo);
     	        
-    	        camInfoTmp[cam_cnt&0x01].pcam_total_info = profiles->mDevieVector[i];     
-    	        strncpy(camInfoTmp[cam_cnt&0x01].device_path, pSensorInfo->mCamsysDevPath, sizeof(camInfoTmp[cam_cnt&0x01].device_path));
-    	        strncpy(camInfoTmp[cam_cnt&0x01].driver, pSensorInfo->mSensorDriver, sizeof(camInfoTmp[cam_cnt&0x01].driver));
+    	        camInfoTmp[cam_cnt].pcam_total_info = profiles->mDevieVector[i];
+    	        strncpy(camInfoTmp[cam_cnt].device_path, pSensorInfo->mCamsysDevPath, sizeof(camInfoTmp[cam_cnt].device_path));
+    	        strncpy(camInfoTmp[cam_cnt].driver, pSensorInfo->mSensorDriver, sizeof(camInfoTmp[cam_cnt].driver));
 				unsigned int SensorDrvVersion = profiles->mDevieVector[i]->mLoadSensorInfo.mpI2cInfo->sensor_drv_version;
 				memset(version,0x00,sizeof(version));
     	        sprintf(version,"%d.%d.%d",((SensorDrvVersion&0xff0000)>>16),
 	    	            ((SensorDrvVersion&0xff00)>>8),SensorDrvVersion&0xff);
 						 
     	        if(pSensorInfo->mFacing == RK_CAM_FACING_FRONT){     
-    	            camInfoTmp[cam_cnt&0x01].facing_info.facing = CAMERA_FACING_FRONT;	    	        
+    	            camInfoTmp[cam_cnt].facing_info.facing = CAMERA_FACING_FRONT;        
     	        } else {
-    	            camInfoTmp[cam_cnt&0x01].facing_info.facing = CAMERA_FACING_BACK;
+    	            camInfoTmp[cam_cnt].facing_info.facing = CAMERA_FACING_BACK;
     	        } 
 
                 memset(sensor_ver,0x00,sizeof(sensor_ver));
@@ -719,7 +720,7 @@ int camera_get_number_of_cameras(void)
                     sprintf(sensor_ver,"%s",pSensorInfo->mSensorName);                
                 property_set(sensor_ver, version);	
                 
-    	        camInfoTmp[cam_cnt&0x01].facing_info.orientation = pSensorInfo->mOrientation;
+    	        camInfoTmp[cam_cnt].facing_info.orientation = pSensorInfo->mOrientation;
     	        cam_cnt++;
 
     			unsigned int CamsysDrvVersion = profiles->mDevieVector[i]->mCamsysVersion.drv_ver;
@@ -762,22 +763,22 @@ 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;
                 } 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));
@@ -1031,6 +1032,7 @@ int camera_get_number_of_cameras(void)
 					
 					strcpy(pNewCamInfo->mHardInfo.mSensorInfo.mSensorName, SOC_CAM_NAME);
 					pNewCamInfo->mIsIommuEnabled = capability.reserved[0];
+                    LOGD("mIsIommuEnabled=%d----------",pNewCamInfo->mIsIommuEnabled);
 					if (strstr((char*)&capability.card[0], "front") != NULL) {
                     	pNewCamInfo->mHardInfo.mSensorInfo.mFacing = 1;
                 	} else {
@@ -1095,6 +1097,7 @@ int camera_get_number_of_cameras(void)
     
     memcpy(&gCamInfos[0], &camInfoTmp[0], sizeof(rk_cam_info_t));
     memcpy(&gCamInfos[1], &camInfoTmp[1], sizeof(rk_cam_info_t));
+    memcpy(&gCamInfos[2], &camInfoTmp[2], sizeof(rk_cam_info_t));
 
 
     property_get("ro.sf.hwrotation", property, "0");
diff --git a/CameraHal/CameraHal_Module.h b/CameraHal/CameraHal_Module.h
index bac86d6..66bcd81 100755
--- a/CameraHal/CameraHal_Module.h
+++ b/CameraHal/CameraHal_Module.h
@@ -11,8 +11,8 @@ 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_SUPPORTED_SIMUL_MAX     1
+#define CAMERAS_SUPPORT_MAX             3
+#define CAMERAS_SUPPORTED_SIMUL_MAX     3
 #define CAMERA_DEVICE_NAME              "/dev/video"
 #define CAMERA_MODULE_NAME              "RK29_ICS_CameraHal_Module"
 
diff --git a/CameraHal/CameraHal_board_xml_parse.cpp b/CameraHal/CameraHal_board_xml_parse.cpp
old mode 100644
new mode 100755
index fcbab39..35e4d72
--- a/CameraHal/CameraHal_board_xml_parse.cpp
+++ b/CameraHal/CameraHal_board_xml_parse.cpp
@@ -1519,11 +1519,12 @@ int camera_board_profiles::CheckSensorSupportDV(rk_cam_total_info* pCamInfo)
 					ALOGD("(%s) UVC camera resolution(%dx%d) is support \n", pCamInfo->mHardInfo.mSensorInfo.mSensorName, pDVInfo->mWidth, pDVInfo->mHeight);
 			}
 			else if(strcmp(pCamInfo->mHardInfo.mSensorInfo.mSensorName, SOC_CAM_NAME)==0){
-				if(pDVInfo->mIsSupport)
+				if(pDVInfo->mIsSupport){
 					pDVInfo->mAddMask = 0;
-				else{
+                    ALOGD("(%s) SOC camera resolution(%dx%d) is support \n", pCamInfo->mHardInfo.mSensorInfo.mSensorName, pDVInfo->mWidth, pDVInfo->mHeight);
+				}else{
 					pDVInfo->mAddMask = 1;
-					ALOGD("(%s) SOC camera resolution(%dx%d) is support \n", pCamInfo->mHardInfo.mSensorInfo.mSensorName, pDVInfo->mWidth, pDVInfo->mHeight);
+					//ALOGD("(%s) SOC camera resolution(%dx%d) is support \n", pCamInfo->mHardInfo.mSensorInfo.mSensorName, pDVInfo->mWidth, pDVInfo->mHeight);
 				}
 			}
 			else{ 
@@ -1543,6 +1544,7 @@ int camera_board_profiles::CheckSensorSupportDV(rk_cam_total_info* pCamInfo)
                                 if ((unsigned int)(ISI_FPS_GET(pCaps->caps.Resolution)) >= pDVInfo->mFps) {
                                     pDVInfo->mFps = ISI_FPS_GET(pCaps->caps.Resolution);
                                     pDVInfo->mAddMask = 0;
+                                    ALOGD("(%s) mipi camera resolution(%dx%d) is support \n", pCamInfo->mHardInfo.mSensorInfo.mSensorName, pDVInfo->mWidth, pDVInfo->mHeight);
                                 }
                             }
                             l = l->p_next;
@@ -1603,10 +1605,12 @@ int camera_board_profiles::WriteDevNameTOXML(camera_board_profiles* profiles, ch
 				continue;
 			}
 
-			for(i=0; (i<(int)nCamNum && i<2); i++){
+			for(i=0; (i<(int)nCamNum /*&& i<2*/); i++){
 				fprintf(fpdst, "  \n", 
                     i, profiles->mDevideConnectVector[i]->mHardInfo.mSensorInfo.mSensorName,
                     profiles->mDevideConnectVector[i]->mDeviceIndex, profiles->mDevideConnectVector[i]->mHardInfo.mSensorInfo.mFacing);
+                LOGD("videoname%d=\"%s\" index=%d facing=%d-----rk",i, profiles->mDevideConnectVector[i]->mHardInfo.mSensorInfo.mSensorName,
+                    profiles->mDevideConnectVector[i]->mDeviceIndex, profiles->mDevideConnectVector[i]->mHardInfo.mSensorInfo.mFacing);
 			}
 			isWrite=1;	
 		}
@@ -1811,7 +1815,7 @@ int camera_board_profiles::ModifyMediaProfileXML( camera_board_profiles* profile
 	long front_fptmp = 0,back_fptmp = 0;
     char *leave_line, *leave_line1, *leave_line2;
     
-	xml_fp_pos_s fp_pos[2];  
+	xml_fp_pos_s fp_pos[3];  
 	xml_video_element_s find_element;
 
 	src_fp = fopen(src_xml_file, "r");
@@ -1848,12 +1852,24 @@ int camera_board_profiles::ModifyMediaProfileXML( camera_board_profiles* profile
 		goto alter_exit;	
 	}
 
+	fp_pos[2].camid = 2;
+    fp_pos[2].camid_start = 0;
+    fp_pos[2].camid_end = 0;
+	ret = XMLFseekCamIDPos(src_fp, &fp_pos[2]);
+	if(ret < 0 || fp_pos[2].camid_end <= fp_pos[2].camid_start){
+		ALOGE("find camid(%d) failed\n", fp_pos[2].camid);
+		err = -3;
+		goto alter_exit;	
+	}
+
     find_element.isAddMark = 1;
     find_element.n_cameraId = -1;
     find_element.n_frameRate = 0;
     find_element.n_width = 0;
     find_element.n_height = 0;
-	if(fp_pos[0].camid_end>0 && fp_pos[0].camid_start>0 && fp_pos[1].camid_end>0 && fp_pos[1].camid_start>0){
+	if(fp_pos[0].camid_end>0 && fp_pos[0].camid_start>0 && 
+       fp_pos[1].camid_end>0 && fp_pos[1].camid_start>0 &&
+       fp_pos[2].camid_end>0 && fp_pos[2].camid_start>0){
 		fseek(src_fp,0,SEEK_SET); 
 		fseek(dst_fp,0,SEEK_SET);
 			
@@ -1945,6 +1961,8 @@ int camera_board_profiles::ModifyMediaProfileXML( camera_board_profiles* profile
 					find_element.n_cameraId = 0;
 				else if(now_fp_pos>fp_pos[1].camid_start && now_fp_pos<fp_pos[1].camid_end)
 					find_element.n_cameraId = 1;
+				else if(now_fp_pos>fp_pos[2].camid_start && now_fp_pos<fp_pos[2].camid_end)
+					find_element.n_cameraId = 2;
 				else
 					find_element.n_cameraId = -1;
 				
@@ -2033,7 +2051,7 @@ int camera_board_profiles::ProduceNewXml(camera_board_profiles* profiles)
 	size_t nCamNum =profiles->mDevideConnectVector.size();
 	
 	//verrify media_xml_device is supported by board xml 
-    for(int i=0; (i<profiles->xml_device_count && i<2); i++)
+    for(int i=0; (i<profiles->xml_device_count && i<nCamNum); i++)
     {
     	res |= ConnectDevHaveDev(profiles, (profiles->mXmlDevInfo + i));
     }
@@ -2047,6 +2065,7 @@ int camera_board_profiles::ProduceNewXml(camera_board_profiles* profiles)
     //if((int)nCamNum>=1){ 
     if((int)nCamNum>=1 && fileexit == -1){
         LOG1("enter produce new xml\n");
+        LOGD("nCamNum=%d",nCamNum);
         //new xml file name
         strlcpy(default_file, RK_DEFAULT_MEDIA_PROFILES_XML_PATH, sizeof(default_file));
         strlcpy(dst_file, RK_DST_MEDIA_PROFILES_XML_PATH, sizeof(dst_file));

开机后Camera HAL层模块函数ModifyMediaProfileXML()会提示找不到 camid(2), 这是由于系统的media_profiles.xml是基于 media_profiles_default.xml创建的, 此文件位于 device/rockchip/common下面。
因此,只要在此文件中添加对应camera id 2的 CamcorderProfiles栏位就可以正常了。

添加四颗以上的USB Camera方法同理。

你可能感兴趣的:(RK3399,子类__Camera)