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 DISTRIBUTED_CAMERA_HOST_H 17 #define DISTRIBUTED_CAMERA_HOST_H 18 19 #include "dcamera_base.h" 20 #include "dcamera_device.h" 21 22 #include "v1_0/icamera_host.h" 23 #include "v1_0/icamera_host_callback.h" 24 #include "v1_0/dcamera_types.h" 25 #include "v1_0/types.h" 26 #include "constants.h" 27 #include "iremote_object.h" 28 29 namespace OHOS { 30 namespace DistributedHardware { 31 using namespace OHOS::HDI::DistributedCamera::V1_0; 32 using namespace OHOS::HDI::Camera::V1_0; 33 class DCameraHost : public ICameraHost { 34 const uint32_t ABILITYINFO_MAX_LENGTH = 50 * 1024 * 1024; 35 const uint32_t ID_MAX_SIZE = 2 * DEVID_MAX_LENGTH; 36 public: 37 DCameraHost() = default; 38 ~DCameraHost() override = default; 39 DCameraHost(const DCameraHost &other) = delete; 40 DCameraHost(DCameraHost &&other) = delete; 41 DCameraHost& operator=(const DCameraHost &other) = delete; 42 DCameraHost& operator=(DCameraHost &&other) = delete; 43 44 public: 45 static OHOS::sptr<DCameraHost> GetInstance(); 46 int32_t SetCallback(const sptr<ICameraHostCallback> &callbackObj) override; 47 int32_t GetCameraIds(std::vector<std::string> &cameraIds) override; 48 int32_t GetCameraAbility(const std::string &cameraId, std::vector<uint8_t> &cameraAbility) override; 49 int32_t OpenCamera(const std::string &cameraId, const sptr<ICameraDeviceCallback> &callbackObj, 50 sptr<ICameraDevice> &device) override; 51 int32_t SetFlashlight(const std::string &cameraId, bool isEnable) override; 52 53 DCamRetCode AddDCameraDevice(const DHBase &dhBase, const std::string &sinkAbilityInfo, 54 const std::string &sourceAbilityInfo, const sptr<IDCameraProviderCallback> &callback); 55 DCamRetCode RemoveDCameraDevice(const DHBase &dhBase); 56 OHOS::sptr<DCameraDevice> GetDCameraDeviceByDHBase(const DHBase &dhBase); 57 void NotifyDCameraStatus(const DHBase &dhBase, int32_t result); 58 59 private: 60 bool IsCameraIdInvalid(const std::string &cameraId); 61 std::string GetCameraIdByDHBase(const DHBase &dhBase); 62 63 private: 64 class AutoRelease { 65 public: AutoRelease()66 AutoRelease() {} ~AutoRelease()67 ~AutoRelease() 68 { 69 if (DCameraHost::instance_ != nullptr) { 70 DCameraHost::instance_ = nullptr; 71 } 72 } 73 }; 74 class DCameraHostRecipient : public IRemoteObject::DeathRecipient { 75 public: 76 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 77 }; 78 sptr<DCameraHostRecipient> dCameraHostRecipient_; 79 static AutoRelease autoRelease_; 80 static OHOS::sptr<DCameraHost> instance_; 81 82 OHOS::sptr<ICameraHostCallback> dCameraHostCallback_; 83 std::map<DCameraBase, std::string> dhBaseHashDCamIdMap_; 84 std::map<std::string, OHOS::sptr<DCameraDevice>> dCameraDeviceMap_; 85 }; 86 } // namespace DistributedHardware 87 } // namespace OHOS 88 #endif // DISTRIBUTED_CAMERA_HOST_H