| 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 <math.h> | 11 #include <math.h> |
| 12 | 12 |
| 13 #include "vp9/common/vp9_common.h" | 13 #include "vp9/common/vp9_common.h" |
| 14 #include "vp9/common/vp9_entropymode.h" | 14 #include "vp9/common/vp9_entropymode.h" |
| 15 #include "vp9/common/vp9_systemdependent.h" | 15 #include "vp9/common/vp9_systemdependent.h" |
| 16 |
| 17 #include "vp9/encoder/vp9_cost.h" |
| 16 #include "vp9/encoder/vp9_encodemv.h" | 18 #include "vp9/encoder/vp9_encodemv.h" |
| 17 | 19 |
| 18 #ifdef ENTROPY_STATS | |
| 19 extern unsigned int active_section; | |
| 20 #endif | |
| 21 | |
| 22 static struct vp9_token mv_joint_encodings[MV_JOINTS]; | 20 static struct vp9_token mv_joint_encodings[MV_JOINTS]; |
| 23 static struct vp9_token mv_class_encodings[MV_CLASSES]; | 21 static struct vp9_token mv_class_encodings[MV_CLASSES]; |
| 24 static struct vp9_token mv_fp_encodings[MV_FP_SIZE]; | 22 static struct vp9_token mv_fp_encodings[MV_FP_SIZE]; |
| 25 static struct vp9_token mv_class0_encodings[CLASS0_SIZE]; | 23 static struct vp9_token mv_class0_encodings[CLASS0_SIZE]; |
| 26 | 24 |
| 27 void vp9_entropy_mv_init() { | 25 void vp9_entropy_mv_init() { |
| 28 vp9_tokens_from_tree(mv_joint_encodings, vp9_mv_joint_tree); | 26 vp9_tokens_from_tree(mv_joint_encodings, vp9_mv_joint_tree); |
| 29 vp9_tokens_from_tree(mv_class_encodings, vp9_mv_class_tree); | 27 vp9_tokens_from_tree(mv_class_encodings, vp9_mv_class_tree); |
| 30 vp9_tokens_from_tree(mv_class0_encodings, vp9_mv_class0_tree); | 28 vp9_tokens_from_tree(mv_class0_encodings, vp9_mv_class0_tree); |
| 31 vp9_tokens_from_tree(mv_fp_encodings, vp9_mv_fp_tree); | 29 vp9_tokens_from_tree(mv_fp_encodings, vp9_mv_fp_tree); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 const unsigned int counts[/*n - 1*/], | 151 const unsigned int counts[/*n - 1*/], |
| 154 int n, vp9_writer *w) { | 152 int n, vp9_writer *w) { |
| 155 int i; | 153 int i; |
| 156 unsigned int branch_ct[32][2]; | 154 unsigned int branch_ct[32][2]; |
| 157 | 155 |
| 158 // Assuming max number of probabilities <= 32 | 156 // Assuming max number of probabilities <= 32 |
| 159 assert(n <= 32); | 157 assert(n <= 32); |
| 160 | 158 |
| 161 vp9_tree_probs_from_distribution(tree, branch_ct, counts); | 159 vp9_tree_probs_from_distribution(tree, branch_ct, counts); |
| 162 for (i = 0; i < n - 1; ++i) | 160 for (i = 0; i < n - 1; ++i) |
| 163 update_mv(w, branch_ct[i], &probs[i], NMV_UPDATE_PROB); | 161 update_mv(w, branch_ct[i], &probs[i], MV_UPDATE_PROB); |
| 164 } | 162 } |
| 165 | 163 |
| 166 void vp9_write_nmv_probs(VP9_COMMON *cm, int usehp, vp9_writer *w) { | 164 void vp9_write_nmv_probs(VP9_COMMON *cm, int usehp, vp9_writer *w) { |
| 167 int i, j; | 165 int i, j; |
| 168 nmv_context *const mvc = &cm->fc.nmvc; | 166 nmv_context *const mvc = &cm->fc.nmvc; |
| 169 nmv_context_counts *const counts = &cm->counts.mv; | 167 nmv_context_counts *const counts = &cm->counts.mv; |
| 170 | 168 |
| 171 write_mv_update(vp9_mv_joint_tree, mvc->joints, counts->joints, MV_JOINTS, w); | 169 write_mv_update(vp9_mv_joint_tree, mvc->joints, counts->joints, MV_JOINTS, w); |
| 172 | 170 |
| 173 for (i = 0; i < 2; ++i) { | 171 for (i = 0; i < 2; ++i) { |
| 174 nmv_component *comp = &mvc->comps[i]; | 172 nmv_component *comp = &mvc->comps[i]; |
| 175 nmv_component_counts *comp_counts = &counts->comps[i]; | 173 nmv_component_counts *comp_counts = &counts->comps[i]; |
| 176 | 174 |
| 177 update_mv(w, comp_counts->sign, &comp->sign, NMV_UPDATE_PROB); | 175 update_mv(w, comp_counts->sign, &comp->sign, MV_UPDATE_PROB); |
| 178 write_mv_update(vp9_mv_class_tree, comp->classes, comp_counts->classes, | 176 write_mv_update(vp9_mv_class_tree, comp->classes, comp_counts->classes, |
| 179 MV_CLASSES, w); | 177 MV_CLASSES, w); |
| 180 write_mv_update(vp9_mv_class0_tree, comp->class0, comp_counts->class0, | 178 write_mv_update(vp9_mv_class0_tree, comp->class0, comp_counts->class0, |
| 181 CLASS0_SIZE, w); | 179 CLASS0_SIZE, w); |
| 182 for (j = 0; j < MV_OFFSET_BITS; ++j) | 180 for (j = 0; j < MV_OFFSET_BITS; ++j) |
| 183 update_mv(w, comp_counts->bits[j], &comp->bits[j], NMV_UPDATE_PROB); | 181 update_mv(w, comp_counts->bits[j], &comp->bits[j], MV_UPDATE_PROB); |
| 184 } | 182 } |
| 185 | 183 |
| 186 for (i = 0; i < 2; ++i) { | 184 for (i = 0; i < 2; ++i) { |
| 187 for (j = 0; j < CLASS0_SIZE; ++j) | 185 for (j = 0; j < CLASS0_SIZE; ++j) |
| 188 write_mv_update(vp9_mv_fp_tree, mvc->comps[i].class0_fp[j], | 186 write_mv_update(vp9_mv_fp_tree, mvc->comps[i].class0_fp[j], |
| 189 counts->comps[i].class0_fp[j], MV_FP_SIZE, w); | 187 counts->comps[i].class0_fp[j], MV_FP_SIZE, w); |
| 190 | 188 |
| 191 write_mv_update(vp9_mv_fp_tree, mvc->comps[i].fp, counts->comps[i].fp, | 189 write_mv_update(vp9_mv_fp_tree, mvc->comps[i].fp, counts->comps[i].fp, |
| 192 MV_FP_SIZE, w); | 190 MV_FP_SIZE, w); |
| 193 } | 191 } |
| 194 | 192 |
| 195 if (usehp) { | 193 if (usehp) { |
| 196 for (i = 0; i < 2; ++i) { | 194 for (i = 0; i < 2; ++i) { |
| 197 update_mv(w, counts->comps[i].class0_hp, &mvc->comps[i].class0_hp, | 195 update_mv(w, counts->comps[i].class0_hp, &mvc->comps[i].class0_hp, |
| 198 NMV_UPDATE_PROB); | 196 MV_UPDATE_PROB); |
| 199 update_mv(w, counts->comps[i].hp, &mvc->comps[i].hp, NMV_UPDATE_PROB); | 197 update_mv(w, counts->comps[i].hp, &mvc->comps[i].hp, MV_UPDATE_PROB); |
| 200 } | 198 } |
| 201 } | 199 } |
| 202 } | 200 } |
| 203 | 201 |
| 204 void vp9_encode_mv(VP9_COMP* cpi, vp9_writer* w, | 202 void vp9_encode_mv(VP9_COMP* cpi, vp9_writer* w, |
| 205 const MV* mv, const MV* ref, | 203 const MV* mv, const MV* ref, |
| 206 const nmv_context* mvctx, int usehp) { | 204 const nmv_context* mvctx, int usehp) { |
| 207 const MV diff = {mv->row - ref->row, | 205 const MV diff = {mv->row - ref->row, |
| 208 mv->col - ref->col}; | 206 mv->col - ref->col}; |
| 209 const MV_JOINT_TYPE j = vp9_get_mv_joint(&diff); | 207 const MV_JOINT_TYPE j = vp9_get_mv_joint(&diff); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 224 } | 222 } |
| 225 } | 223 } |
| 226 | 224 |
| 227 void vp9_build_nmv_cost_table(int *mvjoint, int *mvcost[2], | 225 void vp9_build_nmv_cost_table(int *mvjoint, int *mvcost[2], |
| 228 const nmv_context* ctx, int usehp) { | 226 const nmv_context* ctx, int usehp) { |
| 229 vp9_cost_tokens(mvjoint, ctx->joints, vp9_mv_joint_tree); | 227 vp9_cost_tokens(mvjoint, ctx->joints, vp9_mv_joint_tree); |
| 230 build_nmv_component_cost_table(mvcost[0], &ctx->comps[0], usehp); | 228 build_nmv_component_cost_table(mvcost[0], &ctx->comps[0], usehp); |
| 231 build_nmv_component_cost_table(mvcost[1], &ctx->comps[1], usehp); | 229 build_nmv_component_cost_table(mvcost[1], &ctx->comps[1], usehp); |
| 232 } | 230 } |
| 233 | 231 |
| 234 static void inc_mvs(const int_mv mv[2], const MV ref[2], int is_compound, | 232 static void inc_mvs(const MB_MODE_INFO *mbmi, const int_mv mvs[2], |
| 235 nmv_context_counts *counts) { | 233 nmv_context_counts *counts) { |
| 236 int i; | 234 int i; |
| 237 for (i = 0; i < 1 + is_compound; ++i) { | 235 |
| 238 const MV diff = { mv[i].as_mv.row - ref[i].row, | 236 for (i = 0; i < 1 + has_second_ref(mbmi); ++i) { |
| 239 mv[i].as_mv.col - ref[i].col }; | 237 const MV *ref = &mbmi->ref_mvs[mbmi->ref_frame[i]][0].as_mv; |
| 238 const MV diff = {mvs[i].as_mv.row - ref->row, |
| 239 mvs[i].as_mv.col - ref->col}; |
| 240 vp9_inc_mv(&diff, counts); | 240 vp9_inc_mv(&diff, counts); |
| 241 } | 241 } |
| 242 } | 242 } |
| 243 | 243 |
| 244 void vp9_update_mv_count(VP9_COMMON *cm, const MACROBLOCKD *xd, | 244 void vp9_update_mv_count(VP9_COMMON *cm, const MACROBLOCKD *xd) { |
| 245 const MV best_ref_mv[2]) { | 245 const MODE_INFO *mi = xd->mi[0]; |
| 246 const MODE_INFO *mi = xd->mi_8x8[0]; | |
| 247 const MB_MODE_INFO *const mbmi = &mi->mbmi; | 246 const MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 248 const int is_compound = has_second_ref(mbmi); | |
| 249 nmv_context_counts *counts = &cm->counts.mv; | |
| 250 | 247 |
| 251 if (mbmi->sb_type < BLOCK_8X8) { | 248 if (mbmi->sb_type < BLOCK_8X8) { |
| 252 const int num_4x4_w = num_4x4_blocks_wide_lookup[mbmi->sb_type]; | 249 const int num_4x4_w = num_4x4_blocks_wide_lookup[mbmi->sb_type]; |
| 253 const int num_4x4_h = num_4x4_blocks_high_lookup[mbmi->sb_type]; | 250 const int num_4x4_h = num_4x4_blocks_high_lookup[mbmi->sb_type]; |
| 254 int idx, idy; | 251 int idx, idy; |
| 255 | 252 |
| 256 for (idy = 0; idy < 2; idy += num_4x4_h) { | 253 for (idy = 0; idy < 2; idy += num_4x4_h) { |
| 257 for (idx = 0; idx < 2; idx += num_4x4_w) { | 254 for (idx = 0; idx < 2; idx += num_4x4_w) { |
| 258 const int i = idy * 2 + idx; | 255 const int i = idy * 2 + idx; |
| 259 if (mi->bmi[i].as_mode == NEWMV) | 256 if (mi->bmi[i].as_mode == NEWMV) |
| 260 inc_mvs(mi->bmi[i].as_mv, best_ref_mv, is_compound, counts); | 257 inc_mvs(mbmi, mi->bmi[i].as_mv, &cm->counts.mv); |
| 261 } | 258 } |
| 262 } | 259 } |
| 263 } else if (mbmi->mode == NEWMV) { | 260 } else { |
| 264 inc_mvs(mbmi->mv, best_ref_mv, is_compound, counts); | 261 if (mbmi->mode == NEWMV) |
| 262 inc_mvs(mbmi, mbmi->mv, &cm->counts.mv); |
| 265 } | 263 } |
| 266 } | 264 } |
| 267 | 265 |
| OLD | NEW |