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_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 28 namespace OHOS { 29 namespace DistributedHardware { 30 using namespace OHOS::HDI::DistributedCamera::V1_0; 31 using namespace OHOS::HDI::Camera::V1_0; 32 class DCameraHost : public ICameraHost { 33 const uint32_t ABILITYINFO_MAX_LENGTH = 50 * 1024 * 1024; 34 const uint32_t ID_MAX_SIZE = 2 * DEVID_MAX_LENGTH; 35 public: 36 DCameraHost() = default; 37 ~DCameraHost() override = default; 38 DCameraHost(const DCameraHost &other) = delete; 39 DCameraHost(DCameraHost &&other) = delete; 40 DCameraHost& operator=(const DCameraHost &other) = delete; 41 DCameraHost& operator=(DCameraHost &&other) = delete; 42 43 public: 44 static OHOS::sptr<DCameraHost> GetInstance(); 45 int32_t SetCallback(const sptr<ICameraHostCallback> &callbackObj) override; 46 int32_t GetCameraIds(std::vector<std::string> &cameraIds) override; 47 int32_t GetCameraAbility(const std::string &cameraId, std::vector<uint8_t> &cameraAbility) override; 48 int32_t OpenCamera(const std::string &cameraId, const sptr<ICameraDeviceCallback> &callbackObj, 49 sptr<ICameraDevice> &device) override; 50 int32_t SetFlashlight(const std::string &cameraId, bool isEnable) override; 51 52 DCamRetCode AddDCameraDevice(const DHBase &dhBase, const std::string &abilityInfo, 53 const sptr<IDCameraProviderCallback> &callback); 54 DCamRetCode RemoveDCameraDevice(const DHBase &dhBase); 55 OHOS::sptr<DCameraDevice> GetDCameraDeviceByDHBase(const DHBase &dhBase); 56 void NotifyDCameraStatus(const DHBase &dhBase, int32_t result); 57 58 private: 59 bool IsCameraIdInvalid(const std::string &cameraId); 60 std::string GetCameraIdByDHBase(const DHBase &dhBase); 61 62 private: 63 class AutoRelease { 64 public: AutoRelease()65 AutoRelease() {} ~AutoRelease()66 ~AutoRelease() 67 { 68 if (DCameraHost::instance_ != nullptr) { 69 DCameraHost::instance_ = nullptr; 70 } 71 } 72 }; 73 static AutoRelease autoRelease_; 74 static OHOS::sptr<DCameraHost> instance_; 75 76 OHOS::sptr<ICameraHostCallback> dCameraHostCallback_; 77 std::map<DCameraBase, std::string> dhBaseHashDCamIdMap_; 78 std::map<std::string, OHOS::sptr<DCameraDevice>> dCameraDeviceMap_; 79 }; 80 } // namespace DistributedHardware 81 } // namespace OHOS 82 #endif // DISTRIBUTED_CAMERA_HOST_H