• 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_PROVIDER_H
17 #define DISTRIBUTED_CAMERA_PROVIDER_H
18 
19 #include "dcamera.h"
20 #include "idistributed_camera_provider_callback.h"
21 
22 namespace OHOS {
23 namespace DistributedHardware {
24 class DCameraHost;
25 class DCameraDevice;
26 class DCameraProvider {
27 public:
28     DCameraProvider() = default;
29     virtual ~DCameraProvider() = default;
30     DCameraProvider(const DCameraProvider &other) = delete;
31     DCameraProvider(DCameraProvider &&other) = delete;
32     DCameraProvider& operator=(const DCameraProvider &other) = delete;
33     DCameraProvider& operator=(DCameraProvider &&other) = delete;
34 
35 public:
36     static std::shared_ptr<DCameraProvider> GetInstance();
37     DCamRetCode EnableDCameraDevice(const std::shared_ptr<DHBase> &dhBase, const std::string &abilitySet,
38                                     const sptr<IDCameraProviderCallback> &callback);
39     DCamRetCode DisableDCameraDevice(const std::shared_ptr<DHBase> &dhBase);
40     DCamRetCode AcquireBuffer(const std::shared_ptr<DHBase> &dhBase, int streamId,
41                               std::shared_ptr<DCameraBuffer> &buffer);
42     DCamRetCode ShutterBuffer(const std::shared_ptr<DHBase> &dhBase, int streamId,
43                               const std::shared_ptr<DCameraBuffer> &buffer);
44     DCamRetCode OnSettingsResult(const std::shared_ptr<DHBase> &dhBase, const std::shared_ptr<DCameraSettings> &result);
45     DCamRetCode Notify(const std::shared_ptr<DHBase> &dhBase, const std::shared_ptr<DCameraHDFEvent> &event);
46 
47     DCamRetCode OpenSession(const std::shared_ptr<DHBase> &dhBase);
48     DCamRetCode CloseSession(const std::shared_ptr<DHBase> &dhBase);
49     DCamRetCode ConfigureStreams(const std::shared_ptr<DHBase> &dhBase,
50                                  const std::vector<std::shared_ptr<DCStreamInfo>> &streamInfos);
51     DCamRetCode ReleaseStreams(const std::shared_ptr<DHBase> &dhBase, const std::vector<int> &streamIds);
52     DCamRetCode StartCapture(const std::shared_ptr<DHBase> &dhBase,
53                              const std::vector<std::shared_ptr<DCCaptureInfo>> &captureInfos);
54     DCamRetCode StopCapture(const std::shared_ptr<DHBase> &dhBase);
55     DCamRetCode UpdateSettings(const std::shared_ptr<DHBase> &dhBase,
56                                const std::vector<std::shared_ptr<DCameraSettings>> &settings);
57 
58 private:
59     bool IsDhBaseInfoInvalid(const std::shared_ptr<DHBase> &dhBase);
60     sptr<IDCameraProviderCallback> GetCallbackBydhBase(const std::shared_ptr<DHBase> &dhBase);
61     OHOS::sptr<DCameraDevice> GetDCameraDevice(const std::shared_ptr<DHBase> &dhBase);
62 
63 private:
64     class AutoRelease {
65     public:
AutoRelease()66         AutoRelease() {};
~AutoRelease()67         ~AutoRelease()
68         {
69             if (DCameraProvider::instance_ != nullptr) {
70                 DCameraProvider::instance_ = nullptr;
71             }
72         };
73     };
74     static AutoRelease autoRelease_;
75     static std::shared_ptr<DCameraProvider> instance_;
76 };
77 } // end namespace DistributedHardware
78 } // end namespace OHOS
79 #endif // DISTRIBUTED_CAMERA_PROVIDER_H