From 697467d9ab3e58690b858d8f9061d52c31f96dbd Mon Sep 17 00:00:00 2001 From: Guosong Zhou Date: Mon, 04 Jan 2016 06:45:54 +0000 Subject: PD#117565: camera: add camera reset and logcat debug interface Change-Id: I08fde8ef4531e347235baf070758e61c9add83c2 --- diff --git a/v3/EmulatedCameraFactory.cpp b/v3/EmulatedCameraFactory.cpp index 3e86aee..ca77151 100644 --- a/v3/EmulatedCameraFactory.cpp +++ b/v3/EmulatedCameraFactory.cpp @@ -50,6 +50,18 @@ static const char *SENSOR_PATH[]={ "/dev/video5", }; +int updateLogLevels() +{ + char levels_value[92]; + int tmp = 4; + if (property_get("camera.log_levels", levels_value, NULL) > 0) + sscanf(levels_value, "%d", &tmp); + else + ALOGD("Can not read property camera.log_levels, using defalut value\n"); + gCamHal_LogLevel = tmp; + return tmp; +} + static int getCameraNum() { int iCamerasNum = 0; for (int i = 0; i < (int)ARRAY_SIZE(SENSOR_PATH); i++ ) { @@ -152,6 +164,8 @@ int EmulatedCameraFactory::cameraDeviceOpen(int camera_id, hw_device_t** device) int valid_id; *device = NULL; + updateLogLevels(); + if (!isConstructedOK()) { ALOGE("%s: EmulatedCameraFactory has failed to initialize", __FUNCTION__); return -EINVAL; diff --git a/v3/fake-pipeline2/Sensor.cpp b/v3/fake-pipeline2/Sensor.cpp index 3962968..fa826bb 100644 --- a/v3/fake-pipeline2/Sensor.cpp +++ b/v3/fake-pipeline2/Sensor.cpp @@ -197,6 +197,7 @@ Sensor::Sensor(): mExitSensorThread(false), mIoctlSupport(0), msupportrotate(0), + mTimeOutCount(0), mScene(kResolution[0], kResolution[1], kElectronsPerLuxSecond) { @@ -448,6 +449,9 @@ status_t Sensor::shutDown() { ALOGV("%s: E", __FUNCTION__); int res; + + mTimeOutCount = 0; + res = requestExitAndWait(); if (res != OK) { ALOGE("Unable to shut down sensor capture thread: %d", res); @@ -2001,6 +2005,16 @@ void Sensor::YUYVToYV12(uint8_t *src, uint8_t *dst, int width, int height) } } +status_t Sensor::force_reset_sensor() { + DBG_LOGA("force_reset_sensor"); + status_t ret; + mTimeOutCount = 0; + ret = streamOff(); + ret = setBuffersFormat(vinfo); + ret = streamOn(); + DBG_LOGB("%s , ret = %d", __FUNCTION__, ret); + return ret; +} void Sensor::captureNV21(StreamBuffer b, uint32_t gain) { #if 0 @@ -2103,9 +2117,13 @@ void Sensor::captureNV21(StreamBuffer b, uint32_t gain) { } CAMHAL_LOGDA("get frame NULL, sleep 5ms"); usleep(5000); + mTimeOutCount++; + if (mTimeOutCount > 300) { + force_reset_sensor(); + } continue; } - + mTimeOutCount = 0; if (vinfo->preview.format.fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG) { if (vinfo->preview.buf.length != vinfo->preview.buf.bytesused) { DBG_LOGB("length=%d, bytesused=%d \n", vinfo->preview.buf.length, vinfo->preview.buf.bytesused); @@ -2289,8 +2307,13 @@ void Sensor::captureYV12(StreamBuffer b, uint32_t gain) { } CAMHAL_LOGDA("get frame NULL, sleep 5ms"); usleep(5000); + mTimeOutCount++; + if (mTimeOutCount > 300) { + force_reset_sensor(); + } continue; } + mTimeOutCount = 0; if (vinfo->preview.format.fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG) { if (vinfo->preview.buf.length != vinfo->preview.buf.bytesused) { CAMHAL_LOGDB("length=%d, bytesused=%d \n", vinfo->preview.buf.length, vinfo->preview.buf.bytesused); @@ -2410,8 +2433,13 @@ void Sensor::captureYUYV(uint8_t *img, uint32_t gain, uint32_t stride) { } CAMHAL_LOGDA("get frame NULL, sleep 5ms"); usleep(5000); + mTimeOutCount++; + if (mTimeOutCount > 300) { + force_reset_sensor(); + } continue; } + mTimeOutCount = 0; if (vinfo->preview.format.fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG) { if (vinfo->preview.buf.length != vinfo->preview.buf.bytesused) { CAMHAL_LOGDB("length=%d, bytesused=%d \n", vinfo->preview.buf.length, vinfo->preview.buf.bytesused); diff --git a/v3/fake-pipeline2/Sensor.h b/v3/fake-pipeline2/Sensor.h index 4f6cc4c..05c1436 100644 --- a/v3/fake-pipeline2/Sensor.h +++ b/v3/fake-pipeline2/Sensor.h @@ -232,6 +232,7 @@ class Sensor: private Thread, public virtual RefBase { // To simplify tracking sensor's current frame void setFrameNumber(uint32_t frameNumber); + status_t force_reset_sensor(); /* * Controls that cause reconfiguration delay */ @@ -356,6 +357,7 @@ class Sensor: private Thread, public virtual RefBase { enum sensor_type_e mSensorType; unsigned int mIoctlSupport; unsigned int msupportrotate; + uint32_t mTimeOutCount; /** * Inherited Thread virtual overrides, and members only used by the -- cgit