Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: source/libvpx/vp9/encoder/vp9_encodemv.c

Issue 23600008: libvpx: Pull from upstream (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_encodemb.c ('k') | source/libvpx/vp9/encoder/vp9_firstpass.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 11
12 #include "vp9/common/vp9_common.h" 12 #include "vp9/common/vp9_common.h"
13 #include "vp9/encoder/vp9_encodemv.h" 13 #include "vp9/encoder/vp9_encodemv.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 16
17 #include <math.h> 17 #include <math.h>
18 18
19 #ifdef ENTROPY_STATS 19 #ifdef ENTROPY_STATS
20 extern unsigned int active_section; 20 extern unsigned int active_section;
21 #endif 21 #endif
22 22
23 #ifdef NMV_STATS
24 nmv_context_counts tnmvcounts;
25 #endif
26
27 static void encode_mv_component(vp9_writer* w, int comp, 23 static void encode_mv_component(vp9_writer* w, int comp,
28 const nmv_component* mvcomp, int usehp) { 24 const nmv_component* mvcomp, int usehp) {
29 int offset; 25 int offset;
30 const int sign = comp < 0; 26 const int sign = comp < 0;
31 const int mag = sign ? -comp : comp; 27 const int mag = sign ? -comp : comp;
32 const int mv_class = vp9_get_mv_class(mag - 1, &offset); 28 const int mv_class = vp9_get_mv_class(mag - 1, &offset);
33 const int d = offset >> 3; // int mv data 29 const int d = offset >> 3; // int mv data
34 const int fr = (offset >> 1) & 3; // fractional mv data 30 const int fr = (offset >> 1) & 3; // fractional mv data
35 const int hp = offset & 1; // high precision mv data 31 const int hp = offset & 1; // high precision mv data
36 32
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 branch_ct_class0_hp[i][0] = c0_hp0; 207 branch_ct_class0_hp[i][0] = c0_hp0;
212 branch_ct_class0_hp[i][1] = c0_hp1; 208 branch_ct_class0_hp[i][1] = c0_hp1;
213 209
214 prob->comps[i].hp = get_binary_prob(hp0, hp1); 210 prob->comps[i].hp = get_binary_prob(hp0, hp1);
215 branch_ct_hp[i][0] = hp0; 211 branch_ct_hp[i][0] = hp0;
216 branch_ct_hp[i][1] = hp1; 212 branch_ct_hp[i][1] = hp1;
217 } 213 }
218 } 214 }
219 } 215 }
220 216
221 #ifdef NMV_STATS
222 void init_nmvstats() {
223 vp9_zero(tnmvcounts);
224 }
225
226 void print_nmvstats() {
227 nmv_context prob;
228 unsigned int branch_ct_joint[MV_JOINTS - 1][2];
229 unsigned int branch_ct_sign[2][2];
230 unsigned int branch_ct_classes[2][MV_CLASSES - 1][2];
231 unsigned int branch_ct_class0[2][CLASS0_SIZE - 1][2];
232 unsigned int branch_ct_bits[2][MV_OFFSET_BITS][2];
233 unsigned int branch_ct_class0_fp[2][CLASS0_SIZE][4 - 1][2];
234 unsigned int branch_ct_fp[2][4 - 1][2];
235 unsigned int branch_ct_class0_hp[2][2];
236 unsigned int branch_ct_hp[2][2];
237 int i, j, k;
238 counts_to_nmv_context(&tnmvcounts, &prob, 1,
239 branch_ct_joint, branch_ct_sign, branch_ct_classes,
240 branch_ct_class0, branch_ct_bits,
241 branch_ct_class0_fp, branch_ct_fp,
242 branch_ct_class0_hp, branch_ct_hp);
243
244 printf("\nCounts =\n { ");
245 for (j = 0; j < MV_JOINTS; ++j)
246 printf("%d, ", tnmvcounts.joints[j]);
247 printf("},\n");
248 for (i = 0; i < 2; ++i) {
249 printf(" {\n");
250 printf(" %d/%d,\n", tnmvcounts.comps[i].sign[0],
251 tnmvcounts.comps[i].sign[1]);
252 printf(" { ");
253 for (j = 0; j < MV_CLASSES; ++j)
254 printf("%d, ", tnmvcounts.comps[i].classes[j]);
255 printf("},\n");
256 printf(" { ");
257 for (j = 0; j < CLASS0_SIZE; ++j)
258 printf("%d, ", tnmvcounts.comps[i].class0[j]);
259 printf("},\n");
260 printf(" { ");
261 for (j = 0; j < MV_OFFSET_BITS; ++j)
262 printf("%d/%d, ", tnmvcounts.comps[i].bits[j][0],
263 tnmvcounts.comps[i].bits[j][1]);
264 printf("},\n");
265
266 printf(" {");
267 for (j = 0; j < CLASS0_SIZE; ++j) {
268 printf("{");
269 for (k = 0; k < 4; ++k)
270 printf("%d, ", tnmvcounts.comps[i].class0_fp[j][k]);
271 printf("}, ");
272 }
273 printf("},\n");
274
275 printf(" { ");
276 for (j = 0; j < 4; ++j)
277 printf("%d, ", tnmvcounts.comps[i].fp[j]);
278 printf("},\n");
279
280 printf(" %d/%d,\n",
281 tnmvcounts.comps[i].class0_hp[0],
282 tnmvcounts.comps[i].class0_hp[1]);
283 printf(" %d/%d,\n",
284 tnmvcounts.comps[i].hp[0],
285 tnmvcounts.comps[i].hp[1]);
286 printf(" },\n");
287 }
288
289 printf("\nProbs =\n { ");
290 for (j = 0; j < MV_JOINTS - 1; ++j)
291 printf("%d, ", prob.joints[j]);
292 printf("},\n");
293 for (i=0; i< 2; ++i) {
294 printf(" {\n");
295 printf(" %d,\n", prob.comps[i].sign);
296 printf(" { ");
297 for (j = 0; j < MV_CLASSES - 1; ++j)
298 printf("%d, ", prob.comps[i].classes[j]);
299 printf("},\n");
300 printf(" { ");
301 for (j = 0; j < CLASS0_SIZE - 1; ++j)
302 printf("%d, ", prob.comps[i].class0[j]);
303 printf("},\n");
304 printf(" { ");
305 for (j = 0; j < MV_OFFSET_BITS; ++j)
306 printf("%d, ", prob.comps[i].bits[j]);
307 printf("},\n");
308 printf(" { ");
309 for (j = 0; j < CLASS0_SIZE; ++j) {
310 printf("{");
311 for (k = 0; k < 3; ++k)
312 printf("%d, ", prob.comps[i].class0_fp[j][k]);
313 printf("}, ");
314 }
315 printf("},\n");
316 printf(" { ");
317 for (j = 0; j < 3; ++j)
318 printf("%d, ", prob.comps[i].fp[j]);
319 printf("},\n");
320
321 printf(" %d,\n", prob.comps[i].class0_hp);
322 printf(" %d,\n", prob.comps[i].hp);
323 printf(" },\n");
324 }
325 }
326
327 static void add_nmvcount(nmv_context_counts* const dst,
328 const nmv_context_counts* const src) {
329 int i, j, k;
330 for (j = 0; j < MV_JOINTS; ++j) {
331 dst->joints[j] += src->joints[j];
332 }
333 for (i = 0; i < 2; ++i) {
334 for (j = 0; j < MV_VALS; ++j) {
335 dst->comps[i].mvcount[j] += src->comps[i].mvcount[j];
336 }
337 dst->comps[i].sign[0] += src->comps[i].sign[0];
338 dst->comps[i].sign[1] += src->comps[i].sign[1];
339 for (j = 0; j < MV_CLASSES; ++j) {
340 dst->comps[i].classes[j] += src->comps[i].classes[j];
341 }
342 for (j = 0; j < CLASS0_SIZE; ++j) {
343 dst->comps[i].class0[j] += src->comps[i].class0[j];
344 }
345 for (j = 0; j < MV_OFFSET_BITS; ++j) {
346 dst->comps[i].bits[j][0] += src->comps[i].bits[j][0];
347 dst->comps[i].bits[j][1] += src->comps[i].bits[j][1];
348 }
349 }
350 for (i = 0; i < 2; ++i) {
351 for (j = 0; j < CLASS0_SIZE; ++j) {
352 for (k = 0; k < 4; ++k) {
353 dst->comps[i].class0_fp[j][k] += src->comps[i].class0_fp[j][k];
354 }
355 }
356 for (j = 0; j < 4; ++j) {
357 dst->comps[i].fp[j] += src->comps[i].fp[j];
358 }
359 dst->comps[i].class0_hp[0] += src->comps[i].class0_hp[0];
360 dst->comps[i].class0_hp[1] += src->comps[i].class0_hp[1];
361 dst->comps[i].hp[0] += src->comps[i].hp[0];
362 dst->comps[i].hp[1] += src->comps[i].hp[1];
363 }
364 }
365 #endif
366
367 void vp9_write_nmv_probs(VP9_COMP* const cpi, int usehp, vp9_writer* const bc) { 217 void vp9_write_nmv_probs(VP9_COMP* const cpi, int usehp, vp9_writer* const bc) {
368 int i, j; 218 int i, j;
369 nmv_context prob; 219 nmv_context prob;
370 unsigned int branch_ct_joint[MV_JOINTS - 1][2]; 220 unsigned int branch_ct_joint[MV_JOINTS - 1][2];
371 unsigned int branch_ct_sign[2][2]; 221 unsigned int branch_ct_sign[2][2];
372 unsigned int branch_ct_classes[2][MV_CLASSES - 1][2]; 222 unsigned int branch_ct_classes[2][MV_CLASSES - 1][2];
373 unsigned int branch_ct_class0[2][CLASS0_SIZE - 1][2]; 223 unsigned int branch_ct_class0[2][CLASS0_SIZE - 1][2];
374 unsigned int branch_ct_bits[2][MV_OFFSET_BITS][2]; 224 unsigned int branch_ct_bits[2][MV_OFFSET_BITS][2];
375 unsigned int branch_ct_class0_fp[2][CLASS0_SIZE][4 - 1][2]; 225 unsigned int branch_ct_class0_fp[2][CLASS0_SIZE][4 - 1][2];
376 unsigned int branch_ct_fp[2][4 - 1][2]; 226 unsigned int branch_ct_fp[2][4 - 1][2];
377 unsigned int branch_ct_class0_hp[2][2]; 227 unsigned int branch_ct_class0_hp[2][2];
378 unsigned int branch_ct_hp[2][2]; 228 unsigned int branch_ct_hp[2][2];
379 nmv_context *mvc = &cpi->common.fc.nmvc; 229 nmv_context *mvc = &cpi->common.fc.nmvc;
380 230
381 #ifdef NMV_STATS
382 if (!cpi->dummy_packing)
383 add_nmvcount(&tnmvcounts, &cpi->NMVcount);
384 #endif
385 counts_to_nmv_context(&cpi->NMVcount, &prob, usehp, 231 counts_to_nmv_context(&cpi->NMVcount, &prob, usehp,
386 branch_ct_joint, branch_ct_sign, branch_ct_classes, 232 branch_ct_joint, branch_ct_sign, branch_ct_classes,
387 branch_ct_class0, branch_ct_bits, 233 branch_ct_class0, branch_ct_bits,
388 branch_ct_class0_fp, branch_ct_fp, 234 branch_ct_class0_fp, branch_ct_fp,
389 branch_ct_class0_hp, branch_ct_hp); 235 branch_ct_class0_hp, branch_ct_hp);
390 236
391 for (j = 0; j < MV_JOINTS - 1; ++j) 237 for (j = 0; j < MV_JOINTS - 1; ++j)
392 update_mv(bc, branch_ct_joint[j], &mvc->joints[j], prob.joints[j], 238 update_mv(bc, branch_ct_joint[j], &mvc->joints[j], prob.joints[j],
393 VP9_NMV_UPDATE_PROB); 239 NMV_UPDATE_PROB);
394 240
395 for (i = 0; i < 2; ++i) { 241 for (i = 0; i < 2; ++i) {
396 update_mv(bc, branch_ct_sign[i], &mvc->comps[i].sign, 242 update_mv(bc, branch_ct_sign[i], &mvc->comps[i].sign,
397 prob.comps[i].sign, VP9_NMV_UPDATE_PROB); 243 prob.comps[i].sign, NMV_UPDATE_PROB);
398 for (j = 0; j < MV_CLASSES - 1; ++j) 244 for (j = 0; j < MV_CLASSES - 1; ++j)
399 update_mv(bc, branch_ct_classes[i][j], &mvc->comps[i].classes[j], 245 update_mv(bc, branch_ct_classes[i][j], &mvc->comps[i].classes[j],
400 prob.comps[i].classes[j], VP9_NMV_UPDATE_PROB); 246 prob.comps[i].classes[j], NMV_UPDATE_PROB);
401 247
402 for (j = 0; j < CLASS0_SIZE - 1; ++j) 248 for (j = 0; j < CLASS0_SIZE - 1; ++j)
403 update_mv(bc, branch_ct_class0[i][j], &mvc->comps[i].class0[j], 249 update_mv(bc, branch_ct_class0[i][j], &mvc->comps[i].class0[j],
404 prob.comps[i].class0[j], VP9_NMV_UPDATE_PROB); 250 prob.comps[i].class0[j], NMV_UPDATE_PROB);
405 251
406 for (j = 0; j < MV_OFFSET_BITS; ++j) 252 for (j = 0; j < MV_OFFSET_BITS; ++j)
407 update_mv(bc, branch_ct_bits[i][j], &mvc->comps[i].bits[j], 253 update_mv(bc, branch_ct_bits[i][j], &mvc->comps[i].bits[j],
408 prob.comps[i].bits[j], VP9_NMV_UPDATE_PROB); 254 prob.comps[i].bits[j], NMV_UPDATE_PROB);
409 } 255 }
410 256
411 for (i = 0; i < 2; ++i) { 257 for (i = 0; i < 2; ++i) {
412 for (j = 0; j < CLASS0_SIZE; ++j) { 258 for (j = 0; j < CLASS0_SIZE; ++j) {
413 int k; 259 int k;
414 for (k = 0; k < 3; ++k) 260 for (k = 0; k < 3; ++k)
415 update_mv(bc, branch_ct_class0_fp[i][j][k], 261 update_mv(bc, branch_ct_class0_fp[i][j][k],
416 &mvc->comps[i].class0_fp[j][k], 262 &mvc->comps[i].class0_fp[j][k],
417 prob.comps[i].class0_fp[j][k], VP9_NMV_UPDATE_PROB); 263 prob.comps[i].class0_fp[j][k], NMV_UPDATE_PROB);
418 } 264 }
419 265
420 for (j = 0; j < 3; ++j) 266 for (j = 0; j < 3; ++j)
421 update_mv(bc, branch_ct_fp[i][j], &mvc->comps[i].fp[j], 267 update_mv(bc, branch_ct_fp[i][j], &mvc->comps[i].fp[j],
422 prob.comps[i].fp[j], VP9_NMV_UPDATE_PROB); 268 prob.comps[i].fp[j], NMV_UPDATE_PROB);
423 } 269 }
424 270
425 if (usehp) { 271 if (usehp) {
426 for (i = 0; i < 2; ++i) { 272 for (i = 0; i < 2; ++i) {
427 update_mv(bc, branch_ct_class0_hp[i], &mvc->comps[i].class0_hp, 273 update_mv(bc, branch_ct_class0_hp[i], &mvc->comps[i].class0_hp,
428 prob.comps[i].class0_hp, VP9_NMV_UPDATE_PROB); 274 prob.comps[i].class0_hp, NMV_UPDATE_PROB);
429 update_mv(bc, branch_ct_hp[i], &mvc->comps[i].hp, 275 update_mv(bc, branch_ct_hp[i], &mvc->comps[i].hp,
430 prob.comps[i].hp, VP9_NMV_UPDATE_PROB); 276 prob.comps[i].hp, NMV_UPDATE_PROB);
431 } 277 }
432 } 278 }
433 } 279 }
434 280
435 void vp9_encode_mv(VP9_COMP* cpi, vp9_writer* w, 281 void vp9_encode_mv(VP9_COMP* cpi, vp9_writer* w,
436 const MV* mv, const MV* ref, 282 const MV* mv, const MV* ref,
437 const nmv_context* mvctx, int usehp) { 283 const nmv_context* mvctx, int usehp) {
438 const MV diff = {mv->row - ref->row, 284 const MV diff = {mv->row - ref->row,
439 mv->col - ref->col}; 285 mv->col - ref->col};
440 const MV_JOINT_TYPE j = vp9_get_mv_joint(&diff); 286 const MV_JOINT_TYPE j = vp9_get_mv_joint(&diff);
(...skipping 30 matching lines...) Expand all
471 317
472 void vp9_update_nmv_count(VP9_COMP *cpi, MACROBLOCK *x, 318 void vp9_update_nmv_count(VP9_COMP *cpi, MACROBLOCK *x,
473 int_mv *best_ref_mv, int_mv *second_best_ref_mv) { 319 int_mv *best_ref_mv, int_mv *second_best_ref_mv) {
474 MODE_INFO *mi = x->e_mbd.mode_info_context; 320 MODE_INFO *mi = x->e_mbd.mode_info_context;
475 MB_MODE_INFO *const mbmi = &mi->mbmi; 321 MB_MODE_INFO *const mbmi = &mi->mbmi;
476 MV diff; 322 MV diff;
477 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[mbmi->sb_type]; 323 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[mbmi->sb_type];
478 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[mbmi->sb_type]; 324 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[mbmi->sb_type];
479 int idx, idy; 325 int idx, idy;
480 326
481 if (mbmi->sb_type < BLOCK_SIZE_SB8X8) { 327 if (mbmi->sb_type < BLOCK_8X8) {
482 PARTITION_INFO *pi = x->partition_info; 328 PARTITION_INFO *pi = x->partition_info;
483 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { 329 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) {
484 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { 330 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) {
485 const int i = idy * 2 + idx; 331 const int i = idy * 2 + idx;
486 if (pi->bmi[i].mode == NEWMV) { 332 if (pi->bmi[i].mode == NEWMV) {
487 diff.row = mi->bmi[i].as_mv[0].as_mv.row - best_ref_mv->as_mv.row; 333 diff.row = mi->bmi[i].as_mv[0].as_mv.row - best_ref_mv->as_mv.row;
488 diff.col = mi->bmi[i].as_mv[0].as_mv.col - best_ref_mv->as_mv.col; 334 diff.col = mi->bmi[i].as_mv[0].as_mv.col - best_ref_mv->as_mv.col;
489 vp9_inc_mv(&diff, &cpi->NMVcount); 335 vp9_inc_mv(&diff, &cpi->NMVcount);
490 336
491 if (x->e_mbd.mode_info_context->mbmi.ref_frame[1] > INTRA_FRAME) { 337 if (x->e_mbd.mode_info_context->mbmi.ref_frame[1] > INTRA_FRAME) {
(...skipping 11 matching lines...) Expand all
503 diff.col = mbmi->mv[0].as_mv.col - best_ref_mv->as_mv.col; 349 diff.col = mbmi->mv[0].as_mv.col - best_ref_mv->as_mv.col;
504 vp9_inc_mv(&diff, &cpi->NMVcount); 350 vp9_inc_mv(&diff, &cpi->NMVcount);
505 351
506 if (mbmi->ref_frame[1] > INTRA_FRAME) { 352 if (mbmi->ref_frame[1] > INTRA_FRAME) {
507 diff.row = mbmi->mv[1].as_mv.row - second_best_ref_mv->as_mv.row; 353 diff.row = mbmi->mv[1].as_mv.row - second_best_ref_mv->as_mv.row;
508 diff.col = mbmi->mv[1].as_mv.col - second_best_ref_mv->as_mv.col; 354 diff.col = mbmi->mv[1].as_mv.col - second_best_ref_mv->as_mv.col;
509 vp9_inc_mv(&diff, &cpi->NMVcount); 355 vp9_inc_mv(&diff, &cpi->NMVcount);
510 } 356 }
511 } 357 }
512 } 358 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_encodemb.c ('k') | source/libvpx/vp9/encoder/vp9_firstpass.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698