• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #ifndef DISTRIBUTED_CAMERA_DEVICE_H
17 #define DISTRIBUTED_CAMERA_DEVICE_H
18 
19 #include <vector>
20 #include <string>
21 #include "dcamera_device_stub.h"
22 #include "dmetadata_processor.h"
23 #include "dstream_operator.h"
24 #include "icamera_device_callback.h"
25 #include "idistributed_camera_provider_callback.h"
26 #include "types.h"
27 
28 namespace OHOS {
29 namespace DistributedHardware {
30 class DCameraDevice : public DCameraDeviceStub {
31 public:
32     DCameraDevice(const std::shared_ptr<DHBase> &dhBase, const std::string &abilityInfo);
33     DCameraDevice() = default;
34     virtual ~DCameraDevice() = default;
35     DCameraDevice(const DCameraDevice &other) = delete;
36     DCameraDevice(DCameraDevice &&other) = delete;
37     DCameraDevice& operator=(const DCameraDevice &other) = delete;
38     DCameraDevice& operator=(DCameraDevice &&other) = delete;
39 
40 public:
41     CamRetCode GetStreamOperator(const OHOS::sptr<IStreamOperatorCallback> &callback,
42                                  OHOS::sptr<IStreamOperator> &streamOperator) override;
43     CamRetCode UpdateSettings(const std::shared_ptr<CameraSetting> &settings) override;
44     CamRetCode SetResultMode(const ResultCallbackMode &mode) override;
45     CamRetCode GetEnabledResults(std::vector<MetaType> &results) override;
46     CamRetCode EnableResult(const std::vector<MetaType> &results) override;
47     CamRetCode DisableResult(const std::vector<MetaType> &results) override;
48     void Close() override;
49 
50     CamRetCode OpenDCamera(const OHOS::sptr<ICameraDeviceCallback> &callback);
51     CamRetCode GetDCameraAbility(std::shared_ptr<CameraAbility> &ability);
52     DCamRetCode AcquireBuffer(int streamId, std::shared_ptr<DCameraBuffer> &buffer);
53     DCamRetCode ShutterBuffer(int streamId, const std::shared_ptr<DCameraBuffer> &buffer);
54     DCamRetCode OnSettingsResult(const std::shared_ptr<DCameraSettings> &result);
55     DCamRetCode Notify(const std::shared_ptr<DCameraHDFEvent> &event);
56     void SetProviderCallback(const OHOS::sptr<IDCameraProviderCallback> &callback);
57     OHOS::sptr<IDCameraProviderCallback> GetProviderCallback();
58     std::string GetDCameraId();
59     bool IsOpened();
60 
61 private:
62     void Init(const std::string &abilityInfo);
63     DCamRetCode CreateDStreamOperator();
64     std::string GenerateCameraId(const std::shared_ptr<DHBase> &dhBase);
65 
66 private:
67     bool isOpened_;
68     std::string dCameraId_;
69     std::shared_ptr<DHBase> dhBase_;
70     std::string dCameraAbilityInfo_;
71     OHOS::sptr<ICameraDeviceCallback> dCameraDeviceCallback_;
72     OHOS::sptr<IDCameraProviderCallback> dCameraProviderCallback_;
73     OHOS::sptr<DStreamOperator> dCameraStreamOperator_;
74     std::shared_ptr<DMetadataProcessor> dMetadataProcessor_;
75 
76     std::mutex openSesslock_;
77     std::condition_variable openSessCV_;
78     bool isOpenSessFailed_ = false;
79     std::mutex isOpenSessFailedlock_;
80 };
81 } // end namespace DistributedHardware
82 } // end namespace OHOS
83 
84 #endif // DISTRIBUTED_CAMERA_DEVICE_H