diff --git a/services/ca_mock/src/face_auth_ca.cpp b/services/ca_mock/src/face_auth_ca.cpp index ecf7be7..b5394b4 100644 --- a/services/ca_mock/src/face_auth_ca.cpp +++ b/services/ca_mock/src/face_auth_ca.cpp @@ -134,7 +134,7 @@ int32_t FaceAuthCA::StartAlgorithmOperation(AlgorithmOperation algorithmOperatio int32_t FaceAuthCA::TransferImageToAlgorithm(CameraImage images) { - sleep(1); + FACEAUTH_HILOGI(MODULE_SERVICE, "TransferImageToAlgorithm"); (void)(images); return CA_RESULT_SUCCESS; } @@ -187,6 +187,8 @@ int FaceAuthCA::getAlgorithmResult() int32_t FaceAuthCA::FinishAlgorithmOperation(AlgorithmResult &retResult) { FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); + FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s wait for image receive", __PRETTY_FUNCTION__); + sleep(1); isAuthingFlag = false; FACEAUTH_HILOGI(MODULE_SERVICE, "isAuthingFlag = %{public}d.", isAuthingFlag); int32_t authResult = getAlgorithmResult(); diff --git a/services/common/include/face_auth_defines.h b/services/common/include/face_auth_defines.h index acfe256..9f19aa6 100644 --- a/services/common/include/face_auth_defines.h +++ b/services/common/include/face_auth_defines.h @@ -27,6 +27,9 @@ #include #include #include +#include "output/video_output.h" +#include "surface.h" +#include "surface_buffer.h" namespace OHOS { namespace UserIAM { @@ -123,6 +126,7 @@ typedef struct { uint64_t templateID = 0; uint64_t callerUID = 0; uint32_t eventID = 0; + sptr producer = nullptr; }EnrollParam; typedef struct { diff --git a/services/faceauth/include/face_auth_camera.h b/services/faceauth/include/face_auth_camera.h old mode 100644 new mode 100755 index 47ddc14..7de0c87 --- a/services/faceauth/include/face_auth_camera.h +++ b/services/faceauth/include/face_auth_camera.h @@ -29,7 +29,7 @@ public: static std::shared_ptr GetInstance(); FaceAuthCamera(); virtual ~FaceAuthCamera(); - int32_t OpenCamera(sptr surface); + int32_t OpenCamera(sptr producer); void CloseCamera(); void SetZoomRatio(float zoom); void SetFlashMode(camera_flash_mode_enum_t flash); @@ -37,10 +37,10 @@ public: void SetExposureMode(camera_ae_mode_t exposure); private: - int32_t CreateCamera(sptr surface); - int32_t PrepareCamera(sptr surface); + int32_t CreateCamera(sptr producer); + int32_t PrepareCamera(sptr producer); int32_t CreateDisplayPreviewOutput(sptr &camManagerObj, - sptr surface); + sptr producer); int32_t Start(); void Stop(); void Release(); diff --git a/services/faceauth/include/face_auth_manager.h b/services/faceauth/include/face_auth_manager.h index 975b52c..373e3ff 100644 --- a/services/faceauth/include/face_auth_manager.h +++ b/services/faceauth/include/face_auth_manager.h @@ -18,6 +18,9 @@ #include "face_auth_executor_callback.h" #include "face_auth_event.h" #include "face_auth_ca.h" +#include "output/video_output.h" +#include "surface.h" +#include "surface_buffer.h" namespace OHOS { namespace UserIAM { @@ -72,7 +75,7 @@ private: void Finish(uint64_t scheduleId, int32_t srcType, int32_t resultCode, pAuthAttributes finalResult); FIRetCode OperForAlgorithm(uint64_t scheduleID); void HandleAlgoResult(uint64_t scheduleID); - int32_t OpenCamera(); + int32_t OpenCamera(sptr producer); int32_t WaitAlgorithmProcessDone(uint64_t scheduleID); bool GetRandomNum(int32_t *randomNum); }; diff --git a/services/faceauth/src/face_auth_camera.cpp b/services/faceauth/src/face_auth_camera.cpp old mode 100644 new mode 100755 index a5cff37..21263e8 --- a/services/faceauth/src/face_auth_camera.cpp +++ b/services/faceauth/src/face_auth_camera.cpp @@ -14,9 +14,9 @@ */ #include "face_auth_camera.h" -#include "output/video_output.h" #include "face_auth_log_wrapper.h" #include "face_auth_camera_buffer_listener.h" +#include "output/video_output.h" #include "surface.h" #include "surface_buffer.h" #include "face_auth_defines.h" @@ -54,6 +54,8 @@ sptr FaceAuthCamera::CreatePreviewOutput( return nullptr; } previewBuffer->SetDefaultWidthAndHeight(PREVIEW_DEFAULT_WIDTH, PREVIEW_DEFAULT_HEIGHT); + previewBuffer->SetUserData(CameraStandard::CameraManager::surfaceFormat, + std::to_string(OHOS_CAMERA_FORMAT_YCRCB_420_SP)); sptr listener = new FaceAuthCameraBufferListener(); if (listener == nullptr) { FACEAUTH_HILOGE(MODULE_SERVICE, "listener is nullptr."); @@ -65,7 +67,7 @@ sptr FaceAuthCamera::CreatePreviewOutput( return previewOutput; } -int32_t FaceAuthCamera::CreateCamera(sptr surface) +int32_t FaceAuthCamera::CreateCamera(sptr producer) { FACEAUTH_HILOGI(MODULE_SERVICE, "Create Camera start."); sptr camManagerObj = OHOS::CameraStandard::CameraManager::GetInstance(); @@ -89,12 +91,16 @@ int32_t FaceAuthCamera::CreateCamera(sptr surface) } } } + if (camera == nullptr) { + FACEAUTH_HILOGE(MODULE_SERVICE, "Camera not found"); + return FA_RET_ERROR; + } camInput_ = camManagerObj->CreateCameraInput(camera); if (camInput_ == nullptr) { FACEAUTH_HILOGE(MODULE_SERVICE, "Create Camera Input Failed"); return FA_RET_ERROR; } - int32_t intResult = PrepareCamera(surface); + int32_t intResult = PrepareCamera(producer); if (intResult != 0) { FACEAUTH_HILOGE(MODULE_SERVICE, "Prepare Camera Failed"); return FA_RET_ERROR; @@ -103,11 +109,16 @@ int32_t FaceAuthCamera::CreateCamera(sptr surface) return FA_RET_OK; } -int32_t FaceAuthCamera::PrepareCamera(sptr surface) +int32_t FaceAuthCamera::PrepareCamera(sptr producer) { int32_t intResult = FA_RET_OK; FACEAUTH_HILOGI(MODULE_SERVICE, "Prepare Camera start."); sptr camManagerObj = CameraStandard::CameraManager::GetInstance(); + if (camManagerObj == nullptr) { + FACEAUTH_HILOGE(MODULE_SERVICE, "camManagerObj is null"); + return FA_RET_ERROR; + } + capSession_ = camManagerObj->CreateCaptureSession(); if ((capSession_ == nullptr) || (camInput_ == nullptr)) { FACEAUTH_HILOGE(MODULE_SERVICE, "Create was not Proper!"); @@ -132,7 +143,7 @@ int32_t FaceAuthCamera::PrepareCamera(sptr surface) return FA_RET_ERROR; } if (isDisplay_) { - if (CreateDisplayPreviewOutput(camManagerObj, surface) != FA_RET_OK) { + if (CreateDisplayPreviewOutput(camManagerObj, producer) != FA_RET_OK) { FACEAUTH_HILOGE(MODULE_SERVICE, "Switch PreviewOutput Failed!"); return FA_RET_ERROR; } @@ -146,12 +157,12 @@ int32_t FaceAuthCamera::PrepareCamera(sptr surface) return FA_RET_OK; } -int32_t FaceAuthCamera::OpenCamera(sptr surface) +int32_t FaceAuthCamera::OpenCamera(sptr producer) { - if (surface != nullptr) { + if (producer != nullptr) { isDisplay_ = true; } - if (CreateCamera(surface) != FA_RET_OK) { + if (CreateCamera(producer) != FA_RET_OK) { return FA_RET_ERROR; } return Start(); @@ -214,17 +225,19 @@ void FaceAuthCamera::Release() } int32_t FaceAuthCamera::CreateDisplayPreviewOutput(sptr &camManagerObj, - sptr surface) + sptr producer) { int32_t intResult = FA_RET_OK; - FACEAUTH_HILOGI(MODULE_SERVICE, "Use UI's surface"); - disPlayPreviewOutput_ = camManagerObj->CreatePreviewOutput(surface); + FACEAUTH_HILOGI(MODULE_SERVICE, "Use UI's producer"); + disPlayPreviewOutput_ = camManagerObj->CreatePreviewOutput(producer, OHOS_CAMERA_FORMAT_YCRCB_420_SP); if (disPlayPreviewOutput_ == nullptr) { + isDisplay_ = false; FACEAUTH_HILOGE(MODULE_SERVICE, "Failed to create PreviewOutput for UI"); return FA_RET_ERROR; } intResult = capSession_->AddOutput(disPlayPreviewOutput_); if (intResult != FA_RET_OK) { + isDisplay_ = false; FACEAUTH_HILOGE(MODULE_SERVICE, "Failed to Add PreviewOutput For UI"); return FA_RET_ERROR; } diff --git a/services/faceauth/src/face_auth_camera_buffer_listener.cpp b/services/faceauth/src/face_auth_camera_buffer_listener.cpp index 4bbfefa..c6fc1d6 100644 --- a/services/faceauth/src/face_auth_camera_buffer_listener.cpp +++ b/services/faceauth/src/face_auth_camera_buffer_listener.cpp @@ -23,6 +23,7 @@ namespace UserIAM { namespace FaceAuth { int32_t FaceAuthCameraBufferListener::SendCameraImage(OHOS::sptr buffer, int64_t timestamp) { + FACEAUTH_HILOGI(MODULE_SERVICE, "receive image from camera"); CameraImage image = {}; image.image = static_cast(buffer->GetVirAddr()); image.imageSize = buffer->GetSize(); diff --git a/services/faceauth/src/face_auth_manager.cpp b/services/faceauth/src/face_auth_manager.cpp index c65943f..f60211c 100644 --- a/services/faceauth/src/face_auth_manager.cpp +++ b/services/faceauth/src/face_auth_manager.cpp @@ -253,7 +253,7 @@ void FaceAuthManager::DoAuthenticate(const AuthParam ¶m) } this->InitAlgorithm(FACE_LOCAL_INIT_ALGO_NAME); // open camera and send image to algorithm - if (OpenCamera() != FA_RET_OK) { + if (OpenCamera(nullptr) != FA_RET_OK) { // RK3568 no support camera, temporary ignore error FACEAUTH_HILOGE(MODULE_SERVICE, "Ignore open camera fail."); } @@ -334,7 +334,7 @@ void FaceAuthManager::DoEnroll(const EnrollParam ¶m) } this->InitAlgorithm(FACE_LOCAL_INIT_ALGO_NAME); // open camera and send image to algorithm - if (OpenCamera() != FA_RET_OK) { + if (OpenCamera(param.producer) != FA_RET_OK) { // RK3568 no support camera, temporary ignore error FACEAUTH_HILOGI(MODULE_SERVICE, "Ignore open camera fail."); } @@ -657,13 +657,12 @@ int32_t FaceAuthManager::GenerateEventId() FACEAUTH_HILOGI(MODULE_SERVICE, "GenerateEventId generate eventId %{public}u", eventId); return eventId; } - -int32_t FaceAuthManager::OpenCamera() +int32_t FaceAuthManager::OpenCamera(sptr producer) { std::promise promiseobj; std::future futureobj = promiseobj.get_future(); - FaceAuthThreadPool::GetInstance()->AddTask([&promiseobj]() { - promiseobj.set_value(FaceAuthCamera::GetInstance()->OpenCamera(nullptr)); + FaceAuthThreadPool::GetInstance()->AddTask([&promiseobj, &producer]() { + promiseobj.set_value(FaceAuthCamera::GetInstance()->OpenCamera(producer)); }); std::chrono::microseconds span(OPEN_CAMERA_TIME_OUT); while (futureobj.wait_for(span) == std::future_status::timeout) {