From 6ff173539166e746ce703cabb77f1aec208449e8 Mon Sep 17 00:00:00 2001 From: zouxiaoh Date: Tue, 24 Dec 2024 14:39:54 +0800 Subject: [PATCH] RPL-P MR4 & RPL-PS MR2 release Signed-off-by: zouxiaoh --- config/linux/ipu6ep/libcamhal_profile.xml | 2 +- config/linux/ipu6ep/sensors/lt6911uxc-1.xml | 41 ++--- config/linux/ipu6ep/sensors/lt6911uxc-2.xml | 35 ++--- .../ipu6ep/sensors/lt6911uxc-pdata1-1.xml | 143 ++++++++++++++++++ .../ipu6ep/sensors/lt6911uxc-pdata2-2.xml | 83 ++++++++++ modules/algowrapper/IntelTNR7US.cpp | 88 ++++++----- modules/algowrapper/IntelTNR7US.h | 38 +++-- src/3a/AiqUnit.cpp | 74 ++++----- src/core/RequestThread.cpp | 2 +- 9 files changed, 361 insertions(+), 145 deletions(-) create mode 100644 config/linux/ipu6ep/sensors/lt6911uxc-pdata1-1.xml create mode 100644 config/linux/ipu6ep/sensors/lt6911uxc-pdata2-2.xml diff --git a/config/linux/ipu6ep/libcamhal_profile.xml b/config/linux/ipu6ep/libcamhal_profile.xml index 74a85d3c..64be41d1 100644 --- a/config/linux/ipu6ep/libcamhal_profile.xml +++ b/config/linux/ipu6ep/libcamhal_profile.xml @@ -22,6 +22,6 @@ + lt6911uxc-1-1,lt6911uxc-2-2,lt6911uxc-pdata1-1,lt6911uxc-pdata2-2,lt6911uxe-1-1,lt6911uxe-2-2"/> diff --git a/config/linux/ipu6ep/sensors/lt6911uxc-1.xml b/config/linux/ipu6ep/sensors/lt6911uxc-1.xml index b6ee2a3b..bca847d3 100644 --- a/config/linux/ipu6ep/sensors/lt6911uxc-1.xml +++ b/config/linux/ipu6ep/sensors/lt6911uxc-1.xml @@ -40,18 +40,6 @@ - - - - - - - - - - - - @@ -63,7 +51,7 @@ - + @@ -75,7 +63,7 @@ - + @@ -107,17 +95,7 @@ - - - - - - - - - - - + @@ -127,7 +105,7 @@ - + @@ -137,7 +115,7 @@ - + @@ -152,13 +130,12 @@ + V4L2_PIX_FMT_UYVY,2560x1440,0,2, + V4L2_PIX_FMT_UYVY,1920x2160,0,3, + V4L2_PIX_FMT_UYVY,3840x2160,0,4"/> - + diff --git a/config/linux/ipu6ep/sensors/lt6911uxc-2.xml b/config/linux/ipu6ep/sensors/lt6911uxc-2.xml index 29ffcac5..cfb24160 100644 --- a/config/linux/ipu6ep/sensors/lt6911uxc-2.xml +++ b/config/linux/ipu6ep/sensors/lt6911uxc-2.xml @@ -41,9 +41,9 @@ - - - + + + @@ -53,9 +53,9 @@ - - - + + + @@ -95,17 +95,7 @@ - - - - - - - - - - - + @@ -115,7 +105,7 @@ - + @@ -125,7 +115,7 @@ - + @@ -135,16 +125,17 @@ + - + diff --git a/config/linux/ipu6ep/sensors/lt6911uxc-pdata1-1.xml b/config/linux/ipu6ep/sensors/lt6911uxc-pdata1-1.xml new file mode 100644 index 00000000..9f01388d --- /dev/null +++ b/config/linux/ipu6ep/sensors/lt6911uxc-pdata1-1.xml @@ -0,0 +1,143 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/linux/ipu6ep/sensors/lt6911uxc-pdata2-2.xml b/config/linux/ipu6ep/sensors/lt6911uxc-pdata2-2.xml new file mode 100644 index 00000000..c5857470 --- /dev/null +++ b/config/linux/ipu6ep/sensors/lt6911uxc-pdata2-2.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/algowrapper/IntelTNR7US.cpp b/modules/algowrapper/IntelTNR7US.cpp index 66404596..2f5e8f36 100644 --- a/modules/algowrapper/IntelTNR7US.cpp +++ b/modules/algowrapper/IntelTNR7US.cpp @@ -18,9 +18,6 @@ #include "modules/algowrapper/IntelTNR7US.h" -#include -#include - #include #include "iutils/CameraLog.h" @@ -34,6 +31,8 @@ namespace icamera { IntelTNR7US* IntelTNR7US::createIntelTNR(int cameraId) { #ifdef TNR7_CM return new IntelC4mTNR(cameraId); +#else + return nullptr; #endif } @@ -45,6 +44,15 @@ Tnr7Param* IntelTNR7US::allocTnr7ParamBuf() { #ifdef TNR7_CM IntelC4mTNR::~IntelC4mTNR() { + icamera::Thread::requestExit(); + { + std::lock_guard l(mLock); + mThreadRunning = false; + mRequestCondition.notify_one(); + } + + icamera::Thread::requestExitAndWait(); + for (auto surface : mCMSurfaceMap) { destroyCMSurface(surface.second); } @@ -58,8 +66,9 @@ int IntelC4mTNR::init(int width, int height, TnrType type) { mTnrType = type; std::string threadName = "IntelC4mTNR" + std::to_string(type + (mCameraId << 1)); - mThread = std::unique_ptr(new base::Thread(threadName)); - mThread->Start(); + run(threadName); + mThreadRunning = true; + return OK; } @@ -116,10 +125,7 @@ int IntelC4mTNR::runTnrFrame(const void* inBufAddr, void* outBufAddr, uint32_t i } CheckAndLogError(outSurface == nullptr, UNKNOWN_ERROR, "Failed to get CMSurface for output buffer"); - struct timespec beginTime = {}; - if (Log::isLogTagEnabled(ST_GPU_TNR, CAMERA_DEBUG_LOG_LEVEL2)) { - clock_gettime(CLOCK_MONOTONIC, &beginTime); - } + /* call Tnr api to run tnr for the inSurface and store the result in outSurface */ int ret = run_tnr7us_frame(mWidth, mHeight, mWidth, inSurface, outSurface, &tnrParam->scale, @@ -127,23 +133,43 @@ int IntelC4mTNR::runTnrFrame(const void* inBufAddr, void* outBufAddr, uint32_t i if (fd >= 0) { destroyCMSurface(outSurface); } - CheckAndLogError(ret != OK, UNKNOWN_ERROR, "tnr7us process failed"); - if (Log::isLogTagEnabled(ST_GPU_TNR, CAMERA_DEBUG_LOG_LEVEL2)) { - struct timespec endTime = {}; - clock_gettime(CLOCK_MONOTONIC, &endTime); - uint64_t timeUsedUs = (endTime.tv_sec - beginTime.tv_sec) * 1000000 + - (endTime.tv_nsec - beginTime.tv_nsec) / 1000; - LOG2(ST_GPU_TNR, "%s time:%lu us", __func__, timeUsedUs); + + return ret; +} +bool IntelC4mTNR::threadLoop() { + { + std::unique_lock lock(mLock); + if (!mThreadRunning) return false; + if (mParamGainRequest.empty()) { + std::cv_status ret = mRequestCondition.wait_for( + lock, std::chrono::nanoseconds(kMaxDuration * SLOWLY_MULTIPLIER)); + + // Already stopped + if (!mThreadRunning) return false; + + if (ret == std::cv_status::timeout) { + return true; + } + } } - return OK; + + ParamGain param; + { + std::lock_guard l(mLock); + param = mParamGainRequest.front(); + mParamGainRequest.pop(); + } + + tnr7usParamUpdate(param.gain, param.forceUpdate, mTnrType); + + return true; } int IntelC4mTNR::asyncParamUpdate(int gain, bool forceUpdate) { - if (mThread->task_runner()) { - mThread->task_runner()->PostTask( - FROM_HERE, base::BindOnce(&IntelC4mTNR::handleParamUpdate, base::Unretained(this), gain, - forceUpdate)); - } + std::lock_guard l(mLock); + mParamGainRequest.push({gain, forceUpdate}); + mRequestCondition.notify_one(); + return OK; } @@ -158,24 +184,6 @@ int32_t IntelC4mTNR::getTnrBufferSize(int width, int height, uint32_t* size) { return OK; } -void IntelC4mTNR::handleParamUpdate(int gain, bool forceUpdate) { - LOG2("@%s gain: %d", __func__, gain); - // gain value is from AE expore analog_gain * digital_gain - struct timespec beginTime = {}; - if (Log::isLogTagEnabled(ST_GPU_TNR, CAMERA_DEBUG_LOG_LEVEL2)) { - clock_gettime(CLOCK_MONOTONIC, &beginTime); - } - - tnr7usParamUpdate(gain, forceUpdate, mTnrType); - if (Log::isLogTagEnabled(ST_GPU_TNR, CAMERA_DEBUG_LOG_LEVEL2)) { - struct timespec endTime = {}; - clock_gettime(CLOCK_MONOTONIC, &endTime); - uint64_t timeUsedUs = (endTime.tv_sec - beginTime.tv_sec) * 1000000 + - (endTime.tv_nsec - beginTime.tv_nsec) / 1000; - LOG2(ST_GPU_TNR, "%s time:%lu us", __func__, timeUsedUs); - } -} - CmSurface2DUP* IntelC4mTNR::getBufferCMSurface(void* bufAddr) { if (mCMSurfaceMap.find(bufAddr) != mCMSurfaceMap.end()) { return mCMSurfaceMap[bufAddr]; diff --git a/modules/algowrapper/IntelTNR7US.h b/modules/algowrapper/IntelTNR7US.h index 2db4d59b..dcb59895 100644 --- a/modules/algowrapper/IntelTNR7US.h +++ b/modules/algowrapper/IntelTNR7US.h @@ -16,7 +16,6 @@ #pragma once -#include #include #include @@ -28,8 +27,11 @@ extern "C" { #include "CameraBuffer.h" #include "PlatformData.h" #include "TNRCommon.h" +#include "iutils/Thread.h" #ifdef TNR7_CM +#define HANDLE cancel_fw_pre_define +#ifndef HAVE_ANDROID_OS /* the cm_rt.h has some build error with current clang build flags * use the ignored setting to ignore these errors, and use * push/pop to make the ignore only take effect on this file */ @@ -37,9 +39,11 @@ extern "C" { #pragma clang diagnostic ignored "-Wbitfield-constant-conversion" #pragma clang diagnostic ignored "-Wunused-private-field" // HANDLE is redefined in cm_rt.h, avoid the redefinition build error -#define HANDLE cancel_fw_pre_define #include "cm_rt.h" #pragma clang diagnostic pop +#else +#include "cm_rt.h" +#endif extern int run_tnr7us_frame(int width, int height, int stride, CmSurface2DUP*& inputSurface, CmSurface2DUP*& outputSurface, tnr_scale_1_0_t* dsPtr, @@ -99,11 +103,11 @@ class IntelTNR7US { }; #ifdef TNR7_CM -class IntelC4mTNR : public IntelTNR7US { +class IntelC4mTNR : public IntelTNR7US, public icamera::Thread { public: explicit IntelC4mTNR(int cameraId) : IntelTNR7US(cameraId) {} virtual ~IntelC4mTNR(); - virtual int init(int width, int height, TnrType type = TNR_INSTANCE0); + virtual int init(int width, int height, TnrType type = TNR_INSTANCE0) override; /** * call tnr api to calc tnr result * @@ -113,12 +117,13 @@ class IntelC4mTNR : public IntelTNR7US { * \param fd: user output buffer file handle */ virtual int runTnrFrame(const void* inBufAddr, void* outBufAddr, uint32_t inBufSize, - uint32_t outBufSize, Tnr7Param* tnrParam, bool syncUpdate, int fd = -1); - virtual void* allocCamBuf(uint32_t bufSize, int id); - virtual void freeAllBufs(); - virtual int prepareSurface(void* bufAddr, int size); - virtual int asyncParamUpdate(int gain, bool forceUpdate); - virtual int getTnrBufferSize(int width, int height, uint32_t* size); + uint32_t outBufSize, Tnr7Param* tnrParam, bool syncUpdate, + int fd = -1) override; + virtual void* allocCamBuf(uint32_t bufSize, int id) override; + virtual void freeAllBufs() override; + virtual int prepareSurface(void* bufAddr, int size) override; + virtual int asyncParamUpdate(int gain, bool forceUpdate) override; + virtual int getTnrBufferSize(int width, int height, uint32_t* size) override; private: /* tnr api use CmSurface2DUP object as data buffer, call this api to create @@ -127,14 +132,21 @@ class IntelC4mTNR : public IntelTNR7US { int32_t destroyCMSurface(CmSurface2DUP* surface); // get the CmSurface object of the bufAddr in mCMSurfaceMap CmSurface2DUP* getBufferCMSurface(void* bufAddr); - /* call tnr7us API to update params */ - void handleParamUpdate(int gain, bool forceUpdate); DISALLOW_COPY_AND_ASSIGN(IntelC4mTNR); private: // Tnr will create CMSurface for input buffers and cache them in the map std::unordered_map mCMSurfaceMap; - std::unique_ptr mThread; + virtual bool threadLoop() override; + std::mutex mLock; + std::condition_variable mRequestCondition; + const uint64_t kMaxDuration = 5000000000; // 5s + typedef struct { + int gain; + bool forceUpdate; + } ParamGain; + std::queue mParamGainRequest; + bool mThreadRunning; }; #endif } // namespace icamera diff --git a/src/3a/AiqUnit.cpp b/src/3a/AiqUnit.cpp index c5306073..a1f8da66 100644 --- a/src/3a/AiqUnit.cpp +++ b/src/3a/AiqUnit.cpp @@ -241,14 +241,15 @@ int AiqUnit::initIntelCcaHandle(const std::vector& configModes) { // Initialize cca_cpf data ia_binary_data cpfData; - cca::cca_init_params params = {}; + std::unique_ptr params = + std::unique_ptr(new cca::cca_init_params()); ret = PlatformData::getCpf(mCameraId, tuningMode, &cpfData); if (ret == OK && cpfData.data) { CheckAndLogError(cpfData.size > cca::MAX_CPF_LEN, UNKNOWN_ERROR, "%s, AIQB buffer is too small cpfData:%d > MAX_CPF_LEN:%d", __func__, cpfData.size, cca::MAX_CPF_LEN); - MEMCPY_S(params.aiq_cpf.buf, cca::MAX_CPF_LEN, cpfData.data, cpfData.size); - params.aiq_cpf.size = cpfData.size; + MEMCPY_S(params->aiq_cpf.buf, cca::MAX_CPF_LEN, cpfData.data, cpfData.size); + params->aiq_cpf.size = cpfData.size; } // Initialize cca_nvm data @@ -257,8 +258,8 @@ int AiqUnit::initIntelCcaHandle(const std::vector& configModes) { CheckAndLogError(nvmData->size > cca::MAX_NVM_LEN, UNKNOWN_ERROR, "%s, NVM buffer is too small: nvmData:%d MAX_NVM_LEN:%d", __func__, nvmData->size, cca::MAX_NVM_LEN); - MEMCPY_S(params.aiq_nvm.buf, cca::MAX_NVM_LEN, nvmData->data, nvmData->size); - params.aiq_nvm.size = nvmData->size; + MEMCPY_S(params->aiq_nvm.buf, cca::MAX_NVM_LEN, nvmData->data, nvmData->size); + params->aiq_nvm.size = nvmData->size; } // Initialize cca_aiqd data @@ -267,25 +268,25 @@ int AiqUnit::initIntelCcaHandle(const std::vector& configModes) { CheckAndLogError(aiqdData->size > cca::MAX_AIQD_LEN, UNKNOWN_ERROR, "%s, AIQD buffer is too small aiqdData:%d > MAX_AIQD_LEN:%d", __func__, aiqdData->size, cca::MAX_AIQD_LEN); - MEMCPY_S(params.aiq_aiqd.buf, cca::MAX_AIQD_LEN, aiqdData->data, aiqdData->size); - params.aiq_aiqd.size = aiqdData->size; + MEMCPY_S(params->aiq_aiqd.buf, cca::MAX_AIQD_LEN, aiqdData->data, aiqdData->size); + params->aiq_aiqd.size = aiqdData->size; } SensorFrameParams sensorParam = {}; ret = PlatformData::calculateFrameParams(mCameraId, sensorParam); CheckAndLogError(ret != OK, ret, "%s: Failed to calculate frame params", __func__); - AiqUtils::convertToAiqFrameParam(sensorParam, params.frameParams); + AiqUtils::convertToAiqFrameParam(sensorParam, params->frameParams); - params.frameUse = ia_aiq_frame_use_video; - params.aiqStorageLen = MAX_SETTING_COUNT; + params->frameUse = ia_aiq_frame_use_video; + params->aiqStorageLen = MAX_SETTING_COUNT; // handle AE delay in AiqEngine - params.aecFrameDelay = 0; + params->aecFrameDelay = 0; // Initialize functions which need to be started - params.bitmap = cca::CCA_MODULE_AE | cca::CCA_MODULE_AWB | cca::CCA_MODULE_PA | - cca::CCA_MODULE_SA | cca::CCA_MODULE_GBCE | cca::CCA_MODULE_LARD; + params->bitmap = cca::CCA_MODULE_AE | cca::CCA_MODULE_AWB | cca::CCA_MODULE_PA | + cca::CCA_MODULE_SA | cca::CCA_MODULE_GBCE | cca::CCA_MODULE_LARD; if (PlatformData::getLensHwType(mCameraId) == LENS_VCM_HW) { - params.bitmap |= cca::CCA_MODULE_AF; + params->bitmap |= cca::CCA_MODULE_AF; } std::shared_ptr graphConfig = @@ -305,7 +306,7 @@ int AiqUnit::initIntelCcaHandle(const std::vector& configModes) { PlatformData::isDolMediumEnabled(mCameraId)); // DOL_FEATURE_E if (hasLtm && mLtm) { - params.bitmap |= cca::CCA_MODULE_LTM; + params->bitmap |= cca::CCA_MODULE_LTM; ret = mLtm->configure(configModes, graphConfig, VIDEO_STREAM_ID); CheckAndLogError(ret != OK, ret, "configure LTM engine error: %d", ret); } @@ -324,11 +325,11 @@ int AiqUnit::initIntelCcaHandle(const std::vector& configModes) { } ret = mDvs->configure(cfg, &dvsConfig); CheckAndLogError(ret != OK, UNKNOWN_ERROR, "%s, configure DVS error", __func__); - params.bitmap |= cca::CCA_MODULE_DVS; - params.dvsOutputType = dvsConfig.outputType; - params.dvsZoomRatio = dvsConfig.zoomRatio; - params.enableVideoStablization = dvsConfig.enableDvs; - params.gdcConfigs = dvsConfig.gdcConfigs; + params->bitmap |= cca::CCA_MODULE_DVS; + params->dvsOutputType = dvsConfig.outputType; + params->dvsZoomRatio = dvsConfig.zoomRatio; + params->enableVideoStablization = dvsConfig.enableDvs; + params->gdcConfigs = dvsConfig.gdcConfigs; } // INTEL_DVS_E @@ -339,25 +340,25 @@ int AiqUnit::initIntelCcaHandle(const std::vector& configModes) { // Parse the DOL mode and CG ratio from sensor mode config if (graphConfig != nullptr) { std::string dol_mode_name; - graphConfig->getDolInfo(params.conversionGainRatio, dol_mode_name); + graphConfig->getDolInfo(params->conversionGainRatio, dol_mode_name); std::map dolModeNameMap; dolModeNameMap["DOL_MODE_2_3_FRAME"] = ia_bcomp_dol_two_or_three_frame; dolModeNameMap["DOL_MODE_DCG"] = ia_bcomp_dol_dcg; dolModeNameMap["DOL_MODE_COMBINED_VERY_SHORT"] = ia_bcomp_dol_combined_very_short; dolModeNameMap["DOL_MODE_DCG_VERY_SHORT"] = ia_bcomp_dol_dcg_very_short; if (dolModeNameMap.count(dol_mode_name)) { - params.dolMode = dolModeNameMap[dol_mode_name]; + params->dolMode = dolModeNameMap[dol_mode_name]; } } - LOG2("conversionGainRatio: %f, dolMode: %d", params.conversionGainRatio, - params.dolMode); - params.bitmap = params.bitmap | cca::CCA_MODULE_BCOM; + LOG2("conversionGainRatio: %f, dolMode: %d", params->conversionGainRatio, + params->dolMode); + params->bitmap = params->bitmap | cca::CCA_MODULE_BCOM; } else if (PlatformData::getSensorAeEnable(mCameraId)) { - params.conversionGainRatio = 1; - params.dolMode = ia_bcomp_linear_hdr_mode; - LOG2("WA: conversionGainRatio: %f, dolMode: %d", params.conversionGainRatio, - params.dolMode); - params.bitmap = params.bitmap | cca::CCA_MODULE_BCOM; + params->conversionGainRatio = 1; + params->dolMode = ia_bcomp_linear_hdr_mode; + LOG2("WA: conversionGainRatio: %f, dolMode: %d", params->conversionGainRatio, + params->dolMode); + params->bitmap = params->bitmap | cca::CCA_MODULE_BCOM; } // DOL_FEATURE_E @@ -365,18 +366,18 @@ int AiqUnit::initIntelCcaHandle(const std::vector& configModes) { if (graphConfig != nullptr) { std::vector streamIds; graphConfig->graphGetStreamIds(streamIds); - params.aic_stream_ids.count = streamIds.size(); + params->aic_stream_ids.count = streamIds.size(); CheckAndLogError(streamIds.size() > cca::MAX_STREAM_NUM, UNKNOWN_ERROR, "%s, Too many streams: %zu in graph", __func__, streamIds.size()); for (size_t i = 0; i < streamIds.size(); ++i) { - params.aic_stream_ids.ids[i] = streamIds[i]; + params->aic_stream_ids.ids[i] = streamIds[i]; } } } IntelCca* intelCca = IntelCca::getInstance(mCameraId, tuningMode); CheckAndLogError(!intelCca, UNKNOWN_ERROR, "Failed to get cca. mode:%d cameraId:%d", tuningMode, mCameraId); - ia_err iaErr = intelCca->init(params); + ia_err iaErr = intelCca->init(*params); if (iaErr == ia_err_none) { mTuningModes.push_back(tuningMode); } else { @@ -404,10 +405,11 @@ void AiqUnit::deinitIntelCcaHandle() { __func__, mode, mCameraId); if (PlatformData::isAiqdEnabled(mCameraId)) { - cca::cca_aiqd aiqd = {}; - ia_err iaErr = intelCca->getAiqd(&aiqd); + std::unique_ptr aiqd = + std::unique_ptr(new cca::cca_aiqd()); + ia_err iaErr = intelCca->getAiqd(aiqd.get()); if (AiqUtils::convertError(iaErr) == OK) { - ia_binary_data data = {aiqd.buf, static_cast(aiqd.size)}; + ia_binary_data data = {aiqd->buf, static_cast(aiqd->size)}; PlatformData::saveAiqd(mCameraId, mode, data); } else { LOGW("@%s, failed to get aiqd data, iaErr %d", __func__, iaErr); diff --git a/src/core/RequestThread.cpp b/src/core/RequestThread.cpp index 0719195d..c76773d6 100644 --- a/src/core/RequestThread.cpp +++ b/src/core/RequestThread.cpp @@ -374,7 +374,7 @@ bool RequestThread::threadLoop() { } if (!mActive) { - return false; + return true; } CameraRequest request;