1 /*
2  * Copyright (c) 2022-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_client.h"
17 #include "camera_impl.h"
18 #include "media_log.h"
19 #include "camera_config.h"
20 #include "frame_config.h"
21 
22 using namespace std;
23 namespace OHOS {
24 namespace Media {
GetInstance()25 CameraDeviceClient *CameraDeviceClient::GetInstance()
26 {
27     static CameraDeviceClient client;
28     return &client;
29 }
30 
CameraDeviceClient()31 CameraDeviceClient::CameraDeviceClient()
32 {
33     cameraService_ = CameraService::GetInstance();
34 }
35 
~CameraDeviceClient()36 CameraDeviceClient::~CameraDeviceClient() {}
37 
SetCameraId(string cameraId)38 void CameraDeviceClient::SetCameraId(string cameraId)
39 {
40     cameraId_ = cameraId;
41 }
42 
SetCameraImpl(CameraImpl * cameraImpl)43 void CameraDeviceClient::SetCameraImpl(CameraImpl *cameraImpl)
44 {
45     cameraImpl_ = cameraImpl;
46 }
SetCameraCallback()47 void CameraDeviceClient::SetCameraCallback() {}
48 
SetCameraConfig(CameraConfig & cc)49 int32_t CameraDeviceClient::SetCameraConfig(CameraConfig &cc)
50 {
51     CameraDevice *device_ = cameraService_->GetCameraDevice(cameraId_);
52     if (device_ == nullptr) {
53         MEDIA_ERR_LOG("device_ is null");
54         return -1;
55     }
56     cc_ = &cc;
57     int32_t ret = device_->SetCameraConfig();
58     cameraImpl_->OnConfigured(ret, *cc_);
59     return ret;
60 }
61 
62 
TriggerLoopingCapture(FrameConfig & fc)63 int32_t CameraDeviceClient::TriggerLoopingCapture(FrameConfig &fc)
64 {
65     CameraDevice *device_ = cameraService_->GetCameraDevice(cameraId_);
66     if (device_ == nullptr) {
67         MEDIA_ERR_LOG("device_ is null");
68         return -1;
69     }
70     uint32_t streamId = 0;
71     return device_->TriggerLoopingCapture(fc, &streamId);
72 }
73 
TriggerSingleCapture(FrameConfig & fc)74 int32_t CameraDeviceClient::TriggerSingleCapture(FrameConfig &fc)
75 {
76     CameraDevice *device_ = cameraService_->GetCameraDevice(cameraId_);
77     if (device_ == nullptr) {
78         MEDIA_ERR_LOG("device_ is null");
79         return -1;
80     }
81     uint32_t streamId = 0;
82     int32_t ret = device_->TriggerSingleCapture(fc, &streamId);
83     cameraImpl_->OnFrameFinished(ret, fc);
84     return ret;
85 }
86 
StopLoopingCapture(int32_t type)87 void CameraDeviceClient::StopLoopingCapture(int32_t type)
88 {
89     CameraDevice *device_ = cameraService_->GetCameraDevice(cameraId_);
90     if (device_ == nullptr) {
91         MEDIA_ERR_LOG("device_ is null");
92         return;
93     }
94     return device_->StopLoopingCapture(type);
95 }
96 
Release()97 void CameraDeviceClient::Release()
98 {
99     cameraService_->CloseCamera(cameraId_);
100 }
101 }
102 }