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