• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "hmech_session.h"
17 
18 #include "camera_log.h"
19 #include "camera_util.h"
20 #include "hcamera_session_manager.h"
21 #include "hcapture_session.h"
22 
23 namespace OHOS {
24 namespace CameraStandard {
25 
HMechSession(int32_t userId)26 HMechSession::HMechSession(int32_t userId) : userId_(userId)
27 {
28     MEDIA_INFO_LOG("%{public}s is called, userId:%{public}d", __FUNCTION__, userId);
29 }
30 
~HMechSession()31 HMechSession::~HMechSession()
32 {
33     MEDIA_INFO_LOG("%{public}s is called", __FUNCTION__);
34 }
35 
EnableMechDelivery(bool isEnableMech)36 int32_t HMechSession::EnableMechDelivery(bool isEnableMech)
37 {
38     MEDIA_INFO_LOG("%{public}s is called, isEnableMech:%{public}d", __FUNCTION__, isEnableMech);
39     std::lock_guard<std::mutex> lock(enableLock_);
40     this->isEnableMech_ = isEnableMech;
41     auto &sessionManager = HCameraSessionManager::GetInstance();
42     std::vector<sptr<HCaptureSession>> userSessions = sessionManager.GetUserSessions(userId_);
43     for (size_t i = 0; i < userSessions.size(); i++) {
44         sptr<HCaptureSession> captureSession = userSessions[i];
45         captureSession->EnableMechDelivery(isEnableMech);
46     }
47     return CAMERA_OK;
48 }
49 
SetCallback(const sptr<IMechSessionCallback> & callback)50 int32_t HMechSession::SetCallback(const sptr<IMechSessionCallback>& callback)
51 {
52     MEDIA_INFO_LOG("%{public}s is called", __FUNCTION__);
53     std::unique_lock<std::shared_mutex> lock(callbackLock_);
54     callback_ = callback;
55     HanldeOnCaptureSessionConfiged(callback);
56     return CAMERA_OK;
57 }
58 
CallbackEnter(uint32_t code)59 int32_t HMechSession::CallbackEnter([[maybe_unused]] uint32_t code)
60 {
61     MEDIA_DEBUG_LOG("start, code:%{public}u", code);
62     return CAMERA_OK;
63 }
64 
CallbackExit(uint32_t code,int32_t result)65 int32_t HMechSession::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result)
66 {
67     MEDIA_DEBUG_LOG("leave, code:%{public}u, result:%{public}d", code, result);
68     return CAMERA_OK;
69 }
70 
Release()71 int32_t HMechSession::Release()
72 {
73     MEDIA_INFO_LOG("%{public}s is called", __FUNCTION__);
74     sptr<IMechSessionCallback> emptyCallback = nullptr;
75     SetCallback(emptyCallback);
76     EnableMechDelivery(false);
77     auto &sessionManager = HCameraSessionManager::GetInstance();
78     sessionManager.RemoveMechSession(userId_);
79     return CAMERA_OK;
80 }
81 
GetCallback()82 sptr<IMechSessionCallback> HMechSession::GetCallback()
83 {
84     std::shared_lock<std::shared_mutex> lock(callbackLock_);
85     return callback_;
86 }
87 
IsEnableMech()88 bool HMechSession::IsEnableMech()
89 {
90     std::lock_guard<std::mutex> lock(enableLock_);
91     return isEnableMech_;
92 }
93 
OnFocusTrackingInfo(int32_t streamId,bool isNeedMirror,bool isNeedFlip,const std::shared_ptr<OHOS::Camera::CameraMetadata> & result)94 int32_t HMechSession::OnFocusTrackingInfo(int32_t streamId, bool isNeedMirror, bool isNeedFlip,
95     const std::shared_ptr<OHOS::Camera::CameraMetadata> &result)
96 {
97     std::shared_lock<std::shared_mutex> lock(callbackLock_);
98     if (callback_ != nullptr) {
99         callback_->OnFocusTrackingInfo(streamId, isNeedMirror, isNeedFlip, result);
100     }
101     return CAMERA_OK;
102 }
103 
OnCaptureSessionConfiged(const CaptureSessionInfo & captureSessionInfo)104 int32_t HMechSession::OnCaptureSessionConfiged(const CaptureSessionInfo& captureSessionInfo)
105 {
106     std::shared_lock<std::shared_mutex> lock(callbackLock_);
107     if (callback_ != nullptr) {
108         callback_->OnCaptureSessionConfiged(captureSessionInfo);
109     }
110     return CAMERA_OK;
111 }
112 
OnZoomInfoChange(int32_t sessionid,const ZoomInfo & zoomInfo)113 int32_t HMechSession::OnZoomInfoChange(int32_t sessionid, const ZoomInfo& zoomInfo)
114 {
115     std::shared_lock<std::shared_mutex> lock(callbackLock_);
116     if (callback_ != nullptr) {
117         callback_->OnZoomInfoChange(sessionid, zoomInfo);
118     }
119     return CAMERA_OK;
120 }
121 
OnSessionStatusChange(int32_t sessionid,bool status)122 int32_t HMechSession::OnSessionStatusChange(int32_t sessionid, bool status)
123 {
124     std::shared_lock<std::shared_mutex> lock(callbackLock_);
125     if (callback_ != nullptr) {
126         callback_->OnSessionStatusChange(sessionid, status);
127     }
128     return CAMERA_OK;
129 }
130 
HanldeOnCaptureSessionConfiged(const sptr<IMechSessionCallback> & callback)131 void HMechSession::HanldeOnCaptureSessionConfiged(const sptr<IMechSessionCallback>& callback)
132 {
133     CHECK_RETURN(callback == nullptr);
134     auto &sessionManager = HCameraSessionManager::GetInstance();
135     std::vector<sptr<HCaptureSession>> userSessions = sessionManager.GetUserSessions(userId_);
136     for (size_t i = 0; i < userSessions.size(); i++) {
137         sptr<HCaptureSession> captureSession = userSessions[i];
138         CaptureSessionInfo sessionInfo;
139         if (captureSession->GetCaptureSessionInfo(sessionInfo)) {
140             callback->OnCaptureSessionConfiged(sessionInfo);
141         }
142     }
143 }
144 } // namespace CameraStandard
145 } // namespace OHOS
146