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 CAMERA_DEVICE_CAMERA_DEVICE_IMPL_H 17 #define CAMERA_DEVICE_CAMERA_DEVICE_IMPL_H 18 19 #include "v1_0/icamera_device.h" 20 #include "v1_0/icamera_device_callback.h" 21 #include "camera.h" 22 #include "camera_metadata_info.h" 23 #include "stream_operator.h" 24 #include <mutex> 25 26 namespace OHOS::Camera { 27 using namespace OHOS::HDI::Camera::V1_0; 28 class IPipelineCore; 29 class CameraDeviceImpl : public ICameraDevice, public std::enable_shared_from_this<CameraDeviceImpl> { 30 public: 31 CameraDeviceImpl(const std::string &cameraId, 32 const std::shared_ptr<IPipelineCore> &pipelineCore); 33 CameraDeviceImpl() = default; 34 virtual ~CameraDeviceImpl() = default; 35 CameraDeviceImpl(const CameraDeviceImpl& other) = delete; 36 CameraDeviceImpl(CameraDeviceImpl &&other) = delete; 37 CameraDeviceImpl& operator=(const CameraDeviceImpl &other) = delete; 38 CameraDeviceImpl& operator=(CameraDeviceImpl &&other) = delete; 39 40 public: 41 int32_t GetStreamOperator(const sptr<IStreamOperatorCallback>& callbackObj, 42 sptr<IStreamOperator>& streamOperator) override; 43 int32_t UpdateSettings(const std::vector<uint8_t>& settings) override; 44 int32_t SetResultMode(ResultCallbackMode mode) override; 45 int32_t GetEnabledResults(std::vector<int32_t>& results) override; 46 int32_t EnableResult(const std::vector<int32_t>& results) override; 47 int32_t DisableResult(const std::vector<int32_t>& results) override; 48 int32_t Close() override; 49 50 static std::shared_ptr<CameraDeviceImpl> CreateCameraDevice(const std::string &cameraId); 51 std::shared_ptr<IPipelineCore> GetPipelineCore() const; 52 CamRetCode SetCallback(const OHOS::sptr<ICameraDeviceCallback> &callback); 53 ResultCallbackMode GetMetaResultMode() const; 54 /* RC_OK: metadata changed;RC_ERROR: metadata unchanged; */ 55 RetCode GetMetadataResults(std::shared_ptr<CameraMetadata> &metadata); 56 void ResultMetadata(); 57 void GetCameraId(std::string &cameraId) const; 58 void SetStatus(bool isOpened); 59 void OnRequestTimeout(); 60 void OnMetadataChanged(const std::shared_ptr<CameraMetadata> &metadata); 61 void OnDevStatusErr(); 62 bool IsOpened() const; 63 private: 64 RetCode GetEnabledFromCfg(); 65 bool CompareTagData(const camera_metadata_item_t &baseEntry, 66 const camera_metadata_item_t &newEntry); 67 RetCode UpdataMetadataResultsBase(); 68 uint64_t GetCurrentLocalTimeStamp(); 69 70 private: 71 bool isOpened_; 72 std::string cameraId_; 73 std::shared_ptr<IPipelineCore> pipelineCore_; 74 OHOS::sptr<ICameraDeviceCallback> cameraDeciceCallback_; 75 OHOS::sptr<IStreamOperatorCallback> spCameraDeciceCallback_; 76 OHOS::sptr<StreamOperator> spStreamOperator_; 77 ResultCallbackMode metaResultMode_; 78 std::vector<MetaType> deviceMetaTypes_; 79 std::mutex enabledRstMutex_; 80 std::vector<MetaType> enabledResults_; 81 std::shared_ptr<CameraMetadata> metadataResultsBase_; 82 std::mutex metaRstMutex_; 83 std::shared_ptr<CameraMetadata> metadataResults_; 84 85 // to keep OHOS::sptr<IStreamOperator> alive 86 OHOS::sptr<IStreamOperator> ismOperator_ = nullptr; 87 }; 88 } // end namespace OHOS::Camera 89 #endif // CAMERA_DEVICE_CAMERA_DEVICE_IMPL_H 90