From 74a21444397e323a088fa1f274c9fc942ee7a870 Mon Sep 17 00:00:00 2001
From: Jamaika1 <lukaszcz18@wp.pl>
Date: Wed, 26 Jan 2022 18:24:31 +0100
Subject: [PATCH] Change function in SVT-AV1 0.9.0 (#807)

---
 CHANGELOG.md    | 1 +
 ext/svt.cmd     | 2 +-
 ext/svt.sh      | 2 +-
 src/codec_svt.c | 6 ++++++
 4 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index b3416169..583d3092 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 *   - speed 8-9: re-test and re-adjust speed according to your app needs
 * Update aom.cmd: v3.2.0
 * Update dav1d.cmd: 0.9.2
+* Update svt-av1.cmd: v0.9.0
 * Pass TestCase's minQuantizer, maxQuantizer, speed to encoder.
 * Regenerate tests.json
 * Disable JSON-based tests for now, the metrics are inconsistent/unreliable
diff --git a/ext/svt.cmd b/ext/svt.cmd
index e97de2be..03485b83 100755
--- a/ext/svt.cmd
+++ b/ext/svt.cmd
@@ -11,7 +11,7 @@
 : # If you're running this on Windows, be sure you've already run this (from your VC2019 install dir):
 : #    "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat"
 
-git clone -b v0.8.7 --depth 1 https://gitlab.com/AOMediaCodec/SVT-AV1.git
+git clone -b v0.9.0 --depth 1 https://gitlab.com/AOMediaCodec/SVT-AV1.git
 
 cd SVT-AV1
 cd Build/windows
diff --git a/ext/svt.sh b/ext/svt.sh
index 049bed80..8e3b0f9b 100644
--- a/ext/svt.sh
+++ b/ext/svt.sh
@@ -2,7 +2,7 @@
 # then enable CMake's AVIF_CODEC_SVT and AVIF_LOCAL_SVT options.
 # cmake and ninja must be in your PATH.
 
-git clone -b v0.8.7 --depth 1 https://gitlab.com/AOMediaCodec/SVT-AV1.git
+git clone -b v0.9.0 --depth 1 https://gitlab.com/AOMediaCodec/SVT-AV1.git
 
 cd SVT-AV1
 cd Build/linux
diff --git a/src/codec_svt.c b/src/codec_svt.c
index dfd085a7..3c84defc 100644
--- a/src/codec_svt.c
+++ b/src/codec_svt.c
@@ -92,7 +92,9 @@ static avifResult svtCodecEncodeImage(avifCodec * codec,
         }
         svt_config->encoder_color_format = color_format;
         svt_config->encoder_bit_depth = (uint8_t)image->depth;
+#if !SVT_AV1_CHECK_VERSION(0, 9, 0)
         svt_config->is_16bit_pipeline = image->depth > 8;
+#endif
 
         // Follow comment in svt header: set if input is HDR10 BT2020 using SMPTE ST2084.
         svt_config->high_dynamic_range_input = (image->depth == 10 && image->colorPrimaries == AVIF_COLOR_PRIMARIES_BT2020 &&
@@ -104,8 +106,12 @@ static avifResult svtCodecEncodeImage(avifCodec * codec,
         svt_config->logical_processors = encoder->maxThreads;
         svt_config->enable_adaptive_quantization = AVIF_FALSE;
         // disable 2-pass
+#if SVT_AV1_CHECK_VERSION(0, 9, 0)
+        svt_config->rc_stats_buffer = (SvtAv1FixedBuf) { NULL, 0 };
+#else
         svt_config->rc_firstpass_stats_out = AVIF_FALSE;
         svt_config->rc_twopass_stats_in = (SvtAv1FixedBuf) { NULL, 0 };
+#endif
 
         if (alpha) {
             svt_config->min_qp_allowed = AVIF_CLAMP(encoder->minQuantizerAlpha, 0, 63);
