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_CLIENT_H 17 #define OHOS_DCAMERA_CLIENT_H 18 19 #include "icamera_operator.h" 20 21 #include <queue> 22 23 #include "camera_info.h" 24 #include "camera_input.h" 25 #include "camera_manager.h" 26 #include "camera_output_capability.h" 27 #include "capture_input.h" 28 #include "capture_output.h" 29 #include "capture_session.h" 30 #include "photo_output.h" 31 #include "preview_output.h" 32 33 #include "dcamera_photo_surface_listener.h" 34 35 namespace OHOS { 36 namespace DistributedHardware { 37 class DCameraClient : public ICameraOperator { 38 public: 39 explicit DCameraClient(const std::string& dhId); 40 ~DCameraClient() override; 41 42 int32_t Init() override; 43 int32_t UnInit() override; 44 int32_t UpdateSettings(std::vector<std::shared_ptr<DCameraSettings>>& settings) override; 45 int32_t StartCapture(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos, 46 sptr<Surface>& surface, int32_t sceneMode) override; 47 int32_t StopCapture() override; 48 int32_t SetStateCallback(std::shared_ptr<StateCallback>& callback) override; 49 int32_t SetResultCallback(std::shared_ptr<ResultCallback>& callback) override; 50 int32_t PauseCapture() override; 51 int32_t ResumeCapture() override; 52 53 private: 54 int32_t ConfigCaptureSession(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos, int32_t sceneMode); 55 int32_t ConfigCaptureSessionInner(); 56 int32_t CreateCaptureOutput(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos); 57 int32_t CreatePhotoOutput(std::shared_ptr<DCameraCaptureInfo>& info); 58 int32_t CreatePreviewOutput(std::shared_ptr<DCameraCaptureInfo>& info); 59 int32_t StartCaptureInner(std::shared_ptr<DCameraCaptureInfo>& info); 60 int32_t StartPhotoOutput(std::shared_ptr<DCameraCaptureInfo>& info); 61 void FindCameraMetadata(const std::string& metadataStr); 62 void SetPhotoCaptureRotation(const std::shared_ptr<Camera::CameraMetadata>& cameraMetadata, 63 std::shared_ptr<CameraStandard::PhotoCaptureSetting>& photoCaptureSetting); 64 void SetPhotoCaptureQuality(const std::shared_ptr<Camera::CameraMetadata>& cameraMetadata, 65 std::shared_ptr<CameraStandard::PhotoCaptureSetting>& photoCaptureSetting); 66 void SetPhotoCaptureLocation(const std::shared_ptr<Camera::CameraMetadata>& cameraMetadata, 67 std::shared_ptr<CameraStandard::PhotoCaptureSetting>& photoCaptureSetting); 68 void StopOutput(); 69 void ReleaseCaptureSession(); 70 int32_t CameraServiceErrorType(const int32_t errorType); 71 CameraStandard::CameraFormat ConvertToCameraFormat(int32_t format); 72 void UpdateSettingCache(const std::string& metadataStr); 73 74 private: 75 constexpr static uint32_t DCAMERA_MAX_METADATA_SIZE = 20; 76 77 bool isInit_; 78 std::string cameraId_; 79 std::queue<std::string> cameraMetadatas_; 80 sptr<IConsumerSurface> photoSurface_; 81 sptr<Surface> previewSurface_; 82 sptr<CameraStandard::CameraDevice> cameraInfo_; 83 sptr<CameraStandard::CameraManager> cameraManager_; 84 sptr<CameraStandard::CaptureSession> captureSession_; 85 sptr<CameraStandard::CaptureInput> cameraInput_; 86 sptr<CameraStandard::CaptureOutput> photoOutput_; 87 sptr<CameraStandard::CaptureOutput> previewOutput_; 88 sptr<DCameraPhotoSurfaceListener> photoListener_; 89 std::shared_ptr<StateCallback> stateCallback_; 90 std::shared_ptr<ResultCallback> resultCallback_; 91 }; 92 } // namespace DistributedHardware 93 } // namespace OHOS 94 #endif // OHOS_DCAMERA_CLIENT_H