From 342584c1cc2d8efe7c9c4447da9c33232c98e7e0 Mon Sep 17 00:00:00 2001 From: Chih-Wei Huang Date: Wed, 20 Jun 2018 18:04:58 +0800 Subject: [PATCH] Ignore invalid camera --- CameraFactory.cpp | 6 ++++++ CameraHardware.cpp | 8 ++++---- V4L2Camera.cpp | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CameraFactory.cpp b/CameraFactory.cpp index 0e8c920..00be34e 100644 --- a/CameraFactory.cpp +++ b/CameraFactory.cpp @@ -150,6 +150,12 @@ void CameraFactory::parseConfig(const char* configFile) // Although realloc could be a costly operation, we only execute this function usually 2 times void CameraFactory::newCameraConfig(int facing, const char* location, int orientation) { + V4L2Camera camera; + if (camera.Open(location) || !camera.getBestPreviewFmt().getFps()) { + ALOGW("ignore invalid camera: %s", location); + return; + } + // Keep track of cameras mCameraNum++; diff --git a/CameraHardware.cpp b/CameraHardware.cpp index 0345039..bcedcde 100644 --- a/CameraHardware.cpp +++ b/CameraHardware.cpp @@ -308,7 +308,7 @@ bool CameraHardware::NegotiatePreviewFormat(struct preview_stream_ops* win) status_t CameraHardware::connectCamera(hw_device_t** device) { - ALOGD("CameraHardware::connectCamera"); + ALOGD("CameraHardware::connectCamera: %s", mVideoDevice); *device = &common; return NO_ERROR; @@ -324,7 +324,7 @@ status_t CameraHardware::closeCamera() status_t CameraHardware::getCameraInfo(struct camera_info* info, int facing, int orientation) { - ALOGD("CameraHardware::getCameraInfo"); + ALOGV("CameraHardware::getCameraInfo"); info->facing = facing; info->orientation = orientation; @@ -684,7 +684,7 @@ status_t CameraHardware::cancelPicture() status_t CameraHardware::setParameters(const char* parms) { - ALOGD("CameraHardware::setParameters"); + ALOGV("CameraHardware::setParameters"); CameraParameters params; String8 str8_param(parms); @@ -974,7 +974,7 @@ void CameraHardware::initDefaultParameters() void CameraHardware::initHeapLocked() { - ALOGD("CameraHardware::initHeapLocked"); + ALOGV("CameraHardware::initHeapLocked"); int preview_width, preview_height; int picture_width, picture_height; diff --git a/V4L2Camera.cpp b/V4L2Camera.cpp index 49949cf..08b5ba2 100644 --- a/V4L2Camera.cpp +++ b/V4L2Camera.cpp @@ -64,6 +64,7 @@ int V4L2Camera::Open (const char *device) ALOGE("ERROR opening V4L interface %s: %s", device, strerror(errno)); return -1; } + ALOGD("Open %s OK", device); ret = ioctl (fd, VIDIOC_QUERYCAP, &videoIn->cap); if (ret < 0) { -- 2.11.0