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_PROVIDER_H 17 #define DISTRIBUTED_CAMERA_PROVIDER_H 18 19 #include "v1_0/id_camera_provider.h" 20 21 namespace OHOS { 22 namespace DistributedHardware { 23 using namespace OHOS::HDI::DistributedCamera::V1_0; 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 48 int32_t OpenSession(const DHBase &dhBase); 49 int32_t CloseSession(const DHBase &dhBase); 50 int32_t ConfigureStreams(const DHBase &dhBase, const std::vector<DCStreamInfo> &streamInfos); 51 int32_t ReleaseStreams(const DHBase &dhBase, const std::vector<int> &streamIds); 52 int32_t StartCapture(const DHBase &dhBase, const std::vector<DCCaptureInfo> &captureInfos); 53 int32_t StopCapture(const DHBase &dhBase, const std::vector<int> &streamIds); 54 int32_t UpdateSettings(const DHBase &dhBase, const std::vector<DCameraSettings> &settings); 55 56 private: 57 bool IsDCameraSettingsInvalid(const DCameraSettings& result); 58 bool IsDCameraHDFEventInvalid(const DCameraHDFEvent& event); 59 sptr<IDCameraProviderCallback> GetCallbackBydhBase(const DHBase &dhBase); 60 OHOS::sptr<DCameraDevice> GetDCameraDevice(const DHBase &dhBase); 61 62 private: 63 class AutoRelease { 64 public: AutoRelease()65 AutoRelease() {} ~AutoRelease()66 ~AutoRelease() 67 { 68 if (DCameraProvider::instance_ != nullptr) { 69 DCameraProvider::instance_ = nullptr; 70 } 71 } 72 }; 73 static AutoRelease autoRelease_; 74 static OHOS::sptr<DCameraProvider> instance_; 75 }; 76 } // namespace DistributedHardware 77 } // namespace OHOS 78 #endif // DISTRIBUTED_CAMERA_PROVIDER_H