1 /* 2 * Copyright (c) 2021-2024 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 OHOS_DCAMERA_HANDLER_H 17 #define OHOS_DCAMERA_HANDLER_H 18 19 #include "ihardware_handler.h" 20 21 #include <set> 22 23 #include "camera_info.h" 24 #include "camera_input.h" 25 #include "camera_manager.h" 26 #include "camera_output_capability.h" 27 #include "single_instance.h" 28 #include "v1_1/dcamera_types.h" 29 #include "cJSON.h" 30 31 namespace OHOS { 32 namespace DistributedHardware { 33 using namespace OHOS::HDI::DistributedCamera::V1_1; 34 35 class DCameraHandler : public IHardwareHandler { 36 DECLARE_SINGLE_INSTANCE_BASE(DCameraHandler); 37 public: 38 int32_t Initialize() override; 39 std::vector<DHItem> QueryMeta() override; 40 std::vector<DHItem> Query() override; 41 std::map<std::string, std::string> QueryExtraInfo() override; 42 bool IsSupportPlugin() override; 43 void RegisterPluginListener(std::shared_ptr<PluginListener> listener) override; 44 void UnRegisterPluginListener() override; 45 46 std::vector<std::string> GetCameras(); 47 48 private: 49 DCameraHandler() = default; 50 ~DCameraHandler(); 51 52 private: 53 const int32_t INVALID_FORMAT = -1; 54 int32_t CreateMetaDHItem(sptr<CameraStandard::CameraDevice>& info, DHItem& item); 55 int32_t CreateDHItem(sptr<CameraStandard::CameraDevice>& info, DHItem& item); 56 int32_t CreateAVCodecList(cJSON* root); 57 std::string GetCameraPosition(CameraStandard::CameraPosition position); 58 void ProcessProfile(const DCStreamType type, std::map<std::string, std::list<std::string>>& formatMap, 59 std::vector<CameraStandard::Profile>& profileList, std::set<int32_t>& formatSet); 60 void ConfigFormatphoto(const DCStreamType type, cJSON* root, 61 std::vector<CameraStandard::Profile>& profileList); 62 void ConfigFormatvideo(const DCStreamType type, cJSON* root, 63 std::vector<CameraStandard::Profile>& profileList); 64 bool IsValid(const DCStreamType type, const CameraStandard::Size& size); 65 int32_t CovertToDcameraFormat(CameraStandard::CameraFormat format); 66 int32_t CreateMeatdataStr(sptr<CameraStandard::CameraDevice>& info, cJSON *root); 67 68 sptr<CameraStandard::CameraManager> cameraManager_; 69 std::shared_ptr<PluginListener> pluginListener_; 70 }; 71 72 #ifdef __cplusplus 73 extern "C" { 74 #endif // __cplusplus 75 __attribute__((visibility("default"))) IHardwareHandler* GetHardwareHandler(); 76 #ifdef __cplusplus 77 } 78 #endif // __cplusplus 79 } // namespace DistributedHardware 80 } // namespace OHOS 81 #endif // OHOS_DCAMERA_HANDLER_H