1 /* 2 * Copyright (c) 2021-2023 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 #include <stdlib.h> 17 #include <thread> 18 #include <iostream> 19 #include <unistd.h> 20 #include <map> 21 #include <vector> 22 #include <fcntl.h> 23 #include "camera.h" 24 #include "v1_1/types.h" 25 #include "metadata_utils.h" 26 #include "v1_1/icamera_host.h" 27 #include "v1_1/icamera_device.h" 28 #include "v1_1/istream_operator.h" 29 #include "v1_1/camera_host_proxy.h" 30 31 namespace OHOS::Camera { 32 using namespace OHOS::HDI::Camera::V1_0; 33 class CameraManager { 34 public: 35 void Init(); 36 void Open(); 37 void Close(); 38 void GetCameraMetadata(); 39 OHOS::sptr<OHOS::Camera::ICameraHost> service = nullptr; 40 OHOS::sptr<OHOS::HDI::Camera::V1_1::ICameraHost> serviceV1_1 = nullptr; 41 OHOS::sptr<ICameraHostCallback> hostCallback = nullptr; 42 OHOS::sptr<ICameraDevice> cameraDevice = nullptr; 43 OHOS::sptr<ICameraDeviceCallback> deviceCallback = nullptr; 44 OHOS::sptr<OHOS::HDI::Camera::V1_1::ICameraDevice> cameraDeviceV1_1 = nullptr; 45 46 int32_t rc; 47 std::vector<std::string> cameraIds; 48 std::vector<uint8_t> abilityVec = {}; 49 std::shared_ptr<CameraMetadata> ability = nullptr; 50 51 using ResultCallback = std::function<void (uint64_t, const std::shared_ptr<CameraMetadata>)>; 52 static ResultCallback resultCallback_; 53 54 class TestStreamOperatorCallback : public IStreamOperatorCallback { 55 public: 56 TestStreamOperatorCallback() = default; 57 virtual ~TestStreamOperatorCallback() = default; 58 int32_t OnCaptureStarted(int32_t captureId, const std::vector<int32_t> &streamId) override; 59 int32_t OnCaptureEnded(int32_t captureId, const std::vector<CaptureEndedInfo> &infos) override; 60 int32_t OnCaptureError(int32_t captureId, const std::vector<CaptureErrorInfo> &infos) override; 61 int32_t OnFrameShutter(int32_t captureId, const std::vector<int32_t> &streamIds, uint64_t timestamp) override; 62 }; 63 64 class DemoCameraDeviceCallback : public ICameraDeviceCallback { 65 public: 66 DemoCameraDeviceCallback() = default; 67 virtual ~DemoCameraDeviceCallback() = default; 68 69 int32_t OnError(ErrorType type, int32_t errorMsg) override; 70 int32_t OnResult(uint64_t timestamp, const std::vector<uint8_t> &result) override; 71 }; 72 73 class TestCameraHostCallback : public ICameraHostCallback { 74 public: 75 TestCameraHostCallback() = default; 76 virtual ~TestCameraHostCallback() = default; 77 78 int32_t OnCameraStatus(const std::string& cameraId, CameraStatus status) override; 79 int32_t OnFlashlightStatus(const std::string& cameraId, FlashlightStatus status) override; 80 int32_t OnCameraEvent(const std::string& cameraId, CameraEvent event) override; 81 }; 82 }; 83 } 84