• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 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 HOS_CAMERA_3516_DEMO_H
17 #define HOS_CAMERA_3516_DEMO_H
18 
19 #include <vector>
20 #include <map>
21 #include <iostream>
22 #include <hdf_log.h>
23 #include <surface.h>
24 #include <time.h>
25 #include <sys/time.h>
26 #include <display_type.h>
27 #include "camera.h"
28 #include "camera_metadata_info.h"
29 #include "ibuffer.h"
30 #include "if_system_ability_manager.h"
31 #include "ioffline_stream_operator.h"
32 #include "iservice_registry.h"
33 #include "icamera_host.h"
34 #include "camera_host_proxy.h"
35 #include "camera_host_callback.h"
36 #include "camera_device_callback.h"
37 #include "icamera_device.h"
38 #include "stream_operator_callback.h"
39 #include "istream_operator_callback.h"
40 #include "stream_customer.h"
41 #include "securec.h"
42 
43 namespace OHOS::Camera {
44 enum CaptureMode {
45     CAPTURE_PREVIEW = 0,
46     CAPTURE_SNAPSHOT,
47     CAPTURE_VIDEO,
48 };
49 
50 enum CameraId {
51     STREAM_ID_PREVIEW = 1001,
52     STREAM_ID_CAPTURE,
53     STREAM_ID_VIDEO,
54     CAPTURE_ID_PREVIEW = 2001,
55     CAPTURE_ID_CAPTURE,
56     CAPTURE_ID_VIDEO,
57 };
58 
59 class Hos3516Demo {
60 public:
61     Hos3516Demo();
62     ~Hos3516Demo();
63 
64     RetCode InitCameraDevice();
65     void ReleaseCameraDevice();
66     RetCode InitSensors();
67 
68     RetCode StartPreviewStream();
69     RetCode StartCaptureStream();
70     RetCode StartVideoStream();
71     RetCode StartDualStreams(const int streamIdSecond);
72 
73     RetCode ReleaseAllStream();
74 
75     RetCode CaptureOnDualStreams(const int streamIdSecond);
76     RetCode CaptureON(const int streamId, const int captureId, CaptureMode mode);
77     RetCode CaptureOff(const int captureId, const CaptureMode mode);
78 
79     void SetAwbMode(const int mode) const;
80     void SetAeExpo();
81     void FlashlightOnOff(bool onOff);
82 
83     RetCode StreamOffline(const int streamId);
84 
85     void QuitDemo();
86 
87 private:
88     void SetStreamInfo(std::shared_ptr<OHOS::Camera::StreamInfo>& streamInfo,
89         const std::shared_ptr<StreamCustomer>& streamCustomer,
90         const int streamId, const StreamIntent intent);
91     void GetStreamOpt();
92 
93     RetCode CreatStream(const int streamId, std::shared_ptr<StreamCustomer>& streamCustomer,
94         StreamIntent intent);
95     RetCode CreatStreams(const int streamIdSecond, StreamIntent intent);
96 
97     void StoreImage(const void* bufStart, const unsigned int size) const;
98     void StoreVideo(const void* bufStart, const unsigned int size) const;
99     void OpenVideoFile();
100 
101     int aeStatus_ = 1;
102     int videoFd_ = -1;
103     unsigned int isPreviewOn_ = 0;
104     unsigned int isCaptureOn_ = 0;
105     unsigned int isVideoOn_ = 0;
106 
107     std::shared_ptr<StreamCustomer> streamCustomerPreview_ = nullptr;
108     std::shared_ptr<StreamCustomer> streamCustomerCapture_ = nullptr;
109     std::shared_ptr<StreamCustomer> streamCustomerVideo_ = nullptr;
110     std::shared_ptr<CameraAbility> ability_ = nullptr;
111 
112     sptr<CameraHostCallback> hostCallback_ = nullptr;
113     sptr<IStreamOperator> streamOperator_ = nullptr;
114     sptr<ICameraHost> demoCameraHost_ = nullptr;
115     sptr<ICameraDevice> demoCameraDevice_ = nullptr;
116     std::vector<std::string> cameraIds_ = {};
117 };
118 } // namespace OHOS::Camera
119 #endif // HOS_CAMERA_3516_DEMO_H
120