• 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     OHOS::sptr<IStreamOperatorVdi> streamOperatorVdi = nullptr;
31     CHECK_IF_PTR_NULL_RETURN_VALUE(cameraDeviceServiceVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT);
32     OHOS::sptr<IStreamOperatorVdiCallback> vdiCallbackObj = new StreamOperatorServiceCallback(callbackObj);
33     if (vdiCallbackObj == nullptr) {
34         CAMERA_LOGE("Get stream operator error, vdiCallbackObj is nullptr");
35         return OHOS::HDI::Camera::V1_0::INSUFFICIENT_RESOURCES;
36     }
37     int32_t ret = cameraDeviceServiceVdi_->GetStreamOperator(vdiCallbackObj, streamOperatorVdi);
38     if (ret != OHOS::HDI::Camera::V1_0::NO_ERROR) {
39         CAMERA_LOGE("Get stream operator error, ret=%{public}d", ret);
40         return ret;
41     }
42     if (streamOperatorVdi == nullptr) {
43         CAMERA_LOGE("Get stream operator error, streamOperatorVdi is nullptr");
44         return OHOS::HDI::Camera::V1_0::INSUFFICIENT_RESOURCES;
45     }
46     streamOperator = new StreamOperatorService(streamOperatorVdi);
47     if (streamOperator == nullptr) {
48         CAMERA_LOGE("Get stream operator error, streamOperator is nullptr");
49         return OHOS::HDI::Camera::V1_0::INSUFFICIENT_RESOURCES;
50     }
51 
52     return OHOS::HDI::Camera::V1_0::NO_ERROR;
53 }
54 
UpdateSettings(const std::vector<uint8_t> & settings)55 int32_t CameraDeviceService::UpdateSettings(const std::vector<uint8_t> &settings)
56 {
57     CHECK_IF_PTR_NULL_RETURN_VALUE(cameraDeviceServiceVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT);
58     return cameraDeviceServiceVdi_->UpdateSettings(settings);
59 }
60 
SetResultMode(ResultCallbackMode mode)61 int32_t CameraDeviceService::SetResultMode(ResultCallbackMode mode)
62 {
63     CHECK_IF_PTR_NULL_RETURN_VALUE(cameraDeviceServiceVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT);
64     return cameraDeviceServiceVdi_->SetResultMode(static_cast<VdiResultCallbackMode>(mode));
65 }
66 
GetEnabledResults(std::vector<int32_t> & results)67 int32_t CameraDeviceService::GetEnabledResults(std::vector<int32_t> &results)
68 {
69     CHECK_IF_PTR_NULL_RETURN_VALUE(cameraDeviceServiceVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT);
70     return cameraDeviceServiceVdi_->GetEnabledResults(results);
71 }
72 
EnableResult(const std::vector<int32_t> & results)73 int32_t CameraDeviceService::EnableResult(const std::vector<int32_t> &results)
74 {
75     CHECK_IF_PTR_NULL_RETURN_VALUE(cameraDeviceServiceVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT);
76     return cameraDeviceServiceVdi_->EnableResult(results);
77 }
78 
DisableResult(const std::vector<int32_t> & results)79 int32_t CameraDeviceService::DisableResult(const std::vector<int32_t> &results)
80 {
81     CHECK_IF_PTR_NULL_RETURN_VALUE(cameraDeviceServiceVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT);
82     return cameraDeviceServiceVdi_->DisableResult(results);
83 }
84 
Close()85 int32_t CameraDeviceService::Close()
86 {
87     CHECK_IF_PTR_NULL_RETURN_VALUE(cameraDeviceServiceVdi_, OHOS::HDI::Camera::V1_0::INVALID_ARGUMENT);
88     return cameraDeviceServiceVdi_->Close();
89 }
90 } // end namespace OHOS::Camera
91