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