From 5fa64bdef0bf760074407b9bf853eef6d64ea089 Mon Sep 17 00:00:00 2001
From: Deb Mukherjee <debargha@google.com>
Date: Mon, 22 Apr 2013 12:43:12 -0700
Subject: [PATCH] Bugfix from reordering frame probs patch

This fixes an intermittent mismatch issue cause by moving
the lossless mode decoding bit to after the loop filter
setup information. We need to ensure that the lossless bit
is decoded prior to loop filter setup.

Change-Id: I3faa3fff8e1013b7405dac91268350e059ed121e
---
 vp9/decoder/vp9_decodframe.c | 3 ++-
 vp9/encoder/vp9_bitstream.c  | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/vp9/decoder/vp9_decodframe.c b/vp9/decoder/vp9_decodframe.c
index a13c4580a5..da0159769a 100644
--- a/vp9/decoder/vp9_decodframe.c
+++ b/vp9/decoder/vp9_decodframe.c
@@ -1613,6 +1613,8 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) {
   pc->clamp_type = (CLAMP_TYPE)vp9_read_bit(&header_bc);
   pc->error_resilient_mode = vp9_read_bit(&header_bc);
 
+  xd->lossless = vp9_read_bit(&header_bc);
+
   setup_loopfilter(pc, xd, &header_bc);
 
   // Dummy read for now
@@ -1681,7 +1683,6 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) {
 
   setup_pred_probs(pc, &header_bc);
 
-  xd->lossless = vp9_read_bit(&header_bc);
   pc->txfm_mode = xd->lossless ? ONLY_4X4 : read_txfm_mode(&header_bc);
   if (pc->txfm_mode == TX_MODE_SELECT) {
     pc->prob_tx[0] = vp9_read_prob(&header_bc);
diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c
index b12e28816d..1f419c3f51 100644
--- a/vp9/encoder/vp9_bitstream.c
+++ b/vp9/encoder/vp9_bitstream.c
@@ -2614,6 +2614,9 @@ void vp9_pack_bitstream(VP9_COMP *cpi, unsigned char *dest,
   // error resilient mode
   vp9_write_bit(&header_bc, pc->error_resilient_mode);
 
+  // lossless mode: note this needs to be before loopfilter
+  vp9_write_bit(&header_bc, cpi->mb.e_mbd.lossless);
+
   // Encode the loop filter level and type
   vp9_write_bit(&header_bc, pc->filter_type);
   vp9_write_literal(&header_bc, pc->filter_level, 6);
@@ -2883,7 +2886,6 @@ void vp9_pack_bitstream(VP9_COMP *cpi, unsigned char *dest,
     }
   }
 
-  vp9_write_bit(&header_bc, cpi->mb.e_mbd.lossless);
   if (cpi->mb.e_mbd.lossless) {
     pc->txfm_mode = ONLY_4X4;
   } else {
-- 
GitLab