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 OHOS_CAMERA_H_CAMERA_SERVICE_H 17 #define OHOS_CAMERA_H_CAMERA_SERVICE_H 18 #include <set> 19 #include <shared_mutex> 20 #include <iostream> 21 22 #include "camera_util.h" 23 #include "hcamera_device.h" 24 #include "hcamera_host_manager.h" 25 #include "hcamera_service_stub.h" 26 #include "hcapture_session.h" 27 #include "hstream_capture.h" 28 #include "hstream_metadata.h" 29 #include "hstream_repeat.h" 30 #include "iremote_stub.h" 31 #include "privacy_kit.h" 32 #include "system_ability.h" 33 34 namespace OHOS { 35 namespace CameraStandard { 36 using namespace OHOS::HDI::Camera::V1_0; 37 class HCameraService : public SystemAbility, public HCameraServiceStub, public HCameraHostManager::StatusCallback, 38 public IDeviceOperatorsCallback { 39 DECLARE_SYSTEM_ABILITY(HCameraService); 40 41 public: 42 DISALLOW_COPY_AND_MOVE(HCameraService); 43 44 explicit HCameraService(int32_t systemAbilityId, bool runOnCreate = true); 45 ~HCameraService() override; 46 int32_t GetCameras(std::vector<std::string> &cameraIds, 47 std::vector<std::shared_ptr<OHOS::Camera::CameraMetadata>> &cameraAbilityList) override; 48 int32_t CreateCameraDevice(std::string cameraId, sptr<ICameraDeviceService> &device) override; 49 int32_t CreateCaptureSession(sptr<ICaptureSession> &session) override; 50 int32_t CreatePhotoOutput(const sptr<OHOS::IBufferProducer> &producer, int32_t format, 51 int32_t width, int32_t height, 52 sptr<IStreamCapture> &photoOutput) override; 53 int32_t CreateDeferredPreviewOutput(int32_t format, int32_t width, int32_t height, 54 sptr<IStreamRepeat> &previewOutput) override; 55 int32_t CreatePreviewOutput(const sptr<OHOS::IBufferProducer> &producer, int32_t format, 56 int32_t width, int32_t height, 57 sptr<IStreamRepeat> &previewOutput) override; 58 int32_t CreateMetadataOutput(const sptr<OHOS::IBufferProducer> &producer, int32_t format, 59 sptr<IStreamMetadata> &metadataOutput) override; 60 int32_t CreateVideoOutput(const sptr<OHOS::IBufferProducer> &producer, int32_t format, 61 int32_t width, int32_t height, 62 sptr<IStreamRepeat> &videoOutput) override; 63 int32_t SetCallback(sptr<ICameraServiceCallback> &callback) override; 64 int32_t UnSetCallback(pid_t pid) override; 65 int32_t CloseCameraForDestory(pid_t pid) override; 66 int32_t SetMuteCallback(sptr<ICameraMuteServiceCallback> &callback) override; 67 int32_t MuteCamera(bool muteMode) override; 68 int32_t PrelaunchCamera() override; 69 int32_t SetPrelaunchConfig(std::string cameraId) override; 70 int32_t IsCameraMuted(bool &muteMode) override; 71 void OnDump() override; 72 void OnStart() override; 73 void OnStop() override; 74 int32_t Dump(int fd, const std::vector<std::u16string>& args) override; 75 76 // HCameraHostManager::StatusCallback 77 void OnCameraStatus(const std::string& cameraId, CameraStatus status) override; 78 void OnFlashlightStatus(const std::string& cameraId, FlashStatus status) override; 79 // IDeviceOperatorsCallback 80 int32_t DeviceOpen(const std::string& cameraId) override; 81 int32_t DeviceClose(const std::string& cameraId, pid_t pidFromSession = 0) override; 82 std::vector<sptr<HCameraDevice>> CameraConflictDetection(const std::string& cameraId, bool& isPermisson) override; 83 84 protected: HCameraService(sptr<HCameraHostManager> cameraHostManager)85 explicit HCameraService(sptr<HCameraHostManager> cameraHostManager) : cameraHostManager_(cameraHostManager), 86 streamOperatorCallback_(nullptr), 87 muteMode_(false) {} 88 89 private: 90 void CameraSummary(std::vector<std::string> cameraIds, std::string& dumpString); 91 void CameraDumpAbility(common_metadata_header_t* metadataEntry, std::string& dumpString); 92 void CameraDumpStreaminfo(common_metadata_header_t* metadataEntry, std::string& dumpString); 93 void CameraDumpZoom(common_metadata_header_t* metadataEntry, std::string& dumpString); 94 void CameraDumpFlash(common_metadata_header_t* metadataEntry, std::string& dumpString); 95 void CameraDumpAF(common_metadata_header_t* metadataEntry, std::string& dumpString); 96 void CameraDumpAE(common_metadata_header_t* metadataEntry, std::string& dumpString); 97 void CameraDumpSensorInfo(common_metadata_header_t* metadataEntry, std::string& dumpString); 98 void CameraDumpVideoStabilization(common_metadata_header_t* metadataEntry, std::string& dumpString); 99 void CameraDumpVideoFrameRateRange(common_metadata_header_t* metadataEntry, std::string& dumpString); 100 void CameraDumpPrelaunch(common_metadata_header_t* metadataEntry, std::string& dumpString); 101 void CameraDumpThumbnail(common_metadata_header_t* metadataEntry, std::string& dumpString); 102 bool IsCameraMuteSupported(std::string cameraId); 103 bool IsPrelaunchSupported(std::string cameraId); 104 int32_t UpdateMuteSetting(sptr<HCameraDevice> cameraDevice, bool muteMode); 105 int32_t UnSetMuteCallback(pid_t pid); 106 bool IsDeviceAlreadyOpen(pid_t& tempPid, std::string& tempCameraId, sptr<HCameraDevice> &tempDevice); 107 int32_t DeviceClose(sptr<HCameraDevice> cameraDevice); 108 std::mutex mutex_; 109 std::mutex cbMutex_; 110 std::mutex muteCbMutex_; 111 sptr<HCameraHostManager> cameraHostManager_; 112 sptr<StreamOperatorCallback> streamOperatorCallback_; 113 std::map<uint32_t, sptr<ICameraMuteServiceCallback>> cameraMuteServiceCallbacks_; 114 std::map<uint32_t, sptr<ICameraServiceCallback>> cameraServiceCallbacks_; 115 SafeMap<std::string, sptr<HCameraDevice>> devicesManager_; 116 std::map<uint32_t, std::set<std::string>> camerasForPid_; 117 bool muteMode_; 118 std::mutex mapOperatorsLock_; 119 std::string preCameraId_; 120 }; 121 } // namespace CameraStandard 122 } // namespace OHOS 123 #endif // OHOS_CAMERA_H_CAMERA_SERVICE_H 124