Skip to content

Commit

Permalink
msm8956-common: Camera: HAL flashlight control [SQUASH]
Browse files Browse the repository at this point in the history
msm8956-common: QCamera2: Control longshot via parameters

msm8956-common: QCamera2: Add HAL support for flashlight

msm8956-common: QCamera2: Prevent fail if flashlight control not used

msm8956-common: QCamera2: flashlight control via camera flash device

msm8956-common: camera: Add HAL support for flashlight

msm8956-common: camera: flashlight control via camera flash device
  • Loading branch information
billchen1977 authored and Adarsh-MR committed May 3, 2018
1 parent e728c63 commit bffc23d
Show file tree
Hide file tree
Showing 15 changed files with 772 additions and 27 deletions.
5 changes: 5 additions & 0 deletions BoardConfigCommon.mk
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ QCOM_BT_USE_SMD_TTY := true
BOARD_QTI_CAMERA_32BIT_ONLY := true
USE_DEVICE_SPECIFIC_CAMERA := true
TARGET_TS_MAKEUP := true
TARGET_FLASHLIGHT_CONTROL := true
TARGET_FLASHLIGHT_CONTROL_ID := 0
TARGET_FLASHLIGHT_CONTROL_PATH := /dev/v4l-subdev7
TARGET_FLASHLIGHT_CURRENT_VALUE0 := 195
TARGET_FLASHLIGHT_CURRENT_VALUE1 := 78

# Charger
BOARD_CHARGER_ENABLE_SUSPEND := true
Expand Down
22 changes: 22 additions & 0 deletions camera/QCamera2/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ LOCAL_SRC_FILES := \
util/QCameraCmdThread.cpp \
util/QCameraQueue.cpp \
util/QCameraBufferMaps.cpp \
util/QCameraFlash.cpp \
QCamera2Hal.cpp \
QCamera2Factory.cpp

Expand Down Expand Up @@ -58,6 +59,7 @@ LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/../mm-image-codec/qomx_core \
$(LOCAL_PATH)/util \
hardware/qcom/media-caf/msm8952/mm-core/inc \
$(LOCAL_PATH)/HAL3

#HAL 1.0 Include paths
LOCAL_C_INCLUDES += \
Expand All @@ -71,6 +73,26 @@ ifeq ($(TARGET_TS_MAKEUP),true)
LOCAL_CFLAGS += -DTARGET_TS_MAKEUP
LOCAL_C_INCLUDES += $(LOCAL_PATH)/HAL/tsMakeuplib/include
endif

ifeq ($(TARGET_FLASHLIGHT_CONTROL),true)
LOCAL_CFLAGS += -DFLASHLIGHT_CONTROL
ifdef TARGET_FLASHLIGHT_CONTROL_ID
LOCAL_CFLAGS += -DFLASHLIGHT_CONTROL_ID=$(TARGET_FLASHLIGHT_CONTROL_ID)
endif
ifdef TARGET_FLASHLIGHT_CONTROL_PATH
LOCAL_CFLAGS += -DFLASHLIGHT_CONTROL_PATH=\"$(TARGET_FLASHLIGHT_CONTROL_PATH)\"
endif
ifdef TARGET_FLASHLIGHT_CURRENT_VALUE0
LOCAL_CFLAGS += -DFLASHLIGHT_CURRENT_VALUE0=$(TARGET_FLASHLIGHT_CURRENT_VALUE0)
endif
ifdef TARGET_FLASHLIGHT_CURRENT_VALUE1
LOCAL_CFLAGS += -DFLASHLIGHT_CURRENT_VALUE1=$(TARGET_FLASHLIGHT_CURRENT_VALUE1)
endif
ifdef TARGET_FLASHLIGHT_CURRENT_VALUE2
LOCAL_CFLAGS += -DFLASHLIGHT_CURRENT_VALUE2=$(TARGET_FLASHLIGHT_CURRENT_VALUE2)
endif
endif

