From c4d64f2afc74f43ef3e67e45e5fa6ef3537e4f1a Mon Sep 17 00:00:00 2001 From: zhuxu Date: Tue, 2 Aug 2022 21:24:11 +0800 Subject: [PATCH] fix: modify distributed camera client Signed-off-by: zhuxu --- .../client/include/dcamera_client.h | 5 ++-- .../client/src/dcamera_client.cpp | 12 ++++++++ .../client/test/sample/main.cpp | 29 +++++++++++-------- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/services/cameraservice/cameraoperator/client/include/dcamera_client.h b/services/cameraservice/cameraoperator/client/include/dcamera_client.h index 87c231f6..e973bfad 100644 --- a/services/cameraservice/cameraoperator/client/include/dcamera_client.h +++ b/services/cameraservice/cameraoperator/client/include/dcamera_client.h @@ -65,8 +65,9 @@ private: void ReleaseCaptureSession(); int32_t CameraServiceErrorType(const int32_t errorType); - bool isInit_; - std::string cameraId_; + bool isInit_ = false; + std::string cameraId_ = ""; + std::string latestCameraMetadata_ = ""; sptr photoSurface_; sptr videoSurface_; sptr cameraInfo_; diff --git a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp index 8d241716..25f717a9 100644 --- a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp +++ b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp @@ -102,6 +102,7 @@ int32_t DCameraClient::UpdateSettings(std::vector &)cameraInput_)->SetErrorCallback(inputCallback); ((sptr &)cameraInput_)->SetFocusCallback(inputCallback); + if (!latestCameraMetadata_.empty()) { + FindCameraMetadata(latestCameraMetadata_); + int32_t ret = ((sptr &)cameraInput_)->SetCameraSettings(latestCameraMetadata_); + latestCameraMetadata_ = ""; + if (ret != DCAMERA_OK) { + DHLOGE("DCameraClient::ConfigCaptureSession %s set camera settings failed, ret: %d", + GetAnonyString(cameraId_).c_str(), ret); + return ret; + } + } + captureSession_ = cameraManager_->CreateCaptureSession(); if (captureSession_ == nullptr) { DHLOGE("DCameraClient::ConfigCaptureSession %s create captureSession failed", diff --git a/services/cameraservice/cameraoperator/client/test/sample/main.cpp b/services/cameraservice/cameraoperator/client/test/sample/main.cpp index 7e268cbb..80c51044 100644 --- a/services/cameraservice/cameraoperator/client/test/sample/main.cpp +++ b/services/cameraservice/cameraoperator/client/test/sample/main.cpp @@ -142,6 +142,22 @@ static void InitVideoOutput() ((sptr &)g_videoOutput)->SetCallback(std::make_shared()); } +static void ConfigCaptureSession() +{ + g_captureSession->BeginConfig(); + g_captureSession->AddInput(g_cameraInput); + g_captureSession->AddOutput(g_previewOutput); + g_captureSession->AddOutput(g_videoOutput); + g_captureSession->AddOutput(g_photoOutput); + + std::vector stabilizationModes = g_captureSession->GetSupportedStabilizationMode(); + for (auto mode : stabilizationModes) { + DHLOGI("Distributed Camera Demo: video stabilization mode %d", mode); + } + g_captureSession->SetVideoStabilizationMode(stabilizationModes.back()); + g_captureSession->CommitConfig(); +} + static void ConfigFocusAndExposure() { ((sptr &)g_cameraInput)->LockForControl(); @@ -190,22 +206,11 @@ int main() InitPhotoOutput(); InitPreviewOutput(); InitVideoOutput(); + ConfigCaptureSession(); - g_captureSession->BeginConfig(); - g_captureSession->AddInput(g_cameraInput); - g_captureSession->AddOutput(g_previewOutput); - g_captureSession->AddOutput(g_videoOutput); - g_captureSession->AddOutput(g_photoOutput); - g_captureSession->CommitConfig(); g_captureSession->Start(); sleep(SLEEP_FIVE_SECOND); - std::vector stabilizationModes = g_captureSession->GetSupportedStabilizationMode(); - for (auto mode : stabilizationModes) { - DHLOGI("Distributed Camera Demo: video stabilization mode %d", mode); - } - g_captureSession->SetVideoStabilizationMode(stabilizationModes.back()); - ((sptr &)g_videoOutput)->Start(); sleep(SLEEP_FIVE_SECOND); -- Gitee