1 /* 2 * Copyright (c) 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 #ifndef OHOS_FPS_CONTROLLER_PROCESS_H 16 #define OHOS_FPS_CONTROLLER_PROCESS_H 17 18 #include <cstdint> 19 #include <vector> 20 21 #include "abstract_data_process.h" 22 #include "dcamera_pipeline_source.h" 23 24 namespace OHOS { 25 namespace DistributedHardware { 26 class DCameraPipelineSource; 27 28 class FpsControllerProcess : public AbstractDataProcess { 29 public: FpsControllerProcess(const std::weak_ptr<DCameraPipelineSource> & callbackPipSource)30 explicit FpsControllerProcess(const std::weak_ptr<DCameraPipelineSource>& callbackPipSource) 31 : callbackPipelineSource_(callbackPipSource) {} 32 ~FpsControllerProcess(); 33 34 int32_t InitNode(const VideoConfigParams& sourceConfig, const VideoConfigParams& targetConfig, 35 VideoConfigParams& processedConfig) override; 36 int32_t ProcessData(std::vector<std::shared_ptr<DataBuffer>>& inputBuffers) override; 37 void ReleaseProcessNode() override; 38 39 private: 40 void UpdateFPSControllerInfo(int64_t nowMs); 41 void UpdateFrameRateCorrectionFactor(int64_t nowMs); 42 void UpdateIncomingFrameTimes(int64_t nowMs); 43 float CalculateFrameRate(int64_t nowMs); 44 bool IsDropFrame(float incomingFps); 45 bool ReduceFrameRateByUniformStrategy(int32_t incomingFps); 46 int32_t FpsControllerDone(std::vector<std::shared_ptr<DataBuffer>>& outputBuffers); 47 48 private: 49 constexpr static int32_t MAX_TARGET_FRAME_RATE = 30; 50 constexpr static int32_t VIDEO_FRAME_DROP_INTERVAL = 4; 51 constexpr static int32_t MIN_INCOME_FRAME_NUM_COEFFICIENT = 3; 52 constexpr static int32_t INCOME_FRAME_TIME_HISTORY_WINDOWS_SIZE = 60; 53 /* Receive video frame detect time windows */ 54 constexpr static int32_t FRAME_HISTORY_TIME_WINDOWS_MS = 2000; 55 constexpr static int64_t FRMAE_MAX_INTERVAL_TIME_WINDOW_MS = 700; 56 constexpr static int32_t OVERSHOOT_MODIFY_COEFFICIENT = 3; 57 constexpr static int32_t DOUBLE_MULTIPLE = 2; 58 59 std::weak_ptr<DCameraPipelineSource> callbackPipelineSource_; 60 std::mutex mtx; 61 VideoConfigParams sourceConfig_; 62 VideoConfigParams targetConfig_; 63 VideoConfigParams processedConfig_; 64 bool isFpsControllerProcess_ = false; 65 bool isFirstFrame_ = false; 66 int32_t targetFrameRate_ = 0; 67 int64_t lastFrameIncomeTimeMs_ = 0; 68 /* the time span between current and last frame */ 69 int64_t recentFrameTimeSpanMs_ = -1; 70 int32_t keepCorrectionCount_ = 0; 71 int32_t keepLessThanDoubleCount_ = 0; 72 int32_t keepMoreThanDoubleCount_ = 0; 73 float frameRateCorrectionFactor_ = 0.0; 74 /* modify the frame rate controller argument */ 75 int32_t frameRateOvershootMdf_ = 0; 76 int64_t incomingFrameTimesMs_[INCOME_FRAME_TIME_HISTORY_WINDOWS_SIZE] = { 0 }; 77 }; 78 } // namespace DistributedHardware 79 } // namespace OHOS 80 #endif // OHOS_FPS_CONTROLLER_PROCESS_H