| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <assert.h> | 11 #include <assert.h> |
| 12 #include <stdio.h> | 12 #include <stdio.h> |
| 13 #include <limits.h> | 13 #include <limits.h> |
| 14 | 14 |
| 15 #include "vpx/vpx_encoder.h" | 15 #include "vpx/vpx_encoder.h" |
| 16 #include "vpx_mem/vpx_mem.h" | 16 #include "vpx_mem/vpx_mem.h" |
| 17 #include "vpx_ports/mem_ops.h" |
| 17 | 18 |
| 19 #include "vp9/common/vp9_entropy.h" |
| 18 #include "vp9/common/vp9_entropymode.h" | 20 #include "vp9/common/vp9_entropymode.h" |
| 19 #include "vp9/common/vp9_entropymv.h" | 21 #include "vp9/common/vp9_entropymv.h" |
| 22 #include "vp9/common/vp9_mvref_common.h" |
| 23 #include "vp9/common/vp9_pragmas.h" |
| 24 #include "vp9/common/vp9_pred_common.h" |
| 25 #include "vp9/common/vp9_seg_common.h" |
| 26 #include "vp9/common/vp9_systemdependent.h" |
| 20 #include "vp9/common/vp9_tile_common.h" | 27 #include "vp9/common/vp9_tile_common.h" |
| 21 #include "vp9/common/vp9_seg_common.h" | |
| 22 #include "vp9/common/vp9_pred_common.h" | |
| 23 #include "vp9/common/vp9_entropy.h" | |
| 24 #include "vp9/common/vp9_mvref_common.h" | |
| 25 #include "vp9/common/vp9_systemdependent.h" | |
| 26 #include "vp9/common/vp9_pragmas.h" | |
| 27 | 28 |
| 29 #include "vp9/encoder/vp9_bitstream.h" |
| 30 #include "vp9/encoder/vp9_encodemv.h" |
| 28 #include "vp9/encoder/vp9_mcomp.h" | 31 #include "vp9/encoder/vp9_mcomp.h" |
| 29 #include "vp9/encoder/vp9_encodemv.h" | |
| 30 #include "vp9/encoder/vp9_bitstream.h" | |
| 31 #include "vp9/encoder/vp9_segmentation.h" | 32 #include "vp9/encoder/vp9_segmentation.h" |
| 32 #include "vp9/encoder/vp9_subexp.h" | 33 #include "vp9/encoder/vp9_subexp.h" |
| 33 #include "vp9/encoder/vp9_tokenize.h" | 34 #include "vp9/encoder/vp9_tokenize.h" |
| 34 #include "vp9/encoder/vp9_write_bit_buffer.h" | 35 #include "vp9/encoder/vp9_write_bit_buffer.h" |
| 35 | 36 |
| 36 #ifdef ENTROPY_STATS | 37 #ifdef ENTROPY_STATS |
| 37 vp9_coeff_stats tree_update_hist[TX_SIZES][PLANE_TYPES]; | |
| 38 extern unsigned int active_section; | 38 extern unsigned int active_section; |
| 39 #endif | 39 #endif |
| 40 | 40 |
| 41 static struct vp9_token intra_mode_encodings[INTRA_MODES]; | 41 static struct vp9_token intra_mode_encodings[INTRA_MODES]; |
| 42 static struct vp9_token switchable_interp_encodings[SWITCHABLE_FILTERS]; | 42 static struct vp9_token switchable_interp_encodings[SWITCHABLE_FILTERS]; |
| 43 static struct vp9_token partition_encodings[PARTITION_TYPES]; | 43 static struct vp9_token partition_encodings[PARTITION_TYPES]; |
| 44 static struct vp9_token inter_mode_encodings[INTER_MODES]; | 44 static struct vp9_token inter_mode_encodings[INTER_MODES]; |
| 45 | 45 |
| 46 void vp9_entropy_mode_init() { | 46 void vp9_entropy_mode_init() { |
| 47 vp9_tokens_from_tree(intra_mode_encodings, vp9_intra_mode_tree); | 47 vp9_tokens_from_tree(intra_mode_encodings, vp9_intra_mode_tree); |
| 48 vp9_tokens_from_tree(switchable_interp_encodings, vp9_switchable_interp_tree); | 48 vp9_tokens_from_tree(switchable_interp_encodings, vp9_switchable_interp_tree); |
| 49 vp9_tokens_from_tree(partition_encodings, vp9_partition_tree); | 49 vp9_tokens_from_tree(partition_encodings, vp9_partition_tree); |
| 50 vp9_tokens_from_tree(inter_mode_encodings, vp9_inter_mode_tree); | 50 vp9_tokens_from_tree(inter_mode_encodings, vp9_inter_mode_tree); |
| 51 } | 51 } |
| 52 | 52 |
| 53 static void write_intra_mode(vp9_writer *w, MB_PREDICTION_MODE mode, | 53 static void write_intra_mode(vp9_writer *w, MB_PREDICTION_MODE mode, |
| 54 const vp9_prob *probs) { | 54 const vp9_prob *probs) { |
| 55 vp9_write_token(w, vp9_intra_mode_tree, probs, &intra_mode_encodings[mode]); | 55 vp9_write_token(w, vp9_intra_mode_tree, probs, &intra_mode_encodings[mode]); |
| 56 } | 56 } |
| 57 | 57 |
| 58 static void write_inter_mode(vp9_writer *w, MB_PREDICTION_MODE mode, | 58 static void write_inter_mode(vp9_writer *w, MB_PREDICTION_MODE mode, |
| 59 const vp9_prob *probs) { | 59 const vp9_prob *probs) { |
| 60 assert(is_inter_mode(mode)); | 60 assert(is_inter_mode(mode)); |
| 61 vp9_write_token(w, vp9_inter_mode_tree, probs, | 61 vp9_write_token(w, vp9_inter_mode_tree, probs, |
| 62 &inter_mode_encodings[INTER_OFFSET(mode)]); | 62 &inter_mode_encodings[INTER_OFFSET(mode)]); |
| 63 } | 63 } |
| 64 | 64 |
| 65 static INLINE void write_be32(uint8_t *p, int value) { | 65 static void encode_unsigned_max(struct vp9_write_bit_buffer *wb, |
| 66 p[0] = value >> 24; | 66 int data, int max) { |
| 67 p[1] = value >> 16; | |
| 68 p[2] = value >> 8; | |
| 69 p[3] = value; | |
| 70 } | |
| 71 | |
| 72 void vp9_encode_unsigned_max(struct vp9_write_bit_buffer *wb, | |
| 73 int data, int max) { | |
| 74 vp9_wb_write_literal(wb, data, get_unsigned_bits(max)); | 67 vp9_wb_write_literal(wb, data, get_unsigned_bits(max)); |
| 75 } | 68 } |
| 76 | 69 |
| 77 static void prob_diff_update(const vp9_tree_index *tree, | 70 static void prob_diff_update(const vp9_tree_index *tree, |
| 78 vp9_prob probs[/*n - 1*/], | 71 vp9_prob probs[/*n - 1*/], |
| 79 const unsigned int counts[/*n - 1*/], | 72 const unsigned int counts[/*n - 1*/], |
| 80 int n, vp9_writer *w) { | 73 int n, vp9_writer *w) { |
| 81 int i; | 74 int i; |
| 82 unsigned int branch_ct[32][2]; | 75 unsigned int branch_ct[32][2]; |
| 83 | 76 |
| 84 // Assuming max number of probabilities <= 32 | 77 // Assuming max number of probabilities <= 32 |
| 85 assert(n <= 32); | 78 assert(n <= 32); |
| 86 | 79 |
| 87 vp9_tree_probs_from_distribution(tree, branch_ct, counts); | 80 vp9_tree_probs_from_distribution(tree, branch_ct, counts); |
| 88 for (i = 0; i < n - 1; ++i) | 81 for (i = 0; i < n - 1; ++i) |
| 89 vp9_cond_prob_diff_update(w, &probs[i], branch_ct[i]); | 82 vp9_cond_prob_diff_update(w, &probs[i], branch_ct[i]); |
| 90 } | 83 } |
| 91 | 84 |
| 92 static void write_selected_tx_size(const VP9_COMP *cpi, MODE_INFO *m, | 85 static void write_selected_tx_size(const VP9_COMP *cpi, |
| 93 TX_SIZE tx_size, BLOCK_SIZE bsize, | 86 TX_SIZE tx_size, BLOCK_SIZE bsize, |
| 94 vp9_writer *w) { | 87 vp9_writer *w) { |
| 95 const TX_SIZE max_tx_size = max_txsize_lookup[bsize]; | 88 const TX_SIZE max_tx_size = max_txsize_lookup[bsize]; |
| 96 const MACROBLOCKD *const xd = &cpi->mb.e_mbd; | 89 const MACROBLOCKD *const xd = &cpi->mb.e_mbd; |
| 97 const vp9_prob *const tx_probs = get_tx_probs2(max_tx_size, xd, | 90 const vp9_prob *const tx_probs = get_tx_probs2(max_tx_size, xd, |
| 98 &cpi->common.fc.tx_probs); | 91 &cpi->common.fc.tx_probs); |
| 99 vp9_write(w, tx_size != TX_4X4, tx_probs[0]); | 92 vp9_write(w, tx_size != TX_4X4, tx_probs[0]); |
| 100 if (tx_size != TX_4X4 && max_tx_size >= TX_16X16) { | 93 if (tx_size != TX_4X4 && max_tx_size >= TX_16X16) { |
| 101 vp9_write(w, tx_size != TX_8X8, tx_probs[1]); | 94 vp9_write(w, tx_size != TX_8X8, tx_probs[1]); |
| 102 if (tx_size != TX_8X8 && max_tx_size >= TX_32X32) | 95 if (tx_size != TX_8X8 && max_tx_size >= TX_32X32) |
| 103 vp9_write(w, tx_size != TX_16X16, tx_probs[2]); | 96 vp9_write(w, tx_size != TX_16X16, tx_probs[2]); |
| 104 } | 97 } |
| 105 } | 98 } |
| 106 | 99 |
| 107 static int write_skip(const VP9_COMP *cpi, int segment_id, MODE_INFO *m, | 100 static int write_skip(const VP9_COMP *cpi, int segment_id, MODE_INFO *m, |
| 108 vp9_writer *w) { | 101 vp9_writer *w) { |
| 109 const MACROBLOCKD *const xd = &cpi->mb.e_mbd; | 102 const MACROBLOCKD *const xd = &cpi->mb.e_mbd; |
| 110 if (vp9_segfeature_active(&cpi->common.seg, segment_id, SEG_LVL_SKIP)) { | 103 if (vp9_segfeature_active(&cpi->common.seg, segment_id, SEG_LVL_SKIP)) { |
| 111 return 1; | 104 return 1; |
| 112 } else { | 105 } else { |
| 113 const int skip = m->mbmi.skip; | 106 const int skip = m->mbmi.skip; |
| 114 vp9_write(w, skip, vp9_get_skip_prob(&cpi->common, xd)); | 107 vp9_write(w, skip, vp9_get_skip_prob(&cpi->common, xd)); |
| 115 return skip; | 108 return skip; |
| 116 } | 109 } |
| 117 } | 110 } |
| 118 | 111 |
| 119 void vp9_update_skip_probs(VP9_COMMON *cm, vp9_writer *w) { | 112 static void update_skip_probs(VP9_COMMON *cm, vp9_writer *w) { |
| 120 int k; | 113 int k; |
| 121 | 114 |
| 122 for (k = 0; k < SKIP_CONTEXTS; ++k) | 115 for (k = 0; k < SKIP_CONTEXTS; ++k) |
| 123 vp9_cond_prob_diff_update(w, &cm->fc.skip_probs[k], cm->counts.skip[k]); | 116 vp9_cond_prob_diff_update(w, &cm->fc.skip_probs[k], cm->counts.skip[k]); |
| 124 } | 117 } |
| 125 | 118 |
| 126 static void update_switchable_interp_probs(VP9_COMP *cpi, vp9_writer *w) { | 119 static void update_switchable_interp_probs(VP9_COMMON *cm, vp9_writer *w) { |
| 127 VP9_COMMON *const cm = &cpi->common; | |
| 128 int j; | 120 int j; |
| 129 for (j = 0; j < SWITCHABLE_FILTER_CONTEXTS; ++j) | 121 for (j = 0; j < SWITCHABLE_FILTER_CONTEXTS; ++j) |
| 130 prob_diff_update(vp9_switchable_interp_tree, | 122 prob_diff_update(vp9_switchable_interp_tree, |
| 131 cm->fc.switchable_interp_prob[j], | 123 cm->fc.switchable_interp_prob[j], |
| 132 cm->counts.switchable_interp[j], SWITCHABLE_FILTERS, w); | 124 cm->counts.switchable_interp[j], SWITCHABLE_FILTERS, w); |
| 133 } | 125 } |
| 134 | 126 |
| 135 static void pack_mb_tokens(vp9_writer* const w, | 127 static void pack_mb_tokens(vp9_writer *w, |
| 136 TOKENEXTRA **tp, | 128 TOKENEXTRA **tp, const TOKENEXTRA *stop) { |
| 137 const TOKENEXTRA *const stop) { | |
| 138 TOKENEXTRA *p = *tp; | 129 TOKENEXTRA *p = *tp; |
| 139 | 130 |
| 140 while (p < stop && p->token != EOSB_TOKEN) { | 131 while (p < stop && p->token != EOSB_TOKEN) { |
| 141 const int t = p->token; | 132 const int t = p->token; |
| 142 const struct vp9_token *const a = &vp9_coef_encodings[t]; | 133 const struct vp9_token *const a = &vp9_coef_encodings[t]; |
| 143 const vp9_extra_bit *const b = &vp9_extra_bits[t]; | 134 const vp9_extra_bit *const b = &vp9_extra_bits[t]; |
| 144 int i = 0; | 135 int i = 0; |
| 145 int v = a->value; | 136 int v = a->value; |
| 146 int n = a->len; | 137 int n = a->len; |
| 147 | 138 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 *tp = p + (p->token == EOSB_TOKEN); | 185 *tp = p + (p->token == EOSB_TOKEN); |
| 195 } | 186 } |
| 196 | 187 |
| 197 static void write_segment_id(vp9_writer *w, const struct segmentation *seg, | 188 static void write_segment_id(vp9_writer *w, const struct segmentation *seg, |
| 198 int segment_id) { | 189 int segment_id) { |
| 199 if (seg->enabled && seg->update_map) | 190 if (seg->enabled && seg->update_map) |
| 200 vp9_write_tree(w, vp9_segment_tree, seg->tree_probs, segment_id, 3, 0); | 191 vp9_write_tree(w, vp9_segment_tree, seg->tree_probs, segment_id, 3, 0); |
| 201 } | 192 } |
| 202 | 193 |
| 203 // This function encodes the reference frame | 194 // This function encodes the reference frame |
| 204 static void encode_ref_frame(VP9_COMP *cpi, vp9_writer *bc) { | 195 static void write_ref_frames(const VP9_COMP *cpi, vp9_writer *w) { |
| 205 VP9_COMMON *const cm = &cpi->common; | 196 const VP9_COMMON *const cm = &cpi->common; |
| 206 MACROBLOCK *const x = &cpi->mb; | 197 const MACROBLOCKD *const xd = &cpi->mb.e_mbd; |
| 207 MACROBLOCKD *const xd = &x->e_mbd; | 198 const MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
| 208 MB_MODE_INFO *mi = &xd->mi_8x8[0]->mbmi; | 199 const int is_compound = has_second_ref(mbmi); |
| 209 const int segment_id = mi->segment_id; | 200 const int segment_id = mbmi->segment_id; |
| 210 int seg_ref_active = vp9_segfeature_active(&cm->seg, segment_id, | 201 |
| 211 SEG_LVL_REF_FRAME); | |
| 212 // If segment level coding of this signal is disabled... | 202 // If segment level coding of this signal is disabled... |
| 213 // or the segment allows multiple reference frame options | 203 // or the segment allows multiple reference frame options |
| 214 if (!seg_ref_active) { | 204 if (vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) { |
| 205 assert(!is_compound); |
| 206 assert(mbmi->ref_frame[0] == |
| 207 vp9_get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME)); |
| 208 } else { |
| 215 // does the feature use compound prediction or not | 209 // does the feature use compound prediction or not |
| 216 // (if not specified at the frame/segment level) | 210 // (if not specified at the frame/segment level) |
| 217 if (cm->reference_mode == REFERENCE_MODE_SELECT) { | 211 if (cm->reference_mode == REFERENCE_MODE_SELECT) { |
| 218 vp9_write(bc, mi->ref_frame[1] > INTRA_FRAME, | 212 vp9_write(w, is_compound, vp9_get_reference_mode_prob(cm, xd)); |
| 219 vp9_get_reference_mode_prob(cm, xd)); | |
| 220 } else { | 213 } else { |
| 221 assert((mi->ref_frame[1] <= INTRA_FRAME) == | 214 assert(!is_compound == (cm->reference_mode == SINGLE_REFERENCE)); |
| 222 (cm->reference_mode == SINGLE_REFERENCE)); | |
| 223 } | 215 } |
| 224 | 216 |
| 225 if (mi->ref_frame[1] > INTRA_FRAME) { | 217 if (is_compound) { |
| 226 vp9_write(bc, mi->ref_frame[0] == GOLDEN_FRAME, | 218 vp9_write(w, mbmi->ref_frame[0] == GOLDEN_FRAME, |
| 227 vp9_get_pred_prob_comp_ref_p(cm, xd)); | 219 vp9_get_pred_prob_comp_ref_p(cm, xd)); |
| 228 } else { | 220 } else { |
| 229 vp9_write(bc, mi->ref_frame[0] != LAST_FRAME, | 221 const int bit0 = mbmi->ref_frame[0] != LAST_FRAME; |
| 230 vp9_get_pred_prob_single_ref_p1(cm, xd)); | 222 vp9_write(w, bit0, vp9_get_pred_prob_single_ref_p1(cm, xd)); |
| 231 if (mi->ref_frame[0] != LAST_FRAME) | 223 if (bit0) { |
| 232 vp9_write(bc, mi->ref_frame[0] != GOLDEN_FRAME, | 224 const int bit1 = mbmi->ref_frame[0] != GOLDEN_FRAME; |
| 233 vp9_get_pred_prob_single_ref_p2(cm, xd)); | 225 vp9_write(w, bit1, vp9_get_pred_prob_single_ref_p2(cm, xd)); |
| 226 } |
| 234 } | 227 } |
| 235 } else { | |
| 236 assert(mi->ref_frame[1] <= INTRA_FRAME); | |
| 237 assert(vp9_get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME) == | |
| 238 mi->ref_frame[0]); | |
| 239 } | 228 } |
| 240 | |
| 241 // If using the prediction model we have nothing further to do because | |
| 242 // the reference frame is fully coded by the segment. | |
| 243 } | 229 } |
| 244 | 230 |
| 245 static void pack_inter_mode_mvs(VP9_COMP *cpi, MODE_INFO *m, vp9_writer *bc) { | 231 static void pack_inter_mode_mvs(VP9_COMP *cpi, MODE_INFO *m, vp9_writer *bc) { |
| 246 VP9_COMMON *const cm = &cpi->common; | 232 VP9_COMMON *const cm = &cpi->common; |
| 247 const nmv_context *nmvc = &cm->fc.nmvc; | 233 const nmv_context *nmvc = &cm->fc.nmvc; |
| 248 MACROBLOCK *const x = &cpi->mb; | 234 MACROBLOCK *const x = &cpi->mb; |
| 249 MACROBLOCKD *const xd = &x->e_mbd; | 235 MACROBLOCKD *const xd = &x->e_mbd; |
| 250 struct segmentation *seg = &cm->seg; | 236 const struct segmentation *const seg = &cm->seg; |
| 251 MB_MODE_INFO *const mi = &m->mbmi; | 237 const MB_MODE_INFO *const mi = &m->mbmi; |
| 252 const MV_REFERENCE_FRAME rf = mi->ref_frame[0]; | 238 const MV_REFERENCE_FRAME ref0 = mi->ref_frame[0]; |
| 253 const MV_REFERENCE_FRAME sec_rf = mi->ref_frame[1]; | 239 const MV_REFERENCE_FRAME ref1 = mi->ref_frame[1]; |
| 254 const MB_PREDICTION_MODE mode = mi->mode; | 240 const MB_PREDICTION_MODE mode = mi->mode; |
| 255 const int segment_id = mi->segment_id; | 241 const int segment_id = mi->segment_id; |
| 256 int skip; | |
| 257 const BLOCK_SIZE bsize = mi->sb_type; | 242 const BLOCK_SIZE bsize = mi->sb_type; |
| 258 const int allow_hp = cm->allow_high_precision_mv; | 243 const int allow_hp = cm->allow_high_precision_mv; |
| 244 int skip; |
| 259 | 245 |
| 260 #ifdef ENTROPY_STATS | 246 #ifdef ENTROPY_STATS |
| 261 active_section = 9; | 247 active_section = 9; |
| 262 #endif | 248 #endif |
| 263 | 249 |
| 264 if (seg->update_map) { | 250 if (seg->update_map) { |
| 265 if (seg->temporal_update) { | 251 if (seg->temporal_update) { |
| 266 const int pred_flag = mi->seg_id_predicted; | 252 const int pred_flag = mi->seg_id_predicted; |
| 267 vp9_prob pred_prob = vp9_get_pred_prob_seg_id(seg, xd); | 253 vp9_prob pred_prob = vp9_get_pred_prob_seg_id(seg, xd); |
| 268 vp9_write(bc, pred_flag, pred_prob); | 254 vp9_write(bc, pred_flag, pred_prob); |
| 269 if (!pred_flag) | 255 if (!pred_flag) |
| 270 write_segment_id(bc, seg, segment_id); | 256 write_segment_id(bc, seg, segment_id); |
| 271 } else { | 257 } else { |
| 272 write_segment_id(bc, seg, segment_id); | 258 write_segment_id(bc, seg, segment_id); |
| 273 } | 259 } |
| 274 } | 260 } |
| 275 | 261 |
| 276 skip = write_skip(cpi, segment_id, m, bc); | 262 skip = write_skip(cpi, segment_id, m, bc); |
| 277 | 263 |
| 278 if (!vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) | 264 if (!vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) |
| 279 vp9_write(bc, rf != INTRA_FRAME, vp9_get_intra_inter_prob(cm, xd)); | 265 vp9_write(bc, ref0 != INTRA_FRAME, vp9_get_intra_inter_prob(cm, xd)); |
| 280 | 266 |
| 281 if (bsize >= BLOCK_8X8 && cm->tx_mode == TX_MODE_SELECT && | 267 if (bsize >= BLOCK_8X8 && cm->tx_mode == TX_MODE_SELECT && |
| 282 !(rf != INTRA_FRAME && | 268 !(ref0 != INTRA_FRAME && |
| 283 (skip || vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP)))) { | 269 (skip || vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP)))) { |
| 284 write_selected_tx_size(cpi, m, mi->tx_size, bsize, bc); | 270 write_selected_tx_size(cpi, mi->tx_size, bsize, bc); |
| 285 } | 271 } |
| 286 | 272 |
| 287 if (rf == INTRA_FRAME) { | 273 if (ref0 == INTRA_FRAME) { |
| 288 #ifdef ENTROPY_STATS | 274 #ifdef ENTROPY_STATS |
| 289 active_section = 6; | 275 active_section = 6; |
| 290 #endif | 276 #endif |
| 291 | 277 |
| 292 if (bsize >= BLOCK_8X8) { | 278 if (bsize >= BLOCK_8X8) { |
| 293 write_intra_mode(bc, mode, cm->fc.y_mode_prob[size_group_lookup[bsize]]); | 279 write_intra_mode(bc, mode, cm->fc.y_mode_prob[size_group_lookup[bsize]]); |
| 294 } else { | 280 } else { |
| 295 int idx, idy; | 281 int idx, idy; |
| 296 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; | 282 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; |
| 297 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; | 283 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; |
| 298 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { | 284 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { |
| 299 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { | 285 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { |
| 300 const MB_PREDICTION_MODE bm = m->bmi[idy * 2 + idx].as_mode; | 286 const MB_PREDICTION_MODE bm = m->bmi[idy * 2 + idx].as_mode; |
| 301 write_intra_mode(bc, bm, cm->fc.y_mode_prob[0]); | 287 write_intra_mode(bc, bm, cm->fc.y_mode_prob[0]); |
| 302 } | 288 } |
| 303 } | 289 } |
| 304 } | 290 } |
| 305 write_intra_mode(bc, mi->uv_mode, cm->fc.uv_mode_prob[mode]); | 291 write_intra_mode(bc, mi->uv_mode, cm->fc.uv_mode_prob[mode]); |
| 306 } else { | 292 } else { |
| 307 vp9_prob *mv_ref_p; | 293 vp9_prob *mv_ref_p; |
| 308 encode_ref_frame(cpi, bc); | 294 write_ref_frames(cpi, bc); |
| 309 mv_ref_p = cpi->common.fc.inter_mode_probs[mi->mode_context[rf]]; | 295 mv_ref_p = cm->fc.inter_mode_probs[mi->mode_context[ref0]]; |
| 310 | 296 |
| 311 #ifdef ENTROPY_STATS | 297 #ifdef ENTROPY_STATS |
| 312 active_section = 3; | 298 active_section = 3; |
| 313 #endif | 299 #endif |
| 314 | 300 |
| 315 // If segment skip is not enabled code the mode. | 301 // If segment skip is not enabled code the mode. |
| 316 if (!vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP)) { | 302 if (!vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP)) { |
| 317 if (bsize >= BLOCK_8X8) { | 303 if (bsize >= BLOCK_8X8) { |
| 318 write_inter_mode(bc, mode, mv_ref_p); | 304 write_inter_mode(bc, mode, mv_ref_p); |
| 319 ++cm->counts.inter_mode[mi->mode_context[rf]][INTER_OFFSET(mode)]; | 305 ++cm->counts.inter_mode[mi->mode_context[ref0]][INTER_OFFSET(mode)]; |
| 320 } | 306 } |
| 321 } | 307 } |
| 322 | 308 |
| 323 if (cm->interp_filter == SWITCHABLE) { | 309 if (cm->interp_filter == SWITCHABLE) { |
| 324 const int ctx = vp9_get_pred_context_switchable_interp(xd); | 310 const int ctx = vp9_get_pred_context_switchable_interp(xd); |
| 325 vp9_write_token(bc, vp9_switchable_interp_tree, | 311 vp9_write_token(bc, vp9_switchable_interp_tree, |
| 326 cm->fc.switchable_interp_prob[ctx], | 312 cm->fc.switchable_interp_prob[ctx], |
| 327 &switchable_interp_encodings[mi->interp_filter]); | 313 &switchable_interp_encodings[mi->interp_filter]); |
| 328 } else { | 314 } else { |
| 329 assert(mi->interp_filter == cm->interp_filter); | 315 assert(mi->interp_filter == cm->interp_filter); |
| 330 } | 316 } |
| 331 | 317 |
| 332 if (bsize < BLOCK_8X8) { | 318 if (bsize < BLOCK_8X8) { |
| 333 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; | 319 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; |
| 334 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; | 320 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; |
| 335 int idx, idy; | 321 int idx, idy; |
| 336 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { | 322 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { |
| 337 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { | 323 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { |
| 338 const int j = idy * 2 + idx; | 324 const int j = idy * 2 + idx; |
| 339 const MB_PREDICTION_MODE blockmode = m->bmi[j].as_mode; | 325 const MB_PREDICTION_MODE b_mode = m->bmi[j].as_mode; |
| 340 write_inter_mode(bc, blockmode, mv_ref_p); | 326 write_inter_mode(bc, b_mode, mv_ref_p); |
| 341 ++cm->counts.inter_mode[mi->mode_context[rf]] | 327 ++cm->counts.inter_mode[mi->mode_context[ref0]][INTER_OFFSET(b_mode)]; |
| 342 [INTER_OFFSET(blockmode)]; | 328 if (b_mode == NEWMV) { |
| 343 | |
| 344 if (blockmode == NEWMV) { | |
| 345 #ifdef ENTROPY_STATS | 329 #ifdef ENTROPY_STATS |
| 346 active_section = 11; | 330 active_section = 11; |
| 347 #endif | 331 #endif |
| 348 vp9_encode_mv(cpi, bc, &m->bmi[j].as_mv[0].as_mv, | 332 vp9_encode_mv(cpi, bc, &m->bmi[j].as_mv[0].as_mv, |
| 349 &mi->ref_mvs[rf][0].as_mv, nmvc, allow_hp); | 333 &mi->ref_mvs[ref0][0].as_mv, nmvc, allow_hp); |
| 350 | 334 |
| 351 if (has_second_ref(mi)) | 335 if (has_second_ref(mi)) |
| 352 vp9_encode_mv(cpi, bc, &m->bmi[j].as_mv[1].as_mv, | 336 vp9_encode_mv(cpi, bc, &m->bmi[j].as_mv[1].as_mv, |
| 353 &mi->ref_mvs[sec_rf][0].as_mv, nmvc, allow_hp); | 337 &mi->ref_mvs[ref1][0].as_mv, nmvc, allow_hp); |
| 354 } | 338 } |
| 355 } | 339 } |
| 356 } | 340 } |
| 357 } else if (mode == NEWMV) { | 341 } else if (mode == NEWMV) { |
| 358 #ifdef ENTROPY_STATS | 342 #ifdef ENTROPY_STATS |
| 359 active_section = 5; | 343 active_section = 5; |
| 360 #endif | 344 #endif |
| 361 vp9_encode_mv(cpi, bc, &mi->mv[0].as_mv, | 345 vp9_encode_mv(cpi, bc, &mi->mv[0].as_mv, |
| 362 &mi->ref_mvs[rf][0].as_mv, nmvc, allow_hp); | 346 &mi->ref_mvs[ref0][0].as_mv, nmvc, allow_hp); |
| 363 | 347 |
| 364 if (has_second_ref(mi)) | 348 if (has_second_ref(mi)) |
| 365 vp9_encode_mv(cpi, bc, &mi->mv[1].as_mv, | 349 vp9_encode_mv(cpi, bc, &mi->mv[1].as_mv, |
| 366 &mi->ref_mvs[sec_rf][0].as_mv, nmvc, allow_hp); | 350 &mi->ref_mvs[ref1][0].as_mv, nmvc, allow_hp); |
| 367 } | 351 } |
| 368 } | 352 } |
| 369 } | 353 } |
| 370 | 354 |
| 371 static void write_mb_modes_kf(const VP9_COMP *cpi, MODE_INFO **mi_8x8, | 355 static void write_mb_modes_kf(const VP9_COMP *cpi, MODE_INFO **mi_8x8, |
| 372 vp9_writer *bc) { | 356 vp9_writer *bc) { |
| 373 const VP9_COMMON *const cm = &cpi->common; | 357 const VP9_COMMON *const cm = &cpi->common; |
| 374 const MACROBLOCKD *const xd = &cpi->mb.e_mbd; | 358 const MACROBLOCKD *const xd = &cpi->mb.e_mbd; |
| 375 const struct segmentation *const seg = &cm->seg; | 359 const struct segmentation *const seg = &cm->seg; |
| 376 MODE_INFO *m = mi_8x8[0]; | 360 MODE_INFO *m = mi_8x8[0]; |
| 377 const int ym = m->mbmi.mode; | 361 const int ym = m->mbmi.mode; |
| 378 const int segment_id = m->mbmi.segment_id; | 362 const int segment_id = m->mbmi.segment_id; |
| 379 MODE_INFO *above_mi = mi_8x8[-xd->mode_info_stride]; | 363 MODE_INFO *above_mi = mi_8x8[-xd->mode_info_stride]; |
| 380 MODE_INFO *left_mi = xd->left_available ? mi_8x8[-1] : NULL; | 364 MODE_INFO *left_mi = xd->left_available ? mi_8x8[-1] : NULL; |
| 381 | 365 |
| 382 if (seg->update_map) | 366 if (seg->update_map) |
| 383 write_segment_id(bc, seg, m->mbmi.segment_id); | 367 write_segment_id(bc, seg, m->mbmi.segment_id); |
| 384 | 368 |
| 385 write_skip(cpi, segment_id, m, bc); | 369 write_skip(cpi, segment_id, m, bc); |
| 386 | 370 |
| 387 if (m->mbmi.sb_type >= BLOCK_8X8 && cm->tx_mode == TX_MODE_SELECT) | 371 if (m->mbmi.sb_type >= BLOCK_8X8 && cm->tx_mode == TX_MODE_SELECT) |
| 388 write_selected_tx_size(cpi, m, m->mbmi.tx_size, m->mbmi.sb_type, bc); | 372 write_selected_tx_size(cpi, m->mbmi.tx_size, m->mbmi.sb_type, bc); |
| 389 | 373 |
| 390 if (m->mbmi.sb_type >= BLOCK_8X8) { | 374 if (m->mbmi.sb_type >= BLOCK_8X8) { |
| 391 const MB_PREDICTION_MODE A = vp9_above_block_mode(m, above_mi, 0); | 375 const MB_PREDICTION_MODE A = vp9_above_block_mode(m, above_mi, 0); |
| 392 const MB_PREDICTION_MODE L = vp9_left_block_mode(m, left_mi, 0); | 376 const MB_PREDICTION_MODE L = vp9_left_block_mode(m, left_mi, 0); |
| 393 write_intra_mode(bc, ym, vp9_kf_y_mode_prob[A][L]); | 377 write_intra_mode(bc, ym, vp9_kf_y_mode_prob[A][L]); |
| 394 } else { | 378 } else { |
| 395 int idx, idy; | 379 int idx, idy; |
| 396 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[m->mbmi.sb_type]; | 380 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[m->mbmi.sb_type]; |
| 397 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[m->mbmi.sb_type]; | 381 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[m->mbmi.sb_type]; |
| 398 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { | 382 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) { | 527 for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) { |
| 544 vp9_tree_probs_from_distribution(vp9_coef_tree, | 528 vp9_tree_probs_from_distribution(vp9_coef_tree, |
| 545 coef_branch_ct[i][j][k][l], | 529 coef_branch_ct[i][j][k][l], |
| 546 coef_counts[i][j][k][l]); | 530 coef_counts[i][j][k][l]); |
| 547 coef_branch_ct[i][j][k][l][0][1] = eob_branch_ct[i][j][k][l] - | 531 coef_branch_ct[i][j][k][l][0][1] = eob_branch_ct[i][j][k][l] - |
| 548 coef_branch_ct[i][j][k][l][0][0]; | 532 coef_branch_ct[i][j][k][l][0][0]; |
| 549 for (m = 0; m < UNCONSTRAINED_NODES; ++m) | 533 for (m = 0; m < UNCONSTRAINED_NODES; ++m) |
| 550 coef_probs[i][j][k][l][m] = get_binary_prob( | 534 coef_probs[i][j][k][l][m] = get_binary_prob( |
| 551 coef_branch_ct[i][j][k][l][m][0], | 535 coef_branch_ct[i][j][k][l][m][0], |
| 552 coef_branch_ct[i][j][k][l][m][1]); | 536 coef_branch_ct[i][j][k][l][m][1]); |
| 553 #ifdef ENTROPY_STATS | |
| 554 if (!cpi->dummy_packing) { | |
| 555 int t; | |
| 556 for (t = 0; t < ENTROPY_TOKENS; ++t) | |
| 557 context_counters[tx_size][i][j][k][l][t] += | |
| 558 coef_counts[i][j][k][l][t]; | |
| 559 context_counters[tx_size][i][j][k][l][ENTROPY_TOKENS] += | |
| 560 eob_branch_ct[i][j][k][l]; | |
| 561 } | |
| 562 #endif | |
| 563 } | 537 } |
| 564 } | 538 } |
| 565 } | 539 } |
| 566 } | 540 } |
| 567 } | 541 } |
| 568 | 542 |
| 569 static void update_coef_probs_common(vp9_writer* const bc, VP9_COMP *cpi, | 543 static void update_coef_probs_common(vp9_writer* const bc, VP9_COMP *cpi, |
| 570 TX_SIZE tx_size) { | 544 TX_SIZE tx_size) { |
| 571 vp9_coeff_probs_model *new_frame_coef_probs = cpi->frame_coef_probs[tx_size]; | 545 vp9_coeff_probs_model *new_frame_coef_probs = cpi->frame_coef_probs[tx_size]; |
| 572 vp9_coeff_probs_model *old_frame_coef_probs = | 546 vp9_coeff_probs_model *old_frame_coef_probs = |
| (...skipping 12 matching lines...) Expand all Loading... |
| 585 for (k = 0; k < COEF_BANDS; ++k) { | 559 for (k = 0; k < COEF_BANDS; ++k) { |
| 586 for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) { | 560 for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) { |
| 587 for (t = 0; t < entropy_nodes_update; ++t) { | 561 for (t = 0; t < entropy_nodes_update; ++t) { |
| 588 vp9_prob newp = new_frame_coef_probs[i][j][k][l][t]; | 562 vp9_prob newp = new_frame_coef_probs[i][j][k][l][t]; |
| 589 const vp9_prob oldp = old_frame_coef_probs[i][j][k][l][t]; | 563 const vp9_prob oldp = old_frame_coef_probs[i][j][k][l][t]; |
| 590 int s; | 564 int s; |
| 591 int u = 0; | 565 int u = 0; |
| 592 if (t == PIVOT_NODE) | 566 if (t == PIVOT_NODE) |
| 593 s = vp9_prob_diff_update_savings_search_model( | 567 s = vp9_prob_diff_update_savings_search_model( |
| 594 frame_branch_ct[i][j][k][l][0], | 568 frame_branch_ct[i][j][k][l][0], |
| 595 old_frame_coef_probs[i][j][k][l], &newp, upd, i, j); | 569 old_frame_coef_probs[i][j][k][l], &newp, upd); |
| 596 else | 570 else |
| 597 s = vp9_prob_diff_update_savings_search( | 571 s = vp9_prob_diff_update_savings_search( |
| 598 frame_branch_ct[i][j][k][l][t], oldp, &newp, upd); | 572 frame_branch_ct[i][j][k][l][t], oldp, &newp, upd); |
| 599 if (s > 0 && newp != oldp) | 573 if (s > 0 && newp != oldp) |
| 600 u = 1; | 574 u = 1; |
| 601 if (u) | 575 if (u) |
| 602 savings += s - (int)(vp9_cost_zero(upd)); | 576 savings += s - (int)(vp9_cost_zero(upd)); |
| 603 else | 577 else |
| 604 savings -= (int)(vp9_cost_zero(upd)); | 578 savings -= (int)(vp9_cost_zero(upd)); |
| 605 update[u]++; | 579 update[u]++; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 623 // calc probs and branch cts for this frame only | 597 // calc probs and branch cts for this frame only |
| 624 for (t = 0; t < entropy_nodes_update; ++t) { | 598 for (t = 0; t < entropy_nodes_update; ++t) { |
| 625 vp9_prob newp = new_frame_coef_probs[i][j][k][l][t]; | 599 vp9_prob newp = new_frame_coef_probs[i][j][k][l][t]; |
| 626 vp9_prob *oldp = old_frame_coef_probs[i][j][k][l] + t; | 600 vp9_prob *oldp = old_frame_coef_probs[i][j][k][l] + t; |
| 627 const vp9_prob upd = DIFF_UPDATE_PROB; | 601 const vp9_prob upd = DIFF_UPDATE_PROB; |
| 628 int s; | 602 int s; |
| 629 int u = 0; | 603 int u = 0; |
| 630 if (t == PIVOT_NODE) | 604 if (t == PIVOT_NODE) |
| 631 s = vp9_prob_diff_update_savings_search_model( | 605 s = vp9_prob_diff_update_savings_search_model( |
| 632 frame_branch_ct[i][j][k][l][0], | 606 frame_branch_ct[i][j][k][l][0], |
| 633 old_frame_coef_probs[i][j][k][l], &newp, upd, i, j); | 607 old_frame_coef_probs[i][j][k][l], &newp, upd); |
| 634 else | 608 else |
| 635 s = vp9_prob_diff_update_savings_search( | 609 s = vp9_prob_diff_update_savings_search( |
| 636 frame_branch_ct[i][j][k][l][t], | 610 frame_branch_ct[i][j][k][l][t], |
| 637 *oldp, &newp, upd); | 611 *oldp, &newp, upd); |
| 638 if (s > 0 && newp != *oldp) | 612 if (s > 0 && newp != *oldp) |
| 639 u = 1; | 613 u = 1; |
| 640 vp9_write(bc, u, upd); | 614 vp9_write(bc, u, upd); |
| 641 #ifdef ENTROPY_STATS | |
| 642 if (!cpi->dummy_packing) | |
| 643 ++tree_update_hist[tx_size][i][j][k][l][t][u]; | |
| 644 #endif | |
| 645 if (u) { | 615 if (u) { |
| 646 /* send/use new probability */ | 616 /* send/use new probability */ |
| 647 vp9_write_prob_diff_update(bc, newp, *oldp); | 617 vp9_write_prob_diff_update(bc, newp, *oldp); |
| 648 *oldp = newp; | 618 *oldp = newp; |
| 649 } | 619 } |
| 650 } | 620 } |
| 651 } | 621 } |
| 652 } | 622 } |
| 653 } | 623 } |
| 654 } | 624 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 675 vp9_prob *oldp = old_frame_coef_probs[i][j][k][l] + t; | 645 vp9_prob *oldp = old_frame_coef_probs[i][j][k][l] + t; |
| 676 int s; | 646 int s; |
| 677 int u = 0; | 647 int u = 0; |
| 678 if (l >= prev_coef_contexts_to_update || | 648 if (l >= prev_coef_contexts_to_update || |
| 679 k >= coef_band_to_update) { | 649 k >= coef_band_to_update) { |
| 680 u = 0; | 650 u = 0; |
| 681 } else { | 651 } else { |
| 682 if (t == PIVOT_NODE) | 652 if (t == PIVOT_NODE) |
| 683 s = vp9_prob_diff_update_savings_search_model( | 653 s = vp9_prob_diff_update_savings_search_model( |
| 684 frame_branch_ct[i][j][k][l][0], | 654 frame_branch_ct[i][j][k][l][0], |
| 685 old_frame_coef_probs[i][j][k][l], &newp, upd, i, j); | 655 old_frame_coef_probs[i][j][k][l], &newp, upd); |
| 686 else | 656 else |
| 687 s = vp9_prob_diff_update_savings_search( | 657 s = vp9_prob_diff_update_savings_search( |
| 688 frame_branch_ct[i][j][k][l][t], | 658 frame_branch_ct[i][j][k][l][t], |
| 689 *oldp, &newp, upd); | 659 *oldp, &newp, upd); |
| 690 if (s > 0 && newp != *oldp) | 660 if (s > 0 && newp != *oldp) |
| 691 u = 1; | 661 u = 1; |
| 692 } | 662 } |
| 693 updates += u; | 663 updates += u; |
| 694 if (u == 0 && updates == 0) { | 664 if (u == 0 && updates == 0) { |
| 695 noupdates_before_first++; | 665 noupdates_before_first++; |
| 696 #ifdef ENTROPY_STATS | |
| 697 if (!cpi->dummy_packing) | |
| 698 ++tree_update_hist[tx_size][i][j][k][l][t][u]; | |
| 699 #endif | |
| 700 continue; | 666 continue; |
| 701 } | 667 } |
| 702 if (u == 1 && updates == 1) { | 668 if (u == 1 && updates == 1) { |
| 703 int v; | 669 int v; |
| 704 // first update | 670 // first update |
| 705 vp9_write_bit(bc, 1); | 671 vp9_write_bit(bc, 1); |
| 706 for (v = 0; v < noupdates_before_first; ++v) | 672 for (v = 0; v < noupdates_before_first; ++v) |
| 707 vp9_write(bc, 0, upd); | 673 vp9_write(bc, 0, upd); |
| 708 } | 674 } |
| 709 vp9_write(bc, u, upd); | 675 vp9_write(bc, u, upd); |
| 710 #ifdef ENTROPY_STATS | |
| 711 if (!cpi->dummy_packing) | |
| 712 ++tree_update_hist[tx_size][i][j][k][l][t][u]; | |
| 713 #endif | |
| 714 if (u) { | 676 if (u) { |
| 715 /* send/use new probability */ | 677 /* send/use new probability */ |
| 716 vp9_write_prob_diff_update(bc, newp, *oldp); | 678 vp9_write_prob_diff_update(bc, newp, *oldp); |
| 717 *oldp = newp; | 679 *oldp = newp; |
| 718 } | 680 } |
| 719 } | 681 } |
| 720 } | 682 } |
| 721 } | 683 } |
| 722 } | 684 } |
| 723 } | 685 } |
| 724 if (updates == 0) { | 686 if (updates == 0) { |
| 725 vp9_write_bit(bc, 0); // no updates | 687 vp9_write_bit(bc, 0); // no updates |
| 726 } | 688 } |
| 727 return; | 689 return; |
| 728 } | 690 } |
| 729 | 691 |
| 730 default: | 692 default: |
| 731 assert(0); | 693 assert(0); |
| 732 } | 694 } |
| 733 } | 695 } |
| 734 | 696 |
| 735 static void update_coef_probs(VP9_COMP* cpi, vp9_writer* w) { | 697 static void update_coef_probs(VP9_COMP *cpi, vp9_writer* w) { |
| 736 const TX_MODE tx_mode = cpi->common.tx_mode; | 698 const TX_MODE tx_mode = cpi->common.tx_mode; |
| 737 const TX_SIZE max_tx_size = tx_mode_to_biggest_tx_size[tx_mode]; | 699 const TX_SIZE max_tx_size = tx_mode_to_biggest_tx_size[tx_mode]; |
| 738 TX_SIZE tx_size; | 700 TX_SIZE tx_size; |
| 739 vp9_clear_system_state(); | 701 vp9_clear_system_state(); |
| 740 | 702 |
| 741 for (tx_size = TX_4X4; tx_size <= TX_32X32; ++tx_size) | 703 for (tx_size = TX_4X4; tx_size <= TX_32X32; ++tx_size) |
| 742 build_tree_distribution(cpi, tx_size); | 704 build_tree_distribution(cpi, tx_size); |
| 743 | 705 |
| 744 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size) | 706 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size) |
| 745 update_coef_probs_common(w, cpi, tx_size); | 707 update_coef_probs_common(w, cpi, tx_size); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 | 810 |
| 849 for (i = 0; i < MAX_SEGMENTS; i++) { | 811 for (i = 0; i < MAX_SEGMENTS; i++) { |
| 850 for (j = 0; j < SEG_LVL_MAX; j++) { | 812 for (j = 0; j < SEG_LVL_MAX; j++) { |
| 851 const int active = vp9_segfeature_active(seg, i, j); | 813 const int active = vp9_segfeature_active(seg, i, j); |
| 852 vp9_wb_write_bit(wb, active); | 814 vp9_wb_write_bit(wb, active); |
| 853 if (active) { | 815 if (active) { |
| 854 const int data = vp9_get_segdata(seg, i, j); | 816 const int data = vp9_get_segdata(seg, i, j); |
| 855 const int data_max = vp9_seg_feature_data_max(j); | 817 const int data_max = vp9_seg_feature_data_max(j); |
| 856 | 818 |
| 857 if (vp9_is_segfeature_signed(j)) { | 819 if (vp9_is_segfeature_signed(j)) { |
| 858 vp9_encode_unsigned_max(wb, abs(data), data_max); | 820 encode_unsigned_max(wb, abs(data), data_max); |
| 859 vp9_wb_write_bit(wb, data < 0); | 821 vp9_wb_write_bit(wb, data < 0); |
| 860 } else { | 822 } else { |
| 861 vp9_encode_unsigned_max(wb, data, data_max); | 823 encode_unsigned_max(wb, data, data_max); |
| 862 } | 824 } |
| 863 } | 825 } |
| 864 } | 826 } |
| 865 } | 827 } |
| 866 } | 828 } |
| 867 } | 829 } |
| 868 | 830 |
| 869 | 831 |
| 870 static void encode_txfm_probs(VP9_COMP *cpi, vp9_writer *w) { | 832 static void encode_txfm_probs(VP9_COMMON *cm, vp9_writer *w) { |
| 871 VP9_COMMON *const cm = &cpi->common; | |
| 872 | |
| 873 // Mode | 833 // Mode |
| 874 vp9_write_literal(w, MIN(cm->tx_mode, ALLOW_32X32), 2); | 834 vp9_write_literal(w, MIN(cm->tx_mode, ALLOW_32X32), 2); |
| 875 if (cm->tx_mode >= ALLOW_32X32) | 835 if (cm->tx_mode >= ALLOW_32X32) |
| 876 vp9_write_bit(w, cm->tx_mode == TX_MODE_SELECT); | 836 vp9_write_bit(w, cm->tx_mode == TX_MODE_SELECT); |
| 877 | 837 |
| 878 // Probabilities | 838 // Probabilities |
| 879 if (cm->tx_mode == TX_MODE_SELECT) { | 839 if (cm->tx_mode == TX_MODE_SELECT) { |
| 880 int i, j; | 840 int i, j; |
| 881 unsigned int ct_8x8p[TX_SIZES - 3][2]; | 841 unsigned int ct_8x8p[TX_SIZES - 3][2]; |
| 882 unsigned int ct_16x16p[TX_SIZES - 2][2]; | 842 unsigned int ct_16x16p[TX_SIZES - 2][2]; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 if (tile_col < tile_cols - 1 || tile_row < tile_rows - 1) | 985 if (tile_col < tile_cols - 1 || tile_row < tile_rows - 1) |
| 1026 vp9_start_encode(&residual_bc, data_ptr + total_size + 4); | 986 vp9_start_encode(&residual_bc, data_ptr + total_size + 4); |
| 1027 else | 987 else |
| 1028 vp9_start_encode(&residual_bc, data_ptr + total_size); | 988 vp9_start_encode(&residual_bc, data_ptr + total_size); |
| 1029 | 989 |
| 1030 write_modes(cpi, &tile, &residual_bc, &tok[tile_row][tile_col], tok_end); | 990 write_modes(cpi, &tile, &residual_bc, &tok[tile_row][tile_col], tok_end); |
| 1031 assert(tok[tile_row][tile_col] == tok_end); | 991 assert(tok[tile_row][tile_col] == tok_end); |
| 1032 vp9_stop_encode(&residual_bc); | 992 vp9_stop_encode(&residual_bc); |
| 1033 if (tile_col < tile_cols - 1 || tile_row < tile_rows - 1) { | 993 if (tile_col < tile_cols - 1 || tile_row < tile_rows - 1) { |
| 1034 // size of this tile | 994 // size of this tile |
| 1035 write_be32(data_ptr + total_size, residual_bc.pos); | 995 mem_put_be32(data_ptr + total_size, residual_bc.pos); |
| 1036 total_size += 4; | 996 total_size += 4; |
| 1037 } | 997 } |
| 1038 | 998 |
| 1039 total_size += residual_bc.pos; | 999 total_size += residual_bc.pos; |
| 1040 } | 1000 } |
| 1041 } | 1001 } |
| 1042 | 1002 |
| 1043 return total_size; | 1003 return total_size; |
| 1044 } | 1004 } |
| 1045 | 1005 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1180 VP9_COMMON *const cm = &cpi->common; | 1140 VP9_COMMON *const cm = &cpi->common; |
| 1181 MACROBLOCKD *const xd = &cpi->mb.e_mbd; | 1141 MACROBLOCKD *const xd = &cpi->mb.e_mbd; |
| 1182 FRAME_CONTEXT *const fc = &cm->fc; | 1142 FRAME_CONTEXT *const fc = &cm->fc; |
| 1183 vp9_writer header_bc; | 1143 vp9_writer header_bc; |
| 1184 | 1144 |
| 1185 vp9_start_encode(&header_bc, data); | 1145 vp9_start_encode(&header_bc, data); |
| 1186 | 1146 |
| 1187 if (xd->lossless) | 1147 if (xd->lossless) |
| 1188 cm->tx_mode = ONLY_4X4; | 1148 cm->tx_mode = ONLY_4X4; |
| 1189 else | 1149 else |
| 1190 encode_txfm_probs(cpi, &header_bc); | 1150 encode_txfm_probs(cm, &header_bc); |
| 1191 | 1151 |
| 1192 update_coef_probs(cpi, &header_bc); | 1152 update_coef_probs(cpi, &header_bc); |
| 1193 | 1153 |
| 1194 #ifdef ENTROPY_STATS | 1154 #ifdef ENTROPY_STATS |
| 1195 active_section = 2; | 1155 active_section = 2; |
| 1196 #endif | 1156 #endif |
| 1197 | 1157 |
| 1198 vp9_update_skip_probs(cm, &header_bc); | 1158 update_skip_probs(cm, &header_bc); |
| 1199 | 1159 |
| 1200 if (!frame_is_intra_only(cm)) { | 1160 if (!frame_is_intra_only(cm)) { |
| 1201 int i; | 1161 int i; |
| 1202 #ifdef ENTROPY_STATS | 1162 #ifdef ENTROPY_STATS |
| 1203 active_section = 1; | 1163 active_section = 1; |
| 1204 #endif | 1164 #endif |
| 1205 | 1165 |
| 1206 for (i = 0; i < INTER_MODE_CONTEXTS; ++i) | 1166 for (i = 0; i < INTER_MODE_CONTEXTS; ++i) |
| 1207 prob_diff_update(vp9_inter_mode_tree, cm->fc.inter_mode_probs[i], | 1167 prob_diff_update(vp9_inter_mode_tree, cm->fc.inter_mode_probs[i], |
| 1208 cm->counts.inter_mode[i], INTER_MODES, &header_bc); | 1168 cm->counts.inter_mode[i], INTER_MODES, &header_bc); |
| 1209 | 1169 |
| 1210 vp9_zero(cm->counts.inter_mode); | 1170 vp9_zero(cm->counts.inter_mode); |
| 1211 | 1171 |
| 1212 if (cm->interp_filter == SWITCHABLE) | 1172 if (cm->interp_filter == SWITCHABLE) |
| 1213 update_switchable_interp_probs(cpi, &header_bc); | 1173 update_switchable_interp_probs(cm, &header_bc); |
| 1214 | 1174 |
| 1215 for (i = 0; i < INTRA_INTER_CONTEXTS; i++) | 1175 for (i = 0; i < INTRA_INTER_CONTEXTS; i++) |
| 1216 vp9_cond_prob_diff_update(&header_bc, &fc->intra_inter_prob[i], | 1176 vp9_cond_prob_diff_update(&header_bc, &fc->intra_inter_prob[i], |
| 1217 cm->counts.intra_inter[i]); | 1177 cm->counts.intra_inter[i]); |
| 1218 | 1178 |
| 1219 if (cm->allow_comp_inter_inter) { | 1179 if (cm->allow_comp_inter_inter) { |
| 1220 const int use_compound_pred = cm->reference_mode != SINGLE_REFERENCE; | 1180 const int use_compound_pred = cm->reference_mode != SINGLE_REFERENCE; |
| 1221 const int use_hybrid_pred = cm->reference_mode == REFERENCE_MODE_SELECT; | 1181 const int use_hybrid_pred = cm->reference_mode == REFERENCE_MODE_SELECT; |
| 1222 | 1182 |
| 1223 vp9_write_bit(&header_bc, use_compound_pred); | 1183 vp9_write_bit(&header_bc, use_compound_pred); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1275 | 1235 |
| 1276 vp9_compute_update_table(); | 1236 vp9_compute_update_table(); |
| 1277 | 1237 |
| 1278 #ifdef ENTROPY_STATS | 1238 #ifdef ENTROPY_STATS |
| 1279 if (cm->frame_type == INTER_FRAME) | 1239 if (cm->frame_type == INTER_FRAME) |
| 1280 active_section = 0; | 1240 active_section = 0; |
| 1281 else | 1241 else |
| 1282 active_section = 7; | 1242 active_section = 7; |
| 1283 #endif | 1243 #endif |
| 1284 | 1244 |
| 1285 vp9_clear_system_state(); // __asm emms; | 1245 vp9_clear_system_state(); |
| 1286 | 1246 |
| 1287 first_part_size = write_compressed_header(cpi, data); | 1247 first_part_size = write_compressed_header(cpi, data); |
| 1288 data += first_part_size; | 1248 data += first_part_size; |
| 1289 vp9_wb_write_literal(&saved_wb, first_part_size, 16); | 1249 // TODO(jbb): Figure out what to do if first_part_size > 16 bits. |
| 1250 vp9_wb_write_literal(&saved_wb, (int)first_part_size, 16); |
| 1290 | 1251 |
| 1291 data += encode_tiles(cpi, data); | 1252 data += encode_tiles(cpi, data); |
| 1292 | 1253 |
| 1293 *size = data - dest; | 1254 *size = data - dest; |
| 1294 } | 1255 } |
| 1295 | 1256 |
| OLD | NEW |