blob: 8fe830120ec4b51673e50a745d0fa83fed2b352e [file] [log] [blame]
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define LOG_TAG "QCamera3HWI"
//#define LOG_NDEBUG 0
#define __STDC_LIMIT_MACROS
// To remove
#include <cutils/properties.h>
// System dependencies
#include <dlfcn.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sync/sync.h>
#include "gralloc_priv.h"
// Display dependencies
#include "qdMetaData.h"
// Camera dependencies
#include "android/QCamera3External.h"
#include "util/QCameraFlash.h"
#include "QCamera3HWI.h"
#include "QCamera3VendorTags.h"
#include "QCameraTrace.h"
extern "C" {
#include "mm_camera_dbg.h"
}
using namespace android;
namespace qcamera {
#define DATA_PTR(MEM_OBJ,INDEX) MEM_OBJ->getPtr( INDEX )
#define EMPTY_PIPELINE_DELAY 2
#define PARTIAL_RESULT_COUNT 2
#define FRAME_SKIP_DELAY 0
#define MAX_VALUE_8BIT ((1<<8)-1)
#define MAX_VALUE_10BIT ((1<<10)-1)
#define MAX_VALUE_12BIT ((1<<12)-1)
#define VIDEO_4K_WIDTH 3840
#define VIDEO_4K_HEIGHT 2160
#define MAX_EIS_WIDTH 3840
#define MAX_EIS_HEIGHT 2160
#define MAX_RAW_STREAMS 1
#define MAX_STALLING_STREAMS 1
#define MAX_PROCESSED_STREAMS 3
/* Batch mode is enabled only if FPS set is equal to or greater than this */
#define MIN_FPS_FOR_BATCH_MODE (120)
#define PREVIEW_FPS_FOR_HFR (30)
#define DEFAULT_VIDEO_FPS (30.0)
#define TEMPLATE_MAX_PREVIEW_FPS (30.0)
#define MAX_HFR_BATCH_SIZE (8)
#define REGIONS_TUPLE_COUNT 5
#define HDR_PLUS_PERF_TIME_OUT (7000) // milliseconds
// Set a threshold for detection of missing buffers //seconds
#define MISSING_REQUEST_BUF_TIMEOUT 3
#define FLUSH_TIMEOUT 3
#define METADATA_MAP_SIZE(MAP) (sizeof(MAP)/sizeof(MAP[0]))
#define CAM_QCOM_FEATURE_PP_SUPERSET_HAL3 ( CAM_QCOM_FEATURE_DENOISE2D |\
CAM_QCOM_FEATURE_CROP |\
CAM_QCOM_FEATURE_ROTATION |\
CAM_QCOM_FEATURE_SHARPNESS |\
CAM_QCOM_FEATURE_SCALE |\
CAM_QCOM_FEATURE_CAC |\
CAM_QCOM_FEATURE_CDS )
/* Per configuration size for static metadata length*/
#define PER_CONFIGURATION_SIZE_3 (3)
#define TIMEOUT_NEVER -1
cam_capability_t *gCamCapability[MM_CAMERA_MAX_NUM_SENSORS];
const camera_metadata_t *gStaticMetadata[MM_CAMERA_MAX_NUM_SENSORS];
extern pthread_mutex_t gCamLock;
volatile uint32_t gCamHal3LogLevel = 1;
extern uint8_t gNumCameraSessions;
const QCamera3HardwareInterface::QCameraPropMap QCamera3HardwareInterface::CDS_MAP [] = {
{"On", CAM_CDS_MODE_ON},
{"Off", CAM_CDS_MODE_OFF},
{"Auto",CAM_CDS_MODE_AUTO}
};
const QCamera3HardwareInterface::QCameraMap<
camera_metadata_enum_android_control_effect_mode_t,
cam_effect_mode_type> QCamera3HardwareInterface::EFFECT_MODES_MAP[] = {
{ ANDROID_CONTROL_EFFECT_MODE_OFF, CAM_EFFECT_MODE_OFF },
{ ANDROID_CONTROL_EFFECT_MODE_MONO, CAM_EFFECT_MODE_MONO },
{ ANDROID_CONTROL_EFFECT_MODE_NEGATIVE, CAM_EFFECT_MODE_NEGATIVE },
{ ANDROID_CONTROL_EFFECT_MODE_SOLARIZE, CAM_EFFECT_MODE_SOLARIZE },
{ ANDROID_CONTROL_EFFECT_MODE_SEPIA, CAM_EFFECT_MODE_SEPIA },
{ ANDROID_CONTROL_EFFECT_MODE_POSTERIZE, CAM_EFFECT_MODE_POSTERIZE },
{ ANDROID_CONTROL_EFFECT_MODE_WHITEBOARD, CAM_EFFECT_MODE_WHITEBOARD },
{ ANDROID_CONTROL_EFFECT_MODE_BLACKBOARD, CAM_EFFECT_MODE_BLACKBOARD },
{ ANDROID_CONTROL_EFFECT_MODE_AQUA, CAM_EFFECT_MODE_AQUA }
};
const QCamera3HardwareInterface::QCameraMap<
camera_metadata_enum_android_control_awb_mode_t,
cam_wb_mode_type> QCamera3HardwareInterface::WHITE_BALANCE_MODES_MAP[] = {
{ ANDROID_CONTROL_AWB_MODE_OFF, CAM_WB_MODE_OFF },
{ ANDROID_CONTROL_AWB_MODE_AUTO, CAM_WB_MODE_AUTO },
{ ANDROID_CONTROL_AWB_MODE_INCANDESCENT, CAM_WB_MODE_INCANDESCENT },
{ ANDROID_CONTROL_AWB_MODE_FLUORESCENT, CAM_WB_MODE_FLUORESCENT },
{ ANDROID_CONTROL_AWB_MODE_WARM_FLUORESCENT,CAM_WB_MODE_WARM_FLUORESCENT},
{ ANDROID_CONTROL_AWB_MODE_DAYLIGHT, CAM_WB_MODE_DAYLIGHT },
{ ANDROID_CONTROL_AWB_MODE_CLOUDY_DAYLIGHT, CAM_WB_MODE_CLOUDY_DAYLIGHT },
{ ANDROID_CONTROL_AWB_MODE_TWILIGHT, CAM_WB_MODE_TWILIGHT },
{ ANDROID_CONTROL_AWB_MODE_SHADE, CAM_WB_MODE_SHADE }
};
const QCamera3HardwareInterface::QCameraMap<
camera_metadata_enum_android_control_scene_mode_t,
cam_scene_mode_type> QCamera3HardwareInterface::SCENE_MODES_MAP[] = {
{ ANDROID_CONTROL_SCENE_MODE_FACE_PRIORITY, CAM_SCENE_MODE_FACE_PRIORITY },
{ ANDROID_CONTROL_SCENE_MODE_ACTION, CAM_SCENE_MODE_ACTION },
{ ANDROID_CONTROL_SCENE_MODE_PORTRAIT, CAM_SCENE_MODE_PORTRAIT },
{ ANDROID_CONTROL_SCENE_MODE_LANDSCAPE, CAM_SCENE_MODE_LANDSCAPE },
{ ANDROID_CONTROL_SCENE_MODE_NIGHT, CAM_SCENE_MODE_NIGHT },
{ ANDROID_CONTROL_SCENE_MODE_NIGHT_PORTRAIT, CAM_SCENE_MODE_NIGHT_PORTRAIT },
{ ANDROID_CONTROL_SCENE_MODE_THEATRE, CAM_SCENE_MODE_THEATRE },
{ ANDROID_CONTROL_SCENE_MODE_BEACH, CAM_SCENE_MODE_BEACH },
{ ANDROID_CONTROL_SCENE_MODE_SNOW, CAM_SCENE_MODE_SNOW },
{ ANDROID_CONTROL_SCENE_MODE_SUNSET, CAM_SCENE_MODE_SUNSET },
{ ANDROID_CONTROL_SCENE_MODE_STEADYPHOTO, CAM_SCENE_MODE_ANTISHAKE },
{ ANDROID_CONTROL_SCENE_MODE_FIREWORKS , CAM_SCENE_MODE_FIREWORKS },
{ ANDROID_CONTROL_SCENE_MODE_SPORTS , CAM_SCENE_MODE_SPORTS },
{ ANDROID_CONTROL_SCENE_MODE_PARTY, CAM_SCENE_MODE_PARTY },
{ ANDROID_CONTROL_SCENE_MODE_CANDLELIGHT, CAM_SCENE_MODE_CANDLELIGHT },
{ ANDROID_CONTROL_SCENE_MODE_BARCODE, CAM_SCENE_MODE_BARCODE}
};
const QCamera3HardwareInterface::QCameraMap<
camera_metadata_enum_android_control_af_mode_t,
cam_focus_mode_type> QCamera3HardwareInterface::FOCUS_MODES_MAP[] = {
{ ANDROID_CONTROL_AF_MODE_OFF, CAM_FOCUS_MODE_OFF },
{ ANDROID_CONTROL_AF_MODE_OFF, CAM_FOCUS_MODE_FIXED },
{ ANDROID_CONTROL_AF_MODE_AUTO, CAM_FOCUS_MODE_AUTO },
{ ANDROID_CONTROL_AF_MODE_MACRO, CAM_FOCUS_MODE_MACRO },
{ ANDROID_CONTROL_AF_MODE_EDOF, CAM_FOCUS_MODE_EDOF },
{ ANDROID_CONTROL_AF_MODE_CONTINUOUS_PICTURE, CAM_FOCUS_MODE_CONTINOUS_PICTURE },
{ ANDROID_CONTROL_AF_MODE_CONTINUOUS_VIDEO, CAM_FOCUS_MODE_CONTINOUS_VIDEO }
};
const QCamera3HardwareInterface::QCameraMap<
camera_metadata_enum_android_color_correction_aberration_mode_t,
cam_aberration_mode_t> QCamera3HardwareInterface::COLOR_ABERRATION_MAP[] = {
{ ANDROID_COLOR_CORRECTION_ABERRATION_MODE_OFF,
CAM_COLOR_CORRECTION_ABERRATION_OFF },
{ ANDROID_COLOR_CORRECTION_ABERRATION_MODE_FAST,
CAM_COLOR_CORRECTION_ABERRATION_FAST },
{ ANDROID_COLOR_CORRECTION_ABERRATION_MODE_HIGH_QUALITY,
CAM_COLOR_CORRECTION_ABERRATION_HIGH_QUALITY },
};
const QCamera3HardwareInterface::QCameraMap<
camera_metadata_enum_android_control_ae_antibanding_mode_t,
cam_antibanding_mode_type> QCamera3HardwareInterface::ANTIBANDING_MODES_MAP[] = {
{ ANDROID_CONTROL_AE_ANTIBANDING_MODE_OFF, CAM_ANTIBANDING_MODE_OFF },
{ ANDROID_CONTROL_AE_ANTIBANDING_MODE_50HZ, CAM_ANTIBANDING_MODE_50HZ },
{ ANDROID_CONTROL_AE_ANTIBANDING_MODE_60HZ, CAM_ANTIBANDING_MODE_60HZ },
{ ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO, CAM_ANTIBANDING_MODE_AUTO }
};
const QCamera3HardwareInterface::QCameraMap<
camera_metadata_enum_android_control_ae_mode_t,
cam_flash_mode_t> QCamera3HardwareInterface::AE_FLASH_MODE_MAP[] = {
{ ANDROID_CONTROL_AE_MODE_OFF, CAM_FLASH_MODE_OFF },
{ ANDROID_CONTROL_AE_MODE_ON, CAM_FLASH_MODE_OFF },
{ ANDROID_CONTROL_AE_MODE_ON_AUTO_FLASH, CAM_FLASH_MODE_AUTO},
{ ANDROID_CONTROL_AE_MODE_ON_ALWAYS_FLASH, CAM_FLASH_MODE_ON },
{ ANDROID_CONTROL_AE_MODE_ON_AUTO_FLASH_REDEYE, CAM_FLASH_MODE_AUTO}
};
const QCamera3HardwareInterface::QCameraMap<
camera_metadata_enum_android_flash_mode_t,
cam_flash_mode_t> QCamera3HardwareInterface::FLASH_MODES_MAP[] = {
{ ANDROID_FLASH_MODE_OFF, CAM_FLASH_MODE_OFF },
{ ANDROID_FLASH_MODE_SINGLE, CAM_FLASH_MODE_SINGLE },
{ ANDROID_FLASH_MODE_TORCH, CAM_FLASH_MODE_TORCH }
};
const QCamera3HardwareInterface::QCameraMap<
camera_metadata_enum_android_statistics_face_detect_mode_t,
cam_face_detect_mode_t> QCamera3HardwareInterface::FACEDETECT_MODES_MAP[] = {
{ ANDROID_STATISTICS_FACE_DETECT_MODE_OFF, CAM_FACE_DETECT_MODE_OFF },
{ ANDROID_STATISTICS_FACE_DETECT_MODE_SIMPLE, CAM_FACE_DETECT_MODE_SIMPLE },
{ ANDROID_STATISTICS_FACE_DETECT_MODE_FULL, CAM_FACE_DETECT_MODE_FULL }
};
const QCamera3HardwareInterface::QCameraMap<
camera_metadata_enum_android_lens_info_focus_distance_calibration_t,
cam_focus_calibration_t> QCamera3HardwareInterface::FOCUS_CALIBRATION_MAP[] = {
{ ANDROID_LENS_INFO_FOCUS_DISTANCE_CALIBRATION_UNCALIBRATED,
CAM_FOCUS_UNCALIBRATED },
{ ANDROID_LENS_INFO_FOCUS_DISTANCE_CALIBRATION_APPROXIMATE,
CAM_FOCUS_APPROXIMATE },
{ ANDROID_LENS_INFO_FOCUS_DISTANCE_CALIBRATION_CALIBRATED,
CAM_FOCUS_CALIBRATED }
};
const QCamera3HardwareInterface::QCameraMap<
camera_metadata_enum_android_lens_state_t,
cam_af_lens_state_t> QCamera3HardwareInterface::LENS_STATE_MAP[] = {
{ ANDROID_LENS_STATE_STATIONARY, CAM_AF_LENS_STATE_STATIONARY},
{ ANDROID_LENS_STATE_MOVING, CAM_AF_LENS_STATE_MOVING}
};
const int32_t available_thumbnail_sizes[] = {0, 0,
176, 144,
240, 144,
256, 144,
240, 160,
256, 154,
240, 240,
320, 240};
const QCamera3HardwareInterface::QCameraMap<
camera_metadata_enum_android_sensor_test_pattern_mode_t,
cam_test_pattern_mode_t> QCamera3HardwareInterface::TEST_PATTERN_MAP[] = {
{ ANDROID_SENSOR_TEST_PATTERN_MODE_OFF, CAM_TEST_PATTERN_OFF },
{ ANDROID_SENSOR_TEST_PATTERN_MODE_SOLID_COLOR, CAM_TEST_PATTERN_SOLID_COLOR },
{ ANDROID_SENSOR_TEST_PATTERN_MODE_COLOR_BARS, CAM_TEST_PATTERN_COLOR_BARS },
{ ANDROID_SENSOR_TEST_PATTERN_MODE_COLOR_BARS_FADE_TO_GRAY, CAM_TEST_PATTERN_COLOR_BARS_FADE_TO_GRAY },
{ ANDROID_SENSOR_TEST_PATTERN_MODE_PN9, CAM_TEST_PATTERN_PN9 },
{ ANDROID_SENSOR_TEST_PATTERN_MODE_CUSTOM1, CAM_TEST_PATTERN_CUSTOM1},
};
/* Since there is no mapping for all the options some Android enum are not listed.
* Also, the order in this list is important because while mapping from HAL to Android it will
* traverse from lower to higher index which means that for HAL values that are map to different
* Android values, the traverse logic will select the first one found.
*/
const QCamera3HardwareInterface::QCameraMap<
camera_metadata_enum_android_sensor_reference_illuminant1_t,
cam_illuminat_t> QCamera3HardwareInterface::REFERENCE_ILLUMINANT_MAP[] = {
{ ANDROID_SENSOR_REFERENCE_ILLUMINANT1_FLUORESCENT, CAM_AWB_WARM_FLO},
{ ANDROID_SENSOR_REFERENCE_ILLUMINANT1_DAYLIGHT_FLUORESCENT, CAM_AWB_CUSTOM_DAYLIGHT },
{ ANDROID_SENSOR_REFERENCE_ILLUMINANT1_COOL_WHITE_FLUORESCENT, CAM_AWB_COLD_FLO },
{ ANDROID_SENSOR_REFERENCE_ILLUMINANT1_STANDARD_A, CAM_AWB_A },
{ ANDROID_SENSOR_REFERENCE_ILLUMINANT1_D55, CAM_AWB_NOON },
{ ANDROID_SENSOR_REFERENCE_ILLUMINANT1_D65, CAM_AWB_D65 },
{ ANDROID_SENSOR_REFERENCE_ILLUMINANT1_D75, CAM_AWB_D75 },
{ ANDROID_SENSOR_REFERENCE_ILLUMINANT1_D50, CAM_AWB_D50 },
{ ANDROID_SENSOR_REFERENCE_ILLUMINANT1_ISO_STUDIO_TUNGSTEN, CAM_AWB_CUSTOM_A},
{ ANDROID_SENSOR_REFERENCE_ILLUMINANT1_DAYLIGHT, CAM_AWB_D50 },
{ ANDROID_SENSOR_REFERENCE_ILLUMINANT1_TUNGSTEN, CAM_AWB_A },
{ ANDROID_SENSOR_REFERENCE_ILLUMINANT1_FINE_WEATHER, CAM_AWB_D50 },
{ ANDROID_SENSOR_REFERENCE_ILLUMINANT1_CLOUDY_WEATHER, CAM_AWB_D65 },
{ ANDROID_SENSOR_REFERENCE_ILLUMINANT1_SHADE, CAM_AWB_D75 },
{ ANDROID_SENSOR_REFERENCE_ILLUMINANT1_DAY_WHITE_FLUORESCENT, CAM_AWB_CUSTOM_DAYLIGHT },
{ ANDROID_SENSOR_REFERENCE_ILLUMINANT1_WHITE_FLUORESCENT, CAM_AWB_COLD_FLO},
};
const QCamera3HardwareInterface::QCameraMap<
int32_t, cam_hfr_mode_t> QCamera3HardwareInterface::HFR_MODE_MAP[] = {
{ 60, CAM_HFR_MODE_60FPS},
{ 90, CAM_HFR_MODE_90FPS},
{ 120, CAM_HFR_MODE_120FPS},
{ 150, CAM_HFR_MODE_150FPS},
{ 180, CAM_HFR_MODE_180FPS},
{ 210, CAM_HFR_MODE_210FPS},
{ 240, CAM_HFR_MODE_240FPS},
{ 480, CAM_HFR_MODE_480FPS},
};
camera3_device_ops_t QCamera3HardwareInterface::mCameraOps = {
.initialize = QCamera3HardwareInterface::initialize,
.configure_streams = QCamera3HardwareInterface::configure_streams,
.register_stream_buffers = NULL,
.construct_default_request_settings = QCamera3HardwareInterface::construct_default_request_settings,
.process_capture_request = QCamera3HardwareInterface::process_capture_request,
.get_metadata_vendor_tag_ops = NULL,
.dump = QCamera3HardwareInterface::dump,
.flush = QCamera3HardwareInterface::flush,
.reserved = {0},
};
// initialise to some default value
uint32_t QCamera3HardwareInterface::sessionId[] = {0xDEADBEEF, 0xDEADBEEF, 0xDEADBEEF};
/*===========================================================================
* FUNCTION : QCamera3HardwareInterface
*
* DESCRIPTION: constructor of QCamera3HardwareInterface
*
* PARAMETERS :
* @cameraId : camera ID
*
* RETURN : none
*==========================================================================*/
QCamera3HardwareInterface::QCamera3HardwareInterface(uint32_t cameraId,
const camera_module_callbacks_t *callbacks)
: mCameraId(cameraId),
mCameraHandle(NULL),
mCameraInitialized(false),
mCallbackOps(NULL),
mMetadataChannel(NULL),
mPictureChannel(NULL),
mRawChannel(NULL),
mSupportChannel(NULL),
mAnalysisChannel(NULL),
mRawDumpChannel(NULL),
mDummyBatchChannel(NULL),
m_perfLock(),
mCommon(),
mChannelHandle(0),
mFirstConfiguration(true),
mFlush(false),
mFlushPerf(false),
mParamHeap(NULL),
mParameters(NULL),
mPrevParameters(NULL),
m_bIsVideo(false),
m_bIs4KVideo(false),
m_bEisSupportedSize(false),
m_bEisEnable(false),
m_MobicatMask(0),
mMinProcessedFrameDuration(0),
mMinJpegFrameDuration(0),
mMinRawFrameDuration(0),
mMetaFrameCount(0U),
mUpdateDebugLevel(false),
mCallbacks(callbacks),
mCaptureIntent(0),
mCacMode(0),
mHybridAeEnable(0),
/* DevCamDebug metadata internal m control*/
mDevCamDebugMetaEnable(0),
/* DevCamDebug metadata end */
mBatchSize(0),
mToBeQueuedVidBufs(0),
mHFRVideoFps(DEFAULT_VIDEO_FPS),
mOpMode(CAMERA3_STREAM_CONFIGURATION_NORMAL_MODE),
mFirstFrameNumberInBatch(0),
mNeedSensorRestart(false),
mMinInFlightRequests(MIN_INFLIGHT_REQUESTS),
mMaxInFlightRequests(MAX_INFLIGHT_REQUESTS),
mLdafCalibExist(false),
mPowerHintEnabled(false),
mLastCustIntentFrmNum(-1),
mState(CLOSED),
mIsDeviceLinked(false),
mIsMainCamera(true),
mLinkedCameraId(0),
m_pRelCamSyncHeap(NULL),
m_pRelCamSyncBuf(NULL)
{
getLogLevel();
m_perfLock.lock_init();
mCommon.init(gCamCapability[cameraId]);
mCameraDevice.common.tag = HARDWARE_DEVICE_TAG;
mCameraDevice.common.version = CAMERA_DEVICE_API_VERSION_3_4;
mCameraDevice.common.close = close_camera_device;
mCameraDevice.ops = &mCameraOps;
mCameraDevice.priv = this;
gCamCapability[cameraId]->version = CAM_HAL_V3;
// TODO: hardcode for now until mctl add support for min_num_pp_bufs
//TBD - To see if this hardcoding is needed. Check by printing if this is filled by mctl to 3
gCamCapability[cameraId]->min_num_pp_bufs = 3;
pthread_cond_init(&mBuffersCond, NULL);
pthread_cond_init(&mRequestCond, NULL);
mPendingLiveRequest = 0;
mCurrentRequestId = -1;
pthread_mutex_init(&mMutex, NULL);
for (size_t i = 0; i < CAMERA3_TEMPLATE_COUNT; i++)
mDefaultMetadata[i] = NULL;
// Getting system props of different kinds
char prop[PROPERTY_VALUE_MAX];
memset(prop, 0, sizeof(prop));
property_get("persist.camera.raw.dump", prop, "0");
mEnableRawDump = atoi(prop);
if (mEnableRawDump)
LOGD("Raw dump from Camera HAL enabled");
memset(&mInputStreamInfo, 0, sizeof(mInputStreamInfo));
memset(mLdafCalib, 0, sizeof(mLdafCalib));
memset(prop, 0, sizeof(prop));
property_get("persist.camera.tnr.preview", prop, "0");
m_bTnrPreview = (uint8_t)atoi(prop);
memset(prop, 0, sizeof(prop));
property_get("persist.camera.tnr.video", prop, "0");
m_bTnrVideo = (uint8_t)atoi(prop);
memset(prop, 0, sizeof(prop));
property_get("persist.camera.avtimer.debug", prop, "0");
m_debug_avtimer = (uint8_t)atoi(prop);
//Load and read GPU library.
lib_surface_utils = NULL;
LINK_get_surface_pixel_alignment = NULL;
mSurfaceStridePadding = CAM_PAD_TO_32;
lib_surface_utils = dlopen("libadreno_utils.so", RTLD_NOW);
if (lib_surface_utils) {
*(void **)&LINK_get_surface_pixel_alignment =
dlsym(lib_surface_utils, "get_gpu_pixel_alignment");
if (LINK_get_surface_pixel_alignment) {
mSurfaceStridePadding = LINK_get_surface_pixel_alignment();
}
dlclose(lib_surface_utils);
}
m60HzZone = is60HzZone();
}
/*===========================================================================
* FUNCTION : ~QCamera3HardwareInterface
*
* DESCRIPTION: destructor of QCamera3HardwareInterface
*
* PARAMETERS : none
*
* RETURN : none
*==========================================================================*/
QCamera3HardwareInterface::~QCamera3HardwareInterface()
{
LOGD("E");
/* Turn off current power hint before acquiring perfLock in case they
* conflict with each other */
disablePowerHint();
m_perfLock.lock_acq();
/* We need to stop all streams before deleting any stream */
if (mRawDumpChannel) {
mRawDumpChannel->stop();
}
// NOTE: 'camera3_stream_t *' objects are already freed at
// this stage by the framework
for (List<stream_info_t *>::iterator it = mStreamInfo.begin();
it != mStreamInfo.end(); it++) {
QCamera3ProcessingChannel *channel = (*it)->channel;
if (channel) {
channel->stop();
}
}
if (mSupportChannel)
mSupportChannel->stop();
if (mAnalysisChannel) {
mAnalysisChannel->stop();
}
if (mMetadataChannel) {
mMetadataChannel->stop();
}
if (mChannelHandle) {
mCameraHandle->ops->stop_channel(mCameraHandle->camera_handle,
mChannelHandle);
LOGD("stopping channel %d", mChannelHandle);
}
for (List<stream_info_t *>::iterator it = mStreamInfo.begin();
it != mStreamInfo.end(); it++) {
QCamera3ProcessingChannel *channel = (*it)->channel;
if (channel)
delete channel;
free (*it);
}
if (mSupportChannel) {
delete mSupportChannel;
mSupportChannel = NULL;
}
if (mAnalysisChannel) {
delete mAnalysisChannel;
mAnalysisChannel = NULL;
}
if (mRawDumpChannel) {
delete mRawDumpChannel;
mRawDumpChannel = NULL;
}
if (mDummyBatchChannel) {
delete mDummyBatchChannel;
mDummyBatchChannel = NULL;
}
mPictureChannel = NULL;
if (mMetadataChannel) {
delete mMetadataChannel;
mMetadataChannel = NULL;
}
/* Clean up all channels */
if (mCameraInitialized) {
if(!mFirstConfiguration){
//send the last unconfigure
cam_stream_size_info_t stream_config_info;
memset(&stream_config_info, 0, sizeof(cam_stream_size_info_t));
stream_config_info.buffer_info.min_buffers = MIN_INFLIGHT_REQUESTS;
stream_config_info.buffer_info.max_buffers =
m_bIs4KVideo ? 0 : MAX_INFLIGHT_REQUESTS;
ADD_SET_PARAM_ENTRY_TO_BATCH(mParameters, CAM_INTF_META_STREAM_INFO,
stream_config_info);
int rc = mCameraHandle->ops->set_parms(mCameraHandle->camera_handle, mParameters);
if (rc < 0) {
LOGE("set_parms failed for unconfigure");
}
}
deinitParameters();
}
if (mChannelHandle) {
mCameraHandle->ops->delete_channel(mCameraHandle->camera_handle,
mChannelHandle);
LOGH("deleting channel %d", mChannelHandle);
mChannelHandle = 0;
}
if (mState != CLOSED)
closeCamera();
for (auto &req : mPendingBuffersMap.mPendingBuffersInRequest) {
req.mPendingBufferList.clear();
}
mPendingBuffersMap.mPendingBuffersInRequest.clear();
mPendingReprocessResultList.clear();
for (pendingRequestIterator i = mPendingRequestsList.begin();
i != mPendingRequestsList.end();) {
i = erasePendingRequest(i);
}
for (size_t i = 0; i < CAMERA3_TEMPLATE_COUNT; i++)
if (mDefaultMetadata[i])
free_camera_metadata(mDefaultMetadata[i]);
m_perfLock.lock_rel();
m_perfLock.lock_deinit();
pthread_cond_destroy(&mRequestCond);
pthread_cond_destroy(&mBuffersCond);
pthread_mutex_destroy(&mMutex);
LOGD("X");
}
/*===========================================================================
* FUNCTION : erasePendingRequest
*
* DESCRIPTION: function to erase a desired pending request after freeing any
* allocated memory
*
* PARAMETERS :
* @i : iterator pointing to pending request to be erased
*
* RETURN : iterator pointing to the next request
*==========================================================================*/
QCamera3HardwareInterface::pendingRequestIterator
QCamera3HardwareInterface::erasePendingRequest (pendingRequestIterator i)
{
if (i->input_buffer != NULL) {
free(i->input_buffer);
i->input_buffer = NULL;
}
if (i->settings != NULL)
free_camera_metadata((camera_metadata_t*)i->settings);
return mPendingRequestsList.erase(i);
}
/*===========================================================================
* FUNCTION : camEvtHandle
*
* DESCRIPTION: Function registered to mm-camera-interface to handle events
*
* PARAMETERS :
* @camera_handle : interface layer camera handle
* @evt : ptr to event
* @user_data : user data ptr
*
* RETURN : none
*==========================================================================*/
void QCamera3HardwareInterface::camEvtHandle(uint32_t /*camera_handle*/,
mm_camera_event_t *evt,
void *user_data)
{
QCamera3HardwareInterface *obj = (QCamera3HardwareInterface *)user_data;
if (obj && evt) {
switch(evt->server_event_type) {
case CAM_EVENT_TYPE_DAEMON_DIED:
pthread_mutex_lock(&obj->mMutex);
obj->mState = ERROR;
pthread_mutex_unlock(&obj->mMutex);
LOGE("Fatal, camera daemon died");
break;
case CAM_EVENT_TYPE_DAEMON_PULL_REQ:
LOGD("HAL got request pull from Daemon");
pthread_mutex_lock(&obj->mMutex);
obj->mWokenUpByDaemon = true;
obj->unblockRequestIfNecessary();
pthread_mutex_unlock(&obj->mMutex);
break;
default:
LOGW("Warning: Unhandled event %d",
evt->server_event_type);
break;
}
} else {
LOGE("NULL user_data/evt");
}
}
/*===========================================================================
* FUNCTION : openCamera
*
* DESCRIPTION: open camera
*
* PARAMETERS :
* @hw_device : double ptr for camera device struct
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int QCamera3HardwareInterface::openCamera(struct hw_device_t **hw_device)
{
int rc = 0;
if (mState != CLOSED) {
*hw_device = NULL;
return PERMISSION_DENIED;
}
m_perfLock.lock_acq();
LOGI("[KPI Perf]: E PROFILE_OPEN_CAMERA camera id %d",
mCameraId);
rc = openCamera();
if (rc == 0) {
*hw_device = &mCameraDevice.common;
} else
*hw_device = NULL;
m_perfLock.lock_rel();
LOGI("[KPI Perf]: X PROFILE_OPEN_CAMERA camera id %d, rc: %d",
mCameraId, rc);
if (rc == NO_ERROR) {
mState = OPENED;
}
return rc;
}
/*===========================================================================
* FUNCTION : openCamera
*
* DESCRIPTION: open camera
*
* PARAMETERS : none
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int QCamera3HardwareInterface::openCamera()
{
int rc = 0;
char value[PROPERTY_VALUE_MAX];
KPI_ATRACE_CALL();
if (mCameraHandle) {
LOGE("Failure: Camera already opened");
return ALREADY_EXISTS;
}
rc = QCameraFlash::getInstance().reserveFlashForCamera(mCameraId);
if (rc < 0) {
LOGE("Failed to reserve flash for camera id: %d",
mCameraId);
return UNKNOWN_ERROR;
}
rc = camera_open((uint8_t)mCameraId, &mCameraHandle);
if (rc) {
LOGE("camera_open failed. rc = %d, mCameraHandle = %p", rc, mCameraHandle);
return rc;
}
if (!mCameraHandle) {
LOGE("camera_open failed. mCameraHandle = %p", mCameraHandle);
return -ENODEV;
}
rc = mCameraHandle->ops->register_event_notify(mCameraHandle->camera_handle,
camEvtHandle, (void *)this);
if (rc < 0) {
LOGE("Error, failed to register event callback");
/* Not closing camera here since it is already handled in destructor */
return FAILED_TRANSACTION;
}
mExifParams.debug_params =
(mm_jpeg_debug_exif_params_t *) malloc (sizeof(mm_jpeg_debug_exif_params_t));
if (mExifParams.debug_params) {
memset(mExifParams.debug_params, 0, sizeof(mm_jpeg_debug_exif_params_t));
} else {
LOGE("Out of Memory. Allocation failed for 3A debug exif params");
return NO_MEMORY;
}
mFirstConfiguration = true;
//Notify display HAL that a camera session is active.
//But avoid calling the same during bootup because camera service might open/close
//cameras at boot time during its initialization and display service will also internally
//wait for camera service to initialize first while calling this display API, resulting in a
//deadlock situation. Since boot time camera open/close calls are made only to fetch
//capabilities, no need of this display bw optimization.
//Use "service.bootanim.exit" property to know boot status.
property_get("service.bootanim.exit", value, "0");
if (atoi(value) == 1) {
pthread_mutex_lock(&gCamLock);
if (gNumCameraSessions++ == 0) {
setCameraLaunchStatus(true);
}
pthread_mutex_unlock(&gCamLock);
}
//fill the session id needed while linking dual cam
pthread_mutex_lock(&gCamLock);
rc = mCameraHandle->ops->get_session_id(mCameraHandle->camera_handle,
&sessionId[mCameraId]);
pthread_mutex_unlock(&gCamLock);
if (rc < 0) {
LOGE("Error, failed to get sessiion id");
return UNKNOWN_ERROR;
} else {
//Allocate related cam sync buffer
//this is needed for the payload that goes along with bundling cmd for related
//camera use cases
m_pRelCamSyncHeap = new QCamera3HeapMemory(1);
rc = m_pRelCamSyncHeap->allocate(sizeof(cam_sync_related_sensors_event_info_t));
if(rc != OK) {
rc = NO_MEMORY;
LOGE("Dualcam: Failed to allocate Related cam sync Heap memory");
return NO_MEMORY;
}
//Map memory for related cam sync buffer
rc = mCameraHandle->ops->map_buf(mCameraHandle->camera_handle,
CAM_MAPPING_BUF_TYPE_SYNC_RELATED_SENSORS_BUF,
m_pRelCamSyncHeap->getFd(0),
sizeof(cam_sync_related_sensors_event_info_t),
m_pRelCamSyncHeap->getPtr(0));
if(rc < 0) {
LOGE("Dualcam: failed to map Related cam sync buffer");
rc = FAILED_TRANSACTION;
return NO_MEMORY;
}
m_pRelCamSyncBuf =
(cam_sync_related_sensors_event_info_t*) DATA_PTR(m_pRelCamSyncHeap,0);
}
LOGH("mCameraId=%d",mCameraId);
return NO_ERROR;
}
/*===========================================================================
* FUNCTION : closeCamera
*
* DESCRIPTION: close camera
*
* PARAMETERS : none
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int QCamera3HardwareInterface::closeCamera()
{
KPI_ATRACE_CALL();
int rc = NO_ERROR;
char value[PROPERTY_VALUE_MAX];
LOGI("[KPI Perf]: E PROFILE_CLOSE_CAMERA camera id %d",
mCameraId);
rc = mCameraHandle->ops->close_camera(mCameraHandle->camera_handle);
mCameraHandle = NULL;
//reset session id to some invalid id
pthread_mutex_lock(&gCamLock);
sessionId[mCameraId] = 0xDEADBEEF;
pthread_mutex_unlock(&gCamLock);
//Notify display HAL that there is no active camera session
//but avoid calling the same during bootup. Refer to openCamera
//for more details.
property_get("service.bootanim.exit", value, "0");
if (atoi(value) == 1) {
pthread_mutex_lock(&gCamLock);
if (--gNumCameraSessions == 0) {
setCameraLaunchStatus(false);
}
pthread_mutex_unlock(&gCamLock);
}
if (NULL != m_pRelCamSyncHeap) {
m_pRelCamSyncHeap->deallocate();
delete m_pRelCamSyncHeap;
m_pRelCamSyncHeap = NULL;
m_pRelCamSyncBuf = NULL;
}
if (mExifParams.debug_params) {
free(mExifParams.debug_params);
mExifParams.debug_params = NULL;
}
if (QCameraFlash::getInstance().releaseFlashFromCamera(mCameraId) != 0) {
LOGW("Failed to release flash for camera id: %d",
mCameraId);
}
mState = CLOSED;
LOGI("[KPI Perf]: X PROFILE_CLOSE_CAMERA camera id %d, rc: %d",
mCameraId, rc);
return rc;
}
/*===========================================================================
* FUNCTION : initialize
*
* DESCRIPTION: Initialize frameworks callback functions
*
* PARAMETERS :
* @callback_ops : callback function to frameworks
*
* RETURN :
*
*==========================================================================*/
int QCamera3HardwareInterface::initialize(
const struct camera3_callback_ops *callback_ops)
{
ATRACE_CALL();
int rc;
LOGI("E :mCameraId = %d mState = %d", mCameraId, mState);
pthread_mutex_lock(&mMutex);
// Validate current state
switch (mState) {
case OPENED:
/* valid state */
break;
default:
LOGE("Invalid state %d", mState);
rc = -ENODEV;
goto err1;
}
rc = initParameters();
if (rc < 0) {
LOGE("initParamters failed %d", rc);
goto err1;
}
mCallbackOps = callback_ops;
mChannelHandle = mCameraHandle->ops->add_channel(
mCameraHandle->camera_handle, NULL, NULL, this);
if (mChannelHandle == 0) {
LOGE("add_channel failed");
rc = -ENOMEM;
pthread_mutex_unlock(&mMutex);
return rc;
}
pthread_mutex_unlock(&mMutex);
mCameraInitialized = true;
mState = INITIALIZED;
LOGI("X");
return 0;
err1:
pthread_mutex_unlock(&mMutex);
return rc;
}
/*===========================================================================
* FUNCTION : validateStreamDimensions
*
* DESCRIPTION: Check if the configuration requested are those advertised
*
* PARAMETERS :
* @stream_list : streams to be configured
*
* RETURN :
*
*==========================================================================*/
int QCamera3HardwareInterface::validateStreamDimensions(
camera3_stream_configuration_t *streamList)
{
int rc = NO_ERROR;
size_t count = 0;
camera3_stream_t *inputStream = NULL;
/*
* Loop through all streams to find input stream if it exists*
*/
for (size_t i = 0; i< streamList->num_streams; i++) {
if (streamList->streams[i]->stream_type == CAMERA3_STREAM_INPUT) {
if (inputStream != NULL) {
LOGE("Error, Multiple input streams requested");
return -EINVAL;
}
inputStream = streamList->streams[i];
}
}
/*
* Loop through all streams requested in configuration
* Check if unsupported sizes have been requested on any of them
*/
for (size_t j = 0; j < streamList->num_streams; j++) {
bool sizeFound = false;
camera3_stream_t *newStream = streamList->streams[j];
uint32_t rotatedHeight = newStream->height;
uint32_t rotatedWidth = newStream->width;
if ((newStream->rotation == CAMERA3_STREAM_ROTATION_90) ||
(newStream->rotation == CAMERA3_STREAM_ROTATION_270)) {
rotatedHeight = newStream->width;
rotatedWidth = newStream->height;
}
/*
* Sizes are different for each type of stream format check against
* appropriate table.
*/
switch (newStream->format) {
case ANDROID_SCALER_AVAILABLE_FORMATS_RAW16:
case ANDROID_SCALER_AVAILABLE_FORMATS_RAW_OPAQUE:
case HAL_PIXEL_FORMAT_RAW10:
count = MIN(gCamCapability[mCameraId]->supported_raw_dim_cnt, MAX_SIZES_CNT);
for (size_t i = 0; i < count; i++) {
if ((gCamCapability[mCameraId]->raw_dim[i].width == (int32_t)rotatedWidth) &&
(gCamCapability[mCameraId]->raw_dim[i].height == (int32_t)rotatedHeight)) {
sizeFound = true;
break;
}
}
break;
case HAL_PIXEL_FORMAT_BLOB:
count = MIN(gCamCapability[mCameraId]->picture_sizes_tbl_cnt, MAX_SIZES_CNT);
/* Verify set size against generated sizes table */
for (size_t i = 0; i < count; i++) {
if (((int32_t)rotatedWidth ==
gCamCapability[mCameraId]->picture_sizes_tbl[i].width) &&
((int32_t)rotatedHeight ==
gCamCapability[mCameraId]->picture_sizes_tbl[i].height)) {
sizeFound = true;
break;
}
}
break;
case HAL_PIXEL_FORMAT_YCbCr_420_888:
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
default:
if (newStream->stream_type == CAMERA3_STREAM_BIDIRECTIONAL
|| newStream->stream_type == CAMERA3_STREAM_INPUT
|| IS_USAGE_ZSL(newStream->usage)) {
if (((int32_t)rotatedWidth ==
gCamCapability[mCameraId]->active_array_size.width) &&
((int32_t)rotatedHeight ==
gCamCapability[mCameraId]->active_array_size.height)) {
sizeFound = true;
break;
}
/* We could potentially break here to enforce ZSL stream
* set from frameworks always is full active array size
* but it is not clear from the spc if framework will always
* follow that, also we have logic to override to full array
* size, so keeping the logic lenient at the moment
*/
}
count = MIN(gCamCapability[mCameraId]->picture_sizes_tbl_cnt,
MAX_SIZES_CNT);
for (size_t i = 0; i < count; i++) {
if (((int32_t)rotatedWidth ==
gCamCapability[mCameraId]->picture_sizes_tbl[i].width) &&
((int32_t)rotatedHeight ==
gCamCapability[mCameraId]->picture_sizes_tbl[i].height)) {
sizeFound = true;
break;
}
}
break;
} /* End of switch(newStream->format) */
/* We error out even if a single stream has unsupported size set */
if (!sizeFound) {
LOGE("Error: Unsupported size: %d x %d type: %d array size: %d x %d",
rotatedWidth, rotatedHeight, newStream->format,
gCamCapability[mCameraId]->active_array_size.width,
gCamCapability[mCameraId]->active_array_size.height);
rc = -EINVAL;
break;
}
} /* End of for each stream */
return rc;
}
/*==============================================================================
* FUNCTION : isSupportChannelNeeded
*
* DESCRIPTION: Simple heuristic func to determine if support channels is needed
*
* PARAMETERS :
* @stream_list : streams to be configured
* @stream_config_info : the config info for streams to be configured
*
* RETURN : Boolen true/false decision
*
*==========================================================================*/
bool QCamera3HardwareInterface::isSupportChannelNeeded(
camera3_stream_configuration_t *streamList,
cam_stream_size_info_t stream_config_info)
{
uint32_t i;
bool pprocRequested = false;
/* Check for conditions where PProc pipeline does not have any streams*/
for (i = 0; i < stream_config_info.num_streams; i++) {
if (stream_config_info.type[i] != CAM_STREAM_TYPE_ANALYSIS &&
stream_config_info.postprocess_mask[i] != CAM_QCOM_FEATURE_NONE) {
pprocRequested = true;
break;
}
}
if (pprocRequested == false )
return true;
/* Dummy stream needed if only raw or jpeg streams present */
for (i = 0; i < streamList->num_streams; i++) {
switch(streamList->streams[i]->format) {
case HAL_PIXEL_FORMAT_RAW_OPAQUE:
case HAL_PIXEL_FORMAT_RAW10:
case HAL_PIXEL_FORMAT_RAW16:
case HAL_PIXEL_FORMAT_BLOB:
break;
default:
return false;
}
}
return true;
}
/*==============================================================================
* FUNCTION : getSensorOutputSize
*
* DESCRIPTION: Get sensor output size based on current stream configuratoin
*
* PARAMETERS :
* @sensor_dim : sensor output dimension (output)
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*
*==========================================================================*/
int32_t QCamera3HardwareInterface::getSensorOutputSize(cam_dimension_t &sensor_dim)
{
int32_t rc = NO_ERROR;
cam_dimension_t max_dim = {0, 0};
for (uint32_t i = 0; i < mStreamConfigInfo.num_streams; i++) {
if (mStreamConfigInfo.stream_sizes[i].width > max_dim.width)
max_dim.width = mStreamConfigInfo.stream_sizes[i].width;
if (mStreamConfigInfo.stream_sizes[i].height > max_dim.height)
max_dim.height = mStreamConfigInfo.stream_sizes[i].height;
}
clear_metadata_buffer(mParameters);
rc = ADD_SET_PARAM_ENTRY_TO_BATCH(mParameters, CAM_INTF_PARM_MAX_DIMENSION,
max_dim);
if (rc != NO_ERROR) {
LOGE("Failed to update table for CAM_INTF_PARM_MAX_DIMENSION");
return rc;
}
rc = mCameraHandle->ops->set_parms(mCameraHandle->camera_handle, mParameters);
if (rc != NO_ERROR) {
LOGE("Failed to set CAM_INTF_PARM_MAX_DIMENSION");
return rc;
}
clear_metadata_buffer(mParameters);
ADD_GET_PARAM_ENTRY_TO_BATCH(mParameters, CAM_INTF_PARM_RAW_DIMENSION);
rc = mCameraHandle->ops->get_parms(mCameraHandle->camera_handle,
mParameters);
if (rc != NO_ERROR) {
LOGE("Failed to get CAM_INTF_PARM_RAW_DIMENSION");
return rc;
}
READ_PARAM_ENTRY(mParameters, CAM_INTF_PARM_RAW_DIMENSION, sensor_dim);
LOGH("sensor output dimension = %d x %d", sensor_dim.width, sensor_dim.height);
return rc;
}
/*==============================================================================
* FUNCTION : enablePowerHint
*
* DESCRIPTION: enable single powerhint for preview and different video modes.
*
* PARAMETERS :
*
* RETURN : NULL
*
*==========================================================================*/
void QCamera3HardwareInterface::enablePowerHint()
{
if (!mPowerHintEnabled) {
m_perfLock.powerHint(POWER_HINT_VIDEO_ENCODE, true);
mPowerHintEnabled = true;
}
}
/*==============================================================================
* FUNCTION : disablePowerHint
*
* DESCRIPTION: disable current powerhint.
*
* PARAMETERS :
*
* RETURN : NULL
*
*==========================================================================*/
void QCamera3HardwareInterface::disablePowerHint()
{
if (mPowerHintEnabled) {
m_perfLock.powerHint(POWER_HINT_VIDEO_ENCODE, false);
mPowerHintEnabled = false;
}
}
/*==============================================================================
* FUNCTION : addToPPFeatureMask
*
* DESCRIPTION: add additional features to pp feature mask based on
* stream type and usecase
*
* PARAMETERS :
* @stream_format : stream type for feature mask
* @stream_idx : stream idx within postprocess_mask list to change
*
* RETURN : NULL
*
*==========================================================================*/
void QCamera3HardwareInterface::addToPPFeatureMask(int stream_format,
uint32_t stream_idx)
{
char feature_mask_value[PROPERTY_VALUE_MAX];
cam_feature_mask_t feature_mask;
int args_converted;
int property_len;
/* Get feature mask from property */
property_len = property_get("persist.camera.hal3.feature",
feature_mask_value, "0");
if ((property_len > 2) && (feature_mask_value[0] == '0') &&
(feature_mask_value[1] == 'x')) {
args_converted = sscanf(feature_mask_value, "0x%llx", &feature_mask);
} else {
args_converted = sscanf(feature_mask_value, "%lld", &feature_mask);
}
if (1 != args_converted) {
feature_mask = 0;
LOGE("Wrong feature mask %s", feature_mask_value);
return;
}
switch (stream_format) {
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: {
/* Add LLVD to pp feature mask only if video hint is enabled */
if ((m_bIsVideo) && (feature_mask & CAM_QTI_FEATURE_SW_TNR)) {
mStreamConfigInfo.postprocess_mask[stream_idx]
|= CAM_QTI_FEATURE_SW_TNR;
LOGH("Added SW TNR to pp feature mask");
} else if ((m_bIsVideo) && (feature_mask & CAM_QCOM_FEATURE_LLVD)) {
mStreamConfigInfo.postprocess_mask[stream_idx]
|= CAM_QCOM_FEATURE_LLVD;
LOGH("Added LLVD SeeMore to pp feature mask");
}
break;
}
default:
break;
}
LOGD("PP feature mask %llx",
mStreamConfigInfo.postprocess_mask[stream_idx]);
}
/*==============================================================================
* FUNCTION : updateFpsInPreviewBuffer
*
* DESCRIPTION: update FPS information in preview buffer.
*
* PARAMETERS :
* @metadata : pointer to metadata buffer
* @frame_number: frame_number to look for in pending buffer list
*
* RETURN : None
*
*==========================================================================*/
void QCamera3HardwareInterface::updateFpsInPreviewBuffer(metadata_buffer_t *metadata,
uint32_t frame_number)
{
// Mark all pending buffers for this particular request
// with corresponding framerate information
for (List<PendingBuffersInRequest>::iterator req =
mPendingBuffersMap.mPendingBuffersInRequest.begin();
req != mPendingBuffersMap.mPendingBuffersInRequest.end(); req++) {
for(List<PendingBufferInfo>::iterator j =
req->mPendingBufferList.begin();
j != req->mPendingBufferList.end(); j++) {
QCamera3Channel *channel = (QCamera3Channel *)j->stream->priv;
if ((req->frame_number == frame_number) &&
(channel->getStreamTypeMask() &
(1U << CAM_STREAM_TYPE_PREVIEW))) {
IF_META_AVAILABLE(cam_fps_range_t, float_range,
CAM_INTF_PARM_FPS_RANGE, metadata) {
int32_t cameraFps = float_range->max_fps;
struct private_handle_t *priv_handle =
(struct private_handle_t *)(*(j->buffer));
setMetaData(priv_handle, UPDATE_REFRESH_RATE, &cameraFps);
}
}
}
}
}
/*==============================================================================
* FUNCTION : updateTimeStampInPendingBuffers
*
* DESCRIPTION: update timestamp in display metadata for all pending buffers
* of a frame number
*
* PARAMETERS :
* @frame_number: frame_number. Timestamp will be set on pending buffers of this frame number
* @timestamp : timestamp to be set
*
* RETURN : None
*
*==========================================================================*/
void QCamera3HardwareInterface::updateTimeStampInPendingBuffers(
uint32_t frameNumber, nsecs_t timestamp)
{
for (auto req = mPendingBuffersMap.mPendingBuffersInRequest.begin();
req != mPendingBuffersMap.mPendingBuffersInRequest.end(); req++) {
if (req->frame_number != frameNumber)
continue;
for (auto k = req->mPendingBufferList.begin();
k != req->mPendingBufferList.end(); k++ ) {
struct private_handle_t *priv_handle =
(struct private_handle_t *) (*(k->buffer));
setMetaData(priv_handle, SET_VT_TIMESTAMP, &timestamp);
}
}
return;
}
/*===========================================================================
* FUNCTION : configureStreams
*
* DESCRIPTION: Reset HAL camera device processing pipeline and set up new input
* and output streams.
*
* PARAMETERS :
* @stream_list : streams to be configured
*
* RETURN :
*
*==========================================================================*/
int QCamera3HardwareInterface::configureStreams(
camera3_stream_configuration_t *streamList)
{
ATRACE_CALL();
int rc = 0;
// Acquire perfLock before configure streams
m_perfLock.lock_acq();
rc = configureStreamsPerfLocked(streamList);
m_perfLock.lock_rel();
return rc;
}
/*===========================================================================
* FUNCTION : configureStreamsPerfLocked
*
* DESCRIPTION: configureStreams while perfLock is held.
*
* PARAMETERS :
* @stream_list : streams to be configured
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int QCamera3HardwareInterface::configureStreamsPerfLocked(
camera3_stream_configuration_t *streamList)
{
ATRACE_CALL();
int rc = 0;
// Sanity check stream_list
if (streamList == NULL) {
LOGE("NULL stream configuration");
return BAD_VALUE;
}
if (streamList->streams == NULL) {
LOGE("NULL stream list");
return BAD_VALUE;
}
if (streamList->num_streams < 1) {
LOGE("Bad number of streams requested: %d",
streamList->num_streams);
return BAD_VALUE;
}
if (streamList->num_streams >= MAX_NUM_STREAMS) {
LOGE("Maximum number of streams %d exceeded: %d",
MAX_NUM_STREAMS, streamList->num_streams);
return BAD_VALUE;
}
mOpMode = streamList->operation_mode;
LOGD("mOpMode: %d", mOpMode);
/* first invalidate all the steams in the mStreamList
* if they appear again, they will be validated */
for (List<stream_info_t*>::iterator it = mStreamInfo.begin();
it != mStreamInfo.end(); it++) {
QCamera3ProcessingChannel *channel = (QCamera3ProcessingChannel*)(*it)->stream->priv;
if (channel) {
channel->stop();
}
(*it)->status = INVALID;
}
if (mRawDumpChannel) {
mRawDumpChannel->stop();
delete mRawDumpChannel;
mRawDumpChannel = NULL;
}
if (mSupportChannel)
mSupportChannel->stop();
if (mAnalysisChannel) {
mAnalysisChannel->stop();
}
if (mMetadataChannel) {
/* If content of mStreamInfo is not 0, there is metadata stream */
mMetadataChannel->stop();
}
if (mChannelHandle) {
mCameraHandle->ops->stop_channel(mCameraHandle->camera_handle,
mChannelHandle);
LOGD("stopping channel %d", mChannelHandle);
}
pthread_mutex_lock(&mMutex);
// Check state
switch (mState) {
case INITIALIZED:
case CONFIGURED:
case STARTED:
/* valid state */
break;
default:
LOGE("Invalid state %d", mState);
pthread_mutex_unlock(&mMutex);
return -ENODEV;
}
/* Check whether we have video stream */
m_bIs4KVideo = false;
m_bIsVideo = false;
m_bEisSupportedSize = false;
m_bTnrEnabled = false;
bool isZsl = false;
uint32_t videoWidth = 0U;
uint32_t videoHeight = 0U;
size_t rawStreamCnt = 0;
size_t stallStreamCnt = 0;
size_t processedStreamCnt = 0;
// Number of streams on ISP encoder path
size_t numStreamsOnEncoder = 0;
size_t numYuv888OnEncoder = 0;
bool bYuv888OverrideJpeg = false;
cam_dimension_t largeYuv888Size = {0, 0};
cam_dimension_t maxViewfinderSize = {0, 0};
bool bJpegExceeds4K = false;
bool bJpegOnEncoder = false;
bool bUseCommonFeatureMask = false;
cam_feature_mask_t commonFeatureMask = 0;
bool bSmallJpegSize = false;
uint32_t width_ratio;
uint32_t height_ratio;
maxViewfinderSize = gCamCapability[mCameraId]->max_viewfinder_size;
camera3_stream_t *inputStream = NULL;
bool isJpeg = false;
cam_dimension_t jpegSize = {0, 0};
cam_padding_info_t padding_info = gCamCapability[mCameraId]->padding_info;
/*EIS configuration*/
bool eisSupported = false;
bool oisSupported = false;
int32_t margin_index = -1;
uint8_t eis_prop_set;
uint32_t maxEisWidth = 0;
uint32_t maxEisHeight = 0;
memset(&mInputStreamInfo, 0, sizeof(mInputStreamInfo));
size_t count = IS_TYPE_MAX;
count = MIN(gCamCapability[mCameraId]->supported_is_types_cnt, count);
for (size_t i = 0; i < count; i++) {
if (gCamCapability[mCameraId]->supported_is_types[i] == IS_TYPE_EIS_2_0) {
eisSupported = true;
margin_index = (int32_t)i;
break;
}
}
count = CAM_OPT_STAB_MAX;
count = MIN(gCamCapability[mCameraId]->optical_stab_modes_count, count);
for (size_t i = 0; i < count; i++) {
if (gCamCapability[mCameraId]->optical_stab_modes[i] == CAM_OPT_STAB_ON) {
oisSupported = true;
break;
}
}
if (eisSupported) {
maxEisWidth = MAX_EIS_WIDTH;
maxEisHeight = MAX_EIS_HEIGHT;
}
/* EIS setprop control */
char eis_prop[PROPERTY_VALUE_MAX];
memset(eis_prop, 0, sizeof(eis_prop));
property_get("persist.camera.eis.enable", eis_prop, "0");
eis_prop_set = (uint8_t)atoi(eis_prop);
m_bEisEnable = eis_prop_set && (!oisSupported && eisSupported) &&
(mOpMode != CAMERA3_STREAM_CONFIGURATION_CONSTRAINED_HIGH_SPEED_MODE);
/* stream configurations */
for (size_t i = 0; i < streamList->num_streams; i++) {
camera3_stream_t *newStream = streamList->streams[i];
LOGI("stream[%d] type = %d, format = %d, width = %d, "
"height = %d, rotation = %d, usage = 0x%x",
i, newStream->stream_type, newStream->format,
newStream->width, newStream->height, newStream->rotation,
newStream->usage);
if (newStream->stream_type == CAMERA3_STREAM_BIDIRECTIONAL ||
newStream->stream_type == CAMERA3_STREAM_INPUT){
isZsl = true;
}
if (newStream->stream_type == CAMERA3_STREAM_INPUT){
inputStream = newStream;
}
if (newStream->format == HAL_PIXEL_FORMAT_BLOB) {
isJpeg = true;
jpegSize.width = newStream->width;
jpegSize.height = newStream->height;
if (newStream->width > VIDEO_4K_WIDTH ||
newStream->height > VIDEO_4K_HEIGHT)
bJpegExceeds4K = true;
}
if ((HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED == newStream->format) &&
(newStream->usage & private_handle_t::PRIV_FLAGS_VIDEO_ENCODER)) {
m_bIsVideo = true;
videoWidth = newStream->width;
videoHeight = newStream->height;
if ((VIDEO_4K_WIDTH <= newStream->width) &&
(VIDEO_4K_HEIGHT <= newStream->height)) {
m_bIs4KVideo = true;
}
m_bEisSupportedSize = (newStream->width <= maxEisWidth) &&
(newStream->height <= maxEisHeight);
}
if (newStream->stream_type == CAMERA3_STREAM_BIDIRECTIONAL ||
newStream->stream_type == CAMERA3_STREAM_OUTPUT) {
switch (newStream->format) {
case HAL_PIXEL_FORMAT_BLOB:
stallStreamCnt++;
if (isOnEncoder(maxViewfinderSize, newStream->width,
newStream->height)) {
numStreamsOnEncoder++;
bJpegOnEncoder = true;
}
width_ratio = CEIL_DIVISION(gCamCapability[mCameraId]->active_array_size.width,
newStream->width);
height_ratio = CEIL_DIVISION(gCamCapability[mCameraId]->active_array_size.height,
newStream->height);;
FATAL_IF(gCamCapability[mCameraId]->max_downscale_factor == 0,
"FATAL: max_downscale_factor cannot be zero and so assert");
if ( (width_ratio > gCamCapability[mCameraId]->max_downscale_factor) ||
(height_ratio > gCamCapability[mCameraId]->max_downscale_factor)) {
LOGH("Setting small jpeg size flag to true");
bSmallJpegSize = true;
}
break;
case HAL_PIXEL_FORMAT_RAW10:
case HAL_PIXEL_FORMAT_RAW_OPAQUE:
case HAL_PIXEL_FORMAT_RAW16:
rawStreamCnt++;
break;
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
processedStreamCnt++;
if (isOnEncoder(maxViewfinderSize, newStream->width,
newStream->height)) {
if (newStream->stream_type != CAMERA3_STREAM_BIDIRECTIONAL &&
!IS_USAGE_ZSL(newStream->usage)) {
commonFeatureMask |= CAM_QCOM_FEATURE_PP_SUPERSET_HAL3;
}
numStreamsOnEncoder++;
}
break;
case HAL_PIXEL_FORMAT_YCbCr_420_888:
processedStreamCnt++;
if (isOnEncoder(maxViewfinderSize, newStream->width,
newStream->height)) {
// If Yuv888 size is not greater than 4K, set feature mask
// to SUPERSET so that it support concurrent request on
// YUV and JPEG.
if (newStream->width <= VIDEO_4K_WIDTH &&
newStream->height <= VIDEO_4K_HEIGHT) {
commonFeatureMask |= CAM_QCOM_FEATURE_PP_SUPERSET_HAL3;
}
numStreamsOnEncoder++;
numYuv888OnEncoder++;
largeYuv888Size.width = newStream->width;
largeYuv888Size.height = newStream->height;
}
break;
default:
processedStreamCnt++;
if (isOnEncoder(maxViewfinderSize, newStream->width,
newStream->height)) {
commonFeatureMask |= CAM_QCOM_FEATURE_PP_SUPERSET_HAL3;
numStreamsOnEncoder++;
}
break;
}
}
}
if (gCamCapability[mCameraId]->position == CAM_POSITION_FRONT ||
!m_bIsVideo) {
m_bEisEnable = false;
}
/* Logic to enable/disable TNR based on specific config size/etc.*/
if ((m_bTnrPreview || m_bTnrVideo) && m_bIsVideo &&
((videoWidth == 1920 && videoHeight == 1080) ||
(videoWidth == 1280 && videoHeight == 720)) &&
(mOpMode != CAMERA3_STREAM_CONFIGURATION_CONSTRAINED_HIGH_SPEED_MODE))
m_bTnrEnabled = true;
/* Check if num_streams is sane */
if (stallStreamCnt > MAX_STALLING_STREAMS ||
rawStreamCnt > MAX_RAW_STREAMS ||
processedStreamCnt > MAX_PROCESSED_STREAMS) {
LOGE("Invalid stream configu: stall: %d, raw: %d, processed %d",
stallStreamCnt, rawStreamCnt, processedStreamCnt);
pthread_mutex_unlock(&mMutex);
return -EINVAL;
}
/* Check whether we have zsl stream or 4k video case */
if (isZsl && m_bIsVideo) {
LOGE("Currently invalid configuration ZSL&Video!");
pthread_mutex_unlock(&mMutex);
return -EINVAL;
}
/* Check if stream sizes are sane */
if (numStreamsOnEncoder > 2) {
LOGE("Number of streams on ISP encoder path exceeds limits of 2");
pthread_mutex_unlock(&mMutex);
return -EINVAL;
} else if (1 < numStreamsOnEncoder){
bUseCommonFeatureMask = true;
LOGH("Multiple streams above max viewfinder size, common mask needed");
}
/* Check if BLOB size is greater than 4k in 4k recording case */
if (m_bIs4KVideo && bJpegExceeds4K) {
LOGE("HAL doesn't support Blob size greater than 4k in 4k recording");
pthread_mutex_unlock(&mMutex);
return -EINVAL;
}
// When JPEG and preview streams share VFE output, CPP will not apply CAC2
// on JPEG stream. So disable such configurations to ensure CAC2 is applied.
// Don't fail for reprocess configurations. Also don't fail if bJpegExceeds4K
// is not true. Otherwise testMandatoryOutputCombinations will fail with following
// configurations:
// {[PRIV, PREVIEW] [PRIV, RECORD] [JPEG, RECORD]}
// {[PRIV, PREVIEW] [YUV, RECORD] [JPEG, RECORD]}
// (These two configurations will not have CAC2 enabled even in HQ modes.)
if (!isZsl && bJpegOnEncoder && bJpegExceeds4K && bUseCommonFeatureMask) {
ALOGE("%s: Blob size greater than 4k and multiple streams are on encoder output",
__func__);
pthread_mutex_unlock(&mMutex);
return -EINVAL;
}
// If jpeg stream is available, and a YUV 888 stream is on Encoder path, and
// the YUV stream's size is greater or equal to the JPEG size, set common
// postprocess mask to NONE, so that we can take advantage of postproc bypass.
if (numYuv888OnEncoder && isOnEncoder(maxViewfinderSize,
jpegSize.width, jpegSize.height) &&
largeYuv888Size.width > jpegSize.width &&
largeYuv888Size.height > jpegSize.height) {
bYuv888OverrideJpeg = true;
} else if (!isJpeg && numStreamsOnEncoder > 1) {
commonFeatureMask = CAM_QCOM_FEATURE_PP_SUPERSET_HAL3;
}
LOGH("max viewfinder width %d height %d isZsl %d bUseCommonFeature %x commonFeatureMask %llx",
maxViewfinderSize.width, maxViewfinderSize.height, isZsl, bUseCommonFeatureMask,
commonFeatureMask);
LOGH("numStreamsOnEncoder %d, processedStreamCnt %d, stallcnt %d bSmallJpegSize %d",
numStreamsOnEncoder, processedStreamCnt, stallStreamCnt, bSmallJpegSize);
rc = validateStreamDimensions(streamList);
if (rc == NO_ERROR) {
rc = validateStreamRotations(streamList);
}
if (rc != NO_ERROR) {
LOGE("Invalid stream configuration requested!");
pthread_mutex_unlock(&mMutex);
return rc;
}
camera3_stream_t *zslStream = NULL; //Only use this for size and not actual handle!
camera3_stream_t *jpegStream = NULL;
for (size_t i = 0; i < streamList->num_streams; i++) {
camera3_stream_t *newStream = streamList->streams[i];
LOGH("newStream type = %d, stream format = %d "
"stream size : %d x %d, stream rotation = %d",
newStream->stream_type, newStream->format,
newStream->width, newStream->height, newStream->rotation);
//if the stream is in the mStreamList validate it
bool stream_exists = false;
for (List<stream_info_t*>::iterator it=mStreamInfo.begin();
it != mStreamInfo.end(); it++) {
if ((*it)->stream == newStream) {
QCamera3ProcessingChannel *channel =
(QCamera3ProcessingChannel*)(*it)->stream->priv;
stream_exists = true;
if (channel)
delete channel;
(*it)->status = VALID;
(*it)->stream->priv = NULL;
(*it)->channel = NULL;
}
}
if (!stream_exists && newStream->stream_type != CAMERA3_STREAM_INPUT) {
//new stream
stream_info_t* stream_info;
stream_info = (stream_info_t* )malloc(sizeof(stream_info_t));
if (!stream_info) {
LOGE("Could not allocate stream info");
rc = -ENOMEM;
pthread_mutex_unlock(&mMutex);
return rc;
}
stream_info->stream = newStream;
stream_info->status = VALID;
stream_info->channel = NULL;
mStreamInfo.push_back(stream_info);
}
/* Covers Opaque ZSL and API1 F/W ZSL */
if (IS_USAGE_ZSL(newStream->usage)
|| newStream->stream_type == CAMERA3_STREAM_BIDIRECTIONAL ) {
if (zslStream != NULL) {
LOGE("Multiple input/reprocess streams requested!");
pthread_mutex_unlock(&mMutex);
return BAD_VALUE;
}
zslStream = newStream;
}
/* Covers YUV reprocess */
if (inputStream != NULL) {
if (newStream->stream_type == CAMERA3_STREAM_OUTPUT
&& newStream->format == HAL_PIXEL_FORMAT_YCbCr_420_888
&& inputStream->format == HAL_PIXEL_FORMAT_YCbCr_420_888
&& inputStream->width == newStream->width
&& inputStream->height == newStream->height) {
if (zslStream != NULL) {
/* This scenario indicates multiple YUV streams with same size
* as input stream have been requested, since zsl stream handle
* is solely use for the purpose of overriding the size of streams
* which share h/w streams we will just make a guess here as to
* which of the stream is a ZSL stream, this will be refactored
* once we make generic logic for streams sharing encoder output
*/
LOGH("Warning, Multiple ip/reprocess streams requested!");
}
zslStream = newStream;
}
}
if (newStream->format == HAL_PIXEL_FORMAT_BLOB) {
jpegStream = newStream;
}
}
/* If a zsl stream is set, we know that we have configured at least one input or
bidirectional stream */
if (NULL != zslStream) {
mInputStreamInfo.dim.width = (int32_t)zslStream->width;
mInputStreamInfo.dim.height = (int32_t)zslStream->height;
mInputStreamInfo.format = zslStream->format;
mInputStreamInfo.usage = zslStream->usage;
LOGD("Input stream configured! %d x %d, format %d, usage %d",
mInputStreamInfo.dim.width,
mInputStreamInfo.dim.height,
mInputStreamInfo.format, mInputStreamInfo.usage);
}
cleanAndSortStreamInfo();
if (mMetadataChannel) {
delete mMetadataChannel;
mMetadataChannel = NULL;
}
if (mSupportChannel) {
delete mSupportChannel;
mSupportChannel = NULL;
}
if (mAnalysisChannel) {
delete mAnalysisChannel;
mAnalysisChannel = NULL;
}
if (mDummyBatchChannel) {
delete mDummyBatchChannel;
mDummyBatchChannel = NULL;
}
//Create metadata channel and initialize it
cam_feature_mask_t metadataFeatureMask = CAM_QCOM_FEATURE_NONE;
setPAAFSupport(metadataFeatureMask, CAM_STREAM_TYPE_METADATA,
gCamCapability[mCameraId]->color_arrangement);
mMetadataChannel = new QCamera3MetadataChannel(mCameraHandle->camera_handle,
mChannelHandle, mCameraHandle->ops, captureResultCb,
setBufferErrorStatus, &padding_info, metadataFeatureMask, this);
if (mMetadataChannel == NULL) {
LOGE("failed to allocate metadata channel");
rc = -ENOMEM;
pthread_mutex_unlock(&mMutex);
return rc;
}
rc = mMetadataChannel->initialize(IS_TYPE_NONE);
if (rc < 0) {
LOGE("metadata channel initialization failed");
delete mMetadataChannel;
mMetadataChannel = NULL;
pthread_mutex_unlock(&mMutex);
return rc;
}
// Create analysis stream all the time, even when h/w support is not available
{
cam_feature_mask_t analysisFeatureMask = CAM_QCOM_FEATURE_PP_SUPERSET_HAL3;
cam_analysis_info_t analysisInfo;
rc = mCommon.getAnalysisInfo(
FALSE,
TRUE,
analysisFeatureMask,
&analysisInfo);
if (rc != NO_ERROR) {
LOGE("getAnalysisInfo failed, ret = %d", rc);
pthread_mutex_unlock(&mMutex);
return rc;
}
cam_color_filter_arrangement_t analysis_color_arrangement =
(analysisInfo.analysis_format == CAM_FORMAT_Y_ONLY ?
CAM_FILTER_ARRANGEMENT_Y :
gCamCapability[mCameraId]->color_arrangement);
setPAAFSupport(analysisFeatureMask, CAM_STREAM_TYPE_ANALYSIS,
analysis_color_arrangement);
mAnalysisChannel = new QCamera3SupportChannel(
mCameraHandle->camera_handle,
mChannelHandle,
mCameraHandle->ops,
&analysisInfo.analysis_padding_info,
analysisFeatureMask,
CAM_STREAM_TYPE_ANALYSIS,
&analysisInfo.analysis_max_res,
(analysisInfo.analysis_format
== CAM_FORMAT_Y_ONLY ? CAM_FORMAT_Y_ONLY
: CAM_FORMAT_YUV_420_NV21),
analysisInfo.hw_analysis_supported,
this,
0); // force buffer count to 0
if (!mAnalysisChannel) {
LOGE("H/W Analysis channel cannot be created");
pthread_mutex_unlock(&mMutex);
return -ENOMEM;
}
}
bool isRawStreamRequested = false;
memset(&mStreamConfigInfo, 0, sizeof(cam_stream_size_info_t));
/* Allocate channel objects for the requested streams */
for (size_t i = 0; i < streamList->num_streams; i++) {
camera3_stream_t *newStream = streamList->streams[i];
uint32_t stream_usage = newStream->usage;
mStreamConfigInfo.stream_sizes[mStreamConfigInfo.num_streams].width = (int32_t)newStream->width;
mStreamConfigInfo.stream_sizes[mStreamConfigInfo.num_streams].height = (int32_t)newStream->height;
if ((newStream->stream_type == CAMERA3_STREAM_BIDIRECTIONAL
|| IS_USAGE_ZSL(newStream->usage)) &&
newStream->format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED){
mStreamConfigInfo.type[mStreamConfigInfo.num_streams] = CAM_STREAM_TYPE_SNAPSHOT;
if (bUseCommonFeatureMask) {
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams] =
commonFeatureMask;
} else {
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams] =
CAM_QCOM_FEATURE_NONE;
}
} else if(newStream->stream_type == CAMERA3_STREAM_INPUT) {
LOGH("Input stream configured, reprocess config");
} else {
//for non zsl streams find out the format
switch (newStream->format) {
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED :
{
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams] =
CAM_QCOM_FEATURE_PP_SUPERSET_HAL3;
/* add additional features to pp feature mask */
addToPPFeatureMask(HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
mStreamConfigInfo.num_streams);
if (stream_usage & private_handle_t::PRIV_FLAGS_VIDEO_ENCODER) {
mStreamConfigInfo.type[mStreamConfigInfo.num_streams] =
CAM_STREAM_TYPE_VIDEO;
if (m_bTnrEnabled && m_bTnrVideo) {
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams] |=
CAM_QCOM_FEATURE_CPP_TNR;
//TNR and CDS are mutually exclusive. So reset CDS from feature mask
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams] &=
~CAM_QCOM_FEATURE_CDS;
}
} else {
mStreamConfigInfo.type[mStreamConfigInfo.num_streams] =
CAM_STREAM_TYPE_PREVIEW;
if (m_bTnrEnabled && m_bTnrPreview) {
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams] |=
CAM_QCOM_FEATURE_CPP_TNR;
//TNR and CDS are mutually exclusive. So reset CDS from feature mask
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams] &=
~CAM_QCOM_FEATURE_CDS;
}
padding_info.width_padding = mSurfaceStridePadding;
padding_info.height_padding = CAM_PAD_TO_2;
}
if ((newStream->rotation == CAMERA3_STREAM_ROTATION_90) ||
(newStream->rotation == CAMERA3_STREAM_ROTATION_270)) {
mStreamConfigInfo.stream_sizes[mStreamConfigInfo.num_streams].width =
newStream->height;
mStreamConfigInfo.stream_sizes[mStreamConfigInfo.num_streams].height =
newStream->width;
}
}
break;
case HAL_PIXEL_FORMAT_YCbCr_420_888:
mStreamConfigInfo.type[mStreamConfigInfo.num_streams] = CAM_STREAM_TYPE_CALLBACK;
if (isOnEncoder(maxViewfinderSize, newStream->width, newStream->height)) {
if (bUseCommonFeatureMask)
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams] =
commonFeatureMask;
else
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams] =
CAM_QCOM_FEATURE_NONE;
} else {
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams] =
CAM_QCOM_FEATURE_PP_SUPERSET_HAL3;
}
break;
case HAL_PIXEL_FORMAT_BLOB:
mStreamConfigInfo.type[mStreamConfigInfo.num_streams] = CAM_STREAM_TYPE_SNAPSHOT;
// No need to check bSmallJpegSize if ZSL is present since JPEG uses ZSL stream
if ((m_bIs4KVideo && !isZsl) || (bSmallJpegSize && !isZsl)) {
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams] =
CAM_QCOM_FEATURE_PP_SUPERSET_HAL3;
} else {
if (bUseCommonFeatureMask &&
isOnEncoder(maxViewfinderSize, newStream->width,
newStream->height)) {
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams] = commonFeatureMask;
} else {
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams] = CAM_QCOM_FEATURE_NONE;
}
}
if (isZsl) {
if (zslStream) {
mStreamConfigInfo.stream_sizes[mStreamConfigInfo.num_streams].width =
(int32_t)zslStream->width;
mStreamConfigInfo.stream_sizes[mStreamConfigInfo.num_streams].height =
(int32_t)zslStream->height;
} else {
LOGE("Error, No ZSL stream identified");
pthread_mutex_unlock(&mMutex);
return -EINVAL;
}
} else if (m_bIs4KVideo) {
mStreamConfigInfo.stream_sizes[mStreamConfigInfo.num_streams].width = (int32_t)videoWidth;
mStreamConfigInfo.stream_sizes[mStreamConfigInfo.num_streams].height = (int32_t)videoHeight;
} else if (bYuv888OverrideJpeg) {
mStreamConfigInfo.stream_sizes[mStreamConfigInfo.num_streams].width =
(int32_t)largeYuv888Size.width;
mStreamConfigInfo.stream_sizes[mStreamConfigInfo.num_streams].height =
(int32_t)largeYuv888Size.height;
}
break;
case HAL_PIXEL_FORMAT_RAW_OPAQUE:
case HAL_PIXEL_FORMAT_RAW16:
case HAL_PIXEL_FORMAT_RAW10:
mStreamConfigInfo.type[mStreamConfigInfo.num_streams] = CAM_STREAM_TYPE_RAW;
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams] = CAM_QCOM_FEATURE_NONE;
isRawStreamRequested = true;
break;
default:
mStreamConfigInfo.type[mStreamConfigInfo.num_streams] = CAM_STREAM_TYPE_DEFAULT;
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams] = CAM_QCOM_FEATURE_NONE;
break;
}
}
setPAAFSupport(mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams],
(cam_stream_type_t) mStreamConfigInfo.type[mStreamConfigInfo.num_streams],
gCamCapability[mCameraId]->color_arrangement);
if (newStream->priv == NULL) {
//New stream, construct channel
switch (newStream->stream_type) {
case CAMERA3_STREAM_INPUT:
newStream->usage |= GRALLOC_USAGE_HW_CAMERA_READ;
newStream->usage |= GRALLOC_USAGE_HW_CAMERA_WRITE;//WR for inplace algo's
break;
case CAMERA3_STREAM_BIDIRECTIONAL:
newStream->usage |= GRALLOC_USAGE_HW_CAMERA_READ |
GRALLOC_USAGE_HW_CAMERA_WRITE;
break;
case CAMERA3_STREAM_OUTPUT:
/* For video encoding stream, set read/write rarely
* flag so that they may be set to un-cached */
if (newStream->usage & GRALLOC_USAGE_HW_VIDEO_ENCODER)
newStream->usage |=
(GRALLOC_USAGE_SW_READ_RARELY |
GRALLOC_USAGE_SW_WRITE_RARELY |
GRALLOC_USAGE_HW_CAMERA_WRITE);
else if (IS_USAGE_ZSL(newStream->usage))
{
LOGD("ZSL usage flag skipping");
}
else if (newStream == zslStream
|| newStream->format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
newStream->usage |= GRALLOC_USAGE_HW_CAMERA_ZSL;
} else
newStream->usage |= GRALLOC_USAGE_HW_CAMERA_WRITE;
break;
default:
LOGE("Invalid stream_type %d", newStream->stream_type);
break;
}
if (newStream->stream_type == CAMERA3_STREAM_OUTPUT ||
newStream->stream_type == CAMERA3_STREAM_BIDIRECTIONAL) {
QCamera3ProcessingChannel *channel = NULL;
switch (newStream->format) {
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
if ((newStream->usage &
private_handle_t::PRIV_FLAGS_VIDEO_ENCODER) &&
(streamList->operation_mode ==
CAMERA3_STREAM_CONFIGURATION_CONSTRAINED_HIGH_SPEED_MODE)
) {
channel = new QCamera3RegularChannel(mCameraHandle->camera_handle,
mChannelHandle, mCameraHandle->ops, captureResultCb,
setBufferErrorStatus, &gCamCapability[mCameraId]->padding_info,
this,
newStream,
(cam_stream_type_t)
mStreamConfigInfo.type[mStreamConfigInfo.num_streams],
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams],
mMetadataChannel,
0); //heap buffers are not required for HFR video channel
if (channel == NULL) {
LOGE("allocation of channel failed");
pthread_mutex_unlock(&mMutex);
return -ENOMEM;
}
//channel->getNumBuffers() will return 0 here so use
//MAX_INFLIGH_HFR_REQUESTS
newStream->max_buffers = MAX_INFLIGHT_HFR_REQUESTS;
newStream->priv = channel;
LOGI("num video buffers in HFR mode: %d",
MAX_INFLIGHT_HFR_REQUESTS);
} else {
/* Copy stream contents in HFR preview only case to create
* dummy batch channel so that sensor streaming is in
* HFR mode */
if (!m_bIsVideo && (streamList->operation_mode ==
CAMERA3_STREAM_CONFIGURATION_CONSTRAINED_HIGH_SPEED_MODE)) {
mDummyBatchStream = *newStream;
}
channel = new QCamera3RegularChannel(mCameraHandle->camera_handle,
mChannelHandle, mCameraHandle->ops, captureResultCb,
setBufferErrorStatus, &gCamCapability[mCameraId]->padding_info,
this,
newStream,
(cam_stream_type_t)
mStreamConfigInfo.type[mStreamConfigInfo.num_streams],
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams],
mMetadataChannel,
MAX_INFLIGHT_REQUESTS);
if (channel == NULL) {
LOGE("allocation of channel failed");
pthread_mutex_unlock(&mMutex);
return -ENOMEM;
}
newStream->max_buffers = MAX_INFLIGHT_60FPS_REQUESTS;
newStream->priv = channel;
}
break;
case HAL_PIXEL_FORMAT_YCbCr_420_888: {
channel = new QCamera3YUVChannel(mCameraHandle->camera_handle,
mChannelHandle,
mCameraHandle->ops, captureResultCb,
setBufferErrorStatus, &padding_info,
this,
newStream,
(cam_stream_type_t)
mStreamConfigInfo.type[mStreamConfigInfo.num_streams],
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams],
mMetadataChannel);
if (channel == NULL) {
LOGE("allocation of YUV channel failed");
pthread_mutex_unlock(&mMutex);
return -ENOMEM;
}
newStream->max_buffers = channel->getNumBuffers();
newStream->priv = channel;
break;
}
case HAL_PIXEL_FORMAT_RAW_OPAQUE:
case HAL_PIXEL_FORMAT_RAW16:
case HAL_PIXEL_FORMAT_RAW10:
mRawChannel = new QCamera3RawChannel(
mCameraHandle->camera_handle, mChannelHandle,
mCameraHandle->ops, captureResultCb,
setBufferErrorStatus, &padding_info,
this, newStream,
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams],
mMetadataChannel,
(newStream->format == HAL_PIXEL_FORMAT_RAW16));
if (mRawChannel == NULL) {
LOGE("allocation of raw channel failed");
pthread_mutex_unlock(&mMutex);
return -ENOMEM;
}
newStream->max_buffers = mRawChannel->getNumBuffers();
newStream->priv = (QCamera3ProcessingChannel*)mRawChannel;
break;
case HAL_PIXEL_FORMAT_BLOB:
// Max live snapshot inflight buffer is 1. This is to mitigate
// frame drop issues for video snapshot. The more buffers being
// allocated, the more frame drops there are.
mPictureChannel = new QCamera3PicChannel(
mCameraHandle->camera_handle, mChannelHandle,
mCameraHandle->ops, captureResultCb,
setBufferErrorStatus, &padding_info, this, newStream,
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams],
m_bIs4KVideo, isZsl, mMetadataChannel,
(m_bIsVideo ? 1 : MAX_INFLIGHT_BLOB));
if (mPictureChannel == NULL) {
LOGE("allocation of channel failed");
pthread_mutex_unlock(&mMutex);
return -ENOMEM;
}
newStream->priv = (QCamera3ProcessingChannel*)mPictureChannel;
newStream->max_buffers = mPictureChannel->getNumBuffers();
mPictureChannel->overrideYuvSize(
mStreamConfigInfo.stream_sizes[mStreamConfigInfo.num_streams].width,
mStreamConfigInfo.stream_sizes[mStreamConfigInfo.num_streams].height);
break;
default:
LOGE("not a supported format 0x%x", newStream->format);
break;
}
} else if (newStream->stream_type == CAMERA3_STREAM_INPUT) {
newStream->max_buffers = MAX_INFLIGHT_REPROCESS_REQUESTS;
} else {
LOGE("Error, Unknown stream type");
pthread_mutex_unlock(&mMutex);
return -EINVAL;
}
QCamera3Channel *channel = (QCamera3Channel*) newStream->priv;
if (channel != NULL && channel->isUBWCEnabled()) {
cam_format_t fmt = channel->getStreamDefaultFormat(
mStreamConfigInfo.type[mStreamConfigInfo.num_streams],
newStream->width, newStream->height);
if(fmt == CAM_FORMAT_YUV_420_NV12_UBWC) {
newStream->usage |= GRALLOC_USAGE_PRIVATE_ALLOC_UBWC;
}
}
for (List<stream_info_t*>::iterator it=mStreamInfo.begin();
it != mStreamInfo.end(); it++) {
if ((*it)->stream == newStream) {
(*it)->channel = (QCamera3ProcessingChannel*) newStream->priv;
break;
}
}
} else {
// Channel already exists for this stream
// Do nothing for now
}
padding_info = gCamCapability[mCameraId]->padding_info;
/* Do not add entries for input stream in metastream info
* since there is no real stream associated with it
*/
if (newStream->stream_type != CAMERA3_STREAM_INPUT)
mStreamConfigInfo.num_streams++;
}
//RAW DUMP channel
if (mEnableRawDump && isRawStreamRequested == false){
cam_dimension_t rawDumpSize;
rawDumpSize = getMaxRawSize(mCameraId);
cam_feature_mask_t rawDumpFeatureMask = CAM_QCOM_FEATURE_NONE;
setPAAFSupport(rawDumpFeatureMask,
CAM_STREAM_TYPE_RAW,
gCamCapability[mCameraId]->color_arrangement);
mRawDumpChannel = new QCamera3RawDumpChannel(mCameraHandle->camera_handle,
mChannelHandle,
mCameraHandle->ops,
rawDumpSize,
&padding_info,
this, rawDumpFeatureMask);
if (!mRawDumpChannel) {
LOGE("Raw Dump channel cannot be created");
pthread_mutex_unlock(&mMutex);
return -ENOMEM;
}
}
if (mAnalysisChannel) {
cam_analysis_info_t analysisInfo;
memset(&analysisInfo, 0, sizeof(cam_analysis_info_t));
mStreamConfigInfo.type[mStreamConfigInfo.num_streams] =
CAM_STREAM_TYPE_ANALYSIS;
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams] =
CAM_QCOM_FEATURE_PP_SUPERSET_HAL3;
rc = mCommon.getAnalysisInfo(FALSE, TRUE,
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams],
&analysisInfo);
if (rc != NO_ERROR) {
LOGE("getAnalysisInfo failed, ret = %d", rc);
pthread_mutex_unlock(&mMutex);
return rc;
}
cam_color_filter_arrangement_t analysis_color_arrangement =
(analysisInfo.analysis_format == CAM_FORMAT_Y_ONLY ?
CAM_FILTER_ARRANGEMENT_Y :
gCamCapability[mCameraId]->color_arrangement);
setPAAFSupport(mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams],
mStreamConfigInfo.type[mStreamConfigInfo.num_streams],
analysis_color_arrangement);
mStreamConfigInfo.stream_sizes[mStreamConfigInfo.num_streams] =
analysisInfo.analysis_max_res;
mStreamConfigInfo.num_streams++;
}
if (isSupportChannelNeeded(streamList, mStreamConfigInfo)) {
cam_analysis_info_t supportInfo;
memset(&supportInfo, 0, sizeof(cam_analysis_info_t));
cam_feature_mask_t callbackFeatureMask = CAM_QCOM_FEATURE_PP_SUPERSET_HAL3;
setPAAFSupport(callbackFeatureMask,
CAM_STREAM_TYPE_CALLBACK,
gCamCapability[mCameraId]->color_arrangement);
rc = mCommon.getAnalysisInfo(FALSE, TRUE, callbackFeatureMask, &supportInfo);
if (rc != NO_ERROR) {
LOGE("getAnalysisInfo failed, ret = %d", rc);
pthread_mutex_unlock(&mMutex);
return rc;
}
mSupportChannel = new QCamera3SupportChannel(
mCameraHandle->camera_handle,
mChannelHandle,
mCameraHandle->ops,
&gCamCapability[mCameraId]->padding_info,
callbackFeatureMask,
CAM_STREAM_TYPE_CALLBACK,
&QCamera3SupportChannel::kDim,
CAM_FORMAT_YUV_420_NV21,
supportInfo.hw_analysis_supported,
this, 0);
if (!mSupportChannel) {
LOGE("dummy channel cannot be created");
pthread_mutex_unlock(&mMutex);
return -ENOMEM;
}
}
if (mSupportChannel) {
mStreamConfigInfo.stream_sizes[mStreamConfigInfo.num_streams] =
QCamera3SupportChannel::kDim;
mStreamConfigInfo.type[mStreamConfigInfo.num_streams] =
CAM_STREAM_TYPE_CALLBACK;
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams] =
CAM_QCOM_FEATURE_PP_SUPERSET_HAL3;
setPAAFSupport(mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams],
mStreamConfigInfo.type[mStreamConfigInfo.num_streams],
gCamCapability[mCameraId]->color_arrangement);
mStreamConfigInfo.num_streams++;
}
if (mRawDumpChannel) {
cam_dimension_t rawSize;
rawSize = getMaxRawSize(mCameraId);
mStreamConfigInfo.stream_sizes[mStreamConfigInfo.num_streams] =
rawSize;
mStreamConfigInfo.type[mStreamConfigInfo.num_streams] =
CAM_STREAM_TYPE_RAW;
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams] =
CAM_QCOM_FEATURE_NONE;
setPAAFSupport(mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams],
mStreamConfigInfo.type[mStreamConfigInfo.num_streams],
gCamCapability[mCameraId]->color_arrangement);
mStreamConfigInfo.num_streams++;
}
/* In HFR mode, if video stream is not added, create a dummy channel so that
* ISP can create a batch mode even for preview only case. This channel is
* never 'start'ed (no stream-on), it is only 'initialized' */
if ((mOpMode == CAMERA3_STREAM_CONFIGURATION_CONSTRAINED_HIGH_SPEED_MODE) &&
!m_bIsVideo) {
cam_feature_mask_t dummyFeatureMask = CAM_QCOM_FEATURE_PP_SUPERSET_HAL3;
setPAAFSupport(dummyFeatureMask,
CAM_STREAM_TYPE_VIDEO,
gCamCapability[mCameraId]->color_arrangement);
mDummyBatchChannel = new QCamera3RegularChannel(mCameraHandle->camera_handle,
mChannelHandle,
mCameraHandle->ops, captureResultCb,
setBufferErrorStatus, &gCamCapability[mCameraId]->padding_info,
this,
&mDummyBatchStream,
CAM_STREAM_TYPE_VIDEO,
dummyFeatureMask,
mMetadataChannel);
if (NULL == mDummyBatchChannel) {
LOGE("creation of mDummyBatchChannel failed."
"Preview will use non-hfr sensor mode ");
}
}
if (mDummyBatchChannel) {
mStreamConfigInfo.stream_sizes[mStreamConfigInfo.num_streams].width =
mDummyBatchStream.width;
mStreamConfigInfo.stream_sizes[mStreamConfigInfo.num_streams].height =
mDummyBatchStream.height;
mStreamConfigInfo.type[mStreamConfigInfo.num_streams] =
CAM_STREAM_TYPE_VIDEO;
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams] =
CAM_QCOM_FEATURE_PP_SUPERSET_HAL3;
setPAAFSupport(mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams],
mStreamConfigInfo.type[mStreamConfigInfo.num_streams],
gCamCapability[mCameraId]->color_arrangement);
mStreamConfigInfo.num_streams++;
}
mStreamConfigInfo.buffer_info.min_buffers = MIN_INFLIGHT_REQUESTS;
mStreamConfigInfo.buffer_info.max_buffers =
m_bIs4KVideo ? 0 : MAX_INFLIGHT_REQUESTS;
/* Initialize mPendingRequestInfo and mPendingBuffersMap */
for (pendingRequestIterator i = mPendingRequestsList.begin();
i != mPendingRequestsList.end();) {
i = erasePendingRequest(i);
}
mPendingFrameDropList.clear();
// Initialize/Reset the pending buffers list
for (auto &req : mPendingBuffersMap.mPendingBuffersInRequest) {
req.mPendingBufferList.clear();
}
mPendingBuffersMap.mPendingBuffersInRequest.clear();
mPendingReprocessResultList.clear();
mCurJpegMeta.clear();
//Get min frame duration for this streams configuration
deriveMinFrameDuration();
// Update state
mState = CONFIGURED;
pthread_mutex_unlock(&mMutex);
return rc;
}
/*===========================================================================
* FUNCTION : validateCaptureRequest
*
* DESCRIPTION: validate a capture request from camera service
*
* PARAMETERS :
* @request : request from framework to process
*
* RETURN :
*
*==========================================================================*/
int QCamera3HardwareInterface::validateCaptureRequest(
camera3_capture_request_t *request)
{
ssize_t idx = 0;
const camera3_stream_buffer_t *b;
CameraMetadata meta;
/* Sanity check the request */
if (request == NULL) {
LOGE("NULL capture request");
return BAD_VALUE;
}
if ((request->settings == NULL) && (mState == CONFIGURED)) {
/*settings cannot be null for the first request*/
return BAD_VALUE;
}
uint32_t frameNumber = request->frame_number;
if (request->num_output_buffers < 1 || request->output_buffers == NULL) {
LOGE("Request %d: No output buffers provided!",
__FUNCTION__, frameNumber);
return BAD_VALUE;
}
if (request->num_output_buffers >= MAX_NUM_STREAMS) {
LOGE("Number of buffers %d equals or is greater than maximum number of streams!",
request->num_output_buffers, MAX_NUM_STREAMS);
return BAD_VALUE;
}
if (request->input_buffer != NULL) {
b = request->input_buffer;
if (b->status != CAMERA3_BUFFER_STATUS_OK) {
LOGE("Request %d: Buffer %ld: Status not OK!",
frameNumber, (long)idx);
return BAD_VALUE;
}
if (b->release_fence != -1) {
LOGE("Request %d: Buffer %ld: Has a release fence!",
frameNumber, (long)idx);
return BAD_VALUE;
}
if (b->buffer == NULL) {
LOGE("Request %d: Buffer %ld: NULL buffer handle!",
frameNumber, (long)idx);
return BAD_VALUE;
}
}
// Validate all buffers
b = request->output_buffers;
do {
QCamera3ProcessingChannel *channel =
static_cast<QCamera3ProcessingChannel*>(b->stream->priv);
if (channel == NULL) {
LOGE("Request %d: Buffer %ld: Unconfigured stream!",
frameNumber, (long)idx);
return BAD_VALUE;
}
if (b->status != CAMERA3_BUFFER_STATUS_OK) {
LOGE("Request %d: Buffer %ld: Status not OK!",
frameNumber, (long)idx);
return BAD_VALUE;
}
if (b->release_fence != -1) {
LOGE("Request %d: Buffer %ld: Has a release fence!",
frameNumber, (long)idx);
return BAD_VALUE;
}
if (b->buffer == NULL) {
LOGE("Request %d: Buffer %ld: NULL buffer handle!",
frameNumber, (long)idx);
return BAD_VALUE;
}
if (*(b->buffer) == NULL) {
LOGE("Request %d: Buffer %ld: NULL private handle!",
frameNumber, (long)idx);
return BAD_VALUE;
}
idx++;
b = request->output_buffers + idx;
} while (idx < (ssize_t)request->num_output_buffers);
return NO_ERROR;
}
/*===========================================================================
* FUNCTION : deriveMinFrameDuration
*
* DESCRIPTION: derive mininum processed, jpeg, and raw frame durations based
* on currently configured streams.
*
* PARAMETERS : NONE
*
* RETURN : NONE
*
*==========================================================================*/
void QCamera3HardwareInterface::deriveMinFrameDuration()
{
int32_t maxJpegDim, maxProcessedDim, maxRawDim;
maxJpegDim = 0;
maxProcessedDim = 0;
maxRawDim = 0;
// Figure out maximum jpeg, processed, and raw dimensions
for (List<stream_info_t*>::iterator it = mStreamInfo.begin();
it != mStreamInfo.end(); it++) {
// Input stream doesn't have valid stream_type
if ((*it)->stream->stream_type == CAMERA3_STREAM_INPUT)
continue;
int32_t dimension = (int32_t)((*it)->stream->width * (*it)->stream->height);
if ((*it)->stream->format == HAL_PIXEL_FORMAT_BLOB) {
if (dimension > maxJpegDim)
maxJpegDim = dimension;
} else if ((*it)->stream->format == HAL_PIXEL_FORMAT_RAW_OPAQUE ||
(*it)->stream->format == HAL_PIXEL_FORMAT_RAW10 ||
(*it)->stream->format == HAL_PIXEL_FORMAT_RAW16) {
if (dimension > maxRawDim)
maxRawDim = dimension;
} else {
if (dimension > maxProcessedDim)
maxProcessedDim = dimension;
}
}
size_t count = MIN(gCamCapability[mCameraId]->supported_raw_dim_cnt,
MAX_SIZES_CNT);
//Assume all jpeg dimensions are in processed dimensions.
if (maxJpegDim > maxProcessedDim)
maxProcessedDim = maxJpegDim;
//Find the smallest raw dimension that is greater or equal to jpeg dimension
if (maxProcessedDim > maxRawDim) {
maxRawDim = INT32_MAX;
for (size_t i = 0; i < count; i++) {
int32_t dimension = gCamCapability[mCameraId]->raw_dim[i].width *
gCamCapability[mCameraId]->raw_dim[i].height;
if (dimension >= maxProcessedDim && dimension < maxRawDim)
maxRawDim = dimension;
}
}
//Find minimum durations for processed, jpeg, and raw
for (size_t i = 0; i < count; i++) {
if (maxRawDim == gCamCapability[mCameraId]->raw_dim[i].width *
gCamCapability[mCameraId]->raw_dim[i].height) {
mMinRawFrameDuration = gCamCapability[mCameraId]->raw_min_duration[i];
break;
}
}
count = MIN(gCamCapability[mCameraId]->picture_sizes_tbl_cnt, MAX_SIZES_CNT);
for (size_t i = 0; i < count; i++) {
if (maxProcessedDim ==
gCamCapability[mCameraId]->picture_sizes_tbl[i].width *
gCamCapability[mCameraId]->picture_sizes_tbl[i].height) {
mMinProcessedFrameDuration = gCamCapability[mCameraId]->picture_min_duration[i];
mMinJpegFrameDuration = gCamCapability[mCameraId]->picture_min_duration[i];
break;
}
}
}
/*===========================================================================
* FUNCTION : getMinFrameDuration
*
* DESCRIPTION: get minimum frame draution based on the current maximum frame durations
* and current request configuration.
*
* PARAMETERS : @request: requset sent by the frameworks
*
* RETURN : min farme duration for a particular request
*
*==========================================================================*/
int64_t QCamera3HardwareInterface::getMinFrameDuration(const camera3_capture_request_t *request)
{
bool hasJpegStream = false;
bool hasRawStream = false;
for (uint32_t i = 0; i < request->num_output_buffers; i ++) {
const camera3_stream_t *stream = request->output_buffers[i].stream;
if (stream->format == HAL_PIXEL_FORMAT_BLOB)
hasJpegStream = true;
else if (stream->format == HAL_PIXEL_FORMAT_RAW_OPAQUE ||
stream->format == HAL_PIXEL_FORMAT_RAW10 ||
stream->format == HAL_PIXEL_FORMAT_RAW16)
hasRawStream = true;
}
if (!hasJpegStream)
return MAX(mMinRawFrameDuration, mMinProcessedFrameDuration);
else
return MAX(MAX(mMinRawFrameDuration, mMinProcessedFrameDuration), mMinJpegFrameDuration);
}
/*===========================================================================
* FUNCTION : handleBuffersDuringFlushLock
*
* DESCRIPTION: Account for buffers returned from back-end during flush
* This function is executed while mMutex is held by the caller.
*
* PARAMETERS :
* @buffer: image buffer for the callback
*
* RETURN :
*==========================================================================*/
void QCamera3HardwareInterface::handleBuffersDuringFlushLock(camera3_stream_buffer_t *buffer)
{
bool buffer_found = false;
for (List<PendingBuffersInRequest>::iterator req =
mPendingBuffersMap.mPendingBuffersInRequest.begin();
req != mPendingBuffersMap.mPendingBuffersInRequest.end(); req++) {
for (List<PendingBufferInfo>::iterator i =
req->mPendingBufferList.begin();
i != req->mPendingBufferList.end(); i++) {
if (i->buffer == buffer->buffer) {
mPendingBuffersMap.numPendingBufsAtFlush--;
LOGD("Found buffer %p for Frame %d, numPendingBufsAtFlush = %d",
buffer->buffer, req->frame_number,
mPendingBuffersMap.numPendingBufsAtFlush);
buffer_found = true;
break;
}
}
if (buffer_found) {
break;
}
}
if (mPendingBuffersMap.numPendingBufsAtFlush == 0) {
//signal the flush()
LOGD("All buffers returned to HAL. Continue flush");
pthread_cond_signal(&mBuffersCond);
}
}
/*===========================================================================
* FUNCTION : handlePendingReprocResults
*
* DESCRIPTION: check and notify on any pending reprocess results
*
* PARAMETERS :
* @frame_number : Pending request frame number
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCamera3HardwareInterface::handlePendingReprocResults(uint32_t frame_number)
{
for (List<PendingReprocessResult>::iterator j = mPendingReprocessResultList.begin();
j != mPendingReprocessResultList.end(); j++) {
if (j->frame_number == frame_number) {
mCallbackOps->notify(mCallbackOps, &j->notify_msg);
LOGD("Delayed reprocess notify %d",
frame_number);
for (pendingRequestIterator k = mPendingRequestsList.begin();
k != mPendingRequestsList.end(); k++) {
if (k->frame_number == j->frame_number) {
LOGD("Found reprocess frame number %d in pending reprocess List "
"Take it out!!",
k->frame_number);
camera3_capture_result result;
memset(&result, 0, sizeof(camera3_capture_result));
result.frame_number = frame_number;
result.num_output_buffers = 1;
result.output_buffers = &j->buffer;
result.input_buffer = k->input_buffer;
result.result = k->settings;
result.partial_result = PARTIAL_RESULT_COUNT;
mCallbackOps->process_capture_result(mCallbackOps, &result);
erasePendingRequest(k);
break;
}
}
mPendingReprocessResultList.erase(j);
break;
}
}
return NO_ERROR;
}
/*===========================================================================
* FUNCTION : handleBatchMetadata
*
* DESCRIPTION: Handles metadata buffer callback in batch mode
*
* PARAMETERS : @metadata_buf: metadata buffer
* @free_and_bufdone_meta_buf: Buf done on the meta buf and free
* the meta buf in this method
*
* RETURN :
*
*==========================================================================*/
void QCamera3HardwareInterface::handleBatchMetadata(
mm_camera_super_buf_t *metadata_buf, bool free_and_bufdone_meta_buf)
{
ATRACE_CALL();
if (NULL == metadata_buf) {
LOGE("metadata_buf is NULL");
return;
}
/* In batch mode, the metdata will contain the frame number and timestamp of
* the last frame in the batch. Eg: a batch containing buffers from request
* 5,6,7 and 8 will have frame number and timestamp corresponding to 8.
* multiple process_capture_requests => 1 set_param => 1 handleBatchMetata =>
* multiple process_capture_results */
metadata_buffer_t *metadata =
(metadata_buffer_t *)metadata_buf->bufs[0]->buffer;
int32_t frame_number_valid = 0, urgent_frame_number_valid = 0;
uint32_t last_frame_number = 0, last_urgent_frame_number = 0;
uint32_t first_frame_number = 0, first_urgent_frame_number = 0;
uint32_t frame_number = 0, urgent_frame_number = 0;
int64_t last_frame_capture_time = 0, first_frame_capture_time, capture_time;
bool invalid_metadata = false;
size_t urgentFrameNumDiff = 0, frameNumDiff = 0;
size_t loopCount = 1;
int32_t *p_frame_number_valid =
POINTER_OF_META(CAM_INTF_META_FRAME_NUMBER_VALID, metadata);
uint32_t *p_frame_number =