1 /*
2 * Copyright (c) 2024 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 "camera_input_impl.h"
17 #include "camera_error.h"
18 #include <cstdlib>
19 #include <iomanip>
20 #include <map>
21 #include <string>
22 #include <variant>
23 #include <vector>
24 #include "camera_log.h"
25 #include "camera_utils.h"
26 #include "cj_lambda.h"
27 #include "ffi_remote_data.h"
28 #include "securec.h"
29
30 using namespace OHOS::FFI;
31
32 namespace OHOS {
33 namespace CameraStandard {
OnError(const int32_t errorType,const int32_t errorMsg) const34 void CJErrorCallbackListener::OnError(const int32_t errorType, const int32_t errorMsg) const
35 {
36 ExecuteCallback(errorType, errorMsg);
37 }
38
CJCameraInput(sptr<CameraInput> cameraInputInstance)39 CJCameraInput::CJCameraInput(sptr<CameraInput> cameraInputInstance)
40 {
41 cameraInput_ = cameraInputInstance;
42 }
43
~CJCameraInput()44 CJCameraInput::~CJCameraInput()
45 {
46 }
47
GetCameraInput()48 sptr<CameraStandard::CameraInput> CJCameraInput::GetCameraInput()
49 {
50 return cameraInput_;
51 }
52
Open()53 int32_t CJCameraInput::Open()
54 {
55 if (cameraInput_ == nullptr) {
56 return CameraError::CAMERA_SERVICE_ERROR;
57 }
58 return cameraInput_->Open();
59 }
60
Open(bool isEnableSecureCamera,uint64_t * secureSeqId)61 int32_t CJCameraInput::Open(bool isEnableSecureCamera, uint64_t *secureSeqId)
62 {
63 if (cameraInput_ == nullptr) {
64 return CameraError::CAMERA_SERVICE_ERROR;
65 }
66 return cameraInput_->Open(isEnableSecureCamera, secureSeqId);
67 }
68
Close()69 int32_t CJCameraInput::Close()
70 {
71 if (cameraInput_ == nullptr) {
72 return CameraError::CAMERA_SERVICE_ERROR;
73 }
74 return cameraInput_->Close();
75 }
76
OnError(int64_t callbackId)77 void CJCameraInput::OnError(int64_t callbackId)
78 {
79 if (errorCallback_ == nullptr) {
80 errorCallback_ = std::make_shared<CJErrorCallbackListener>();
81 if (errorCallback_ == nullptr || cameraInput_ == nullptr) {
82 return;
83 }
84 cameraInput_->SetErrorCallback(errorCallback_);
85 }
86 auto cFunc = reinterpret_cast<void (*)(CJErrorCallback error)>(callbackId);
87 auto callback = [lambda = CJLambda::Create(cFunc)](const int32_t errorType, const int32_t errorMsg) -> void {
88 lambda(ErrorCallBackToCJErrorCallBack(errorType, errorMsg));
89 };
90 auto callbackRef = std::make_shared<CallbackRef<const int32_t, const int32_t>>(callback, callbackId);
91 errorCallback_->SaveCallbackRef(callbackRef);
92 }
93
OffError(int64_t callbackId)94 void CJCameraInput::OffError(int64_t callbackId)
95 {
96 if (errorCallback_ == nullptr) {
97 return;
98 }
99 errorCallback_->RemoveCallbackRef(callbackId);
100 }
101
OffAllError()102 void CJCameraInput::OffAllError()
103 {
104 if (errorCallback_ == nullptr) {
105 return;
106 }
107 errorCallback_->RemoveAllCallbackRef();
108 }
109
110 } // namespace CameraStandard
111 } // namespace OHOS