mirror of
https://github.com/openharmony/useriam_faceauth.git
synced 2026-07-19 18:13:32 -04:00
!66 解决OpenCamera Crash问题
Merge pull request !66 from Tianshi Liu/master
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
#include <chrono>
|
||||
#include <future>
|
||||
#include <thread>
|
||||
#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<IBufferProducer> producer = nullptr;
|
||||
}EnrollParam;
|
||||
|
||||
typedef struct {
|
||||
|
||||
Regular → Executable
+4
-4
@@ -29,7 +29,7 @@ public:
|
||||
static std::shared_ptr<FaceAuthCamera> GetInstance();
|
||||
FaceAuthCamera();
|
||||
virtual ~FaceAuthCamera();
|
||||
int32_t OpenCamera(sptr<Surface> surface);
|
||||
int32_t OpenCamera(sptr<IBufferProducer> 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> surface);
|
||||
int32_t PrepareCamera(sptr<Surface> surface);
|
||||
int32_t CreateCamera(sptr<IBufferProducer> producer);
|
||||
int32_t PrepareCamera(sptr<IBufferProducer> producer);
|
||||
int32_t CreateDisplayPreviewOutput(sptr<CameraStandard::CameraManager> &camManagerObj,
|
||||
sptr<Surface> surface);
|
||||
sptr<IBufferProducer> producer);
|
||||
int32_t Start();
|
||||
void Stop();
|
||||
void Release();
|
||||
|
||||
@@ -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<IBufferProducer> producer);
|
||||
int32_t WaitAlgorithmProcessDone(uint64_t scheduleID);
|
||||
bool GetRandomNum(int32_t *randomNum);
|
||||
};
|
||||
|
||||
Regular → Executable
+24
-11
@@ -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<CameraStandard::CaptureOutput> 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<FaceAuthCameraBufferListener> listener = new FaceAuthCameraBufferListener();
|
||||
if (listener == nullptr) {
|
||||
FACEAUTH_HILOGE(MODULE_SERVICE, "listener is nullptr.");
|
||||
@@ -65,7 +67,7 @@ sptr<CameraStandard::CaptureOutput> FaceAuthCamera::CreatePreviewOutput(
|
||||
return previewOutput;
|
||||
}
|
||||
|
||||
int32_t FaceAuthCamera::CreateCamera(sptr<Surface> surface)
|
||||
int32_t FaceAuthCamera::CreateCamera(sptr<IBufferProducer> producer)
|
||||
{
|
||||
FACEAUTH_HILOGI(MODULE_SERVICE, "Create Camera start.");
|
||||
sptr<CameraStandard::CameraManager> camManagerObj = OHOS::CameraStandard::CameraManager::GetInstance();
|
||||
@@ -89,12 +91,16 @@ int32_t FaceAuthCamera::CreateCamera(sptr<Surface> 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> surface)
|
||||
return FA_RET_OK;
|
||||
}
|
||||
|
||||
int32_t FaceAuthCamera::PrepareCamera(sptr<Surface> surface)
|
||||
int32_t FaceAuthCamera::PrepareCamera(sptr<IBufferProducer> producer)
|
||||
{
|
||||
int32_t intResult = FA_RET_OK;
|
||||
FACEAUTH_HILOGI(MODULE_SERVICE, "Prepare Camera start.");
|
||||
sptr<CameraStandard::CameraManager> 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> 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> surface)
|
||||
return FA_RET_OK;
|
||||
}
|
||||
|
||||
int32_t FaceAuthCamera::OpenCamera(sptr<Surface> surface)
|
||||
int32_t FaceAuthCamera::OpenCamera(sptr<IBufferProducer> 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<CameraStandard::CameraManager> &camManagerObj,
|
||||
sptr<Surface> surface)
|
||||
sptr<IBufferProducer> 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;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace UserIAM {
|
||||
namespace FaceAuth {
|
||||
int32_t FaceAuthCameraBufferListener::SendCameraImage(OHOS::sptr<OHOS::SurfaceBuffer> buffer, int64_t timestamp)
|
||||
{
|
||||
FACEAUTH_HILOGI(MODULE_SERVICE, "receive image from camera");
|
||||
CameraImage image = {};
|
||||
image.image = static_cast<uint8_t*>(buffer->GetVirAddr());
|
||||
image.imageSize = buffer->GetSize();
|
||||
|
||||
@@ -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<IBufferProducer> producer)
|
||||
{
|
||||
std::promise<int32_t> promiseobj;
|
||||
std::future<int32_t> 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) {
|
||||
|
||||
Reference in New Issue
Block a user