From 8aa40fec60f2aac6a0b7426bb210673cbcefecfa Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 3 May 2024 10:16:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9B=9D=E5=85=89=E8=A1=A5?= =?UTF-8?q?=E5=81=BF=E7=9A=84=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/PhoneDevice.cpp | 1 + app/src/main/cpp/camera2/ndkcamera.cpp | 53 ++++++++++++++++++++++++-- app/src/main/cpp/camera2/ndkcamera.h | 3 ++ 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index 7b115eac..9b62eb8b 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -912,6 +912,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< params.focusTimeout = mPhotoInfo.focusTimeout * 1000; params.exposureTime = mPhotoInfo.exposureTime; params.sensibility = mPhotoInfo.sensibility; + params.compensation = mPhotoInfo.compensation; params.orientation = mPhotoInfo.orientation; params.zoom = mPhotoInfo.zoom; params.zoomRatio = mPhotoInfo.zoomRatio; diff --git a/app/src/main/cpp/camera2/ndkcamera.cpp b/app/src/main/cpp/camera2/ndkcamera.cpp index 18b8419b..5436b9e3 100644 --- a/app/src/main/cpp/camera2/ndkcamera.cpp +++ b/app/src/main/cpp/camera2/ndkcamera.cpp @@ -282,9 +282,21 @@ int NdkCamera::open(const std::string& cameraId) { ACameraMetadata_const_entry e = {0}; status = ACameraMetadata_getConstEntry(camera_metadata,ACAMERA_CONTROL_AF_AVAILABLE_MODES, &e); // AASSERT(status == ACAMERA_OK, "ACameraMetadata_getConstEntry::ACAMERA_CONTROL_AF_AVAILABLE_MODES return error, %d", status); +#ifdef _DEBUG + for (int idx = 0; idx < e.count; idx++) + { + unsigned int m = e.data.u8[idx]; + XYLOG(XYLOG_SEVERITY_DEBUG, "Available AF Mode %u", m); + } +#endif afSupported = (status == ACAMERA_OK) && !(e.count == 0 || (e.count == 1 && e.data.u8[0] == ACAMERA_CONTROL_AF_MODE_OFF)); } + if (!afSupported) + { + XYLOG(XYLOG_SEVERITY_ERROR, "AF not Supported"); + } + { ACameraMetadata_const_entry val = {0}; status = ACameraMetadata_getConstEntry(camera_metadata,ACAMERA_SENSOR_INFO_EXPOSURE_TIME_RANGE, &val); @@ -343,6 +355,8 @@ int NdkCamera::open(const std::string& cameraId) { { aeCompensationRange.min_ = val.data.i32[0]; aeCompensationRange.max_ = val.data.i32[1]; + + XYLOG(XYLOG_SEVERITY_DEBUG, "AE_COMPENSATION_RANGE %d-%d", aeCompensationRange.min_, aeCompensationRange.max_); } else { @@ -351,6 +365,17 @@ int NdkCamera::open(const std::string& cameraId) { } } + { + ACameraMetadata_const_entry val = {0}; + status = ACameraMetadata_getConstEntry(camera_metadata, ACAMERA_CONTROL_AE_COMPENSATION_STEP, &val); + if (status == ACAMERA_OK) + { + aeCompensationStep = val.data.r[0]; + + XYLOG(XYLOG_SEVERITY_DEBUG, "AE_COMPENSATION_RANGE num=%d den=%d", aeCompensationStep.numerator, aeCompensationStep.denominator); + } + } + { ACameraMetadata_const_entry val = {0}; status = ACameraMetadata_getConstEntry(camera_metadata,ACAMERA_SENSOR_INFO_SENSITIVITY_RANGE, &val); @@ -421,7 +446,6 @@ int NdkCamera::open(const std::string& cameraId) { m_imagesCaptured = 0; - if (afSupported && m_params.autoFocus) { // uint8_t afMode = ACAMERA_CONTROL_AF_MODE_CONTINUOUS_VIDEO; uint8_t afMode = ACAMERA_CONTROL_AF_MODE_CONTINUOUS_PICTURE; @@ -459,6 +483,25 @@ int NdkCamera::open(const std::string& cameraId) { status = ACaptureRequest_setEntry_u8(capture_request, ACAMERA_CONTROL_AE_MODE, 1, &aeMode); // ACaptureRequest_setEntry_i32(capture_request, ACAMERA_SENSOR_SENSITIVITY, 1, &sensitivity_); + if ((aeCompensationRange.min_ != 0 || aeCompensationRange.max_ != 0) && m_params.compensation != 0) + { + int32_t compensation = m_params.compensation; + if (compensation < aeCompensationRange.min_) + { + compensation = aeCompensationRange.min_; + } + if (compensation > aeCompensationRange.max_) + { + compensation = aeCompensationRange.max_; + } + // int32_t aeCompensation = aeCompensationRange.max_; + status = ACaptureRequest_setEntry_i32(capture_request, ACAMERA_CONTROL_AE_EXPOSURE_COMPENSATION, 1, &compensation); + if (status != ACAMERA_OK) + { + int aa = 0; + } + } + uint8_t aePrecatureTrigger = ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER_START; status = ACaptureRequest_setEntry_u8(capture_request, ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER, 1, &aePrecatureTrigger); if (status == ACAMERA_OK) @@ -949,7 +992,7 @@ void NdkCamera::onCaptureCompleted(ACameraCaptureSession* session, ACaptureReque if (afSupported && (m_params.autoFocus != 0)) { - if (mResult.afState == ACAMERA_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED) + if (mResult.afState == ACAMERA_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED || mResult.afState == ACAMERA_CONTROL_AF_STATE_PASSIVE_UNFOCUSED) { uint8_t aePrecatureTrigger = ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER_CANCEL; status = ACaptureRequest_setEntry_u8(capture_request, ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER, 1, &aePrecatureTrigger); @@ -960,7 +1003,7 @@ void NdkCamera::onCaptureCompleted(ACameraCaptureSession* session, ACaptureReque return; } - ALOGD("onCaptureCompleted AFS=%u AES=%u", (unsigned int)mResult.afState, (unsigned int)mResult.aeState); + ALOGD("onCaptureCompleted 1 AFS=%u AES=%u", (unsigned int)mResult.afState, (unsigned int)mResult.aeState); if (mResult.afState == ACAMERA_CONTROL_AF_STATE_PASSIVE_FOCUSED || mResult.afState == ACAMERA_CONTROL_AF_STATE_FOCUSED_LOCKED) // if (afState != ACAMERA_CONTROL_AF_STATE_INACTIVE) { @@ -1014,11 +1057,13 @@ void NdkCamera::onCaptureCompleted(ACameraCaptureSession* session, ACaptureReque mResult.zoomRatio = *val.data.f; } + /* val = { 0 }; status = ACameraMetadata_getConstEntry(result, ACAMERA_CONTROL_AF_STATE, &val); mResult.afState = *(val.data.u8); + */ - ALOGD("onCaptureCompleted AFS=%u AES=%u", (unsigned int)mResult.afState, (unsigned int)mResult.aeState); + ALOGD("onCaptureCompleted 2 AFS=%u AES=%u", (unsigned int)mResult.afState, (unsigned int)mResult.aeState); val = {0}; status = ACameraMetadata_getConstEntry(result, ACAMERA_SENSOR_SENSITIVITY, &val); diff --git a/app/src/main/cpp/camera2/ndkcamera.h b/app/src/main/cpp/camera2/ndkcamera.h index 72fd6d33..0e89b4f8 100644 --- a/app/src/main/cpp/camera2/ndkcamera.h +++ b/app/src/main/cpp/camera2/ndkcamera.h @@ -78,6 +78,7 @@ public: unsigned int reserved : 7; unsigned int exposureTime; // ms unsigned int sensibility; + int compensation; float zoomRatio; }; @@ -91,6 +92,7 @@ public: int64_t exposureTime; float FocusDistance; int32_t sensitibity; + int32_t compensation; uint8_t sceneMode; float zoomRatio; @@ -146,6 +148,7 @@ protected: // int32_t sensitivity_; RangeValue sensitivityRange; RangeValue aeCompensationRange; + ACameraMetadata_rational aeCompensationStep; unsigned int m_imagesCaptured;