From 4e2b7311ef2aa4fdca70fbdbe32e2da4cf2f650e Mon Sep 17 00:00:00 2001 From: Chih-Wei Huang Date: Fri, 22 Mar 2019 23:53:23 +0800 Subject: [PATCH] Search more video device nodes 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 | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/CameraFactory.cpp b/CameraFactory.cpp index 5b022e6..ccd66ad 100644 --- a/CameraFactory.cpp +++ b/CameraFactory.cpp @@ -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; } } } -- 2.11.0