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 <memory> 16 17 #include "vp8/encoder/onyx_int.h" 18 #include "vp8/common/common.h" 19 #include "vpx/internal/vpx_ratectrl_rtc.h" 20 21 namespace libvpx { 22 struct VP8RateControlRtcConfig : public VpxRateControlRtcConfig { 23 public: VP8RateControlRtcConfigVP8RateControlRtcConfig24 VP8RateControlRtcConfig() { 25 vp8_zero(layer_target_bitrate); 26 vp8_zero(ts_rate_decimator); 27 } 28 }; 29 30 struct VP8FrameParamsQpRTC { 31 FRAME_TYPE 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); ~VP8RateControlRTC()39 ~VP8RateControlRTC() { 40 if (cpi_) { 41 vpx_free(cpi_->gf_active_flags); 42 vpx_free(cpi_); 43 } 44 } 45 46 void UpdateRateControl(const VP8RateControlRtcConfig &rc_cfg); 47 // GetQP() needs to be called after ComputeQP() to get the latest QP 48 int GetQP() const; 49 // int GetLoopfilterLevel() const; 50 void ComputeQP(const VP8FrameParamsQpRTC &frame_params); 51 // Feedback to rate control with the size of current encoded frame 52 void PostEncodeUpdate(uint64_t encoded_frame_size); 53 54 private: VP8RateControlRTC()55 VP8RateControlRTC() {} 56 void InitRateControl(const VP8RateControlRtcConfig &cfg); 57 VP8_COMP *cpi_; 58 int q_; 59 }; 60 61 } // namespace libvpx 62 63 #endif // VPX_VP8_RATECTRL_RTC_H_ 64