• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CAMERA_MANAGER_H
17 #define OHOS_CAMERA_CAMERA_MANAGER_H
18 
19 #include <iostream>
20 #include <refbase.h>
21 #include <vector>
22 #include "input/camera_input.h"
23 #include "input/camera_info.h"
24 #include "hcamera_service_proxy.h"
25 #include "icamera_device_service.h"
26 #include "session/capture_session.h"
27 #include "output/photo_output.h"
28 #include "output/video_output.h"
29 #include "output/preview_output.h"
30 #include "hcamera_listener_stub.h"
31 #include "input/camera_death_recipient.h"
32 #include "hcamera_service_callback_stub.h"
33 
34 namespace OHOS {
35 namespace CameraStandard {
36 enum CameraDeviceStatus {
37     CAMERA_DEVICE_STATUS_UNAVAILABLE = 0,
38     CAMERA_DEVICE_STATUS_AVAILABLE
39 };
40 
41 enum FlashlightStatus {
42     FLASHLIGHT_STATUS_OFF = 0,
43     FLASHLIGHT_STATUS_ON,
44     FLASHLIGHT_STATUS_UNAVAILABLE
45 };
46 
47 struct CameraStatusInfo {
48     sptr<CameraInfo> cameraInfo;
49     CameraDeviceStatus cameraStatus;
50 };
51 
52 class CameraManagerCallback {
53 public:
54     CameraManagerCallback() = default;
55     virtual ~CameraManagerCallback() = default;
56     virtual void OnCameraStatusChanged(const CameraStatusInfo &cameraStatusInfo) const = 0;
57     virtual void OnFlashlightStatusChanged(const std::string &cameraID, const FlashlightStatus flashStatus) const = 0;
58 };
59 
60 class CameraManager : public RefBase {
61 public:
62     static sptr<CameraManager> &GetInstance();
63     std::vector<sptr<CameraInfo>> GetCameras();
64     sptr<CameraInput> CreateCameraInput(sptr<CameraInfo> &camera);
65     sptr<CaptureSession> CreateCaptureSession();
66     sptr<PhotoOutput> CreatePhotoOutput(sptr<Surface> &surface);
67     sptr<PhotoOutput> CreatePhotoOutput(const sptr<OHOS::IBufferProducer> &producer, int32_t format);
68     sptr<VideoOutput> CreateVideoOutput(sptr<Surface> &surface);
69     sptr<VideoOutput> CreateVideoOutput(const sptr<OHOS::IBufferProducer> &producer, int32_t format);
70     sptr<PreviewOutput> CreatePreviewOutput(sptr<Surface> surface);
71     sptr<PreviewOutput> CreatePreviewOutput(const sptr<OHOS::IBufferProducer> &producer, int32_t format);
72     sptr<PreviewOutput> CreateCustomPreviewOutput(sptr<Surface> surface, int32_t width, int32_t height);
73     sptr<PreviewOutput> CreateCustomPreviewOutput(const sptr<OHOS::IBufferProducer> &producer, int32_t format,
74                                                   int32_t width, int32_t height);
75     void SetCallback(std::shared_ptr<CameraManagerCallback> callback);
76     std::shared_ptr<CameraManagerCallback> GetApplicationCallback();
77     sptr<CameraInfo> GetCameraInfo(std::string cameraId);
78 
79     static const std::string surfaceFormat;
80 
81 protected:
CameraManager(sptr<ICameraService> serviceProxy)82     CameraManager(sptr<ICameraService> serviceProxy) : serviceProxy_(serviceProxy) {}
83 
84 private:
85     CameraManager();
86     void Init();
87     void SetCameraServiceCallback(sptr<ICameraServiceCallback>& callback);
88     int32_t CreateListenerObject();
89     void CameraServerDied(pid_t pid);
90 
91     sptr<ICameraDeviceService> CreateCameraDevice(std::string cameraId);
92     sptr<ICameraService> serviceProxy_;
93     sptr<CameraListenerStub> listenerStub_ = nullptr;
94     sptr<CameraDeathRecipient> deathRecipient_ = nullptr;
95     static sptr<CameraManager> cameraManager_;
96     sptr<ICameraServiceCallback> cameraSvcCallback_;
97     std::shared_ptr<CameraManagerCallback> cameraMngrCallback_;
98     std::vector<sptr<CameraInfo>> cameraObjList;
99 };
100 } // namespace CameraStandard
101 } // namespace OHOS
102 #endif // OHOS_CAMERA_CAMERA_MANAGER_H
103