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_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 #include "video_output.h" 33 34 #include "dcamera_photo_surface_listener.h" 35 #include "dcamera_video_surface_listener.h" 36 37 namespace OHOS { 38 namespace DistributedHardware { 39 class DCameraClient : public ICameraOperator { 40 public: 41 explicit DCameraClient(const std::string& dhId); 42 ~DCameraClient(); 43 44 int32_t Init() override; 45 int32_t UnInit() override; 46 int32_t UpdateSettings(std::vector<std::shared_ptr<DCameraSettings>>& settings) override; 47 int32_t StartCapture(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos) override; 48 int32_t StopCapture() override; 49 int32_t SetStateCallback(std::shared_ptr<StateCallback>& callback) override; 50 int32_t SetResultCallback(std::shared_ptr<ResultCallback>& callback) override; 51 52 private: 53 int32_t ConfigCaptureSession(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos); 54 int32_t ConfigCaptureSessionInner(); 55 int32_t CreateCaptureOutput(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos); 56 int32_t CreatePhotoOutput(std::shared_ptr<DCameraCaptureInfo>& info); 57 int32_t CreateVideoOutput(std::shared_ptr<DCameraCaptureInfo>& info); 58 int32_t StartCaptureInner(std::shared_ptr<DCameraCaptureInfo>& info); 59 int32_t StartPhotoOutput(std::shared_ptr<DCameraCaptureInfo>& info); 60 int32_t StartVideoOutput(); 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 ReleaseCaptureSession(); 69 int32_t CameraServiceErrorType(const int32_t errorType); 70 CameraStandard::CameraFormat ConvertToCameraFormat(int32_t format); 71 void UpdateSettingCache(const std::string& metadataStr); 72 73 private: 74 constexpr static uint32_t DCAMERA_MAX_METADATA_SIZE = 20; 75 76 bool isInit_; 77 std::string cameraId_; 78 std::queue<std::string> cameraMetadatas_; 79 sptr<Surface> photoSurface_; 80 sptr<Surface> videoSurface_; 81 sptr<CameraStandard::CameraDevice> cameraInfo_; 82 sptr<CameraStandard::CameraManager> cameraManager_; 83 sptr<CameraStandard::CaptureSession> captureSession_; 84 sptr<CameraStandard::CaptureInput> cameraInput_; 85 sptr<CameraStandard::CaptureOutput> photoOutput_; 86 sptr<CameraStandard::CaptureOutput> previewOutput_; 87 sptr<CameraStandard::CaptureOutput> videoOutput_; 88 sptr<DCameraPhotoSurfaceListener> photoListener_; 89 sptr<DCameraVideoSurfaceListener> videoListener_; 90 std::shared_ptr<StateCallback> stateCallback_; 91 std::shared_ptr<ResultCallback> resultCallback_; 92 }; 93 } // namespace DistributedHardware 94 } // namespace OHOS 95 #endif // OHOS_DCAMERA_CLIENT_H