1 /* 2 * Copyright (c) 2021-2024 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 35 namespace OHOS { 36 namespace DistributedHardware { 37 class DistributedCameraSourceService : public SystemAbility, public DistributedCameraSourceStub { 38 DECLARE_SYSTEM_ABILITY(DistributedCameraSourceService); 39 40 public: 41 DistributedCameraSourceService(int32_t saId, bool runOnCreate); 42 ~DistributedCameraSourceService() override = default; 43 44 int32_t InitSource(const std::string& params, const sptr<IDCameraSourceCallback>& callback) override; 45 int32_t ReleaseSource() override; 46 int32_t RegisterDistributedHardware(const std::string& devId, const std::string& dhId, 47 const std::string& reqId, const EnableParam& param) override; 48 int32_t UnregisterDistributedHardware(const std::string& devId, const std::string& dhId, 49 const std::string& reqId) override; 50 int32_t DCameraNotify(const std::string& devId, const std::string& dhId, std::string& events) override; 51 int Dump(int32_t fd, const std::vector<std::u16string>& args) override; 52 static void GetDumpInfo(CameraDumpInfo& camDump); 53 54 static void CamDevInsert(DCameraIndex& index, std::shared_ptr<DCameraSourceDev>& camDev); 55 static std::shared_ptr<DCameraSourceDev> GetCamDevByIndex(DCameraIndex& index); 56 static void CamDevErase(DCameraIndex& index); 57 static uint32_t GetCamDevNum(); 58 void StartHicollieThread(); 59 60 protected: 61 void OnStart() override; 62 void OnStop() override; 63 DISALLOW_COPY_AND_MOVE(DistributedCameraSourceService); 64 65 private: 66 bool Init(); 67 int32_t LoadDCameraHDF(); 68 int32_t UnLoadCameraHDF(); 69 std::string GetCodecInfo(); 70 71 bool registerToService_ = false; 72 DCameraServiceState state_ = DCameraServiceState::DCAMERA_SRV_STATE_NOT_START; 73 74 std::shared_ptr<ICameraStateListener> listener_; 75 std::string sourceVer_; 76 const size_t MAX_CAMERAS_NUMBER = 32; 77 const size_t DUMP_MAX_SIZE = 10 * 1024; 78 79 static std::map<DCameraIndex, std::shared_ptr<DCameraSourceDev>> camerasMap_; 80 static std::mutex camDevMutex_; 81 std::thread hicollieThread_; 82 std::atomic<bool> isHicollieRunning_ = false; 83 }; 84 } // namespace DistributedHardware 85 } // namespace OHOS 86 #endif // OHOS_DISTRIBUTED_CAMERA_SOURCE_SERVICE_H 87