blob: 8fc129c00501f907122dd53a64894b5e50c009b2 [file] [log] [blame]
/* Copyright (c) 2012-2015, The Linux Foundataion. 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 ATRACE_TAG ATRACE_TAG_CAMERA
#define LOG_TAG "QCamera3HWI"
//#define LOG_NDEBUG 0
#define __STDC_LIMIT_MACROS
#include <cutils/properties.h>
#include <hardware/camera3.h>
#include <camera/CameraMetadata.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stdint.h>
#include <utils/Log.h>
#include <utils/Errors.h>
#include <utils/Trace.h>
#include <sync/sync.h>
#include <gralloc_priv.h>
#include "util/QCameraFlash.h"
#include "QCamera3HWI.h"
#include "QCamera3Mem.h"
#include "QCamera3Channel.h"
#include "QCamera3PostProc.h"
#include "QCamera3VendorTags.h"
#include "cam_cond.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 3
#define FRAME_SKIP_DELAY 0
#define CAM_MAX_SYNC_LATENCY 4
#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 1920
#define MAX_EIS_HEIGHT 1080
#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 MAX_HFR_BATCH_SIZE (8)
#define REGIONS_TUPLE_COUNT 5
#define HDR_PLUS_PERF_TIME_OUT (7000) // milliseconds
#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 )
#define TIMEOUT_NEVER -1
cam_capability_t *gCamCapability[MM_CAMERA_MAX_NUM_SENSORS];
const camera_metadata_t *gStaticMetadata[MM_CAMERA_MAX_NUM_SENSORS];
static pthread_mutex_t gCamLock = PTHREAD_MUTEX_INITIALIZER;
volatile uint32_t gCamHal3LogLevel = 1;
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,
320, 240,
432, 288,
480, 288,
512, 288,
512, 384};
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 },
};
/* 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},
};
/*===========================================================================
* 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),
mCameraOpened(false),
mCameraInitialized(false),
mCallbackOps(NULL),
mMetadataChannel(NULL),
mPictureChannel(NULL),
mRawChannel(NULL),
mSupportChannel(NULL),
mAnalysisChannel(NULL),
mRawDumpChannel(NULL),
mDummyBatchChannel(NULL),
mChannelHandle(0),
mFirstRequest(false),
mFirstConfiguration(true),
mFlush(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),
mHybridAeEnable(0),
mBatchSize(0),
mToBeQueuedVidBufs(0),
mHFRVideoFps(DEFAULT_VIDEO_FPS),
mOpMode(CAMERA3_STREAM_CONFIGURATION_NORMAL_MODE),
mFirstFrameNumberInBatch(0),
mNeedSensorRestart(false),
mLdafCalibExist(false),
mPowerHintEnabled(false),
mLastCustIntentFrmNum(-1)
{
getLogLevel();
m_perfLock.lock_init();
mCameraDevice.common.tag = HARDWARE_DEVICE_TAG;
mCameraDevice.common.version = CAMERA_DEVICE_API_VERSION_3_3;
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(&mRequestCond);
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)
CDBG("%s: Raw dump from Camera HAL enabled", __func__);
memset(&mInputStreamInfo, 0, sizeof(mInputStreamInfo));
memset(mLdafCalib, 0, sizeof(mLdafCalib));
memset(prop, 0, sizeof(prop));
property_get("persist.camera.tnr.preview", prop, "1");
m_bTnrPreview = (uint8_t)atoi(prop);
memset(prop, 0, sizeof(prop));
property_get("persist.camera.tnr.video", prop, "1");
m_bTnrVideo = (uint8_t)atoi(prop);
mPendingBuffersMap.num_buffers = 0;
mPendingBuffersMap.last_frame_number = -1;
}
/*===========================================================================
* FUNCTION : ~QCamera3HardwareInterface
*
* DESCRIPTION: destructor of QCamera3HardwareInterface
*
* PARAMETERS : none
*
* RETURN : none
*==========================================================================*/
QCamera3HardwareInterface::~QCamera3HardwareInterface()
{
CDBG("%s: E", __func__);
bool hasPendingBuffers = (mPendingBuffersMap.num_buffers > 0);
/* 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);
ALOGI("%s: stopping channel %d", __func__, 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){
clear_metadata_buffer(mParameters);
// Check if there is still pending buffer not yet returned.
if (hasPendingBuffers) {
for (auto& pendingBuffer : mPendingBuffersMap.mPendingBufferList) {
ALOGE("%s: Buffer not yet returned for stream. Frame number %d, format 0x%x, width %d, height %d",
__func__, pendingBuffer.frame_number, pendingBuffer.stream->format, pendingBuffer.stream->width,
pendingBuffer.stream->height);
}
ALOGE("%s: Last requested frame number is %d", __func__, mPendingBuffersMap.last_frame_number);
uint8_t restart = TRUE;
ADD_SET_PARAM_ENTRY_TO_BATCH(mParameters, CAM_INTF_META_DAEMON_RESTART,
restart);
}
//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) {
ALOGE("%s: set_parms failed for unconfigure", __func__);
}
}
deinitParameters();
}
if (mChannelHandle) {
mCameraHandle->ops->delete_channel(mCameraHandle->camera_handle,
mChannelHandle);
ALOGE("%s: deleting channel %d", __func__, mChannelHandle);
mChannelHandle = 0;
}
if (mCameraOpened)
closeCamera();
mPendingBuffersMap.mPendingBufferList.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_mutex_destroy(&mMutex);
if (hasPendingBuffers) {
ALOGE("%s: Not all buffers were returned. Notified the camera daemon process to restart."
" Exiting here...", __func__);
exit(EXIT_FAILURE);
}
CDBG("%s: X", __func__);
}
/*===========================================================================
* 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:
ALOGE("%s: Fatal, camera daemon died", __func__);
//close the camera backend
if (obj->mCameraHandle && obj->mCameraHandle->camera_handle
&& obj->mCameraHandle->ops) {
obj->mCameraHandle->ops->error_close_camera(obj->mCameraHandle->camera_handle);
} else {
ALOGE("%s: Could not close camera on error because the handle or ops is NULL",
__func__);
}
camera3_notify_msg_t notify_msg;
memset(&notify_msg, 0, sizeof(camera3_notify_msg_t));
notify_msg.type = CAMERA3_MSG_ERROR;
notify_msg.message.error.error_code = CAMERA3_MSG_ERROR_DEVICE;
notify_msg.message.error.error_stream = NULL;
notify_msg.message.error.frame_number = 0;
obj->mCallbackOps->notify(obj->mCallbackOps, &notify_msg);
break;
case CAM_EVENT_TYPE_DAEMON_PULL_REQ:
CDBG("%s: HAL got request pull from Daemon", __func__);
pthread_mutex_lock(&obj->mMutex);
obj->mWokenUpByDaemon = true;
obj->unblockRequestIfNecessary();
pthread_mutex_unlock(&obj->mMutex);
break;
default:
CDBG_HIGH("%s: Warning: Unhandled event %d", __func__,
evt->server_event_type);
break;
}
} else {
ALOGE("%s: NULL user_data/evt", __func__);
}
}
/*===========================================================================
* 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 (mCameraOpened) {
*hw_device = NULL;
return PERMISSION_DENIED;
}
m_perfLock.lock_acq();
rc = openCamera();
if (rc == 0) {
*hw_device = &mCameraDevice.common;
} else
*hw_device = NULL;
m_perfLock.lock_rel();
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;
ATRACE_CALL();
if (mCameraHandle) {
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;
}
mCameraOpened = true;
rc = mCameraHandle->ops->register_event_notify(mCameraHandle->camera_handle,
camEvtHandle, (void *)this);
if (rc < 0) {
ALOGE("%s: Error, failed to register event callback", __func__);
/* Not closing camera here since it is already handled in destructor */
return FAILED_TRANSACTION;
}
mFirstConfiguration = true;
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()
{
ATRACE_CALL();
int rc = NO_ERROR;
rc = mCameraHandle->ops->close_camera(mCameraHandle->camera_handle);
mCameraHandle = NULL;
mCameraOpened = false;
if (QCameraFlash::getInstance().releaseFlashFromCamera(mCameraId) != 0) {
CDBG("%s: Failed to release flash for camera id: %d",
__func__,
mCameraId);
}
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;
pthread_mutex_lock(&mMutex);
rc = initParameters();
if (rc < 0) {
ALOGE("%s: initParamters failed %d", __func__, rc);
goto err1;
}
mCallbackOps = callback_ops;
mChannelHandle = mCameraHandle->ops->add_channel(
mCameraHandle->camera_handle, NULL, NULL, this);
if (mChannelHandle == 0) {
ALOGE("%s: add_channel failed", __func__);
rc = -ENOMEM;
pthread_mutex_unlock(&mMutex);
return rc;
}
pthread_mutex_unlock(&mMutex);
mCameraInitialized = true;
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;
int32_t available_processed_sizes[MAX_SIZES_CNT * 2];
int32_t available_jpeg_sizes[MAX_SIZES_CNT * 2];
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) {
ALOGE("%s: Error, Multiple input streams requested", __func__);
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;
size_t jpeg_sizes_cnt = 0;
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);
/* Generate JPEG sizes table */
makeTable(gCamCapability[mCameraId]->picture_sizes_tbl,
count,
MAX_SIZES_CNT,
available_processed_sizes);
jpeg_sizes_cnt = filterJpegSizes(
available_jpeg_sizes,
available_processed_sizes,
count * 2,
MAX_SIZES_CNT * 2,
gCamCapability[mCameraId]->active_array_size,
gCamCapability[mCameraId]->max_downscale_factor);
/* Verify set size against generated sizes table */
for (size_t i = 0; i < (jpeg_sizes_cnt / 2); i++) {
if (((int32_t)rotatedWidth == available_jpeg_sizes[i*2]) &&
((int32_t)rotatedHeight == available_jpeg_sizes[i*2+1])) {
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) {
ALOGE("%s: Error: Unsupported size of %d x %d requested for stream"
"type:%d", __func__, rotatedWidth, rotatedHeight,
newStream->format);
ALOGE("%s: Active array size is %d x %d", __func__,
gCamCapability[mCameraId]->active_array_size.width,
gCamCapability[mCameraId]->active_array_size.height);
rc = -EINVAL;
break;
}
} /* End of for each stream */
return rc;
}
/*===========================================================================
* FUNCTION : validateUsageFlags
*
* DESCRIPTION: Check if the configuration usage flags are supported
*
* PARAMETERS :
* @stream_list : streams to be configured
*
* RETURN :
* NO_ERROR if the usage flags are supported
* error code if usage flags are not supported
*
*==========================================================================*/
int QCamera3HardwareInterface::validateUsageFlags(
const camera3_stream_configuration_t* streamList)
{
for (size_t j = 0; j < streamList->num_streams; j++) {
const camera3_stream_t *newStream = streamList->streams[j];
if (newStream->format != HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED ||
(newStream->stream_type != CAMERA3_STREAM_OUTPUT &&
newStream->stream_type != CAMERA3_STREAM_BIDIRECTIONAL)) {
continue;
}
bool isVideo = IS_USAGE_VIDEO(newStream->usage);
bool isPreview = IS_USAGE_PREVIEW(newStream->usage);
bool isZSL = IS_USAGE_ZSL(newStream->usage);
// Color space for this camera device is guaranteed to be ITU_R_601_FR.
// So color spaces will always match.
// Check whether underlying formats of shared streams match.
if (isVideo && isPreview) {
ALOGE("Combined video and preview usage flag is not supported");
return -EINVAL;
}
if (isPreview && isZSL) {
ALOGE("Combined preview and zsl usage flag is not supported");
return -EINVAL;
}
if (isVideo && isZSL) {
ALOGE("Combined video and zsl usage flag is not supported");
return -EINVAL;
}
}
return NO_ERROR;
}
/*==============================================================================
* 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) {
ALOGE("%s:Failed to update table for CAM_INTF_PARM_MAX_DIMENSION", __func__);
return rc;
}
rc = mCameraHandle->ops->set_parms(mCameraHandle->camera_handle, mParameters);
if (rc != NO_ERROR) {
ALOGE("%s: Failed to set CAM_INTF_PARM_MAX_DIMENSION", __func__);
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) {
ALOGE("%s: Failed to get CAM_INTF_PARM_RAW_DIMENSION", __func__);
return rc;
}
READ_PARAM_ENTRY(mParameters, CAM_INTF_PARM_RAW_DIMENSION, sensor_dim);
ALOGI("%s: sensor output dimension = %d x %d", __func__, 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, 1);
mPowerHintEnabled = true;
}
}
/*==============================================================================
* FUNCTION : disablePowerHint
*
* DESCRIPTION: disable current powerhint.
*
* PARAMETERS :
*
* RETURN : NULL
*
*==========================================================================*/
void QCamera3HardwareInterface::disablePowerHint()
{
if (mPowerHintEnabled) {
m_perfLock.powerHint(POWER_HINT_VIDEO_ENCODE, 0);
mPowerHintEnabled = false;
}
}
/*===========================================================================
* 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) {
ALOGE("%s: NULL stream configuration", __func__);
return BAD_VALUE;
}
if (streamList->streams == NULL) {
ALOGE("%s: NULL stream list", __func__);
return BAD_VALUE;
}
if (streamList->num_streams < 1) {
ALOGE("%s: Bad number of streams requested: %d", __func__,
streamList->num_streams);
return BAD_VALUE;
}
if (streamList->num_streams >= MAX_NUM_STREAMS) {
ALOGE("%s: Maximum number of streams %d exceeded: %d", __func__,
MAX_NUM_STREAMS, streamList->num_streams);
return BAD_VALUE;
}
rc = validateUsageFlags(streamList);
if (rc != NO_ERROR) {
return rc;
}
mOpMode = streamList->operation_mode;
CDBG("%s: mOpMode: %d", __func__, 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);
ALOGI("%s: stopping channel %d", __func__, mChannelHandle);
}
pthread_mutex_lock(&mMutex);
/* 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;
uint32_t commonFeatureMask = 0;
maxViewfinderSize = gCamCapability[mCameraId]->max_viewfinder_size;
camera3_stream_t *inputStream = NULL;
bool isJpeg = false;
cam_dimension_t jpegSize = {0, 0};
/*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;
int32_t hal_version = CAM_HAL_V3;
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];
ALOGI("%s: stream[%d] type = %d, format = %d, width = %d, "
"height = %d, rotation = %d, usage = 0x%x",
__func__, 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)) {
commonFeatureMask |= CAM_QCOM_FEATURE_NONE;
numStreamsOnEncoder++;
bJpegOnEncoder = 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_NONE;
} else {
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;
} else {
commonFeatureMask |= CAM_QCOM_FEATURE_NONE;
}
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) {
ALOGE("%s: Invalid stream configu: stall: %d, raw: %d, processed %d",
__func__, stallStreamCnt, rawStreamCnt, processedStreamCnt);
pthread_mutex_unlock(&mMutex);
return -EINVAL;
}
/* Check whether we have zsl stream or 4k video case */
if (isZsl && m_bIsVideo) {
ALOGE("%s: Currently invalid configuration ZSL&Video!", __func__);
pthread_mutex_unlock(&mMutex);
return -EINVAL;
}
/* Check if stream sizes are sane */
if (numStreamsOnEncoder > 2) {
ALOGE("%s: Number of streams on ISP encoder path exceeds limits of 2",
__func__);
pthread_mutex_unlock(&mMutex);
return -EINVAL;
} else if (1 < numStreamsOnEncoder){
bUseCommonFeatureMask = true;
CDBG_HIGH("%s: Multiple streams above max viewfinder size, common mask needed",
__func__);
}
/* Check if BLOB size is greater than 4k in 4k recording case */
if (m_bIs4KVideo && bJpegExceeds4K) {
ALOGE("%s: HAL doesn't support Blob size greater than 4k in 4k recording",
__func__);
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;
}
rc = validateStreamDimensions(streamList);
if (rc == NO_ERROR) {
rc = validateStreamRotations(streamList);
}
if (rc != NO_ERROR) {
ALOGE("%s: Invalid stream configuration requested!", __func__);
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];
CDBG_HIGH("%s: newStream type = %d, stream format = %d "
"stream size : %d x %d, stream rotation = %d",
__func__, 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) {
ALOGE("%s: Could not allocate stream info", __func__);
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) {
ALOGE("%s: Multiple input/reprocess streams requested!", __func__);
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
*/
CDBG_HIGH("%s: Warning, Multiple ip/reprocess streams requested!", __func__);
}
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;
CDBG("%s: Input stream configured! %d x %d, format %d, usage %d",
__func__, 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
mMetadataChannel = new QCamera3MetadataChannel(mCameraHandle->camera_handle,
mChannelHandle, mCameraHandle->ops, captureResultCb,
&gCamCapability[mCameraId]->padding_info, CAM_QCOM_FEATURE_NONE, this);
if (mMetadataChannel == NULL) {
ALOGE("%s: failed to allocate metadata channel", __func__);
rc = -ENOMEM;
pthread_mutex_unlock(&mMutex);
return rc;
}
rc = mMetadataChannel->initialize(IS_TYPE_NONE);
if (rc < 0) {
ALOGE("%s: metadata channel initialization failed", __func__);
delete mMetadataChannel;
mMetadataChannel = NULL;
pthread_mutex_unlock(&mMutex);
return rc;
}
// Create analysis stream all the time, even when h/w support is not available
{
mAnalysisChannel = new QCamera3SupportChannel(
mCameraHandle->camera_handle,
mChannelHandle,
mCameraHandle->ops,
&gCamCapability[mCameraId]->padding_info,
CAM_QCOM_FEATURE_PP_SUPERSET_HAL3,
CAM_STREAM_TYPE_ANALYSIS,
&gCamCapability[mCameraId]->analysis_recommended_res,
gCamCapability[mCameraId]->analysis_recommended_format,
this,
0); // force buffer count to 0
if (!mAnalysisChannel) {
ALOGE("%s: H/W Analysis channel cannot be created", __func__);
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) {
CDBG_HIGH("%s: Input stream configured, reprocess config", __func__);
} 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;
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;
}
} 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;
}
}
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;
if (m_bIs4KVideo && !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 {
ALOGE("%s: Error, No ZSL stream identified",__func__);
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;
isRawStreamRequested = true;
break;
default:
mStreamConfigInfo.type[mStreamConfigInfo.num_streams] = CAM_STREAM_TYPE_DEFAULT;
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams] = CAM_QCOM_FEATURE_NONE;
break;
}
}
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))
CDBG("%s: ZSL usage flag skipping", __func__);
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:
ALOGE("%s: Invalid stream_type %d", __func__, 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,
&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) {
ALOGE("%s: allocation of channel failed", __func__);
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;
ALOGI("%s: num video buffers in HFR mode: %d",
__func__, 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,
&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) {
ALOGE("%s: allocation of channel failed", __func__);
pthread_mutex_unlock(&mMutex);
return -ENOMEM;
}
newStream->max_buffers = channel->getNumBuffers();
newStream->priv = channel;
}
break;
case HAL_PIXEL_FORMAT_YCbCr_420_888: {
channel = new QCamera3YUVChannel(mCameraHandle->camera_handle,
mChannelHandle,
mCameraHandle->ops, captureResultCb,
&gCamCapability[mCameraId]->padding_info,
this,
newStream,
(cam_stream_type_t)
mStreamConfigInfo.type[mStreamConfigInfo.num_streams],
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams],
mMetadataChannel);
if (channel == NULL) {
ALOGE("%s: allocation of YUV channel failed", __func__);
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,
&gCamCapability[mCameraId]->padding_info,
this, newStream, CAM_QCOM_FEATURE_NONE,
mMetadataChannel,
(newStream->format == HAL_PIXEL_FORMAT_RAW16));
if (mRawChannel == NULL) {
ALOGE("%s: allocation of raw channel failed", __func__);
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,
&gCamCapability[mCameraId]->padding_info, this, newStream,
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams],
m_bIs4KVideo, isZsl, mMetadataChannel,
(m_bIsVideo ? 1 : MAX_INFLIGHT_BLOB));
if (mPictureChannel == NULL) {
ALOGE("%s: allocation of channel failed", __func__);
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:
ALOGE("%s: not a supported format 0x%x", __func__, newStream->format);
pthread_mutex_unlock(&mMutex);
return -EINVAL;
}
} else if (newStream->stream_type == CAMERA3_STREAM_INPUT) {
newStream->max_buffers = MAX_INFLIGHT_REPROCESS_REQUESTS;
} else {
ALOGE("%s: Error, Unknown stream type", __func__);
pthread_mutex_unlock(&mMutex);
return -EINVAL;
}
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
}
/* 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);
mRawDumpChannel = new QCamera3RawDumpChannel(mCameraHandle->camera_handle,
mChannelHandle,
mCameraHandle->ops,
rawDumpSize,
&gCamCapability[mCameraId]->padding_info,
this, CAM_QCOM_FEATURE_NONE);
if (!mRawDumpChannel) {
ALOGE("%s: Raw Dump channel cannot be created", __func__);
pthread_mutex_unlock(&mMutex);
return -ENOMEM;
}
}
if (mAnalysisChannel) {
mStreamConfigInfo.stream_sizes[mStreamConfigInfo.num_streams] =
gCamCapability[mCameraId]->analysis_recommended_res;
mStreamConfigInfo.type[mStreamConfigInfo.num_streams] =
CAM_STREAM_TYPE_ANALYSIS;
mStreamConfigInfo.postprocess_mask[mStreamConfigInfo.num_streams] =
CAM_QCOM_FEATURE_PP_SUPERSET_HAL3;
mStreamConfigInfo.num_streams++;
}
if (isSupportChannelNeeded(streamList, mStreamConfigInfo)) {
mSupportChannel = new QCamera3SupportChannel(
mCameraHandle->camera_handle,
mChannelHandle,
mCameraHandle->ops,
&gCamCapability[mCameraId]->padding_info,
CAM_QCOM_FEATURE_PP_SUPERSET_HAL3,
CAM_STREAM_TYPE_CALLBACK,
&QCamera3SupportChannel::kDim,
CAM_FORMAT_YUV_420_NV21,
this);
if (!mSupportChannel) {
ALOGE("%s: dummy channel cannot be created", __func__);
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;
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;
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) {
mDummyBatchChannel = new QCamera3RegularChannel(mCameraHandle->camera_handle,
mChannelHandle,
mCameraHandle->ops, captureResultCb,
&gCamCapability[mCameraId]->padding_info,
this,
&mDummyBatchStream,
CAM_STREAM_TYPE_VIDEO,
CAM_QCOM_FEATURE_PP_SUPERSET_HAL3,
mMetadataChannel);
if (NULL == mDummyBatchChannel) {
ALOGE("%s: creation of mDummyBatchChannel failed."
"Preview will use non-hfr sensor mode ", __func__);
}
}
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;
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 mPendnigBuffersMap */
for (pendingRequestIterator i = mPendingRequestsList.begin();
i != mPendingRequestsList.end();) {
i = erasePendingRequest(i);
}
mPendingFrameDropList.clear();
// Initialize/Reset the pending buffers list
mPendingBuffersMap.num_buffers = 0;
mPendingBuffersMap.mPendingBufferList.clear();
mPendingReprocessResultList.clear();
mFirstRequest = true;
mCurJpegMeta.clear();
//Get min frame duration for this streams configuration
deriveMinFrameDuration();
/* Turn on video hint only if video stream is 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) {
ALOGE("%s: NULL capture request", __func__);
return BAD_VALUE;
}
if (request->settings == NULL && mFirstRequest) {
/*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) {
ALOGE("%s: Request %d: No output buffers provided!",
__FUNCTION__, frameNumber);
return BAD_VALUE;
}
if (request->num_output_buffers >= MAX_NUM_STREAMS) {
ALOGE("%s: Number of buffers %d equals or is greater than maximum number of streams %d!",
__func__, 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) {
ALOGE("%s: Request %d: Buffer %ld: Status not OK!",
__func__, frameNumber, (long)idx);
return BAD_VALUE;
}
if (b->release_fence != -1) {
ALOGE("%s: Request %d: Buffer %ld: Has a release fence!",
__func__, frameNumber, (long)idx);
return BAD_VALUE;
}
if (b->buffer == NULL) {
ALOGE("%s: Request %d: Buffer %ld: NULL buffer handle!",
__func__, 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) {
ALOGE("%s: Request %d: Buffer %ld: Unconfigured stream!",
__func__, frameNumber, (long)idx);
return BAD_VALUE;
}
if (b->status != CAMERA3_BUFFER_STATUS_OK) {
ALOGE("%s: Request %d: Buffer %ld: Status not OK!",
__func__, frameNumber, (long)idx);
return BAD_VALUE;
}
if (b->release_fence != -1) {
ALOGE("%s: Request %d: Buffer %ld: Has a release fence!",
__func__, frameNumber, (long)idx);
return BAD_VALUE;
}
if (b->buffer == NULL) {
ALOGE("%s: Request %d: Buffer %ld: NULL buffer handle!",
__func__, frameNumber, (long)idx);
return BAD_VALUE;
}
if (*(b->buffer) == NULL) {
ALOGE("%s: Request %d: Buffer %ld: NULL private handle!",
__func__, 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 : 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);
CDBG("%s: Delayed reprocess notify %d", __func__,
frame_number);
for (pendingRequestIterator k = mPendingRequestsList.begin();
k != mPendingRequestsList.end(); k++) {
if (k->frame_number == j->frame_number) {
CDBG("%s: Found reprocess frame number %d in pending reprocess List "
"Take it out!!", __func__,
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) {
ALOGE("%s: metadata_buf is NULL", __func__);
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 =
POINTER_OF_META(CAM_INTF_META_FRAME_NUMBER, metadata);
int64_t *p_capture_time =
POINTER_OF_META(CAM_INTF_META_SENSOR_TIMESTAMP, metadata);
int32_t *p_urgent_frame_number_valid =
POINTER_OF_META(CAM_INTF_META_URGENT_FRAME_NUMBER_VALID, metadata);
uint32_t *p_urgent_frame_number =
POINTER_OF_META(CAM_INTF_META_URGENT_FRAME_NUMBER, metadata);
if ((NULL == p_frame_number_valid) || (NULL == p_frame_number) ||
(NULL == p_capture_time) || (NULL == p_urgent_frame_number_valid) ||
(NULL == p_urgent_frame_number)) {
ALOGE("%s: Invalid metadata", __func__);
invalid_metadata = true;
} else {
frame_number_valid = *p_frame_number_valid;
last_frame_number = *p_frame_number;
last_frame_capture_time = *p_capture_time;
urgent_frame_number_valid = *p_urgent_frame_number_valid;
last_urgent_frame_number = *p_urgent_frame_number;
}
/* In batchmode, when no video buffers are requested, set_parms are sent
* for every capture_request. The difference between consecutive urgent
* frame numbers and frame numbers should be used to interpolate the
* corresponding frame numbers and time stamps */
pthread_mutex_lock(&mMutex);
if (urgent_frame_number_valid) {
first_urgent_frame_number =
mPendingBatchMap.valueFor(last_urgent_frame_number);
urgentFrameNumDiff = last_urgent_frame_number + 1 -
first_urgent_frame_number;
CDBG_HIGH("%s: urgent_frm: valid: %d frm_num: %d - %d",
__func__, urgent_frame_number_valid,
first_urgent_frame_number, last_urgent_frame_number);
}
if (frame_number_valid) {
first_frame_number = mPendingBatchMap.valueFor(last_frame_number);
frameNumDiff = last_frame_number + 1 -
first_frame_number;
mPendingBatchMap.removeItem(last_frame_number);
CDBG_HIGH("%s: frm: valid: %d frm_num: %d - %d",
__func__, frame_number_valid,
first_frame_number, last_frame_number);
}
pthread_mutex_unlock(&mMutex);
if (urgent_frame_number_valid || frame_number_valid) {
loopCount = MAX(urgentFrameNumDiff, frameNumDiff);
if (urgentFrameNumDiff > MAX_HFR_BATCH_SIZE)
ALOGE("%s: urgentFrameNumDiff: %d urgentFrameNum: %d",
__func__, urgentFrameNumDiff, last_urgent_frame_number);
if (frameNumDiff > MAX_HFR_BATCH_SIZE)
ALOGE("%s: frameNumDiff: %d frameNum: %d",
__func__, frameNumDiff, last_frame_number);
}
for (size_t i = 0; i < loopCount; i++) {
/* handleMetadataWithLock is called even for invalid_metadata for
* pipeline depth calculation */
if (!invalid_metadata) {
/* Infer frame number. Batch metadata contains frame number of the
* last frame */
if (urgent_frame_number_valid) {
if (i < urgentFrameNumDiff) {
urgent_frame_number =
first_urgent_frame_number + i;
CDBG("%s: inferred urgent frame_number: %d",
__func__, urgent_frame_number);
ADD_SET_PARAM_ENTRY_TO_BATCH(metadata,
CAM_INTF_META_URGENT_FRAME_NUMBER, urgent_frame_number);
} else {
/* This is to handle when urgentFrameNumDiff < frameNumDiff */
ADD_SET_PARAM_ENTRY_TO_BATCH(metadata,
CAM_INTF_META_URGENT_FRAME_NUMBER_VALID, 0);
}
}
/* Infer frame number. Batch metadata contains frame number of the
* last frame */
if (frame_number_valid) {
if (i < frameNumDiff) {
frame_number = first_frame_number + i;
CDBG("%s: inferred frame_number: %d", __func__, frame_number);
ADD_SET_PARAM_ENTRY_TO_BATCH(metadata,
CAM_INTF_META_FRAME_NUMBER, frame_number);
} else {
/* This is to handle when urgentFrameNumDiff > frameNumDiff */
ADD_SET_PARAM_ENTRY_TO_BATCH(metadata,
CAM_INTF_META_FRAME_NUMBER_VALID, 0);
}
}
if (last_frame_capture_time) {
//Infer timestamp
first_frame_capture_time = last_frame_capture_time -
(((loopCount - 1) * NSEC_PER_SEC) / (double) mHFRVideoFps);
capture_time =
first_frame_capture_time + (i * NSEC_PER_SEC / (double) mHFRVideoFps);
ADD_SET_PARAM_ENTRY_TO_BATCH(metadata,
CAM_INTF_META_SENSOR_TIMESTAMP, capture_time);
CDBG_HIGH("%s: batch capture_time: %lld, capture_time: %lld",
__func__, last_frame_capture_time, capture_time);
}
}
pthread_mutex_lock(&mMutex);
handleMetadataWithLock(metadata_buf,
false /* free_and_bufdone_meta_buf */,
(i == urgentFrameNumDiff-1), /* last urgent metadata in the batch */
(i == frameNumDiff-1) /* last metadata in the batch metadata */);
pthread_mutex_unlock(&mMutex);
}
done_batch_metadata:
/* BufDone metadata buffer */
if (free_and_bufdone_meta_buf) {
mMetadataChannel->bufDone(metadata_buf);
free(metadata_buf);
}
}
/*===========================================================================
* FUNCTION : handleMetadataWithLock
*
* DESCRIPTION: Handles metadata buffer callback with mMutex lock held.
*
* PARAMETERS : @metadata_buf: metadata buffer
* @free_and_bufdone_meta_buf: Buf done on the meta buf and free
* the meta buf in this method
* @lastUrgentMetadataInBatch: Boolean to indicate whether this is the
* last urgent metadata in a batch. Always true for non-batch mode
* @lastMetadataInBatch: Boolean to indicate whether this is the
* last metadata in a batch. Always true for non-batch mode
*
* RETURN :
*
*==========================================================================*/
void QCamera3HardwareInterface::handleMetadataWithLock(
mm_camera_super_buf_t *metadata_buf, bool free_and_bufdone_meta_buf,
bool lastUrgentMetadataInBatch, bool lastMetadataInBatch)
{
ATRACE_CALL();
metadata_buffer_t *metadata = (metadata_buffer_t *)metadata_buf->bufs[0]->buffer;
int32_t frame_number_valid, urgent_frame_number_valid;
uint32_t frame_number, urgent_frame_number;
int64_t capture_time;
bool unfinished_raw_request = false;
int32_t *p_frame_number_valid =
POINTER_OF_META(CAM_INTF_META_FRAME_NUMBER_VALID, metadata);
uint32_t *p_frame_number = POINTER_OF_META(CAM_INTF_META_FRAME_NUMBER, metadata);
int64_t *p_capture_time = POINTER_OF_META(CAM_INTF_META_SENSOR_TIMESTAMP, metadata);
int32_t *p_urgent_frame_number_valid =
POINTER_OF_META(CAM_INTF_META_URGENT_FRAME_NUMBER_VALID, metadata);
uint32_t *p_urgent_frame_number =
POINTER_OF_META(CAM_INTF_META_URGENT_FRAME_NUMBER, metadata);
IF_META_AVAILABLE(cam_frame_dropped_t, p_cam_frame_drop, CAM_INTF_META_FRAME_DROPPED,
metadata) {
ALOGE("%s: Dropped frame info for frame_number_valid %d, frame_number %d",
__func__, *p_frame_number_valid, *p_frame_number);
}
if ((NULL == p_frame_number_valid) || (NULL == p_frame_number) || (NULL == p_capture_time) ||
(NULL == p_urgent_frame_number_valid) || (NULL == p_urgent_frame_number)) {
ALOGE("%s: Invalid metadata", __func__);
if (free_and_bufdone_meta_buf) {
mMetadataChannel->bufDone(metadata_buf);
free(metadata_buf);
}
goto done_metadata;
} else {
frame_number_valid = *p_frame_number_valid;
frame_number = *p_frame_number;
capture_time = *p_capture_time;
urgent_frame_number_valid = *p_urgent_frame_number_valid;
urgent_frame_number = *p_urgent_frame_number;
}
//Partial result on process_capture_result for timestamp
if (urgent_frame_number_valid) {
CDBG("%s: valid urgent frame_number = %u, capture_time = %lld",
__func__, urgent_frame_number, capture_time);
//Recieved an urgent Frame Number, handle it
//using partial results
for (pendingRequestIterator i =
mPendingRequestsList.begin(); i != mPendingRequestsList.end(); i++) {
CDBG("%s: Iterator Frame = %d urgent frame = %d",
__func__, i->frame_number, urgent_frame_number);
if ((!i->input_buffer) && (i->frame_number < urgent_frame_number) &&
(i->partial_result_cnt == 0)) {
ALOGE("%s: Error: HAL missed urgent metadata for frame number %d",
__func__, i->frame_number);
i->partial_result_cnt++;
}
if (i->frame_number == urgent_frame_number &&
i->bUrgentReceived == 0) {
camera3_capture_result_t result;
memset(&result, 0, sizeof(camera3_capture_result_t));
i->partial_result_cnt++;
i->bUrgentReceived = 1;
// Extract 3A metadata
result.result = translateCbUrgentMetadataToResultMetadata(
metadata, lastUrgentMetadataInBatch);
// Populate metadata result
result.frame_number = urgent_frame_number;
result.num_output_buffers = 0;
result.output_buffers = NULL;
result.partial_result = i->partial_result_cnt;
mCallbackOps->process_capture_result(mCallbackOps, &result);
CDBG("%s: urgent frame_number = %u, capture_time = %lld",
__func__, result.frame_number, capture_time);
free_camera_metadata((camera_metadata_t *)result.result);
break;
}
}
}
if (!frame_number_valid) {
CDBG("%s: Not a valid normal frame number, used as SOF only", __func__);
if (free_and_bufdone_meta_buf) {
mMetadataChannel->bufDone(metadata_buf);
free(metadata_buf);
}
goto done_metadata;
}
CDBG_HIGH("%s: valid frame_number = %u, capture_time = %lld", __func__,
frame_number, capture_time);
for (pendingRequestIterator i = mPendingRequestsList.begin();
i != mPendingRequestsList.end() && i->frame_number <= frame_number;) {
// Flush out all entries with less or equal frame numbers.
camera3_capture_result_t result;
memset(&result, 0, sizeof(camera3_capture_result_t));
CDBG("%s: frame_number in the list is %u", __func__, i->frame_number);
// Check whether any stream buffer corresponding to this is dropped or not
// If dropped, then send the ERROR_BUFFER for the corresponding stream
// The API does not expect a blob buffer to be dropped
if (p_cam_frame_drop && p_cam_frame_drop->frame_dropped) {
/* Clear notify_msg structure */
camera3_notify_msg_t notify_msg;
memset(&notify_msg, 0, sizeof(camera3_notify_msg_t));
for (List<RequestedBufferInfo>::iterator j = i->buffers.begin();
j != i->buffers.end(); j++) {
QCamera3ProcessingChannel *channel = (QCamera3ProcessingChannel *)j->stream->priv;
uint32_t streamID = channel->getStreamID(channel->getStreamTypeMask());
for (uint32_t k = 0; k < p_cam_frame_drop->cam_stream_ID.num_streams; k++) {
if (streamID == p_cam_frame_drop->cam_stream_ID.streamID[k]) {
// Send Error notify to frameworks with CAMERA3_MSG_ERROR_BUFFER
ALOGW("%s: Start of reporting error frame#=%u, streamID=%u streamFormat=%d",
__func__, i->frame_number, streamID, j->stream->format);
notify_msg.type = CAMERA3_MSG_ERROR;
notify_msg.message.error.frame_number = i->frame_number;
notify_msg.message.error.error_code = CAMERA3_MSG_ERROR_BUFFER ;
notify_msg.message.error.error_stream = j->stream;
mCallbackOps->notify(mCallbackOps, &notify_msg);
ALOGW("%s: End of reporting error frame#=%u, streamID=%u streamFormat=%d",
__func__, i->frame_number, streamID, j->stream->format);
PendingFrameDropInfo PendingFrameDrop;
PendingFrameDrop.frame_number=i->frame_number;
PendingFrameDrop.stream_ID = streamID;
// Add the Frame drop info to mPendingFrameDropList
mPendingFrameDropList.push_back(PendingFrameDrop);
}
}
}
}
// Send empty metadata with already filled buffers for dropped metadata
// and send valid metadata with already filled buffers for current metadata
/* we could hit this case when we either
* 1. have a pending reprocess request or
* 2. miss a metadata buffer callback */
if (i->frame_number < frame_number) {
if (i->input_buffer) {
/* this will be handled in handleInputBufferWithLock */
i++;
continue;
} else if (i->need_dynamic_blklvl) {
unfinished_raw_request = true;
// i->partial_result_cnt--;
CDBG("%s, frame number:%d, partial_result:%d, unfinished raw request..",
__func__, i->frame_number, i->partial_result_cnt);
i++;
continue;
} else if (i->pending_extra_result) {
CDBG("%s, frame_number:%d, partial_result:%d, need_dynamic_blklvl:%d",
__func__, i->frame_number, i->partial_result_cnt,
i->need_dynamic_blklvl);
// i->partial_result_cnt--;
i++;
continue;
} else {
ALOGE("%s: Missing metadata buffer for frame number %d, reporting CAMERA3_MSG_ERROR_RESULT",
__func__, i->frame_number);
CameraMetadata dummyMetadata;
dummyMetadata.update(ANDROID_REQUEST_ID, &(i->request_id), 1);
result.result = dummyMetadata.release();
camera3_notify_msg_t notify_msg;
memset(&notify_msg, 0, sizeof(notify_msg));
notify_msg.type = CAMERA3_MSG_ERROR;
notify_msg.message.error.error_code = CAMERA3_MSG_ERROR_RESULT;
notify_msg.message.error.error_stream = NULL;
notify_msg.message.error.frame_number = i->frame_number;
mCallbackOps->notify(mCallbackOps, &notify_msg);
// partial_result should be PARTIAL_RESULT_CNT in case of
// ERROR_RESULT.
i->partial_result_cnt = PARTIAL_RESULT_COUNT;
result.partial_result = PARTIAL_RESULT_COUNT;
}
} else {
i->partial_result_cnt++;
CDBG("%s, frame_number:%d, need_dynamic_blklvl:%d, partial cnt:%d\n",
__func__, i->frame_number, i->need_dynamic_blklvl,
i->partial_result_cnt);
if (!i->need_dynamic_blklvl) {
CDBG("%s, meta for request without raw, frame number: %d\n",
__func__, i->frame_number);
if (!unfinished_raw_request) {
i->partial_result_cnt++;
CDBG("%s, no raw request pending, send the final (cnt:%d) partial result",
__func__, i->partial_result_cnt);
}
}
result.partial_result = i->partial_result_cnt;
/* Clear notify_msg structure */
camera3_notify_msg_t notify_msg;
memset(&notify_msg, 0, sizeof(camera3_notify_msg_t));
// Send shutter notify to frameworks
notify_msg.type = CAMERA3_MSG_SHUTTER;
notify_msg.message.shutter.frame_number = i->frame_number;
notify_msg.message.shutter.timestamp = (uint64_t)capture_time;
mCallbackOps->notify(mCallbackOps, &notify_msg);
i->timestamp = capture_time;
// Find channel requiring metadata, meaning internal offline postprocess
// is needed.
//TODO: for now, we don't support two streams requiring metadata at the same time.
// (because we are not making copies, and metadata buffer is not reference counted.
bool internalPproc = false;
for (pendingBufferIterator iter = i->buffers.begin();
iter != i->buffers.end(); iter++) {
if (iter->need_metadata) {
internalPproc = true;
QCamera3ProcessingChannel *channel =
(QCamera3ProcessingChannel *)iter->stream->priv;
channel->queueReprocMetadata(metadata_buf);
break;
}
}
result.result = translateFromHalMetadata(metadata,
i->timestamp, i->request_id, i->jpegMetadata, i->pipeline_depth,
i->capture_intent, i->hybrid_ae_enable, internalPproc, i->need_dynamic_blklvl,
lastMetadataInBatch);
saveExifParams(metadata);
if (i->blob_request) {
{
//Dump tuning metadata if enabled and available
char prop[PROPERTY_VALUE_MAX];
memset(prop, 0, sizeof(prop));
property_get("persist.camera.dumpmetadata", prop, "0");
int32_t enabled = atoi(prop);
if (enabled && metadata->is_tuning_params_valid) {
dumpMetadataToFile(metadata->tuning_params,
mMetaFrameCount,
enabled,
"Snapshot",
frame_number);
}
}
}
if (!internalPproc) {
CDBG("%s: couldn't find need_metadata for this metadata", __func__);
// Return metadata buffer
if (free_and_bufdone_meta_buf) {
mMetadataChannel->bufDone(metadata_buf);
free(metadata_buf);
}
}
}
if (!result.result) {
ALOGE("%s: metadata is NULL", __func__);
}
result.frame_number = i->frame_number;
result.input_buffer = i->input_buffer;
result.num_output_buffers = 0;
result.output_buffers = NULL;
for (List<RequestedBufferInfo>::iterator j = i->buffers.begin();
j != i->buffers.end(); j++) {
if (j->buffer) {
result.num_output_buffers++;
}
}
if (result.num_output_buffers > 0) {
camera3_stream_buffer_t *result_buffers =
new camera3_stream_buffer_t[result.num_output_buffers];
if (!result_buffers) {
ALOGE("%s: Fatal error: out of memory", __func__);
}
size_t result_buffers_idx = 0;
for (List<RequestedBufferInfo>::iterator j = i->buffers.begin();
j != i->buffers.end(); j++) {
if (j->buffer) {
for (List<PendingFrameDropInfo>::iterator m = mPendingFrameDropList.begin();
m != mPendingFrameDropList.end(); m++) {
QCamera3Channel *channel = (QCamera3Channel *)j->buffer->stream->priv;
uint32_t streamID = channel->getStreamID(channel->getStreamTypeMask());
if((m->stream_ID == streamID) && (m->frame_number==frame_number)) {
j->buffer->status=CAMERA3_BUFFER_STATUS_ERROR;
ALOGW("%s: Stream STATUS_ERROR frame_number=%u, streamID=%u",
__func__, frame_number, streamID);
m = mPendingFrameDropList.erase(m);
break;
}
}
for (List<PendingBufferInfo>::iterator k =
mPendingBuffersMap.mPendingBufferList.begin();
k != mPendingBuffersMap.mPendingBufferList.end(); k++) {
if (k->buffer == j->buffer->buffer) {
CDBG("%s: Found buffer %p in pending buffer List "
"for frame %u, Take it out!!", __func__,
k->buffer, k->frame_number);
mPendingBuffersMap.num_buffers--;
k = mPendingBuffersMap.mPendingBufferList.erase(k);
break;
}
}
result_buffers[result_buffers_idx++] = *(j->buffer);
free(j->buffer);
j->buffer = NULL;
}
}
result.output_buffers = result_buffers;
mCallbackOps->process_capture_result(mCallbackOps, &result);
CDBG("%s %d: meta frame_number = %u, capture_time = %lld, partial:%d",
__func__, __LINE__, result.frame_number, i->timestamp, result.partial_result);
free_camera_metadata((camera_metadata_t *)result.result);
delete[] result_buffers;
} else {
mCallbackOps->process_capture_result(mCallbackOps, &result);
CDBG("%s %d: meta frame_number = %u, capture_time = %lld, partial:%d",
__func__, __LINE__, result.frame_number, i->timestamp, result.partial_result);
free_camera_metadata((camera_metadata_t *)result.result);
}
if (i->partial_result_cnt == PARTIAL_RESULT_COUNT) {
mPendingLiveRequest--;
i = erasePendingRequest(i);
} else {
CDBG("%s, keep in list, frame number:%d, partial result:%d",
__func__, i->frame_number, i->partial_result_cnt);
i->pending_extra_result = true;
i++;
}
if (!mPendingReprocessResultList.empty()) {
handlePendingReprocResults(frame_number + 1);
}
}
done_metadata:
for (pendingRequestIterator i = mPendingRequestsList.begin();
i != mPendingRequestsList.end() ;i++) {
i->pipeline_depth++;
}
CDBG("%s: mPendingLiveRequest = %d", __func__, mPendingLiveRequest);
unblockRequestIfNecessary();
}
/*===========================================================================
* FUNCTION : hdrPlusPerfLock
*
* DESCRIPTION: perf lock for HDR+ using custom intent
*
* PARAMETERS : @metadata_buf: Metadata super_buf pointer
*
* RETURN : None
*
*==========================================================================*/
void QCamera3HardwareInterface::hdrPlusPerfLock(
mm_camera_super_buf_t *metadata_buf)
{
if (NULL == metadata_buf) {
ALOGE("%s: metadata_buf is NULL", __func__);
return;
}
metadata_buffer_t *metadata =
(metadata_buffer_t *)metadata_buf->bufs[0]->buffer;
int32_t *p_frame_number_valid =
POINTER_OF_META(CAM_INTF_META_FRAME_NUMBER_VALID, metadata);
uint32_t *p_frame_number =
POINTER_OF_META(CAM_INTF_META_FRAME_NUMBER, metadata);
//acquire perf lock for 5 sec after the last HDR frame is captured
if (*p_frame_number_valid) {
if (mLastCustIntentFrmNum == (int32_t)*p_frame_number) {
m_perfLock.lock_acq_timed(HDR_PLUS_PERF_TIME_OUT);
}
}
//release lock after perf lock timer is expired. If lock is already released,
//isTimerReset returns false
if (m_perfLock.isTimerReset()) {
mLastCustIntentFrmNum = -1;
m_perfLock.lock_rel_timed();
}
}
/*===========================================================================
* FUNCTION : handleInputBufferWithLock
*
* DESCRIPTION: Handles input buffer and shutter callback with mMutex lock held.
*
* PARAMETERS :
* @buffer: contains status information about the processed buffer
* @frame_number: frame number of the input buffer
*
* RETURN :
*
*==========================================================================*/
void QCamera3HardwareInterface::handleInputBufferWithLock(
camera3_stream_buffer_t *buffer, uint32_t frame_number)
{
ATRACE_CALL();
pendingRequestIterator i = mPendingRequestsList.begin();
while (i != mPendingRequestsList.end() && i->frame_number != frame_number){
i++;
}
if (i != mPendingRequestsList.end() && i->input_buffer) {
//found the right request
if (!i->shutter_notified) {
CameraMetadata settings;
camera3_notify_msg_t notify_msg;
memset(&notify_msg, 0, sizeof(camera3_notify_msg_t));
nsecs_t capture_time = systemTime(CLOCK_MONOTONIC);
if(i->settings) {
settings = i->settings;
if (settings.exists(ANDROID_SENSOR_TIMESTAMP)) {
capture_time = settings.find(ANDROID_SENSOR_TIMESTAMP).data.i64[0];
} else {
ALOGE("%s: No timestamp in input settings! Using current one.",
__func__);
}
} else {
ALOGE("%s: Input settings missing!", __func__);
}
notify_msg.type = CAMERA3_MSG_SHUTTER;
notify_msg.message.shutter.frame_number = frame_number;
notify_msg.message.shutter.timestamp = (uint64_t)capture_time;
mCallbackOps->notify(mCallbackOps, &notify_msg);
i->shutter_notified = true;
CDBG("%s: Input request metadata notify frame_number = %u, capture_time = %llu",
__func__, i->frame_number, notify_msg.message.shutter.timestamp);
}
if (i->input_buffer->release_fence != -1) {
int32_t rc = sync_wait(i->input_buffer->release_fence, TIMEOUT_NEVER);
close(i->input_buffer->release_fence);
if (rc != OK) {
ALOGE("%s: input buffer sync wait failed %d", __func__, rc);
}
}
if ((nullptr != buffer) && (CAMERA3_BUFFER_STATUS_OK != buffer->status)) {
camera3_notify_msg_t notify_msg;
memset(&notify_msg, 0, sizeof(camera3_notify_msg_t));
notify_msg.type = CAMERA3_MSG_ERROR;
notify_msg.message.error.error_code = CAMERA3_MSG_ERROR_REQUEST;
notify_msg.message.error.error_stream = NULL;
notify_msg.message.error.frame_number = frame_number;
mCallbackOps->notify(mCallbackOps, &notify_msg);
Vector<camera3_stream_buffer_t> pendingBuffers;
camera3_stream_buffer_t pending;
memset(&pending, 0, sizeof(pending));
pending.acquire_fence = -1;
pending.release_fence = -1;
pending.status = CAMERA3_BUFFER_STATUS_ERROR;
for (List<PendingBufferInfo>::iterator k =
mPendingBuffersMap.mPendingBufferList.begin();
k != mPendingBuffersMap.mPendingBufferList.end();) {
if (k->frame_number == frame_number) {
pending.buffer = k->buffer;
pending.stream = k->stream;
pendingBuffers.add(pending);
mPendingBuffersMap.num_buffers--;