Merge "Moving segmentation and tile info to uncompressed header." into experimental
This commit is contained in:
		@@ -117,13 +117,8 @@ static int decode_term_subexp(vp9_reader *r, int k, int num_syms) {
 | 
				
			|||||||
  return word;
 | 
					  return word;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int decode_unsigned_max(vp9_reader *r, int max) {
 | 
					static int decode_unsigned_max(struct vp9_read_bit_buffer *rb, int max) {
 | 
				
			||||||
  int data = 0, bit = 0, lmax = max;
 | 
					  const int data = vp9_rb_read_literal(rb, get_unsigned_bits(max));
 | 
				
			||||||
 | 
					 | 
				
			||||||
  while (lmax) {
 | 
					 | 
				
			||||||
    data |= vp9_read_bit(r) << bit++;
 | 
					 | 
				
			||||||
    lmax >>= 1;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  return data > max ? max : data;
 | 
					  return data > max ? max : data;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -566,65 +561,68 @@ static void read_coef_probs_common(FRAME_CONTEXT *fc, TX_SIZE tx_size,
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void read_coef_probs(VP9D_COMP *pbi, vp9_reader *r) {
 | 
					static void read_coef_probs(VP9D_COMP *pbi, vp9_reader *r) {
 | 
				
			||||||
  const TXFM_MODE mode = pbi->common.txfm_mode;
 | 
					  const TXFM_MODE txfm_mode = pbi->common.txfm_mode;
 | 
				
			||||||
  FRAME_CONTEXT *const fc = &pbi->common.fc;
 | 
					  FRAME_CONTEXT *const fc = &pbi->common.fc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  read_coef_probs_common(fc, TX_4X4, r);
 | 
					  read_coef_probs_common(fc, TX_4X4, r);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (mode > ONLY_4X4)
 | 
					  if (txfm_mode > ONLY_4X4)
 | 
				
			||||||
    read_coef_probs_common(fc, TX_8X8, r);
 | 
					    read_coef_probs_common(fc, TX_8X8, r);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (mode > ALLOW_8X8)
 | 
					  if (txfm_mode > ALLOW_8X8)
 | 
				
			||||||
    read_coef_probs_common(fc, TX_16X16, r);
 | 
					    read_coef_probs_common(fc, TX_16X16, r);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (mode > ALLOW_16X16)
 | 
					  if (txfm_mode > ALLOW_16X16)
 | 
				
			||||||
    read_coef_probs_common(fc, TX_32X32, r);
 | 
					    read_coef_probs_common(fc, TX_32X32, r);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void setup_segmentation(VP9_COMMON *pc, MACROBLOCKD *xd, vp9_reader *r) {
 | 
					static void setup_segmentation(VP9D_COMP *pbi, struct vp9_read_bit_buffer *rb) {
 | 
				
			||||||
  int i, j;
 | 
					  int i, j;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  VP9_COMMON *const cm = &pbi->common;
 | 
				
			||||||
 | 
					  MACROBLOCKD *const xd = &pbi->mb;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  xd->update_mb_segmentation_map = 0;
 | 
					  xd->update_mb_segmentation_map = 0;
 | 
				
			||||||
  xd->update_mb_segmentation_data = 0;
 | 
					  xd->update_mb_segmentation_data = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  xd->segmentation_enabled = vp9_read_bit(r);
 | 
					  xd->segmentation_enabled = vp9_rb_read_bit(rb);
 | 
				
			||||||
  if (!xd->segmentation_enabled)
 | 
					  if (!xd->segmentation_enabled)
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Segmentation map update
 | 
					  // Segmentation map update
 | 
				
			||||||
  xd->update_mb_segmentation_map = vp9_read_bit(r);
 | 
					  xd->update_mb_segmentation_map = vp9_rb_read_bit(rb);
 | 
				
			||||||
  if (xd->update_mb_segmentation_map) {
 | 
					  if (xd->update_mb_segmentation_map) {
 | 
				
			||||||
    for (i = 0; i < MB_SEG_TREE_PROBS; i++)
 | 
					    for (i = 0; i < MB_SEG_TREE_PROBS; i++)
 | 
				
			||||||
      xd->mb_segment_tree_probs[i] = vp9_read_bit(r) ? vp9_read_prob(r)
 | 
					      xd->mb_segment_tree_probs[i] = vp9_rb_read_bit(rb) ?
 | 
				
			||||||
                                                     : MAX_PROB;
 | 
					                                         vp9_rb_read_literal(rb, 8) : MAX_PROB;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pc->temporal_update = vp9_read_bit(r);
 | 
					    cm->temporal_update = vp9_rb_read_bit(rb);
 | 
				
			||||||
    if (pc->temporal_update) {
 | 
					    if (cm->temporal_update) {
 | 
				
			||||||
      for (i = 0; i < PREDICTION_PROBS; i++)
 | 
					      for (i = 0; i < PREDICTION_PROBS; i++)
 | 
				
			||||||
        pc->segment_pred_probs[i] = vp9_read_bit(r) ? vp9_read_prob(r)
 | 
					        cm->segment_pred_probs[i] = vp9_rb_read_bit(rb) ?
 | 
				
			||||||
                                                    : MAX_PROB;
 | 
					                                        vp9_rb_read_literal(rb, 8) : MAX_PROB;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      for (i = 0; i < PREDICTION_PROBS; i++)
 | 
					      for (i = 0; i < PREDICTION_PROBS; i++)
 | 
				
			||||||
        pc->segment_pred_probs[i] = MAX_PROB;
 | 
					        cm->segment_pred_probs[i] = MAX_PROB;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Segmentation data update
 | 
					  // Segmentation data update
 | 
				
			||||||
  xd->update_mb_segmentation_data = vp9_read_bit(r);
 | 
					  xd->update_mb_segmentation_data = vp9_rb_read_bit(rb);
 | 
				
			||||||
  if (xd->update_mb_segmentation_data) {
 | 
					  if (xd->update_mb_segmentation_data) {
 | 
				
			||||||
    xd->mb_segment_abs_delta = vp9_read_bit(r);
 | 
					    xd->mb_segment_abs_delta = vp9_rb_read_bit(rb);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    vp9_clearall_segfeatures(xd);
 | 
					    vp9_clearall_segfeatures(xd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; i < MAX_MB_SEGMENTS; i++) {
 | 
					    for (i = 0; i < MAX_MB_SEGMENTS; i++) {
 | 
				
			||||||
      for (j = 0; j < SEG_LVL_MAX; j++) {
 | 
					      for (j = 0; j < SEG_LVL_MAX; j++) {
 | 
				
			||||||
        int data = 0;
 | 
					        int data = 0;
 | 
				
			||||||
        const int feature_enabled = vp9_read_bit(r);
 | 
					        const int feature_enabled = vp9_rb_read_bit(rb);
 | 
				
			||||||
        if (feature_enabled) {
 | 
					        if (feature_enabled) {
 | 
				
			||||||
          vp9_enable_segfeature(xd, i, j);
 | 
					          vp9_enable_segfeature(xd, i, j);
 | 
				
			||||||
          data = decode_unsigned_max(r, vp9_seg_feature_data_max(j));
 | 
					          data = decode_unsigned_max(rb, vp9_seg_feature_data_max(j));
 | 
				
			||||||
          if (vp9_is_segfeature_signed(j))
 | 
					          if (vp9_is_segfeature_signed(j))
 | 
				
			||||||
            data = vp9_read_and_apply_sign(r, data);
 | 
					            data = vp9_rb_read_bit(rb) ? -data : data;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        vp9_set_segdata(xd, i, j, data);
 | 
					        vp9_set_segdata(xd, i, j, data);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@@ -676,14 +674,30 @@ static int read_delta_q(struct vp9_read_bit_buffer *rb, int *delta_q) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void setup_quantization(VP9D_COMP *pbi, struct vp9_read_bit_buffer *rb) {
 | 
					static void setup_quantization(VP9D_COMP *pbi, struct vp9_read_bit_buffer *rb) {
 | 
				
			||||||
 | 
					  MACROBLOCKD *const xd = &pbi->mb;
 | 
				
			||||||
  VP9_COMMON *const cm = &pbi->common;
 | 
					  VP9_COMMON *const cm = &pbi->common;
 | 
				
			||||||
  int update = 0;
 | 
					  int update = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  cm->base_qindex = vp9_rb_read_literal(rb, QINDEX_BITS);
 | 
					  cm->base_qindex = vp9_rb_read_literal(rb, QINDEX_BITS);
 | 
				
			||||||
  update |= read_delta_q(rb, &cm->y_dc_delta_q);
 | 
					  update |= read_delta_q(rb, &cm->y_dc_delta_q);
 | 
				
			||||||
  update |= read_delta_q(rb, &cm->uv_dc_delta_q);
 | 
					  update |= read_delta_q(rb, &cm->uv_dc_delta_q);
 | 
				
			||||||
  update |= read_delta_q(rb, &cm->uv_ac_delta_q);
 | 
					  update |= read_delta_q(rb, &cm->uv_ac_delta_q);
 | 
				
			||||||
  if (update)
 | 
					  if (update)
 | 
				
			||||||
    vp9_init_dequantizer(cm);
 | 
					    vp9_init_dequantizer(cm);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  xd->lossless = cm->base_qindex == 0 &&
 | 
				
			||||||
 | 
					                 cm->y_dc_delta_q == 0 &&
 | 
				
			||||||
 | 
					                 cm->uv_dc_delta_q == 0 &&
 | 
				
			||||||
 | 
					                 cm->uv_ac_delta_q == 0;
 | 
				
			||||||
 | 
					  if (xd->lossless) {
 | 
				
			||||||
 | 
					    xd->itxm_add          = vp9_idct_add_lossless_c;
 | 
				
			||||||
 | 
					    xd->itxm_add_y_block  = vp9_idct_add_y_block_lossless_c;
 | 
				
			||||||
 | 
					    xd->itxm_add_uv_block = vp9_idct_add_uv_block_lossless_c;
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    xd->itxm_add          = vp9_idct_add;
 | 
				
			||||||
 | 
					    xd->itxm_add_y_block  = vp9_idct_add_y_block;
 | 
				
			||||||
 | 
					    xd->itxm_add_uv_block = vp9_idct_add_uv_block;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static INTERPOLATIONFILTERTYPE read_interp_filter_type(
 | 
					static INTERPOLATIONFILTERTYPE read_interp_filter_type(
 | 
				
			||||||
@@ -787,27 +801,33 @@ static void decode_tile(VP9D_COMP *pbi, vp9_reader *r) {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void decode_tiles(VP9D_COMP *pbi,
 | 
					static void setup_tile_info(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) {
 | 
				
			||||||
                         const uint8_t *data, int first_partition_size,
 | 
					  int delta_log2_tiles;
 | 
				
			||||||
                         vp9_reader *header_bc, vp9_reader *residual_bc) {
 | 
					 | 
				
			||||||
  VP9_COMMON *const pc = &pbi->common;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const uint8_t *data_ptr = data + first_partition_size;
 | 
					  vp9_get_tile_n_bits(cm, &cm->log2_tile_columns, &delta_log2_tiles);
 | 
				
			||||||
  int tile_row, tile_col, delta_log2_tiles;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  vp9_get_tile_n_bits(pc, &pc->log2_tile_columns, &delta_log2_tiles);
 | 
					 | 
				
			||||||
  while (delta_log2_tiles--) {
 | 
					  while (delta_log2_tiles--) {
 | 
				
			||||||
    if (vp9_read_bit(header_bc)) {
 | 
					    if (vp9_rb_read_bit(rb)) {
 | 
				
			||||||
      pc->log2_tile_columns++;
 | 
					      cm->log2_tile_columns++;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  pc->log2_tile_rows = vp9_read_bit(header_bc);
 | 
					
 | 
				
			||||||
  if (pc->log2_tile_rows)
 | 
					  cm->log2_tile_rows = vp9_rb_read_bit(rb);
 | 
				
			||||||
    pc->log2_tile_rows += vp9_read_bit(header_bc);
 | 
					  if (cm->log2_tile_rows)
 | 
				
			||||||
  pc->tile_columns = 1 << pc->log2_tile_columns;
 | 
					    cm->log2_tile_rows += vp9_rb_read_bit(rb);
 | 
				
			||||||
  pc->tile_rows    = 1 << pc->log2_tile_rows;
 | 
					
 | 
				
			||||||
 | 
					  cm->tile_columns = 1 << cm->log2_tile_columns;
 | 
				
			||||||
 | 
					  cm->tile_rows    = 1 << cm->log2_tile_rows;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void decode_tiles(VP9D_COMP *pbi,
 | 
				
			||||||
 | 
					                         const uint8_t *data, size_t first_partition_size,
 | 
				
			||||||
 | 
					                         vp9_reader *residual_bc) {
 | 
				
			||||||
 | 
					  VP9_COMMON *const pc = &pbi->common;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const uint8_t *data_ptr = data + first_partition_size;
 | 
				
			||||||
 | 
					  int tile_row, tile_col;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Note: this memset assumes above_context[0], [1] and [2]
 | 
					  // Note: this memset assumes above_context[0], [1] and [2]
 | 
				
			||||||
  // are allocated as part of the same buffer.
 | 
					  // are allocated as part of the same buffer.
 | 
				
			||||||
@@ -955,6 +975,9 @@ size_t read_uncompressed_header(VP9D_COMP *pbi,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  setup_loopfilter(pbi, rb);
 | 
					  setup_loopfilter(pbi, rb);
 | 
				
			||||||
  setup_quantization(pbi, rb);
 | 
					  setup_quantization(pbi, rb);
 | 
				
			||||||
 | 
					  setup_segmentation(pbi, rb);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  setup_tile_info(cm, rb);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return vp9_rb_read_literal(rb, 16);
 | 
					  return vp9_rb_read_literal(rb, 16);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -999,27 +1022,11 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  mb_init_dequantizer(pc, &pbi->mb);  // MB level dequantizer setup
 | 
					  mb_init_dequantizer(pc, &pbi->mb);  // MB level dequantizer setup
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  xd->lossless = pc->base_qindex == 0 &&
 | 
					 | 
				
			||||||
                 pc->y_dc_delta_q == 0 &&
 | 
					 | 
				
			||||||
                 pc->uv_dc_delta_q == 0 &&
 | 
					 | 
				
			||||||
                 pc->uv_ac_delta_q == 0;
 | 
					 | 
				
			||||||
  if (xd->lossless) {
 | 
					 | 
				
			||||||
    xd->itxm_add          = vp9_idct_add_lossless_c;
 | 
					 | 
				
			||||||
    xd->itxm_add_y_block  = vp9_idct_add_y_block_lossless_c;
 | 
					 | 
				
			||||||
    xd->itxm_add_uv_block = vp9_idct_add_uv_block_lossless_c;
 | 
					 | 
				
			||||||
  } else {
 | 
					 | 
				
			||||||
    xd->itxm_add          = vp9_idct_add;
 | 
					 | 
				
			||||||
    xd->itxm_add_y_block  = vp9_idct_add_y_block;
 | 
					 | 
				
			||||||
    xd->itxm_add_uv_block = vp9_idct_add_uv_block;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (!keyframe)
 | 
					  if (!keyframe)
 | 
				
			||||||
    vp9_setup_interp_filters(xd, pc->mcomp_filter_type, pc);
 | 
					    vp9_setup_interp_filters(xd, pc->mcomp_filter_type, pc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pc->fc = pc->frame_contexts[pc->frame_context_idx];
 | 
					  pc->fc = pc->frame_contexts[pc->frame_context_idx];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  setup_segmentation(pc, xd, &header_bc);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  setup_txfm_mode(pc, xd->lossless, &header_bc);
 | 
					  setup_txfm_mode(pc, xd->lossless, &header_bc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  update_frame_context(&pc->fc);
 | 
					  update_frame_context(&pc->fc);
 | 
				
			||||||
@@ -1046,7 +1053,7 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  vp9_decode_mode_mvs_init(pbi, &header_bc);
 | 
					  vp9_decode_mode_mvs_init(pbi, &header_bc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  decode_tiles(pbi, data, first_partition_size, &header_bc, &residual_bc);
 | 
					  decode_tiles(pbi, data, first_partition_size, &residual_bc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pc->last_width = pc->width;
 | 
					  pc->last_width = pc->width;
 | 
				
			||||||
  pc->last_height = pc->height;
 | 
					  pc->last_height = pc->height;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -60,14 +60,7 @@ static INLINE void write_le32(uint8_t *p, int value) {
 | 
				
			|||||||
  p[3] = value >> 24;
 | 
					  p[3] = value >> 24;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void vp9_encode_unsigned_max(vp9_writer *br, int data, int max) {
 | 
					
 | 
				
			||||||
  assert(data <= max);
 | 
					 | 
				
			||||||
  while (max) {
 | 
					 | 
				
			||||||
    vp9_write_bit(br, data & 1);
 | 
					 | 
				
			||||||
    data >>= 1;
 | 
					 | 
				
			||||||
    max >>= 1;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
int recenter_nonneg(int v, int m) {
 | 
					int recenter_nonneg(int v, int m) {
 | 
				
			||||||
  if (v > (m << 1))
 | 
					  if (v > (m << 1))
 | 
				
			||||||
@@ -88,6 +81,11 @@ static int get_unsigned_bits(unsigned num_values) {
 | 
				
			|||||||
  return cat;
 | 
					  return cat;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void vp9_encode_unsigned_max(struct vp9_write_bit_buffer *wb,
 | 
				
			||||||
 | 
					                             int data, int max) {
 | 
				
			||||||
 | 
					  vp9_wb_write_literal(wb, data, get_unsigned_bits(max));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void encode_uniform(vp9_writer *w, int v, int n) {
 | 
					void encode_uniform(vp9_writer *w, int v, int n) {
 | 
				
			||||||
  int l = get_unsigned_bits(n);
 | 
					  int l = get_unsigned_bits(n);
 | 
				
			||||||
  int m;
 | 
					  int m;
 | 
				
			||||||
@@ -1266,73 +1264,63 @@ static void encode_quantization(VP9_COMMON *cm,
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void encode_segmentation(VP9_COMP *cpi, vp9_writer *w) {
 | 
					static void encode_segmentation(VP9_COMP *cpi,
 | 
				
			||||||
 | 
					                               struct vp9_write_bit_buffer *wb) {
 | 
				
			||||||
  int i, j;
 | 
					  int i, j;
 | 
				
			||||||
  VP9_COMMON *const pc = &cpi->common;
 | 
					  VP9_COMMON *const cm = &cpi->common;
 | 
				
			||||||
  MACROBLOCKD *const xd = &cpi->mb.e_mbd;
 | 
					  MACROBLOCKD *const xd = &cpi->mb.e_mbd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  vp9_write_bit(w, xd->segmentation_enabled);
 | 
					  vp9_wb_write_bit(wb, xd->segmentation_enabled);
 | 
				
			||||||
  if (!xd->segmentation_enabled)
 | 
					  if (!xd->segmentation_enabled)
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Segmentation map
 | 
					  // Segmentation map
 | 
				
			||||||
  vp9_write_bit(w, xd->update_mb_segmentation_map);
 | 
					  vp9_wb_write_bit(wb, xd->update_mb_segmentation_map);
 | 
				
			||||||
  if (xd->update_mb_segmentation_map) {
 | 
					  if (xd->update_mb_segmentation_map) {
 | 
				
			||||||
    // Select the coding strategy (temporal or spatial)
 | 
					    // Select the coding strategy (temporal or spatial)
 | 
				
			||||||
    vp9_choose_segmap_coding_method(cpi);
 | 
					    vp9_choose_segmap_coding_method(cpi);
 | 
				
			||||||
    // Write out probabilities used to decode unpredicted  macro-block segments
 | 
					    // Write out probabilities used to decode unpredicted  macro-block segments
 | 
				
			||||||
    for (i = 0; i < MB_SEG_TREE_PROBS; i++) {
 | 
					    for (i = 0; i < MB_SEG_TREE_PROBS; i++) {
 | 
				
			||||||
      const int prob = xd->mb_segment_tree_probs[i];
 | 
					      const int prob = xd->mb_segment_tree_probs[i];
 | 
				
			||||||
      if (prob != MAX_PROB) {
 | 
					      const int update = prob != MAX_PROB;
 | 
				
			||||||
        vp9_write_bit(w, 1);
 | 
					      vp9_wb_write_bit(wb, update);
 | 
				
			||||||
        vp9_write_prob(w, prob);
 | 
					      if (update)
 | 
				
			||||||
      } else {
 | 
					        vp9_wb_write_literal(wb, prob, 8);
 | 
				
			||||||
        vp9_write_bit(w, 0);
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Write out the chosen coding method.
 | 
					    // Write out the chosen coding method.
 | 
				
			||||||
    vp9_write_bit(w, pc->temporal_update);
 | 
					    vp9_wb_write_bit(wb, cm->temporal_update);
 | 
				
			||||||
    if (pc->temporal_update) {
 | 
					    if (cm->temporal_update) {
 | 
				
			||||||
      for (i = 0; i < PREDICTION_PROBS; i++) {
 | 
					      for (i = 0; i < PREDICTION_PROBS; i++) {
 | 
				
			||||||
        const int prob = pc->segment_pred_probs[i];
 | 
					        const int prob = cm->segment_pred_probs[i];
 | 
				
			||||||
        if (prob != MAX_PROB) {
 | 
					        const int update = prob != MAX_PROB;
 | 
				
			||||||
          vp9_write_bit(w, 1);
 | 
					        vp9_wb_write_bit(wb, update);
 | 
				
			||||||
          vp9_write_prob(w, prob);
 | 
					        if (update)
 | 
				
			||||||
        } else {
 | 
					          vp9_wb_write_literal(wb, prob, 8);
 | 
				
			||||||
          vp9_write_bit(w, 0);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Segmentation data
 | 
					  // Segmentation data
 | 
				
			||||||
  vp9_write_bit(w, xd->update_mb_segmentation_data);
 | 
					  vp9_wb_write_bit(wb, xd->update_mb_segmentation_data);
 | 
				
			||||||
  // segment_reference_frames(cpi);
 | 
					  // segment_reference_frames(cpi);
 | 
				
			||||||
  if (xd->update_mb_segmentation_data) {
 | 
					  if (xd->update_mb_segmentation_data) {
 | 
				
			||||||
    vp9_write_bit(w, xd->mb_segment_abs_delta);
 | 
					    vp9_wb_write_bit(wb, xd->mb_segment_abs_delta);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; i < MAX_MB_SEGMENTS; i++) {
 | 
					    for (i = 0; i < MAX_MB_SEGMENTS; i++) {
 | 
				
			||||||
      for (j = 0; j < SEG_LVL_MAX; j++) {
 | 
					      for (j = 0; j < SEG_LVL_MAX; j++) {
 | 
				
			||||||
        const int data = vp9_get_segdata(xd, i, j);
 | 
					        const int active = vp9_segfeature_active(xd, i, j);
 | 
				
			||||||
        const int data_max = vp9_seg_feature_data_max(j);
 | 
					        vp9_wb_write_bit(wb, active);
 | 
				
			||||||
 | 
					        if (active) {
 | 
				
			||||||
        if (vp9_segfeature_active(xd, i, j)) {
 | 
					          const int data = vp9_get_segdata(xd, i, j);
 | 
				
			||||||
          vp9_write_bit(w, 1);
 | 
					          const int data_max = vp9_seg_feature_data_max(j);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          if (vp9_is_segfeature_signed(j)) {
 | 
					          if (vp9_is_segfeature_signed(j)) {
 | 
				
			||||||
            if (data < 0) {
 | 
					            vp9_encode_unsigned_max(wb, abs(data), data_max);
 | 
				
			||||||
              vp9_encode_unsigned_max(w, -data, data_max);
 | 
					            vp9_wb_write_bit(wb, data < 0);
 | 
				
			||||||
              vp9_write_bit(w, 1);
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
              vp9_encode_unsigned_max(w, data, data_max);
 | 
					 | 
				
			||||||
              vp9_write_bit(w, 0);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
          } else {
 | 
					          } else {
 | 
				
			||||||
            vp9_encode_unsigned_max(w, data, data_max);
 | 
					            vp9_encode_unsigned_max(wb, data, data_max);
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
          vp9_write_bit(w, 0);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -1414,6 +1402,24 @@ static void fix_mcomp_filter_type(VP9_COMP *cpi) {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void write_tile_info(VP9_COMMON *cm, struct vp9_write_bit_buffer *wb) {
 | 
				
			||||||
 | 
					  int min_log2_tiles, delta_log2_tiles, n_tile_bits, n;
 | 
				
			||||||
 | 
					  vp9_get_tile_n_bits(cm, &min_log2_tiles, &delta_log2_tiles);
 | 
				
			||||||
 | 
					  n_tile_bits = cm->log2_tile_columns - min_log2_tiles;
 | 
				
			||||||
 | 
					  for (n = 0; n < delta_log2_tiles; n++) {
 | 
				
			||||||
 | 
					    if (n_tile_bits--) {
 | 
				
			||||||
 | 
					      vp9_wb_write_bit(wb, 1);
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      vp9_wb_write_bit(wb, 0);
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  vp9_wb_write_bit(wb, cm->log2_tile_rows != 0);
 | 
				
			||||||
 | 
					  if (cm->log2_tile_rows != 0)
 | 
				
			||||||
 | 
					    vp9_wb_write_bit(wb, cm->log2_tile_rows != 1);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void write_uncompressed_header(VP9_COMP *cpi,
 | 
					void write_uncompressed_header(VP9_COMP *cpi,
 | 
				
			||||||
                               struct vp9_write_bit_buffer *wb) {
 | 
					                               struct vp9_write_bit_buffer *wb) {
 | 
				
			||||||
  VP9_COMMON *const cm = &cpi->common;
 | 
					  VP9_COMMON *const cm = &cpi->common;
 | 
				
			||||||
@@ -1522,6 +1528,9 @@ void write_uncompressed_header(VP9_COMP *cpi,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  encode_loopfilter(cm, xd, wb);
 | 
					  encode_loopfilter(cm, xd, wb);
 | 
				
			||||||
  encode_quantization(cm, wb);
 | 
					  encode_quantization(cm, wb);
 | 
				
			||||||
 | 
					  encode_segmentation(cpi, wb);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  write_tile_info(cm, wb);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, unsigned long *size) {
 | 
					void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, unsigned long *size) {
 | 
				
			||||||
@@ -1552,8 +1561,6 @@ void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, unsigned long *size) {
 | 
				
			|||||||
    active_section = 7;
 | 
					    active_section = 7;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  encode_segmentation(cpi, &header_bc);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (xd->lossless)
 | 
					  if (xd->lossless)
 | 
				
			||||||
    pc->txfm_mode = ONLY_4X4;
 | 
					    pc->txfm_mode = ONLY_4X4;
 | 
				
			||||||
  else
 | 
					  else
 | 
				
			||||||
@@ -1630,24 +1637,6 @@ void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, unsigned long *size) {
 | 
				
			|||||||
    vp9_write_nmv_probs(cpi, xd->allow_high_precision_mv, &header_bc);
 | 
					    vp9_write_nmv_probs(cpi, xd->allow_high_precision_mv, &header_bc);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* tiling */
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    int min_log2_tiles, delta_log2_tiles, n_tile_bits, n;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    vp9_get_tile_n_bits(pc, &min_log2_tiles, &delta_log2_tiles);
 | 
					 | 
				
			||||||
    n_tile_bits = pc->log2_tile_columns - min_log2_tiles;
 | 
					 | 
				
			||||||
    for (n = 0; n < delta_log2_tiles; n++) {
 | 
					 | 
				
			||||||
      if (n_tile_bits--) {
 | 
					 | 
				
			||||||
        vp9_write_bit(&header_bc, 1);
 | 
					 | 
				
			||||||
      } else {
 | 
					 | 
				
			||||||
        vp9_write_bit(&header_bc, 0);
 | 
					 | 
				
			||||||
        break;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    vp9_write_bit(&header_bc, pc->log2_tile_rows != 0);
 | 
					 | 
				
			||||||
    if (pc->log2_tile_rows != 0)
 | 
					 | 
				
			||||||
      vp9_write_bit(&header_bc, pc->log2_tile_rows != 1);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  vp9_stop_encode(&header_bc);
 | 
					  vp9_stop_encode(&header_bc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user