1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (c) 2020 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci
16094332d3Sopenharmony_ci#ifndef OHOS_CAMERA_CAMERA_DEMO_H
17094332d3Sopenharmony_ci#define OHOS_CAMERA_CAMERA_DEMO_H
18094332d3Sopenharmony_ci
19094332d3Sopenharmony_ci#include <vector>
20094332d3Sopenharmony_ci#include <map>
21094332d3Sopenharmony_ci#include <iostream>
22094332d3Sopenharmony_ci#include <hdf_log.h>
23094332d3Sopenharmony_ci#include <surface.h>
24094332d3Sopenharmony_ci#include <sys/time.h>
25094332d3Sopenharmony_ci#include <ctime>
26094332d3Sopenharmony_ci#include <fcntl.h>
27094332d3Sopenharmony_ci#include "camera.h"
28094332d3Sopenharmony_ci#include "camera_metadata_info.h"
29094332d3Sopenharmony_ci#include "ibuffer.h"
30094332d3Sopenharmony_ci#include "v1_0/ioffline_stream_operator.h"
31094332d3Sopenharmony_ci#include "v1_0/icamera_host.h"
32094332d3Sopenharmony_ci#include "camera_host_callback.h"
33094332d3Sopenharmony_ci#include "camera_device_callback.h"
34094332d3Sopenharmony_ci#include "v1_0/icamera_device.h"
35094332d3Sopenharmony_ci#include "stream_operator_callback.h"
36094332d3Sopenharmony_ci#include "v1_0/istream_operator_callback.h"
37094332d3Sopenharmony_ci#include "stream_customer.h"
38094332d3Sopenharmony_ci#include "securec.h"
39094332d3Sopenharmony_ci#include "project_camera_demo.h"
40094332d3Sopenharmony_ci#include "if_system_ability_manager.h"
41094332d3Sopenharmony_ci#include "iservice_registry.h"
42094332d3Sopenharmony_ci#include "v1_0/camera_host_proxy.h"
43094332d3Sopenharmony_ci
44094332d3Sopenharmony_cinamespace OHOS::Camera {
45094332d3Sopenharmony_ciusing namespace OHOS::HDI::Camera::V1_0;
46094332d3Sopenharmony_ci
47094332d3Sopenharmony_cienum CaptureMode {
48094332d3Sopenharmony_ci    CAPTURE_PREVIEW = 0,
49094332d3Sopenharmony_ci    CAPTURE_SNAPSHOT,
50094332d3Sopenharmony_ci    CAPTURE_VIDEO,
51094332d3Sopenharmony_ci};
52094332d3Sopenharmony_ci
53094332d3Sopenharmony_cienum DemoActionID {
54094332d3Sopenharmony_ci    STREAM_ID_PREVIEW = 1001,
55094332d3Sopenharmony_ci    STREAM_ID_CAPTURE,
56094332d3Sopenharmony_ci    STREAM_ID_VIDEO,
57094332d3Sopenharmony_ci    CAPTURE_ID_PREVIEW = 2001,
58094332d3Sopenharmony_ci    CAPTURE_ID_CAPTURE,
59094332d3Sopenharmony_ci    CAPTURE_ID_VIDEO,
60094332d3Sopenharmony_ci};
61094332d3Sopenharmony_ci
62094332d3Sopenharmony_ciclass DemoCameraHostCallback;
63094332d3Sopenharmony_ciclass OhosCameraDemo {
64094332d3Sopenharmony_cipublic:
65094332d3Sopenharmony_ci    OhosCameraDemo();
66094332d3Sopenharmony_ci    ~OhosCameraDemo();
67094332d3Sopenharmony_ci
68094332d3Sopenharmony_ci    RetCode InitCameraDevice();
69094332d3Sopenharmony_ci    void ReleaseCameraDevice();
70094332d3Sopenharmony_ci    RetCode InitSensors();
71094332d3Sopenharmony_ci
72094332d3Sopenharmony_ci    RetCode StartPreviewStream();
73094332d3Sopenharmony_ci    RetCode StartCaptureStream();
74094332d3Sopenharmony_ci    RetCode StartVideoStream();
75094332d3Sopenharmony_ci    RetCode StartDualStreams(const int streamIdSecond);
76094332d3Sopenharmony_ci
77094332d3Sopenharmony_ci    RetCode ReleaseAllStream();
78094332d3Sopenharmony_ci
79094332d3Sopenharmony_ci    RetCode CaptureOnDualStreams(const int streamIdSecond);
80094332d3Sopenharmony_ci    RetCode CaptureON(const int streamId, const int captureId, CaptureMode mode);
81094332d3Sopenharmony_ci    RetCode CaptureOff(const int captureId, const CaptureMode mode);
82094332d3Sopenharmony_ci
83094332d3Sopenharmony_ci    void SetAwbMode(const int mode) const;
84094332d3Sopenharmony_ci    void SetAeExpo();
85094332d3Sopenharmony_ci    void SetMetadata();
86094332d3Sopenharmony_ci    void SetEnableResult();
87094332d3Sopenharmony_ci    void FlashlightOnOff(bool onOff);
88094332d3Sopenharmony_ci
89094332d3Sopenharmony_ci    RetCode StreamOffline(const int streamId);
90094332d3Sopenharmony_ci
91094332d3Sopenharmony_ci    void QuitDemo();
92094332d3Sopenharmony_ci
93094332d3Sopenharmony_ciprivate:
94094332d3Sopenharmony_ci    void SetStreamInfo(StreamInfo& streamInfo,
95094332d3Sopenharmony_ci        const std::shared_ptr<StreamCustomer>& streamCustomer,
96094332d3Sopenharmony_ci        const int streamId, const StreamIntent intent);
97094332d3Sopenharmony_ci    void GetStreamOpt();
98094332d3Sopenharmony_ci
99094332d3Sopenharmony_ci    RetCode CreateStream(const int streamId, std::shared_ptr<StreamCustomer> &streamCustomer,
100094332d3Sopenharmony_ci        StreamIntent intent);
101094332d3Sopenharmony_ci    RetCode CreateStreams(const int streamIdSecond, StreamIntent intent);
102094332d3Sopenharmony_ci
103094332d3Sopenharmony_ci    void StoreImage(const void *bufStart, const uint32_t size) const;
104094332d3Sopenharmony_ci    void StoreVideo(const void *bufStart, const uint32_t size) const;
105094332d3Sopenharmony_ci    void OpenVideoFile();
106094332d3Sopenharmony_ci
107094332d3Sopenharmony_ci    RetCode GetFaceDetectMode(std::shared_ptr<CameraAbility> &ability);
108094332d3Sopenharmony_ci    RetCode GetFocalLength(std::shared_ptr<CameraAbility> &ability);
109094332d3Sopenharmony_ci    RetCode GetAvailableFocusModes(std::shared_ptr<CameraAbility> &ability);
110094332d3Sopenharmony_ci    RetCode GetAvailableExposureModes(std::shared_ptr<CameraAbility> &ability);
111094332d3Sopenharmony_ci    RetCode GetExposureCompensationRange(std::shared_ptr<CameraAbility> &ability);
112094332d3Sopenharmony_ci    RetCode GetExposureCompensationSteps(std::shared_ptr<CameraAbility> &ability);
113094332d3Sopenharmony_ci    RetCode GetAvailableMeterModes(std::shared_ptr<CameraAbility> &ability);
114094332d3Sopenharmony_ci    RetCode GetAvailableFlashModes(std::shared_ptr<CameraAbility> &ability);
115094332d3Sopenharmony_ci    RetCode GetMirrorSupported(std::shared_ptr<CameraAbility> &ability);
116094332d3Sopenharmony_ci    RetCode GetStreamBasicConfigurations(std::shared_ptr<CameraAbility> &ability);
117094332d3Sopenharmony_ci    RetCode GetFpsRange(std::shared_ptr<CameraAbility> &ability);
118094332d3Sopenharmony_ci    RetCode GetCameraPosition(std::shared_ptr<CameraAbility> &ability);
119094332d3Sopenharmony_ci    RetCode GetCameraType(std::shared_ptr<CameraAbility> &ability);
120094332d3Sopenharmony_ci    RetCode GetCameraConnectionType(std::shared_ptr<CameraAbility> &ability);
121094332d3Sopenharmony_ci    RetCode GetFaceDetectMaxNum(std::shared_ptr<CameraAbility> &ability);
122094332d3Sopenharmony_ci
123094332d3Sopenharmony_ci    bool aeStatus_ = true;
124094332d3Sopenharmony_ci    int videoFd_ = -1;
125094332d3Sopenharmony_ci    unsigned int isPreviewOn_ = 0;
126094332d3Sopenharmony_ci    unsigned int isCaptureOn_ = 0;
127094332d3Sopenharmony_ci    unsigned int isVideoOn_ = 0;
128094332d3Sopenharmony_ci
129094332d3Sopenharmony_ci    uint8_t captureQuality_ = 0;
130094332d3Sopenharmony_ci    int32_t captureOrientation_ = 0;
131094332d3Sopenharmony_ci    uint8_t mirrorSwitch_ = 0;
132094332d3Sopenharmony_ci    std::vector<double> gps_;
133094332d3Sopenharmony_ci    CaptureInfo captureInfo_;
134094332d3Sopenharmony_ci
135094332d3Sopenharmony_ci    std::shared_ptr<StreamCustomer> streamCustomerPreview_ = nullptr;
136094332d3Sopenharmony_ci    std::shared_ptr<StreamCustomer> streamCustomerCapture_ = nullptr;
137094332d3Sopenharmony_ci    std::shared_ptr<StreamCustomer> streamCustomerVideo_ = nullptr;
138094332d3Sopenharmony_ci    std::shared_ptr<CameraAbility> ability_ = nullptr;
139094332d3Sopenharmony_ci    std::shared_ptr<CameraSetting> captureSetting_ = nullptr;
140094332d3Sopenharmony_ci    std::mutex metaDatalock_;
141094332d3Sopenharmony_ci    std::vector<uint8_t> cameraAbility_;
142094332d3Sopenharmony_ci
143094332d3Sopenharmony_ci#ifdef CAMERA_BUILT_ON_OHOS_LITE
144094332d3Sopenharmony_ci    std::shared_ptr<DemoCameraHostCallback> hostCallback_ = nullptr;
145094332d3Sopenharmony_ci    std::shared_ptr<IStreamOperator> streamOperator_ = nullptr;
146094332d3Sopenharmony_ci    std::shared_ptr<CameraHost> demoCameraHost_ = nullptr;
147094332d3Sopenharmony_ci    std::shared_ptr<ICameraDevice> demoCameraDevice_ = nullptr;
148094332d3Sopenharmony_ci#else
149094332d3Sopenharmony_ci    OHOS::sptr<DemoCameraHostCallback> hostCallback_ = nullptr;
150094332d3Sopenharmony_ci    OHOS::sptr<IStreamOperator> streamOperator_ = nullptr;
151094332d3Sopenharmony_ci    OHOS::sptr<ICameraHost> demoCameraHost_ = nullptr;
152094332d3Sopenharmony_ci    OHOS::sptr<ICameraDevice> demoCameraDevice_ = nullptr;
153094332d3Sopenharmony_ci#endif
154094332d3Sopenharmony_ci    std::vector<std::string> cameraIds_ = {};
155094332d3Sopenharmony_ci};
156094332d3Sopenharmony_ci#ifdef CAMERA_BUILT_ON_OHOS_LITE
157094332d3Sopenharmony_ci
158094332d3Sopenharmony_ci#else
159094332d3Sopenharmony_ciclass DemoCameraDeviceCallback : public ICameraDeviceCallback {
160094332d3Sopenharmony_cipublic:
161094332d3Sopenharmony_ci    DemoCameraDeviceCallback() = default;
162094332d3Sopenharmony_ci    virtual ~DemoCameraDeviceCallback() = default;
163094332d3Sopenharmony_ci    int32_t OnError(ErrorType type, int32_t errorCode) override;
164094332d3Sopenharmony_ci    int32_t OnResult(uint64_t timestamp, const std::vector<uint8_t>& result) override;
165094332d3Sopenharmony_ci};
166094332d3Sopenharmony_ci
167094332d3Sopenharmony_ciclass DemoCameraHostCallback : public ICameraHostCallback {
168094332d3Sopenharmony_cipublic:
169094332d3Sopenharmony_ci    DemoCameraHostCallback() = default;
170094332d3Sopenharmony_ci    virtual ~DemoCameraHostCallback() = default;
171094332d3Sopenharmony_ci
172094332d3Sopenharmony_cipublic:
173094332d3Sopenharmony_ci    int32_t OnCameraStatus(const std::string& cameraId, CameraStatus status) override;
174094332d3Sopenharmony_ci
175094332d3Sopenharmony_ci    int32_t OnFlashlightStatus(const std::string& cameraId, FlashlightStatus status) override;
176094332d3Sopenharmony_ci
177094332d3Sopenharmony_ci    int32_t OnCameraEvent(const std::string& cameraId, CameraEvent event) override;
178094332d3Sopenharmony_ci};
179094332d3Sopenharmony_ci
180094332d3Sopenharmony_ciclass DemoStreamOperatorCallback : public IStreamOperatorCallback {
181094332d3Sopenharmony_cipublic:
182094332d3Sopenharmony_ci    DemoStreamOperatorCallback() = default;
183094332d3Sopenharmony_ci    virtual ~DemoStreamOperatorCallback() = default;
184094332d3Sopenharmony_ci
185094332d3Sopenharmony_cipublic:
186094332d3Sopenharmony_ci    int32_t OnCaptureStarted(int32_t captureId, const std::vector<int32_t>& streamIds) override;
187094332d3Sopenharmony_ci    int32_t OnCaptureEnded(int32_t captureId, const std::vector<CaptureEndedInfo>& infos) override;
188094332d3Sopenharmony_ci    int32_t OnCaptureError(int32_t captureId, const std::vector<CaptureErrorInfo>& infos) override;
189094332d3Sopenharmony_ci    int32_t OnFrameShutter(int32_t captureId, const std::vector<int32_t>& streamIds, uint64_t timestamp) override;
190094332d3Sopenharmony_ci};
191094332d3Sopenharmony_ci
192094332d3Sopenharmony_ci#endif
193094332d3Sopenharmony_ci} // namespace OHOS::Camera
194094332d3Sopenharmony_ci#endif // OHOS_CAMERA_CAMERA_DEMO_H
195