Add AV1RateControlRTC::GetLoopfilterLevel

Bug: b/278162842
Change-Id: Iecd85c7bd6bae4c32cb831454b6b44e6c77cfd97
diff --git a/av1/ratectrl_rtc.cc b/av1/ratectrl_rtc.cc
index 7aa2cd8..e1470e6 100644
--- a/av1/ratectrl_rtc.cc
+++ b/av1/ratectrl_rtc.cc
@@ -19,6 +19,7 @@
 #include "aom_mem/aom_mem.h"
 #include "av1/encoder/encoder.h"
 #include "av1/encoder/encoder_utils.h"
+#include "av1/encoder/picklpf.h"
 #include "av1/encoder/ratectrl.h"
 #include "av1/encoder/rc_utils.h"
 #include "av1/encoder/svc_layercontext.h"
@@ -125,6 +126,7 @@
   oxcf->rc_cfg.drop_frames_water_mark = 0;
   oxcf->tool_cfg.bit_depth = AOM_BITS_8;
   oxcf->tool_cfg.superblock_size = AOM_SUPERBLOCK_SIZE_DYNAMIC;
+  oxcf->algo_cfg.loopfilter_control = LOOPFILTER_ALL;
   cm->current_frame.frame_number = 0;
   cpi_->ppi->p_rc.kf_boost = DEFAULT_KF_BOOST_RT;
   for (auto &lvl_idx : oxcf->target_seq_level_idx) lvl_idx = SEQ_LEVEL_MAX;
@@ -303,6 +305,17 @@
   return cpi_->common.quant_params.base_qindex;
 }
 
+AV1LoopfilterLevel AV1RateControlRTC::GetLoopfilterLevel() const {
+  av1_pick_filter_level(nullptr, cpi_, LPF_PICK_FROM_Q);
+  AV1LoopfilterLevel lpf_level;
+  lpf_level.filter_level[0] = cpi_->common.lf.filter_level[0];
+  lpf_level.filter_level[1] = cpi_->common.lf.filter_level[1];
+  lpf_level.filter_level_u = cpi_->common.lf.filter_level_u;
+  lpf_level.filter_level_v = cpi_->common.lf.filter_level_v;
+
+  return lpf_level;
+}
+
 signed char *AV1RateControlRTC::GetCyclicRefreshMap() const {
   return cpi_->cyclic_refresh->map;
 }
diff --git a/av1/ratectrl_rtc.h b/av1/ratectrl_rtc.h
index 2d06ee3..c5d0caa 100644
--- a/av1/ratectrl_rtc.h
+++ b/av1/ratectrl_rtc.h
@@ -63,6 +63,12 @@
   int temporal_layer_id;
 };
 
+struct AV1LoopfilterLevel {
+  int filter_level[2];
+  int filter_level_u;
+  int filter_level_v;
+};
+
 class AV1RateControlRTC {
  public:
   static std::unique_ptr<AV1RateControlRTC> Create(
@@ -72,6 +78,8 @@
   bool UpdateRateControl(const AV1RateControlRtcConfig &rc_cfg);
   // GetQP() needs to be called after ComputeQP() to get the latest QP
   int GetQP() const;
+  // GetLoopfilterLevel() needs to be called after ComputeQP()
+  AV1LoopfilterLevel GetLoopfilterLevel() const;
   signed char *GetCyclicRefreshMap() const;
   int *GetDeltaQ() const;
   void ComputeQP(const AV1FrameParamsRTC &frame_params);
diff --git a/test/ratectrl_rtc_test.cc b/test/ratectrl_rtc_test.cc
index 74c114e..1357983 100644
--- a/test/ratectrl_rtc_test.cc
+++ b/test/ratectrl_rtc_test.cc
@@ -146,6 +146,10 @@
     encoder->Control(AOME_GET_LAST_QUANTIZER, &qp);
     rc_api_->ComputeQP(frame_params_);
     ASSERT_EQ(rc_api_->GetQP(), qp);
+    int encoder_lpf_level;
+    encoder->Control(AOME_GET_LOOPFILTER_LEVEL, &encoder_lpf_level);
+    aom::AV1LoopfilterLevel loopfilter_level = rc_api_->GetLoopfilterLevel();
+    ASSERT_EQ(loopfilter_level.filter_level[0], encoder_lpf_level);
   }
 
   void FramePktHook(const aom_codec_cx_pkt_t *pkt) override {