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 "session/control_center_session.h"
17 #include "ability/camera_ability_const.h"
18 #include "camera_log.h"
19 #include "camera_manager.h"
20 #include <cstdint>
21 #include "camera_util.h"
22
23 namespace OHOS {
24 namespace CameraStandard {
25
ControlCenterSession()26 ControlCenterSession::ControlCenterSession()
27 {
28 MEDIA_INFO_LOG("Enter Into ControlCenterSession::ControlCenterSession()");
29 }
30
~ControlCenterSession()31 ControlCenterSession::~ControlCenterSession()
32 {
33 MEDIA_INFO_LOG("Enter Into ControlCenterSession::~ControlCenterSession()");
34 }
35
Release()36 int32_t ControlCenterSession::Release()
37 {
38 MEDIA_INFO_LOG("ControlCenterSession::Release()");
39 return CAMERA_OK;
40 }
41
GetSupportedVirtualApertures(std::vector<float> & apertures)42 int32_t ControlCenterSession::GetSupportedVirtualApertures(std::vector<float>& apertures)
43 {
44 MEDIA_INFO_LOG("ControlCenterSession::GetSupportedVirtualApertures");
45 CHECK_RETURN_RET_ELOG(!CheckIsSupportControlCenter(), CAMERA_INVALID_STATE,
46 "Current status does not support control center.");
47 sptr<ICaptureSession> session = nullptr;
48 auto serviceProxy = CameraManager::GetInstance()->GetServiceProxy();
49 CHECK_RETURN_RET_ELOG(serviceProxy == nullptr, CAMERA_INVALID_ARG,
50 "ControlCenterSession::GetSupportedVirtualApertures serviceProxy is null");
51 auto ret = serviceProxy->GetVideoSessionForControlCenter(session);
52 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK || session == nullptr, ret,
53 "ControlCenterSession::GetSupportedVirtualApertures failed, session is nullptr.");
54 ret = session->GetVirtualApertureMetadate(apertures);
55 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, ret,
56 "ControlCenterSession::GetSupportedVirtualApertures failed, get apertures failed.");
57 return CAMERA_OK;
58 }
59
GetVirtualAperture(float & aperture)60 int32_t ControlCenterSession::GetVirtualAperture(float& aperture)
61 {
62 MEDIA_INFO_LOG("ControlCenterSession::GetVirtualAperture");
63 CHECK_RETURN_RET_ELOG(!CheckIsSupportControlCenter(), CAMERA_INVALID_STATE,
64 "Current status does not support control center.");
65 sptr<ICaptureSession> session = nullptr;
66 auto serviceProxy = CameraManager::GetInstance()->GetServiceProxy();
67 CHECK_RETURN_RET_ELOG(serviceProxy == nullptr, CAMERA_INVALID_ARG,
68 "ControlCenterSession::GetVirtualAperture serviceProxy is null");
69 auto ret = serviceProxy->GetVideoSessionForControlCenter(session);
70 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK || session == nullptr, ret,
71 "ControlCenterSession::GetVirtualAperture failed, session is nullptr.");
72 ret = session->GetVirtualApertureValue(aperture);
73 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, ret,
74 "ControlCenterSession::GetVirtualAperture failed, get aperture failed.");
75 return CAMERA_OK;
76 }
77
SetVirtualAperture(const float virtualAperture)78 int32_t ControlCenterSession::SetVirtualAperture(const float virtualAperture)
79 {
80 MEDIA_INFO_LOG("ControlCenterSession::SetVirtualAperture");
81 CHECK_RETURN_RET_ELOG(!CheckIsSupportControlCenter(), CAMERA_INVALID_STATE,
82 "Current status does not support control center.");
83 sptr<ICaptureSession> session = nullptr;
84 auto serviceProxy = CameraManager::GetInstance()->GetServiceProxy();
85 CHECK_RETURN_RET_ELOG(serviceProxy == nullptr, CAMERA_INVALID_ARG,
86 "ControlCenterSession::SetVirtualAperture serviceProxy is null");
87
88 auto ret = serviceProxy->GetVideoSessionForControlCenter(session);
89 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK || session == nullptr, ret,
90 "ControlCenterSession::SetVirtualAperture failed, session is nullptr.");
91
92 ret = session->SetVirtualApertureValue(virtualAperture, true);
93 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, ret,
94 "ControlCenterSession::SetVirtualAperture failed, set apertures failed.");
95 MEDIA_INFO_LOG("SetVirtualAperture success, value: %{public}f", virtualAperture);
96 return CAMERA_OK;
97 }
98
GetSupportedPhysicalApertures(std::vector<std::vector<float>> & apertures)99 int32_t ControlCenterSession::GetSupportedPhysicalApertures(std::vector<std::vector<float>>& apertures)
100 {
101 return CameraErrorCode::INVALID_ARGUMENT;
102 }
103
GetPhysicalAperture(float & aperture)104 int32_t ControlCenterSession::GetPhysicalAperture(float& aperture)
105 {
106 return CameraErrorCode::INVALID_ARGUMENT;
107 }
108
SetPhysicalAperture(float physicalAperture)109 int32_t ControlCenterSession::SetPhysicalAperture(float physicalAperture)
110 {
111 return CameraErrorCode::INVALID_ARGUMENT;
112 }
113
GetSupportedBeautyTypes()114 std::vector<int32_t> ControlCenterSession::GetSupportedBeautyTypes()
115 {
116 MEDIA_INFO_LOG("ControlCenterSession::GetSupportedBeautyTypes");
117 CHECK_RETURN_RET_ELOG(!CheckIsSupportControlCenter(), {},
118 "Current status does not support control center.");
119 sptr<ICaptureSession> session = nullptr;
120 std::vector<int32_t> metadata = {};
121 auto serviceProxy = CameraManager::GetInstance()->GetServiceProxy();
122 CHECK_RETURN_RET_ELOG(serviceProxy == nullptr, metadata,
123 "ControlCenterSession::GetSupportedBeautyTypes serviceProxy is null");
124 auto ret = serviceProxy->GetVideoSessionForControlCenter(session);
125 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK || session == nullptr, metadata,
126 "ControlCenterSession::GetSupportedBeautyTypes failed, session is nullptr.");
127 ret = session->GetBeautyMetadata(metadata);
128 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, metadata,
129 "ControlCenterSession::GetSupportedBeautyTypes failed, get beauty metadata failed.");
130 return metadata;
131 }
132
GetSupportedBeautyRange(BeautyType type)133 std::vector<int32_t> ControlCenterSession::GetSupportedBeautyRange(BeautyType type)
134 {
135 MEDIA_INFO_LOG("ControlCenterSession::GetSupportedBeautyRange");
136 CHECK_RETURN_RET_ELOG(!CheckIsSupportControlCenter(), {},
137 "Current status does not support control center.");
138 sptr<ICaptureSession> session = nullptr;
139 std::vector<int32_t> metadata = {};
140 auto serviceProxy = CameraManager::GetInstance()->GetServiceProxy();
141 CHECK_RETURN_RET_ELOG(serviceProxy == nullptr, metadata,
142 "ControlCenterSession::GetSupportedBeautyRange serviceProxy is null");
143
144 auto ret = serviceProxy->GetVideoSessionForControlCenter(session);
145 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK || session == nullptr, metadata,
146 "ControlCenterSession::GetSupportedBeautyRange failed, session is nullptr.");
147 ret = session->GetBeautyRange(metadata, type);
148 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, metadata,
149 "ControlCenterSession::GetSupportedBeautyRange failed, get beauty range failed.");
150 return metadata;
151 }
152
153
SetBeauty(BeautyType type,int value)154 void ControlCenterSession::SetBeauty(BeautyType type, int value)
155 {
156 MEDIA_INFO_LOG("ControlCenterSession::SetBeauty");
157 CHECK_RETURN_ELOG(!CheckIsSupportControlCenter(), "Current status does not support control center.");
158 sptr<ICaptureSession> session = nullptr;
159 auto serviceProxy = CameraManager::GetInstance()->GetServiceProxy();
160 CHECK_RETURN_ELOG(serviceProxy == nullptr,
161 "ControlCenterSession::SetBeauty serviceProxy is null");
162 auto ret = serviceProxy->GetVideoSessionForControlCenter(session);
163 CHECK_RETURN_ELOG(ret != CAMERA_OK || session == nullptr,
164 "ControlCenterSession::SetBeauty failed, session is nullptr.");
165 ret = session->SetBeautyValue(type, value, true);
166 CHECK_RETURN_ELOG(ret != CAMERA_OK,
167 "ControlCenterSession::SetBeauty failed, set beauty failed.");
168 MEDIA_INFO_LOG("SetBeauty success value: %{public}d", value);
169 }
170
GetBeauty(BeautyType type)171 int32_t ControlCenterSession::GetBeauty(BeautyType type)
172 {
173 MEDIA_INFO_LOG("ControlCenterSession::GetBeauty");
174 CHECK_RETURN_RET_ELOG(!CheckIsSupportControlCenter(), 0, "Current status does not support control center.");
175 sptr<ICaptureSession> session = nullptr;
176 int32_t value = 0;
177 auto serviceProxy = CameraManager::GetInstance()->GetServiceProxy();
178 CHECK_RETURN_RET_ELOG(serviceProxy == nullptr, value,
179 "ControlCenterSession::GetBeauty serviceProxy is null");
180 auto ret = serviceProxy->GetVideoSessionForControlCenter(session);
181 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK || session == nullptr, value,
182 "ControlCenterSession::GetBeauty failed, session is nullptr.");
183 ret = session->GetBeautyValue(type, value);
184 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, value,
185 "ControlCenterSession::GetBeauty failed, get beauty failed.");
186 MEDIA_INFO_LOG("GetBeauty success value:%{public}d", value);
187 return value;
188 }
189
GetSupportedPortraitThemeTypes(std::vector<PortraitThemeType> & types)190 int32_t ControlCenterSession::GetSupportedPortraitThemeTypes(std::vector<PortraitThemeType>& types)
191 {
192 return CameraErrorCode::INVALID_ARGUMENT;
193 }
194
IsPortraitThemeSupported(bool & isSupported)195 int32_t ControlCenterSession::IsPortraitThemeSupported(bool &isSupported)
196 {
197 return CameraErrorCode::INVALID_ARGUMENT;
198 }
199
IsPortraitThemeSupported()200 bool ControlCenterSession::IsPortraitThemeSupported()
201 {
202 return false;
203 }
204
SetPortraitThemeType(PortraitThemeType type)205 int32_t ControlCenterSession::SetPortraitThemeType(PortraitThemeType type)
206 {
207 return CameraErrorCode::INVALID_ARGUMENT;
208 }
209
CheckIsSupportControlCenter()210 bool ControlCenterSession::CheckIsSupportControlCenter()
211 {
212 return CameraManager::GetInstance()->GetIsControlCenterSupported();
213 }
214
215 } // namespace CameraStandard
216 } // namespace OHOS