ifneq (,$(filter msm8974 msm8916 msm8226 msm8610 msm8916 apq8084 msm8084 msm8994 msm8992 msm8952 msm8996,$(TARGET_BOARD_PLATFORM)))
LOCAL_CFLAGS += -DVENUS_PRESENT
endif
Expand Down
122 changes: 118 additions & 4 deletions camera/QCamera2/HAL/QCamera2HWI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <stdlib.h>
#include <utils/Errors.h>
#include <gralloc_priv.h>
#include "util/QCameraFlash.h"
#include <binder/Parcel.h>
#include <binder/IServiceManager.h>
#include <utils/RefBase.h>
Expand Down Expand Up @@ -1804,6 +1805,14 @@ int QCamera2HardwareInterface::openCamera()
return ALREADY_EXISTS;
}

rc = QCameraFlash::getInstance().reserveFlashForCamera(mCameraId);
if (rc < 0) {
ALOGE("%s: Failed to reserve flash for camera id: %d",
__func__,
mCameraId);
return UNKNOWN_ERROR;
}

// alloc param buffer
DeferWorkArgs args;
memset(&args, 0, sizeof(args));
Expand Down Expand Up @@ -2183,6 +2192,13 @@ int QCamera2HardwareInterface::closeCamera()
free(mExifParams.debug_params);
mExifParams.debug_params = NULL;
}

if (QCameraFlash::getInstance().releaseFlashFromCamera(mCameraId) != 0) {
CDBG("%s: Failed to release flash for camera id: %d",
__func__,
mCameraId);
}

ALOGI("[KPI Perf] %s: X PROFILE_CLOSE_CAMERA camera id %d, rc: %d",
__func__, mCameraId, rc);

