From 2a3ce49b8c032d15a5eee867d0da5b2e1c34d75d Mon Sep 17 00:00:00 2001 From: SongChunPeng Date: Sun, 17 Aug 2025 12:26:27 +0800 Subject: [PATCH 1/3] new mech interface Signed-off-by: SongChunPeng --- frameworks/cj/camera/include/camera_utils.h | 2 +- .../camera/base/src/session/mech_session.cpp | 27 +++- .../session/include/mech_session_unittest.h | 54 ++++--- .../session/src/mech_session_unittest.cpp | 105 +++++-------- .../camera/include/session/mech_session.h | 8 +- services/camera_service/idls/CameraTypes.idl | 46 ++++-- .../idls/IMechSessionCallback.idl | 48 +++--- .../camera_service/include/hcamera_device.h | 8 +- .../camera_service/include/hcapture_session.h | 12 +- .../camera_service/include/hmech_session.h | 10 +- .../camera_service/src/hcamera_device.cpp | 35 +++-- .../camera_service/src/hcapture_session.cpp | 145 ++++++++++++------ services/camera_service/src/hmech_session.cpp | 56 ++++--- 13 files changed, 339 insertions(+), 217 deletions(-) diff --git a/frameworks/cj/camera/include/camera_utils.h b/frameworks/cj/camera/include/camera_utils.h index 9c5876b88..807e9c2f9 100644 --- a/frameworks/cj/camera/include/camera_utils.h +++ b/frameworks/cj/camera/include/camera_utils.h @@ -168,7 +168,7 @@ struct CArrCJMetadataObject { int64_t size; }; -enum OutputType { METADATA_OUTPUT = 0, PHOTO_OUTPUT, PREVIEW_OUTPUT, VIDEO_OUTPUT }; +enum CJOutputType { METADATA_OUTPUT = 0, PHOTO_OUTPUT, PREVIEW_OUTPUT, VIDEO_OUTPUT }; CJMetadataObject MetadataObjectToCJMetadataObject(MetadataObject metaObject); diff --git a/frameworks/native/camera/base/src/session/mech_session.cpp b/frameworks/native/camera/base/src/session/mech_session.cpp index c278a5712..ec06d8018 100644 --- a/frameworks/native/camera/base/src/session/mech_session.cpp +++ b/frameworks/native/camera/base/src/session/mech_session.cpp @@ -57,7 +57,7 @@ int32_t MechSessionCallbackImpl::OnFocusTrackingInfo(int32_t streamId, bool isNe return ret; } -int32_t MechSessionCallbackImpl::OnCameraAppInfo(const std::vector& cameraAppInfos) +int32_t MechSessionCallbackImpl::OnCaptureSessionConfiged(const CaptureSessionInfo& captureSessionInfo) { MEDIA_DEBUG_LOG("%{public}s is called!", __FUNCTION__); int32_t ret = CAMERA_OK; @@ -65,8 +65,31 @@ int32_t MechSessionCallbackImpl::OnCameraAppInfo(const std::vectorGetCallback(); CHECK_RETURN_RET(!appCallback, ret); + appCallback->OnCaptureSessionConfiged(captureSessionInfo); + return CAMERA_OK; +} - appCallback->OnCameraAppInfo(cameraAppInfos); +int32_t MechSessionCallbackImpl::OnZoomInfoChange(int32_t sessionid, const ZoomInfo& zoomInfo) +{ + MEDIA_DEBUG_LOG("%{public}s is called!", __FUNCTION__); + int32_t ret = CAMERA_OK; + auto mechSession = mechSession_.promote(); + CHECK_RETURN_RET(!mechSession, ret); + auto appCallback = mechSession->GetCallback(); + CHECK_RETURN_RET(!appCallback, ret); + appCallback->OnZoomInfoChange(sessionid, zoomInfo); + return CAMERA_OK; +} + +int32_t MechSessionCallbackImpl::OnSessionStatusChange(int32_t sessionid, bool status) +{ + MEDIA_DEBUG_LOG("%{public}s is called!", __FUNCTION__); + int32_t ret = CAMERA_OK; + auto mechSession = mechSession_.promote(); + CHECK_RETURN_RET(!mechSession, ret); + auto appCallback = mechSession->GetCallback(); + CHECK_RETURN_RET(!appCallback, ret); + appCallback->OnSessionStatusChange(sessionid, status); return CAMERA_OK; } diff --git a/frameworks/native/camera/test/unittest/framework_native/session/include/mech_session_unittest.h b/frameworks/native/camera/test/unittest/framework_native/session/include/mech_session_unittest.h index 8c6ebb2ae..46cff305f 100644 --- a/frameworks/native/camera/test/unittest/framework_native/session/include/mech_session_unittest.h +++ b/frameworks/native/camera/test/unittest/framework_native/session/include/mech_session_unittest.h @@ -37,6 +37,7 @@ private: void CommitConfig(); void StartSession(); void StopSession(); + void SetFocusPoint(float x, float y); void ReleaseSession(); int32_t uid_ = 0; @@ -50,34 +51,49 @@ class AppMechSessionCallback : public MechSessionCallback { public: void OnFocusTrackingInfo(FocusTrackingMetaInfo info) override { - MEDIA_INFO_LOG("CallbackListener::OnFocusTrackingInfo "); return; } - void OnCameraAppInfo(const std::vector& cameraAppInfos) override + void OnCaptureSessionConfiged(CaptureSessionInfo captureSessionInfo) override { - cameraAppInfos_ = cameraAppInfos; - for (int i = 0; i < cameraAppInfos.size(); i++) { - auto appInfo = cameraAppInfos[i]; - MEDIA_INFO_LOG("AppMechSessionCallback::OnCameraAppInfo tokenId:%{public}d", appInfo.tokenId); - MEDIA_INFO_LOG("AppMechSessionCallback::OnCameraAppInfo cameraId:%{public}s", appInfo.cameraId.c_str()); - MEDIA_INFO_LOG("AppMechSessionCallback::OnCameraAppInfo opmode:%{public}d", appInfo.opmode); - MEDIA_INFO_LOG("AppMechSessionCallback::OnCameraAppInfo zoomValue:%{public}f", appInfo.zoomValue); - MEDIA_INFO_LOG("AppMechSessionCallback::OnCameraAppInfo equivalentFocus:%{public}d", - appInfo.equivalentFocus); - MEDIA_INFO_LOG("AppMechSessionCallback::OnCameraAppInfo width:%{public}d", appInfo.width); - MEDIA_INFO_LOG("AppMechSessionCallback::OnCameraAppInfo height:%{public}d", appInfo.height); - MEDIA_INFO_LOG("AppMechSessionCallback::OnCameraAppInfo videoStatus:%{public}d", appInfo.videoStatus); - } - return; + captureSessionInfo_ = captureSessionInfo; } - std::vector GetCameraAppInfos() - { + void OnZoomInfoChange(int sessionid, ZoomInfo zoomInfo) override + { return cameraAppInfos_; + zoomInfo_ = zoomInfo; + } + + void OnSessionStatusChange(int sessionid, bool status) override + { + sessionStatus_ = status; + } + + CaptureSessionInfo GetSessionInfo() + { + return captureSessionInfo_; + } + + ZoomInfo GetZoomInfo() + { + return zoomInfo_; + } + + bool GetSessionStatus() + { + return sessionStatus_; + } + + bool GetFocusStatus() + { + return focusStatus_; } private: - std::vector cameraAppInfos_; + CaptureSessionInfo captureSessionInfo_; + ZoomInfo zoomInfo_; + bool sessionStatus_; + bool focusStatus_; }; } } diff --git a/frameworks/native/camera/test/unittest/framework_native/session/src/mech_session_unittest.cpp b/frameworks/native/camera/test/unittest/framework_native/session/src/mech_session_unittest.cpp index b184d93d4..e0f4cf52d 100644 --- a/frameworks/native/camera/test/unittest/framework_native/session/src/mech_session_unittest.cpp +++ b/frameworks/native/camera/test/unittest/framework_native/session/src/mech_session_unittest.cpp @@ -49,9 +49,6 @@ void MechSessionUnitTest::TearDownTestCase(void) {} void MechSessionUnitTest::SetUp() { - uid_ = IPCSkeleton::GetCallingUid(); - AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid_, userId_); - MEDIA_DEBUG_LOG("MechSessionUnitTest::NativeAuthorization uid_:%{public}d, userId_:%{public}d", uid_, userId_); cameraManager_ = CameraManager::GetInstance(); ASSERT_NE(cameraManager_, nullptr); } @@ -112,6 +109,15 @@ void MechSessionUnitTest::StopSession() captureSession_->Stop(); } +void MechSessionUnitTest::SetFocusPoint(float x, float y) +{ + ASSERT_NE(captureSession_, nullptr); + Point point; + point.x = x; + point.y = y; + captureSession_->SetFocusPoint(point); +} + void MechSessionUnitTest::ReleaseSession() { if (captureSession_ != nullptr) { @@ -263,40 +269,49 @@ HWTEST_F(MechSessionUnitTest, mech_session_unittest_007, TestSize.Level0) /* * Feature: Framework - * Function: Test MechSession SetCallback + * Function: Test OnCaptureSessionConfiged when session start * SubFunction: NA * FunctionPoints: NA * EnvConditions: NA - * CaseDescription: Test MechSession SetCallback + * CaseDescription: Test OnCaptureSessionConfiged when session start */ HWTEST_F(MechSessionUnitTest, mech_session_unittest_008, TestSize.Level0) { - CommitConfig(); - StartSession(); - sptr mechSession = cameraManager_->CreateMechSession(userId_); ASSERT_NE(mechSession, nullptr); int32_t retCode = mechSession->EnableMechDelivery(true); EXPECT_EQ(retCode, 0); + auto mechSessionCallback = std::make_shared(); mechSession->SetCallback(mechSessionCallback); + CommitConfig(); + StartSession(); + CaptureSessionInfo sessionInfo = mechSessionCallback->GetSessionInfo(); + auto outputInfos = sessionInfo.outputInfos; + int size = outputInfos.size(); + EXPECT_NE(size, 0); + for (int i = 0; i < size; i++) { + auto outputInfo = outputInfos[i]; + EXPECT_EQ(outputInfo.width, PREVIEW_WIDTH); + EXPECT_EQ(outputInfo.height, PREVIEW_HEIGHT); + } + StopSession(); ReleaseSession(); - retCode = mechSession->Release(); EXPECT_EQ(retCode, 0); } /* * Feature: Framework - * Function: Test MechSession callback when session start + * Function: Test OnSessionStatusChange when session start * SubFunction: NA * FunctionPoints: NA * EnvConditions: NA - * CaseDescription: Test MechSession callback when session star + * CaseDescription: Test MechSession OnSessionStatusChange when session start */ -HWTEST_F(MechSessionUnitTest, mech_session_unittest_009, TestSize.Level1) +HWTEST_F(MechSessionUnitTest, mech_session_unittest_009, TestSize.Level0) { sptr mechSession = cameraManager_->CreateMechSession(userId_); ASSERT_NE(mechSession, nullptr); @@ -308,16 +323,7 @@ HWTEST_F(MechSessionUnitTest, mech_session_unittest_009, TestSize.Level1) CommitConfig(); StartSession(); - - std::vector cameraAppInfos = mechSessionCallback->GetCameraAppInfos(); - int size = cameraAppInfos.size(); - EXPECT_NE(size, 0); - for (int i = 0; i < size; i++) { - auto appInfo = cameraAppInfos[i]; - EXPECT_EQ(appInfo.width, PREVIEW_WIDTH); - EXPECT_EQ(appInfo.height, PREVIEW_HEIGHT); - EXPECT_EQ(appInfo.videoStatus, true); - } + EXPECT_EQ(mechSessionCallback->GetSessionStatus(), true); retCode = mechSession->Release(); EXPECT_EQ(retCode, 0); @@ -327,72 +333,31 @@ HWTEST_F(MechSessionUnitTest, mech_session_unittest_009, TestSize.Level1) /* * Feature: Framework - * Function: Test MechSession callback when session stop + * Function: Test OnSessionStatusChange when session stop * SubFunction: NA * FunctionPoints: NA * EnvConditions: NA - * CaseDescription: Test MechSession callback when session stop + * CaseDescription: Test MechSession OnSessionStatusChange when session stop */ -HWTEST_F(MechSessionUnitTest, mech_session_unittest_010, TestSize.Level1) +HWTEST_F(MechSessionUnitTest, mech_session_unittest_010, TestSize.Level0) { sptr mechSession = cameraManager_->CreateMechSession(userId_); ASSERT_NE(mechSession, nullptr); int32_t retCode = mechSession->EnableMechDelivery(true); EXPECT_EQ(retCode, 0); - CommitConfig(); - StartSession(); - auto mechSessionCallback = std::make_shared(); mechSession->SetCallback(mechSessionCallback); - StopSession(); - std::vector cameraAppInfos = mechSessionCallback->GetCameraAppInfos(); - int size = cameraAppInfos.size(); - EXPECT_NE(size, 0); - for (int i = 0; i < size; i++) { - auto appInfo = cameraAppInfos[i]; - EXPECT_EQ(appInfo.width, PREVIEW_WIDTH); - EXPECT_EQ(appInfo.height, PREVIEW_HEIGHT); - } - ReleaseSession(); - retCode = mechSession->Release(); - EXPECT_EQ(retCode, 0); -} -/* - * Feature: Framework - * Function: Test MechSession SetCallback when session setZoomRatio - * SubFunction: NA - * FunctionPoints: NA - * EnvConditions: NA - * CaseDescription: Test MechSession SetCallback when session setZoomRatio - */ -HWTEST_F(MechSessionUnitTest, mech_session_unittest_011, TestSize.Level0) -{ - sptr mechSession = cameraManager_->CreateMechSession(userId_); - ASSERT_NE(mechSession, nullptr); - int32_t retCode = mechSession->EnableMechDelivery(true); - auto mechSessionCallback = std::make_shared(); - mechSession->SetCallback(mechSessionCallback); - EXPECT_EQ(retCode, 0); CommitConfig(); StartSession(); - std::vector zoomRatioRange = captureSession_->GetZoomRatioRange(); - if (!zoomRatioRange.empty()) { - for (int i = 0; i < zoomRatioRange.size(); i++) { - float zoomRatio = zoomRatioRange[i]; - captureSession_->LockForControl(); - captureSession_->SetZoomRatio(zoomRatio); - captureSession_->UnlockForControl(); - } - } - - void StopSession(); - void ReleaseSession(); + StopSession(); + ReleaseSession(); + EXPECT_EQ(mechSessionCallback->GetSessionStatus(), false); retCode = mechSession->Release(); EXPECT_EQ(retCode, 0); } } -} +} \ No newline at end of file diff --git a/interfaces/inner_api/native/camera/include/session/mech_session.h b/interfaces/inner_api/native/camera/include/session/mech_session.h index 6c40b4c17..c3cfad552 100644 --- a/interfaces/inner_api/native/camera/include/session/mech_session.h +++ b/interfaces/inner_api/native/camera/include/session/mech_session.h @@ -31,7 +31,9 @@ public: MechSessionCallback() = default; virtual ~MechSessionCallback() = default; virtual void OnFocusTrackingInfo(FocusTrackingMetaInfo info) = 0; - virtual void OnCameraAppInfo(const std::vector& cameraAppInfos) = 0; + virtual void OnCaptureSessionConfiged(CaptureSessionInfo captureSessionInfo); + virtual void OnZoomInfoChange(int sessionid, ZoomInfo zoomInfo); + virtual void OnSessionStatusChange(int sessionid, bool status); }; class MechSession : public RefBase { @@ -91,7 +93,9 @@ public: ErrCode OnFocusTrackingInfo(int32_t streamId, bool isNeedMirror, bool isNeedFlip, const std::shared_ptr& result) override; - ErrCode OnCameraAppInfo(const std::vector& cameraAppInfos) override; + ErrCode OnCaptureSessionConfiged(const CaptureSessionInfo& captureSessionInfo) override; + ErrCode OnZoomInfoChange(int32_t sessionid, const ZoomInfo& zoomInfo) override; + ErrCode OnSessionStatusChange(int32_t sessionid, bool status) override; private: bool ProcessRectInfo(const std::shared_ptr& metadata, diff --git a/services/camera_service/idls/CameraTypes.idl b/services/camera_service/idls/CameraTypes.idl index 507539ea3..d428cc763 100644 --- a/services/camera_service/idls/CameraTypes.idl +++ b/services/camera_service/idls/CameraTypes.idl @@ -110,19 +110,6 @@ enum PressureStatus { SYSTEM_PRESSURE_SHUTDOWN }; -struct CameraAppInfo { - int tokenId; - String cameraId; - int opmode; - float zoomValue; - int equivalentFocus; - int width; - int height; - boolean videoStatus; - int position; - boolean focusStatus; -}; - enum ControlCenterEffectType { BEAUTY = 0, PORTRAIT @@ -131,4 +118,37 @@ enum ControlCenterEffectType { struct ControlCenterStatusInfo { ControlCenterEffectType effectType; boolean isActive; +}; + +enum OutputType { + PREVIEW = 0, + PHOTO = 1, + VIDEO = 2, + MOVING_PHOTO = 3, +}; + +struct OutputInfo { + OutputType type; + int minfps; + int maxfps; + int width; + int height; +}; + +struct ZoomInfo { + float zoomValue; + int equivalentFocus; + boolean focusStatus; + int focusMode; +}; + +struct CaptureSessionInfo { + int sessionId; + int callerTokenId; + String cameraId; + int position; + int sessionMode; + OutputInfo[] outputInfos; + int colorSpace; + ZoomInfo zoomInfo; }; \ No newline at end of file diff --git a/services/camera_service/idls/IMechSessionCallback.idl b/services/camera_service/idls/IMechSessionCallback.idl index 8083e30a7..388598a32 100644 --- a/services/camera_service/idls/IMechSessionCallback.idl +++ b/services/camera_service/idls/IMechSessionCallback.idl @@ -1,23 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package OHOS.CameraStandard; -import CameraTypes; -sequenceable CameraMetadataInfo..OHOS.Camera.CameraMetadata; - -interface IMechSessionCallback{ - [ipccode 0, oneway] void OnFocusTrackingInfo([in] int streamId, [in] boolean isNeedMirror, [in] boolean isNeedFlip, [in] sharedptr results); - [ipccode 1, oneway] void OnCameraAppInfo([in] CameraAppInfo[] cameraAppInfos); -} \ No newline at end of file +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package OHOS.CameraStandard; +import CameraTypes; +sequenceable CameraMetadataInfo..OHOS.Camera.CameraMetadata; + +interface IMechSessionCallback{ + [ipccode 0, oneway] void OnFocusTrackingInfo([in] int streamId, [in] boolean isNeedMirror, [in] boolean isNeedFlip, [in] sharedptr results); + [ipccode 1, oneway] void OnCaptureSessionConfiged([in] CaptureSessionInfo captureSessionInfo); + [ipccode 2, oneway] void OnZoomInfoChange([in] int sessionid, [in] ZoomInfo zoomInfo); + [ipccode 3, oneway] void OnSessionStatusChange([in] int sessionid, [in] boolean status); +} diff --git a/services/camera_service/include/hcamera_device.h b/services/camera_service/include/hcamera_device.h index a70012ae0..858c8cc0c 100644 --- a/services/camera_service/include/hcamera_device.h +++ b/services/camera_service/include/hcamera_device.h @@ -105,6 +105,7 @@ public: uint8_t GetUsedAsPosition(); bool GetDeviceMuteMode(); float GetZoomRatio(); + int32_t GetFocusMode(); void EnableMovingPhoto(bool isMovingPhotoEnabled); static void DeviceEjectCallBack(); static void DeviceFaultCallBack(); @@ -153,7 +154,7 @@ public: void SetMovingPhotoEndTimeCallback(std::function callback); - void SetMechCallback(std::function callback); + void SetZoomInfoCallback(std::function callback); inline void SetCameraConcurrentType(int32_t cameraConcurrentTypenum) { @@ -296,8 +297,11 @@ private: std::vector cameraRotateStrategyInfos_; std::string bundleName_ = ""; std::shared_mutex mechCallbackLock_; - std::function mechCallback_; + std::shared_mutex zoomInfoCallbackLock_; + std::function zoomInfoCallback_; float zoomRatio_ = 1.0f; + int32_t focusMode_ = -1; + bool focusStatus_ = false; }; } // namespace CameraStandard } // namespace OHOS diff --git a/services/camera_service/include/hcapture_session.h b/services/camera_service/include/hcapture_session.h index 2580d7690..73d977f33 100644 --- a/services/camera_service/include/hcapture_session.h +++ b/services/camera_service/include/hcapture_session.h @@ -218,11 +218,8 @@ public: int32_t GetUserId(); int32_t EnableMechDelivery(bool isEnableMech); void SetMechDeliveryState(MechDeliveryState state); - bool GetCameraAppInfo(CameraAppInfo& appInfo); - uint32_t GetEquivalentFocus(); - void OnCameraAppInfo(const CameraAppInfo& appInfo); - void OnCameraAppInfo(); void SetUpdateControlCenterCallback(UpdateControlCenterCallback cb); + bool GetCaptureSessionInfo(CaptureSessionInfo& sessionInfo); private: int32_t CommitConfigWithValidation(); @@ -277,6 +274,7 @@ private: void UpdateSettingForSpecialBundle(); int32_t UpdateSettingForFocusTrackingMech(bool isEnableMech); void UpdateSettingForFocusTrackingMechBeforeStart(std::shared_ptr &settings); + void SetDeviceMechCallback(); void ClearMovingPhotoRepeatStream(); StateMachine stateMachine_; sptr innerPressureCallback_; @@ -304,6 +302,12 @@ private: int32_t AddOutputInner(StreamType streamType, const sptr& stream); int32_t RemoveOutputInner(StreamType streamType, const sptr& stream); + uint32_t GetEquivalentFocus(); + std::vector GetOutputInfos(); + void OnCaptureSessionConfiged(); + void OnZoomInfoChange(const ZoomInfo& zoomInfo); + void OnSessionStatusChange(bool status); + std::mutex cbMutex_; // Make sure device thread safe,set device by {SetCameraDevice}, get device by {GetCameraDevice} diff --git a/services/camera_service/include/hmech_session.h b/services/camera_service/include/hmech_session.h index 9285d93f9..bce528931 100644 --- a/services/camera_service/include/hmech_session.h +++ b/services/camera_service/include/hmech_session.h @@ -16,8 +16,8 @@ #ifndef OHOS_CAMERA_H_MECH_SESSION_H #define OHOS_CAMERA_H_MECH_SESSION_H -#include #include +#include #include "mech_session_callback_stub.h" #include "mech_session_stub.h" @@ -36,17 +36,19 @@ public: int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override; int32_t OnFocusTrackingInfo(int32_t streamId, bool isNeedMirror, bool isNeedFlip, const std::shared_ptr &result); - int32_t OnCameraAppInfo(const std::vector& cameraAppInfos); + int32_t OnCaptureSessionConfiged(const CaptureSessionInfo& captureSessionInfo); + int32_t OnZoomInfoChange(int32_t sessionid, const ZoomInfo& zoomInfo); + int32_t OnSessionStatusChange(int32_t sessionid, bool status); sptr GetCallback(); bool IsEnableMech(); private: - void HandleCameraAppInfo(const sptr& callback); + void HanldeOnCaptureSessionConfiged(const sptr& callback); int32_t userId_; bool isEnableMech_ = false; sptr callback_; std::mutex enableLock_; - std::mutex callbackLock_; + std::shared_mutex callbackLock_; }; } // namespace CameraStandard } // namespace OHOS diff --git a/services/camera_service/src/hcamera_device.cpp b/services/camera_service/src/hcamera_device.cpp index a47a395a7..6fa41cc82 100644 --- a/services/camera_service/src/hcamera_device.cpp +++ b/services/camera_service/src/hcamera_device.cpp @@ -268,6 +268,11 @@ float HCameraDevice::GetZoomRatio() return zoomRatio_; } +int32_t HCameraDevice::GetFocusMode() +{ + return focusMode_; +} + void HCameraDevice::EnableMovingPhoto(bool isMovingPhotoEnabled) { isMovingPhotoEnabled_ = isMovingPhotoEnabled; @@ -923,14 +928,24 @@ void HCameraDevice::CheckZoomChange(const std::shared_ptr& settings) { - std::shared_lock lock(mechCallbackLock_); - CHECK_RETURN(!mechCallback_); + std::unique_lock lock(zoomInfoCallbackLock_); + CHECK_RETURN(!zoomInfoCallback_); int32_t ret; camera_metadata_item_t item; ret = OHOS::Camera::FindCameraMetadataItem(settings->get(), OHOS_CONTROL_AF_REGIONS, &item); + bool focusStatus = (ret == CAM_META_SUCCESS); + + int32_t focusMode = focusMode_; + ret = OHOS::Camera::FindCameraMetadataItem(settings->get(), OHOS_CONTROL_FOCUS_MODE, &item); if (ret == CAM_META_SUCCESS) { - mechCallback_(zoomRatio_, true); + focusMode = static_cast(item.data.u8[0]); } + + CHECK_EXECUTE((focusMode_!= focusMode || focusStatus_ != focusStatus), + zoomInfoCallback_(zoomRatio_, focusStatus, focusMode)); + + focusMode_ = focusMode; + focusStatus_ = focusStatus; } bool HCameraDevice::CheckMovingPhotoSupported(int32_t mode) @@ -1540,8 +1555,8 @@ void HCameraDevice::SetMovingPhotoEndTimeCallback(std::function cameraResult) { - std::shared_lock lock(mechCallbackLock_); - CHECK_RETURN(!mechCallback_); + std::shared_lock lock(zoomInfoCallbackLock_); + CHECK_RETURN(!zoomInfoCallback_); float zoomRatio = 1.0; camera_metadata_item_t item; int ret = OHOS::Camera::FindCameraMetadataItem(cameraResult->get(), OHOS_CONTROL_ZOOM_RATIO, &item); @@ -1550,15 +1565,15 @@ void HCameraDevice::ReportZoomInfos(std::shared_ptr callback) +void HCameraDevice::SetZoomInfoCallback(std::function callback) { - MEDIA_DEBUG_LOG("HCameraDevice::SetMechCallback enter."); - std::unique_lock lock(mechCallbackLock_); - mechCallback_ = callback; + MEDIA_DEBUG_LOG("HCameraDevice::SetZoomInfoCallback enter."); + std::unique_lock lock(zoomInfoCallbackLock_); + zoomInfoCallback_ = callback; } int32_t HCameraDevice::GetCallerToken() diff --git a/services/camera_service/src/hcapture_session.cpp b/services/camera_service/src/hcapture_session.cpp index 5a092e4f3..06bf74053 100644 --- a/services/camera_service/src/hcapture_session.cpp +++ b/services/camera_service/src/hcapture_session.cpp @@ -342,16 +342,7 @@ int32_t HCaptureSession::AddInput(const sptr& cameraDevice MEDIA_INFO_LOG("HCaptureSession::AddInput device:%{public}s", hCameraDevice->GetCameraId().c_str()); SetCameraDevice(hCameraDevice); hCameraDevice->DispatchDefaultSettingToHdi(); - auto thisPtr = wptr(this); - hCameraDevice->SetMechCallback([thisPtr](float zoomRatio, bool focusStatus) { - auto ptr = thisPtr.promote(); - CHECK_RETURN(!ptr); - CameraAppInfo appInfo; - CHECK_RETURN_ILOG(!ptr->GetCameraAppInfo(appInfo), "GetCameraAppInfo failed"); - appInfo.focusStatus = focusStatus; - appInfo.zoomValue = zoomRatio; - ptr->OnCameraAppInfo(appInfo); - }); + SetDeviceMechCallback(); }); if (errorCode == CAMERA_OK) { CAMERA_SYSEVENT_STATISTIC(CreateMsg("CaptureSession::AddInput, sessionID: %d", GetSessionId())); @@ -1549,7 +1540,8 @@ int32_t HCaptureSession::Start() mechDeliveryState_ = MechDeliveryState::ENABLED; } } - OnCameraAppInfo(); + OnSessionStatusChange(true); + OnCaptureSessionConfiged(); }); MEDIA_INFO_LOG("HCaptureSession::Start execute success, sessionID: %{public}d", GetSessionId()); MEDIA_INFO_LOG("%{public}s", GetConcurrentCameraIds(pid_).c_str()); @@ -1625,7 +1617,7 @@ int32_t HCaptureSession::Stop() isSessionStarted_ = false; } stateMachine_.Transfer(CaptureSessionState::SESSION_CONFIG_COMMITTED); - OnCameraAppInfo(); + OnSessionStatusChange(false); }); MEDIA_INFO_LOG("HCaptureSession::Stop execute success, sessionID: %{public}d", GetSessionId()); return errorCode; @@ -2168,52 +2160,72 @@ int32_t HCaptureSession::UpdateSettingForFocusTrackingMech(bool isEnableMech) return CAMERA_OK; } -bool HCaptureSession::GetCameraAppInfo(CameraAppInfo& appInfo) +void HCaptureSession::SetDeviceMechCallback() +{ + CHECK_RETURN(!cameraDevice_); + auto thisPtr = wptr(this); + cameraDevice_->SetZoomInfoCallback([thisPtr](float zoomRatio, bool focusStatus, int32_t focusMode) { + auto ptr = thisPtr.promote(); + CHECK_RETURN(!ptr); + ZoomInfo zoomInfo; + zoomInfo.zoomValue = zoomRatio; + zoomInfo.focusStatus = focusStatus; + zoomInfo.focusMode = focusMode; + zoomInfo.equivalentFocus = ptr->GetEquivalentFocus(); + ptr->OnZoomInfoChange(zoomInfo); + }); +} + +bool HCaptureSession::GetCaptureSessionInfo(CaptureSessionInfo& sessionInfo) { - appInfo.zoomValue = 1.0f; // default zoom - appInfo.cameraId = ""; - appInfo.position = -1; - appInfo.width = 0; - appInfo.height = 0; - appInfo.focusStatus = false; + sessionInfo.cameraId = ""; + sessionInfo.position = -1; + ZoomInfo zoomInfo; + zoomInfo.zoomValue = 1.0f; + zoomInfo.equivalentFocus = GetEquivalentFocus(); if (cameraDevice_ != nullptr) { - appInfo.cameraId = cameraDevice_->GetCameraId(); - appInfo.zoomValue = cameraDevice_->GetZoomRatio(); - appInfo.position = cameraDevice_->GetCameraPosition(); - } - appInfo.tokenId = static_cast(callerToken_); - appInfo.opmode = opMode_; - appInfo.equivalentFocus = GetEquivalentFocus(); - auto hStreamOperatorSptr = GetStreamOperator(); - if (hStreamOperatorSptr != nullptr) { - auto streams = hStreamOperatorSptr->GetAllStreams(); - for (auto& stream : streams) { - if (stream->GetStreamType() == StreamType::REPEAT) { - auto curStreamRepeat = CastStream(stream); - appInfo.width = curStreamRepeat->width_; - appInfo.height = curStreamRepeat->height_; - } - } - } - appInfo.videoStatus = stateMachine_.IsStateNoLock(CaptureSessionState::SESSION_STARTED); + sessionInfo.cameraId = cameraDevice_->GetCameraId(); + sessionInfo.position = cameraDevice_->GetCameraPosition(); + zoomInfo.zoomValue = cameraDevice_->GetZoomRatio(); + zoomInfo.focusMode = cameraDevice_->GetFocusMode(); + } + sessionInfo.zoomInfo = zoomInfo; + sessionInfo.callerTokenId = static_cast(callerToken_); + sessionInfo.sessionId = GetSessionId(); + sessionInfo.sessionMode = GetopMode(); + int32_t curColorSpace = 0; + GetActiveColorSpace(curColorSpace); + sessionInfo.colorSpace = curColorSpace; + std::vector outputInfos = GetOutputInfos(); + sessionInfo.outputInfos = outputInfos; return true; } -void HCaptureSession::OnCameraAppInfo(const CameraAppInfo& appInfo) +void HCaptureSession::OnCaptureSessionConfiged() +{ + auto &sessionManager = HCameraSessionManager::GetInstance(); + auto mechSession = sessionManager.GetMechSession(userId_); + CHECK_RETURN(mechSession == nullptr); + CaptureSessionInfo sessionInfo; + CHECK_RETURN_ILOG(!GetCaptureSessionInfo(sessionInfo), + "HCaptureSession::OnCaptureSessionConfiged GetCaptureSessionInfo failed"); + mechSession->OnCaptureSessionConfiged(sessionInfo); +} + +void HCaptureSession::OnZoomInfoChange(const ZoomInfo& zoomInfo) { auto &sessionManager = HCameraSessionManager::GetInstance(); auto mechSession = sessionManager.GetMechSession(userId_); CHECK_RETURN(mechSession == nullptr); - std::vector cameraAppInfos = {}; - cameraAppInfos.emplace_back(appInfo); - mechSession->OnCameraAppInfo(cameraAppInfos); + mechSession->OnZoomInfoChange(GetSessionId(), zoomInfo); } -void HCaptureSession::OnCameraAppInfo() +void HCaptureSession::OnSessionStatusChange(bool status) { - CameraAppInfo appInfo; - CHECK_RETURN_ILOG(!GetCameraAppInfo(appInfo), "HCaptureSession::OnCameraAppInfo GetCameraAppInfo failed"); - OnCameraAppInfo(appInfo); + auto &sessionManager = HCameraSessionManager::GetInstance(); + auto mechSession = sessionManager.GetMechSession(userId_); + CHECK_RETURN(mechSession == nullptr); + mechSession->OnSessionStatusChange(GetSessionId(), status); } uint32_t HCaptureSession::GetEquivalentFocus() @@ -2243,6 +2255,47 @@ uint32_t HCaptureSession::GetEquivalentFocus() return equivalentFocus; } +std::vector HCaptureSession::GetOutputInfos() +{ + std::vector outputInfos = {}; + auto hStreamOperatorSptr = GetStreamOperator(); + CHECK_RETURN_RET(!hStreamOperatorSptr, outputInfos); + auto streams = hStreamOperatorSptr->GetAllStreams(); + for (auto& stream : streams) { + if (stream->GetStreamType() == StreamType::CAPTURE) { + OutputInfo info; + info.type = OutputType::PHOTO; + info.width = stream->width_; + info.height = stream->height_; + outputInfos.emplace_back(info); + } else if (stream->GetStreamType() == StreamType::REPEAT) { + auto curStreamRepeat = CastStream(stream); + if (curStreamRepeat == nullptr) { + continue; + } + OutputInfo info; + auto streamType = curStreamRepeat->GetRepeatStreamType(); + if (streamType == RepeatStreamType::PREVIEW) { + info.type = OutputType::PREVIEW; + } else if (streamType == RepeatStreamType::VIDEO) { + info.type = OutputType::VIDEO; + } else if (streamType == RepeatStreamType::LIVEPHOTO) { + info.type = OutputType::MOVING_PHOTO; + } + info.width = stream->width_; + info.height = stream->height_; + std::vector frameRateRange = curStreamRepeat->GetFrameRateRange(); + constexpr int32_t fpsSize = 2; + if (frameRateRange.size() == fpsSize) { + info.minfps = frameRateRange[0]; + info.maxfps = frameRateRange[1]; + } + outputInfos.emplace_back(info); + } + } + return outputInfos; +} + int32_t HCaptureSession::EnableMechDelivery(bool isEnableMech) { std::lock_guard lock(mechDeliveryStateLock_); diff --git a/services/camera_service/src/hmech_session.cpp b/services/camera_service/src/hmech_session.cpp index 8fa488ac1..f451e9f18 100644 --- a/services/camera_service/src/hmech_session.cpp +++ b/services/camera_service/src/hmech_session.cpp @@ -50,9 +50,9 @@ int32_t HMechSession::EnableMechDelivery(bool isEnableMech) int32_t HMechSession::SetCallback(const sptr& callback) { MEDIA_INFO_LOG("HMechSession::SetCallback enter"); - std::lock_guard lock(callbackLock_); + std::unique_lock lock(callbackLock_); callback_ = callback; - HandleCameraAppInfo(callback); + HanldeOnCaptureSessionConfiged(callback); return CAMERA_OK; } @@ -79,53 +79,67 @@ int32_t HMechSession::Release() return CAMERA_OK; } +sptr HMechSession::GetCallback() +{ + std::shared_lock lock(callbackLock_); + return callback_; +} + +bool HMechSession::IsEnableMech() +{ + std::lock_guard lock(enableLock_); + return isEnableMech_; +} + int32_t HMechSession::OnFocusTrackingInfo(int32_t streamId, bool isNeedMirror, bool isNeedFlip, const std::shared_ptr &result) { - std::lock_guard lock(callbackLock_); + std::shared_lock lock(callbackLock_); if (callback_ != nullptr) { callback_->OnFocusTrackingInfo(streamId, isNeedMirror, isNeedFlip, result); } return CAMERA_OK; } -int32_t HMechSession::OnCameraAppInfo(const std::vector& cameraAppInfos) +int32_t HMechSession::OnCaptureSessionConfiged(const CaptureSessionInfo& captureSessionInfo) { - std::lock_guard lock(callbackLock_); + std::shared_lock lock(callbackLock_); if (callback_ != nullptr) { - callback_->OnCameraAppInfo(cameraAppInfos); + callback_->OnCaptureSessionConfiged(captureSessionInfo); } return CAMERA_OK; } -sptr HMechSession::GetCallback() +int32_t HMechSession::OnZoomInfoChange(int32_t sessionid, const ZoomInfo& zoomInfo) { - std::lock_guard lock(callbackLock_); - return callback_; + std::shared_lock lock(callbackLock_); + if (callback_ != nullptr) { + callback_->OnZoomInfoChange(sessionid, zoomInfo); + } + return CAMERA_OK; } -bool HMechSession::IsEnableMech() +int32_t HMechSession::OnSessionStatusChange(int32_t sessionid, bool status) { - std::lock_guard lock(enableLock_); - return isEnableMech_; + std::shared_lock lock(callbackLock_); + if (callback_ != nullptr) { + callback_->OnSessionStatusChange(sessionid, status); + } + return CAMERA_OK; } -void HMechSession::HandleCameraAppInfo(const sptr& callback) +void HMechSession::HanldeOnCaptureSessionConfiged(const sptr& callback) { - if (callback == nullptr) { - return; - } + CHECK_RETURN(callback == nullptr); auto &sessionManager = HCameraSessionManager::GetInstance(); std::vector> userSessions = sessionManager.GetUserSessions(userId_); - std::vector cameraAppInfos = {}; for (size_t i = 0; i < userSessions.size(); i++) { sptr captureSession = userSessions[i]; - CameraAppInfo appInfo; - if (captureSession->GetCameraAppInfo(appInfo)) { - cameraAppInfos.emplace_back(appInfo); + CaptureSessionInfo sessionInfo; + if (captureSession->GetCaptureSessionInfo(sessionInfo)) { + callback->OnCaptureSessionConfiged(sessionInfo); } } - callback->OnCameraAppInfo(cameraAppInfos); } } // namespace CameraStandard } // namespace OHOS -- Gitee From fde1de8f5aafb547711688ce1cf98d2bb57411f7 Mon Sep 17 00:00:00 2001 From: SongChunPeng Date: Fri, 22 Aug 2025 11:30:18 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BA=91=E5=8F=B0=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=98=B2=E6=8A=96=E6=A8=A1=E5=BC=8F=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SongChunPeng --- services/camera_service/idls/CameraTypes.idl | 1 + .../camera_service/include/hcamera_device.h | 7 ++- .../camera_service/src/hcamera_device.cpp | 50 ++++++++++++++++--- .../camera_service/src/hcapture_session.cpp | 7 +-- 4 files changed, 52 insertions(+), 13 deletions(-) diff --git a/services/camera_service/idls/CameraTypes.idl b/services/camera_service/idls/CameraTypes.idl index d428cc763..ad793ccd6 100644 --- a/services/camera_service/idls/CameraTypes.idl +++ b/services/camera_service/idls/CameraTypes.idl @@ -140,6 +140,7 @@ struct ZoomInfo { int equivalentFocus; boolean focusStatus; int focusMode; + int videoStabilizationMode; }; struct CaptureSessionInfo { diff --git a/services/camera_service/include/hcamera_device.h b/services/camera_service/include/hcamera_device.h index 858c8cc0c..c15ef26ae 100644 --- a/services/camera_service/include/hcamera_device.h +++ b/services/camera_service/include/hcamera_device.h @@ -106,6 +106,7 @@ public: bool GetDeviceMuteMode(); float GetZoomRatio(); int32_t GetFocusMode(); + int32_t GetVideoStabilizationMode(); void EnableMovingPhoto(bool isMovingPhotoEnabled); static void DeviceEjectCallBack(); static void DeviceFaultCallBack(); @@ -154,7 +155,7 @@ public: void SetMovingPhotoEndTimeCallback(std::function callback); - void SetZoomInfoCallback(std::function callback); + void SetZoomInfoCallback(std::function callback); inline void SetCameraConcurrentType(int32_t cameraConcurrentTypenum) { @@ -252,6 +253,7 @@ private: void ResetZoomTimer(); void CheckZoomChange(const std::shared_ptr& settings); void CheckFocusChange(const std::shared_ptr& settings); + void CheckVideoStabilizationChange(const std::shared_ptr& settings); void UnPrepareZoom(); int32_t OpenDevice(bool isEnableSecCam = false); void ConfigQosParam(const char *bundleName, int32_t qosLevel, @@ -298,10 +300,11 @@ private: std::string bundleName_ = ""; std::shared_mutex mechCallbackLock_; std::shared_mutex zoomInfoCallbackLock_; - std::function zoomInfoCallback_; + std::function zoomInfoCallback_; float zoomRatio_ = 1.0f; int32_t focusMode_ = -1; bool focusStatus_ = false; + int32_t videoStabilizationMode_ = 0; }; } // namespace CameraStandard } // namespace OHOS diff --git a/services/camera_service/src/hcamera_device.cpp b/services/camera_service/src/hcamera_device.cpp index 6fa41cc82..b1cbefae4 100644 --- a/services/camera_service/src/hcamera_device.cpp +++ b/services/camera_service/src/hcamera_device.cpp @@ -273,6 +273,11 @@ int32_t HCameraDevice::GetFocusMode() return focusMode_; } +int32_t HCameraDevice::GetVideoStabilizationMode() +{ + return videoStabilizationMode_; +} + void HCameraDevice::EnableMovingPhoto(bool isMovingPhotoEnabled) { isMovingPhotoEnabled_ = isMovingPhotoEnabled; @@ -937,17 +942,44 @@ void HCameraDevice::CheckFocusChange(const std::shared_ptrget(), OHOS_CONTROL_FOCUS_MODE, &item); - if (ret == CAM_META_SUCCESS) { + if (ret == CAM_META_SUCCESS && item.count != 0) { focusMode = static_cast(item.data.u8[0]); } - CHECK_EXECUTE((focusMode_!= focusMode || focusStatus_ != focusStatus), - zoomInfoCallback_(zoomRatio_, focusStatus, focusMode)); + if (focusMode_!= focusMode || focusStatus_ != focusStatus) { + ZoomInfo zoomInfo; + zoomInfo.zoomValue = zoomRatio_; + zoomInfo.focusStatus = focusStatus; + zoomInfo.focusMode = focusMode; + zoomInfo.videoStabilizationMode = videoStabilizationMode_; + zoomInfoCallback_(zoomInfo); + } focusMode_ = focusMode; focusStatus_ = focusStatus; } +void HCameraDevice::CheckVideoStabilizationChange(const std::shared_ptr& settings) +{ + std::shared_lock lock(zoomInfoCallbackLock_); + CHECK_RETURN(!zoomInfoCallback_); + camera_metadata_item_t item; + + int32_t ret = OHOS::Camera::FindCameraMetadataItem(settings->get(), OHOS_CONTROL_VIDEO_STABILIZATION_MODE, &item); + CHECK_RETURN(ret != CAM_META_SUCCESS || item.count == 0); + int32_t videoStabilizationMode = static_cast(item.data.u8[0]); + + if (videoStabilizationMode_ != videoStabilizationMode) { + ZoomInfo zoomInfo; + zoomInfo.zoomValue = zoomRatio_; + zoomInfo.focusStatus = focusStatus_; + zoomInfo.focusMode = focusMode_; + zoomInfo.videoStabilizationMode = videoStabilizationMode; + zoomInfoCallback_(zoomInfo); + } + videoStabilizationMode_ = videoStabilizationMode; +} + bool HCameraDevice::CheckMovingPhotoSupported(int32_t mode) { std::shared_ptr cameraAbility; @@ -1053,6 +1085,7 @@ int32_t HCameraDevice::UpdateSetting(const std::shared_ptrget()); CHECK_RETURN_RET_ELOG(!count, CAMERA_OK, "HCameraDevice::UpdateSetting Nothing to update"); @@ -1564,12 +1597,17 @@ void HCameraDevice::ReportZoomInfos(std::shared_ptr callback) +void HCameraDevice::SetZoomInfoCallback(std::function callback) { MEDIA_DEBUG_LOG("HCameraDevice::SetZoomInfoCallback enter."); std::unique_lock lock(zoomInfoCallbackLock_); diff --git a/services/camera_service/src/hcapture_session.cpp b/services/camera_service/src/hcapture_session.cpp index 06bf74053..bfc0c1f86 100644 --- a/services/camera_service/src/hcapture_session.cpp +++ b/services/camera_service/src/hcapture_session.cpp @@ -2164,13 +2164,9 @@ void HCaptureSession::SetDeviceMechCallback() { CHECK_RETURN(!cameraDevice_); auto thisPtr = wptr(this); - cameraDevice_->SetZoomInfoCallback([thisPtr](float zoomRatio, bool focusStatus, int32_t focusMode) { + cameraDevice_->SetZoomInfoCallback([thisPtr](ZoomInfo zoomInfo) { auto ptr = thisPtr.promote(); CHECK_RETURN(!ptr); - ZoomInfo zoomInfo; - zoomInfo.zoomValue = zoomRatio; - zoomInfo.focusStatus = focusStatus; - zoomInfo.focusMode = focusMode; zoomInfo.equivalentFocus = ptr->GetEquivalentFocus(); ptr->OnZoomInfoChange(zoomInfo); }); @@ -2188,6 +2184,7 @@ bool HCaptureSession::GetCaptureSessionInfo(CaptureSessionInfo& sessionInfo) sessionInfo.position = cameraDevice_->GetCameraPosition(); zoomInfo.zoomValue = cameraDevice_->GetZoomRatio(); zoomInfo.focusMode = cameraDevice_->GetFocusMode(); + zoomInfo.videoStabilizationMode = cameraDevice_->GetVideoStabilizationMode(); } sessionInfo.zoomInfo = zoomInfo; sessionInfo.callerTokenId = static_cast(callerToken_); -- Gitee From 469b4b53f13be9d096d1bc7fe92af744deb9ed48 Mon Sep 17 00:00:00 2001 From: SongChunPeng Date: Wed, 27 Aug 2025 10:12:37 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BA=91=E5=8F=B0=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=BB=B4=E6=B5=8B=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SongChunPeng --- .../camera/base/src/session/mech_session.cpp | 82 +++++++++++++++++-- .../camera/include/session/mech_session.h | 3 + services/camera_service/idls/CameraTypes.idl | 1 + .../camera_service/src/hcamera_service.cpp | 2 +- .../camera_service/src/hcapture_session.cpp | 9 +- services/camera_service/src/hmech_session.cpp | 10 +-- .../camera_service/src/hstream_operator.cpp | 5 +- 7 files changed, 93 insertions(+), 19 deletions(-) diff --git a/frameworks/native/camera/base/src/session/mech_session.cpp b/frameworks/native/camera/base/src/session/mech_session.cpp index ec06d8018..7723089db 100644 --- a/frameworks/native/camera/base/src/session/mech_session.cpp +++ b/frameworks/native/camera/base/src/session/mech_session.cpp @@ -22,12 +22,14 @@ namespace OHOS { namespace CameraStandard { constexpr int32_t FOCUS_TRACKING_REGION_DATA_CNT = 4; +constexpr int32_t LOG_INTERVAL_FREQUENCY = 10; int32_t MechSessionCallbackImpl::OnFocusTrackingInfo(int32_t streamId, bool isNeedMirror, bool isNeedFlip, const std::shared_ptr& result) { MEDIA_DEBUG_LOG("%{public}s is called!", __FUNCTION__); int32_t ret = CAMERA_OK; + CHECK_RETURN_RET(result == nullptr, ret); auto mechSession = mechSession_.promote(); CHECK_RETURN_RET(!mechSession, ret); auto appCallback = mechSession->GetCallback(); @@ -53,42 +55,52 @@ int32_t MechSessionCallbackImpl::OnFocusTrackingInfo(int32_t streamId, bool isNe if (ret == CAM_META_SUCCESS && item.count > 0) { info.SetTrackingObjectId(item.data.i32[0]); } + PrintFocusTrackingInfo(info); appCallback->OnFocusTrackingInfo(info); return ret; } int32_t MechSessionCallbackImpl::OnCaptureSessionConfiged(const CaptureSessionInfo& captureSessionInfo) { - MEDIA_DEBUG_LOG("%{public}s is called!", __FUNCTION__); + MEDIA_INFO_LOG("%{public}s is called!", __FUNCTION__); int32_t ret = CAMERA_OK; auto mechSession = mechSession_.promote(); CHECK_RETURN_RET(!mechSession, ret); auto appCallback = mechSession->GetCallback(); CHECK_RETURN_RET(!appCallback, ret); + PrintCaptureSessionInfo(captureSessionInfo); appCallback->OnCaptureSessionConfiged(captureSessionInfo); return CAMERA_OK; } int32_t MechSessionCallbackImpl::OnZoomInfoChange(int32_t sessionid, const ZoomInfo& zoomInfo) { - MEDIA_DEBUG_LOG("%{public}s is called!", __FUNCTION__); + MEDIA_INFO_LOG("%{public}s is called!", __FUNCTION__); int32_t ret = CAMERA_OK; auto mechSession = mechSession_.promote(); CHECK_RETURN_RET(!mechSession, ret); auto appCallback = mechSession->GetCallback(); CHECK_RETURN_RET(!appCallback, ret); + MEDIA_INFO_LOG("%{public}s sessionid:%{public}d, zoomValue:%{public}f," + "equivalentFocus:%{public}d, focusStatus:%{public}d," + "focusMode:%{public}d, videoStabilizationMode:%{public}d", + __FUNCTION__, sessionid, zoomInfo.zoomValue, + zoomInfo.equivalentFocus, zoomInfo.focusStatus, + zoomInfo.focusMode, zoomInfo.videoStabilizationMode); appCallback->OnZoomInfoChange(sessionid, zoomInfo); return CAMERA_OK; } int32_t MechSessionCallbackImpl::OnSessionStatusChange(int32_t sessionid, bool status) { - MEDIA_DEBUG_LOG("%{public}s is called!", __FUNCTION__); + MEDIA_INFO_LOG("%{public}s is called!", __FUNCTION__); int32_t ret = CAMERA_OK; auto mechSession = mechSession_.promote(); CHECK_RETURN_RET(!mechSession, ret); auto appCallback = mechSession->GetCallback(); CHECK_RETURN_RET(!appCallback, ret); + MEDIA_INFO_LOG("%{public}s sessionid:%{public}d, status:%{public}d", + __FUNCTION__, sessionid, status); appCallback->OnSessionStatusChange(sessionid, status); return CAMERA_OK; } @@ -122,9 +134,65 @@ bool MechSessionCallbackImpl::ProcessRectInfo(const std::shared_ptr(detectedObjects.size())); + for (size_t i = 0; i < detectedObjects.size(); i++) { + auto metadataObject = detectedObjects[i]; + auto type = metadataObject->GetType(); + auto box = metadataObject->GetBoundingBox(); + int32_t objectId = metadataObject->GetObjectId(); + int32_t confidence = metadataObject->GetConfidence(); + MEDIA_INFO_LOG("OnFocusTrackingInfo detectedObject type:%{public}d, " + "boundingBox:[%{public}f, %{public}f, %{public}f, %{public}f], " + "objectId:%{public}d, confidence:%{public}d", + type, box.topLeftX, box.topLeftY, + box.width, box.height, objectId, confidence); + } +} + +void MechSessionCallbackImpl::PrintCaptureSessionInfo(const CaptureSessionInfo& captureSessionInfo) +{ + MEDIA_INFO_LOG("OnCaptureSessionConfiged sessionId:%{public}d, " + "cameraId:%{public}s, position:%{public}d, sessionMode:%{public}d, " + "colorSpace:%{public}d, sessionStatus:%{public}d", + captureSessionInfo.sessionId, captureSessionInfo.cameraId.c_str(), + captureSessionInfo.position, captureSessionInfo.sessionMode, + captureSessionInfo.colorSpace, captureSessionInfo.sessionStatus); + + auto outputInfos = captureSessionInfo.outputInfos; + MEDIA_INFO_LOG("OnCaptureSessionConfiged outputInfos size:%{public}d", static_cast(outputInfos.size())); + for (size_t i = 0; i < outputInfos.size(); i++) { + auto outputInfo = outputInfos[i]; + MEDIA_INFO_LOG("OnCaptureSessionConfiged outputInfo type:%{public}d, " + "minfps:%{public}d, maxfps:%{public}d, width:%{public}d, " + "height:%{public}d", + outputInfo.type, outputInfo.minfps, outputInfo.minfps, + outputInfo.width, outputInfo.height); + } + + auto zoomInfo = captureSessionInfo.zoomInfo; + MEDIA_INFO_LOG("OnCaptureSessionConfiged zoomInfo zoomValue:%{public}f, " + "equivalentFocus:%{public}d, focusStatus:%{public}d, focusMode:%{public}d, " + "videoStabilizationMode:%{public}d", + zoomInfo.zoomValue, zoomInfo.equivalentFocus, zoomInfo.focusStatus, + zoomInfo.focusMode, zoomInfo.videoStabilizationMode); +} + MechSession::MechSession(sptr session) : remoteSession_(session) { - MEDIA_DEBUG_LOG("%{public}s is called!", __FUNCTION__); + MEDIA_INFO_LOG("%{public}s is called!", __FUNCTION__); sptr object = remoteSession_->AsObject(); pid_t pid = 0; deathRecipient_ = new (std::nothrow) CameraDeathRecipient(pid); @@ -140,7 +208,7 @@ MechSession::MechSession(sptr session) : remoteSession_(session) MechSession::~MechSession() { - MEDIA_DEBUG_LOG("%{public}s is called!", __FUNCTION__); + MEDIA_INFO_LOG("%{public}s is called!", __FUNCTION__); RemoveDeathRecipient(); } @@ -159,7 +227,7 @@ int32_t MechSession::EnableMechDelivery(bool isEnableMech) void MechSession::SetCallback(std::shared_ptr callback) { - MEDIA_DEBUG_LOG("%{public}s is called!", __FUNCTION__); + MEDIA_INFO_LOG("%{public}s is called!", __FUNCTION__); std::lock_guard lock(callbackMutex_); auto remoteSession = GetRemoteSession(); CHECK_RETURN_ELOG(remoteSession == nullptr, @@ -180,7 +248,7 @@ std::shared_ptr MechSession::GetCallback() int32_t MechSession::Release() { - MEDIA_DEBUG_LOG("%{public}s is called!", __FUNCTION__); + MEDIA_INFO_LOG("%{public}s is called!", __FUNCTION__); auto remoteSession = GetRemoteSession(); CHECK_RETURN_RET_ELOG(remoteSession == nullptr, CameraErrorCode::INVALID_ARGUMENT, "MechSession::Release remoteSession is nullptr"); diff --git a/interfaces/inner_api/native/camera/include/session/mech_session.h b/interfaces/inner_api/native/camera/include/session/mech_session.h index c3cfad552..8f7edd9bf 100644 --- a/interfaces/inner_api/native/camera/include/session/mech_session.h +++ b/interfaces/inner_api/native/camera/include/session/mech_session.h @@ -100,7 +100,10 @@ public: private: bool ProcessRectInfo(const std::shared_ptr& metadata, Rect& rect); + void PrintFocusTrackingInfo(FocusTrackingMetaInfo& info); + void PrintCaptureSessionInfo(const CaptureSessionInfo& captureSessionInfo); wptr mechSession_; + uint32_t logCount_ = 0; }; } // namespace CameraStandard } // namespace OHOS diff --git a/services/camera_service/idls/CameraTypes.idl b/services/camera_service/idls/CameraTypes.idl index ad793ccd6..c8aae204b 100644 --- a/services/camera_service/idls/CameraTypes.idl +++ b/services/camera_service/idls/CameraTypes.idl @@ -152,4 +152,5 @@ struct CaptureSessionInfo { OutputInfo[] outputInfos; int colorSpace; ZoomInfo zoomInfo; + boolean sessionStatus; }; \ No newline at end of file diff --git a/services/camera_service/src/hcamera_service.cpp b/services/camera_service/src/hcamera_service.cpp index f69f4911e..dc9618914 100644 --- a/services/camera_service/src/hcamera_service.cpp +++ b/services/camera_service/src/hcamera_service.cpp @@ -712,7 +712,7 @@ int32_t HCameraService::CreateCaptureSession(sptr& session, int int32_t uid = IPCSkeleton::GetCallingUid(); int32_t userId; AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); - MEDIA_DEBUG_LOG("HCameraService::CreateCaptureSession userId= %{public}d", userId); + MEDIA_INFO_LOG("HCameraService::CreateCaptureSession userId= %{public}d", userId); captureSession->SetUserId(userId); auto &sessionManager = HCameraSessionManager::GetInstance(); diff --git a/services/camera_service/src/hcapture_session.cpp b/services/camera_service/src/hcapture_session.cpp index bfc0c1f86..4339c360a 100644 --- a/services/camera_service/src/hcapture_session.cpp +++ b/services/camera_service/src/hcapture_session.cpp @@ -2120,10 +2120,10 @@ void HCaptureSession::SetMechDeliveryState(MechDeliveryState state) void HCaptureSession::UpdateSettingForFocusTrackingMechBeforeStart(std::shared_ptr& settings) { - MEDIA_DEBUG_LOG("HCaptureSession::UpdateSettingForFocusTrackingMechBeforeStart is called"); + MEDIA_INFO_LOG("%{public}s is called!", __FUNCTION__); std::lock_guard lock(mechDeliveryStateLock_); if (mechDeliveryState_ == MechDeliveryState::NEED_ENABLE) { - MEDIA_DEBUG_LOG("start EnableMechDelivery"); + MEDIA_INFO_LOG("%{public}s start EnableMechDelivery", __FUNCTION__); int32_t count = 1; uint8_t value = OHOS_CAMERA_MECH_MODE_ON; settings->addEntry(OHOS_CONTROL_FOCUS_TRACKING_MECH, &value, count); @@ -2132,8 +2132,7 @@ void HCaptureSession::UpdateSettingForFocusTrackingMechBeforeStart(std::shared_p int32_t HCaptureSession::UpdateSettingForFocusTrackingMech(bool isEnableMech) { - MEDIA_DEBUG_LOG("HCaptureSession::UpdateSettingForFocusTrackingMech is called, isEnableMech: %{public}d", - isEnableMech); + MEDIA_INFO_LOG("%{public}s is called, isEnableMech:%{public}d", __FUNCTION__, isEnableMech); auto cameraDevice = GetCameraDevice(); CHECK_RETURN_RET_ELOG(cameraDevice == nullptr, CAMERA_INVALID_SESSION_CFG, "HCaptureSession::UpdateSettingForFocusTrackingMech device is null"); @@ -2195,6 +2194,7 @@ bool HCaptureSession::GetCaptureSessionInfo(CaptureSessionInfo& sessionInfo) sessionInfo.colorSpace = curColorSpace; std::vector outputInfos = GetOutputInfos(); sessionInfo.outputInfos = outputInfos; + sessionInfo.sessionStatus = stateMachine_.IsStateNoLock(CaptureSessionState::SESSION_STARTED); return true; } @@ -2295,6 +2295,7 @@ std::vector HCaptureSession::GetOutputInfos() int32_t HCaptureSession::EnableMechDelivery(bool isEnableMech) { + MEDIA_INFO_LOG("%{public}s is called, isEnableMech:%{public}d", __FUNCTION__, isEnableMech); std::lock_guard lock(mechDeliveryStateLock_); auto currentState = stateMachine_.GetCurrentState(); switch (currentState) { diff --git a/services/camera_service/src/hmech_session.cpp b/services/camera_service/src/hmech_session.cpp index f451e9f18..ac5be36e9 100644 --- a/services/camera_service/src/hmech_session.cpp +++ b/services/camera_service/src/hmech_session.cpp @@ -25,17 +25,17 @@ namespace CameraStandard { HMechSession::HMechSession(int32_t userId) : userId_(userId) { - MEDIA_INFO_LOG("HMechSession::HMechSession enter, userId:%{public}d", userId); + MEDIA_INFO_LOG("%{public}s is called, userId:%{public}d", __FUNCTION__, userId); } HMechSession::~HMechSession() { - MEDIA_INFO_LOG("HMechSession::~HMechSession enter"); + MEDIA_INFO_LOG("%{public}s is called", __FUNCTION__); } int32_t HMechSession::EnableMechDelivery(bool isEnableMech) { - MEDIA_INFO_LOG("HMechSession::EnableMechDelivery enter, isEnableMech:%{public}d", isEnableMech); + MEDIA_INFO_LOG("%{public}s is called, isEnableMech:%{public}d", __FUNCTION__, isEnableMech); std::lock_guard lock(enableLock_); this->isEnableMech_ = isEnableMech; auto &sessionManager = HCameraSessionManager::GetInstance(); @@ -49,7 +49,7 @@ int32_t HMechSession::EnableMechDelivery(bool isEnableMech) int32_t HMechSession::SetCallback(const sptr& callback) { - MEDIA_INFO_LOG("HMechSession::SetCallback enter"); + MEDIA_INFO_LOG("%{public}s is called", __FUNCTION__); std::unique_lock lock(callbackLock_); callback_ = callback; HanldeOnCaptureSessionConfiged(callback); @@ -70,7 +70,7 @@ int32_t HMechSession::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unuse int32_t HMechSession::Release() { - MEDIA_INFO_LOG("HMechSession::Release enter"); + MEDIA_INFO_LOG("%{public}s is called", __FUNCTION__); sptr emptyCallback = nullptr; SetCallback(emptyCallback); EnableMechDelivery(false); diff --git a/services/camera_service/src/hstream_operator.cpp b/services/camera_service/src/hstream_operator.cpp index 1c2a54e5d..6ea2f5287 100644 --- a/services/camera_service/src/hstream_operator.cpp +++ b/services/camera_service/src/hstream_operator.cpp @@ -871,6 +871,7 @@ int32_t HStreamOperator::StartPreviewStream(const std::shared_ptr mechLock(mechCallbackLock_); CHECK_RETURN_RET(!streamOperator_, CAMERA_INVALID_STATE); uint32_t majorVer = 0; @@ -911,10 +912,10 @@ int32_t HStreamOperator::UpdateSettingForFocusTrackingMech(bool isEnableMech) std::vector settings; OHOS::Camera::MetadataUtils::ConvertMetadataToVec(metadata4Types, settings); if (isEnableMech) { - MEDIA_DEBUG_LOG("EnableResult start"); + MEDIA_INFO_LOG("%{public}s EnableResult start!", __FUNCTION__); streamOperatorV1_3->EnableResult(-1, settings); } else { - MEDIA_DEBUG_LOG("DisableResult start"); + MEDIA_INFO_LOG("%{public}s DisableResult start!", __FUNCTION__); streamOperatorV1_3->DisableResult(-1, settings); } return CAMERA_OK; -- Gitee