1 /* 2 * Copyright (c) 2021 The WebM project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef VPX_VP8_RATECTRL_RTC_H_ 12 #define VPX_VP8_RATECTRL_RTC_H_ 13 14 #include <cstdint> 15 #include <cstring> 16 #include <memory> 17 18 #include "vpx/internal/vpx_ratectrl_rtc.h" 19 20 struct VP8_COMP; 21 22 namespace libvpx { 23 struct VP8RateControlRtcConfig : public VpxRateControlRtcConfig { VP8RateControlRtcConfigVP8RateControlRtcConfig24 VP8RateControlRtcConfig() { 25 memset(&layer_target_bitrate, 0, sizeof(layer_target_bitrate)); 26 memset(&ts_rate_decimator, 0, sizeof(ts_rate_decimator)); 27 } 28 }; 29 30 struct VP8FrameParamsQpRTC { 31 RcFrameType frame_type; 32 int temporal_layer_id; 33 }; 34 35 class VP8RateControlRTC { 36 public: 37 static std::unique_ptr<VP8RateControlRTC> Create( 38 const VP8RateControlRtcConfig &cfg); 39 ~VP8RateControlRTC(); 40 41 bool UpdateRateControl(const VP8RateControlRtcConfig &rc_cfg); 42 // GetQP() needs to be called after ComputeQP() to get the latest QP 43 int GetQP() const; 44 // GetUVDeltaQP() needs to be called after ComputeQP() to get the latest 45 // delta QP for UV. 46 UVDeltaQP GetUVDeltaQP() const; 47 // GetLoopfilterLevel() needs to be called after ComputeQP() since loopfilter 48 // level is calculated from frame qp. 49 int GetLoopfilterLevel() const; 50 // ComputeQP computes the QP if the frame is not dropped (kOk return), 51 // otherwise it returns kDrop and subsequent GetQP and PostEncodeUpdate 52 // are not to be called. 53 FrameDropDecision ComputeQP(const VP8FrameParamsQpRTC &frame_params); 54 // Feedback to rate control with the size of current encoded frame 55 void PostEncodeUpdate(uint64_t encoded_frame_size); 56 57 private: 58 VP8RateControlRTC() = default; 59 bool InitRateControl(const VP8RateControlRtcConfig &cfg); 60 struct VP8_COMP *cpi_ = nullptr; 61 int q_ = -1; 62 }; 63 64 } // namespace libvpx 65 66 #endif // VPX_VP8_RATECTRL_RTC_H_ 67