Add codec control to get loopfilter level

Change-Id: Iee5e37d816d4250688f8cd9e51a4013376b80a6a
diff --git a/aom/aomcx.h b/aom/aomcx.h
index a83470b..b8462e5 100644
--- a/aom/aomcx.h
+++ b/aom/aomcx.h
@@ -1393,6 +1393,10 @@
    */
   AV1E_SET_LOOPFILTER_CONTROL = 149,
 
+  /*!\brief Codec control function to get the loopfilter chosen by the encoder,
+   * int* parameter
+   */
+  AOME_GET_LOOPFILTER_LEVEL = 150,
   // Any new encoder control IDs should be added above.
   // Maximum allowed encoder control ID is 229.
   // No encoder control ID should be added below.
@@ -1958,6 +1962,9 @@
 AOM_CTRL_USE_TYPE(AV1E_SET_LOOPFILTER_CONTROL, int)
 #define AOM_CTRL_AV1E_SET_LOOPFILTER_CONTROL
 
+AOM_CTRL_USE_TYPE(AOME_GET_LOOPFILTER_LEVEL, int *)
+#define AOM_CTRL_AOME_GET_LOOPFILTER_LEVEL
+
 /*!\endcond */
 /*! @} - end defgroup aom_encoder */
 #ifdef __cplusplus
diff --git a/av1/av1_cx_iface.c b/av1/av1_cx_iface.c
index d902f1f..458e1b2 100644
--- a/av1/av1_cx_iface.c
+++ b/av1/av1_cx_iface.c
@@ -1483,6 +1483,14 @@
   return AOM_CODEC_OK;
 }
 
+static aom_codec_err_t ctrl_get_loopfilter_level(aom_codec_alg_priv_t *ctx,
+                                                 va_list args) {
+  int *const arg = va_arg(args, int *);
+  if (arg == NULL) return AOM_CODEC_INVALID_PARAM;
+  *arg = ctx->ppi->cpi->common.lf.filter_level[0];
+  return AOM_CODEC_OK;
+}
+
 static aom_codec_err_t ctrl_get_baseline_gf_interval(aom_codec_alg_priv_t *ctx,
                                                      va_list args) {
   int *const arg = va_arg(args, int *);
@@ -3967,6 +3975,7 @@
   // Getters
   { AOME_GET_LAST_QUANTIZER, ctrl_get_quantizer },
   { AOME_GET_LAST_QUANTIZER_64, ctrl_get_quantizer64 },
+  { AOME_GET_LOOPFILTER_LEVEL, ctrl_get_loopfilter_level },
   { AV1_GET_REFERENCE, ctrl_get_reference },
   { AV1E_GET_ACTIVEMAP, ctrl_get_active_map },
   { AV1_GET_NEW_FRAME_IMAGE, ctrl_get_new_frame_image },
diff --git a/test/loopfilter_control_test.cc b/test/loopfilter_control_test.cc
index f604326..a67e97b 100644
--- a/test/loopfilter_control_test.cc
+++ b/test/loopfilter_control_test.cc
@@ -172,6 +172,18 @@
 
 TEST_P(LFControlEndToEndTestThreaded, EndtoEndPSNRTest) { DoTest(); }
 
+TEST(LFControlGetterTest, NullptrInput) {
+  int *lf_level = nullptr;
+  aom_codec_ctx_t encoder;
+  aom_codec_enc_cfg_t cfg;
+  aom_codec_enc_config_default(aom_codec_av1_cx(), &cfg, 1);
+  EXPECT_EQ(aom_codec_enc_init(&encoder, aom_codec_av1_cx(), &cfg, 0),
+            AOM_CODEC_OK);
+  EXPECT_EQ(aom_codec_control(&encoder, AOME_GET_LOOPFILTER_LEVEL, lf_level),
+            AOM_CODEC_INVALID_PARAM);
+  EXPECT_EQ(aom_codec_destroy(&encoder), AOM_CODEC_OK);
+}
+
 AV1_INSTANTIATE_TEST_SUITE(LFControlEndToEndTest,
                            ::testing::ValuesIn(kTestVectors),
                            ::testing::Range(0, 4),