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 DISTRIBUTED_CAMERA_PROVIDER_H 17 #define DISTRIBUTED_CAMERA_PROVIDER_H 18 19 #include "v1_1/id_camera_provider.h" 20 21 namespace OHOS { 22 namespace DistributedHardware { 23 using namespace OHOS::HDI::DistributedCamera::V1_1; 24 class DCameraHost; 25 class DCameraDevice; 26 class DCameraProvider : public IDCameraProvider { 27 const uint32_t ABILITYINFO_MAX_LENGTH = 50 * 1024 * 1024; 28 const uint32_t HDF_EVENT_CONTENT_MAX_LENGTH = 50 * 1024 * 1024; 29 const uint32_t SETTING_VALUE_MAX_LENGTH = 50 * 1024 * 1024; 30 public: 31 DCameraProvider() = default; 32 ~DCameraProvider() override = default; 33 DCameraProvider(const DCameraProvider &other) = delete; 34 DCameraProvider(DCameraProvider &&other) = delete; 35 DCameraProvider& operator=(const DCameraProvider &other) = delete; 36 DCameraProvider& operator=(DCameraProvider &&other) = delete; 37 38 public: 39 static OHOS::sptr<DCameraProvider> GetInstance(); 40 int32_t EnableDCameraDevice(const DHBase& dhBase, const std::string& abilityInfo, 41 const sptr<IDCameraProviderCallback>& callbackObj) override; 42 int32_t DisableDCameraDevice(const DHBase& dhBase) override; 43 int32_t AcquireBuffer(const DHBase& dhBase, int32_t streamId, DCameraBuffer& buffer) override; 44 int32_t ShutterBuffer(const DHBase& dhBase, int32_t streamId, const DCameraBuffer& buffer) override; 45 int32_t OnSettingsResult(const DHBase& dhBase, const DCameraSettings& result) override; 46 int32_t Notify(const DHBase& dhBase, const DCameraHDFEvent& event) override; 47 int32_t RegisterCameraHdfListener(const std::string &serviceName, 48 const sptr<IDCameraHdfCallback> &callbackObj) override; 49 int32_t UnRegisterCameraHdfListener(const std::string &serviceName) override; 50 51 int32_t OpenSession(const DHBase &dhBase); 52 int32_t CloseSession(const DHBase &dhBase); 53 int32_t ConfigureStreams(const DHBase &dhBase, const std::vector<DCStreamInfo> &streamInfos); 54 int32_t ReleaseStreams(const DHBase &dhBase, const std::vector<int> &streamIds); 55 int32_t StartCapture(const DHBase &dhBase, const std::vector<DCCaptureInfo> &captureInfos); 56 int32_t StopCapture(const DHBase &dhBase, const std::vector<int> &streamIds); 57 int32_t UpdateSettings(const DHBase &dhBase, const std::vector<DCameraSettings> &settings); 58 59 private: 60 bool IsDCameraSettingsInvalid(const DCameraSettings& result); 61 bool IsDCameraHDFEventInvalid(const DCameraHDFEvent& event); 62 sptr<IDCameraProviderCallback> GetCallbackBydhBase(const DHBase &dhBase); 63 OHOS::sptr<DCameraDevice> GetDCameraDevice(const DHBase &dhBase); 64 bool GetAbilityInfo(const std::string& abilityInfo, std::string& sinkAbilityInfo, 65 std::string& sourceCodecInfo); 66 67 private: 68 class AutoRelease { 69 public: AutoRelease()70 AutoRelease() {} ~AutoRelease()71 ~AutoRelease() 72 { 73 if (DCameraProvider::instance_ != nullptr) { 74 DCameraProvider::instance_ = nullptr; 75 } 76 } 77 }; 78 static AutoRelease autoRelease_; 79 static OHOS::sptr<DCameraProvider> instance_; 80 }; 81 } // namespace DistributedHardware 82 } // namespace OHOS 83 #endif // DISTRIBUTED_CAMERA_PROVIDER_H