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