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