• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 OHOS_DISTRIBUTED_CAMERA_SOURCE_SERVICE_H
17 #define OHOS_DISTRIBUTED_CAMERA_SOURCE_SERVICE_H
18 
19 #include <memory>
20 #include <mutex>
21 #include <map>
22 #include <thread>
23 #include <vector>
24 
25 #include "system_ability.h"
26 #include "ipc_object_stub.h"
27 
28 #include "dcamera_source_hidumper.h"
29 #include "dcamera_index.h"
30 #include "dcamera_service_state_listener.h"
31 #include "dcamera_source_dev.h"
32 #include "distributed_camera_constants.h"
33 #include "distributed_camera_source_stub.h"
34 #include "distributed_hardware_fwk_kit.h"
35 
36 namespace OHOS {
37 namespace DistributedHardware {
38 class DistributedCameraSourceService : public SystemAbility, public DistributedCameraSourceStub {
39 DECLARE_SYSTEM_ABILITY(DistributedCameraSourceService);
40 
41 public:
42     DistributedCameraSourceService(int32_t saId, bool runOnCreate);
43     ~DistributedCameraSourceService() override = default;
44 
45     int32_t InitSource(const std::string& params, const sptr<IDCameraSourceCallback>& callback) override;
46     int32_t ReleaseSource() override;
47     int32_t RegisterDistributedHardware(const std::string& devId, const std::string& dhId,
48         const std::string& reqId, const EnableParam& param) override;
49     int32_t UnregisterDistributedHardware(const std::string& devId, const std::string& dhId,
50         const std::string& reqId) override;
51     int32_t DCameraNotify(const std::string& devId, const std::string& dhId, std::string& events) override;
52     int Dump(int32_t fd, const std::vector<std::u16string>& args) override;
53     static void GetDumpInfo(CameraDumpInfo& camDump);
54 
55     static void CamDevInsert(DCameraIndex& index, std::shared_ptr<DCameraSourceDev>& camDev);
56     static std::shared_ptr<DCameraSourceDev> GetCamDevByIndex(DCameraIndex& index);
57     static void CamDevErase(DCameraIndex& index);
58     static uint32_t GetCamDevNum();
59     void StartHicollieThread();
60 
61 protected:
62     void OnStart() override;
63     void OnStop() override;
64     DISALLOW_COPY_AND_MOVE(DistributedCameraSourceService);
65 
66 private:
67     bool Init();
68     int32_t LoadDCameraHDF();
69     int32_t UnLoadCameraHDF();
70     std::string GetCodecInfo();
71     std::shared_ptr<DistributedHardwareFwkKit> GetDHFwkKit();
72 
73     bool registerToService_ = false;
74     DCameraServiceState state_ = DCameraServiceState::DCAMERA_SRV_STATE_NOT_START;
75 
76     std::shared_ptr<ICameraStateListener> listener_;
77     std::string sourceVer_;
78     const size_t MAX_CAMERAS_NUMBER = 32;
79     const size_t DUMP_MAX_SIZE = 10 * 1024;
80 
81     static std::map<DCameraIndex, std::shared_ptr<DCameraSourceDev>> camerasMap_;
82     static std::mutex camDevMutex_;
83     std::thread hicollieThread_;
84     std::atomic<bool> isHicollieRunning_ = false;
85     std::shared_ptr<DistributedHardwareFwkKit> dHFwkKit_;
86     std::mutex dHFwkKitMutex_;
87 };
88 } // namespace DistributedHardware
89 } // namespace OHOS
90 #endif // OHOS_DISTRIBUTED_CAMERA_SOURCE_SERVICE_H
91