1 /* 2 * Copyright (c) 2021-2022 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_DEVICE_H 17 #define DISTRIBUTED_CAMERA_DEVICE_H 18 19 #include <vector> 20 #include <string> 21 #include "dmetadata_processor.h" 22 #include "dstream_operator.h" 23 24 #include "v1_0/icamera_device.h" 25 #include "v1_0/icamera_device_callback.h" 26 #include "v1_0/id_camera_provider_callback.h" 27 #include "v1_0/types.h" 28 29 namespace OHOS { 30 namespace DistributedHardware { 31 using namespace OHOS::HDI::Camera::V1_0; 32 class DCameraDevice : public ICameraDevice { 33 public: 34 DCameraDevice(const DHBase &dhBase, const std::string &abilityInfo); 35 DCameraDevice() = default; 36 virtual ~DCameraDevice() = default; 37 DCameraDevice(const DCameraDevice &other) = delete; 38 DCameraDevice(DCameraDevice &&other) = delete; 39 DCameraDevice& operator=(const DCameraDevice &other) = delete; 40 DCameraDevice& operator=(DCameraDevice &&other) = delete; 41 42 public: 43 int32_t GetStreamOperator(const sptr<IStreamOperatorCallback> &callbackObj, 44 sptr<IStreamOperator> &streamOperator) override; 45 int32_t UpdateSettings(const std::vector<uint8_t> &settings) override; 46 int32_t GetSettings(std::vector<uint8_t> &settings); 47 int32_t SetResultMode(ResultCallbackMode mode) override; 48 int32_t GetEnabledResults(std::vector<int32_t> &results) override; 49 int32_t EnableResult(const std::vector<int32_t> &results) override; 50 int32_t DisableResult(const std::vector<int32_t> &results) override; 51 int32_t Close() override; 52 53 CamRetCode OpenDCamera(const OHOS::sptr<ICameraDeviceCallback> &callback); 54 CamRetCode GetDCameraAbility(std::shared_ptr<CameraAbility> &ability); 55 DCamRetCode AcquireBuffer(int streamId, DCameraBuffer &buffer); 56 DCamRetCode ShutterBuffer(int streamId, const DCameraBuffer &buffer); 57 DCamRetCode OnSettingsResult(const std::shared_ptr<DCameraSettings> &result); 58 DCamRetCode Notify(const std::shared_ptr<DCameraHDFEvent> &event); 59 void SetProviderCallback(const OHOS::sptr<IDCameraProviderCallback> &callback); 60 OHOS::sptr<IDCameraProviderCallback> GetProviderCallback(); 61 std::string GetDCameraId(); 62 bool IsOpened(); 63 64 private: 65 void Init(const std::string &abilityInfo); 66 DCamRetCode CreateDStreamOperator(); 67 std::string GenerateCameraId(const DHBase &dhBase); 68 void NotifyStartCaptureError(); 69 void NotifyCameraError(const ErrorType type); 70 void IsOpenSessFailedState(bool state); 71 private: 72 bool isOpened_; 73 std::string dCameraId_; 74 DHBase dhBase_; 75 std::string dCameraAbilityInfo_; 76 OHOS::sptr<ICameraDeviceCallback> dCameraDeviceCallback_; 77 OHOS::sptr<IDCameraProviderCallback> dCameraProviderCallback_; 78 OHOS::sptr<DStreamOperator> dCameraStreamOperator_; 79 std::shared_ptr<DMetadataProcessor> dMetadataProcessor_; 80 81 std::mutex openSesslock_; 82 std::condition_variable openSessCV_; 83 bool isOpenSessFailed_ = false; 84 std::mutex isOpenSessFailedlock_; 85 }; 86 } // namespace DistributedHardware 87 } // namespace OHOS 88 #endif // DISTRIBUTED_CAMERA_DEVICE_H 89