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 { 24 public: VP8RateControlRtcConfigVP8RateControlRtcConfig25 VP8RateControlRtcConfig() { 26 memset(&layer_target_bitrate, 0, sizeof(layer_target_bitrate)); 27 memset(&ts_rate_decimator, 0, sizeof(ts_rate_decimator)); 28 } 29 }; 30 31 struct VP8FrameParamsQpRTC { 32 RcFrameType frame_type; 33 int temporal_layer_id; 34 }; 35 36 class VP8RateControlRTC { 37 public: 38 static std::unique_ptr<VP8RateControlRTC> Create( 39 const VP8RateControlRtcConfig &cfg); 40 ~VP8RateControlRTC(); 41 42 bool UpdateRateControl(const VP8RateControlRtcConfig &rc_cfg); 43 // GetQP() needs to be called after ComputeQP() to get the latest QP 44 int GetQP() const; 45 // GetLoopfilterLevel() needs to be called after ComputeQP() since loopfilter 46 // level is calculated from frame qp. 47 int GetLoopfilterLevel() const; 48 // ComputeQP computes the QP if the frame is not dropped (kOk return), 49 // otherwise it returns kDrop and subsequent GetQP and PostEncodeUpdate 50 // are not to be called. 51 FrameDropDecision ComputeQP(const VP8FrameParamsQpRTC &frame_params); 52 // Feedback to rate control with the size of current encoded frame 53 void PostEncodeUpdate(uint64_t encoded_frame_size); 54 55 private: VP8RateControlRTC()56 VP8RateControlRTC() {} 57 bool InitRateControl(const VP8RateControlRtcConfig &cfg); 58 struct VP8_COMP *cpi_; 59 int q_; 60 }; 61 62 } // namespace libvpx 63 64 #endif // VPX_VP8_RATECTRL_RTC_H_ 65