OSDN Git Service

Search more video device nodes android-x86-7.1-r3 android-x86-8.1-r2 android-x86-8.1-r3 android-x86-8.1-r4 android-x86-9.0-r1 android-x86-9.0-r2
authorChih-Wei Huang <cwhuang@linux.org.tw>
Fri, 22 Mar 2019 15:53:23 +0000 (23:53 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Fri, 22 Mar 2019 15:53:23 +0000 (23:53 +0800)
Since the newer kernel may create more than one device nodes for one
camera, the hardcoded device node path is not appropriate.

The patch searches all /dev/video[0-9] and configure up to 3 cameras
if possible. Besides, the facing and orientation could be configured
via the property hal.camera.[0-9].

CameraFactory.cpp

index 5b022e6..ccd66ad 100644 (file)
@@ -20,8 +20,6 @@
  */
 
 #define LOG_NDEBUG 0
-#define DEFAULT_DEVICE_FRONT "/dev/video1"
-#define DEFAULT_DEVICE_BACK  "/dev/video0"
 #define CONFIG_FILE "/etc/camera.cfg"
 #define LOG_TAG "Camera_Factory"
 
@@ -140,13 +138,24 @@ void CameraFactory::parseConfig(const char* configFile)
         }
     } else {
         ALOGD("%s not found, using camera configuration defaults", CONFIG_FILE);
-        if (access(DEFAULT_DEVICE_BACK, F_OK) != -1){
-            ALOGD("Found device %s", DEFAULT_DEVICE_BACK);
-            newCameraConfig(CAMERA_FACING_BACK, DEFAULT_DEVICE_BACK, 0);
+        char camera_node[] = "/dev/video0";
+        char camera_prop[] = "hal.camera.0";
+        char prop[PROPERTY_VALUE_MAX] = "";
+        while (camera_node[10] <= '9' && mCameraNum < 3) {
+            if (!access(camera_node, F_OK)) {
+                int facing = mCameraNum, orientation = 0;
+                if (property_get(camera_prop, prop, "")) {
+                    sscanf(prop, "%d,%d", &facing, &orientation);
+                    ALOGI("%s got facing=%d orient=%d from property %s", __FUNCTION__, facing, orientation, camera_prop);
+                }
+                newCameraConfig(facing, camera_node, orientation);
+            }
+            camera_node[10]++, camera_prop[11]++;
         }
-        if (access(DEFAULT_DEVICE_FRONT, F_OK) != -1){
-            ALOGD("Found device %s", DEFAULT_DEVICE_FRONT);
-            newCameraConfig(CAMERA_FACING_FRONT, DEFAULT_DEVICE_FRONT, 0);
+
+        // If there is only one camera, assume its facing is front
+        if (mCameraNum == 1 && prop[0] == '\0') {
+            mCameraFacing[0] = CAMERA_FACING_FRONT;
         }
     }
 }