• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_device_service.h"
17 #include "stream_operator_service_callback.h"
18 
19 namespace OHOS::Camera {
20 
CameraDeviceService(OHOS::sptr<ICameraDeviceVdi> cameraDeviceServiceVdi)21 CameraDeviceService::CameraDeviceService(OHOS::sptr<ICameraDeviceVdi> cameraDeviceServiceVdi)
22     : cameraDeviceServiceVdi_(cameraDeviceServiceVdi)
23 {
24     CAMERA_LOGD("ctor, instance");
25 }
26 
GetStreamOperator(const sptr<IStreamOperatorCallback> & callbackObj,sptr<IStreamOperator> & streamOperator)27 int32_t CameraDeviceService::GetStreamOperator(const sptr<IStreamOperatorCallback> &callbackObj,
28     sptr<IStreamOperator> &streamOperator)
29 {
30     CameraHalHicollie cameraHalHicollie("CameraHost:GetStreamOperator");
31     OHOS::sptr<IStreamOperatorVdi> streamOperatorVdi = nullptr;
32     CHECK_IF_PTR_NULL_RETURN_VALUE(cameraDeviceServiceVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT);
33     OHOS::sptr<IStreamOperatorVdiCallback> vdiCallbackObj = new StreamOperatorServiceCallback(callbackObj);
34     if (vdiCallbackObj == nullptr) {
35         CAMERA_LOGE("Get stream operator error, vdiCallbackObj is nullptr");
36         return OHOS::HDI::Camera::V1_0::INSUFFICIENT_RESOURCES;
37     }
38     int32_t ret = cameraDeviceServiceVdi_->GetStreamOperator(vdiCallbackObj, streamOperatorVdi);
39     if (ret != OHOS::HDI::Camera::V1_0::NO_ERROR) {
40         CAMERA_LOGE("Get stream operator error, ret=%{public}d", ret);
41         return ret;
42     }
43     if (streamOperatorVdi == nullptr) {
44         CAMERA_LOGE("Get stream operator error, streamOperatorVdi is nullptr");
45         return OHOS::HDI::Camera::V1_0::INSUFFICIENT_RESOURCES;
46     }
47     streamOperator = new StreamOperatorService(streamOperatorVdi);
48     if (streamOperator == nullptr) {
49         CAMERA_LOGE("Get stream operator error, streamOperator is nullptr");
50         return OHOS::HDI::Camera::V1_0::INSUFFICIENT_RESOURCES;
51     }
52 
53     return OHOS::HDI::Camera::V1_0::NO_ERROR;
54 }
55 
UpdateSettings(const std::vector<uint8_t> & settings)56 int32_t CameraDeviceService::UpdateSettings(const std::vector<uint8_t> &settings)
57 {
58     CameraHalHicollie cameraHalHicollie("CameraHost:UpdateSettings");
59     CHECK_IF_PTR_NULL_RETURN_VALUE(cameraDeviceServiceVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT);
60     return cameraDeviceServiceVdi_->UpdateSettings(settings);
61 }
62 
SetResultMode(ResultCallbackMode mode)63 int32_t CameraDeviceService::SetResultMode(ResultCallbackMode mode)
64 {
65     CameraHalHicollie cameraHalHicollie("CameraHost:SetResultMode");
66     CHECK_IF_PTR_NULL_RETURN_VALUE(cameraDeviceServiceVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT);
67     return cameraDeviceServiceVdi_->SetResultMode(static_cast<VdiResultCallbackMode>(mode));
68 }
69 
GetEnabledResults(std::vector<int32_t> & results)70 int32_t CameraDeviceService::GetEnabledResults(std::vector<int32_t> &results)
71 {
72     CameraHalHicollie cameraHalHicollie("CameraHost:GetEnabledResults");
73     CHECK_IF_PTR_NULL_RETURN_VALUE(cameraDeviceServiceVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT);
74     return cameraDeviceServiceVdi_->GetEnabledResults(results);
75 }
76 
EnableResult(const std::vector<int32_t> & results)77 int32_t CameraDeviceService::EnableResult(const std::vector<int32_t> &results)
78 {
79     CameraHalHicollie cameraHalHicollie("CameraHost:EnableResult");
80     CHECK_IF_PTR_NULL_RETURN_VALUE(cameraDeviceServiceVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT);
81     return cameraDeviceServiceVdi_->EnableResult(results);
82 }
83 
DisableResult(const std::vector<int32_t> & results)84 int32_t CameraDeviceService::DisableResult(const std::vector<int32_t> &results)
85 {
86     CameraHalHicollie cameraHalHicollie("CameraHost:DisableResult");
87     CHECK_IF_PTR_NULL_RETURN_VALUE(cameraDeviceServiceVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT);
88     return cameraDeviceServiceVdi_->DisableResult(results);
89 }
90 
Close()91 int32_t CameraDeviceService::Close()
92 {
93     CameraHalHicollie cameraHalHicollie("CameraHost:Close");
94     CHECK_IF_PTR_NULL_RETURN_VALUE(cameraDeviceServiceVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT);
95     return cameraDeviceServiceVdi_->Close();
96 }
97 } // end namespace OHOS::Camera
98