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_VIDEO_OUTPUT_H 17 #define OHOS_CAMERA_VIDEO_OUTPUT_H 18 19 #include <iostream> 20 #include <vector> 21 #include "camera_metadata_info.h" 22 #include "output/capture_output.h" 23 #include "istream_repeat.h" 24 #include "istream_repeat_callback.h" 25 #include "session/capture_session.h" 26 #include "hstream_repeat_callback_stub.h" 27 28 namespace OHOS { 29 namespace CameraStandard { 30 class VideoStateCallback { 31 public: 32 VideoStateCallback() = default; 33 virtual ~VideoStateCallback() = default; 34 35 /** 36 * @brief Called when video frame is started rendering. 37 */ 38 virtual void OnFrameStarted() const = 0; 39 40 /** 41 * @brief Called when video frame is ended. 42 * 43 * @param frameCount Indicates number of frames captured. 44 */ 45 virtual void OnFrameEnded(const int32_t frameCount) const = 0; 46 47 /** 48 * @brief Called when error occured during video rendering. 49 * 50 * @param errorCode Indicates a {@link ErrorCode} which will give information for video callback error. 51 */ 52 virtual void OnError(const int32_t errorCode) const = 0; 53 }; 54 55 class VideoOutput : public CaptureOutput { 56 public: 57 explicit VideoOutput(sptr<IStreamRepeat> &streamRepeat); 58 virtual ~VideoOutput(); 59 60 /** 61 * @brief Releases a instance of the VideoOutput. 62 */ 63 int32_t Release() override; 64 65 /** 66 * @brief Set the video callback for the video output. 67 * 68 * @param VideoStateCallback pointer to be triggered. 69 */ 70 void SetCallback(std::shared_ptr<VideoStateCallback> callback); 71 72 /** 73 * @brief Start the video capture. 74 */ 75 int32_t Start(); 76 77 /** 78 * @brief Stop the video capture. 79 */ 80 int32_t Stop(); 81 82 /** 83 * @brief Pause the video capture. 84 */ 85 int32_t Pause(); 86 87 /** 88 * @brief Resume the paused video capture. 89 */ 90 int32_t Resume(); 91 92 /** 93 * @brief Get the application callback information. 94 * 95 * @return VideoStateCallback pointer set by application. 96 */ 97 std::shared_ptr<VideoStateCallback> GetApplicationCallback(); 98 99 /** 100 * @brief Get the supported video frame rate range. 101 * 102 * @return Returns vector<int32_t> of supported exposure compensation range. 103 */ 104 const std::vector<int32_t>& GetFrameRateRange(); 105 106 /** 107 * @brief Set the Video fps range. If fixed frame rate 108 * to be set the both min and max framerate should be same. 109 * 110 * @param min frame rate value of range. 111 * @param max frame rate value of range. 112 */ 113 void SetFrameRateRange(int32_t minFrameRate, int32_t maxFrameRate); 114 115 private: 116 std::shared_ptr<VideoStateCallback> appCallback_; 117 sptr<IStreamRepeatCallback> svcCallback_; 118 std::vector<int32_t> videoFrameRateRange_; 119 }; 120 121 class VideoOutputCallbackImpl : public HStreamRepeatCallbackStub { 122 public: 123 VideoOutput* videoOutput_ = nullptr; VideoOutputCallbackImpl()124 VideoOutputCallbackImpl() : videoOutput_(nullptr) { 125 } 126 VideoOutputCallbackImpl(VideoOutput * videoOutput)127 explicit VideoOutputCallbackImpl(VideoOutput* videoOutput) : videoOutput_(videoOutput) { 128 } 129 ~VideoOutputCallbackImpl()130 ~VideoOutputCallbackImpl() 131 { 132 videoOutput_ = nullptr; 133 } 134 135 /** 136 * @brief Called when video frame is started rendering. 137 */ 138 int32_t OnFrameStarted() override; 139 140 /** 141 * @brief Called when video frame is ended. 142 * 143 * @param frameCount Indicates number of frames captured. 144 */ 145 int32_t OnFrameEnded(const int32_t frameCount) override; 146 147 /** 148 * @brief Called when error occured during video rendering. 149 * 150 * @param errorCode Indicates a {@link ErrorCode} which will give information for video callback error. 151 */ 152 int32_t OnFrameError(const int32_t errorCode) override; 153 }; 154 } // namespace CameraStandard 155 } // namespace OHOS 156 #endif // OHOS_CAMERA_VIDEO_OUTPUT_H 157