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_DEPTH_DATA_OUTPUT_H 17 #define OHOS_CAMERA_DEPTH_DATA_OUTPUT_H 18 19 #include <cstdint> 20 #include "camera_output_capability.h" 21 #include "capture_output.h" 22 #include "hstream_depth_data_callback_stub.h" 23 #include "icamera_service.h" 24 #include "istream_depth_data.h" 25 #include "istream_depth_data_callback.h" 26 27 namespace OHOS { 28 namespace CameraStandard { 29 30 class DepthDataStateCallback { 31 public: 32 DepthDataStateCallback() = default; 33 virtual ~DepthDataStateCallback() = default; 34 35 /** 36 * @brief Called when error occured during depth data rendering. 37 * 38 * @param errorCode Indicates a {@link ErrorCode} which will give information for depth data callback error. 39 */ 40 virtual void OnDepthDataError(const int32_t errorCode) const = 0; 41 }; 42 43 class DepthDataOutput : public CaptureOutput { 44 public: 45 explicit DepthDataOutput(sptr<IBufferProducer> bufferProducer); 46 virtual ~DepthDataOutput(); 47 48 /** 49 * @brief Start depth data stream. 50 */ 51 int32_t Start(); 52 53 /** 54 * @brief stop depth data stream. 55 */ 56 int32_t Stop(); 57 58 /** 59 * @brief set depth data accuracy. 60 */ 61 int32_t SetDataAccuracy(int32_t dataAccuracy); 62 63 /** 64 * @brief Create Stream. 65 */ 66 int32_t CreateStream() override; 67 68 /** 69 * @brief Releases a instance of the depth data output. 70 */ 71 int32_t Release() override; 72 73 /** 74 * @brief Set the depth data callback for the depth data output. 75 * 76 * @param DepthDataStateCallback to be triggered. 77 */ 78 void SetCallback(std::shared_ptr<DepthDataStateCallback> callback); 79 80 /** 81 * @brief Get the application callback information. 82 * 83 * @return Returns the pointer application callback. 84 */ 85 std::shared_ptr<DepthDataStateCallback> GetApplicationCallback(); 86 87 void OnNativeRegisterCallback(const std::string& eventString); 88 void OnNativeUnregisterCallback(const std::string& eventString); 89 private: 90 int32_t DepthDataFormat_; 91 Size DepthDataSize_; 92 std::shared_ptr<DepthDataStateCallback> appCallback_; 93 sptr<IStreamDepthDataCallback> svcCallback_; 94 void CameraServerDied(pid_t pid) override; 95 }; 96 97 class DepthDataOutputCallbackImpl : public HStreamDepthDataCallbackStub { 98 public: 99 wptr<DepthDataOutput> depthDataOutput_ = nullptr; DepthDataOutputCallbackImpl()100 DepthDataOutputCallbackImpl() : depthDataOutput_(nullptr) {} 101 DepthDataOutputCallbackImpl(DepthDataOutput * depthDataOutput)102 explicit DepthDataOutputCallbackImpl(DepthDataOutput* depthDataOutput) : depthDataOutput_(depthDataOutput) {} 103 104 /** 105 * @brief Called when error occured during depth data rendering. 106 * 107 * @param errorCode Indicates a {@link ErrorCode} which will give information for depth data callback error. 108 */ 109 int32_t OnDepthDataError(int32_t errorCode) override; 110 }; 111 } // namespace CameraStandard 112 } // namespace OHOS 113 #endif // OHOS_CAMERA_DEPTH_DATA_OUTPUT_H