|
|
|
@ -81,7 +81,7 @@ static void onSessionReady(void* context, ACameraCaptureSession *session)
|
|
|
|
|
|
|
|
|
|
static void onSessionClosed(void* context, ACameraCaptureSession *session)
|
|
|
|
|
{
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_INFO, "onSessionClosed %p", session);
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_DEBUG, "onSessionClosed %p", session);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void onCaptureFailed(void* context, ACameraCaptureSession* session, ACaptureRequest* request, ACameraCaptureFailure* failure)
|
|
|
|
@ -164,6 +164,7 @@ NdkCamera::NdkCamera(int32_t width, int32_t height, const NdkCamera::CAMERA_PARA
|
|
|
|
|
mHeight = height;
|
|
|
|
|
|
|
|
|
|
mCaptureTriggered = false;
|
|
|
|
|
mFocusTriggered = false;
|
|
|
|
|
|
|
|
|
|
maxFrameDuration = 0;
|
|
|
|
|
afSupported = false;
|
|
|
|
@ -732,201 +733,6 @@ int NdkCamera::open(const std::string& cameraId) {
|
|
|
|
|
|
|
|
|
|
CaptureRequest *request = CreateRequest(true);
|
|
|
|
|
mCaptureRequests.push_back(request);
|
|
|
|
|
#if 0
|
|
|
|
|
for (int idx = 0; idx <= burstCaptures; idx++)
|
|
|
|
|
{
|
|
|
|
|
CaptureRequest *request = new CaptureRequest();
|
|
|
|
|
std::memset(request, 0, sizeof(CaptureRequest));
|
|
|
|
|
|
|
|
|
|
bool isPreviewRequest = (idx == PREVIEW_REQUEST_IDX);
|
|
|
|
|
|
|
|
|
|
request->pThis = this;
|
|
|
|
|
request->imageReader = isPreviewRequest ? mPreviewImageReader : mImageReader;
|
|
|
|
|
request->imageWindow = isPreviewRequest ? mPreviewImageWindow : mImageWindow;
|
|
|
|
|
request->imageTarget = isPreviewRequest ? mPreviewOutputTarget : mOutputTarget;
|
|
|
|
|
request->templateId = isPreviewRequest ? TEMPLATE_PREVIEW : (ACameraDevice_request_template)m_params.requestTemplate;
|
|
|
|
|
|
|
|
|
|
// capture request
|
|
|
|
|
status = ACameraDevice_createCaptureRequest(camera_device, request->templateId, &request->request);
|
|
|
|
|
ACaptureRequest_setUserContext(request->request, request);
|
|
|
|
|
|
|
|
|
|
// uint8_t ctrlMode = sceneModeSupported ? ACAMERA_CONTROL_MODE_USE_SCENE_MODE : ACAMERA_CONTROL_MODE_AUTO;
|
|
|
|
|
uint8_t ctrlMode = ACAMERA_CONTROL_MODE_AUTO;
|
|
|
|
|
status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_CONTROL_MODE, 1, &ctrlMode);
|
|
|
|
|
|
|
|
|
|
uint8_t captureIntent = isPreviewRequest ? ACAMERA_CONTROL_CAPTURE_INTENT_PREVIEW : GetCaptureIntent(ACameraDevice_request_template)m_params.requestTemplate);
|
|
|
|
|
status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_CONTROL_CAPTURE_INTENT, 1, &captureIntent);
|
|
|
|
|
|
|
|
|
|
uint8_t flashMode = ACAMERA_FLASH_MODE_OFF;
|
|
|
|
|
status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_FLASH_MODE, 1, &flashMode);
|
|
|
|
|
|
|
|
|
|
uint8_t nrMode = ACAMERA_NOISE_REDUCTION_MODE_HIGH_QUALITY;
|
|
|
|
|
status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_NOISE_REDUCTION_MODE, 1, &nrMode);
|
|
|
|
|
|
|
|
|
|
uint8_t edgeMode = ACAMERA_EDGE_MODE_FAST;
|
|
|
|
|
// status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_EDGE_MODE, 1, &edgeMode);
|
|
|
|
|
|
|
|
|
|
if (afSupported && m_params.autoFocus)
|
|
|
|
|
{
|
|
|
|
|
if (!m_params.zoom)
|
|
|
|
|
{
|
|
|
|
|
if (maxRegions[2] > 0)
|
|
|
|
|
{
|
|
|
|
|
int32_t centerX = activeArraySize[0] >> 1;
|
|
|
|
|
int32_t centerY = activeArraySize[1] >> 1;
|
|
|
|
|
|
|
|
|
|
int32_t sizeX = activeArraySize[0] >> 4;
|
|
|
|
|
int32_t sizeY = activeArraySize[1] >> 4;
|
|
|
|
|
|
|
|
|
|
int32_t afRegions[] = { centerX - sizeX, centerY - sizeY, centerX + sizeX, centerY + sizeY, 1000 };
|
|
|
|
|
// status = ACaptureRequest_setEntry_i32(request->request, ACAMERA_CONTROL_AF_REGIONS, 5, afRegions);
|
|
|
|
|
if (status == ACAMERA_OK)
|
|
|
|
|
{
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
int aa = 0;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// uint8_t afMode = ACAMERA_CONTROL_AF_MODE_CONTINUOUS_VIDEO;
|
|
|
|
|
uint8_t afMode = ACAMERA_CONTROL_AF_MODE_CONTINUOUS_PICTURE;
|
|
|
|
|
// uint8_t afMode = ACAMERA_CONTROL_AF_MODE_AUTO;
|
|
|
|
|
status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_CONTROL_AF_MODE, 1, &afMode);
|
|
|
|
|
|
|
|
|
|
// uint8_t trig = ACAMERA_CONTROL_AF_TRIGGER_CANCEL;
|
|
|
|
|
// status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_CONTROL_AF_TRIGGER, 1, &trig);
|
|
|
|
|
|
|
|
|
|
trig = ACAMERA_CONTROL_AF_TRIGGER_START;
|
|
|
|
|
// status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_CONTROL_AF_TRIGGER, 1, &trig);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
uint8_t trig = ACAMERA_CONTROL_AF_TRIGGER_START;
|
|
|
|
|
// status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_CONTROL_AF_TRIGGER, 1, &trig);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_params.sceneMode != 0)
|
|
|
|
|
{
|
|
|
|
|
uint8_t sceneMode = m_params.sceneMode;
|
|
|
|
|
status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_CONTROL_SCENE_MODE, 1, &sceneMode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_params.autoExposure)
|
|
|
|
|
{
|
|
|
|
|
uint8_t aeMode = ACAMERA_CONTROL_AE_MODE_ON;
|
|
|
|
|
status = ACaptureRequest_setEntry_u8(request->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(request->request, ACAMERA_CONTROL_AE_EXPOSURE_COMPENSATION, 1, &compensation);
|
|
|
|
|
if (status != ACAMERA_OK)
|
|
|
|
|
{
|
|
|
|
|
int aa = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (maxRegions[0] > 0)
|
|
|
|
|
{
|
|
|
|
|
int32_t aeRegions[] = { 0, 0, activeArraySize[0] - 1, activeArraySize[1] - 1, 1000 };
|
|
|
|
|
// status = ACaptureRequest_setEntry_i32(capture_request, ACAMERA_CONTROL_AE_REGIONS, 5, aeRegions);
|
|
|
|
|
if (status == ACAMERA_OK)
|
|
|
|
|
{
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
int aa = 0;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isPreviewRequest)
|
|
|
|
|
{
|
|
|
|
|
if (aeLockAvailable && (m_params.wait3ALocked & WAIT_AE_LOCKED))
|
|
|
|
|
{
|
|
|
|
|
uint8_t aeLock = ACAMERA_CONTROL_AE_LOCK_ON;
|
|
|
|
|
status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_CONTROL_AE_LOCK, 1, &aeLock);
|
|
|
|
|
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_DEBUG, "Try to Lock AE");
|
|
|
|
|
mResult.aeLockSetted = 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
uint8_t aeLock = ACAMERA_CONTROL_AE_LOCK_OFF;
|
|
|
|
|
status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_CONTROL_AE_LOCK, 1, &aeLock);
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_DEBUG, "AE_Lock Not Supported");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t aePrecatureTrigger = ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER_START;
|
|
|
|
|
status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER, 1, &aePrecatureTrigger);
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_DEBUG, "Trigger PRECAPTURE status=%d", (int)status);
|
|
|
|
|
m_precaptureStartTime = m_startTime;
|
|
|
|
|
|
|
|
|
|
// ACaptureRequest_setEntry_u8(capture_request, ACAMERA_CONTROL_AE_LOCK, 1, &aeLockOff);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
uint8_t aeMode = ACAMERA_CONTROL_AE_MODE_OFF;
|
|
|
|
|
status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_CONTROL_AE_MODE, 1, &aeMode);
|
|
|
|
|
|
|
|
|
|
if (m_params.sensitivity > 0)
|
|
|
|
|
{
|
|
|
|
|
int32_t sensitivity = m_params.sensitivity;
|
|
|
|
|
status = ACaptureRequest_setEntry_i32(request->request, ACAMERA_SENSOR_SENSITIVITY, 1, &sensitivity);
|
|
|
|
|
}
|
|
|
|
|
if (m_params.exposureTime > 0)
|
|
|
|
|
{
|
|
|
|
|
int64_t exposureTime = m_params.exposureTime;
|
|
|
|
|
status = ACaptureRequest_setEntry_i64(request->request, ACAMERA_SENSOR_EXPOSURE_TIME, 1, &exposureTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int64_t frameDuration = maxFrameDuration / 2;
|
|
|
|
|
// status = ACaptureRequest_setEntry_i64(request->request, ACAMERA_SENSOR_FRAME_DURATION, 1, &frameDuration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_CONTROL_AWB_MODE, 1, &awbMode);
|
|
|
|
|
if ((awbMode == ACAMERA_CONTROL_AWB_MODE_AUTO) && awbLockAvailable && (m_params.wait3ALocked & WAIT_AWB_LOCKED))
|
|
|
|
|
{
|
|
|
|
|
uint8_t awbLock = ACAMERA_CONTROL_AWB_LOCK_ON;
|
|
|
|
|
status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_CONTROL_AWB_LOCK, 1, &awbLock);
|
|
|
|
|
mResult.awbLockSetted = 1;
|
|
|
|
|
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_DEBUG, "Try to Lock AWB AWBS=%u", (unsigned int)mResult.awbState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
uint8_t antiBandingMode = ACAMERA_CONTROL_AE_ANTIBANDING_MODE_60HZ;
|
|
|
|
|
status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_CONTROL_AE_ANTIBANDING_MODE, 1, &antiBandingMode);
|
|
|
|
|
uint8_t flicker = ACAMERA_STATISTICS_SCENE_FLICKER_60HZ;
|
|
|
|
|
status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_STATISTICS_SCENE_FLICKER, 1, &flicker);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (m_params.zoom)
|
|
|
|
|
{
|
|
|
|
|
float zoomRatio = m_params.zoomRatio;
|
|
|
|
|
// uint8_t afMode = ACAMERA_CONTROL_AF_MODE_AUTO;
|
|
|
|
|
status = ACaptureRequest_setEntry_float(request->request, ACAMERA_CONTROL_ZOOM_RATIO, 1, &zoomRatio);
|
|
|
|
|
if (status != ACAMERA_OK)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status = ACaptureRequest_addTarget(request->request, request->imageTarget);
|
|
|
|
|
|
|
|
|
|
status = ACaptureSessionOutput_create(request->imageWindow, &request->sessionOutput);
|
|
|
|
|
status = ACaptureSessionOutputContainer_add(capture_session_output_container, request->sessionOutput);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// capture session
|
|
|
|
|
ACameraCaptureSession_stateCallbacks camera_capture_session_state_callbacks;
|
|
|
|
@ -1023,14 +829,18 @@ NdkCamera::CaptureRequest* NdkCamera::CreateRequest(bool isPreviewRequest)
|
|
|
|
|
// uint8_t afMode = ACAMERA_CONTROL_AF_MODE_AUTO;
|
|
|
|
|
status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_CONTROL_AF_MODE, 1, &afMode);
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
// For ACAMERA_CONTROL_AF_MODE_CONTINUOUS_PICTURE, we SHOULD NOT call ACAMERA_CONTROL_AF_TRIGGER_START
|
|
|
|
|
// Refer to: https://source.android.google.cn/docs/core/camera/camera3_3Amodes?hl=zh-cn
|
|
|
|
|
if (isPreviewRequest)
|
|
|
|
|
{
|
|
|
|
|
uint8_t trig = ACAMERA_CONTROL_AF_TRIGGER_CANCEL;
|
|
|
|
|
// uint8_t trig = ACAMERA_CONTROL_AF_TRIGGER_CANCEL;
|
|
|
|
|
// status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_CONTROL_AF_TRIGGER, 1, &trig);
|
|
|
|
|
|
|
|
|
|
trig = ACAMERA_CONTROL_AF_TRIGGER_START;
|
|
|
|
|
status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_CONTROL_AF_TRIGGER, 1, &trig);
|
|
|
|
|
// trig = ACAMERA_CONTROL_AF_TRIGGER_START;
|
|
|
|
|
// status = ACaptureRequest_setEntry_u8(request->request, ACAMERA_CONTROL_AF_TRIGGER, 1, &trig);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -1163,6 +973,11 @@ NdkCamera::CaptureRequest* NdkCamera::CreateRequest(bool isPreviewRequest)
|
|
|
|
|
return request;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NdkCamera::DestroyRequest(CaptureRequest* request)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NdkCamera::close()
|
|
|
|
|
{
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_DEBUG, "CameraStatus::try close %s", mCameraId.c_str());
|
|
|
|
@ -1724,8 +1539,7 @@ void NdkCamera::onCaptureCompleted(ACameraCaptureSession* session, ACaptureReque
|
|
|
|
|
status = ACameraMetadata_getConstEntry(result, ACAMERA_CONTROL_AF_STATE, &val);
|
|
|
|
|
afState = (status == ACAMERA_OK) ? *(val.data.u8) : ACAMERA_CONTROL_AF_STATE_INACTIVE;
|
|
|
|
|
|
|
|
|
|
// XYLOG(XYLOG_SEVERITY_DEBUG, "Preview State AFS=%u AES=%u AWBS=%u Time=%u",
|
|
|
|
|
// (unsigned int)afState, (unsigned int)aeState, (unsigned int)awbState, (unsigned int)(ts - m_startTime));
|
|
|
|
|
// XYLOG(XYLOG_SEVERITY_DEBUG, "Preview State AFS=%u AES=%u AWBS=%u Time=%u", (unsigned int)afState, (unsigned int)aeState, (unsigned int)awbState, (unsigned int)(ts - m_startTime));
|
|
|
|
|
|
|
|
|
|
// Check if timeout
|
|
|
|
|
if (ts - m_startTime < m_params.focusTimeout)
|
|
|
|
@ -1749,8 +1563,8 @@ void NdkCamera::onCaptureCompleted(ACameraCaptureSession* session, ACaptureReque
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (afState != ACAMERA_CONTROL_AF_STATE_PASSIVE_FOCUSED &&
|
|
|
|
|
afState != ACAMERA_CONTROL_AF_STATE_FOCUSED_LOCKED &&
|
|
|
|
|
afState != ACAMERA_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED)
|
|
|
|
|
afState != ACAMERA_CONTROL_AF_STATE_FOCUSED_LOCKED/* &&
|
|
|
|
|
afState != ACAMERA_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED*/)
|
|
|
|
|
// if (afState != ACAMERA_CONTROL_AF_STATE_INACTIVE)
|
|
|
|
|
{
|
|
|
|
|
//XYLOG(XYLOG_SEVERITY_DEBUG, "AF Enabled And Focused");
|
|
|
|
@ -1767,7 +1581,7 @@ void NdkCamera::onCaptureCompleted(ACameraCaptureSession* session, ACaptureReque
|
|
|
|
|
|
|
|
|
|
aePrecatureTrigger = ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER_START;
|
|
|
|
|
status = ACaptureRequest_setEntry_u8(request, ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER, 1, &aePrecatureTrigger);
|
|
|
|
|
//XYLOG(XYLOG_SEVERITY_DEBUG, "Trigger PRECAPTURE status=%d AES=%u", (int)status, (unsigned int)mResult.aeState);
|
|
|
|
|
//XYLOG(XYLOG_SEVERITY_DEBUG, "Trigger PRECAPTURE status=%d AES=%u", (int)status, (unsigned int)aeState);
|
|
|
|
|
AASSERT(status == ACAMERA_OK, "Failed to call PRECAPTURE_TRIGGER, status=%d", status);
|
|
|
|
|
|
|
|
|
|
readyForCapture = false;
|
|
|
|
@ -1894,11 +1708,10 @@ void NdkCamera::onCaptureCompleted(ACameraCaptureSession* session, ACaptureReque
|
|
|
|
|
status = ACameraMetadata_getConstEntry(result, ACAMERA_SENSOR_SENSITIVITY, &val);
|
|
|
|
|
int sensitivity = (status == ACAMERA_OK) ? *(val.data.i32) : 0;
|
|
|
|
|
|
|
|
|
|
uint8_t aeModeOff = ACAMERA_CONTROL_AE_MODE_OFF;
|
|
|
|
|
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_INFO, "HDR: Base Exp=%lld ISO=%d", exTime / 1000, sensitivity);
|
|
|
|
|
if (exTime != -1 && sensitivity > 0)
|
|
|
|
|
{
|
|
|
|
|
uint8_t aeModeOff = ACAMERA_CONTROL_AE_MODE_OFF;
|
|
|
|
|
for (int idx = 0; idx < burstCaptures; idx++)
|
|
|
|
|
{
|
|
|
|
|
ACaptureRequest_setEntry_u8(requests[idx], ACAMERA_CONTROL_AE_MODE, 1, &aeModeOff);
|
|
|
|
|