Expand Down Expand Up @@ -5307,6 +5323,83 @@ int QCamera2HardwareInterface::sendCommand(int32_t command,
CDBG_HIGH("%s: Histogram -> %s", __func__,
mParameters.isHistogramEnabled() ? "Enabled" : "Disabled");
break;
#else
case CAMERA_CMD_LONGSHOT_ON:
arg1 = arg2 = 0;
// Longshot can only be enabled when image capture
// is not active.
if ( !m_stateMachine.isCaptureRunning() && m_stateMachine.isPreviewRunning() ) {
if (!mLongshotEnabled) {
CDBG_HIGH("%s: Longshot Enabled", __func__);
mLongshotEnabled = true;
pthread_mutex_lock(&m_parm_lock);
rc = mParameters.setLongshotEnable(mLongshotEnabled);
pthread_mutex_unlock(&m_parm_lock);

// Due to recent buffer count optimizations
// ZSL might run with considerably less buffers
// when not in longshot mode. Preview needs to
// restart in this case.
if (isZSLMode()) {
QCameraChannel *pChannel = NULL;
QCameraStream *pSnapStream = NULL;
pChannel = m_channels[QCAMERA_CH_TYPE_ZSL];
if (NULL != pChannel) {
QCameraStream *pStream = NULL;
for (uint32_t i = 0; i < pChannel->getNumOfStreams(); i++) {
pStream = pChannel->getStreamByIndex(i);
if (pStream != NULL) {
if (pStream->isTypeOf(CAM_STREAM_TYPE_SNAPSHOT)) {
pSnapStream = pStream;
break;
}
}
}
if (NULL != pSnapStream) {
uint8_t required = 0;
required = getBufNumRequired(CAM_STREAM_TYPE_SNAPSHOT);
if (pSnapStream->getBufferCount() < required) {
// We restart here, to reset the FPS and no
// of buffers as per the requirement of longshot usecase.
arg1 = QCAMERA_SM_EVT_RESTART_PERVIEW;
if (getRelatedCamSyncInfo()->sync_control ==
CAM_SYNC_RELATED_SENSORS_ON) {
arg2 = QCAMERA_SM_EVT_DELAYED_RESTART;
}
}
}
}
}
//
mPrepSnapRun = false;
mCACDoneReceived = FALSE;
}
} else {
rc = NO_INIT;
}
break;
case CAMERA_CMD_LONGSHOT_OFF:
arg1 = arg2 = 0;
if ( mLongshotEnabled ) {
if ( m_stateMachine.isCaptureRunning() ) {
cancelPicture();
processEvt(QCAMERA_SM_EVT_SNAPSHOT_DONE, NULL);
QCameraChannel *pZSLChannel = m_channels[QCAMERA_CH_TYPE_ZSL];
if (isZSLMode() && (NULL != pZSLChannel) && mPrepSnapRun) {
mCameraHandle->ops->stop_zsl_snapshot(
mCameraHandle->camera_handle,
pZSLChannel->getMyHandle());
}
}
mPrepSnapRun = false;
CDBG_HIGH("%s: Longshot Disabled", __func__);
mLongshotEnabled = false;
pthread_mutex_lock(&m_parm_lock);
rc = mParameters.setLongshotEnable(mLongshotEnabled);
pthread_mutex_unlock(&m_parm_lock);
mCACDoneReceived = FALSE;
}
break;
#endif
case CAMERA_CMD_START_FACE_DETECTION:
case CAMERA_CMD_STOP_FACE_DETECTION:
Expand Down Expand Up @@ -8368,12 +8461,33 @@ int QCamera2HardwareInterface::updateThermalLevel(void *thermal_level)
*==========================================================================*/
int QCamera2HardwareInterface::updateParameters(const char *parms, bool &needRestart)
{
int rc = NO_ERROR;
int final_rc = NO_ERROR;
int rc;

pthread_mutex_lock(&m_parm_lock);
String8 str = String8(parms);
QCameraParameters param(str);
rc = mParameters.updateParameters(param, needRestart);

#ifdef VANILLA_HAL
const char *longshot = param.get(QCameraParameters::KEY_QC_LONG_SHOT);
int32_t arg1 = 0, arg2 = 0;
if (longshot != NULL) {
if (!strcmp(longshot, QCameraParameters::VALUE_ON))
rc = sendCommand(CAMERA_CMD_LONGSHOT_ON, arg1, arg2);
else
rc = sendCommand(CAMERA_CMD_LONGSHOT_OFF, arg1, arg2);
if (rc == NO_ERROR) {
if (arg1 == QCAMERA_SM_EVT_RESTART_PERVIEW)
needRestart = true;
} else {
param.remove(QCameraParameters::KEY_QC_LONG_SHOT);
final_rc = rc;
}
}
#endif

pthread_mutex_lock(&m_parm_lock);
if ((rc = mParameters.updateParameters(param, needRestart)))
final_rc = rc;

// update stream based parameter settings
for (int i = 0; i < QCAMERA_CH_TYPE_MAX; i++) {
Expand All @@ -8383,7 +8497,7 @@ int QCamera2HardwareInterface::updateParameters(const char *parms, bool &needRes
}
pthread_mutex_unlock(&m_parm_lock);

return rc;
return final_rc;
}

/*===========================================================================
Expand Down
5 changes: 5 additions & 0 deletions camera/QCamera2/HAL/QCamera2HWI.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ typedef struct {

#define MAX(a, b) ((a) > (b) ? (a) : (b))

#ifdef VANILLA_HAL
#define CAMERA_CMD_LONGSHOT_ON 23
#define CAMERA_CMD_LONGSHOT_OFF 24
#endif

extern volatile uint32_t gCamHalLogLevel;

typedef enum {
Expand Down
12 changes: 7 additions & 5 deletions camera/QCamera2/HAL/QCameraMuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

#include "QCameraMuxer.h"
#include "QCamera2HWI.h"
#include "QCamera3HWI.h"
#include "QCameraPostProc.h"

#include <sys/stat.h>
Expand Down Expand Up @@ -223,13 +224,12 @@ int QCameraMuxer::get_camera_info(int camera_id, struct camera_info *info)
{
int rc = NO_ERROR;
CDBG_HIGH("%s: E", __func__);
cam_sync_type_t type;
if ((camera_id < 0) || (camera_id >= gMuxer->getNumberOfCameras())) {
ALOGE("%s : Camera id %d not found!", __func__, camera_id);
return -ENODEV;
}
if(info) {
rc = gMuxer->getCameraInfo(camera_id, info, &type);
rc = gMuxer->getCameraInfo(camera_id, info);
}
CDBG_HIGH("%s: X, rc: %d", __func__, rc);
return rc;
Expand Down Expand Up @@ -1905,8 +1905,7 @@ int QCameraMuxer::getNumberOfCameras()
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int QCameraMuxer::getCameraInfo(int camera_id,
struct camera_info *info, cam_sync_type_t *p_cam_type)
int QCameraMuxer::getCameraInfo(int camera_id, struct camera_info *info)
{
int rc = NO_ERROR;
CDBG_HIGH("%s: E, camera_id = %d", __func__, camera_id);
Expand All @@ -1926,7 +1925,10 @@ int QCameraMuxer::getCameraInfo(int camera_id,
uint32_t phy_id =
m_pLogicalCamera[camera_id].pId[
m_pLogicalCamera[camera_id].nPrimaryPhyCamIndex];
rc = QCamera2HardwareInterface::getCapabilities(phy_id, info, &cam_type);
// Call HAL3 getCamInfo to get the flash light info through static metatdata
// regardless of HAL version
rc = QCamera3HardwareInterface::getCamInfo(phy_id, info);
info->device_version = CAMERA_DEVICE_API_VERSION_1_0; // Hardcode the HAL to HAL1
CDBG_HIGH("%s: X", __func__);
return rc;
}
Expand Down
4 changes: 2 additions & 2 deletions camera/QCamera2/HAL/QCameraMuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <hardware/camera.h>
#include <system/camera.h>
#include "QCamera2HWI.h"
#include "QCamera3HWI.h"

namespace qcamera {

Expand Down Expand Up @@ -255,8 +256,7 @@ class QCameraMuxer {
int setupLogicalCameras();
int cameraDeviceOpen(int camera_id, struct hw_device_t **hw_device);
int getNumberOfCameras();
int getCameraInfo(int camera_id, struct camera_info *info,
cam_sync_type_t *p_cam_type);
int getCameraInfo(int camera_id, struct camera_info *info);
int32_t setCallbacks(const camera_module_callbacks_t *callbacks);
int32_t setDataCallback(camera_data_callback data_cb);
int32_t setMemoryCallback(camera_request_memory get_memory);
Expand Down
21 changes: 21 additions & 0 deletions camera/QCamera2/HAL3/QCamera3HWI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <utils/Errors.h>
#include <ui/Fence.h>
#include <gralloc_priv.h>
#include "util/QCameraFlash.h"
#include "QCamera3HWI.h"
#include "QCamera3Mem.h"
#include "QCamera3Channel.h"
Expand Down Expand Up @@ -599,11 +600,21 @@ int QCamera3HardwareInterface::openCamera()
ALOGE("Failure: Camera already opened");
return ALREADY_EXISTS;
}

rc = QCameraFlash::getInstance().reserveFlashForCamera(mCameraId);
if (rc < 0) {
ALOGE("%s: Failed to reserve flash for camera id: %d",
__func__,
mCameraId);
return UNKNOWN_ERROR;
}

rc = camera_open((uint8_t)mCameraId, &mCameraHandle);
if (rc) {
ALOGE("camera_open failed. rc = %d, mCameraHandle = %p", rc, mCameraHandle);
return rc;
}

if (!mCameraHandle) {
ALOGE("camera_open failed. mCameraHandle = %p", mCameraHandle);
return -ENODEV;
Expand Down Expand Up @@ -703,6 +714,11 @@ int QCamera3HardwareInterface::closeCamera()
free(mExifParams.debug_params);
mExifParams.debug_params = NULL;
}
if (QCameraFlash::getInstance().releaseFlashFromCamera(mCameraId) != 0) {
CDBG("%s: Failed to release flash for camera id: %d",
__func__,
mCameraId);
}

return rc;
}
Expand Down Expand Up @@ -6438,6 +6454,11 @@ int QCamera3HardwareInterface::getCamInfo(uint32_t cameraId,
info->device_version = CAMERA_DEVICE_API_VERSION_3_2;
info->static_camera_characteristics = gStaticMetadata[cameraId];

//assume both cameras cannot operate independently.
info->resource_cost = 100;
info->conflicting_devices = NULL;
info->conflicting_devices_length = 0;

pthread_mutex_unlock(&gCamLock);

return rc;
Expand Down
Loading

0 comments on commit bffc23d

Please sign in to comment.