When reconfiguring VP9 restore previous input pixel format

Otherwise if the pixel format is not I420, the image buffer will
need to be reallocated on each reconfiguration.

Bug: webrtc:11974
Change-Id: Ib13f1865d7dbba4635f57dc09c7bff846e127585
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/186340
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Evan Shrubsole <eshr@google.com>
Cr-Commit-Position: refs/heads/master@{#32281}
diff --git a/modules/video_coding/codecs/vp9/vp9_impl.cc b/modules/video_coding/codecs/vp9/vp9_impl.cc
index 59a0a13..07ccab3 100644
--- a/modules/video_coding/codecs/vp9/vp9_impl.cc
+++ b/modules/video_coding/codecs/vp9/vp9_impl.cc
@@ -490,6 +490,9 @@
     return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
   }
 
+  absl::optional<vpx_img_fmt_t> previous_img_fmt =
+      raw_ ? absl::make_optional<vpx_img_fmt_t>(raw_->fmt) : absl::nullopt;
+
   int ret_val = Release();
   if (ret_val < 0) {
     return ret_val;
@@ -530,7 +533,7 @@
   unsigned int bits_for_storage = 8;
   switch (profile_) {
     case VP9Profile::kProfile0:
-      img_fmt = VPX_IMG_FMT_I420;
+      img_fmt = previous_img_fmt.value_or(VPX_IMG_FMT_I420);
       bits_for_storage = 8;
       config_->g_bit_depth = VPX_BITS_8;
       config_->g_profile = 0;