From 2d624e7c983e5137a888f7cc88a149b60c2b4393 Mon Sep 17 00:00:00 2001 From: Matthew Date: Sun, 11 Aug 2024 17:44:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4fps=E8=8C=83=E5=9B=B4?= =?UTF-8?q?=E5=92=8C=E6=98=BE=E7=A4=BA=E5=85=B3=E9=97=AD=E6=9B=9D=E5=85=89?= =?UTF-8?q?=E9=94=81=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/camera2/ndkcamera.cpp | 30 +++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/app/src/main/cpp/camera2/ndkcamera.cpp b/app/src/main/cpp/camera2/ndkcamera.cpp index 1b9d88e5..96809190 100644 --- a/app/src/main/cpp/camera2/ndkcamera.cpp +++ b/app/src/main/cpp/camera2/ndkcamera.cpp @@ -590,7 +590,7 @@ int NdkCamera::open(const std::string& cameraId) { templateId = (ACameraDevice_request_template)m_params.requestTemplate; status = ACameraDevice_createCaptureRequest(camera_device, templateId, &capture_request); - int32_t fpsRange[2] = {1, 5}; + int32_t fpsRange[2] = {5, 15}; // status = ACaptureRequest_setEntry_i32(capture_request, ACAMERA_CONTROL_AE_TARGET_FPS_RANGE, 2, fpsRange); } @@ -713,6 +713,8 @@ int NdkCamera::open(const std::string& cameraId) { } else { + uint8_t aeLock = ACAMERA_CONTROL_AE_LOCK_OFF; + status = ACaptureRequest_setEntry_u8(capture_request, ACAMERA_CONTROL_AE_LOCK, 1,&aeLock); XYLOG(XYLOG_SEVERITY_DEBUG, "AE_Lock Not Supported"); } @@ -724,8 +726,6 @@ int NdkCamera::open(const std::string& cameraId) { { m_imagesCaptured = ~0; } - - // ACaptureRequest_setEntry_u8(capture_request, ACAMERA_CONTROL_AE_LOCK, 1, &aeLockOff); } else @@ -940,6 +940,7 @@ void NdkCamera::onImageAvailable(AImageReader* reader) #endif avgY = avgY / (uint64_t)y_len; mResult.avgY = avgY; + mFinalResult.avgY = avgY; #if 1 if (avgY < 50) { @@ -964,7 +965,7 @@ void NdkCamera::onImageAvailable(AImageReader* reader) } #endif - if (m_imagesCaptured == ~0 || m_imagesCaptured != 1) + if (m_imagesCaptured == ~0 || m_imagesCaptured != 0) { // XYLOG(XYLOG_SEVERITY_DEBUG, "m_imagesCaptured=%u wait for next image", m_imagesCaptured); // Not Ready Or Taken @@ -977,7 +978,9 @@ void NdkCamera::onImageAvailable(AImageReader* reader) return; } - mResult.duration = GetMicroTimeStamp() - m_startTime; + XYLOG(XYLOG_SEVERITY_INFO, "Photo Taken: AES=%u AFS=%u AWBS=%u", (uint32_t)mFinalResult.aeState, (uint32_t)mFinalResult.awbState, (uint32_t)mFinalResult.afState); + + mFinalResult.duration = GetMicroTimeStamp() - m_startTime; int32_t format; AImage_getFormat(image, &format); @@ -1020,10 +1023,9 @@ void NdkCamera::onImageAvailable(AImageReader* reader) uint64_t avgY = std::accumulate(y_data, y_data + y_len, 0); #endif mResult.avgY = avgY / y_len; + mFinalResult.avgY = mResult.avgY; #endif - mFinalResult = mResult; - if (u_data == v_data + 1 && v_data == y_data + width * height && y_pixelStride == 1 && u_pixelStride == 2 && v_pixelStride == 2 && y_rowStride == width && u_rowStride == width && v_rowStride == width) { // already nv21 :) @@ -1506,9 +1508,17 @@ void NdkCamera::onCaptureCompleted(ACameraCaptureSession* session, ACaptureReque status = ACameraMetadata_getConstEntry(result, ACAMERA_CONTROL_AE_EXPOSURE_COMPENSATION, &val); mResult.compensation = (status == ACAMERA_OK) ? *(val.data.i32) : 0; -#if 0 - ALOGD("onCaptureCompleted EXPO=%lld, FD=%f camera id=%s, AE=%s AFS=%u AES=%u", exTime, focusDistance, mCameraId.c_str(), ((aeMode == 1) ? "ON" : "OFF"), mResult.afState, mResult.aeState); -#endif + if (m_imagesCaptured == 0) + { + mFinalResult = mResult; + } + + if (m_imagesCaptured != ~0) + { + XYLOG(XYLOG_SEVERITY_DEBUG, "onCaptureCompleted 3ASTATE: AES=%u AWBS=%u AFS=%u EXPO=%lld m_imagesCaptured=%u", + (uint32_t)mResult.aeState, (uint32_t)mResult.awbState, (uint32_t)mResult.afState, mResult.exposureTime, m_imagesCaptured); + } + // __android_log_print(ANDROID_LOG_WARN, "NdkCamera", "onCaptureCompleted %p %p %p", session, request, result); }