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 | 11 |
12 #include "vpx_ports/config.h" | 12 #include "./vpx_config.h" |
13 #include "vp9/encoder/vp9_encodeframe.h" | 13 #include "vp9/encoder/vp9_encodeframe.h" |
14 #include "vp9/encoder/vp9_encodemb.h" | 14 #include "vp9/encoder/vp9_encodemb.h" |
15 #include "vp9/encoder/vp9_encodemv.h" | 15 #include "vp9/encoder/vp9_encodemv.h" |
16 #include "vp9/common/vp9_common.h" | 16 #include "vp9/common/vp9_common.h" |
17 #include "vp9/encoder/vp9_onyx_int.h" | 17 #include "vp9/encoder/vp9_onyx_int.h" |
18 #include "vp9/common/vp9_extend.h" | 18 #include "vp9/common/vp9_extend.h" |
| 19 #include "vp9/common/vp9_entropy.h" |
19 #include "vp9/common/vp9_entropymode.h" | 20 #include "vp9/common/vp9_entropymode.h" |
20 #include "vp9/common/vp9_quant_common.h" | 21 #include "vp9/common/vp9_quant_common.h" |
21 #include "vp9/encoder/vp9_segmentation.h" | 22 #include "vp9/encoder/vp9_segmentation.h" |
22 #include "vp9/common/vp9_setupintrarecon.h" | 23 #include "vp9/common/vp9_setupintrarecon.h" |
23 #include "vp9/common/vp9_reconintra4x4.h" | 24 #include "vp9/common/vp9_reconintra4x4.h" |
24 #include "vp9/encoder/vp9_encodeintra.h" | 25 #include "vp9/encoder/vp9_encodeintra.h" |
25 #include "vp9/common/vp9_reconinter.h" | 26 #include "vp9/common/vp9_reconinter.h" |
26 #include "vp9/common/vp9_invtrans.h" | 27 #include "vp9/common/vp9_invtrans.h" |
27 #include "vp9/encoder/vp9_rdopt.h" | 28 #include "vp9/encoder/vp9_rdopt.h" |
28 #include "vp9/common/vp9_findnearmv.h" | 29 #include "vp9/common/vp9_findnearmv.h" |
29 #include "vp9/common/vp9_reconintra.h" | 30 #include "vp9/common/vp9_reconintra.h" |
30 #include "vp9/common/vp9_seg_common.h" | 31 #include "vp9/common/vp9_seg_common.h" |
31 #include "vp9/encoder/vp9_tokenize.h" | 32 #include "vp9/encoder/vp9_tokenize.h" |
32 #include "vp9_rtcd.h" | 33 #include "vp9_rtcd.h" |
33 #include <stdio.h> | 34 #include <stdio.h> |
34 #include <math.h> | 35 #include <math.h> |
35 #include <limits.h> | 36 #include <limits.h> |
36 #include "vpx_ports/vpx_timer.h" | 37 #include "vpx_ports/vpx_timer.h" |
37 #include "vp9/common/vp9_pred_common.h" | 38 #include "vp9/common/vp9_pred_common.h" |
38 #include "vp9/common/vp9_mvref_common.h" | 39 #include "vp9/common/vp9_mvref_common.h" |
39 | 40 |
40 #define DBG_PRNT_SEGMAP 0 | 41 #define DBG_PRNT_SEGMAP 0 |
41 | 42 |
42 // #define ENC_DEBUG | 43 // #define ENC_DEBUG |
43 #ifdef ENC_DEBUG | 44 #ifdef ENC_DEBUG |
44 int enc_debug = 0; | 45 int enc_debug = 0; |
45 #endif | 46 #endif |
46 | 47 |
47 static void encode_macroblock(VP9_COMP *cpi, MACROBLOCK *x, | 48 extern void select_interp_filter_type(VP9_COMP *cpi); |
48 TOKENEXTRA **t, int recon_yoffset, | |
49 int recon_uvoffset, int output_enabled, | |
50 int mb_col, int mb_row); | |
51 | 49 |
52 static void encode_superblock(VP9_COMP *cpi, MACROBLOCK *x, | 50 static void encode_macroblock(VP9_COMP *cpi, TOKENEXTRA **t, |
53 TOKENEXTRA **t, int recon_yoffset, | 51 int recon_yoffset, int recon_uvoffset, |
54 int recon_uvoffset, int mb_col, int mb_row); | 52 int output_enabled, int mb_row, int mb_col); |
| 53 |
| 54 static void encode_superblock32(VP9_COMP *cpi, TOKENEXTRA **t, |
| 55 int recon_yoffset, int recon_uvoffset, |
| 56 int output_enabled, int mb_row, int mb_col); |
| 57 |
| 58 static void encode_superblock64(VP9_COMP *cpi, TOKENEXTRA **t, |
| 59 int recon_yoffset, int recon_uvoffset, |
| 60 int output_enabled, int mb_row, int mb_col); |
55 | 61 |
56 static void adjust_act_zbin(VP9_COMP *cpi, MACROBLOCK *x); | 62 static void adjust_act_zbin(VP9_COMP *cpi, MACROBLOCK *x); |
57 | 63 |
58 #ifdef MODE_STATS | 64 #ifdef MODE_STATS |
59 unsigned int inter_y_modes[MB_MODE_COUNT]; | 65 unsigned int inter_y_modes[MB_MODE_COUNT]; |
60 unsigned int inter_uv_modes[VP9_UV_MODES]; | 66 unsigned int inter_uv_modes[VP9_UV_MODES]; |
61 unsigned int inter_b_modes[B_MODE_COUNT]; | 67 unsigned int inter_b_modes[B_MODE_COUNT]; |
62 unsigned int y_modes[VP9_YMODES]; | 68 unsigned int y_modes[VP9_YMODES]; |
63 unsigned int i8x8_modes[VP9_I8X8_MODES]; | 69 unsigned int i8x8_modes[VP9_I8X8_MODES]; |
64 unsigned int uv_modes[VP9_UV_MODES]; | 70 unsigned int uv_modes[VP9_UV_MODES]; |
65 unsigned int uv_modes_y[VP9_YMODES][VP9_UV_MODES]; | 71 unsigned int uv_modes_y[VP9_YMODES][VP9_UV_MODES]; |
66 unsigned int b_modes[B_MODE_COUNT]; | 72 unsigned int b_modes[B_MODE_COUNT]; |
67 #endif | 73 #endif |
68 | 74 |
69 | 75 |
70 /* activity_avg must be positive, or flat regions could get a zero weight | 76 /* activity_avg must be positive, or flat regions could get a zero weight |
71 * (infinite lambda), which confounds analysis. | 77 * (infinite lambda), which confounds analysis. |
72 * This also avoids the need for divide by zero checks in | 78 * This also avoids the need for divide by zero checks in |
73 * vp9_activity_masking(). | 79 * vp9_activity_masking(). |
74 */ | 80 */ |
75 #define VP9_ACTIVITY_AVG_MIN (64) | 81 #define VP9_ACTIVITY_AVG_MIN (64) |
76 | 82 |
77 /* This is used as a reference when computing the source variance for the | 83 /* This is used as a reference when computing the source variance for the |
78 * purposes of activity masking. | 84 * purposes of activity masking. |
79 * Eventually this should be replaced by custom no-reference routines, | 85 * Eventually this should be replaced by custom no-reference routines, |
80 * which will be faster. | 86 * which will be faster. |
81 */ | 87 */ |
82 static const unsigned char VP9_VAR_OFFS[16] = { | 88 static const uint8_t VP9_VAR_OFFS[16] = { |
83 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 | 89 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 |
84 }; | 90 }; |
85 | 91 |
86 | 92 |
87 // Original activity measure from Tim T's code. | 93 // Original activity measure from Tim T's code. |
88 static unsigned int tt_activity_measure(VP9_COMP *cpi, MACROBLOCK *x) { | 94 static unsigned int tt_activity_measure(VP9_COMP *cpi, MACROBLOCK *x) { |
89 unsigned int act; | 95 unsigned int act; |
90 unsigned int sse; | 96 unsigned int sse; |
91 /* TODO: This could also be done over smaller areas (8x8), but that would | 97 /* TODO: This could also be done over smaller areas (8x8), but that would |
92 * require extensive changes elsewhere, as lambda is assumed to be fixed | 98 * require extensive changes elsewhere, as lambda is assumed to be fixed |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 xd->up_available = (mb_row != 0); | 278 xd->up_available = (mb_row != 0); |
273 recon_yoffset = (mb_row * recon_y_stride * 16); | 279 recon_yoffset = (mb_row * recon_y_stride * 16); |
274 #endif | 280 #endif |
275 // for each macroblock col in image | 281 // for each macroblock col in image |
276 for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) { | 282 for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) { |
277 #if ALT_ACT_MEASURE | 283 #if ALT_ACT_MEASURE |
278 xd->dst.y_buffer = new_yv12->y_buffer + recon_yoffset; | 284 xd->dst.y_buffer = new_yv12->y_buffer + recon_yoffset; |
279 xd->left_available = (mb_col != 0); | 285 xd->left_available = (mb_col != 0); |
280 recon_yoffset += 16; | 286 recon_yoffset += 16; |
281 #endif | 287 #endif |
282 #if !CONFIG_SUPERBLOCKS | |
283 // Copy current mb to a buffer | |
284 vp9_copy_mem16x16(x->src.y_buffer, x->src.y_stride, x->thismb, 16); | |
285 #endif | |
286 | 288 |
287 // measure activity | 289 // measure activity |
288 mb_activity = mb_activity_measure(cpi, x, mb_row, mb_col); | 290 mb_activity = mb_activity_measure(cpi, x, mb_row, mb_col); |
289 | 291 |
290 // Keep frame sum | 292 // Keep frame sum |
291 activity_sum += mb_activity; | 293 activity_sum += mb_activity; |
292 | 294 |
293 // Store MB level activity details. | 295 // Store MB level activity details. |
294 *x->mb_activity_ptr = mb_activity; | 296 *x->mb_activity_ptr = mb_activity; |
295 | 297 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 int_mv target_mv, | 386 int_mv target_mv, |
385 int_mv * mv_ref_list, | 387 int_mv * mv_ref_list, |
386 int_mv * best_ref) { | 388 int_mv * best_ref) { |
387 int i; | 389 int i; |
388 int best_index = 0; | 390 int best_index = 0; |
389 int cost, cost2; | 391 int cost, cost2; |
390 int zero_seen = (mv_ref_list[0].as_int) ? FALSE : TRUE; | 392 int zero_seen = (mv_ref_list[0].as_int) ? FALSE : TRUE; |
391 MACROBLOCKD *xd = &x->e_mbd; | 393 MACROBLOCKD *xd = &x->e_mbd; |
392 int max_mv = MV_MAX; | 394 int max_mv = MV_MAX; |
393 | 395 |
394 cost = vp9_cost_mv_ref_id(xd->mb_mv_ref_id_probs[ref_frame], 0) + | 396 cost = vp9_cost_mv_ref_id(xd->mb_mv_ref_probs[ref_frame], 0) + |
395 vp9_mv_bit_cost(&target_mv, &mv_ref_list[0], x->nmvjointcost, | 397 vp9_mv_bit_cost(&target_mv, &mv_ref_list[0], x->nmvjointcost, |
396 x->mvcost, 96, xd->allow_high_precision_mv); | 398 x->mvcost, 96, xd->allow_high_precision_mv); |
397 | 399 |
398 // Use 4 for now : for (i = 1; i < MAX_MV_REFS; ++i ) { | 400 for (i = 1; i < MAX_MV_REF_CANDIDATES; ++i) { |
399 for (i = 1; i < 4; ++i) { | |
400 // If we see a 0,0 reference vector for a second time we have reached | 401 // If we see a 0,0 reference vector for a second time we have reached |
401 // the end of the list of valid candidate vectors. | 402 // the end of the list of valid candidate vectors. |
402 if (!mv_ref_list[i].as_int) { | 403 if (!mv_ref_list[i].as_int) { |
403 if (zero_seen) | 404 if (zero_seen) |
404 break; | 405 break; |
405 else | 406 else |
406 zero_seen = TRUE; | 407 zero_seen = TRUE; |
407 } | 408 } |
408 | 409 |
409 // Check for cases where the reference choice would give rise to an | 410 // Check for cases where the reference choice would give rise to an |
410 // uncodable/out of range residual for row or col. | 411 // uncodable/out of range residual for row or col. |
411 if ((abs(target_mv.as_mv.row - mv_ref_list[i].as_mv.row) > max_mv) || | 412 if ((abs(target_mv.as_mv.row - mv_ref_list[i].as_mv.row) > max_mv) || |
412 (abs(target_mv.as_mv.col - mv_ref_list[i].as_mv.col) > max_mv)) { | 413 (abs(target_mv.as_mv.col - mv_ref_list[i].as_mv.col) > max_mv)) { |
413 continue; | 414 continue; |
414 } | 415 } |
415 | 416 |
416 cost2 = vp9_cost_mv_ref_id(xd->mb_mv_ref_id_probs[ref_frame], i) + | 417 cost2 = vp9_cost_mv_ref_id(xd->mb_mv_ref_probs[ref_frame], i) + |
417 vp9_mv_bit_cost(&target_mv, &mv_ref_list[i], x->nmvjointcost, | 418 vp9_mv_bit_cost(&target_mv, &mv_ref_list[i], x->nmvjointcost, |
418 x->mvcost, 96, xd->allow_high_precision_mv); | 419 x->mvcost, 96, xd->allow_high_precision_mv); |
419 | 420 |
420 if (cost2 < cost) { | 421 if (cost2 < cost) { |
421 cost = cost2; | 422 cost = cost2; |
422 best_index = i; | 423 best_index = i; |
423 } | 424 } |
424 } | 425 } |
425 | |
426 best_ref->as_int = mv_ref_list[best_index].as_int; | 426 best_ref->as_int = mv_ref_list[best_index].as_int; |
427 | 427 |
428 return best_index; | 428 return best_index; |
429 } | 429 } |
430 #endif | 430 #endif |
431 | 431 |
432 static void update_state(VP9_COMP *cpi, MACROBLOCK *x, | 432 static void update_state(VP9_COMP *cpi, |
433 PICK_MODE_CONTEXT *ctx) { | 433 PICK_MODE_CONTEXT *ctx, int block_size, |
434 int i; | 434 int output_enabled) { |
435 MACROBLOCKD *xd = &x->e_mbd; | 435 int i, x_idx, y; |
| 436 MACROBLOCK *const x = &cpi->mb; |
| 437 MACROBLOCKD *const xd = &x->e_mbd; |
436 MODE_INFO *mi = &ctx->mic; | 438 MODE_INFO *mi = &ctx->mic; |
437 MB_MODE_INFO * mbmi = &xd->mode_info_context->mbmi; | 439 MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi; |
438 int mb_mode = mi->mbmi.mode; | 440 int mb_mode = mi->mbmi.mode; |
439 int mb_mode_index = ctx->best_mode_index; | 441 int mb_mode_index = ctx->best_mode_index; |
| 442 const int mis = cpi->common.mode_info_stride; |
| 443 int mb_block_size = 1 << mi->mbmi.sb_type; |
440 | 444 |
441 #if CONFIG_DEBUG | 445 #if CONFIG_DEBUG |
442 assert(mb_mode < MB_MODE_COUNT); | 446 assert(mb_mode < MB_MODE_COUNT); |
443 assert(mb_mode_index < MAX_MODES); | 447 assert(mb_mode_index < MAX_MODES); |
444 assert(mi->mbmi.ref_frame < MAX_REF_FRAMES); | 448 assert(mi->mbmi.ref_frame < MAX_REF_FRAMES); |
445 #endif | 449 #endif |
| 450 assert(mi->mbmi.sb_type == (block_size >> 5)); |
446 | 451 |
447 // Restore the coding context of the MB to that that was in place | 452 // Restore the coding context of the MB to that that was in place |
448 // when the mode was picked for it | 453 // when the mode was picked for it |
449 vpx_memcpy(xd->mode_info_context, mi, sizeof(MODE_INFO)); | 454 for (y = 0; y < mb_block_size; y++) { |
450 #if CONFIG_SUPERBLOCKS | 455 for (x_idx = 0; x_idx < mb_block_size; x_idx++) { |
451 if (mi->mbmi.encoded_as_sb) { | 456 if ((xd->mb_to_right_edge >> 7) + mb_block_size > x_idx && |
452 const int mis = cpi->common.mode_info_stride; | 457 (xd->mb_to_bottom_edge >> 7) + mb_block_size > y) { |
453 if (xd->mb_to_right_edge >= 0) | 458 MODE_INFO *mi_addr = xd->mode_info_context + x_idx + y * mis; |
454 vpx_memcpy(xd->mode_info_context + 1, mi, sizeof(MODE_INFO)); | 459 |
455 if (xd->mb_to_bottom_edge >= 0) { | 460 vpx_memcpy(mi_addr, mi, sizeof(MODE_INFO)); |
456 vpx_memcpy(xd->mode_info_context + mis, mi, sizeof(MODE_INFO)); | 461 } |
457 if (xd->mb_to_right_edge >= 0) | |
458 vpx_memcpy(xd->mode_info_context + mis + 1, mi, sizeof(MODE_INFO)); | |
459 } | 462 } |
460 } | 463 } |
461 #endif | 464 if (block_size == 16) { |
| 465 ctx->txfm_rd_diff[ALLOW_32X32] = ctx->txfm_rd_diff[ALLOW_16X16]; |
| 466 } |
462 | 467 |
463 if (mb_mode == B_PRED) { | 468 if (mb_mode == B_PRED) { |
464 for (i = 0; i < 16; i++) { | 469 for (i = 0; i < 16; i++) { |
465 xd->block[i].bmi.as_mode = xd->mode_info_context->bmi[i].as_mode; | 470 xd->block[i].bmi.as_mode = xd->mode_info_context->bmi[i].as_mode; |
466 assert(xd->block[i].bmi.as_mode.first < B_MODE_COUNT); | 471 assert(xd->block[i].bmi.as_mode.first < B_MODE_COUNT); |
467 } | 472 } |
468 } else if (mb_mode == I8X8_PRED) { | 473 } else if (mb_mode == I8X8_PRED) { |
469 for (i = 0; i < 16; i++) { | 474 for (i = 0; i < 16; i++) { |
470 xd->block[i].bmi = xd->mode_info_context->bmi[i]; | 475 xd->block[i].bmi = xd->mode_info_context->bmi[i]; |
471 } | 476 } |
472 } else if (mb_mode == SPLITMV) { | 477 } else if (mb_mode == SPLITMV) { |
473 vpx_memcpy(x->partition_info, &ctx->partition_info, | 478 vpx_memcpy(x->partition_info, &ctx->partition_info, |
474 sizeof(PARTITION_INFO)); | 479 sizeof(PARTITION_INFO)); |
475 | 480 |
476 mbmi->mv[0].as_int = x->partition_info->bmi[15].mv.as_int; | 481 mbmi->mv[0].as_int = x->partition_info->bmi[15].mv.as_int; |
477 mbmi->mv[1].as_int = x->partition_info->bmi[15].second_mv.as_int; | 482 mbmi->mv[1].as_int = x->partition_info->bmi[15].second_mv.as_int; |
478 } | 483 } |
479 | 484 |
| 485 x->skip = ctx->skip; |
| 486 if (!output_enabled) |
| 487 return; |
| 488 |
480 { | 489 { |
481 int segment_id = mbmi->segment_id; | 490 int segment_id = mbmi->segment_id; |
482 if (!vp9_segfeature_active(xd, segment_id, SEG_LVL_EOB) || | 491 if (!vp9_segfeature_active(xd, segment_id, SEG_LVL_EOB) || |
483 vp9_get_segdata(xd, segment_id, SEG_LVL_EOB)) { | 492 vp9_get_segdata(xd, segment_id, SEG_LVL_EOB)) { |
484 for (i = 0; i < NB_TXFM_MODES; i++) { | 493 for (i = 0; i < NB_TXFM_MODES; i++) { |
485 cpi->rd_tx_select_diff[i] += ctx->txfm_rd_diff[i]; | 494 cpi->rd_tx_select_diff[i] += ctx->txfm_rd_diff[i]; |
486 } | 495 } |
487 } | 496 } |
488 } | 497 } |
489 | 498 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 #endif | 552 #endif |
544 best_mv.as_int = ctx->best_ref_mv.as_int; | 553 best_mv.as_int = ctx->best_ref_mv.as_int; |
545 best_second_mv.as_int = ctx->second_best_ref_mv.as_int; | 554 best_second_mv.as_int = ctx->second_best_ref_mv.as_int; |
546 if (mbmi->mode == NEWMV) { | 555 if (mbmi->mode == NEWMV) { |
547 best_mv.as_int = mbmi->ref_mvs[rf][0].as_int; | 556 best_mv.as_int = mbmi->ref_mvs[rf][0].as_int; |
548 best_second_mv.as_int = mbmi->ref_mvs[mbmi->second_ref_frame][0].as_int; | 557 best_second_mv.as_int = mbmi->ref_mvs[mbmi->second_ref_frame][0].as_int; |
549 #if CONFIG_NEW_MVREF | 558 #if CONFIG_NEW_MVREF |
550 best_index = pick_best_mv_ref(x, rf, mbmi->mv[0], | 559 best_index = pick_best_mv_ref(x, rf, mbmi->mv[0], |
551 mbmi->ref_mvs[rf], &best_mv); | 560 mbmi->ref_mvs[rf], &best_mv); |
552 mbmi->best_index = best_index; | 561 mbmi->best_index = best_index; |
| 562 ++cpi->mb_mv_ref_count[rf][best_index]; |
553 | 563 |
554 if (mbmi->second_ref_frame > 0) { | 564 if (mbmi->second_ref_frame > 0) { |
555 unsigned int best_index; | 565 unsigned int best_index; |
556 best_index = | 566 best_index = |
557 pick_best_mv_ref(x, sec_ref_frame, mbmi->mv[1], | 567 pick_best_mv_ref(x, sec_ref_frame, mbmi->mv[1], |
558 mbmi->ref_mvs[sec_ref_frame], | 568 mbmi->ref_mvs[sec_ref_frame], |
559 &best_second_mv); | 569 &best_second_mv); |
560 mbmi->best_second_index = best_index; | 570 mbmi->best_second_index = best_index; |
| 571 ++cpi->mb_mv_ref_count[sec_ref_frame][best_index]; |
561 } | 572 } |
562 #endif | 573 #endif |
563 } | 574 } |
564 mbmi->best_mv.as_int = best_mv.as_int; | 575 mbmi->best_mv.as_int = best_mv.as_int; |
565 mbmi->best_second_mv.as_int = best_second_mv.as_int; | 576 mbmi->best_second_mv.as_int = best_second_mv.as_int; |
566 vp9_update_nmv_count(cpi, x, &best_mv, &best_second_mv); | 577 vp9_update_nmv_count(cpi, x, &best_mv, &best_second_mv); |
567 } | 578 } |
568 #if CONFIG_COMP_INTERINTRA_PRED | 579 #if CONFIG_COMP_INTERINTRA_PRED |
569 if (mbmi->mode >= NEARESTMV && mbmi->mode < SPLITMV && | 580 if (mbmi->mode >= NEARESTMV && mbmi->mode < SPLITMV && |
570 mbmi->second_ref_frame <= INTRA_FRAME) { | 581 mbmi->second_ref_frame <= INTRA_FRAME) { |
571 if (mbmi->second_ref_frame == INTRA_FRAME) { | 582 if (mbmi->second_ref_frame == INTRA_FRAME) { |
572 ++cpi->interintra_count[1]; | 583 ++cpi->interintra_count[1]; |
573 ++cpi->ymode_count[mbmi->interintra_mode]; | 584 ++cpi->ymode_count[mbmi->interintra_mode]; |
574 #if SEPARATE_INTERINTRA_UV | 585 #if SEPARATE_INTERINTRA_UV |
575 ++cpi->y_uv_mode_count[mbmi->interintra_mode][mbmi->interintra_uv_mode]; | 586 ++cpi->y_uv_mode_count[mbmi->interintra_mode][mbmi->interintra_uv_mode]; |
576 #endif | 587 #endif |
577 } else { | 588 } else { |
578 ++cpi->interintra_count[0]; | 589 ++cpi->interintra_count[0]; |
579 } | 590 } |
580 } | 591 } |
| 592 #endif |
581 if (cpi->common.mcomp_filter_type == SWITCHABLE && | 593 if (cpi->common.mcomp_filter_type == SWITCHABLE && |
582 mbmi->mode >= NEARESTMV && | 594 mbmi->mode >= NEARESTMV && |
583 mbmi->mode <= SPLITMV) { | 595 mbmi->mode <= SPLITMV) { |
584 ++cpi->switchable_interp_count | 596 ++cpi->switchable_interp_count |
585 [vp9_get_pred_context(&cpi->common, xd, PRED_SWITCHABLE_INTERP)] | 597 [vp9_get_pred_context(&cpi->common, xd, PRED_SWITCHABLE_INTERP)] |
586 [vp9_switchable_interp_map[mbmi->interp_filter]]; | 598 [vp9_switchable_interp_map[mbmi->interp_filter]]; |
587 } | 599 } |
588 #endif | |
589 | 600 |
590 cpi->prediction_error += ctx->distortion; | 601 cpi->prediction_error += ctx->distortion; |
591 cpi->intra_error += ctx->intra_error; | 602 cpi->intra_error += ctx->intra_error; |
592 | 603 |
593 cpi->rd_comp_pred_diff[SINGLE_PREDICTION_ONLY] += ctx->single_pred_diff; | 604 cpi->rd_comp_pred_diff[SINGLE_PREDICTION_ONLY] += ctx->single_pred_diff; |
594 cpi->rd_comp_pred_diff[COMP_PREDICTION_ONLY] += ctx->comp_pred_diff; | 605 cpi->rd_comp_pred_diff[COMP_PREDICTION_ONLY] += ctx->comp_pred_diff; |
595 cpi->rd_comp_pred_diff[HYBRID_PREDICTION] += ctx->hybrid_pred_diff; | 606 cpi->rd_comp_pred_diff[HYBRID_PREDICTION] += ctx->hybrid_pred_diff; |
596 } | 607 } |
597 } | 608 } |
598 | 609 |
| 610 static unsigned find_seg_id(uint8_t *buf, int block_size, |
| 611 int start_y, int height, int start_x, int width) { |
| 612 const int end_x = MIN(start_x + block_size, width); |
| 613 const int end_y = MIN(start_y + block_size, height); |
| 614 int x, y; |
| 615 unsigned seg_id = -1; |
| 616 |
| 617 buf += width * start_y; |
| 618 for (y = start_y; y < end_y; y++, buf += width) { |
| 619 for (x = start_x; x < end_x; x++) { |
| 620 seg_id = MIN(seg_id, buf[x]); |
| 621 } |
| 622 } |
| 623 |
| 624 return seg_id; |
| 625 } |
| 626 |
| 627 static void set_offsets(VP9_COMP *cpi, |
| 628 int mb_row, int mb_col, int block_size, |
| 629 int *ref_yoffset, int *ref_uvoffset) { |
| 630 MACROBLOCK *const x = &cpi->mb; |
| 631 VP9_COMMON *const cm = &cpi->common; |
| 632 MACROBLOCKD *const xd = &x->e_mbd; |
| 633 MB_MODE_INFO *mbmi; |
| 634 const int dst_fb_idx = cm->new_fb_idx; |
| 635 const int recon_y_stride = cm->yv12_fb[dst_fb_idx].y_stride; |
| 636 const int recon_uv_stride = cm->yv12_fb[dst_fb_idx].uv_stride; |
| 637 const int recon_yoffset = 16 * mb_row * recon_y_stride + 16 * mb_col; |
| 638 const int recon_uvoffset = 8 * mb_row * recon_uv_stride + 8 * mb_col; |
| 639 const int src_y_stride = x->src.y_stride; |
| 640 const int src_uv_stride = x->src.uv_stride; |
| 641 const int src_yoffset = 16 * mb_row * src_y_stride + 16 * mb_col; |
| 642 const int src_uvoffset = 8 * mb_row * src_uv_stride + 8 * mb_col; |
| 643 const int ref_fb_idx = cm->lst_fb_idx; |
| 644 const int ref_y_stride = cm->yv12_fb[ref_fb_idx].y_stride; |
| 645 const int ref_uv_stride = cm->yv12_fb[ref_fb_idx].uv_stride; |
| 646 const int idx_map = mb_row * cm->mb_cols + mb_col; |
| 647 const int idx_str = xd->mode_info_stride * mb_row + mb_col; |
| 648 |
| 649 // entropy context structures |
| 650 xd->above_context = cm->above_context + mb_col; |
| 651 xd->left_context = cm->left_context + (mb_row & 3); |
| 652 |
| 653 // GF active flags data structure |
| 654 x->gf_active_ptr = (signed char *)&cpi->gf_active_flags[idx_map]; |
| 655 |
| 656 // Activity map pointer |
| 657 x->mb_activity_ptr = &cpi->mb_activity_map[idx_map]; |
| 658 x->active_ptr = cpi->active_map + idx_map; |
| 659 |
| 660 /* pointers to mode info contexts */ |
| 661 x->partition_info = x->pi + idx_str; |
| 662 xd->mode_info_context = cm->mi + idx_str; |
| 663 mbmi = &xd->mode_info_context->mbmi; |
| 664 xd->prev_mode_info_context = cm->prev_mi + idx_str; |
| 665 |
| 666 // Set up destination pointers |
| 667 xd->dst.y_buffer = cm->yv12_fb[dst_fb_idx].y_buffer + recon_yoffset; |
| 668 xd->dst.u_buffer = cm->yv12_fb[dst_fb_idx].u_buffer + recon_uvoffset; |
| 669 xd->dst.v_buffer = cm->yv12_fb[dst_fb_idx].v_buffer + recon_uvoffset; |
| 670 |
| 671 /* Set up limit values for MV components to prevent them from |
| 672 * extending beyond the UMV borders assuming 16x16 block size */ |
| 673 x->mv_row_min = -((mb_row * 16) + VP9BORDERINPIXELS - VP9_INTERP_EXTEND); |
| 674 x->mv_col_min = -((mb_col * 16) + VP9BORDERINPIXELS - VP9_INTERP_EXTEND); |
| 675 x->mv_row_max = ((cm->mb_rows - mb_row) * 16 + |
| 676 (VP9BORDERINPIXELS - block_size - VP9_INTERP_EXTEND)); |
| 677 x->mv_col_max = ((cm->mb_cols - mb_col) * 16 + |
| 678 (VP9BORDERINPIXELS - block_size - VP9_INTERP_EXTEND)); |
| 679 |
| 680 // Set up distance of MB to edge of frame in 1/8th pel units |
| 681 block_size >>= 4; // in macroblock units |
| 682 assert(!(mb_col & (block_size - 1)) && !(mb_row & (block_size - 1))); |
| 683 xd->mb_to_top_edge = -((mb_row * 16) << 3); |
| 684 xd->mb_to_left_edge = -((mb_col * 16) << 3); |
| 685 xd->mb_to_bottom_edge = ((cm->mb_rows - block_size - mb_row) * 16) << 3; |
| 686 xd->mb_to_right_edge = ((cm->mb_cols - block_size - mb_col) * 16) << 3; |
| 687 |
| 688 // Are edges available for intra prediction? |
| 689 xd->up_available = (mb_row != 0); |
| 690 xd->left_available = (mb_col != 0); |
| 691 |
| 692 /* Reference buffer offsets */ |
| 693 *ref_yoffset = (mb_row * ref_y_stride * 16) + (mb_col * 16); |
| 694 *ref_uvoffset = (mb_row * ref_uv_stride * 8) + (mb_col * 8); |
| 695 |
| 696 /* set up source buffers */ |
| 697 x->src.y_buffer = cpi->Source->y_buffer + src_yoffset; |
| 698 x->src.u_buffer = cpi->Source->u_buffer + src_uvoffset; |
| 699 x->src.v_buffer = cpi->Source->v_buffer + src_uvoffset; |
| 700 |
| 701 /* R/D setup */ |
| 702 x->rddiv = cpi->RDDIV; |
| 703 x->rdmult = cpi->RDMULT; |
| 704 |
| 705 /* segment ID */ |
| 706 if (xd->segmentation_enabled) { |
| 707 if (xd->update_mb_segmentation_map) { |
| 708 mbmi->segment_id = find_seg_id(cpi->segmentation_map, block_size, |
| 709 mb_row, cm->mb_rows, mb_col, cm->mb_cols); |
| 710 } else { |
| 711 mbmi->segment_id = find_seg_id(cm->last_frame_seg_map, block_size, |
| 712 mb_row, cm->mb_rows, mb_col, cm->mb_cols); |
| 713 } |
| 714 assert(mbmi->segment_id <= 3); |
| 715 vp9_mb_init_quantizer(cpi, x); |
| 716 |
| 717 if (xd->segmentation_enabled && cpi->seg0_cnt > 0 && |
| 718 !vp9_segfeature_active(xd, 0, SEG_LVL_REF_FRAME) && |
| 719 vp9_segfeature_active(xd, 1, SEG_LVL_REF_FRAME) && |
| 720 vp9_check_segref(xd, 1, INTRA_FRAME) + |
| 721 vp9_check_segref(xd, 1, LAST_FRAME) + |
| 722 vp9_check_segref(xd, 1, GOLDEN_FRAME) + |
| 723 vp9_check_segref(xd, 1, ALTREF_FRAME) == 1) { |
| 724 cpi->seg0_progress = (cpi->seg0_idx << 16) / cpi->seg0_cnt; |
| 725 } else { |
| 726 const int y = mb_row & ~3; |
| 727 const int x = mb_col & ~3; |
| 728 const int p16 = ((mb_row & 1) << 1) + (mb_col & 1); |
| 729 const int p32 = ((mb_row & 2) << 2) + ((mb_col & 2) << 1); |
| 730 |
| 731 cpi->seg0_progress = |
| 732 ((y * cm->mb_cols + x * 4 + p32 + p16) << 16) / cm->MBs; |
| 733 } |
| 734 } else { |
| 735 mbmi->segment_id = 0; |
| 736 } |
| 737 } |
| 738 |
599 static void pick_mb_modes(VP9_COMP *cpi, | 739 static void pick_mb_modes(VP9_COMP *cpi, |
600 VP9_COMMON *cm, | |
601 int mb_row, | 740 int mb_row, |
602 int mb_col, | 741 int mb_col, |
603 MACROBLOCK *x, | |
604 MACROBLOCKD *xd, | |
605 TOKENEXTRA **tp, | 742 TOKENEXTRA **tp, |
606 int *totalrate, | 743 int *totalrate, |
607 int *totaldist) { | 744 int *totaldist) { |
| 745 VP9_COMMON *const cm = &cpi->common; |
| 746 MACROBLOCK *const x = &cpi->mb; |
| 747 MACROBLOCKD *const xd = &x->e_mbd; |
608 int i; | 748 int i; |
609 int map_index; | |
610 int recon_yoffset, recon_uvoffset; | 749 int recon_yoffset, recon_uvoffset; |
611 int ref_fb_idx = cm->lst_fb_idx; | |
612 int dst_fb_idx = cm->new_fb_idx; | |
613 int recon_y_stride = cm->yv12_fb[ref_fb_idx].y_stride; | |
614 int recon_uv_stride = cm->yv12_fb[ref_fb_idx].uv_stride; | |
615 ENTROPY_CONTEXT_PLANES left_context[2]; | 750 ENTROPY_CONTEXT_PLANES left_context[2]; |
616 ENTROPY_CONTEXT_PLANES above_context[2]; | 751 ENTROPY_CONTEXT_PLANES above_context[2]; |
617 ENTROPY_CONTEXT_PLANES *initial_above_context_ptr = cm->above_context | 752 ENTROPY_CONTEXT_PLANES *initial_above_context_ptr = cm->above_context |
618 + mb_col; | 753 + mb_col; |
619 | 754 |
620 // Offsets to move pointers from MB to MB within a SB in raster order | |
621 int row_delta[4] = { 0, +1, 0, -1}; | |
622 int col_delta[4] = { +1, -1, +1, +1}; | |
623 | |
624 /* Function should not modify L & A contexts; save and restore on exit */ | 755 /* Function should not modify L & A contexts; save and restore on exit */ |
625 vpx_memcpy(left_context, | 756 vpx_memcpy(left_context, |
626 cm->left_context, | 757 cm->left_context + (mb_row & 2), |
627 sizeof(left_context)); | 758 sizeof(left_context)); |
628 vpx_memcpy(above_context, | 759 vpx_memcpy(above_context, |
629 initial_above_context_ptr, | 760 initial_above_context_ptr, |
630 sizeof(above_context)); | 761 sizeof(above_context)); |
631 | 762 |
632 /* Encode MBs in raster order within the SB */ | 763 /* Encode MBs in raster order within the SB */ |
633 for (i = 0; i < 4; i++) { | 764 for (i = 0; i < 4; i++) { |
634 int dy = row_delta[i]; | 765 const int x_idx = i & 1, y_idx = i >> 1; |
635 int dx = col_delta[i]; | 766 MB_MODE_INFO *mbmi; |
636 int offset_unextended = dy * cm->mb_cols + dx; | |
637 int offset_extended = dy * xd->mode_info_stride + dx; | |
638 MB_MODE_INFO * mbmi = &xd->mode_info_context->mbmi; | |
639 | 767 |
640 // TODO Many of the index items here can be computed more efficiently! | 768 if ((mb_row + y_idx >= cm->mb_rows) || (mb_col + x_idx >= cm->mb_cols)) { |
641 | |
642 if ((mb_row >= cm->mb_rows) || (mb_col >= cm->mb_cols)) { | |
643 // MB lies outside frame, move on | 769 // MB lies outside frame, move on |
644 mb_row += dy; | |
645 mb_col += dx; | |
646 | |
647 // Update pointers | |
648 x->src.y_buffer += 16 * (dx + dy * x->src.y_stride); | |
649 x->src.u_buffer += 8 * (dx + dy * x->src.uv_stride); | |
650 x->src.v_buffer += 8 * (dx + dy * x->src.uv_stride); | |
651 | |
652 x->gf_active_ptr += offset_unextended; | |
653 x->partition_info += offset_extended; | |
654 xd->mode_info_context += offset_extended; | |
655 xd->prev_mode_info_context += offset_extended; | |
656 #if CONFIG_DEBUG | |
657 assert((xd->prev_mode_info_context - cpi->common.prev_mip) == | |
658 (xd->mode_info_context - cpi->common.mip)); | |
659 #endif | |
660 continue; | 770 continue; |
661 } | 771 } |
662 | 772 |
663 // Index of the MB in the SB 0..3 | 773 // Index of the MB in the SB 0..3 |
664 xd->mb_index = i; | 774 xd->mb_index = i; |
665 | 775 set_offsets(cpi, mb_row + y_idx, mb_col + x_idx, 16, |
666 map_index = (mb_row * cpi->common.mb_cols) + mb_col; | 776 &recon_yoffset, &recon_uvoffset); |
667 x->mb_activity_ptr = &cpi->mb_activity_map[map_index]; | |
668 | |
669 // set above context pointer | |
670 xd->above_context = cm->above_context + mb_col; | |
671 | |
672 // Restore the appropriate left context depending on which | |
673 // row in the SB the MB is situated | |
674 xd->left_context = cm->left_context + (i >> 1); | |
675 | |
676 // Set up distance of MB to edge of frame in 1/8th pel units | |
677 xd->mb_to_top_edge = -((mb_row * 16) << 3); | |
678 xd->mb_to_left_edge = -((mb_col * 16) << 3); | |
679 xd->mb_to_bottom_edge = ((cm->mb_rows - 1 - mb_row) * 16) << 3; | |
680 xd->mb_to_right_edge = ((cm->mb_cols - 1 - mb_col) * 16) << 3; | |
681 | |
682 // Set up limit values for MV components to prevent them from | |
683 // extending beyond the UMV borders assuming 16x16 block size | |
684 x->mv_row_min = -((mb_row * 16) + VP9BORDERINPIXELS - VP9_INTERP_EXTEND); | |
685 x->mv_col_min = -((mb_col * 16) + VP9BORDERINPIXELS - VP9_INTERP_EXTEND); | |
686 x->mv_row_max = ((cm->mb_rows - mb_row) * 16 + | |
687 (VP9BORDERINPIXELS - 16 - VP9_INTERP_EXTEND)); | |
688 x->mv_col_max = ((cm->mb_cols - mb_col) * 16 + | |
689 (VP9BORDERINPIXELS - 16 - VP9_INTERP_EXTEND)); | |
690 | |
691 xd->up_available = (mb_row != 0); | |
692 xd->left_available = (mb_col != 0); | |
693 | |
694 recon_yoffset = (mb_row * recon_y_stride * 16) + (mb_col * 16); | |
695 recon_uvoffset = (mb_row * recon_uv_stride * 8) + (mb_col * 8); | |
696 | |
697 xd->dst.y_buffer = cm->yv12_fb[dst_fb_idx].y_buffer + recon_yoffset; | |
698 xd->dst.u_buffer = cm->yv12_fb[dst_fb_idx].u_buffer + recon_uvoffset; | |
699 xd->dst.v_buffer = cm->yv12_fb[dst_fb_idx].v_buffer + recon_uvoffset; | |
700 | |
701 #if !CONFIG_SUPERBLOCKS | |
702 // Copy current MB to a work buffer | |
703 vp9_copy_mem16x16(x->src.y_buffer, x->src.y_stride, x->thismb, 16); | |
704 #endif | |
705 | |
706 x->rddiv = cpi->RDDIV; | |
707 x->rdmult = cpi->RDMULT; | |
708 | 777 |
709 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) | 778 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) |
710 vp9_activity_masking(cpi, x); | 779 vp9_activity_masking(cpi, x); |
711 | 780 |
712 // Is segmentation enabled | 781 mbmi = &xd->mode_info_context->mbmi; |
713 if (xd->segmentation_enabled) { | 782 mbmi->sb_type = BLOCK_SIZE_MB16X16; |
714 // Code to set segment id in xd->mbmi.segment_id | |
715 if (xd->update_mb_segmentation_map) | |
716 mbmi->segment_id = cpi->segmentation_map[map_index]; | |
717 else | |
718 mbmi->segment_id = cm->last_frame_seg_map[map_index]; | |
719 if (mbmi->segment_id > 3) | |
720 mbmi->segment_id = 0; | |
721 | |
722 vp9_mb_init_quantizer(cpi, x); | |
723 } else | |
724 // Set to Segment 0 by default | |
725 mbmi->segment_id = 0; | |
726 | |
727 x->active_ptr = cpi->active_map + map_index; | |
728 | |
729 #if CONFIG_SUPERBLOCKS | |
730 xd->mode_info_context->mbmi.encoded_as_sb = 0; | |
731 #endif | |
732 | 783 |
733 cpi->update_context = 0; // TODO Do we need this now?? | 784 cpi->update_context = 0; // TODO Do we need this now?? |
734 | 785 |
735 vp9_intra_prediction_down_copy(xd); | 786 vp9_intra_prediction_down_copy(xd); |
736 | 787 |
737 #ifdef ENC_DEBUG | |
738 enc_debug = (cpi->common.current_video_frame == 46 && | |
739 mb_row == 5 && mb_col == 2); | |
740 #endif | |
741 // Find best coding mode & reconstruct the MB so it is available | 788 // Find best coding mode & reconstruct the MB so it is available |
742 // as a predictor for MBs that follow in the SB | 789 // as a predictor for MBs that follow in the SB |
743 if (cm->frame_type == KEY_FRAME) { | 790 if (cm->frame_type == KEY_FRAME) { |
744 int r, d; | 791 int r, d; |
745 #ifdef ENC_DEBUG | 792 #ifdef ENC_DEBUG |
746 if (enc_debug) | 793 if (enc_debug) |
747 printf("intra pick_mb_modes %d %d\n", mb_row, mb_col); | 794 printf("intra pick_mb_modes %d %d\n", mb_row, mb_col); |
748 #endif | 795 #endif |
749 vp9_rd_pick_intra_mode(cpi, x, &r, &d); | 796 vp9_rd_pick_intra_mode(cpi, x, &r, &d); |
750 *totalrate += r; | 797 *totalrate += r; |
751 *totaldist += d; | 798 *totaldist += d; |
752 | 799 |
753 // Dummy encode, do not do the tokenization | 800 // Dummy encode, do not do the tokenization |
754 encode_macroblock(cpi, x, tp, | 801 encode_macroblock(cpi, tp, recon_yoffset, recon_uvoffset, 0, |
755 recon_yoffset, recon_uvoffset, 0, mb_col, mb_row); | 802 mb_row + y_idx, mb_col + x_idx); |
756 // Note the encoder may have changed the segment_id | 803 // Note the encoder may have changed the segment_id |
757 | 804 |
758 // Save the coding context | 805 // Save the coding context |
759 vpx_memcpy(&x->mb_context[i].mic, xd->mode_info_context, | 806 vpx_memcpy(&x->mb_context[xd->sb_index][i].mic, xd->mode_info_context, |
760 sizeof(MODE_INFO)); | 807 sizeof(MODE_INFO)); |
761 } else { | 808 } else { |
762 int seg_id, r, d; | 809 int seg_id, r, d; |
763 | 810 |
764 if (xd->segmentation_enabled && cpi->seg0_cnt > 0 && | |
765 !vp9_segfeature_active(xd, 0, SEG_LVL_REF_FRAME) && | |
766 vp9_segfeature_active(xd, 1, SEG_LVL_REF_FRAME) && | |
767 vp9_check_segref(xd, 1, INTRA_FRAME) + | |
768 vp9_check_segref(xd, 1, LAST_FRAME) + | |
769 vp9_check_segref(xd, 1, GOLDEN_FRAME) + | |
770 vp9_check_segref(xd, 1, ALTREF_FRAME) == 1) { | |
771 cpi->seg0_progress = (cpi->seg0_idx << 16) / cpi->seg0_cnt; | |
772 } else { | |
773 cpi->seg0_progress = (((mb_col & ~1) * 2 + (mb_row & ~1) * cm->mb_cols +
i) << 16) / cm->MBs; | |
774 } | |
775 | |
776 #ifdef ENC_DEBUG | 811 #ifdef ENC_DEBUG |
777 if (enc_debug) | 812 if (enc_debug) |
778 printf("inter pick_mb_modes %d %d\n", mb_row, mb_col); | 813 printf("inter pick_mb_modes %d %d\n", mb_row, mb_col); |
779 #endif | 814 #endif |
780 vp9_pick_mode_inter_macroblock(cpi, x, recon_yoffset, | 815 vp9_pick_mode_inter_macroblock(cpi, x, recon_yoffset, |
781 recon_uvoffset, &r, &d); | 816 recon_uvoffset, &r, &d); |
782 *totalrate += r; | 817 *totalrate += r; |
783 *totaldist += d; | 818 *totaldist += d; |
784 | 819 |
785 // Dummy encode, do not do the tokenization | 820 // Dummy encode, do not do the tokenization |
786 encode_macroblock(cpi, x, tp, | 821 encode_macroblock(cpi, tp, recon_yoffset, recon_uvoffset, 0, |
787 recon_yoffset, recon_uvoffset, 0, mb_col, mb_row); | 822 mb_row + y_idx, mb_col + x_idx); |
788 | 823 |
789 seg_id = mbmi->segment_id; | 824 seg_id = mbmi->segment_id; |
790 if (cpi->mb.e_mbd.segmentation_enabled && seg_id == 0) { | 825 if (cpi->mb.e_mbd.segmentation_enabled && seg_id == 0) { |
791 cpi->seg0_idx++; | 826 cpi->seg0_idx++; |
792 } | 827 } |
793 if (!xd->segmentation_enabled || | 828 if (!xd->segmentation_enabled || |
794 !vp9_segfeature_active(xd, seg_id, SEG_LVL_REF_FRAME) || | 829 !vp9_segfeature_active(xd, seg_id, SEG_LVL_REF_FRAME) || |
795 vp9_check_segref(xd, seg_id, INTRA_FRAME) + | 830 vp9_check_segref(xd, seg_id, INTRA_FRAME) + |
796 vp9_check_segref(xd, seg_id, LAST_FRAME) + | 831 vp9_check_segref(xd, seg_id, LAST_FRAME) + |
797 vp9_check_segref(xd, seg_id, GOLDEN_FRAME) + | 832 vp9_check_segref(xd, seg_id, GOLDEN_FRAME) + |
798 vp9_check_segref(xd, seg_id, ALTREF_FRAME) > 1) { | 833 vp9_check_segref(xd, seg_id, ALTREF_FRAME) > 1) { |
799 // Get the prediction context and status | 834 // Get the prediction context and status |
800 int pred_flag = vp9_get_pred_flag(xd, PRED_REF); | 835 int pred_flag = vp9_get_pred_flag(xd, PRED_REF); |
801 int pred_context = vp9_get_pred_context(cm, xd, PRED_REF); | 836 int pred_context = vp9_get_pred_context(cm, xd, PRED_REF); |
802 | 837 |
803 // Count prediction success | 838 // Count prediction success |
804 cpi->ref_pred_count[pred_context][pred_flag]++; | 839 cpi->ref_pred_count[pred_context][pred_flag]++; |
805 } | 840 } |
806 } | 841 } |
807 | |
808 // Next MB | |
809 mb_row += dy; | |
810 mb_col += dx; | |
811 | |
812 x->src.y_buffer += 16 * (dx + dy * x->src.y_stride); | |
813 x->src.u_buffer += 8 * (dx + dy * x->src.uv_stride); | |
814 x->src.v_buffer += 8 * (dx + dy * x->src.uv_stride); | |
815 | |
816 x->gf_active_ptr += offset_unextended; | |
817 x->partition_info += offset_extended; | |
818 xd->mode_info_context += offset_extended; | |
819 xd->prev_mode_info_context += offset_extended; | |
820 | |
821 #if CONFIG_DEBUG | |
822 assert((xd->prev_mode_info_context - cpi->common.prev_mip) == | |
823 (xd->mode_info_context - cpi->common.mip)); | |
824 #endif | |
825 } | 842 } |
826 | 843 |
827 /* Restore L & A coding context to those in place on entry */ | 844 /* Restore L & A coding context to those in place on entry */ |
828 vpx_memcpy(cm->left_context, | 845 vpx_memcpy(cm->left_context + (mb_row & 2), |
829 left_context, | 846 left_context, |
830 sizeof(left_context)); | 847 sizeof(left_context)); |
831 vpx_memcpy(initial_above_context_ptr, | 848 vpx_memcpy(initial_above_context_ptr, |
832 above_context, | 849 above_context, |
833 sizeof(above_context)); | 850 sizeof(above_context)); |
834 } | 851 } |
835 | 852 |
836 #if CONFIG_SUPERBLOCKS | 853 static void pick_sb_modes(VP9_COMP *cpi, |
837 static void pick_sb_modes (VP9_COMP *cpi, | 854 int mb_row, |
838 VP9_COMMON *cm, | 855 int mb_col, |
839 int mb_row, | 856 TOKENEXTRA **tp, |
840 int mb_col, | 857 int *totalrate, |
841 MACROBLOCK *x, | 858 int *totaldist) { |
842 MACROBLOCKD *xd, | 859 VP9_COMMON *const cm = &cpi->common; |
843 TOKENEXTRA **tp, | 860 MACROBLOCK *const x = &cpi->mb; |
844 int *totalrate, | 861 MACROBLOCKD *const xd = &x->e_mbd; |
845 int *totaldist) | |
846 { | |
847 int map_index; | |
848 int recon_yoffset, recon_uvoffset; | 862 int recon_yoffset, recon_uvoffset; |
849 int ref_fb_idx = cm->lst_fb_idx; | |
850 int dst_fb_idx = cm->new_fb_idx; | |
851 int recon_y_stride = cm->yv12_fb[ref_fb_idx].y_stride; | |
852 int recon_uv_stride = cm->yv12_fb[ref_fb_idx].uv_stride; | |
853 ENTROPY_CONTEXT_PLANES left_context[2]; | |
854 ENTROPY_CONTEXT_PLANES above_context[2]; | |
855 ENTROPY_CONTEXT_PLANES *initial_above_context_ptr = cm->above_context | |
856 + mb_col; | |
857 | 863 |
858 /* Function should not modify L & A contexts; save and restore on exit */ | 864 set_offsets(cpi, mb_row, mb_col, 32, &recon_yoffset, &recon_uvoffset); |
859 vpx_memcpy (left_context, | 865 xd->mode_info_context->mbmi.sb_type = BLOCK_SIZE_SB32X32; |
860 cm->left_context, | 866 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) |
861 sizeof(left_context)); | |
862 vpx_memcpy (above_context, | |
863 initial_above_context_ptr, | |
864 sizeof(above_context)); | |
865 | |
866 map_index = (mb_row * cpi->common.mb_cols) + mb_col; | |
867 x->mb_activity_ptr = &cpi->mb_activity_map[map_index]; | |
868 | |
869 /* set above context pointer */ | |
870 xd->above_context = cm->above_context + mb_col; | |
871 | |
872 /* Restore the appropriate left context depending on which | |
873 * row in the SB the MB is situated */ | |
874 xd->left_context = cm->left_context; | |
875 | |
876 // Set up distance of MB to edge of frame in 1/8th pel units | |
877 xd->mb_to_top_edge = -((mb_row * 16) << 3); | |
878 xd->mb_to_left_edge = -((mb_col * 16) << 3); | |
879 xd->mb_to_bottom_edge = ((cm->mb_rows - 2 - mb_row) * 16) << 3; | |
880 xd->mb_to_right_edge = ((cm->mb_cols - 2 - mb_col) * 16) << 3; | |
881 | |
882 /* Set up limit values for MV components to prevent them from | |
883 * extending beyond the UMV borders assuming 16x16 block size */ | |
884 x->mv_row_min = -((mb_row * 16) + VP9BORDERINPIXELS - VP9_INTERP_EXTEND); | |
885 x->mv_col_min = -((mb_col * 16) + VP9BORDERINPIXELS - VP9_INTERP_EXTEND); | |
886 x->mv_row_max = ((cm->mb_rows - mb_row) * 16 + | |
887 (VP9BORDERINPIXELS - 32 - VP9_INTERP_EXTEND)); | |
888 x->mv_col_max = ((cm->mb_cols - mb_col) * 16 + | |
889 (VP9BORDERINPIXELS - 32 - VP9_INTERP_EXTEND)); | |
890 | |
891 xd->up_available = (mb_row != 0); | |
892 xd->left_available = (mb_col != 0); | |
893 | |
894 recon_yoffset = (mb_row * recon_y_stride * 16) + (mb_col * 16); | |
895 recon_uvoffset = (mb_row * recon_uv_stride * 8) + (mb_col * 8); | |
896 | |
897 xd->dst.y_buffer = cm->yv12_fb[dst_fb_idx].y_buffer + recon_yoffset; | |
898 xd->dst.u_buffer = cm->yv12_fb[dst_fb_idx].u_buffer + recon_uvoffset; | |
899 xd->dst.v_buffer = cm->yv12_fb[dst_fb_idx].v_buffer + recon_uvoffset; | |
900 #if 0 // FIXME | |
901 /* Copy current MB to a work buffer */ | |
902 vp9_copy_mem16x16(x->src.y_buffer, x->src.y_stride, x->thismb, 16); | |
903 #endif | |
904 x->rddiv = cpi->RDDIV; | |
905 x->rdmult = cpi->RDMULT; | |
906 if(cpi->oxcf.tuning == VP8_TUNE_SSIM) | |
907 vp9_activity_masking(cpi, x); | 867 vp9_activity_masking(cpi, x); |
908 /* Is segmentation enabled */ | |
909 if (xd->segmentation_enabled) | |
910 { | |
911 /* Code to set segment id in xd->mbmi.segment_id */ | |
912 if (xd->update_mb_segmentation_map) | |
913 xd->mode_info_context->mbmi.segment_id = | |
914 cpi->segmentation_map[map_index] && | |
915 cpi->segmentation_map[map_index + 1] && | |
916 cpi->segmentation_map[map_index + cm->mb_cols] && | |
917 cpi->segmentation_map[map_index + cm->mb_cols + 1]; | |
918 else | |
919 xd->mode_info_context->mbmi.segment_id = | |
920 cm->last_frame_seg_map[map_index] && | |
921 cm->last_frame_seg_map[map_index + 1] && | |
922 cm->last_frame_seg_map[map_index + cm->mb_cols] && | |
923 cm->last_frame_seg_map[map_index + cm->mb_cols + 1]; | |
924 if (xd->mode_info_context->mbmi.segment_id > 3) | |
925 xd->mode_info_context->mbmi.segment_id = 0; | |
926 | |
927 vp9_mb_init_quantizer(cpi, x); | |
928 } | |
929 else | |
930 /* Set to Segment 0 by default */ | |
931 xd->mode_info_context->mbmi.segment_id = 0; | |
932 | |
933 x->active_ptr = cpi->active_map + map_index; | |
934 | |
935 cpi->update_context = 0; // TODO Do we need this now?? | 868 cpi->update_context = 0; // TODO Do we need this now?? |
936 | 869 |
937 /* Find best coding mode & reconstruct the MB so it is available | 870 /* Find best coding mode & reconstruct the MB so it is available |
938 * as a predictor for MBs that follow in the SB */ | 871 * as a predictor for MBs that follow in the SB */ |
939 if (cm->frame_type == KEY_FRAME) | 872 if (cm->frame_type == KEY_FRAME) { |
940 { | 873 vp9_rd_pick_intra_mode_sb32(cpi, x, |
941 vp9_rd_pick_intra_mode_sb(cpi, x, | 874 totalrate, |
942 totalrate, | 875 totaldist); |
943 totaldist); | |
944 | 876 |
945 /* Save the coding context */ | 877 /* Save the coding context */ |
946 vpx_memcpy(&x->sb_context[0].mic, xd->mode_info_context, | 878 vpx_memcpy(&x->sb32_context[xd->sb_index].mic, xd->mode_info_context, |
947 sizeof(MODE_INFO)); | 879 sizeof(MODE_INFO)); |
948 } else { | 880 } else { |
949 if (xd->segmentation_enabled && cpi->seg0_cnt > 0 && | 881 vp9_rd_pick_inter_mode_sb32(cpi, x, |
950 !vp9_segfeature_active(xd, 0, SEG_LVL_REF_FRAME) && | 882 recon_yoffset, |
951 vp9_segfeature_active(xd, 1, SEG_LVL_REF_FRAME) && | 883 recon_uvoffset, |
952 vp9_check_segref(xd, 1, INTRA_FRAME) + | 884 totalrate, |
953 vp9_check_segref(xd, 1, LAST_FRAME) + | 885 totaldist); |
954 vp9_check_segref(xd, 1, GOLDEN_FRAME) + | 886 } |
955 vp9_check_segref(xd, 1, ALTREF_FRAME) == 1) { | 887 } |
956 cpi->seg0_progress = (cpi->seg0_idx << 16) / cpi->seg0_cnt; | 888 |
957 } else { | 889 static void pick_sb64_modes(VP9_COMP *cpi, |
958 cpi->seg0_progress = | 890 int mb_row, |
959 (((mb_col & ~1) * 2 + (mb_row & ~1) * cm->mb_cols) << 16) / cm->MBs; | 891 int mb_col, |
| 892 TOKENEXTRA **tp, |
| 893 int *totalrate, |
| 894 int *totaldist) { |
| 895 VP9_COMMON *const cm = &cpi->common; |
| 896 MACROBLOCK *const x = &cpi->mb; |
| 897 MACROBLOCKD *const xd = &x->e_mbd; |
| 898 int recon_yoffset, recon_uvoffset; |
| 899 |
| 900 set_offsets(cpi, mb_row, mb_col, 64, &recon_yoffset, &recon_uvoffset); |
| 901 xd->mode_info_context->mbmi.sb_type = BLOCK_SIZE_SB64X64; |
| 902 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) |
| 903 vp9_activity_masking(cpi, x); |
| 904 cpi->update_context = 0; // TODO(rbultje) Do we need this now?? |
| 905 |
| 906 /* Find best coding mode & reconstruct the MB so it is available |
| 907 * as a predictor for MBs that follow in the SB */ |
| 908 if (cm->frame_type == KEY_FRAME) { |
| 909 vp9_rd_pick_intra_mode_sb64(cpi, x, |
| 910 totalrate, |
| 911 totaldist); |
| 912 |
| 913 /* Save the coding context */ |
| 914 vpx_memcpy(&x->sb64_context.mic, xd->mode_info_context, |
| 915 sizeof(MODE_INFO)); |
| 916 } else { |
| 917 vp9_rd_pick_inter_mode_sb64(cpi, x, |
| 918 recon_yoffset, |
| 919 recon_uvoffset, |
| 920 totalrate, |
| 921 totaldist); |
| 922 } |
| 923 } |
| 924 |
| 925 static void update_stats(VP9_COMP *cpi) { |
| 926 VP9_COMMON *const cm = &cpi->common; |
| 927 MACROBLOCK *const x = &cpi->mb; |
| 928 MACROBLOCKD *const xd = &x->e_mbd; |
| 929 MODE_INFO *mi = xd->mode_info_context; |
| 930 MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 931 |
| 932 if (cm->frame_type == KEY_FRAME) { |
| 933 #ifdef MODE_STATS |
| 934 y_modes[mbmi->mode]++; |
| 935 #endif |
| 936 } else { |
| 937 int segment_id, seg_ref_active; |
| 938 |
| 939 if (mbmi->ref_frame) { |
| 940 int pred_context = vp9_get_pred_context(cm, xd, PRED_COMP); |
| 941 |
| 942 if (mbmi->second_ref_frame <= INTRA_FRAME) |
| 943 cpi->single_pred_count[pred_context]++; |
| 944 else |
| 945 cpi->comp_pred_count[pred_context]++; |
960 } | 946 } |
961 | 947 |
962 vp9_rd_pick_inter_mode_sb(cpi, x, | 948 #ifdef MODE_STATS |
963 recon_yoffset, | 949 inter_y_modes[mbmi->mode]++; |
964 recon_uvoffset, | |
965 totalrate, | |
966 totaldist); | |
967 } | |
968 | 950 |
969 /* Restore L & A coding context to those in place on entry */ | 951 if (mbmi->mode == SPLITMV) { |
970 vpx_memcpy (cm->left_context, | 952 int b; |
971 left_context, | |
972 sizeof(left_context)); | |
973 vpx_memcpy (initial_above_context_ptr, | |
974 above_context, | |
975 sizeof(above_context)); | |
976 } | |
977 #endif | |
978 | 953 |
979 static void encode_sb(VP9_COMP *cpi, | 954 for (b = 0; b < x->partition_info->count; b++) { |
980 VP9_COMMON *cm, | 955 inter_b_modes[x->partition_info->bmi[b].mode]++; |
981 int mbrow, | 956 } |
982 int mbcol, | |
983 MACROBLOCK *x, | |
984 MACROBLOCKD *xd, | |
985 TOKENEXTRA **tp) { | |
986 int i; | |
987 int map_index; | |
988 int mb_row, mb_col; | |
989 int recon_yoffset, recon_uvoffset; | |
990 int ref_fb_idx = cm->lst_fb_idx; | |
991 int dst_fb_idx = cm->new_fb_idx; | |
992 int recon_y_stride = cm->yv12_fb[ref_fb_idx].y_stride; | |
993 int recon_uv_stride = cm->yv12_fb[ref_fb_idx].uv_stride; | |
994 int row_delta[4] = { 0, +1, 0, -1}; | |
995 int col_delta[4] = { +1, -1, +1, +1}; | |
996 | |
997 mb_row = mbrow; | |
998 mb_col = mbcol; | |
999 | |
1000 /* Encode MBs in raster order within the SB */ | |
1001 for (i = 0; i < 4; i++) { | |
1002 int dy = row_delta[i]; | |
1003 int dx = col_delta[i]; | |
1004 int offset_extended = dy * xd->mode_info_stride + dx; | |
1005 int offset_unextended = dy * cm->mb_cols + dx; | |
1006 MB_MODE_INFO * mbmi = &xd->mode_info_context->mbmi; | |
1007 | |
1008 if ((mb_row >= cm->mb_rows) || (mb_col >= cm->mb_cols)) { | |
1009 // MB lies outside frame, move on | |
1010 mb_row += dy; | |
1011 mb_col += dx; | |
1012 | |
1013 x->src.y_buffer += 16 * (dx + dy * x->src.y_stride); | |
1014 x->src.u_buffer += 8 * (dx + dy * x->src.uv_stride); | |
1015 x->src.v_buffer += 8 * (dx + dy * x->src.uv_stride); | |
1016 | |
1017 x->gf_active_ptr += offset_unextended; | |
1018 x->partition_info += offset_extended; | |
1019 xd->mode_info_context += offset_extended; | |
1020 xd->prev_mode_info_context += offset_extended; | |
1021 | |
1022 #if CONFIG_DEBUG | |
1023 assert((xd->prev_mode_info_context - cpi->common.prev_mip) == | |
1024 (xd->mode_info_context - cpi->common.mip)); | |
1025 #endif | |
1026 continue; | |
1027 } | |
1028 | |
1029 xd->mb_index = i; | |
1030 | |
1031 // Restore MB state to that when it was picked | |
1032 #if CONFIG_SUPERBLOCKS | |
1033 if (xd->mode_info_context->mbmi.encoded_as_sb) { | |
1034 update_state(cpi, x, &x->sb_context[i]); | |
1035 cpi->sb_count++; | |
1036 } else | |
1037 #endif | |
1038 update_state(cpi, x, &x->mb_context[i]); | |
1039 | |
1040 map_index = (mb_row * cpi->common.mb_cols) + mb_col; | |
1041 x->mb_activity_ptr = &cpi->mb_activity_map[map_index]; | |
1042 | |
1043 // reset above block coeffs | |
1044 xd->above_context = cm->above_context + mb_col; | |
1045 xd->left_context = cm->left_context + (i >> 1); | |
1046 | |
1047 // Set up distance of MB to edge of the frame in 1/8th pel units | |
1048 // Set up limit values for MV components to prevent them from | |
1049 // extending beyond the UMV borders assuming 32x32 block size | |
1050 x->mv_row_min = -((mb_row * 16) + VP9BORDERINPIXELS - VP9_INTERP_EXTEND); | |
1051 x->mv_col_min = -((mb_col * 16) + VP9BORDERINPIXELS - VP9_INTERP_EXTEND); | |
1052 | |
1053 xd->mb_to_top_edge = -((mb_row * 16) << 3); | |
1054 xd->mb_to_left_edge = -((mb_col * 16) << 3); | |
1055 | |
1056 #if CONFIG_SUPERBLOCKS | |
1057 if (xd->mode_info_context->mbmi.encoded_as_sb) { | |
1058 x->mv_row_max = ((cm->mb_rows - mb_row) * 16 + | |
1059 (VP9BORDERINPIXELS - 32 - VP9_INTERP_EXTEND)); | |
1060 x->mv_col_max = ((cm->mb_cols - mb_col) * 16 + | |
1061 (VP9BORDERINPIXELS - 32 - VP9_INTERP_EXTEND)); | |
1062 | |
1063 xd->mb_to_bottom_edge = ((cm->mb_rows - 2 - mb_row) * 16) << 3; | |
1064 xd->mb_to_right_edge = ((cm->mb_cols - 2 - mb_col) * 16) << 3; | |
1065 } else { | |
1066 #endif | |
1067 x->mv_row_max = ((cm->mb_rows - mb_row) * 16 + | |
1068 (VP9BORDERINPIXELS - 16 - VP9_INTERP_EXTEND)); | |
1069 x->mv_col_max = ((cm->mb_cols - mb_col) * 16 + | |
1070 (VP9BORDERINPIXELS - 16 - VP9_INTERP_EXTEND)); | |
1071 | |
1072 xd->mb_to_bottom_edge = ((cm->mb_rows - 1 - mb_row) * 16) << 3; | |
1073 xd->mb_to_right_edge = ((cm->mb_cols - 1 - mb_col) * 16) << 3; | |
1074 #if CONFIG_SUPERBLOCKS | |
1075 } | 957 } |
1076 #endif | 958 #endif |
1077 | 959 |
1078 xd->up_available = (mb_row != 0); | 960 // If we have just a single reference frame coded for a segment then |
1079 xd->left_available = (mb_col != 0); | 961 // exclude from the reference frame counts used to work out |
| 962 // probabilities. NOTE: At the moment we dont support custom trees |
| 963 // for the reference frame coding for each segment but this is a |
| 964 // possible future action. |
| 965 segment_id = mbmi->segment_id; |
| 966 seg_ref_active = vp9_segfeature_active(xd, segment_id, |
| 967 SEG_LVL_REF_FRAME); |
| 968 if (!seg_ref_active || |
| 969 ((vp9_check_segref(xd, segment_id, INTRA_FRAME) + |
| 970 vp9_check_segref(xd, segment_id, LAST_FRAME) + |
| 971 vp9_check_segref(xd, segment_id, GOLDEN_FRAME) + |
| 972 vp9_check_segref(xd, segment_id, ALTREF_FRAME)) > 1)) { |
| 973 cpi->count_mb_ref_frame_usage[mbmi->ref_frame]++; |
| 974 } |
| 975 // Count of last ref frame 0,0 usage |
| 976 if ((mbmi->mode == ZEROMV) && (mbmi->ref_frame == LAST_FRAME)) |
| 977 cpi->inter_zz_count++; |
| 978 } |
| 979 } |
1080 | 980 |
1081 recon_yoffset = (mb_row * recon_y_stride * 16) + (mb_col * 16); | 981 static void encode_sb(VP9_COMP *cpi, |
1082 recon_uvoffset = (mb_row * recon_uv_stride * 8) + (mb_col * 8); | 982 int mb_row, |
| 983 int mb_col, |
| 984 int output_enabled, |
| 985 TOKENEXTRA **tp, int is_sb) { |
| 986 VP9_COMMON *const cm = &cpi->common; |
| 987 MACROBLOCK *const x = &cpi->mb; |
| 988 MACROBLOCKD *const xd = &x->e_mbd; |
| 989 int recon_yoffset, recon_uvoffset; |
1083 | 990 |
1084 xd->dst.y_buffer = cm->yv12_fb[dst_fb_idx].y_buffer + recon_yoffset; | 991 cpi->sb32_count[is_sb]++; |
1085 xd->dst.u_buffer = cm->yv12_fb[dst_fb_idx].u_buffer + recon_uvoffset; | 992 if (is_sb) { |
1086 xd->dst.v_buffer = cm->yv12_fb[dst_fb_idx].v_buffer + recon_uvoffset; | 993 set_offsets(cpi, mb_row, mb_col, 32, &recon_yoffset, &recon_uvoffset); |
| 994 update_state(cpi, &x->sb32_context[xd->sb_index], 32, output_enabled); |
1087 | 995 |
1088 #if !CONFIG_SUPERBLOCKS | 996 encode_superblock32(cpi, tp, recon_yoffset, recon_uvoffset, |
1089 // Copy current MB to a work buffer | 997 output_enabled, mb_row, mb_col); |
1090 vp9_copy_mem16x16(x->src.y_buffer, x->src.y_stride, x->thismb, 16); | 998 if (output_enabled) |
1091 #endif | 999 update_stats(cpi); |
1092 | 1000 |
1093 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) | 1001 if (output_enabled) { |
1094 vp9_activity_masking(cpi, x); | 1002 (*tp)->Token = EOSB_TOKEN; |
| 1003 (*tp)++; |
| 1004 if (mb_row < cm->mb_rows) |
| 1005 cpi->tplist[mb_row].stop = *tp; |
| 1006 } |
| 1007 } else { |
| 1008 int i; |
1095 | 1009 |
1096 // Is segmentation enabled | 1010 for (i = 0; i < 4; i++) { |
1097 if (xd->segmentation_enabled) { | 1011 const int x_idx = i & 1, y_idx = i >> 1; |
1098 vp9_mb_init_quantizer(cpi, x); | |
1099 } | |
1100 | 1012 |
1101 x->active_ptr = cpi->active_map + map_index; | 1013 if ((mb_row + y_idx >= cm->mb_rows) || (mb_col + x_idx >= cm->mb_cols)) { |
| 1014 // MB lies outside frame, move on |
| 1015 continue; |
| 1016 } |
1102 | 1017 |
1103 cpi->update_context = 0; | 1018 set_offsets(cpi, mb_row + y_idx, mb_col + x_idx, 16, |
| 1019 &recon_yoffset, &recon_uvoffset); |
| 1020 xd->mb_index = i; |
| 1021 update_state(cpi, &x->mb_context[xd->sb_index][i], 16, output_enabled); |
1104 | 1022 |
1105 #if CONFIG_SUPERBLOCKS | 1023 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) |
1106 if (!xd->mode_info_context->mbmi.encoded_as_sb) | 1024 vp9_activity_masking(cpi, x); |
1107 #endif | 1025 |
1108 vp9_intra_prediction_down_copy(xd); | 1026 vp9_intra_prediction_down_copy(xd); |
1109 | 1027 |
1110 if (cm->frame_type == KEY_FRAME) { | 1028 encode_macroblock(cpi, tp, recon_yoffset, recon_uvoffset, |
1111 #if CONFIG_SUPERBLOCKS | 1029 output_enabled, mb_row + y_idx, mb_col + x_idx); |
1112 if (xd->mode_info_context->mbmi.encoded_as_sb) | 1030 if (output_enabled) |
1113 encode_superblock(cpi, x, tp, recon_yoffset, recon_uvoffset, | 1031 update_stats(cpi); |
1114 mb_col, mb_row); | |
1115 else | |
1116 #endif | |
1117 encode_macroblock(cpi, x, tp, recon_yoffset, recon_uvoffset, 1, | |
1118 mb_col, mb_row); | |
1119 // Note the encoder may have changed the segment_id | |
1120 | 1032 |
1121 #ifdef MODE_STATS | 1033 if (output_enabled) { |
1122 y_modes[mbmi->mode]++; | 1034 (*tp)->Token = EOSB_TOKEN; |
1123 #endif | 1035 (*tp)++; |
1124 } else { | 1036 if (mb_row + y_idx < cm->mb_rows) |
1125 unsigned char *segment_id; | 1037 cpi->tplist[mb_row + y_idx].stop = *tp; |
1126 int seg_ref_active; | |
1127 | |
1128 if (xd->mode_info_context->mbmi.ref_frame) { | |
1129 unsigned char pred_context; | |
1130 | |
1131 pred_context = vp9_get_pred_context(cm, xd, PRED_COMP); | |
1132 | |
1133 if (xd->mode_info_context->mbmi.second_ref_frame <= INTRA_FRAME) | |
1134 cpi->single_pred_count[pred_context]++; | |
1135 else | |
1136 cpi->comp_pred_count[pred_context]++; | |
1137 } | 1038 } |
1138 | |
1139 #if CONFIG_SUPERBLOCKS | |
1140 if (xd->mode_info_context->mbmi.encoded_as_sb) | |
1141 encode_superblock(cpi, x, tp, recon_yoffset, recon_uvoffset, | |
1142 mb_col, mb_row); | |
1143 else | |
1144 #endif | |
1145 encode_macroblock(cpi, x, tp, recon_yoffset, recon_uvoffset, 1, | |
1146 mb_col, mb_row); | |
1147 // Note the encoder may have changed the segment_id | |
1148 | |
1149 #ifdef MODE_STATS | |
1150 inter_y_modes[mbmi->mode]++; | |
1151 | |
1152 if (mbmi->mode == SPLITMV) { | |
1153 int b; | |
1154 | |
1155 for (b = 0; b < x->partition_info->count; b++) { | |
1156 inter_b_modes[x->partition_info->bmi[b].mode]++; | |
1157 } | |
1158 } | |
1159 | |
1160 #endif | |
1161 | |
1162 // If we have just a single reference frame coded for a segment then | |
1163 // exclude from the reference frame counts used to work out | |
1164 // probabilities. NOTE: At the moment we dont support custom trees | |
1165 // for the reference frame coding for each segment but this is a | |
1166 // possible future action. | |
1167 segment_id = &mbmi->segment_id; | |
1168 seg_ref_active = vp9_segfeature_active(xd, *segment_id, | |
1169 SEG_LVL_REF_FRAME); | |
1170 if (!seg_ref_active || | |
1171 ((vp9_check_segref(xd, *segment_id, INTRA_FRAME) + | |
1172 vp9_check_segref(xd, *segment_id, LAST_FRAME) + | |
1173 vp9_check_segref(xd, *segment_id, GOLDEN_FRAME) + | |
1174 vp9_check_segref(xd, *segment_id, ALTREF_FRAME)) > 1)) { | |
1175 { | |
1176 cpi->count_mb_ref_frame_usage[mbmi->ref_frame]++; | |
1177 } | |
1178 } | |
1179 | |
1180 // Count of last ref frame 0,0 usage | |
1181 if ((mbmi->mode == ZEROMV) && (mbmi->ref_frame == LAST_FRAME)) | |
1182 cpi->inter_zz_count++; | |
1183 } | 1039 } |
1184 | |
1185 #if CONFIG_SUPERBLOCKS | |
1186 if (xd->mode_info_context->mbmi.encoded_as_sb) { | |
1187 x->src.y_buffer += 32; | |
1188 x->src.u_buffer += 16; | |
1189 x->src.v_buffer += 16; | |
1190 | |
1191 x->gf_active_ptr += 2; | |
1192 x->partition_info += 2; | |
1193 xd->mode_info_context += 2; | |
1194 xd->prev_mode_info_context += 2; | |
1195 | |
1196 (*tp)->Token = EOSB_TOKEN; | |
1197 (*tp)++; | |
1198 if (mb_row < cm->mb_rows) cpi->tplist[mb_row].stop = *tp; | |
1199 break; | |
1200 } | |
1201 #endif | |
1202 | |
1203 // Next MB | |
1204 mb_row += dy; | |
1205 mb_col += dx; | |
1206 | |
1207 x->src.y_buffer += 16 * (dx + dy * x->src.y_stride); | |
1208 x->src.u_buffer += 8 * (dx + dy * x->src.uv_stride); | |
1209 x->src.v_buffer += 8 * (dx + dy * x->src.uv_stride); | |
1210 | |
1211 x->gf_active_ptr += offset_unextended; | |
1212 x->partition_info += offset_extended; | |
1213 xd->mode_info_context += offset_extended; | |
1214 xd->prev_mode_info_context += offset_extended; | |
1215 | |
1216 #if CONFIG_DEBUG | |
1217 assert((xd->prev_mode_info_context - cpi->common.prev_mip) == | |
1218 (xd->mode_info_context - cpi->common.mip)); | |
1219 #endif | |
1220 (*tp)->Token = EOSB_TOKEN; | |
1221 (*tp)++; | |
1222 if (mb_row < cm->mb_rows) cpi->tplist[mb_row].stop = *tp; | |
1223 } | 1040 } |
1224 | 1041 |
1225 // debug output | 1042 // debug output |
1226 #if DBG_PRNT_SEGMAP | 1043 #if DBG_PRNT_SEGMAP |
1227 { | 1044 { |
1228 FILE *statsfile; | 1045 FILE *statsfile; |
1229 statsfile = fopen("segmap2.stt", "a"); | 1046 statsfile = fopen("segmap2.stt", "a"); |
1230 fprintf(statsfile, "\n"); | 1047 fprintf(statsfile, "\n"); |
1231 fclose(statsfile); | 1048 fclose(statsfile); |
1232 } | 1049 } |
1233 #endif | 1050 #endif |
1234 } | 1051 } |
1235 | 1052 |
1236 static | 1053 static void encode_sb64(VP9_COMP *cpi, |
1237 void encode_sb_row(VP9_COMP *cpi, | 1054 int mb_row, |
1238 VP9_COMMON *cm, | 1055 int mb_col, |
1239 int mb_row, | 1056 TOKENEXTRA **tp, int is_sb[4]) { |
1240 MACROBLOCK *x, | 1057 VP9_COMMON *const cm = &cpi->common; |
1241 MACROBLOCKD *xd, | 1058 MACROBLOCK *const x = &cpi->mb; |
1242 TOKENEXTRA **tp, | 1059 MACROBLOCKD *const xd = &x->e_mbd; |
1243 int *totalrate) { | 1060 |
| 1061 cpi->sb64_count[is_sb[0] == 2]++; |
| 1062 if (is_sb[0] == 2) { |
| 1063 int recon_yoffset, recon_uvoffset; |
| 1064 |
| 1065 set_offsets(cpi, mb_row, mb_col, 64, &recon_yoffset, &recon_uvoffset); |
| 1066 update_state(cpi, &x->sb64_context, 64, 1); |
| 1067 encode_superblock64(cpi, tp, recon_yoffset, recon_uvoffset, |
| 1068 1, mb_row, mb_col); |
| 1069 update_stats(cpi); |
| 1070 |
| 1071 (*tp)->Token = EOSB_TOKEN; |
| 1072 (*tp)++; |
| 1073 if (mb_row < cm->mb_rows) |
| 1074 cpi->tplist[mb_row].stop = *tp; |
| 1075 } else { |
| 1076 int i; |
| 1077 |
| 1078 for (i = 0; i < 4; i++) { |
| 1079 const int x_idx = i & 1, y_idx = i >> 1; |
| 1080 |
| 1081 if (mb_row + y_idx * 2 >= cm->mb_rows || |
| 1082 mb_col + x_idx * 2 >= cm->mb_cols) { |
| 1083 // MB lies outside frame, move on |
| 1084 continue; |
| 1085 } |
| 1086 xd->sb_index = i; |
| 1087 encode_sb(cpi, mb_row + 2 * y_idx, mb_col + 2 * x_idx, 1, tp, |
| 1088 is_sb[i]); |
| 1089 } |
| 1090 } |
| 1091 } |
| 1092 |
| 1093 static void encode_sb_row(VP9_COMP *cpi, |
| 1094 int mb_row, |
| 1095 TOKENEXTRA **tp, |
| 1096 int *totalrate) { |
| 1097 VP9_COMMON *const cm = &cpi->common; |
| 1098 MACROBLOCK *const x = &cpi->mb; |
| 1099 MACROBLOCKD *const xd = &x->e_mbd; |
1244 int mb_col; | 1100 int mb_col; |
1245 int mb_cols = cm->mb_cols; | 1101 int mb_cols = cm->mb_cols; |
1246 | 1102 |
1247 // Initialize the left context for the new SB row | 1103 // Initialize the left context for the new SB row |
1248 vpx_memset(cm->left_context, 0, sizeof(cm->left_context)); | 1104 vpx_memset(cm->left_context, 0, sizeof(cm->left_context)); |
1249 | 1105 |
1250 // Code each SB in the row | 1106 // Code each SB in the row |
1251 for (mb_col = 0; mb_col < mb_cols; mb_col += 2) { | 1107 for (mb_col = 0; mb_col < mb_cols; mb_col += 4) { |
1252 int mb_rate = 0, mb_dist = 0; | 1108 int i; |
1253 #if CONFIG_SUPERBLOCKS | 1109 int sb32_rate = 0, sb32_dist = 0; |
1254 int sb_rate = INT_MAX, sb_dist; | 1110 int is_sb[4]; |
1255 #endif | 1111 int sb64_rate = INT_MAX, sb64_dist; |
| 1112 ENTROPY_CONTEXT_PLANES l[4], a[4]; |
| 1113 TOKENEXTRA *tp_orig = *tp; |
1256 | 1114 |
1257 #if CONFIG_DEBUG | 1115 memcpy(&a, cm->above_context + mb_col, sizeof(a)); |
1258 MODE_INFO *mic = xd->mode_info_context; | 1116 memcpy(&l, cm->left_context, sizeof(l)); |
1259 PARTITION_INFO *pi = x->partition_info; | 1117 for (i = 0; i < 4; i++) { |
1260 signed char *gfa = x->gf_active_ptr; | 1118 const int x_idx = (i & 1) << 1, y_idx = i & 2; |
1261 unsigned char *yb = x->src.y_buffer; | 1119 int mb_rate = 0, mb_dist = 0; |
1262 unsigned char *ub = x->src.u_buffer; | 1120 int sb_rate = INT_MAX, sb_dist; |
1263 unsigned char *vb = x->src.v_buffer; | |
1264 #endif | |
1265 | 1121 |
1266 #if CONFIG_SUPERBLOCKS | 1122 if (mb_row + y_idx >= cm->mb_rows || mb_col + x_idx >= cm->mb_cols) |
1267 // Pick modes assuming the SB is coded as 4 independent MBs | 1123 continue; |
1268 xd->mode_info_context->mbmi.encoded_as_sb = 0; | |
1269 #endif | |
1270 pick_mb_modes(cpi, cm, mb_row, mb_col, x, xd, tp, &mb_rate, &mb_dist); | |
1271 #if CONFIG_SUPERBLOCKS | |
1272 mb_rate += vp9_cost_bit(cm->sb_coded, 0); | |
1273 #endif | |
1274 | 1124 |
1275 x->src.y_buffer -= 32; | 1125 xd->sb_index = i; |
1276 x->src.u_buffer -= 16; | |
1277 x->src.v_buffer -= 16; | |
1278 | 1126 |
1279 x->gf_active_ptr -= 2; | 1127 pick_mb_modes(cpi, mb_row + y_idx, mb_col + x_idx, |
1280 x->partition_info -= 2; | 1128 tp, &mb_rate, &mb_dist); |
1281 xd->mode_info_context -= 2; | 1129 mb_rate += vp9_cost_bit(cm->sb32_coded, 0); |
1282 xd->prev_mode_info_context -= 2; | |
1283 | 1130 |
1284 #if CONFIG_DEBUG | 1131 if (!((( mb_cols & 1) && mb_col + x_idx == mb_cols - 1) || |
1285 assert(x->gf_active_ptr == gfa); | 1132 ((cm->mb_rows & 1) && mb_row + y_idx == cm->mb_rows - 1))) { |
1286 assert(x->partition_info == pi); | 1133 /* Pick a mode assuming that it applies to all 4 of the MBs in the SB */ |
1287 assert(xd->mode_info_context == mic); | 1134 pick_sb_modes(cpi, mb_row + y_idx, mb_col + x_idx, |
1288 assert(x->src.y_buffer == yb); | 1135 tp, &sb_rate, &sb_dist); |
1289 assert(x->src.u_buffer == ub); | 1136 sb_rate += vp9_cost_bit(cm->sb32_coded, 1); |
1290 assert(x->src.v_buffer == vb); | 1137 } |
1291 #endif | |
1292 | 1138 |
1293 #if CONFIG_SUPERBLOCKS | 1139 /* Decide whether to encode as a SB or 4xMBs */ |
1294 if (!((( mb_cols & 1) && mb_col == mb_cols - 1) || | 1140 if (sb_rate < INT_MAX && |
1295 ((cm->mb_rows & 1) && mb_row == cm->mb_rows - 1))) { | 1141 RDCOST(x->rdmult, x->rddiv, sb_rate, sb_dist) < |
1296 /* Pick a mode assuming that it applies to all 4 of the MBs in the SB */ | 1142 RDCOST(x->rdmult, x->rddiv, mb_rate, mb_dist)) { |
1297 xd->mode_info_context->mbmi.encoded_as_sb = 1; | 1143 is_sb[i] = 1; |
1298 pick_sb_modes(cpi, cm, mb_row, mb_col, x, xd, tp, &sb_rate, &sb_dist); | 1144 sb32_rate += sb_rate; |
1299 sb_rate += vp9_cost_bit(cm->sb_coded, 1); | 1145 sb32_dist += sb_dist; |
| 1146 } else { |
| 1147 is_sb[i] = 0; |
| 1148 sb32_rate += mb_rate; |
| 1149 sb32_dist += mb_dist; |
| 1150 } |
| 1151 |
| 1152 /* Encode SB using best computed mode(s) */ |
| 1153 // FIXME(rbultje): there really shouldn't be any need to encode_mb/sb |
| 1154 // for each level that we go up, we can just keep tokens and recon |
| 1155 // pixels of the lower level; also, inverting SB/MB order (big->small |
| 1156 // instead of small->big) means we can use as threshold for small, which |
| 1157 // may enable breakouts if RD is not good enough (i.e. faster) |
| 1158 encode_sb(cpi, mb_row + y_idx, mb_col + x_idx, 0, tp, is_sb[i]); |
| 1159 } |
| 1160 |
| 1161 memcpy(cm->above_context + mb_col, &a, sizeof(a)); |
| 1162 memcpy(cm->left_context, &l, sizeof(l)); |
| 1163 sb32_rate += vp9_cost_bit(cm->sb64_coded, 0); |
| 1164 |
| 1165 if (!((( mb_cols & 3) && mb_col + 3 >= mb_cols) || |
| 1166 ((cm->mb_rows & 3) && mb_row + 3 >= cm->mb_rows))) { |
| 1167 pick_sb64_modes(cpi, mb_row, mb_col, tp, &sb64_rate, &sb64_dist); |
| 1168 sb64_rate += vp9_cost_bit(cm->sb64_coded, 1); |
1300 } | 1169 } |
1301 | 1170 |
1302 /* Decide whether to encode as a SB or 4xMBs */ | 1171 /* Decide whether to encode as a SB or 4xMBs */ |
1303 if (sb_rate < INT_MAX && | 1172 if (sb64_rate < INT_MAX && |
1304 RDCOST(x->rdmult, x->rddiv, sb_rate, sb_dist) < | 1173 RDCOST(x->rdmult, x->rddiv, sb64_rate, sb64_dist) < |
1305 RDCOST(x->rdmult, x->rddiv, mb_rate, mb_dist)) { | 1174 RDCOST(x->rdmult, x->rddiv, sb32_rate, sb32_dist)) { |
1306 xd->mode_info_context->mbmi.encoded_as_sb = 1; | 1175 is_sb[0] = 2; |
1307 xd->mode_info_context[1].mbmi.encoded_as_sb = 1; | 1176 *totalrate += sb64_rate; |
1308 xd->mode_info_context[cm->mode_info_stride].mbmi.encoded_as_sb = 1; | 1177 } else { |
1309 xd->mode_info_context[1 + cm->mode_info_stride].mbmi.encoded_as_sb = 1; | 1178 *totalrate += sb32_rate; |
1310 *totalrate += sb_rate; | |
1311 } else | |
1312 #endif | |
1313 { | |
1314 #if CONFIG_SUPERBLOCKS | |
1315 xd->mode_info_context->mbmi.encoded_as_sb = 0; | |
1316 if (cm->mb_cols - 1 > mb_col) | |
1317 xd->mode_info_context[1].mbmi.encoded_as_sb = 0; | |
1318 if (cm->mb_rows - 1 > mb_row) { | |
1319 xd->mode_info_context[cm->mode_info_stride].mbmi.encoded_as_sb = 0; | |
1320 if (cm->mb_cols - 1 > mb_col) | |
1321 xd->mode_info_context[1 + cm->mode_info_stride].mbmi.encoded_as_sb = 0
; | |
1322 } | |
1323 #endif | |
1324 *totalrate += mb_rate; | |
1325 } | 1179 } |
1326 | 1180 |
1327 /* Encode SB using best computed mode(s) */ | 1181 assert(tp_orig == *tp); |
1328 encode_sb(cpi, cm, mb_row, mb_col, x, xd, tp); | 1182 encode_sb64(cpi, mb_row, mb_col, tp, is_sb); |
1329 | 1183 assert(tp_orig < *tp); |
1330 #if CONFIG_DEBUG | |
1331 assert(x->gf_active_ptr == gfa + 2); | |
1332 assert(x->partition_info == pi + 2); | |
1333 assert(xd->mode_info_context == mic + 2); | |
1334 assert(x->src.y_buffer == yb + 32); | |
1335 assert(x->src.u_buffer == ub + 16); | |
1336 assert(x->src.v_buffer == vb + 16); | |
1337 #endif | |
1338 } | 1184 } |
1339 | |
1340 // this is to account for the border | |
1341 x->gf_active_ptr += mb_cols - (mb_cols & 0x1); | |
1342 x->partition_info += xd->mode_info_stride + 1 - (mb_cols & 0x1); | |
1343 xd->mode_info_context += xd->mode_info_stride + 1 - (mb_cols & 0x1); | |
1344 xd->prev_mode_info_context += xd->mode_info_stride + 1 - (mb_cols & 0x1); | |
1345 | |
1346 #if CONFIG_DEBUG | |
1347 assert((xd->prev_mode_info_context - cpi->common.prev_mip) == | |
1348 (xd->mode_info_context - cpi->common.mip)); | |
1349 #endif | |
1350 } | 1185 } |
1351 | 1186 |
1352 static void init_encode_frame_mb_context(VP9_COMP *cpi) { | 1187 static void init_encode_frame_mb_context(VP9_COMP *cpi) { |
1353 MACROBLOCK *const x = &cpi->mb; | 1188 MACROBLOCK *const x = &cpi->mb; |
1354 VP9_COMMON *const cm = &cpi->common; | 1189 VP9_COMMON *const cm = &cpi->common; |
1355 MACROBLOCKD *const xd = &x->e_mbd; | 1190 MACROBLOCKD *const xd = &x->e_mbd; |
1356 | 1191 |
1357 // GF active flags data structure | |
1358 x->gf_active_ptr = (signed char *)cpi->gf_active_flags; | |
1359 | |
1360 // Activity map pointer | |
1361 x->mb_activity_ptr = cpi->mb_activity_map; | |
1362 | |
1363 x->act_zbin_adj = 0; | 1192 x->act_zbin_adj = 0; |
1364 cpi->seg0_idx = 0; | 1193 cpi->seg0_idx = 0; |
1365 vpx_memset(cpi->ref_pred_count, 0, sizeof(cpi->ref_pred_count)); | 1194 vpx_memset(cpi->ref_pred_count, 0, sizeof(cpi->ref_pred_count)); |
1366 | 1195 |
1367 x->partition_info = x->pi; | |
1368 | |
1369 xd->mode_info_context = cm->mi; | |
1370 xd->mode_info_stride = cm->mode_info_stride; | 1196 xd->mode_info_stride = cm->mode_info_stride; |
1371 xd->prev_mode_info_context = cm->prev_mi; | |
1372 | |
1373 xd->frame_type = cm->frame_type; | 1197 xd->frame_type = cm->frame_type; |
1374 | 1198 |
1375 xd->frames_since_golden = cm->frames_since_golden; | 1199 xd->frames_since_golden = cm->frames_since_golden; |
1376 xd->frames_till_alt_ref_frame = cm->frames_till_alt_ref_frame; | 1200 xd->frames_till_alt_ref_frame = cm->frames_till_alt_ref_frame; |
1377 | 1201 |
1378 // reset intra mode contexts | 1202 // reset intra mode contexts |
1379 if (cm->frame_type == KEY_FRAME) | 1203 if (cm->frame_type == KEY_FRAME) |
1380 vp9_init_mbmode_probs(cm); | 1204 vp9_init_mbmode_probs(cm); |
1381 | 1205 |
1382 // Copy data over into macro block data structures. | 1206 // Copy data over into macro block data structures. |
1383 x->src = * cpi->Source; | 1207 x->src = *cpi->Source; |
1384 xd->pre = cm->yv12_fb[cm->lst_fb_idx]; | 1208 xd->pre = cm->yv12_fb[cm->lst_fb_idx]; |
1385 xd->dst = cm->yv12_fb[cm->new_fb_idx]; | 1209 xd->dst = cm->yv12_fb[cm->new_fb_idx]; |
1386 | 1210 |
1387 // set up frame for intra coded blocks | 1211 // set up frame for intra coded blocks |
1388 vp9_setup_intra_recon(&cm->yv12_fb[cm->new_fb_idx]); | 1212 vp9_setup_intra_recon(&cm->yv12_fb[cm->new_fb_idx]); |
1389 | 1213 |
1390 vp9_build_block_offsets(x); | 1214 vp9_build_block_offsets(x); |
1391 | 1215 |
1392 vp9_setup_block_dptrs(&x->e_mbd); | 1216 vp9_setup_block_dptrs(&x->e_mbd); |
1393 | 1217 |
1394 vp9_setup_block_ptrs(x); | 1218 vp9_setup_block_ptrs(x); |
1395 | 1219 |
1396 xd->mode_info_context->mbmi.mode = DC_PRED; | 1220 xd->mode_info_context->mbmi.mode = DC_PRED; |
1397 xd->mode_info_context->mbmi.uv_mode = DC_PRED; | 1221 xd->mode_info_context->mbmi.uv_mode = DC_PRED; |
1398 | 1222 |
1399 vp9_zero(cpi->count_mb_ref_frame_usage) | 1223 vp9_zero(cpi->count_mb_ref_frame_usage) |
1400 vp9_zero(cpi->bmode_count) | 1224 vp9_zero(cpi->bmode_count) |
1401 vp9_zero(cpi->ymode_count) | 1225 vp9_zero(cpi->ymode_count) |
1402 vp9_zero(cpi->i8x8_mode_count) | 1226 vp9_zero(cpi->i8x8_mode_count) |
1403 vp9_zero(cpi->y_uv_mode_count) | 1227 vp9_zero(cpi->y_uv_mode_count) |
1404 vp9_zero(cpi->sub_mv_ref_count) | 1228 vp9_zero(cpi->sub_mv_ref_count) |
1405 vp9_zero(cpi->mbsplit_count) | 1229 vp9_zero(cpi->mbsplit_count) |
1406 vp9_zero(cpi->common.fc.mv_ref_ct) | 1230 vp9_zero(cpi->common.fc.mv_ref_ct) |
1407 #if CONFIG_SUPERBLOCKS | |
1408 vp9_zero(cpi->sb_ymode_count) | 1231 vp9_zero(cpi->sb_ymode_count) |
1409 cpi->sb_count = 0; | 1232 vp9_zero(cpi->sb32_count); |
1410 #endif | 1233 vp9_zero(cpi->sb64_count); |
1411 #if CONFIG_COMP_INTERINTRA_PRED | 1234 #if CONFIG_COMP_INTERINTRA_PRED |
1412 vp9_zero(cpi->interintra_count); | 1235 vp9_zero(cpi->interintra_count); |
1413 vp9_zero(cpi->interintra_select_count); | 1236 vp9_zero(cpi->interintra_select_count); |
1414 #endif | 1237 #endif |
1415 | 1238 |
1416 vpx_memset(cm->above_context, 0, | 1239 vpx_memset(cm->above_context, 0, |
1417 sizeof(ENTROPY_CONTEXT_PLANES) * cm->mb_cols); | 1240 sizeof(ENTROPY_CONTEXT_PLANES) * cm->mb_cols); |
1418 | 1241 |
1419 xd->fullpixel_mask = 0xffffffff; | 1242 xd->fullpixel_mask = 0xffffffff; |
1420 if (cm->full_pixel) | 1243 if (cm->full_pixel) |
(...skipping 10 matching lines...) Expand all Loading... |
1431 int totalrate; | 1254 int totalrate; |
1432 | 1255 |
1433 // printf("encode_frame_internal frame %d (%d)\n", | 1256 // printf("encode_frame_internal frame %d (%d)\n", |
1434 // cpi->common.current_video_frame, cpi->common.show_frame); | 1257 // cpi->common.current_video_frame, cpi->common.show_frame); |
1435 | 1258 |
1436 // Compute a modified set of reference frame probabilities to use when | 1259 // Compute a modified set of reference frame probabilities to use when |
1437 // prediction fails. These are based on the current general estimates for | 1260 // prediction fails. These are based on the current general estimates for |
1438 // this frame which may be updated with each iteration of the recode loop. | 1261 // this frame which may be updated with each iteration of the recode loop. |
1439 vp9_compute_mod_refprobs(cm); | 1262 vp9_compute_mod_refprobs(cm); |
1440 | 1263 |
1441 #if CONFIG_NEW_MVREF | |
1442 // temp stats reset | |
1443 vp9_zero( cpi->best_ref_index_counts ); | |
1444 #endif | |
1445 | |
1446 // debug output | 1264 // debug output |
1447 #if DBG_PRNT_SEGMAP | 1265 #if DBG_PRNT_SEGMAP |
1448 { | 1266 { |
1449 FILE *statsfile; | 1267 FILE *statsfile; |
1450 statsfile = fopen("segmap2.stt", "a"); | 1268 statsfile = fopen("segmap2.stt", "a"); |
1451 fprintf(statsfile, "\n"); | 1269 fprintf(statsfile, "\n"); |
1452 fclose(statsfile); | 1270 fclose(statsfile); |
1453 } | 1271 } |
1454 #endif | 1272 #endif |
1455 | 1273 |
1456 totalrate = 0; | 1274 totalrate = 0; |
1457 | 1275 |
1458 // Functions setup for all frame types so we can use MC in AltRef | 1276 // Functions setup for all frame types so we can use MC in AltRef |
1459 vp9_setup_interp_filters(xd, cm->mcomp_filter_type, cm); | 1277 vp9_setup_interp_filters(xd, cm->mcomp_filter_type, cm); |
1460 | 1278 |
1461 // Reset frame count of inter 0,0 motion vector usage. | 1279 // Reset frame count of inter 0,0 motion vector usage. |
1462 cpi->inter_zz_count = 0; | 1280 cpi->inter_zz_count = 0; |
1463 | 1281 |
1464 cpi->prediction_error = 0; | 1282 cpi->prediction_error = 0; |
1465 cpi->intra_error = 0; | 1283 cpi->intra_error = 0; |
1466 cpi->skip_true_count[0] = cpi->skip_true_count[1] = cpi->skip_true_count[2] =
0; | 1284 cpi->skip_true_count[0] = cpi->skip_true_count[1] = cpi->skip_true_count[2] =
0; |
1467 cpi->skip_false_count[0] = cpi->skip_false_count[1] = cpi->skip_false_count[2]
= 0; | 1285 cpi->skip_false_count[0] = cpi->skip_false_count[1] = cpi->skip_false_count[2]
= 0; |
1468 | 1286 |
1469 #if CONFIG_PRED_FILTER | |
1470 if (cm->current_video_frame == 0) { | |
1471 // Initially assume that we'll signal the prediction filter | |
1472 // state at the frame level and that it is off. | |
1473 cpi->common.pred_filter_mode = 0; | |
1474 cpi->common.prob_pred_filter_off = 128; | |
1475 } | |
1476 cpi->pred_filter_on_count = 0; | |
1477 cpi->pred_filter_off_count = 0; | |
1478 #endif | |
1479 vp9_zero(cpi->switchable_interp_count); | 1287 vp9_zero(cpi->switchable_interp_count); |
| 1288 vp9_zero(cpi->best_switchable_interp_count); |
1480 | 1289 |
1481 xd->mode_info_context = cm->mi; | 1290 xd->mode_info_context = cm->mi; |
1482 xd->prev_mode_info_context = cm->prev_mi; | 1291 xd->prev_mode_info_context = cm->prev_mi; |
1483 | 1292 |
1484 vp9_zero(cpi->NMVcount); | 1293 vp9_zero(cpi->NMVcount); |
1485 vp9_zero(cpi->coef_counts); | 1294 vp9_zero(cpi->coef_counts_4x4); |
1486 vp9_zero(cpi->hybrid_coef_counts); | 1295 vp9_zero(cpi->hybrid_coef_counts_4x4); |
1487 vp9_zero(cpi->coef_counts_8x8); | 1296 vp9_zero(cpi->coef_counts_8x8); |
1488 vp9_zero(cpi->hybrid_coef_counts_8x8); | 1297 vp9_zero(cpi->hybrid_coef_counts_8x8); |
1489 vp9_zero(cpi->coef_counts_16x16); | 1298 vp9_zero(cpi->coef_counts_16x16); |
1490 vp9_zero(cpi->hybrid_coef_counts_16x16); | 1299 vp9_zero(cpi->hybrid_coef_counts_16x16); |
| 1300 vp9_zero(cpi->coef_counts_32x32); |
| 1301 #if CONFIG_NEW_MVREF |
| 1302 vp9_zero(cpi->mb_mv_ref_count); |
| 1303 #endif |
1491 | 1304 |
1492 vp9_frame_init_quantizer(cpi); | 1305 vp9_frame_init_quantizer(cpi); |
1493 | 1306 |
1494 vp9_initialize_rd_consts(cpi, cm->base_qindex + cm->y1dc_delta_q); | 1307 vp9_initialize_rd_consts(cpi, cm->base_qindex + cm->y1dc_delta_q); |
1495 vp9_initialize_me_consts(cpi, cm->base_qindex); | 1308 vp9_initialize_me_consts(cpi, cm->base_qindex); |
1496 | 1309 |
1497 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { | 1310 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { |
1498 // Initialize encode frame context. | 1311 // Initialize encode frame context. |
1499 init_encode_frame_mb_context(cpi); | 1312 init_encode_frame_mb_context(cpi); |
1500 | 1313 |
1501 // Build a frame level activity map | 1314 // Build a frame level activity map |
1502 build_activity_map(cpi); | 1315 build_activity_map(cpi); |
1503 } | 1316 } |
1504 | 1317 |
1505 // re-initencode frame context. | 1318 // re-initencode frame context. |
1506 init_encode_frame_mb_context(cpi); | 1319 init_encode_frame_mb_context(cpi); |
1507 | 1320 |
1508 vpx_memset(cpi->rd_comp_pred_diff, 0, sizeof(cpi->rd_comp_pred_diff)); | 1321 vpx_memset(cpi->rd_comp_pred_diff, 0, sizeof(cpi->rd_comp_pred_diff)); |
1509 vpx_memset(cpi->single_pred_count, 0, sizeof(cpi->single_pred_count)); | 1322 vpx_memset(cpi->single_pred_count, 0, sizeof(cpi->single_pred_count)); |
1510 vpx_memset(cpi->comp_pred_count, 0, sizeof(cpi->comp_pred_count)); | 1323 vpx_memset(cpi->comp_pred_count, 0, sizeof(cpi->comp_pred_count)); |
1511 vpx_memset(cpi->txfm_count, 0, sizeof(cpi->txfm_count)); | 1324 vpx_memset(cpi->txfm_count_32x32p, 0, sizeof(cpi->txfm_count_32x32p)); |
| 1325 vpx_memset(cpi->txfm_count_16x16p, 0, sizeof(cpi->txfm_count_16x16p)); |
1512 vpx_memset(cpi->txfm_count_8x8p, 0, sizeof(cpi->txfm_count_8x8p)); | 1326 vpx_memset(cpi->txfm_count_8x8p, 0, sizeof(cpi->txfm_count_8x8p)); |
1513 vpx_memset(cpi->rd_tx_select_diff, 0, sizeof(cpi->rd_tx_select_diff)); | 1327 vpx_memset(cpi->rd_tx_select_diff, 0, sizeof(cpi->rd_tx_select_diff)); |
1514 { | 1328 { |
1515 struct vpx_usec_timer emr_timer; | 1329 struct vpx_usec_timer emr_timer; |
1516 vpx_usec_timer_start(&emr_timer); | 1330 vpx_usec_timer_start(&emr_timer); |
1517 | 1331 |
1518 { | 1332 { |
1519 // For each row of SBs in the frame | 1333 // For each row of SBs in the frame |
1520 for (mb_row = 0; mb_row < cm->mb_rows; mb_row += 2) { | 1334 for (mb_row = 0; mb_row < cm->mb_rows; mb_row += 4) { |
1521 int offset = (cm->mb_cols + 1) & ~0x1; | 1335 encode_sb_row(cpi, mb_row, &tp, &totalrate); |
1522 | |
1523 encode_sb_row(cpi, cm, mb_row, x, xd, &tp, &totalrate); | |
1524 | |
1525 // adjust to the next row of SBs | |
1526 x->src.y_buffer += 32 * x->src.y_stride - 16 * offset; | |
1527 x->src.u_buffer += 16 * x->src.uv_stride - 8 * offset; | |
1528 x->src.v_buffer += 16 * x->src.uv_stride - 8 * offset; | |
1529 } | 1336 } |
1530 | 1337 |
1531 cpi->tok_count = (unsigned int)(tp - cpi->tok); | 1338 cpi->tok_count = (unsigned int)(tp - cpi->tok); |
1532 } | 1339 } |
1533 | 1340 |
1534 vpx_usec_timer_mark(&emr_timer); | 1341 vpx_usec_timer_mark(&emr_timer); |
1535 cpi->time_encode_mb_row += vpx_usec_timer_elapsed(&emr_timer); | 1342 cpi->time_encode_mb_row += vpx_usec_timer_elapsed(&emr_timer); |
1536 | 1343 |
1537 } | 1344 } |
1538 | 1345 |
(...skipping 24 matching lines...) Expand all Loading... |
1563 vp9_check_segref(xd, 1, ALTREF_FRAME)) | 1370 vp9_check_segref(xd, 1, ALTREF_FRAME)) |
1564 return 1; | 1371 return 1; |
1565 return 0; | 1372 return 0; |
1566 } else { | 1373 } else { |
1567 return (!!(ref_flags & VP9_GOLD_FLAG) + | 1374 return (!!(ref_flags & VP9_GOLD_FLAG) + |
1568 !!(ref_flags & VP9_LAST_FLAG) + | 1375 !!(ref_flags & VP9_LAST_FLAG) + |
1569 !!(ref_flags & VP9_ALT_FLAG)) >= 2; | 1376 !!(ref_flags & VP9_ALT_FLAG)) >= 2; |
1570 } | 1377 } |
1571 } | 1378 } |
1572 | 1379 |
| 1380 static void reset_skip_txfm_size_mb(VP9_COMP *cpi, |
| 1381 MODE_INFO *mi, TX_SIZE txfm_max) { |
| 1382 MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 1383 |
| 1384 if (mbmi->txfm_size > txfm_max) { |
| 1385 VP9_COMMON *const cm = &cpi->common; |
| 1386 MACROBLOCK *const x = &cpi->mb; |
| 1387 MACROBLOCKD *const xd = &x->e_mbd; |
| 1388 const int segment_id = mbmi->segment_id; |
| 1389 |
| 1390 xd->mode_info_context = mi; |
| 1391 assert((vp9_segfeature_active(xd, segment_id, SEG_LVL_EOB) && |
| 1392 vp9_get_segdata(xd, segment_id, SEG_LVL_EOB) == 0) || |
| 1393 (cm->mb_no_coeff_skip && mbmi->mb_skip_coeff)); |
| 1394 mbmi->txfm_size = txfm_max; |
| 1395 } |
| 1396 } |
| 1397 |
| 1398 static int get_skip_flag(MODE_INFO *mi, int mis, int ymbs, int xmbs) { |
| 1399 int x, y; |
| 1400 |
| 1401 for (y = 0; y < ymbs; y++) { |
| 1402 for (x = 0; x < xmbs; x++) { |
| 1403 if (!mi[y * mis + x].mbmi.mb_skip_coeff) |
| 1404 return 0; |
| 1405 } |
| 1406 } |
| 1407 |
| 1408 return 1; |
| 1409 } |
| 1410 |
| 1411 static void set_txfm_flag(MODE_INFO *mi, int mis, int ymbs, int xmbs, |
| 1412 TX_SIZE txfm_size) { |
| 1413 int x, y; |
| 1414 |
| 1415 for (y = 0; y < ymbs; y++) { |
| 1416 for (x = 0; x < xmbs; x++) { |
| 1417 mi[y * mis + x].mbmi.txfm_size = txfm_size; |
| 1418 } |
| 1419 } |
| 1420 } |
| 1421 |
| 1422 static void reset_skip_txfm_size_sb32(VP9_COMP *cpi, MODE_INFO *mi, |
| 1423 int mis, TX_SIZE txfm_max, |
| 1424 int mb_rows_left, int mb_cols_left) { |
| 1425 MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 1426 |
| 1427 if (mbmi->txfm_size > txfm_max) { |
| 1428 VP9_COMMON *const cm = &cpi->common; |
| 1429 MACROBLOCK *const x = &cpi->mb; |
| 1430 MACROBLOCKD *const xd = &x->e_mbd; |
| 1431 const int segment_id = mbmi->segment_id; |
| 1432 const int ymbs = MIN(2, mb_rows_left); |
| 1433 const int xmbs = MIN(2, mb_cols_left); |
| 1434 |
| 1435 xd->mode_info_context = mi; |
| 1436 assert((vp9_segfeature_active(xd, segment_id, SEG_LVL_EOB) && |
| 1437 vp9_get_segdata(xd, segment_id, SEG_LVL_EOB) == 0) || |
| 1438 (cm->mb_no_coeff_skip && get_skip_flag(mi, mis, ymbs, xmbs))); |
| 1439 set_txfm_flag(mi, mis, ymbs, xmbs, txfm_max); |
| 1440 } |
| 1441 } |
| 1442 |
| 1443 static void reset_skip_txfm_size_sb64(VP9_COMP *cpi, MODE_INFO *mi, |
| 1444 int mis, TX_SIZE txfm_max, |
| 1445 int mb_rows_left, int mb_cols_left) { |
| 1446 MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 1447 |
| 1448 if (mbmi->txfm_size > txfm_max) { |
| 1449 VP9_COMMON *const cm = &cpi->common; |
| 1450 MACROBLOCK *const x = &cpi->mb; |
| 1451 MACROBLOCKD *const xd = &x->e_mbd; |
| 1452 const int segment_id = mbmi->segment_id; |
| 1453 const int ymbs = MIN(4, mb_rows_left); |
| 1454 const int xmbs = MIN(4, mb_cols_left); |
| 1455 |
| 1456 xd->mode_info_context = mi; |
| 1457 assert((vp9_segfeature_active(xd, segment_id, SEG_LVL_EOB) && |
| 1458 vp9_get_segdata(xd, segment_id, SEG_LVL_EOB) == 0) || |
| 1459 (cm->mb_no_coeff_skip && get_skip_flag(mi, mis, ymbs, xmbs))); |
| 1460 set_txfm_flag(mi, mis, ymbs, xmbs, txfm_max); |
| 1461 } |
| 1462 } |
| 1463 |
1573 static void reset_skip_txfm_size(VP9_COMP *cpi, TX_SIZE txfm_max) { | 1464 static void reset_skip_txfm_size(VP9_COMP *cpi, TX_SIZE txfm_max) { |
1574 VP9_COMMON *cm = &cpi->common; | 1465 VP9_COMMON *const cm = &cpi->common; |
1575 int mb_row, mb_col, mis = cm->mode_info_stride, segment_id; | 1466 int mb_row, mb_col; |
| 1467 const int mis = cm->mode_info_stride; |
1576 MODE_INFO *mi, *mi_ptr = cm->mi; | 1468 MODE_INFO *mi, *mi_ptr = cm->mi; |
1577 #if CONFIG_SUPERBLOCKS | |
1578 int skip; | |
1579 MODE_INFO *sb_mi_ptr = cm->mi, *sb_mi; | |
1580 MB_MODE_INFO *sb_mbmi; | |
1581 #endif | |
1582 MB_MODE_INFO *mbmi; | |
1583 MACROBLOCK *x = &cpi->mb; | |
1584 MACROBLOCKD *xd = &x->e_mbd; | |
1585 | 1469 |
1586 for (mb_row = 0; mb_row < cm->mb_rows; mb_row++, mi_ptr += mis) { | 1470 for (mb_row = 0; mb_row < cm->mb_rows; mb_row += 4, mi_ptr += 4 * mis) { |
1587 mi = mi_ptr; | 1471 mi = mi_ptr; |
1588 #if CONFIG_SUPERBLOCKS | 1472 for (mb_col = 0; mb_col < cm->mb_cols; mb_col += 4, mi += 4) { |
1589 sb_mi = sb_mi_ptr; | 1473 if (mi->mbmi.sb_type == BLOCK_SIZE_SB64X64) { |
1590 #endif | 1474 reset_skip_txfm_size_sb64(cpi, mi, mis, txfm_max, |
1591 for (mb_col = 0; mb_col < cm->mb_cols; mb_col++, mi++) { | 1475 cm->mb_rows - mb_row, cm->mb_cols - mb_col); |
1592 mbmi = &mi->mbmi; | 1476 } else { |
1593 #if CONFIG_SUPERBLOCKS | 1477 int i; |
1594 sb_mbmi = &sb_mi->mbmi; | 1478 |
1595 #endif | 1479 for (i = 0; i < 4; i++) { |
1596 if (mbmi->txfm_size > txfm_max) { | 1480 const int x_idx_sb = (i & 1) << 1, y_idx_sb = i & 2; |
1597 #if CONFIG_SUPERBLOCKS | 1481 MODE_INFO *sb_mi = mi + y_idx_sb * mis + x_idx_sb; |
1598 if (sb_mbmi->encoded_as_sb) { | 1482 |
1599 if (!((mb_col & 1) || (mb_row & 1))) { | 1483 if (mb_row + y_idx_sb >= cm->mb_rows || |
1600 segment_id = mbmi->segment_id; | 1484 mb_col + x_idx_sb >= cm->mb_cols) |
1601 skip = mbmi->mb_skip_coeff; | 1485 continue; |
1602 if (mb_col < cm->mb_cols - 1) { | 1486 |
1603 segment_id = segment_id && mi[1].mbmi.segment_id; | 1487 if (sb_mi->mbmi.sb_type) { |
1604 skip = skip && mi[1].mbmi.mb_skip_coeff; | 1488 reset_skip_txfm_size_sb32(cpi, sb_mi, mis, txfm_max, |
| 1489 cm->mb_rows - mb_row - y_idx_sb, |
| 1490 cm->mb_cols - mb_col - x_idx_sb); |
| 1491 } else { |
| 1492 int m; |
| 1493 |
| 1494 for (m = 0; m < 4; m++) { |
| 1495 const int x_idx = x_idx_sb + (m & 1), y_idx = y_idx_sb + (m >> 1); |
| 1496 MODE_INFO *mb_mi; |
| 1497 |
| 1498 if (mb_col + x_idx >= cm->mb_cols || |
| 1499 mb_row + y_idx >= cm->mb_rows) |
| 1500 continue; |
| 1501 |
| 1502 mb_mi = mi + y_idx * mis + x_idx; |
| 1503 assert(mb_mi->mbmi.sb_type == BLOCK_SIZE_MB16X16); |
| 1504 reset_skip_txfm_size_mb(cpi, mb_mi, txfm_max); |
1605 } | 1505 } |
1606 if (mb_row < cm->mb_rows - 1) { | |
1607 segment_id = segment_id && | |
1608 mi[cm->mode_info_stride].mbmi.segment_id; | |
1609 skip = skip && mi[cm->mode_info_stride].mbmi.mb_skip_coeff; | |
1610 if (mb_col < cm->mb_cols - 1) { | |
1611 segment_id = segment_id && | |
1612 mi[cm->mode_info_stride + 1].mbmi.segment_id; | |
1613 skip = skip && mi[cm->mode_info_stride + 1].mbmi.mb_skip_coeff; | |
1614 } | |
1615 } | |
1616 xd->mode_info_context = mi; | |
1617 assert((vp9_segfeature_active(xd, segment_id, SEG_LVL_EOB) && | |
1618 vp9_get_segdata(xd, segment_id, SEG_LVL_EOB) == 0) || | |
1619 (cm->mb_no_coeff_skip && skip)); | |
1620 mbmi->txfm_size = txfm_max; | |
1621 } else { | |
1622 mbmi->txfm_size = sb_mbmi->txfm_size; | |
1623 } | 1506 } |
1624 } else { | |
1625 #endif | |
1626 segment_id = mbmi->segment_id; | |
1627 xd->mode_info_context = mi; | |
1628 assert((vp9_segfeature_active(xd, segment_id, SEG_LVL_EOB) && | |
1629 vp9_get_segdata(xd, segment_id, SEG_LVL_EOB) == 0) || | |
1630 (cm->mb_no_coeff_skip && mbmi->mb_skip_coeff)); | |
1631 mbmi->txfm_size = txfm_max; | |
1632 #if CONFIG_SUPERBLOCKS | |
1633 } | 1507 } |
1634 #endif | |
1635 } | 1508 } |
1636 #if CONFIG_SUPERBLOCKS | |
1637 if (mb_col & 1) | |
1638 sb_mi += 2; | |
1639 #endif | |
1640 } | 1509 } |
1641 #if CONFIG_SUPERBLOCKS | |
1642 if (mb_row & 1) | |
1643 sb_mi_ptr += 2 * mis; | |
1644 #endif | |
1645 } | 1510 } |
1646 } | 1511 } |
1647 | 1512 |
1648 void vp9_encode_frame(VP9_COMP *cpi) { | 1513 void vp9_encode_frame(VP9_COMP *cpi) { |
1649 if (cpi->sf.RD) { | 1514 if (cpi->sf.RD) { |
1650 int i, frame_type, pred_type; | 1515 int i, frame_type, pred_type; |
1651 TXFM_MODE txfm_type; | 1516 TXFM_MODE txfm_type; |
1652 | 1517 |
1653 /* | 1518 /* |
1654 * This code does a single RD pass over the whole frame assuming | 1519 * This code does a single RD pass over the whole frame assuming |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1694 * nonsense coefficient cost prediction for keyframes. The probabilities | 1559 * nonsense coefficient cost prediction for keyframes. The probabilities |
1695 * are reset to defaults, and thus we basically have no idea how expensive | 1560 * are reset to defaults, and thus we basically have no idea how expensive |
1696 * a 4x4 vs. 8x8 will really be. The result is that any estimate at which | 1561 * a 4x4 vs. 8x8 will really be. The result is that any estimate at which |
1697 * of the two is better is utterly bogus. | 1562 * of the two is better is utterly bogus. |
1698 * I'd like to eventually remove this hack, but in order to do that, we | 1563 * I'd like to eventually remove this hack, but in order to do that, we |
1699 * need to move the frame reset code from the frame encode init to the | 1564 * need to move the frame reset code from the frame encode init to the |
1700 * bitstream write code, or alternatively keep a backup of the previous | 1565 * bitstream write code, or alternatively keep a backup of the previous |
1701 * keyframe's probabilities as an estimate of what the current keyframe's | 1566 * keyframe's probabilities as an estimate of what the current keyframe's |
1702 * coefficient cost distributions may look like. */ | 1567 * coefficient cost distributions may look like. */ |
1703 if (frame_type == 0) { | 1568 if (frame_type == 0) { |
1704 txfm_type = ALLOW_16X16; | 1569 txfm_type = ALLOW_32X32; |
1705 } else | 1570 } else |
1706 #if 0 | 1571 #if 0 |
1707 /* FIXME (rbultje) | 1572 /* FIXME (rbultje) |
1708 * this code is disabled for a similar reason as the code above; the | 1573 * this code is disabled for a similar reason as the code above; the |
1709 * problem is that each time we "revert" to 4x4 only (or even 8x8 only), | 1574 * problem is that each time we "revert" to 4x4 only (or even 8x8 only), |
1710 * the coefficient probabilities for 16x16 (and 8x8) start lagging behind, | 1575 * the coefficient probabilities for 16x16 (and 8x8) start lagging behind, |
1711 * thus leading to them lagging further behind and not being chosen for | 1576 * thus leading to them lagging further behind and not being chosen for |
1712 * subsequent frames either. This is essentially a local minimum problem | 1577 * subsequent frames either. This is essentially a local minimum problem |
1713 * that we can probably fix by estimating real costs more closely within | 1578 * that we can probably fix by estimating real costs more closely within |
1714 * a frame, perhaps by re-calculating costs on-the-fly as frame encoding | 1579 * a frame, perhaps by re-calculating costs on-the-fly as frame encoding |
(...skipping 10 matching lines...) Expand all Loading... |
1725 && cpi->rd_tx_select_threshes[frame_type][ONLY_4X4] > | 1590 && cpi->rd_tx_select_threshes[frame_type][ONLY_4X4] > |
1726 cpi->rd_tx_select_threshes[frame_type][ALLOW_16X16] | 1591 cpi->rd_tx_select_threshes[frame_type][ALLOW_16X16] |
1727 ) { | 1592 ) { |
1728 txfm_type = ONLY_4X4; | 1593 txfm_type = ONLY_4X4; |
1729 } else if (cpi->rd_tx_select_threshes[frame_type][ALLOW_16X16] >= | 1594 } else if (cpi->rd_tx_select_threshes[frame_type][ALLOW_16X16] >= |
1730 cpi->rd_tx_select_threshes[frame_type][ALLOW_8X8]) { | 1595 cpi->rd_tx_select_threshes[frame_type][ALLOW_8X8]) { |
1731 txfm_type = ALLOW_16X16; | 1596 txfm_type = ALLOW_16X16; |
1732 } else | 1597 } else |
1733 txfm_type = ALLOW_8X8; | 1598 txfm_type = ALLOW_8X8; |
1734 #else | 1599 #else |
1735 txfm_type = cpi->rd_tx_select_threshes[frame_type][ALLOW_16X16] >= | 1600 txfm_type = cpi->rd_tx_select_threshes[frame_type][ALLOW_32X32] >= |
1736 cpi->rd_tx_select_threshes[frame_type][TX_MODE_SELECT] ? | 1601 cpi->rd_tx_select_threshes[frame_type][TX_MODE_SELECT] ? |
1737 ALLOW_16X16 : TX_MODE_SELECT; | 1602 ALLOW_32X32 : TX_MODE_SELECT; |
1738 #endif | 1603 #endif |
1739 cpi->common.txfm_mode = txfm_type; | 1604 cpi->common.txfm_mode = txfm_type; |
1740 if (txfm_type != TX_MODE_SELECT) { | 1605 if (txfm_type != TX_MODE_SELECT) { |
1741 cpi->common.prob_tx[0] = 128; | 1606 cpi->common.prob_tx[0] = 128; |
1742 cpi->common.prob_tx[1] = 128; | 1607 cpi->common.prob_tx[1] = 128; |
1743 } | 1608 } |
1744 cpi->common.comp_pred_mode = pred_type; | 1609 cpi->common.comp_pred_mode = pred_type; |
1745 encode_frame_internal(cpi); | 1610 encode_frame_internal(cpi); |
1746 | 1611 |
1747 for (i = 0; i < NB_PREDICTION_TYPES; ++i) { | 1612 for (i = 0; i < NB_PREDICTION_TYPES; ++i) { |
1748 const int diff = (int)(cpi->rd_comp_pred_diff[i] / cpi->common.MBs); | 1613 const int diff = (int)(cpi->rd_comp_pred_diff[i] / cpi->common.MBs); |
1749 cpi->rd_prediction_type_threshes[frame_type][i] += diff; | 1614 cpi->rd_prediction_type_threshes[frame_type][i] += diff; |
1750 cpi->rd_prediction_type_threshes[frame_type][i] >>= 1; | 1615 cpi->rd_prediction_type_threshes[frame_type][i] >>= 1; |
1751 } | 1616 } |
1752 | 1617 |
1753 for (i = 0; i < NB_TXFM_MODES; ++i) { | 1618 for (i = 0; i < NB_TXFM_MODES; ++i) { |
1754 int64_t pd = cpi->rd_tx_select_diff[i]; | 1619 int64_t pd = cpi->rd_tx_select_diff[i]; |
1755 int diff; | 1620 int diff; |
1756 if (i == TX_MODE_SELECT) | 1621 if (i == TX_MODE_SELECT) |
1757 pd -= RDCOST(cpi->mb.rdmult, cpi->mb.rddiv, 2048 * (TX_SIZE_MAX - 1), 0)
; | 1622 pd -= RDCOST(cpi->mb.rdmult, cpi->mb.rddiv, |
| 1623 2048 * (TX_SIZE_MAX_SB - 1), 0); |
1758 diff = (int)(pd / cpi->common.MBs); | 1624 diff = (int)(pd / cpi->common.MBs); |
1759 cpi->rd_tx_select_threshes[frame_type][i] += diff; | 1625 cpi->rd_tx_select_threshes[frame_type][i] += diff; |
1760 cpi->rd_tx_select_threshes[frame_type][i] /= 2; | 1626 cpi->rd_tx_select_threshes[frame_type][i] /= 2; |
1761 } | 1627 } |
1762 | 1628 |
1763 if (cpi->common.comp_pred_mode == HYBRID_PREDICTION) { | 1629 if (cpi->common.comp_pred_mode == HYBRID_PREDICTION) { |
1764 int single_count_zero = 0; | 1630 int single_count_zero = 0; |
1765 int comp_count_zero = 0; | 1631 int comp_count_zero = 0; |
1766 | 1632 |
1767 for (i = 0; i < COMP_PRED_CONTEXTS; i++) { | 1633 for (i = 0; i < COMP_PRED_CONTEXTS; i++) { |
1768 single_count_zero += cpi->single_pred_count[i]; | 1634 single_count_zero += cpi->single_pred_count[i]; |
1769 comp_count_zero += cpi->comp_pred_count[i]; | 1635 comp_count_zero += cpi->comp_pred_count[i]; |
1770 } | 1636 } |
1771 | 1637 |
1772 if (comp_count_zero == 0) { | 1638 if (comp_count_zero == 0) { |
1773 cpi->common.comp_pred_mode = SINGLE_PREDICTION_ONLY; | 1639 cpi->common.comp_pred_mode = SINGLE_PREDICTION_ONLY; |
1774 } else if (single_count_zero == 0) { | 1640 } else if (single_count_zero == 0) { |
1775 cpi->common.comp_pred_mode = COMP_PREDICTION_ONLY; | 1641 cpi->common.comp_pred_mode = COMP_PREDICTION_ONLY; |
1776 } | 1642 } |
1777 } | 1643 } |
1778 | 1644 |
1779 if (cpi->common.txfm_mode == TX_MODE_SELECT) { | 1645 if (cpi->common.txfm_mode == TX_MODE_SELECT) { |
1780 const int count4x4 = cpi->txfm_count[TX_4X4] + cpi->txfm_count_8x8p[TX_4X4
]; | 1646 const int count4x4 = cpi->txfm_count_16x16p[TX_4X4] + |
1781 const int count8x8 = cpi->txfm_count[TX_8X8]; | 1647 cpi->txfm_count_32x32p[TX_4X4] + |
| 1648 cpi->txfm_count_8x8p[TX_4X4]; |
| 1649 const int count8x8_lp = cpi->txfm_count_32x32p[TX_8X8] + |
| 1650 cpi->txfm_count_16x16p[TX_8X8]; |
1782 const int count8x8_8x8p = cpi->txfm_count_8x8p[TX_8X8]; | 1651 const int count8x8_8x8p = cpi->txfm_count_8x8p[TX_8X8]; |
1783 const int count16x16 = cpi->txfm_count[TX_16X16]; | 1652 const int count16x16_16x16p = cpi->txfm_count_16x16p[TX_16X16]; |
| 1653 const int count16x16_lp = cpi->txfm_count_32x32p[TX_16X16]; |
| 1654 const int count32x32 = cpi->txfm_count_32x32p[TX_32X32]; |
1784 | 1655 |
1785 if (count4x4 == 0 && count16x16 == 0) { | 1656 if (count4x4 == 0 && count16x16_lp == 0 && count16x16_16x16p == 0 && |
| 1657 count32x32 == 0) { |
1786 cpi->common.txfm_mode = ALLOW_8X8; | 1658 cpi->common.txfm_mode = ALLOW_8X8; |
1787 reset_skip_txfm_size(cpi, TX_8X8); | 1659 reset_skip_txfm_size(cpi, TX_8X8); |
1788 } else if (count8x8 == 0 && count16x16 == 0 && count8x8_8x8p == 0) { | 1660 } else if (count8x8_8x8p == 0 && count16x16_16x16p == 0 && |
| 1661 count8x8_lp == 0 && count16x16_lp == 0 && count32x32 == 0) { |
1789 cpi->common.txfm_mode = ONLY_4X4; | 1662 cpi->common.txfm_mode = ONLY_4X4; |
1790 reset_skip_txfm_size(cpi, TX_4X4); | 1663 reset_skip_txfm_size(cpi, TX_4X4); |
1791 } else if (count8x8 == 0 && count4x4 == 0) { | 1664 } else if (count8x8_lp == 0 && count16x16_lp == 0 && count4x4 == 0) { |
| 1665 cpi->common.txfm_mode = ALLOW_32X32; |
| 1666 } else if (count32x32 == 0 && count8x8_lp == 0 && count4x4 == 0) { |
1792 cpi->common.txfm_mode = ALLOW_16X16; | 1667 cpi->common.txfm_mode = ALLOW_16X16; |
| 1668 reset_skip_txfm_size(cpi, TX_16X16); |
1793 } | 1669 } |
1794 } | 1670 } |
| 1671 |
| 1672 // Update interpolation filter strategy for next frame. |
| 1673 if ((cpi->common.frame_type != KEY_FRAME) && (cpi->sf.search_best_filter)) |
| 1674 select_interp_filter_type(cpi); |
1795 } else { | 1675 } else { |
1796 encode_frame_internal(cpi); | 1676 encode_frame_internal(cpi); |
1797 } | 1677 } |
1798 | 1678 |
1799 } | 1679 } |
1800 | 1680 |
1801 void vp9_setup_block_ptrs(MACROBLOCK *x) { | 1681 void vp9_setup_block_ptrs(MACROBLOCK *x) { |
1802 int r, c; | 1682 int r, c; |
1803 int i; | 1683 int i; |
1804 | 1684 |
(...skipping 23 matching lines...) Expand all Loading... |
1828 x->block[i].coeff = x->coeff + i * 16; | 1708 x->block[i].coeff = x->coeff + i * 16; |
1829 } | 1709 } |
1830 } | 1710 } |
1831 | 1711 |
1832 void vp9_build_block_offsets(MACROBLOCK *x) { | 1712 void vp9_build_block_offsets(MACROBLOCK *x) { |
1833 int block = 0; | 1713 int block = 0; |
1834 int br, bc; | 1714 int br, bc; |
1835 | 1715 |
1836 vp9_build_block_doffsets(&x->e_mbd); | 1716 vp9_build_block_doffsets(&x->e_mbd); |
1837 | 1717 |
1838 #if !CONFIG_SUPERBLOCKS | |
1839 // y blocks | |
1840 x->thismb_ptr = &x->thismb[0]; | |
1841 for (br = 0; br < 4; br++) { | |
1842 for (bc = 0; bc < 4; bc++) { | |
1843 BLOCK *this_block = &x->block[block]; | |
1844 // this_block->base_src = &x->src.y_buffer; | |
1845 // this_block->src_stride = x->src.y_stride; | |
1846 // this_block->src = 4 * br * this_block->src_stride + 4 * bc; | |
1847 this_block->base_src = &x->thismb_ptr; | |
1848 this_block->src_stride = 16; | |
1849 this_block->src = 4 * br * 16 + 4 * bc; | |
1850 ++block; | |
1851 } | |
1852 } | |
1853 #else | |
1854 for (br = 0; br < 4; br++) { | 1718 for (br = 0; br < 4; br++) { |
1855 for (bc = 0; bc < 4; bc++) { | 1719 for (bc = 0; bc < 4; bc++) { |
1856 BLOCK *this_block = &x->block[block]; | 1720 BLOCK *this_block = &x->block[block]; |
1857 // this_block->base_src = &x->src.y_buffer; | 1721 // this_block->base_src = &x->src.y_buffer; |
1858 // this_block->src_stride = x->src.y_stride; | 1722 // this_block->src_stride = x->src.y_stride; |
1859 // this_block->src = 4 * br * this_block->src_stride + 4 * bc; | 1723 // this_block->src = 4 * br * this_block->src_stride + 4 * bc; |
1860 this_block->base_src = &x->src.y_buffer; | 1724 this_block->base_src = &x->src.y_buffer; |
1861 this_block->src_stride = x->src.y_stride; | 1725 this_block->src_stride = x->src.y_stride; |
1862 this_block->src = 4 * br * this_block->src_stride + 4 * bc; | 1726 this_block->src = 4 * br * this_block->src_stride + 4 * bc; |
1863 ++block; | 1727 ++block; |
1864 } | 1728 } |
1865 } | 1729 } |
1866 #endif | |
1867 | 1730 |
1868 // u blocks | 1731 // u blocks |
1869 for (br = 0; br < 2; br++) { | 1732 for (br = 0; br < 2; br++) { |
1870 for (bc = 0; bc < 2; bc++) { | 1733 for (bc = 0; bc < 2; bc++) { |
1871 BLOCK *this_block = &x->block[block]; | 1734 BLOCK *this_block = &x->block[block]; |
1872 this_block->base_src = &x->src.u_buffer; | 1735 this_block->base_src = &x->src.u_buffer; |
1873 this_block->src_stride = x->src.uv_stride; | 1736 this_block->src_stride = x->src.uv_stride; |
1874 this_block->src = 4 * br * this_block->src_stride + 4 * bc; | 1737 this_block->src = 4 * br * this_block->src_stride + 4 * bc; |
1875 ++block; | 1738 ++block; |
1876 } | 1739 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1910 } | 1773 } |
1911 | 1774 |
1912 if (m == I8X8_PRED) { | 1775 if (m == I8X8_PRED) { |
1913 i8x8_modes[xd->block[0].bmi.as_mode.first]++; | 1776 i8x8_modes[xd->block[0].bmi.as_mode.first]++; |
1914 i8x8_modes[xd->block[2].bmi.as_mode.first]++; | 1777 i8x8_modes[xd->block[2].bmi.as_mode.first]++; |
1915 i8x8_modes[xd->block[8].bmi.as_mode.first]++; | 1778 i8x8_modes[xd->block[8].bmi.as_mode.first]++; |
1916 i8x8_modes[xd->block[10].bmi.as_mode.first]++; | 1779 i8x8_modes[xd->block[10].bmi.as_mode.first]++; |
1917 } | 1780 } |
1918 #endif | 1781 #endif |
1919 | 1782 |
1920 #if CONFIG_SUPERBLOCKS | 1783 if (xd->mode_info_context->mbmi.sb_type) { |
1921 if (xd->mode_info_context->mbmi.encoded_as_sb) { | |
1922 ++cpi->sb_ymode_count[m]; | 1784 ++cpi->sb_ymode_count[m]; |
1923 } else | 1785 } else { |
1924 #endif | |
1925 ++cpi->ymode_count[m]; | 1786 ++cpi->ymode_count[m]; |
| 1787 } |
1926 if (m != I8X8_PRED) | 1788 if (m != I8X8_PRED) |
1927 ++cpi->y_uv_mode_count[m][uvm]; | 1789 ++cpi->y_uv_mode_count[m][uvm]; |
1928 else { | 1790 else { |
1929 cpi->i8x8_mode_count[xd->block[0].bmi.as_mode.first]++; | 1791 cpi->i8x8_mode_count[xd->block[0].bmi.as_mode.first]++; |
1930 cpi->i8x8_mode_count[xd->block[2].bmi.as_mode.first]++; | 1792 cpi->i8x8_mode_count[xd->block[2].bmi.as_mode.first]++; |
1931 cpi->i8x8_mode_count[xd->block[8].bmi.as_mode.first]++; | 1793 cpi->i8x8_mode_count[xd->block[8].bmi.as_mode.first]++; |
1932 cpi->i8x8_mode_count[xd->block[10].bmi.as_mode.first]++; | 1794 cpi->i8x8_mode_count[xd->block[10].bmi.as_mode.first]++; |
1933 } | 1795 } |
1934 if (m == B_PRED) { | 1796 if (m == B_PRED) { |
1935 int b = 0; | 1797 int b = 0; |
(...skipping 21 matching lines...) Expand all Loading... |
1957 a = act + 4 * cpi->activity_avg; | 1819 a = act + 4 * cpi->activity_avg; |
1958 b = 4 * act + cpi->activity_avg; | 1820 b = 4 * act + cpi->activity_avg; |
1959 | 1821 |
1960 if (act > cpi->activity_avg) | 1822 if (act > cpi->activity_avg) |
1961 x->act_zbin_adj = (int)(((int64_t)b + (a >> 1)) / a) - 1; | 1823 x->act_zbin_adj = (int)(((int64_t)b + (a >> 1)) / a) - 1; |
1962 else | 1824 else |
1963 x->act_zbin_adj = 1 - (int)(((int64_t)a + (b >> 1)) / b); | 1825 x->act_zbin_adj = 1 - (int)(((int64_t)a + (b >> 1)) / b); |
1964 #endif | 1826 #endif |
1965 } | 1827 } |
1966 | 1828 |
1967 #if CONFIG_SUPERBLOCKS | |
1968 static void update_sb_skip_coeff_state(VP9_COMP *cpi, | 1829 static void update_sb_skip_coeff_state(VP9_COMP *cpi, |
1969 MACROBLOCK *x, | |
1970 ENTROPY_CONTEXT_PLANES ta[4], | 1830 ENTROPY_CONTEXT_PLANES ta[4], |
1971 ENTROPY_CONTEXT_PLANES tl[4], | 1831 ENTROPY_CONTEXT_PLANES tl[4], |
1972 TOKENEXTRA *t[4], | 1832 TOKENEXTRA *t[4], |
1973 TOKENEXTRA **tp, | 1833 TOKENEXTRA **tp, |
1974 int skip[4]) | 1834 int skip[4], int output_enabled) { |
1975 { | 1835 MACROBLOCK *const x = &cpi->mb; |
1976 TOKENEXTRA tokens[4][16 * 24]; | 1836 TOKENEXTRA tokens[4][16 * 25]; |
1977 int n_tokens[4], n; | 1837 int n_tokens[4], n; |
1978 | 1838 |
1979 // if there were no skips, we don't need to do anything | 1839 // if there were no skips, we don't need to do anything |
1980 if (!skip[0] && !skip[1] && !skip[2] && !skip[3]) | 1840 if (!skip[0] && !skip[1] && !skip[2] && !skip[3]) |
1981 return; | 1841 return; |
1982 | 1842 |
1983 // if we don't do coeff skipping for this frame, we don't | 1843 // if we don't do coeff skipping for this frame, we don't |
1984 // need to do anything here | 1844 // need to do anything here |
1985 if (!cpi->common.mb_no_coeff_skip) | 1845 if (!cpi->common.mb_no_coeff_skip) |
1986 return; | 1846 return; |
(...skipping 19 matching lines...) Expand all Loading... |
2006 memcpy(tokens[2], t[2], n_tokens[2] * sizeof(*t[0])); | 1866 memcpy(tokens[2], t[2], n_tokens[2] * sizeof(*t[0])); |
2007 if (n_tokens[3]) | 1867 if (n_tokens[3]) |
2008 memcpy(tokens[3], t[3], n_tokens[3] * sizeof(*t[0])); | 1868 memcpy(tokens[3], t[3], n_tokens[3] * sizeof(*t[0])); |
2009 | 1869 |
2010 // reset pointer, stuff EOBs where necessary | 1870 // reset pointer, stuff EOBs where necessary |
2011 *tp = t[0]; | 1871 *tp = t[0]; |
2012 for (n = 0; n < 4; n++) { | 1872 for (n = 0; n < 4; n++) { |
2013 if (skip[n]) { | 1873 if (skip[n]) { |
2014 x->e_mbd.above_context = &ta[n]; | 1874 x->e_mbd.above_context = &ta[n]; |
2015 x->e_mbd.left_context = &tl[n]; | 1875 x->e_mbd.left_context = &tl[n]; |
2016 vp9_stuff_mb(cpi, &x->e_mbd, tp, 0); | 1876 vp9_stuff_mb(cpi, &x->e_mbd, tp, !output_enabled); |
2017 } else { | 1877 } else { |
2018 if (n_tokens[n]) { | 1878 if (n_tokens[n]) { |
2019 memcpy(*tp, tokens[n], sizeof(*t[0]) * n_tokens[n]); | 1879 memcpy(*tp, tokens[n], sizeof(*t[0]) * n_tokens[n]); |
2020 } | 1880 } |
2021 (*tp) += n_tokens[n]; | 1881 (*tp) += n_tokens[n]; |
2022 } | 1882 } |
2023 } | 1883 } |
2024 } | 1884 } |
2025 #endif /* CONFIG_SUPERBLOCKS */ | |
2026 | 1885 |
2027 static void encode_macroblock(VP9_COMP *cpi, MACROBLOCK *x, | 1886 static void update_sb64_skip_coeff_state(VP9_COMP *cpi, |
2028 TOKENEXTRA **t, int recon_yoffset, | 1887 ENTROPY_CONTEXT_PLANES ta[16], |
2029 int recon_uvoffset, int output_enabled, | 1888 ENTROPY_CONTEXT_PLANES tl[16], |
2030 int mb_col, int mb_row) { | 1889 TOKENEXTRA *t[16], |
2031 VP9_COMMON *cm = &cpi->common; | 1890 TOKENEXTRA **tp, |
| 1891 int skip[16], int output_enabled) { |
| 1892 MACROBLOCK *const x = &cpi->mb; |
| 1893 |
| 1894 if (x->e_mbd.mode_info_context->mbmi.txfm_size == TX_32X32) { |
| 1895 TOKENEXTRA tokens[4][1024+512]; |
| 1896 int n_tokens[4], n; |
| 1897 |
| 1898 // if there were no skips, we don't need to do anything |
| 1899 if (!skip[0] && !skip[1] && !skip[2] && !skip[3]) |
| 1900 return; |
| 1901 |
| 1902 // if we don't do coeff skipping for this frame, we don't |
| 1903 // need to do anything here |
| 1904 if (!cpi->common.mb_no_coeff_skip) |
| 1905 return; |
| 1906 |
| 1907 // if all 4 MBs skipped coeff coding, nothing to be done |
| 1908 if (skip[0] && skip[1] && skip[2] && skip[3]) |
| 1909 return; |
| 1910 |
| 1911 // so the situation now is that we want to skip coeffs |
| 1912 // for some MBs, but not all, and we didn't code EOB |
| 1913 // coefficients for them. However, the skip flag for this |
| 1914 // SB will be 0 overall, so we need to insert EOBs in the |
| 1915 // middle of the token tree. Do so here. |
| 1916 for (n = 0; n < 4; n++) { |
| 1917 if (n < 3) { |
| 1918 n_tokens[n] = t[n + 1] - t[n]; |
| 1919 } else { |
| 1920 n_tokens[n] = *tp - t[3]; |
| 1921 } |
| 1922 if (n_tokens[n]) { |
| 1923 memcpy(tokens[n], t[n], n_tokens[n] * sizeof(*t[0])); |
| 1924 } |
| 1925 } |
| 1926 |
| 1927 // reset pointer, stuff EOBs where necessary |
| 1928 *tp = t[0]; |
| 1929 for (n = 0; n < 4; n++) { |
| 1930 if (skip[n]) { |
| 1931 x->e_mbd.above_context = &ta[n * 2]; |
| 1932 x->e_mbd.left_context = &tl[n * 2]; |
| 1933 vp9_stuff_sb(cpi, &x->e_mbd, tp, !output_enabled); |
| 1934 } else { |
| 1935 if (n_tokens[n]) { |
| 1936 memcpy(*tp, tokens[n], sizeof(*t[0]) * n_tokens[n]); |
| 1937 } |
| 1938 (*tp) += n_tokens[n]; |
| 1939 } |
| 1940 } |
| 1941 } else { |
| 1942 TOKENEXTRA tokens[16][16 * 25]; |
| 1943 int n_tokens[16], n; |
| 1944 |
| 1945 // if there were no skips, we don't need to do anything |
| 1946 if (!skip[ 0] && !skip[ 1] && !skip[ 2] && !skip[ 3] && |
| 1947 !skip[ 4] && !skip[ 5] && !skip[ 6] && !skip[ 7] && |
| 1948 !skip[ 8] && !skip[ 9] && !skip[10] && !skip[11] && |
| 1949 !skip[12] && !skip[13] && !skip[14] && !skip[15]) |
| 1950 return; |
| 1951 |
| 1952 // if we don't do coeff skipping for this frame, we don't |
| 1953 // need to do anything here |
| 1954 if (!cpi->common.mb_no_coeff_skip) |
| 1955 return; |
| 1956 |
| 1957 // if all 4 MBs skipped coeff coding, nothing to be done |
| 1958 if (skip[ 0] && skip[ 1] && skip[ 2] && skip[ 3] && |
| 1959 skip[ 4] && skip[ 5] && skip[ 6] && skip[ 7] && |
| 1960 skip[ 8] && skip[ 9] && skip[10] && skip[11] && |
| 1961 skip[12] && skip[13] && skip[14] && skip[15]) |
| 1962 return; |
| 1963 |
| 1964 // so the situation now is that we want to skip coeffs |
| 1965 // for some MBs, but not all, and we didn't code EOB |
| 1966 // coefficients for them. However, the skip flag for this |
| 1967 // SB will be 0 overall, so we need to insert EOBs in the |
| 1968 // middle of the token tree. Do so here. |
| 1969 for (n = 0; n < 16; n++) { |
| 1970 if (n < 15) { |
| 1971 n_tokens[n] = t[n + 1] - t[n]; |
| 1972 } else { |
| 1973 n_tokens[n] = *tp - t[15]; |
| 1974 } |
| 1975 if (n_tokens[n]) { |
| 1976 memcpy(tokens[n], t[n], n_tokens[n] * sizeof(*t[0])); |
| 1977 } |
| 1978 } |
| 1979 |
| 1980 // reset pointer, stuff EOBs where necessary |
| 1981 *tp = t[0]; |
| 1982 for (n = 0; n < 16; n++) { |
| 1983 if (skip[n]) { |
| 1984 x->e_mbd.above_context = &ta[n]; |
| 1985 x->e_mbd.left_context = &tl[n]; |
| 1986 vp9_stuff_mb(cpi, &x->e_mbd, tp, !output_enabled); |
| 1987 } else { |
| 1988 if (n_tokens[n]) { |
| 1989 memcpy(*tp, tokens[n], sizeof(*t[0]) * n_tokens[n]); |
| 1990 } |
| 1991 (*tp) += n_tokens[n]; |
| 1992 } |
| 1993 } |
| 1994 } |
| 1995 } |
| 1996 |
| 1997 static void encode_macroblock(VP9_COMP *cpi, TOKENEXTRA **t, |
| 1998 int recon_yoffset, int recon_uvoffset, |
| 1999 int output_enabled, |
| 2000 int mb_row, int mb_col) { |
| 2001 VP9_COMMON *const cm = &cpi->common; |
| 2002 MACROBLOCK *const x = &cpi->mb; |
2032 MACROBLOCKD *const xd = &x->e_mbd; | 2003 MACROBLOCKD *const xd = &x->e_mbd; |
2033 MB_MODE_INFO * mbmi = &xd->mode_info_context->mbmi; | 2004 MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi; |
2034 unsigned char *segment_id = &mbmi->segment_id; | |
2035 int seg_ref_active; | |
2036 unsigned char ref_pred_flag; | 2005 unsigned char ref_pred_flag; |
2037 | 2006 |
2038 x->skip = 0; | 2007 assert(!xd->mode_info_context->mbmi.sb_type); |
2039 #if CONFIG_SUPERBLOCKS | |
2040 assert(!xd->mode_info_context->mbmi.encoded_as_sb); | |
2041 #endif | |
2042 | 2008 |
2043 #ifdef ENC_DEBUG | 2009 #ifdef ENC_DEBUG |
2044 enc_debug = (cpi->common.current_video_frame == 46 && | 2010 enc_debug = (cpi->common.current_video_frame == 46 && |
2045 mb_row == 5 && mb_col == 2); | 2011 mb_row == 5 && mb_col == 2); |
2046 if (enc_debug) | 2012 if (enc_debug) |
2047 printf("Encode MB %d %d output %d\n", mb_row, mb_col, output_enabled); | 2013 printf("Encode MB %d %d output %d\n", mb_row, mb_col, output_enabled); |
2048 #endif | 2014 #endif |
2049 if (cm->frame_type == KEY_FRAME) { | 2015 if (cm->frame_type == KEY_FRAME) { |
2050 if (cpi->oxcf.tuning == VP8_TUNE_SSIM && output_enabled) { | 2016 if (cpi->oxcf.tuning == VP8_TUNE_SSIM && output_enabled) { |
2051 // Adjust the zbin based on this MB rate. | 2017 // Adjust the zbin based on this MB rate. |
(...skipping 20 matching lines...) Expand all Loading... |
2072 cpi->zbin_mode_boost = LF_ZEROMV_ZBIN_BOOST; | 2038 cpi->zbin_mode_boost = LF_ZEROMV_ZBIN_BOOST; |
2073 } else if (mbmi->mode == SPLITMV) | 2039 } else if (mbmi->mode == SPLITMV) |
2074 cpi->zbin_mode_boost = 0; | 2040 cpi->zbin_mode_boost = 0; |
2075 else | 2041 else |
2076 cpi->zbin_mode_boost = MV_ZBIN_BOOST; | 2042 cpi->zbin_mode_boost = MV_ZBIN_BOOST; |
2077 } | 2043 } |
2078 } | 2044 } |
2079 | 2045 |
2080 vp9_update_zbin_extra(cpi, x); | 2046 vp9_update_zbin_extra(cpi, x); |
2081 | 2047 |
2082 seg_ref_active = vp9_segfeature_active(xd, *segment_id, SEG_LVL_REF_FRAME); | |
2083 | |
2084 // SET VARIOUS PREDICTION FLAGS | 2048 // SET VARIOUS PREDICTION FLAGS |
2085 | 2049 |
2086 // Did the chosen reference frame match its predicted value. | 2050 // Did the chosen reference frame match its predicted value. |
2087 ref_pred_flag = ((mbmi->ref_frame == vp9_get_pred_ref(cm, xd))); | 2051 ref_pred_flag = ((mbmi->ref_frame == vp9_get_pred_ref(cm, xd))); |
2088 vp9_set_pred_flag(xd, PRED_REF, ref_pred_flag); | 2052 vp9_set_pred_flag(xd, PRED_REF, ref_pred_flag); |
2089 } | 2053 } |
2090 | 2054 |
2091 if (mbmi->ref_frame == INTRA_FRAME) { | 2055 if (mbmi->ref_frame == INTRA_FRAME) { |
2092 #ifdef ENC_DEBUG | 2056 #ifdef ENC_DEBUG |
2093 if (enc_debug) { | 2057 if (enc_debug) { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2243 } else { | 2207 } else { |
2244 int mb_skip_context = | 2208 int mb_skip_context = |
2245 cpi->common.mb_no_coeff_skip ? | 2209 cpi->common.mb_no_coeff_skip ? |
2246 (x->e_mbd.mode_info_context - 1)->mbmi.mb_skip_coeff + | 2210 (x->e_mbd.mode_info_context - 1)->mbmi.mb_skip_coeff + |
2247 (x->e_mbd.mode_info_context - cpi->common.mode_info_stride)->mbmi.mb_skip_
coeff : | 2211 (x->e_mbd.mode_info_context - cpi->common.mode_info_stride)->mbmi.mb_skip_
coeff : |
2248 0; | 2212 0; |
2249 if (cpi->common.mb_no_coeff_skip) { | 2213 if (cpi->common.mb_no_coeff_skip) { |
2250 mbmi->mb_skip_coeff = 1; | 2214 mbmi->mb_skip_coeff = 1; |
2251 if (output_enabled) | 2215 if (output_enabled) |
2252 cpi->skip_true_count[mb_skip_context]++; | 2216 cpi->skip_true_count[mb_skip_context]++; |
2253 vp9_fix_contexts(xd); | 2217 vp9_reset_mb_tokens_context(xd); |
2254 } else { | 2218 } else { |
2255 vp9_stuff_mb(cpi, xd, t, !output_enabled); | 2219 vp9_stuff_mb(cpi, xd, t, !output_enabled); |
2256 mbmi->mb_skip_coeff = 0; | 2220 mbmi->mb_skip_coeff = 0; |
2257 if (output_enabled) | 2221 if (output_enabled) |
2258 cpi->skip_false_count[mb_skip_context]++; | 2222 cpi->skip_false_count[mb_skip_context]++; |
2259 } | 2223 } |
2260 } | 2224 } |
2261 | 2225 |
2262 if (output_enabled) { | 2226 if (output_enabled) { |
2263 int segment_id = mbmi->segment_id; | 2227 int segment_id = mbmi->segment_id; |
2264 if (cpi->common.txfm_mode == TX_MODE_SELECT && | 2228 if (cpi->common.txfm_mode == TX_MODE_SELECT && |
2265 !((cpi->common.mb_no_coeff_skip && mbmi->mb_skip_coeff) || | 2229 !((cpi->common.mb_no_coeff_skip && mbmi->mb_skip_coeff) || |
2266 (vp9_segfeature_active(&x->e_mbd, segment_id, SEG_LVL_EOB) && | 2230 (vp9_segfeature_active(&x->e_mbd, segment_id, SEG_LVL_EOB) && |
2267 vp9_get_segdata(&x->e_mbd, segment_id, SEG_LVL_EOB) == 0))) { | 2231 vp9_get_segdata(&x->e_mbd, segment_id, SEG_LVL_EOB) == 0))) { |
| 2232 assert(mbmi->txfm_size <= TX_16X16); |
2268 if (mbmi->mode != B_PRED && mbmi->mode != I8X8_PRED && | 2233 if (mbmi->mode != B_PRED && mbmi->mode != I8X8_PRED && |
2269 mbmi->mode != SPLITMV) { | 2234 mbmi->mode != SPLITMV) { |
2270 cpi->txfm_count[mbmi->txfm_size]++; | 2235 cpi->txfm_count_16x16p[mbmi->txfm_size]++; |
2271 } else if (mbmi->mode == I8X8_PRED || | 2236 } else if (mbmi->mode == I8X8_PRED || |
2272 (mbmi->mode == SPLITMV && | 2237 (mbmi->mode == SPLITMV && |
2273 mbmi->partitioning != PARTITIONING_4X4)) { | 2238 mbmi->partitioning != PARTITIONING_4X4)) { |
2274 cpi->txfm_count_8x8p[mbmi->txfm_size]++; | 2239 cpi->txfm_count_8x8p[mbmi->txfm_size]++; |
2275 } | 2240 } |
2276 } else if (mbmi->mode != B_PRED && mbmi->mode != I8X8_PRED && | 2241 } else if (mbmi->mode != B_PRED && mbmi->mode != I8X8_PRED && |
2277 mbmi->mode != SPLITMV && cpi->common.txfm_mode >= ALLOW_16X16) { | 2242 mbmi->mode != SPLITMV && cpi->common.txfm_mode >= ALLOW_16X16) { |
2278 mbmi->txfm_size = TX_16X16; | 2243 mbmi->txfm_size = TX_16X16; |
2279 } else if (mbmi->mode != B_PRED && | 2244 } else if (mbmi->mode != B_PRED && |
2280 !(mbmi->mode == SPLITMV && | 2245 !(mbmi->mode == SPLITMV && |
2281 mbmi->partitioning == PARTITIONING_4X4) && | 2246 mbmi->partitioning == PARTITIONING_4X4) && |
2282 cpi->common.txfm_mode >= ALLOW_8X8) { | 2247 cpi->common.txfm_mode >= ALLOW_8X8) { |
2283 mbmi->txfm_size = TX_8X8; | 2248 mbmi->txfm_size = TX_8X8; |
2284 } else { | 2249 } else { |
2285 mbmi->txfm_size = TX_4X4; | 2250 mbmi->txfm_size = TX_4X4; |
2286 } | 2251 } |
2287 } | 2252 } |
2288 } | 2253 } |
2289 | 2254 |
2290 #if CONFIG_SUPERBLOCKS | 2255 static void encode_superblock32(VP9_COMP *cpi, TOKENEXTRA **t, |
2291 static void encode_superblock(VP9_COMP *cpi, MACROBLOCK *x, | 2256 int recon_yoffset, int recon_uvoffset, |
2292 TOKENEXTRA **t, int recon_yoffset, | 2257 int output_enabled, int mb_row, int mb_col) { |
2293 int recon_uvoffset, int mb_col, int mb_row) { | |
2294 VP9_COMMON *const cm = &cpi->common; | 2258 VP9_COMMON *const cm = &cpi->common; |
| 2259 MACROBLOCK *const x = &cpi->mb; |
2295 MACROBLOCKD *const xd = &x->e_mbd; | 2260 MACROBLOCKD *const xd = &x->e_mbd; |
2296 const uint8_t *src = x->src.y_buffer; | 2261 const uint8_t *src = x->src.y_buffer; |
2297 uint8_t *dst = xd->dst.y_buffer; | 2262 uint8_t *dst = xd->dst.y_buffer; |
2298 const uint8_t *usrc = x->src.u_buffer; | 2263 const uint8_t *usrc = x->src.u_buffer; |
2299 uint8_t *udst = xd->dst.u_buffer; | 2264 uint8_t *udst = xd->dst.u_buffer; |
2300 const uint8_t *vsrc = x->src.v_buffer; | 2265 const uint8_t *vsrc = x->src.v_buffer; |
2301 uint8_t *vdst = xd->dst.v_buffer; | 2266 uint8_t *vdst = xd->dst.v_buffer; |
2302 int src_y_stride = x->src.y_stride, dst_y_stride = xd->dst.y_stride; | 2267 int src_y_stride = x->src.y_stride, dst_y_stride = xd->dst.y_stride; |
2303 int src_uv_stride = x->src.uv_stride, dst_uv_stride = xd->dst.uv_stride; | 2268 int src_uv_stride = x->src.uv_stride, dst_uv_stride = xd->dst.uv_stride; |
2304 int seg_ref_active; | |
2305 unsigned char ref_pred_flag; | 2269 unsigned char ref_pred_flag; |
2306 int n; | 2270 int n; |
2307 TOKENEXTRA *tp[4]; | 2271 TOKENEXTRA *tp[4]; |
2308 int skip[4]; | 2272 int skip[4]; |
2309 MODE_INFO *mi = x->e_mbd.mode_info_context; | 2273 MODE_INFO *mi = x->e_mbd.mode_info_context; |
2310 unsigned int segment_id = mi->mbmi.segment_id; | 2274 unsigned int segment_id = mi->mbmi.segment_id; |
2311 ENTROPY_CONTEXT_PLANES ta[4], tl[4]; | 2275 ENTROPY_CONTEXT_PLANES ta[4], tl[4]; |
2312 | 2276 const int mis = cm->mode_info_stride; |
2313 x->skip = 0; | |
2314 | 2277 |
2315 if (cm->frame_type == KEY_FRAME) { | 2278 if (cm->frame_type == KEY_FRAME) { |
2316 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { | 2279 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { |
2317 adjust_act_zbin(cpi, x); | 2280 adjust_act_zbin(cpi, x); |
2318 vp9_update_zbin_extra(cpi, x); | 2281 vp9_update_zbin_extra(cpi, x); |
2319 } | 2282 } |
2320 } else { | 2283 } else { |
2321 vp9_setup_interp_filters(xd, xd->mode_info_context->mbmi.interp_filter, cm); | 2284 vp9_setup_interp_filters(xd, xd->mode_info_context->mbmi.interp_filter, cm); |
2322 | 2285 |
2323 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { | 2286 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { |
(...skipping 13 matching lines...) Expand all Loading... |
2337 cpi->zbin_mode_boost = LF_ZEROMV_ZBIN_BOOST; | 2300 cpi->zbin_mode_boost = LF_ZEROMV_ZBIN_BOOST; |
2338 } else if (xd->mode_info_context->mbmi.mode == SPLITMV) | 2301 } else if (xd->mode_info_context->mbmi.mode == SPLITMV) |
2339 cpi->zbin_mode_boost = 0; | 2302 cpi->zbin_mode_boost = 0; |
2340 else | 2303 else |
2341 cpi->zbin_mode_boost = MV_ZBIN_BOOST; | 2304 cpi->zbin_mode_boost = MV_ZBIN_BOOST; |
2342 } | 2305 } |
2343 } | 2306 } |
2344 | 2307 |
2345 vp9_update_zbin_extra(cpi, x); | 2308 vp9_update_zbin_extra(cpi, x); |
2346 | 2309 |
2347 seg_ref_active = vp9_segfeature_active(xd, segment_id, SEG_LVL_REF_FRAME); | |
2348 | |
2349 // SET VARIOUS PREDICTION FLAGS | 2310 // SET VARIOUS PREDICTION FLAGS |
2350 | |
2351 // Did the chosen reference frame match its predicted value. | 2311 // Did the chosen reference frame match its predicted value. |
2352 ref_pred_flag = ((xd->mode_info_context->mbmi.ref_frame == | 2312 ref_pred_flag = ((xd->mode_info_context->mbmi.ref_frame == |
2353 vp9_get_pred_ref(cm, xd))); | 2313 vp9_get_pred_ref(cm, xd))); |
2354 vp9_set_pred_flag(xd, PRED_REF, ref_pred_flag); | 2314 vp9_set_pred_flag(xd, PRED_REF, ref_pred_flag); |
2355 } | 2315 } |
2356 | 2316 |
2357 | 2317 |
2358 if (xd->mode_info_context->mbmi.ref_frame == INTRA_FRAME) { | 2318 if (xd->mode_info_context->mbmi.ref_frame == INTRA_FRAME) { |
2359 vp9_build_intra_predictors_sby_s(&x->e_mbd); | 2319 vp9_build_intra_predictors_sby_s(&x->e_mbd); |
2360 vp9_build_intra_predictors_sbuv_s(&x->e_mbd); | 2320 vp9_build_intra_predictors_sbuv_s(&x->e_mbd); |
2361 sum_intra_stats(cpi, x); | 2321 if (output_enabled) |
| 2322 sum_intra_stats(cpi, x); |
2362 } else { | 2323 } else { |
2363 int ref_fb_idx; | 2324 int ref_fb_idx; |
2364 | 2325 |
2365 assert(cm->frame_type != KEY_FRAME); | 2326 assert(cm->frame_type != KEY_FRAME); |
2366 | 2327 |
2367 if (xd->mode_info_context->mbmi.ref_frame == LAST_FRAME) | 2328 if (xd->mode_info_context->mbmi.ref_frame == LAST_FRAME) |
2368 ref_fb_idx = cpi->common.lst_fb_idx; | 2329 ref_fb_idx = cpi->common.lst_fb_idx; |
2369 else if (xd->mode_info_context->mbmi.ref_frame == GOLDEN_FRAME) | 2330 else if (xd->mode_info_context->mbmi.ref_frame == GOLDEN_FRAME) |
2370 ref_fb_idx = cpi->common.gld_fb_idx; | 2331 ref_fb_idx = cpi->common.gld_fb_idx; |
2371 else | 2332 else |
(...skipping 19 matching lines...) Expand all Loading... |
2391 recon_uvoffset; | 2352 recon_uvoffset; |
2392 xd->second_pre.v_buffer = cpi->common.yv12_fb[second_ref_fb_idx].v_buffer
+ | 2353 xd->second_pre.v_buffer = cpi->common.yv12_fb[second_ref_fb_idx].v_buffer
+ |
2393 recon_uvoffset; | 2354 recon_uvoffset; |
2394 } | 2355 } |
2395 | 2356 |
2396 vp9_build_inter32x32_predictors_sb(xd, xd->dst.y_buffer, | 2357 vp9_build_inter32x32_predictors_sb(xd, xd->dst.y_buffer, |
2397 xd->dst.u_buffer, xd->dst.v_buffer, | 2358 xd->dst.u_buffer, xd->dst.v_buffer, |
2398 xd->dst.y_stride, xd->dst.uv_stride); | 2359 xd->dst.y_stride, xd->dst.uv_stride); |
2399 } | 2360 } |
2400 | 2361 |
2401 for (n = 0; n < 4; n++) { | 2362 if (xd->mode_info_context->mbmi.txfm_size == TX_32X32) { |
2402 int x_idx = n & 1, y_idx = n >> 1; | |
2403 | |
2404 xd->left_context = cm->left_context + y_idx; | |
2405 xd->above_context = cm->above_context + mb_col + x_idx; | |
2406 memcpy(&ta[n], xd->above_context, sizeof(ta[n])); | |
2407 memcpy(&tl[n], xd->left_context, sizeof(tl[n])); | |
2408 tp[n] = *t; | |
2409 xd->mode_info_context = mi + x_idx + y_idx * cm->mode_info_stride; | |
2410 | |
2411 vp9_subtract_mby_s_c(x->src_diff, | |
2412 src + x_idx * 16 + y_idx * 16 * src_y_stride, | |
2413 src_y_stride, | |
2414 dst + x_idx * 16 + y_idx * 16 * dst_y_stride, | |
2415 dst_y_stride); | |
2416 vp9_subtract_mbuv_s_c(x->src_diff, | |
2417 usrc + x_idx * 8 + y_idx * 8 * src_uv_stride, | |
2418 vsrc + x_idx * 8 + y_idx * 8 * src_uv_stride, | |
2419 src_uv_stride, | |
2420 udst + x_idx * 8 + y_idx * 8 * dst_uv_stride, | |
2421 vdst + x_idx * 8 + y_idx * 8 * dst_uv_stride, | |
2422 dst_uv_stride); | |
2423 vp9_fidct_mb(x); | |
2424 vp9_recon_mby_s_c(&x->e_mbd, | |
2425 dst + x_idx * 16 + y_idx * 16 * dst_y_stride); | |
2426 vp9_recon_mbuv_s_c(&x->e_mbd, | |
2427 udst + x_idx * 8 + y_idx * 8 * dst_uv_stride, | |
2428 vdst + x_idx * 8 + y_idx * 8 * dst_uv_stride); | |
2429 | |
2430 if (!x->skip) { | 2363 if (!x->skip) { |
2431 vp9_tokenize_mb(cpi, &x->e_mbd, t, 0); | 2364 vp9_subtract_sby_s_c(x->sb_coeff_data.src_diff, src, src_y_stride, |
2432 skip[n] = xd->mode_info_context->mbmi.mb_skip_coeff; | 2365 dst, dst_y_stride); |
| 2366 vp9_subtract_sbuv_s_c(x->sb_coeff_data.src_diff, |
| 2367 usrc, vsrc, src_uv_stride, |
| 2368 udst, vdst, dst_uv_stride); |
| 2369 vp9_transform_sby_32x32(x); |
| 2370 vp9_transform_sbuv_16x16(x); |
| 2371 vp9_quantize_sby_32x32(x); |
| 2372 vp9_quantize_sbuv_16x16(x); |
| 2373 // TODO(rbultje): trellis optimize |
| 2374 vp9_inverse_transform_sbuv_16x16(&x->e_mbd.sb_coeff_data); |
| 2375 vp9_inverse_transform_sby_32x32(&x->e_mbd.sb_coeff_data); |
| 2376 vp9_recon_sby_s_c(&x->e_mbd, dst); |
| 2377 vp9_recon_sbuv_s_c(&x->e_mbd, udst, vdst); |
| 2378 |
| 2379 vp9_tokenize_sb(cpi, &x->e_mbd, t, !output_enabled); |
2433 } else { | 2380 } else { |
2434 int mb_skip_context = | 2381 int mb_skip_context = |
2435 cpi->common.mb_no_coeff_skip ? | 2382 cpi->common.mb_no_coeff_skip ? |
| 2383 (mi - 1)->mbmi.mb_skip_coeff + |
| 2384 (mi - mis)->mbmi.mb_skip_coeff : |
| 2385 0; |
| 2386 mi->mbmi.mb_skip_coeff = 1; |
| 2387 if (cm->mb_no_coeff_skip) { |
| 2388 if (output_enabled) |
| 2389 cpi->skip_true_count[mb_skip_context]++; |
| 2390 vp9_fix_contexts_sb(xd); |
| 2391 } else { |
| 2392 vp9_stuff_sb(cpi, xd, t, !output_enabled); |
| 2393 if (output_enabled) |
| 2394 cpi->skip_false_count[mb_skip_context]++; |
| 2395 } |
| 2396 } |
| 2397 |
| 2398 // copy skip flag on all mb_mode_info contexts in this SB |
| 2399 // if this was a skip at this txfm size |
| 2400 if (mb_col < cm->mb_cols - 1) |
| 2401 mi[1].mbmi.mb_skip_coeff = mi->mbmi.mb_skip_coeff; |
| 2402 if (mb_row < cm->mb_rows - 1) { |
| 2403 mi[mis].mbmi.mb_skip_coeff = mi->mbmi.mb_skip_coeff; |
| 2404 if (mb_col < cm->mb_cols - 1) |
| 2405 mi[mis + 1].mbmi.mb_skip_coeff = mi->mbmi.mb_skip_coeff; |
| 2406 } |
| 2407 skip[0] = skip[2] = skip[1] = skip[3] = mi->mbmi.mb_skip_coeff; |
| 2408 } else { |
| 2409 for (n = 0; n < 4; n++) { |
| 2410 int x_idx = n & 1, y_idx = n >> 1; |
| 2411 |
| 2412 xd->left_context = cm->left_context + y_idx + (mb_row & 2); |
| 2413 xd->above_context = cm->above_context + mb_col + x_idx; |
| 2414 memcpy(&ta[n], xd->above_context, sizeof(ta[n])); |
| 2415 memcpy(&tl[n], xd->left_context, sizeof(tl[n])); |
| 2416 tp[n] = *t; |
| 2417 xd->mode_info_context = mi + x_idx + y_idx * mis; |
| 2418 |
| 2419 if (!x->skip) { |
| 2420 vp9_subtract_mby_s_c(x->src_diff, |
| 2421 src + x_idx * 16 + y_idx * 16 * src_y_stride, |
| 2422 src_y_stride, |
| 2423 dst + x_idx * 16 + y_idx * 16 * dst_y_stride, |
| 2424 dst_y_stride); |
| 2425 vp9_subtract_mbuv_s_c(x->src_diff, |
| 2426 usrc + x_idx * 8 + y_idx * 8 * src_uv_stride, |
| 2427 vsrc + x_idx * 8 + y_idx * 8 * src_uv_stride, |
| 2428 src_uv_stride, |
| 2429 udst + x_idx * 8 + y_idx * 8 * dst_uv_stride, |
| 2430 vdst + x_idx * 8 + y_idx * 8 * dst_uv_stride, |
| 2431 dst_uv_stride); |
| 2432 vp9_fidct_mb(x); |
| 2433 vp9_recon_mby_s_c(&x->e_mbd, |
| 2434 dst + x_idx * 16 + y_idx * 16 * dst_y_stride); |
| 2435 vp9_recon_mbuv_s_c(&x->e_mbd, |
| 2436 udst + x_idx * 8 + y_idx * 8 * dst_uv_stride, |
| 2437 vdst + x_idx * 8 + y_idx * 8 * dst_uv_stride); |
| 2438 |
| 2439 vp9_tokenize_mb(cpi, &x->e_mbd, t, !output_enabled); |
| 2440 skip[n] = xd->mode_info_context->mbmi.mb_skip_coeff; |
| 2441 } else { |
| 2442 int mb_skip_context = cpi->common.mb_no_coeff_skip ? |
| 2443 (x->e_mbd.mode_info_context - 1)->mbmi.mb_skip_coeff + |
| 2444 (x->e_mbd.mode_info_context - mis)->mbmi.mb_skip_coeff : |
| 2445 0; |
| 2446 xd->mode_info_context->mbmi.mb_skip_coeff = skip[n] = 1; |
| 2447 if (cpi->common.mb_no_coeff_skip) { |
| 2448 // TODO(rbultje) this should be done per-sb instead of per-mb? |
| 2449 if (output_enabled) |
| 2450 cpi->skip_true_count[mb_skip_context]++; |
| 2451 vp9_reset_mb_tokens_context(xd); |
| 2452 } else { |
| 2453 vp9_stuff_mb(cpi, xd, t, !output_enabled); |
| 2454 // TODO(rbultje) this should be done per-sb instead of per-mb? |
| 2455 if (output_enabled) |
| 2456 cpi->skip_false_count[mb_skip_context]++; |
| 2457 } |
| 2458 } |
| 2459 } |
| 2460 |
| 2461 xd->mode_info_context = mi; |
| 2462 update_sb_skip_coeff_state(cpi, ta, tl, tp, t, skip, output_enabled); |
| 2463 } |
| 2464 |
| 2465 if (output_enabled) { |
| 2466 if (cm->txfm_mode == TX_MODE_SELECT && |
| 2467 !((cm->mb_no_coeff_skip && skip[0] && skip[1] && skip[2] && skip[3]) || |
| 2468 (vp9_segfeature_active(xd, segment_id, SEG_LVL_EOB) && |
| 2469 vp9_get_segdata(xd, segment_id, SEG_LVL_EOB) == 0))) { |
| 2470 cpi->txfm_count_32x32p[mi->mbmi.txfm_size]++; |
| 2471 } else { |
| 2472 TX_SIZE sz = (cm->txfm_mode == TX_MODE_SELECT) ? |
| 2473 TX_32X32 : |
| 2474 cm->txfm_mode; |
| 2475 mi->mbmi.txfm_size = sz; |
| 2476 if (mb_col < cm->mb_cols - 1) |
| 2477 mi[1].mbmi.txfm_size = sz; |
| 2478 if (mb_row < cm->mb_rows - 1) { |
| 2479 mi[mis].mbmi.txfm_size = sz; |
| 2480 if (mb_col < cm->mb_cols - 1) |
| 2481 mi[mis + 1].mbmi.txfm_size = sz; |
| 2482 } |
| 2483 } |
| 2484 } |
| 2485 } |
| 2486 |
| 2487 static void encode_superblock64(VP9_COMP *cpi, TOKENEXTRA **t, |
| 2488 int recon_yoffset, int recon_uvoffset, |
| 2489 int output_enabled, int mb_row, int mb_col) { |
| 2490 VP9_COMMON *const cm = &cpi->common; |
| 2491 MACROBLOCK *const x = &cpi->mb; |
| 2492 MACROBLOCKD *const xd = &x->e_mbd; |
| 2493 const uint8_t *src = x->src.y_buffer; |
| 2494 uint8_t *dst = xd->dst.y_buffer; |
| 2495 const uint8_t *usrc = x->src.u_buffer; |
| 2496 uint8_t *udst = xd->dst.u_buffer; |
| 2497 const uint8_t *vsrc = x->src.v_buffer; |
| 2498 uint8_t *vdst = xd->dst.v_buffer; |
| 2499 int src_y_stride = x->src.y_stride, dst_y_stride = xd->dst.y_stride; |
| 2500 int src_uv_stride = x->src.uv_stride, dst_uv_stride = xd->dst.uv_stride; |
| 2501 unsigned char ref_pred_flag; |
| 2502 int n; |
| 2503 TOKENEXTRA *tp[16]; |
| 2504 int skip[16]; |
| 2505 MODE_INFO *mi = x->e_mbd.mode_info_context; |
| 2506 unsigned int segment_id = mi->mbmi.segment_id; |
| 2507 ENTROPY_CONTEXT_PLANES ta[16], tl[16]; |
| 2508 const int mis = cm->mode_info_stride; |
| 2509 |
| 2510 if (cm->frame_type == KEY_FRAME) { |
| 2511 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { |
| 2512 adjust_act_zbin(cpi, x); |
| 2513 vp9_update_zbin_extra(cpi, x); |
| 2514 } |
| 2515 } else { |
| 2516 vp9_setup_interp_filters(xd, xd->mode_info_context->mbmi.interp_filter, cm); |
| 2517 |
| 2518 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { |
| 2519 // Adjust the zbin based on this MB rate. |
| 2520 adjust_act_zbin(cpi, x); |
| 2521 } |
| 2522 |
| 2523 // Experimental code. Special case for gf and arf zeromv modes. |
| 2524 // Increase zbin size to suppress noise |
| 2525 cpi->zbin_mode_boost = 0; |
| 2526 if (cpi->zbin_mode_boost_enabled) { |
| 2527 if (xd->mode_info_context->mbmi.ref_frame != INTRA_FRAME) { |
| 2528 if (xd->mode_info_context->mbmi.mode == ZEROMV) { |
| 2529 if (xd->mode_info_context->mbmi.ref_frame != LAST_FRAME) |
| 2530 cpi->zbin_mode_boost = GF_ZEROMV_ZBIN_BOOST; |
| 2531 else |
| 2532 cpi->zbin_mode_boost = LF_ZEROMV_ZBIN_BOOST; |
| 2533 } else if (xd->mode_info_context->mbmi.mode == SPLITMV) { |
| 2534 cpi->zbin_mode_boost = 0; |
| 2535 } else { |
| 2536 cpi->zbin_mode_boost = MV_ZBIN_BOOST; |
| 2537 } |
| 2538 } |
| 2539 } |
| 2540 |
| 2541 vp9_update_zbin_extra(cpi, x); |
| 2542 |
| 2543 // Did the chosen reference frame match its predicted value. |
| 2544 ref_pred_flag = ((xd->mode_info_context->mbmi.ref_frame == |
| 2545 vp9_get_pred_ref(cm, xd))); |
| 2546 vp9_set_pred_flag(xd, PRED_REF, ref_pred_flag); |
| 2547 } |
| 2548 |
| 2549 if (xd->mode_info_context->mbmi.ref_frame == INTRA_FRAME) { |
| 2550 vp9_build_intra_predictors_sb64y_s(&x->e_mbd); |
| 2551 vp9_build_intra_predictors_sb64uv_s(&x->e_mbd); |
| 2552 if (output_enabled) |
| 2553 sum_intra_stats(cpi, x); |
| 2554 } else { |
| 2555 int ref_fb_idx; |
| 2556 |
| 2557 assert(cm->frame_type != KEY_FRAME); |
| 2558 |
| 2559 if (xd->mode_info_context->mbmi.ref_frame == LAST_FRAME) |
| 2560 ref_fb_idx = cpi->common.lst_fb_idx; |
| 2561 else if (xd->mode_info_context->mbmi.ref_frame == GOLDEN_FRAME) |
| 2562 ref_fb_idx = cpi->common.gld_fb_idx; |
| 2563 else |
| 2564 ref_fb_idx = cpi->common.alt_fb_idx; |
| 2565 |
| 2566 xd->pre.y_buffer = |
| 2567 cpi->common.yv12_fb[ref_fb_idx].y_buffer + recon_yoffset; |
| 2568 xd->pre.u_buffer = |
| 2569 cpi->common.yv12_fb[ref_fb_idx].u_buffer + recon_uvoffset; |
| 2570 xd->pre.v_buffer = |
| 2571 cpi->common.yv12_fb[ref_fb_idx].v_buffer + recon_uvoffset; |
| 2572 |
| 2573 if (xd->mode_info_context->mbmi.second_ref_frame > 0) { |
| 2574 int second_ref_fb_idx; |
| 2575 |
| 2576 if (xd->mode_info_context->mbmi.second_ref_frame == LAST_FRAME) |
| 2577 second_ref_fb_idx = cpi->common.lst_fb_idx; |
| 2578 else if (xd->mode_info_context->mbmi.second_ref_frame == GOLDEN_FRAME) |
| 2579 second_ref_fb_idx = cpi->common.gld_fb_idx; |
| 2580 else |
| 2581 second_ref_fb_idx = cpi->common.alt_fb_idx; |
| 2582 |
| 2583 xd->second_pre.y_buffer = |
| 2584 cpi->common.yv12_fb[second_ref_fb_idx].y_buffer + recon_yoffset; |
| 2585 xd->second_pre.u_buffer = |
| 2586 cpi->common.yv12_fb[second_ref_fb_idx].u_buffer + recon_uvoffset; |
| 2587 xd->second_pre.v_buffer = |
| 2588 cpi->common.yv12_fb[second_ref_fb_idx].v_buffer + recon_uvoffset; |
| 2589 } |
| 2590 |
| 2591 vp9_build_inter64x64_predictors_sb(xd, xd->dst.y_buffer, |
| 2592 xd->dst.u_buffer, xd->dst.v_buffer, |
| 2593 xd->dst.y_stride, xd->dst.uv_stride); |
| 2594 } |
| 2595 |
| 2596 if (xd->mode_info_context->mbmi.txfm_size == TX_32X32) { |
| 2597 int n; |
| 2598 |
| 2599 for (n = 0; n < 4; n++) { |
| 2600 int x_idx = n & 1, y_idx = n >> 1; |
| 2601 |
| 2602 xd->mode_info_context = mi + x_idx * 2 + mis * y_idx * 2; |
| 2603 xd->left_context = cm->left_context + (y_idx << 1); |
| 2604 xd->above_context = cm->above_context + mb_col + (x_idx << 1); |
| 2605 memcpy(&ta[n * 2], xd->above_context, sizeof(*ta) * 2); |
| 2606 memcpy(&tl[n * 2], xd->left_context, sizeof(*tl) * 2); |
| 2607 tp[n] = *t; |
| 2608 xd->mode_info_context = mi + x_idx * 2 + y_idx * mis * 2; |
| 2609 if (!x->skip) { |
| 2610 vp9_subtract_sby_s_c(x->sb_coeff_data.src_diff, |
| 2611 src + x_idx * 32 + y_idx * 32 * src_y_stride, |
| 2612 src_y_stride, |
| 2613 dst + x_idx * 32 + y_idx * 32 * dst_y_stride, |
| 2614 dst_y_stride); |
| 2615 vp9_subtract_sbuv_s_c(x->sb_coeff_data.src_diff, |
| 2616 usrc + x_idx * 16 + y_idx * 16 * src_uv_stride, |
| 2617 vsrc + x_idx * 16 + y_idx * 16 * src_uv_stride, |
| 2618 src_uv_stride, |
| 2619 udst + x_idx * 16 + y_idx * 16 * dst_uv_stride, |
| 2620 vdst + x_idx * 16 + y_idx * 16 * dst_uv_stride, |
| 2621 dst_uv_stride); |
| 2622 vp9_transform_sby_32x32(x); |
| 2623 vp9_transform_sbuv_16x16(x); |
| 2624 vp9_quantize_sby_32x32(x); |
| 2625 vp9_quantize_sbuv_16x16(x); |
| 2626 // TODO(rbultje): trellis optimize |
| 2627 vp9_inverse_transform_sbuv_16x16(&x->e_mbd.sb_coeff_data); |
| 2628 vp9_inverse_transform_sby_32x32(&x->e_mbd.sb_coeff_data); |
| 2629 vp9_recon_sby_s_c(&x->e_mbd, |
| 2630 dst + 32 * x_idx + 32 * y_idx * dst_y_stride); |
| 2631 vp9_recon_sbuv_s_c(&x->e_mbd, |
| 2632 udst + x_idx * 16 + y_idx * 16 * dst_uv_stride, |
| 2633 vdst + x_idx * 16 + y_idx * 16 * dst_uv_stride); |
| 2634 |
| 2635 vp9_tokenize_sb(cpi, &x->e_mbd, t, !output_enabled); |
| 2636 } else { |
| 2637 int mb_skip_context = cpi->common.mb_no_coeff_skip ? |
| 2638 (mi - 1)->mbmi.mb_skip_coeff + |
| 2639 (mi - mis)->mbmi.mb_skip_coeff : 0; |
| 2640 xd->mode_info_context->mbmi.mb_skip_coeff = 1; |
| 2641 if (cm->mb_no_coeff_skip) { |
| 2642 if (output_enabled) |
| 2643 cpi->skip_true_count[mb_skip_context]++; |
| 2644 vp9_fix_contexts_sb(xd); |
| 2645 } else { |
| 2646 vp9_stuff_sb(cpi, xd, t, !output_enabled); |
| 2647 if (output_enabled) |
| 2648 cpi->skip_false_count[mb_skip_context]++; |
| 2649 } |
| 2650 } |
| 2651 |
| 2652 // copy skip flag on all mb_mode_info contexts in this SB |
| 2653 // if this was a skip at this txfm size |
| 2654 if (mb_col + x_idx * 2 < cm->mb_cols - 1) |
| 2655 mi[mis * y_idx * 2 + x_idx * 2 + 1].mbmi.mb_skip_coeff = |
| 2656 mi[mis * y_idx * 2 + x_idx * 2].mbmi.mb_skip_coeff; |
| 2657 if (mb_row + y_idx * 2 < cm->mb_rows - 1) { |
| 2658 mi[mis * y_idx * 2 + x_idx * 2 + mis].mbmi.mb_skip_coeff = |
| 2659 mi[mis * y_idx * 2 + x_idx * 2].mbmi.mb_skip_coeff; |
| 2660 if (mb_col + x_idx * 2 < cm->mb_cols - 1) |
| 2661 mi[mis * y_idx * 2 + x_idx * 2 + mis + 1].mbmi.mb_skip_coeff = |
| 2662 mi[mis * y_idx * 2 + x_idx * 2].mbmi.mb_skip_coeff; |
| 2663 } |
| 2664 skip[n] = xd->mode_info_context->mbmi.mb_skip_coeff; |
| 2665 } |
| 2666 } else { |
| 2667 for (n = 0; n < 16; n++) { |
| 2668 const int x_idx = n & 3, y_idx = n >> 2; |
| 2669 |
| 2670 xd->left_context = cm->left_context + y_idx; |
| 2671 xd->above_context = cm->above_context + mb_col + x_idx; |
| 2672 memcpy(&ta[n], xd->above_context, sizeof(ta[n])); |
| 2673 memcpy(&tl[n], xd->left_context, sizeof(tl[n])); |
| 2674 tp[n] = *t; |
| 2675 xd->mode_info_context = mi + x_idx + y_idx * mis; |
| 2676 |
| 2677 if (!x->skip) { |
| 2678 vp9_subtract_mby_s_c(x->src_diff, |
| 2679 src + x_idx * 16 + y_idx * 16 * src_y_stride, |
| 2680 src_y_stride, |
| 2681 dst + x_idx * 16 + y_idx * 16 * dst_y_stride, |
| 2682 dst_y_stride); |
| 2683 vp9_subtract_mbuv_s_c(x->src_diff, |
| 2684 usrc + x_idx * 8 + y_idx * 8 * src_uv_stride, |
| 2685 vsrc + x_idx * 8 + y_idx * 8 * src_uv_stride, |
| 2686 src_uv_stride, |
| 2687 udst + x_idx * 8 + y_idx * 8 * dst_uv_stride, |
| 2688 vdst + x_idx * 8 + y_idx * 8 * dst_uv_stride, |
| 2689 dst_uv_stride); |
| 2690 vp9_fidct_mb(x); |
| 2691 vp9_recon_mby_s_c(&x->e_mbd, |
| 2692 dst + x_idx * 16 + y_idx * 16 * dst_y_stride); |
| 2693 vp9_recon_mbuv_s_c(&x->e_mbd, |
| 2694 udst + x_idx * 8 + y_idx * 8 * dst_uv_stride, |
| 2695 vdst + x_idx * 8 + y_idx * 8 * dst_uv_stride); |
| 2696 |
| 2697 vp9_tokenize_mb(cpi, &x->e_mbd, t, !output_enabled); |
| 2698 skip[n] = xd->mode_info_context->mbmi.mb_skip_coeff; |
| 2699 } else { |
| 2700 int mb_skip_context = cpi->common.mb_no_coeff_skip ? |
2436 (x->e_mbd.mode_info_context - 1)->mbmi.mb_skip_coeff + | 2701 (x->e_mbd.mode_info_context - 1)->mbmi.mb_skip_coeff + |
2437 (x->e_mbd.mode_info_context - cpi->common.mode_info_stride)->mbmi.mb
_skip_coeff : | 2702 (x->e_mbd.mode_info_context - mis)->mbmi.mb_skip_coeff : 0; |
2438 0; | 2703 xd->mode_info_context->mbmi.mb_skip_coeff = skip[n] = 1; |
2439 xd->mode_info_context->mbmi.mb_skip_coeff = skip[n] = 1; | 2704 if (cpi->common.mb_no_coeff_skip) { |
2440 if (cpi->common.mb_no_coeff_skip) { | 2705 // TODO(rbultje) this should be done per-sb instead of per-mb? |
2441 // TODO(rbultje) this should be done per-sb instead of per-mb? | 2706 if (output_enabled) |
2442 cpi->skip_true_count[mb_skip_context]++; | 2707 cpi->skip_true_count[mb_skip_context]++; |
2443 vp9_fix_contexts(xd); | 2708 vp9_reset_mb_tokens_context(xd); |
2444 } else { | 2709 } else { |
2445 vp9_stuff_mb(cpi, xd, t, 0); | 2710 vp9_stuff_mb(cpi, xd, t, !output_enabled); |
2446 // TODO(rbultje) this should be done per-sb instead of per-mb? | 2711 // TODO(rbultje) this should be done per-sb instead of per-mb? |
2447 cpi->skip_false_count[mb_skip_context]++; | 2712 if (output_enabled) |
| 2713 cpi->skip_false_count[mb_skip_context]++; |
| 2714 } |
2448 } | 2715 } |
2449 } | 2716 } |
2450 } | 2717 } |
2451 | 2718 |
2452 xd->mode_info_context = mi; | 2719 xd->mode_info_context = mi; |
2453 update_sb_skip_coeff_state(cpi, x, ta, tl, tp, t, skip); | 2720 update_sb64_skip_coeff_state(cpi, ta, tl, tp, t, skip, output_enabled); |
2454 if (cm->txfm_mode == TX_MODE_SELECT && | 2721 |
2455 !((cm->mb_no_coeff_skip && skip[0] && skip[1] && skip[2] && skip[3]) || | 2722 if (output_enabled) { |
2456 (vp9_segfeature_active(xd, segment_id, SEG_LVL_EOB) && | 2723 if (cm->txfm_mode == TX_MODE_SELECT && |
2457 vp9_get_segdata(xd, segment_id, SEG_LVL_EOB) == 0))) { | 2724 !((cm->mb_no_coeff_skip && |
2458 cpi->txfm_count[mi->mbmi.txfm_size]++; | 2725 ((mi->mbmi.txfm_size == TX_32X32 && |
2459 } else { | 2726 skip[0] && skip[1] && skip[2] && skip[3]) || |
2460 TX_SIZE sz = (cm->txfm_mode == TX_MODE_SELECT) ? TX_16X16 : cm->txfm_mode; | 2727 (mi->mbmi.txfm_size != TX_32X32 && |
2461 mi->mbmi.txfm_size = sz; | 2728 skip[0] && skip[1] && skip[2] && skip[3] && |
2462 if (mb_col < cm->mb_cols - 1) | 2729 skip[4] && skip[5] && skip[6] && skip[7] && |
2463 mi[1].mbmi.txfm_size = sz; | 2730 skip[8] && skip[9] && skip[10] && skip[11] && |
2464 if (mb_row < cm->mb_rows - 1) { | 2731 skip[12] && skip[13] && skip[14] && skip[15]))) || |
2465 mi[cm->mode_info_stride].mbmi.txfm_size = sz; | 2732 (vp9_segfeature_active(xd, segment_id, SEG_LVL_EOB) && |
2466 if (mb_col < cm->mb_cols - 1) | 2733 vp9_get_segdata(xd, segment_id, SEG_LVL_EOB) == 0))) { |
2467 mi[cm->mode_info_stride + 1].mbmi.txfm_size = sz; | 2734 cpi->txfm_count_32x32p[mi->mbmi.txfm_size]++; |
| 2735 } else { |
| 2736 int x, y; |
| 2737 TX_SIZE sz = (cm->txfm_mode == TX_MODE_SELECT) ? |
| 2738 TX_32X32 : |
| 2739 cm->txfm_mode; |
| 2740 for (y = 0; y < 4; y++) { |
| 2741 for (x = 0; x < 4; x++) { |
| 2742 if (mb_col + x < cm->mb_cols && mb_row + y < cm->mb_rows) { |
| 2743 mi[mis * y + x].mbmi.txfm_size = sz; |
| 2744 } |
| 2745 } |
| 2746 } |
2468 } | 2747 } |
2469 } | 2748 } |
2470 } | 2749 } |
2471 #endif | |
OLD | NEW |