Add delta_q support to inspector

Change-Id: Idfc8ebee2325ab51d962efa5846d54db3e139c23
diff --git a/av1/decoder/decodemv.c b/av1/decoder/decodemv.c
index e9164ef..361297d 100644
--- a/av1/decoder/decodemv.c
+++ b/av1/decoder/decodemv.c
@@ -1206,6 +1206,8 @@
 #endif
   }
 
+  mbmi->current_q_index = xd->current_qindex;
+
   mbmi->ref_frame[0] = INTRA_FRAME;
   mbmi->ref_frame[1] = NONE_FRAME;
 
@@ -2710,6 +2712,8 @@
 #endif
   }
 
+  mbmi->current_q_index = xd->current_qindex;
+
   inter_block = read_is_inter_block(cm, xd, mbmi->segment_id, r);
 
   xd->above_txfm_context =
diff --git a/av1/decoder/inspection.c b/av1/decoder/inspection.c
index 96a9321..56e0c28 100644
--- a/av1/decoder/inspection.c
+++ b/av1/decoder/inspection.c
@@ -50,6 +50,8 @@
   fd->base_qindex = cm->base_qindex;
   fd->tile_mi_cols = cm->tile_width;
   fd->tile_mi_rows = cm->tile_height;
+  fd->delta_q_present_flag = cm->delta_q_present_flag;
+  fd->delta_q_res = cm->delta_q_res;
 #if CONFIG_ACCOUNTING
   fd->accounting = &pbi->accounting;
 #endif
@@ -117,6 +119,8 @@
         mi->cfl_alpha_sign = 0;
       }
 #endif
+      // delta_q
+      mi->current_qindex = mbmi->current_q_index;
     }
   }
   return 1;
diff --git a/av1/decoder/inspection.h b/av1/decoder/inspection.h
index 67ddad7..bd9d87a 100644
--- a/av1/decoder/inspection.h
+++ b/av1/decoder/inspection.h
@@ -35,28 +35,29 @@
 
 struct insp_mi_data {
   insp_mv mv[2];
-  int8_t ref_frame[2];
-  int8_t mode;
-  int8_t uv_mode;
-  int8_t sb_type;
-  int8_t skip;
-  int8_t segment_id;
+  int16_t ref_frame[2];
+  int16_t mode;
+  int16_t uv_mode;
+  int16_t sb_type;
+  int16_t skip;
+  int16_t segment_id;
 #if CONFIG_DUAL_FILTER
-  int8_t dual_filter_type;
-  int8_t filter[2];
+  int16_t dual_filter_type;
+  int16_t filter[2];
 #else
-  int8_t filter;
+  int16_t filter;
 #endif
-  int8_t tx_type;
-  int8_t tx_size;
+  int16_t tx_type;
+  int16_t tx_size;
 #if CONFIG_CDEF
-  int8_t cdef_level;
-  int8_t cdef_strength;
+  int16_t cdef_level;
+  int16_t cdef_strength;
 #endif
 #if CONFIG_CFL
-  int8_t cfl_alpha_idx;
-  int8_t cfl_alpha_sign;
+  int16_t cfl_alpha_idx;
+  int16_t cfl_alpha_sign;
 #endif
+  int16_t current_qindex;
 };
 
 typedef struct insp_frame_data insp_frame_data;
@@ -78,6 +79,8 @@
 #if CONFIG_CDEF
 // TODO(negge): add per frame CDEF data
 #endif
+  int delta_q_present_flag;
+  int delta_q_res;
 };
 
 void ifd_init(insp_frame_data *fd, int frame_width, int frame_height);
diff --git a/examples/inspect.c b/examples/inspect.c
index daccb19..fb10499 100644
--- a/examples/inspect.c
+++ b/examples/inspect.c
@@ -58,7 +58,8 @@
   UV_MODE_LAYER = 1 << 10,
   CFL_LAYER = 1 << 11,
   DUAL_FILTER_LAYER = 1 << 12,
-  ALL_LAYERS = (1 << 13) - 1
+  Q_INDEX_LAYER = 1 << 13,
+  ALL_LAYERS = (1 << 14) - 1
 } LayerType;
 
 static LayerType layers = 0;
@@ -98,6 +99,8 @@
 #endif
 static const arg_def_t dump_reference_frame_arg =
     ARG_DEF("r", "referenceFrame", 0, "Dump Reference Frame");
+static const arg_def_t dump_delta_q_arg =
+    ARG_DEF("dq", "delta_q", 0, "Dump QIndex");
 static const arg_def_t usage_arg = ARG_DEF("h", "help", 0, "Help");
 
 static const arg_def_t *main_args[] = { &limit_arg,
@@ -124,6 +127,7 @@
 #endif
                                         &dump_reference_frame_arg,
                                         &dump_motion_vectors_arg,
+                                        &dump_delta_q_arg,
                                         &usage_arg,
                                         NULL };
 #define ENUM(name) \
@@ -432,7 +436,7 @@
     *(buf++) = '[';
     for (c = 0; c < mi_cols; ++c) {
       insp_mi_data *mi = &frame_data.mi_grid[r * mi_cols + c];
-      int8_t *v = ((int8_t *)mi) + offset;
+      int16_t *v = (int16_t *)(((int8_t *)mi) + offset);
       if (len == 0) {
         buf += put_num(buf, 0, v[0], 0);
       } else {
@@ -448,7 +452,7 @@
       if (compress) {  // RLE
         for (t = c + 1; t < mi_cols; ++t) {
           insp_mi_data *next_mi = &frame_data.mi_grid[r * mi_cols + t];
-          int8_t *nv = ((int8_t *)next_mi) + offset;
+          int16_t *nv = (int16_t *)(((int8_t *)next_mi) + offset);
           int same = 0;
           if (len == 0) {
             same = v[0] == nv[0];
@@ -584,6 +588,10 @@
                           offsetof(insp_mi_data, cfl_alpha_sign), 0);
   }
 #endif
+  if (layers & Q_INDEX_LAYER) {
+    buf += put_block_info(buf, NULL, "delta_q",
+                          offsetof(insp_mi_data, current_qindex), 0);
+  }
   if (layers & MOTION_VECTORS_LAYER) {
     buf += put_motion_vectors(buf);
   }
@@ -607,6 +615,10 @@
                   frame_data.tile_mi_cols);
   buf += snprintf(buf, MAX_BUFFER, "  \"tileRows\": %d,\n",
                   frame_data.tile_mi_rows);
+  buf += snprintf(buf, MAX_BUFFER, "  \"deltaQPresentFlag\": %d,\n",
+                  frame_data.delta_q_present_flag);
+  buf += snprintf(buf, MAX_BUFFER, "  \"deltaQRes\": %d,\n",
+                  frame_data.delta_q_res);
   buf += put_str(buf, "  \"config\": {");
   buf += put_map(buf, config_map);
   buf += put_str(buf, "},\n");
@@ -736,6 +748,8 @@
     else if (arg_match(&arg, &dump_dual_filter_type_arg, argi))
       layers |= DUAL_FILTER_LAYER;
 #endif
+    else if (arg_match(&arg, &dump_delta_q_arg, argi))
+      layers |= Q_INDEX_LAYER;
     else if (arg_match(&arg, &dump_all_arg, argi))
       layers |= ALL_LAYERS;
     else if (arg_match(&arg, &compress_arg, argi))