1 /*
2 * Copyright (c) 2023-2023 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_log.h"
18 #include "camera_util.h"
19
20 using namespace std;
21 using namespace OHOS;
22 using namespace OHOS::CameraStandard;
23
24 class InnerCameraInputCallback : public ErrorCallback {
25 public:
InnerCameraInputCallback(Camera_Input * cameraInput,CameraInput_Callbacks * callback)26 InnerCameraInputCallback(Camera_Input* cameraInput, CameraInput_Callbacks* callback)
27 : cameraInput_(cameraInput), callback_(*callback) {}
28 ~InnerCameraInputCallback() = default;
OnError(const int32_t errorType,const int32_t errorMsg) const29 void OnError(const int32_t errorType, const int32_t errorMsg) const override
30 {
31 MEDIA_DEBUG_LOG("OnError is called!, errorType: %{public}d", errorType);
32 if (cameraInput_ != nullptr && callback_.onError != nullptr) {
33 callback_.onError(cameraInput_, FrameworkToNdkCameraError(errorType));
34 }
35 }
36
37 private:
38 Camera_Input* cameraInput_;
39 CameraInput_Callbacks callback_;
40 };
41
Camera_Input(sptr<CameraInput> & innerCameraInput)42 Camera_Input::Camera_Input(sptr<CameraInput> &innerCameraInput) : innerCameraInput_(innerCameraInput)
43 {
44 MEDIA_DEBUG_LOG("Camera_Input Constructor is called");
45 }
46
~Camera_Input()47 Camera_Input::~Camera_Input()
48 {
49 MEDIA_DEBUG_LOG("~Camera_Input is called");
50 CHECK_RETURN(!innerCameraInput_);
51 innerCameraInput_ = nullptr;
52 }
53
RegisterCallback(CameraInput_Callbacks * callback)54 Camera_ErrorCode Camera_Input::RegisterCallback(CameraInput_Callbacks* callback)
55 {
56 shared_ptr<InnerCameraInputCallback> innerCallback =
57 make_shared<InnerCameraInputCallback>(this, callback);
58 innerCameraInput_->SetErrorCallback(innerCallback);
59 return CAMERA_OK;
60 }
61
UnregisterCallback(CameraInput_Callbacks * callback)62 Camera_ErrorCode Camera_Input::UnregisterCallback(CameraInput_Callbacks* callback)
63 {
64 innerCameraInput_->SetErrorCallback(nullptr);
65 return CAMERA_OK;
66 }
67
Open()68 Camera_ErrorCode Camera_Input::Open()
69 {
70 int32_t ret = innerCameraInput_->Open();
71 return FrameworkToNdkCameraError(ret);
72 }
73
OpenSecureCamera(uint64_t * secureSeqId)74 Camera_ErrorCode Camera_Input::OpenSecureCamera(uint64_t* secureSeqId)
75 {
76 int32_t ret = innerCameraInput_->Open(true, secureSeqId);
77 MEDIA_INFO_LOG("Camera_Input::OpenSecureCamera secureSeqId = %{public}" PRIu64 "", *secureSeqId);
78 return FrameworkToNdkCameraError(ret);
79 }
80
OpenConcurrentCameras(Camera_ConcurrentType type)81 Camera_ErrorCode Camera_Input::OpenConcurrentCameras(Camera_ConcurrentType type)
82 {
83 int32_t ret = innerCameraInput_->Open(type);
84 MEDIA_INFO_LOG("Camera_Input::OpenSecureCamera secureSeqId = %{public}" PRId32 "", type);
85 return FrameworkToNdkCameraError(ret);
86 }
87
Close()88 Camera_ErrorCode Camera_Input::Close()
89 {
90 int32_t ret = innerCameraInput_->Close();
91 return FrameworkToNdkCameraError(ret);
92 }
93
Release()94 Camera_ErrorCode Camera_Input::Release()
95 {
96 int32_t ret = innerCameraInput_->Release();
97 return FrameworkToNdkCameraError(ret);
98 }
99
GetInnerCameraInput()100 sptr<CameraInput> Camera_Input::GetInnerCameraInput()
101 {
102 return innerCameraInput_;
103 }