OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
| 11 #include <limits.h> |
| 12 #include <math.h> |
| 13 #include <stdio.h> |
| 14 |
| 15 #include "./vp9_rtcd.h" |
11 #include "./vpx_config.h" | 16 #include "./vpx_config.h" |
12 #include "./vp9_rtcd.h" | 17 |
| 18 #include "vpx_ports/vpx_timer.h" |
| 19 |
| 20 #include "vp9/common/vp9_common.h" |
| 21 #include "vp9/common/vp9_entropy.h" |
| 22 #include "vp9/common/vp9_entropymode.h" |
| 23 #include "vp9/common/vp9_extend.h" |
| 24 #include "vp9/common/vp9_findnearmv.h" |
| 25 #include "vp9/common/vp9_mvref_common.h" |
| 26 #include "vp9/common/vp9_pred_common.h" |
| 27 #include "vp9/common/vp9_quant_common.h" |
| 28 #include "vp9/common/vp9_reconintra.h" |
| 29 #include "vp9/common/vp9_reconinter.h" |
| 30 #include "vp9/common/vp9_seg_common.h" |
| 31 #include "vp9/common/vp9_tile_common.h" |
| 32 |
13 #include "vp9/encoder/vp9_encodeframe.h" | 33 #include "vp9/encoder/vp9_encodeframe.h" |
| 34 #include "vp9/encoder/vp9_encodeintra.h" |
14 #include "vp9/encoder/vp9_encodemb.h" | 35 #include "vp9/encoder/vp9_encodemb.h" |
15 #include "vp9/encoder/vp9_encodemv.h" | 36 #include "vp9/encoder/vp9_encodemv.h" |
16 #include "vp9/common/vp9_common.h" | |
17 #include "vp9/encoder/vp9_onyx_int.h" | 37 #include "vp9/encoder/vp9_onyx_int.h" |
18 #include "vp9/common/vp9_extend.h" | 38 #include "vp9/encoder/vp9_rdopt.h" |
19 #include "vp9/common/vp9_entropy.h" | |
20 #include "vp9/common/vp9_entropymode.h" | |
21 #include "vp9/common/vp9_quant_common.h" | |
22 #include "vp9/encoder/vp9_segmentation.h" | 39 #include "vp9/encoder/vp9_segmentation.h" |
23 #include "vp9/encoder/vp9_encodeintra.h" | |
24 #include "vp9/common/vp9_reconinter.h" | |
25 #include "vp9/encoder/vp9_rdopt.h" | |
26 #include "vp9/common/vp9_findnearmv.h" | |
27 #include "vp9/common/vp9_reconintra.h" | |
28 #include "vp9/common/vp9_seg_common.h" | |
29 #include "vp9/common/vp9_tile_common.h" | |
30 #include "vp9/encoder/vp9_tokenize.h" | 40 #include "vp9/encoder/vp9_tokenize.h" |
31 #include "./vp9_rtcd.h" | |
32 #include <stdio.h> | |
33 #include <math.h> | |
34 #include <limits.h> | |
35 #include "vpx_ports/vpx_timer.h" | |
36 #include "vp9/common/vp9_pred_common.h" | |
37 #include "vp9/common/vp9_mvref_common.h" | |
38 | 41 |
39 #define DBG_PRNT_SEGMAP 0 | 42 #define DBG_PRNT_SEGMAP 0 |
40 | 43 |
41 // #define ENC_DEBUG | 44 // #define ENC_DEBUG |
42 #ifdef ENC_DEBUG | 45 #ifdef ENC_DEBUG |
43 int enc_debug = 0; | 46 int enc_debug = 0; |
44 #endif | 47 #endif |
45 | 48 |
46 static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, | 49 static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, |
47 int mi_row, int mi_col, BLOCK_SIZE_TYPE bsize); | 50 int mi_row, int mi_col, BLOCK_SIZE bsize); |
48 | 51 |
49 static void adjust_act_zbin(VP9_COMP *cpi, MACROBLOCK *x); | 52 static void adjust_act_zbin(VP9_COMP *cpi, MACROBLOCK *x); |
50 | 53 |
51 /* activity_avg must be positive, or flat regions could get a zero weight | 54 /* activity_avg must be positive, or flat regions could get a zero weight |
52 * (infinite lambda), which confounds analysis. | 55 * (infinite lambda), which confounds analysis. |
53 * This also avoids the need for divide by zero checks in | 56 * This also avoids the need for divide by zero checks in |
54 * vp9_activity_masking(). | 57 * vp9_activity_masking(). |
55 */ | 58 */ |
56 #define VP9_ACTIVITY_AVG_MIN (64) | 59 #define ACTIVITY_AVG_MIN (64) |
| 60 |
| 61 /* Motion vector component magnitude threshold for defining fast motion. */ |
| 62 #define FAST_MOTION_MV_THRESH (24) |
57 | 63 |
58 /* This is used as a reference when computing the source variance for the | 64 /* This is used as a reference when computing the source variance for the |
59 * purposes of activity masking. | 65 * purposes of activity masking. |
60 * Eventually this should be replaced by custom no-reference routines, | 66 * Eventually this should be replaced by custom no-reference routines, |
61 * which will be faster. | 67 * which will be faster. |
62 */ | 68 */ |
63 static const uint8_t VP9_VAR_OFFS[16] = {128, 128, 128, 128, 128, 128, 128, 128, | 69 static const uint8_t VP9_VAR_OFFS[64] = { |
64 128, 128, 128, 128, 128, 128, 128, 128}; | 70 128, 128, 128, 128, 128, 128, 128, 128, |
| 71 128, 128, 128, 128, 128, 128, 128, 128, |
| 72 128, 128, 128, 128, 128, 128, 128, 128, |
| 73 128, 128, 128, 128, 128, 128, 128, 128, |
| 74 128, 128, 128, 128, 128, 128, 128, 128, |
| 75 128, 128, 128, 128, 128, 128, 128, 128, |
| 76 128, 128, 128, 128, 128, 128, 128, 128, |
| 77 128, 128, 128, 128, 128, 128, 128, 128 |
| 78 }; |
| 79 |
| 80 static unsigned int get_sby_perpixel_variance(VP9_COMP *cpi, MACROBLOCK *x, |
| 81 BLOCK_SIZE bs) { |
| 82 unsigned int var, sse; |
| 83 var = cpi->fn_ptr[bs].vf(x->plane[0].src.buf, |
| 84 x->plane[0].src.stride, |
| 85 VP9_VAR_OFFS, 0, &sse); |
| 86 return (var + (1 << (num_pels_log2_lookup[bs] - 1))) >> |
| 87 num_pels_log2_lookup[bs]; |
| 88 } |
65 | 89 |
66 // Original activity measure from Tim T's code. | 90 // Original activity measure from Tim T's code. |
67 static unsigned int tt_activity_measure(VP9_COMP *cpi, MACROBLOCK *x) { | 91 static unsigned int tt_activity_measure(MACROBLOCK *x) { |
68 unsigned int act; | 92 unsigned int act; |
69 unsigned int sse; | 93 unsigned int sse; |
70 /* TODO: This could also be done over smaller areas (8x8), but that would | 94 /* TODO: This could also be done over smaller areas (8x8), but that would |
71 * require extensive changes elsewhere, as lambda is assumed to be fixed | 95 * require extensive changes elsewhere, as lambda is assumed to be fixed |
72 * over an entire MB in most of the code. | 96 * over an entire MB in most of the code. |
73 * Another option is to compute four 8x8 variances, and pick a single | 97 * Another option is to compute four 8x8 variances, and pick a single |
74 * lambda using a non-linear combination (e.g., the smallest, or second | 98 * lambda using a non-linear combination (e.g., the smallest, or second |
75 * smallest, etc.). | 99 * smallest, etc.). |
76 */ | 100 */ |
77 act = vp9_variance16x16(x->plane[0].src.buf, x->plane[0].src.stride, | 101 act = vp9_variance16x16(x->plane[0].src.buf, x->plane[0].src.stride, |
78 VP9_VAR_OFFS, 0, &sse); | 102 VP9_VAR_OFFS, 0, &sse); |
79 act <<= 4; | 103 act <<= 4; |
80 | 104 |
81 /* If the region is flat, lower the activity some more. */ | 105 /* If the region is flat, lower the activity some more. */ |
82 if (act < 8 << 12) | 106 if (act < 8 << 12) |
83 act = act < 5 << 12 ? act : 5 << 12; | 107 act = act < 5 << 12 ? act : 5 << 12; |
84 | 108 |
85 return act; | 109 return act; |
86 } | 110 } |
87 | 111 |
88 // Stub for alternative experimental activity measures. | 112 // Stub for alternative experimental activity measures. |
89 static unsigned int alt_activity_measure(VP9_COMP *cpi, MACROBLOCK *x, | 113 static unsigned int alt_activity_measure(MACROBLOCK *x, int use_dc_pred) { |
90 int use_dc_pred) { | 114 return vp9_encode_intra(x, use_dc_pred); |
91 return vp9_encode_intra(cpi, x, use_dc_pred); | |
92 } | 115 } |
93 DECLARE_ALIGNED(16, static const uint8_t, vp9_64x64_zeros[64*64]) = {0}; | 116 DECLARE_ALIGNED(16, static const uint8_t, vp9_64x64_zeros[64*64]) = {0}; |
94 | 117 |
95 // Measure the activity of the current macroblock | 118 // Measure the activity of the current macroblock |
96 // What we measure here is TBD so abstracted to this function | 119 // What we measure here is TBD so abstracted to this function |
97 #define ALT_ACT_MEASURE 1 | 120 #define ALT_ACT_MEASURE 1 |
98 static unsigned int mb_activity_measure(VP9_COMP *cpi, MACROBLOCK *x, | 121 static unsigned int mb_activity_measure(MACROBLOCK *x, int mb_row, int mb_col) { |
99 int mb_row, int mb_col) { | |
100 unsigned int mb_activity; | 122 unsigned int mb_activity; |
101 | 123 |
102 if (ALT_ACT_MEASURE) { | 124 if (ALT_ACT_MEASURE) { |
103 int use_dc_pred = (mb_col || mb_row) && (!mb_col || !mb_row); | 125 int use_dc_pred = (mb_col || mb_row) && (!mb_col || !mb_row); |
104 | 126 |
105 // Or use and alternative. | 127 // Or use and alternative. |
106 mb_activity = alt_activity_measure(cpi, x, use_dc_pred); | 128 mb_activity = alt_activity_measure(x, use_dc_pred); |
107 } else { | 129 } else { |
108 // Original activity measure from Tim T's code. | 130 // Original activity measure from Tim T's code. |
109 mb_activity = tt_activity_measure(cpi, x); | 131 mb_activity = tt_activity_measure(x); |
110 } | 132 } |
111 | 133 |
112 if (mb_activity < VP9_ACTIVITY_AVG_MIN) | 134 if (mb_activity < ACTIVITY_AVG_MIN) |
113 mb_activity = VP9_ACTIVITY_AVG_MIN; | 135 mb_activity = ACTIVITY_AVG_MIN; |
114 | 136 |
115 return mb_activity; | 137 return mb_activity; |
116 } | 138 } |
117 | 139 |
118 // Calculate an "average" mb activity value for the frame | 140 // Calculate an "average" mb activity value for the frame |
119 #define ACT_MEDIAN 0 | 141 #define ACT_MEDIAN 0 |
120 static void calc_av_activity(VP9_COMP *cpi, int64_t activity_sum) { | 142 static void calc_av_activity(VP9_COMP *cpi, int64_t activity_sum) { |
121 #if ACT_MEDIAN | 143 #if ACT_MEDIAN |
122 // Find median: Simple n^2 algorithm for experimentation | 144 // Find median: Simple n^2 algorithm for experimentation |
123 { | 145 { |
(...skipping 27 matching lines...) Expand all Loading... |
151 median = (1 + sortlist[cpi->common.MBs >> 1] + | 173 median = (1 + sortlist[cpi->common.MBs >> 1] + |
152 sortlist[(cpi->common.MBs >> 1) + 1]) >> 1; | 174 sortlist[(cpi->common.MBs >> 1) + 1]) >> 1; |
153 | 175 |
154 cpi->activity_avg = median; | 176 cpi->activity_avg = median; |
155 | 177 |
156 vpx_free(sortlist); | 178 vpx_free(sortlist); |
157 } | 179 } |
158 #else | 180 #else |
159 // Simple mean for now | 181 // Simple mean for now |
160 cpi->activity_avg = (unsigned int) (activity_sum / cpi->common.MBs); | 182 cpi->activity_avg = (unsigned int) (activity_sum / cpi->common.MBs); |
161 #endif | 183 #endif // ACT_MEDIAN |
162 | 184 |
163 if (cpi->activity_avg < VP9_ACTIVITY_AVG_MIN) | 185 if (cpi->activity_avg < ACTIVITY_AVG_MIN) |
164 cpi->activity_avg = VP9_ACTIVITY_AVG_MIN; | 186 cpi->activity_avg = ACTIVITY_AVG_MIN; |
165 | 187 |
166 // Experimental code: return fixed value normalized for several clips | 188 // Experimental code: return fixed value normalized for several clips |
167 if (ALT_ACT_MEASURE) | 189 if (ALT_ACT_MEASURE) |
168 cpi->activity_avg = 100000; | 190 cpi->activity_avg = 100000; |
169 } | 191 } |
170 | 192 |
171 #define USE_ACT_INDEX 0 | 193 #define USE_ACT_INDEX 0 |
172 #define OUTPUT_NORM_ACT_STATS 0 | 194 #define OUTPUT_NORM_ACT_STATS 0 |
173 | 195 |
174 #if USE_ACT_INDEX | 196 #if USE_ACT_INDEX |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 fprintf(f, "\n"); | 238 fprintf(f, "\n"); |
217 #endif | 239 #endif |
218 | 240 |
219 } | 241 } |
220 | 242 |
221 #if OUTPUT_NORM_ACT_STATS | 243 #if OUTPUT_NORM_ACT_STATS |
222 fclose(f); | 244 fclose(f); |
223 #endif | 245 #endif |
224 | 246 |
225 } | 247 } |
226 #endif | 248 #endif // USE_ACT_INDEX |
227 | 249 |
228 // Loop through all MBs. Note activity of each, average activity and | 250 // Loop through all MBs. Note activity of each, average activity and |
229 // calculate a normalized activity for each | 251 // calculate a normalized activity for each |
230 static void build_activity_map(VP9_COMP *cpi) { | 252 static void build_activity_map(VP9_COMP *cpi) { |
231 MACROBLOCK * const x = &cpi->mb; | 253 MACROBLOCK * const x = &cpi->mb; |
232 MACROBLOCKD *xd = &x->e_mbd; | 254 MACROBLOCKD *xd = &x->e_mbd; |
233 VP9_COMMON * const cm = &cpi->common; | 255 VP9_COMMON * const cm = &cpi->common; |
234 | 256 |
235 #if ALT_ACT_MEASURE | 257 #if ALT_ACT_MEASURE |
236 YV12_BUFFER_CONFIG *new_yv12 = &cm->yv12_fb[cm->new_fb_idx]; | 258 YV12_BUFFER_CONFIG *new_yv12 = &cm->yv12_fb[cm->new_fb_idx]; |
(...skipping 16 matching lines...) Expand all Loading... |
253 #endif | 275 #endif |
254 // for each macroblock col in image | 276 // for each macroblock col in image |
255 for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) { | 277 for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) { |
256 #if ALT_ACT_MEASURE | 278 #if ALT_ACT_MEASURE |
257 xd->plane[0].dst.buf = new_yv12->y_buffer + recon_yoffset; | 279 xd->plane[0].dst.buf = new_yv12->y_buffer + recon_yoffset; |
258 xd->left_available = (mb_col != 0); | 280 xd->left_available = (mb_col != 0); |
259 recon_yoffset += 16; | 281 recon_yoffset += 16; |
260 #endif | 282 #endif |
261 | 283 |
262 // measure activity | 284 // measure activity |
263 mb_activity = mb_activity_measure(cpi, x, mb_row, mb_col); | 285 mb_activity = mb_activity_measure(x, mb_row, mb_col); |
264 | 286 |
265 // Keep frame sum | 287 // Keep frame sum |
266 activity_sum += mb_activity; | 288 activity_sum += mb_activity; |
267 | 289 |
268 // Store MB level activity details. | 290 // Store MB level activity details. |
269 *x->mb_activity_ptr = mb_activity; | 291 *x->mb_activity_ptr = mb_activity; |
270 | 292 |
271 // Increment activity map pointer | 293 // Increment activity map pointer |
272 x->mb_activity_ptr++; | 294 x->mb_activity_ptr++; |
273 | 295 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 x->rdmult = (unsigned int) (((int64_t) x->rdmult * b + (a >> 1)) / a); | 329 x->rdmult = (unsigned int) (((int64_t) x->rdmult * b + (a >> 1)) / a); |
308 x->errorperbit = x->rdmult * 100 / (110 * x->rddiv); | 330 x->errorperbit = x->rdmult * 100 / (110 * x->rddiv); |
309 x->errorperbit += (x->errorperbit == 0); | 331 x->errorperbit += (x->errorperbit == 0); |
310 #endif | 332 #endif |
311 | 333 |
312 // Activity based Zbin adjustment | 334 // Activity based Zbin adjustment |
313 adjust_act_zbin(cpi, x); | 335 adjust_act_zbin(cpi, x); |
314 } | 336 } |
315 | 337 |
316 static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, | 338 static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, |
317 BLOCK_SIZE_TYPE bsize, int output_enabled) { | 339 BLOCK_SIZE bsize, int output_enabled) { |
318 int i, x_idx, y; | 340 int i, x_idx, y; |
319 MACROBLOCK * const x = &cpi->mb; | 341 VP9_COMMON *const cm = &cpi->common; |
320 MACROBLOCKD * const xd = &x->e_mbd; | 342 MACROBLOCK *const x = &cpi->mb; |
| 343 MACROBLOCKD *const xd = &x->e_mbd; |
321 MODE_INFO *mi = &ctx->mic; | 344 MODE_INFO *mi = &ctx->mic; |
322 MB_MODE_INFO * const mbmi = &xd->mode_info_context->mbmi; | 345 MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi; |
323 | 346 |
324 int mb_mode_index = ctx->best_mode_index; | 347 int mb_mode_index = ctx->best_mode_index; |
325 const int mis = cpi->common.mode_info_stride; | 348 const int mis = cm->mode_info_stride; |
| 349 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; |
326 const int mi_height = num_8x8_blocks_high_lookup[bsize]; | 350 const int mi_height = num_8x8_blocks_high_lookup[bsize]; |
327 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; | |
328 | 351 |
329 assert(mi->mbmi.mode < MB_MODE_COUNT); | 352 assert(mi->mbmi.mode < MB_MODE_COUNT); |
330 assert(mb_mode_index < MAX_MODES); | 353 assert(mb_mode_index < MAX_MODES); |
331 assert(mi->mbmi.ref_frame[0] < MAX_REF_FRAMES); | 354 assert(mi->mbmi.ref_frame[0] < MAX_REF_FRAMES); |
332 assert(mi->mbmi.ref_frame[1] < MAX_REF_FRAMES); | 355 assert(mi->mbmi.ref_frame[1] < MAX_REF_FRAMES); |
333 assert(mi->mbmi.sb_type == bsize); | 356 assert(mi->mbmi.sb_type == bsize); |
334 | 357 |
335 // Restore the coding context of the MB to that that was in place | 358 // Restore the coding context of the MB to that that was in place |
336 // when the mode was picked for it | 359 // when the mode was picked for it |
337 for (y = 0; y < mi_height; y++) { | 360 for (y = 0; y < mi_height; y++) |
338 for (x_idx = 0; x_idx < mi_width; x_idx++) { | 361 for (x_idx = 0; x_idx < mi_width; x_idx++) |
339 if ((xd->mb_to_right_edge >> (3 + LOG2_MI_SIZE)) + mi_width > x_idx | 362 if ((xd->mb_to_right_edge >> (3 + MI_SIZE_LOG2)) + mi_width > x_idx |
340 && (xd->mb_to_bottom_edge >> (3 + LOG2_MI_SIZE)) + mi_height > y) { | 363 && (xd->mb_to_bottom_edge >> (3 + MI_SIZE_LOG2)) + mi_height > y) |
341 MODE_INFO *mi_addr = xd->mode_info_context + x_idx + y * mis; | 364 xd->mode_info_context[x_idx + y * mis] = *mi; |
342 *mi_addr = *mi; | 365 |
343 } | |
344 } | |
345 } | |
346 // FIXME(rbultje) I'm pretty sure this should go to the end of this block | 366 // FIXME(rbultje) I'm pretty sure this should go to the end of this block |
347 // (i.e. after the output_enabled) | 367 // (i.e. after the output_enabled) |
348 if (bsize < BLOCK_SIZE_SB32X32) { | 368 if (bsize < BLOCK_32X32) { |
349 if (bsize < BLOCK_SIZE_MB16X16) | 369 if (bsize < BLOCK_16X16) |
350 ctx->txfm_rd_diff[ALLOW_16X16] = ctx->txfm_rd_diff[ALLOW_8X8]; | 370 ctx->tx_rd_diff[ALLOW_16X16] = ctx->tx_rd_diff[ALLOW_8X8]; |
351 ctx->txfm_rd_diff[ALLOW_32X32] = ctx->txfm_rd_diff[ALLOW_16X16]; | 371 ctx->tx_rd_diff[ALLOW_32X32] = ctx->tx_rd_diff[ALLOW_16X16]; |
352 } | 372 } |
353 | 373 |
354 if (mbmi->ref_frame[0] != INTRA_FRAME && mbmi->sb_type < BLOCK_SIZE_SB8X8) { | 374 if (is_inter_block(mbmi) && mbmi->sb_type < BLOCK_8X8) { |
355 *x->partition_info = ctx->partition_info; | 375 *x->partition_info = ctx->partition_info; |
356 mbmi->mv[0].as_int = mi->bmi[3].as_mv[0].as_int; | 376 mbmi->mv[0].as_int = mi->bmi[3].as_mv[0].as_int; |
357 mbmi->mv[1].as_int = mi->bmi[3].as_mv[1].as_int; | 377 mbmi->mv[1].as_int = mi->bmi[3].as_mv[1].as_int; |
358 } | 378 } |
359 | 379 |
360 x->skip = ctx->skip; | 380 x->skip = ctx->skip; |
361 if (!output_enabled) | 381 if (!output_enabled) |
362 return; | 382 return; |
363 | 383 |
364 if (!vp9_segfeature_active(&xd->seg, mbmi->segment_id, SEG_LVL_SKIP)) { | 384 if (!vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { |
365 for (i = 0; i < NB_TXFM_MODES; i++) { | 385 for (i = 0; i < TX_MODES; i++) |
366 cpi->rd_tx_select_diff[i] += ctx->txfm_rd_diff[i]; | 386 cpi->rd_tx_select_diff[i] += ctx->tx_rd_diff[i]; |
367 } | |
368 } | 387 } |
369 | 388 |
370 if (cpi->common.frame_type == KEY_FRAME) { | 389 if (cm->frame_type == KEY_FRAME) { |
371 // Restore the coding modes to that held in the coding context | 390 // Restore the coding modes to that held in the coding context |
372 // if (mb_mode == I4X4_PRED) | 391 // if (mb_mode == I4X4_PRED) |
373 // for (i = 0; i < 16; i++) | 392 // for (i = 0; i < 16; i++) |
374 // { | 393 // { |
375 // xd->block[i].bmi.as_mode = | 394 // xd->block[i].bmi.as_mode = |
376 // xd->mode_info_context->bmi[i].as_mode; | 395 // xd->mode_info_context->bmi[i].as_mode; |
377 // assert(xd->mode_info_context->bmi[i].as_mode < MB_MODE_COUNT); | 396 // assert(xd->mode_info_context->bmi[i].as_mode < MB_MODE_COUNT); |
378 // } | 397 // } |
379 #if CONFIG_INTERNAL_STATS | 398 #if CONFIG_INTERNAL_STATS |
380 static const int kf_mode_index[] = { | 399 static const int kf_mode_index[] = { |
381 THR_DC /*DC_PRED*/, | 400 THR_DC /*DC_PRED*/, |
382 THR_V_PRED /*V_PRED*/, | 401 THR_V_PRED /*V_PRED*/, |
383 THR_H_PRED /*H_PRED*/, | 402 THR_H_PRED /*H_PRED*/, |
384 THR_D45_PRED /*D45_PRED*/, | 403 THR_D45_PRED /*D45_PRED*/, |
385 THR_D135_PRED /*D135_PRED*/, | 404 THR_D135_PRED /*D135_PRED*/, |
386 THR_D117_PRED /*D117_PRED*/, | 405 THR_D117_PRED /*D117_PRED*/, |
387 THR_D153_PRED /*D153_PRED*/, | 406 THR_D153_PRED /*D153_PRED*/, |
388 THR_D27_PRED /*D27_PRED*/, | 407 THR_D207_PRED /*D207_PRED*/, |
389 THR_D63_PRED /*D63_PRED*/, | 408 THR_D63_PRED /*D63_PRED*/, |
390 THR_TM /*TM_PRED*/, | 409 THR_TM /*TM_PRED*/, |
391 THR_B_PRED /*I4X4_PRED*/, | 410 THR_B_PRED /*I4X4_PRED*/, |
392 }; | 411 }; |
393 cpi->mode_chosen_counts[kf_mode_index[mi->mbmi.mode]]++; | 412 cpi->mode_chosen_counts[kf_mode_index[mi->mbmi.mode]]++; |
394 #endif | 413 #endif |
395 } else { | 414 } else { |
396 // Note how often each mode chosen as best | 415 // Note how often each mode chosen as best |
397 cpi->mode_chosen_counts[mb_mode_index]++; | 416 cpi->mode_chosen_counts[mb_mode_index]++; |
398 if (mbmi->ref_frame[0] != INTRA_FRAME | 417 if (is_inter_block(mbmi) |
399 && (mbmi->sb_type < BLOCK_SIZE_SB8X8 || mbmi->mode == NEWMV)) { | 418 && (mbmi->sb_type < BLOCK_8X8 || mbmi->mode == NEWMV)) { |
400 int_mv best_mv, best_second_mv; | 419 int_mv best_mv, best_second_mv; |
401 const MV_REFERENCE_FRAME rf1 = mbmi->ref_frame[0]; | 420 const MV_REFERENCE_FRAME rf1 = mbmi->ref_frame[0]; |
402 const MV_REFERENCE_FRAME rf2 = mbmi->ref_frame[1]; | 421 const MV_REFERENCE_FRAME rf2 = mbmi->ref_frame[1]; |
403 best_mv.as_int = ctx->best_ref_mv.as_int; | 422 best_mv.as_int = ctx->best_ref_mv.as_int; |
404 best_second_mv.as_int = ctx->second_best_ref_mv.as_int; | 423 best_second_mv.as_int = ctx->second_best_ref_mv.as_int; |
405 if (mbmi->mode == NEWMV) { | 424 if (mbmi->mode == NEWMV) { |
406 best_mv.as_int = mbmi->ref_mvs[rf1][0].as_int; | 425 best_mv.as_int = mbmi->ref_mvs[rf1][0].as_int; |
407 best_second_mv.as_int = mbmi->ref_mvs[rf2][0].as_int; | 426 best_second_mv.as_int = mbmi->ref_mvs[rf2][0].as_int; |
408 } | 427 } |
409 mbmi->best_mv.as_int = best_mv.as_int; | 428 mbmi->best_mv.as_int = best_mv.as_int; |
410 mbmi->best_second_mv.as_int = best_second_mv.as_int; | 429 mbmi->best_second_mv.as_int = best_second_mv.as_int; |
411 vp9_update_nmv_count(cpi, x, &best_mv, &best_second_mv); | 430 vp9_update_nmv_count(cpi, x, &best_mv, &best_second_mv); |
412 } | 431 } |
413 | 432 |
414 if (bsize > BLOCK_SIZE_SB8X8 && mbmi->mode == NEWMV) { | 433 if (bsize > BLOCK_8X8 && mbmi->mode == NEWMV) { |
415 int i, j; | 434 int i, j; |
416 for (j = 0; j < mi_height; ++j) | 435 for (j = 0; j < mi_height; ++j) |
417 for (i = 0; i < mi_width; ++i) | 436 for (i = 0; i < mi_width; ++i) |
418 if ((xd->mb_to_right_edge >> (3 + LOG2_MI_SIZE)) + mi_width > i | 437 if ((xd->mb_to_right_edge >> (3 + MI_SIZE_LOG2)) + mi_width > i |
419 && (xd->mb_to_bottom_edge >> (3 + LOG2_MI_SIZE)) + mi_height > j) | 438 && (xd->mb_to_bottom_edge >> (3 + MI_SIZE_LOG2)) + mi_height > j) |
420 xd->mode_info_context[mis * j + i].mbmi = *mbmi; | 439 xd->mode_info_context[mis * j + i].mbmi = *mbmi; |
421 } | 440 } |
422 | 441 |
423 if (cpi->common.mcomp_filter_type == SWITCHABLE | 442 if (cm->mcomp_filter_type == SWITCHABLE && is_inter_mode(mbmi->mode)) { |
424 && is_inter_mode(mbmi->mode)) { | 443 const int ctx = vp9_get_pred_context_switchable_interp(xd); |
425 ++cpi->common.counts.switchable_interp[ | 444 ++cm->counts.switchable_interp[ctx][mbmi->interp_filter]; |
426 vp9_get_pred_context_switchable_interp(xd)] | |
427 [vp9_switchable_interp_map[mbmi->interp_filter]]; | |
428 } | 445 } |
429 | 446 |
430 cpi->rd_comp_pred_diff[SINGLE_PREDICTION_ONLY] += ctx->single_pred_diff; | 447 cpi->rd_comp_pred_diff[SINGLE_PREDICTION_ONLY] += ctx->single_pred_diff; |
431 cpi->rd_comp_pred_diff[COMP_PREDICTION_ONLY] += ctx->comp_pred_diff; | 448 cpi->rd_comp_pred_diff[COMP_PREDICTION_ONLY] += ctx->comp_pred_diff; |
432 cpi->rd_comp_pred_diff[HYBRID_PREDICTION] += ctx->hybrid_pred_diff; | 449 cpi->rd_comp_pred_diff[HYBRID_PREDICTION] += ctx->hybrid_pred_diff; |
433 | 450 |
434 for (i = 0; i <= VP9_SWITCHABLE_FILTERS; i++) { | 451 for (i = 0; i <= SWITCHABLE_FILTERS; i++) |
435 cpi->rd_filter_diff[i] += ctx->best_filter_diff[i]; | 452 cpi->rd_filter_diff[i] += ctx->best_filter_diff[i]; |
436 } | |
437 } | 453 } |
438 } | 454 } |
439 | 455 |
440 void vp9_setup_src_planes(MACROBLOCK *x, const YV12_BUFFER_CONFIG *src, | 456 void vp9_setup_src_planes(MACROBLOCK *x, const YV12_BUFFER_CONFIG *src, |
441 int mb_row, int mb_col) { | 457 int mb_row, int mb_col) { |
442 uint8_t *buffers[4] = {src->y_buffer, src->u_buffer, src->v_buffer, src | 458 uint8_t *buffers[4] = {src->y_buffer, src->u_buffer, src->v_buffer, src |
443 ->alpha_buffer}; | 459 ->alpha_buffer}; |
444 int strides[4] = {src->y_stride, src->uv_stride, src->uv_stride, src | 460 int strides[4] = {src->y_stride, src->uv_stride, src->uv_stride, src |
445 ->alpha_stride}; | 461 ->alpha_stride}; |
446 int i; | 462 int i; |
447 | 463 |
448 for (i = 0; i < MAX_MB_PLANE; i++) { | 464 for (i = 0; i < MAX_MB_PLANE; i++) { |
449 setup_pred_plane(&x->plane[i].src, buffers[i], strides[i], mb_row, mb_col, | 465 setup_pred_plane(&x->plane[i].src, buffers[i], strides[i], mb_row, mb_col, |
450 NULL, x->e_mbd.plane[i].subsampling_x, | 466 NULL, x->e_mbd.plane[i].subsampling_x, |
451 x->e_mbd.plane[i].subsampling_y); | 467 x->e_mbd.plane[i].subsampling_y); |
452 } | 468 } |
453 } | 469 } |
454 | 470 |
455 static void set_offsets(VP9_COMP *cpi, int mi_row, int mi_col, | 471 static void set_offsets(VP9_COMP *cpi, int mi_row, int mi_col, |
456 BLOCK_SIZE_TYPE bsize) { | 472 BLOCK_SIZE bsize) { |
457 MACROBLOCK * const x = &cpi->mb; | 473 MACROBLOCK *const x = &cpi->mb; |
458 VP9_COMMON * const cm = &cpi->common; | 474 VP9_COMMON *const cm = &cpi->common; |
459 MACROBLOCKD * const xd = &x->e_mbd; | 475 MACROBLOCKD *const xd = &x->e_mbd; |
460 MB_MODE_INFO *mbmi; | 476 MB_MODE_INFO *mbmi; |
461 const int dst_fb_idx = cm->new_fb_idx; | 477 const int dst_fb_idx = cm->new_fb_idx; |
462 const int idx_str = xd->mode_info_stride * mi_row + mi_col; | 478 const int idx_str = xd->mode_info_stride * mi_row + mi_col; |
463 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; | 479 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; |
464 const int mi_height = num_8x8_blocks_high_lookup[bsize]; | 480 const int mi_height = num_8x8_blocks_high_lookup[bsize]; |
465 const int mb_row = mi_row >> 1; | 481 const int mb_row = mi_row >> 1; |
466 const int mb_col = mi_col >> 1; | 482 const int mb_col = mi_col >> 1; |
467 const int idx_map = mb_row * cm->mb_cols + mb_col; | 483 const int idx_map = mb_row * cm->mb_cols + mb_col; |
468 int i; | 484 const struct segmentation *const seg = &cm->seg; |
469 | 485 |
470 // entropy context structures | 486 set_skip_context(cm, xd, mi_row, mi_col); |
471 for (i = 0; i < MAX_MB_PLANE; i++) { | |
472 xd->plane[i].above_context = cm->above_context[i] | |
473 + (mi_col * 2 >> xd->plane[i].subsampling_x); | |
474 xd->plane[i].left_context = cm->left_context[i] | |
475 + (((mi_row * 2) & 15) >> xd->plane[i].subsampling_y); | |
476 } | |
477 | |
478 // partition contexts | |
479 set_partition_seg_context(cm, xd, mi_row, mi_col); | 487 set_partition_seg_context(cm, xd, mi_row, mi_col); |
480 | 488 |
481 // Activity map pointer | 489 // Activity map pointer |
482 x->mb_activity_ptr = &cpi->mb_activity_map[idx_map]; | 490 x->mb_activity_ptr = &cpi->mb_activity_map[idx_map]; |
483 x->active_ptr = cpi->active_map + idx_map; | 491 x->active_ptr = cpi->active_map + idx_map; |
484 | 492 |
485 /* pointers to mode info contexts */ | 493 /* pointers to mode info contexts */ |
486 x->partition_info = x->pi + idx_str; | 494 x->partition_info = x->pi + idx_str; |
487 xd->mode_info_context = cm->mi + idx_str; | 495 xd->mode_info_context = cm->mi + idx_str; |
488 mbmi = &xd->mode_info_context->mbmi; | 496 mbmi = &xd->mode_info_context->mbmi; |
489 // Special case: if prev_mi is NULL, the previous mode info context | 497 // Special case: if prev_mi is NULL, the previous mode info context |
490 // cannot be used. | 498 // cannot be used. |
491 xd->prev_mode_info_context = cm->prev_mi ? cm->prev_mi + idx_str : NULL; | 499 xd->prev_mode_info_context = cm->prev_mi ? cm->prev_mi + idx_str : NULL; |
492 | 500 |
493 // Set up destination pointers | 501 // Set up destination pointers |
494 setup_dst_planes(xd, &cm->yv12_fb[dst_fb_idx], mi_row, mi_col); | 502 setup_dst_planes(xd, &cm->yv12_fb[dst_fb_idx], mi_row, mi_col); |
495 | 503 |
496 /* Set up limit values for MV components to prevent them from | 504 // Set up limit values for MV components |
497 * extending beyond the UMV borders assuming 16x16 block size */ | 505 // mv beyond the range do not produce new/different prediction block |
498 x->mv_row_min = -((mi_row * MI_SIZE)+ VP9BORDERINPIXELS - VP9_INTERP_EXTEND); | 506 x->mv_row_min = -(((mi_row + mi_height) * MI_SIZE) + VP9_INTERP_EXTEND); |
499 x->mv_col_min = -((mi_col * MI_SIZE)+ VP9BORDERINPIXELS - VP9_INTERP_EXTEND); | 507 x->mv_col_min = -(((mi_col + mi_width) * MI_SIZE) + VP9_INTERP_EXTEND); |
500 x->mv_row_max = ((cm->mi_rows - mi_row) * MI_SIZE | 508 x->mv_row_max = (cm->mi_rows - mi_row) * MI_SIZE + VP9_INTERP_EXTEND; |
501 + (VP9BORDERINPIXELS - MI_SIZE * mi_height - VP9_INTERP_EXTEND)); | 509 x->mv_col_max = (cm->mi_cols - mi_col) * MI_SIZE + VP9_INTERP_EXTEND; |
502 x->mv_col_max = ((cm->mi_cols - mi_col) * MI_SIZE | |
503 + (VP9BORDERINPIXELS - MI_SIZE * mi_width - VP9_INTERP_EXTEND)); | |
504 | 510 |
505 // Set up distance of MB to edge of frame in 1/8th pel units | 511 // Set up distance of MB to edge of frame in 1/8th pel units |
506 assert(!(mi_col & (mi_width - 1)) && !(mi_row & (mi_height - 1))); | 512 assert(!(mi_col & (mi_width - 1)) && !(mi_row & (mi_height - 1))); |
507 set_mi_row_col(cm, xd, mi_row, mi_height, mi_col, mi_width); | 513 set_mi_row_col(cm, xd, mi_row, mi_height, mi_col, mi_width); |
508 | 514 |
509 /* set up source buffers */ | 515 /* set up source buffers */ |
510 vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col); | 516 vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col); |
511 | 517 |
512 /* R/D setup */ | 518 /* R/D setup */ |
513 x->rddiv = cpi->RDDIV; | 519 x->rddiv = cpi->RDDIV; |
514 x->rdmult = cpi->RDMULT; | 520 x->rdmult = cpi->RDMULT; |
515 | 521 |
516 /* segment ID */ | 522 /* segment ID */ |
517 if (xd->seg.enabled) { | 523 if (seg->enabled) { |
518 uint8_t *map = xd->seg.update_map ? cpi->segmentation_map | 524 uint8_t *map = seg->update_map ? cpi->segmentation_map |
519 : cm->last_frame_seg_map; | 525 : cm->last_frame_seg_map; |
520 mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); | 526 mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); |
521 | 527 |
522 vp9_mb_init_quantizer(cpi, x); | 528 vp9_mb_init_quantizer(cpi, x); |
523 | 529 |
524 if (xd->seg.enabled && cpi->seg0_cnt > 0 | 530 if (seg->enabled && cpi->seg0_cnt > 0 |
525 && !vp9_segfeature_active(&xd->seg, 0, SEG_LVL_REF_FRAME) | 531 && !vp9_segfeature_active(seg, 0, SEG_LVL_REF_FRAME) |
526 && vp9_segfeature_active(&xd->seg, 1, SEG_LVL_REF_FRAME)) { | 532 && vp9_segfeature_active(seg, 1, SEG_LVL_REF_FRAME)) { |
527 cpi->seg0_progress = (cpi->seg0_idx << 16) / cpi->seg0_cnt; | 533 cpi->seg0_progress = (cpi->seg0_idx << 16) / cpi->seg0_cnt; |
528 } else { | 534 } else { |
529 const int y = mb_row & ~3; | 535 const int y = mb_row & ~3; |
530 const int x = mb_col & ~3; | 536 const int x = mb_col & ~3; |
531 const int p16 = ((mb_row & 1) << 1) + (mb_col & 1); | 537 const int p16 = ((mb_row & 1) << 1) + (mb_col & 1); |
532 const int p32 = ((mb_row & 2) << 2) + ((mb_col & 2) << 1); | 538 const int p32 = ((mb_row & 2) << 2) + ((mb_col & 2) << 1); |
533 const int tile_progress = cm->cur_tile_mi_col_start * cm->mb_rows >> 1; | 539 const int tile_progress = cm->cur_tile_mi_col_start * cm->mb_rows >> 1; |
534 const int mb_cols = (cm->cur_tile_mi_col_end - cm->cur_tile_mi_col_start) | 540 const int mb_cols = (cm->cur_tile_mi_col_end - cm->cur_tile_mi_col_start) |
535 >> 1; | 541 >> 1; |
536 | 542 |
537 cpi->seg0_progress = ((y * mb_cols + x * 4 + p32 + p16 + tile_progress) | 543 cpi->seg0_progress = ((y * mb_cols + x * 4 + p32 + p16 + tile_progress) |
538 << 16) / cm->MBs; | 544 << 16) / cm->MBs; |
539 } | 545 } |
| 546 |
| 547 x->encode_breakout = cpi->segment_encode_breakout[mbmi->segment_id]; |
540 } else { | 548 } else { |
541 mbmi->segment_id = 0; | 549 mbmi->segment_id = 0; |
| 550 x->encode_breakout = cpi->oxcf.encode_breakout; |
542 } | 551 } |
543 } | 552 } |
544 | 553 |
545 static void pick_sb_modes(VP9_COMP *cpi, int mi_row, int mi_col, | 554 static void pick_sb_modes(VP9_COMP *cpi, int mi_row, int mi_col, |
546 int *totalrate, int64_t *totaldist, | 555 int *totalrate, int64_t *totaldist, |
547 BLOCK_SIZE_TYPE bsize, PICK_MODE_CONTEXT *ctx, | 556 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx, |
548 int64_t best_rd) { | 557 int64_t best_rd) { |
549 VP9_COMMON *const cm = &cpi->common; | 558 VP9_COMMON *const cm = &cpi->common; |
550 MACROBLOCK *const x = &cpi->mb; | 559 MACROBLOCK *const x = &cpi->mb; |
551 MACROBLOCKD *const xd = &x->e_mbd; | 560 MACROBLOCKD *const xd = &x->e_mbd; |
552 | 561 |
553 x->rd_search = 1; | 562 // Use the lower precision, but faster, 32x32 fdct for mode selection. |
| 563 x->use_lp32x32fdct = 1; |
554 | 564 |
555 if (bsize < BLOCK_SIZE_SB8X8) | 565 if (bsize < BLOCK_8X8) { |
556 if (xd->ab_index != 0) | 566 // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 |
| 567 // there is nothing to be done. |
| 568 if (xd->ab_index != 0) { |
| 569 *totalrate = 0; |
| 570 *totaldist = 0; |
557 return; | 571 return; |
| 572 } |
| 573 } |
558 | 574 |
559 set_offsets(cpi, mi_row, mi_col, bsize); | 575 set_offsets(cpi, mi_row, mi_col, bsize); |
560 xd->mode_info_context->mbmi.sb_type = bsize; | 576 xd->mode_info_context->mbmi.sb_type = bsize; |
| 577 |
| 578 // Set to zero to make sure we do not use the previous encoded frame stats |
| 579 xd->mode_info_context->mbmi.skip_coeff = 0; |
| 580 |
| 581 x->source_variance = get_sby_perpixel_variance(cpi, x, bsize); |
| 582 |
561 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) | 583 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) |
562 vp9_activity_masking(cpi, x); | 584 vp9_activity_masking(cpi, x); |
563 | 585 |
564 // Find best coding mode & reconstruct the MB so it is available | 586 // Find best coding mode & reconstruct the MB so it is available |
565 // as a predictor for MBs that follow in the SB | 587 // as a predictor for MBs that follow in the SB |
566 if (cm->frame_type == KEY_FRAME) | 588 if (cm->frame_type == KEY_FRAME) |
567 vp9_rd_pick_intra_mode_sb(cpi, x, totalrate, totaldist, bsize, ctx, | 589 vp9_rd_pick_intra_mode_sb(cpi, x, totalrate, totaldist, bsize, ctx, |
568 best_rd); | 590 best_rd); |
569 else | 591 else |
570 vp9_rd_pick_inter_mode_sb(cpi, x, mi_row, mi_col, totalrate, totaldist, | 592 vp9_rd_pick_inter_mode_sb(cpi, x, mi_row, mi_col, totalrate, totaldist, |
571 bsize, ctx, best_rd); | 593 bsize, ctx, best_rd); |
572 } | 594 } |
573 | 595 |
574 static void update_stats(VP9_COMP *cpi, int mi_row, int mi_col) { | 596 static void update_stats(VP9_COMP *cpi) { |
575 VP9_COMMON * const cm = &cpi->common; | 597 VP9_COMMON *const cm = &cpi->common; |
576 MACROBLOCK * const x = &cpi->mb; | 598 MACROBLOCK *const x = &cpi->mb; |
577 MACROBLOCKD * const xd = &x->e_mbd; | 599 MACROBLOCKD *const xd = &x->e_mbd; |
578 MODE_INFO *mi = xd->mode_info_context; | 600 MODE_INFO *mi = xd->mode_info_context; |
579 MB_MODE_INFO * const mbmi = &mi->mbmi; | 601 MB_MODE_INFO *const mbmi = &mi->mbmi; |
580 | 602 |
581 if (cm->frame_type != KEY_FRAME) { | 603 if (cm->frame_type != KEY_FRAME) { |
582 const int seg_ref_active = vp9_segfeature_active(&xd->seg, mbmi->segment_id, | 604 const int seg_ref_active = vp9_segfeature_active(&cm->seg, mbmi->segment_id, |
583 SEG_LVL_REF_FRAME); | 605 SEG_LVL_REF_FRAME); |
584 | 606 |
585 if (!seg_ref_active) | 607 if (!seg_ref_active) |
586 cpi->intra_inter_count[vp9_get_pred_context_intra_inter(xd)][mbmi | 608 cpi->intra_inter_count[vp9_get_pred_context_intra_inter(xd)] |
587 ->ref_frame[0] > INTRA_FRAME]++; | 609 [is_inter_block(mbmi)]++; |
588 | 610 |
589 // If the segment reference feature is enabled we have only a single | 611 // If the segment reference feature is enabled we have only a single |
590 // reference frame allowed for the segment so exclude it from | 612 // reference frame allowed for the segment so exclude it from |
591 // the reference frame counts used to work out probabilities. | 613 // the reference frame counts used to work out probabilities. |
592 if ((mbmi->ref_frame[0] > INTRA_FRAME) && !seg_ref_active) { | 614 if (is_inter_block(mbmi) && !seg_ref_active) { |
593 if (cm->comp_pred_mode == HYBRID_PREDICTION) | 615 if (cm->comp_pred_mode == HYBRID_PREDICTION) |
594 cpi->comp_inter_count[vp9_get_pred_context_comp_inter_inter(cm, xd)] | 616 cpi->comp_inter_count[vp9_get_pred_context_comp_inter_inter(cm, xd)] |
595 [mbmi->ref_frame[1] > INTRA_FRAME]++; | 617 [has_second_ref(mbmi)]++; |
596 | 618 |
597 if (mbmi->ref_frame[1] > INTRA_FRAME) { | 619 if (has_second_ref(mbmi)) { |
598 cpi->comp_ref_count[vp9_get_pred_context_comp_ref_p(cm, xd)][mbmi | 620 cpi->comp_ref_count[vp9_get_pred_context_comp_ref_p(cm, xd)] |
599 ->ref_frame[0] == GOLDEN_FRAME]++; | 621 [mbmi->ref_frame[0] == GOLDEN_FRAME]++; |
600 } else { | 622 } else { |
601 cpi->single_ref_count[vp9_get_pred_context_single_ref_p1(xd)] | 623 cpi->single_ref_count[vp9_get_pred_context_single_ref_p1(xd)][0] |
602 [0][mbmi->ref_frame[0] != LAST_FRAME]++; | 624 [mbmi->ref_frame[0] != LAST_FRAME]++; |
603 if (mbmi->ref_frame[0] != LAST_FRAME) | 625 if (mbmi->ref_frame[0] != LAST_FRAME) |
604 cpi->single_ref_count[vp9_get_pred_context_single_ref_p2(xd)][1] | 626 cpi->single_ref_count[vp9_get_pred_context_single_ref_p2(xd)][1] |
605 [mbmi->ref_frame[0] != GOLDEN_FRAME]++; | 627 [mbmi->ref_frame[0] != GOLDEN_FRAME]++; |
606 } | 628 } |
607 } | 629 } |
| 630 |
608 // Count of last ref frame 0,0 usage | 631 // Count of last ref frame 0,0 usage |
609 if ((mbmi->mode == ZEROMV) && (mbmi->ref_frame[0] == LAST_FRAME)) | 632 if (mbmi->mode == ZEROMV && mbmi->ref_frame[0] == LAST_FRAME) |
610 cpi->inter_zz_count++; | 633 cpi->inter_zz_count++; |
611 } | 634 } |
612 } | 635 } |
613 | 636 |
614 // TODO(jingning): the variables used here are little complicated. need further | 637 // TODO(jingning): the variables used here are little complicated. need further |
615 // refactoring on organizing the the temporary buffers, when recursive | 638 // refactoring on organizing the temporary buffers, when recursive |
616 // partition down to 4x4 block size is enabled. | 639 // partition down to 4x4 block size is enabled. |
617 static PICK_MODE_CONTEXT *get_block_context(MACROBLOCK *x, | 640 static PICK_MODE_CONTEXT *get_block_context(MACROBLOCK *x, BLOCK_SIZE bsize) { |
618 BLOCK_SIZE_TYPE bsize) { | 641 MACROBLOCKD *const xd = &x->e_mbd; |
619 MACROBLOCKD * const xd = &x->e_mbd; | |
620 | 642 |
621 switch (bsize) { | 643 switch (bsize) { |
622 case BLOCK_SIZE_SB64X64: | 644 case BLOCK_64X64: |
623 return &x->sb64_context; | 645 return &x->sb64_context; |
624 case BLOCK_SIZE_SB64X32: | 646 case BLOCK_64X32: |
625 return &x->sb64x32_context[xd->sb_index]; | 647 return &x->sb64x32_context[xd->sb_index]; |
626 case BLOCK_SIZE_SB32X64: | 648 case BLOCK_32X64: |
627 return &x->sb32x64_context[xd->sb_index]; | 649 return &x->sb32x64_context[xd->sb_index]; |
628 case BLOCK_SIZE_SB32X32: | 650 case BLOCK_32X32: |
629 return &x->sb32_context[xd->sb_index]; | 651 return &x->sb32_context[xd->sb_index]; |
630 case BLOCK_SIZE_SB32X16: | 652 case BLOCK_32X16: |
631 return &x->sb32x16_context[xd->sb_index][xd->mb_index]; | 653 return &x->sb32x16_context[xd->sb_index][xd->mb_index]; |
632 case BLOCK_SIZE_SB16X32: | 654 case BLOCK_16X32: |
633 return &x->sb16x32_context[xd->sb_index][xd->mb_index]; | 655 return &x->sb16x32_context[xd->sb_index][xd->mb_index]; |
634 case BLOCK_SIZE_MB16X16: | 656 case BLOCK_16X16: |
635 return &x->mb_context[xd->sb_index][xd->mb_index]; | 657 return &x->mb_context[xd->sb_index][xd->mb_index]; |
636 case BLOCK_SIZE_SB16X8: | 658 case BLOCK_16X8: |
637 return &x->sb16x8_context[xd->sb_index][xd->mb_index][xd->b_index]; | 659 return &x->sb16x8_context[xd->sb_index][xd->mb_index][xd->b_index]; |
638 case BLOCK_SIZE_SB8X16: | 660 case BLOCK_8X16: |
639 return &x->sb8x16_context[xd->sb_index][xd->mb_index][xd->b_index]; | 661 return &x->sb8x16_context[xd->sb_index][xd->mb_index][xd->b_index]; |
640 case BLOCK_SIZE_SB8X8: | 662 case BLOCK_8X8: |
641 return &x->sb8x8_context[xd->sb_index][xd->mb_index][xd->b_index]; | 663 return &x->sb8x8_context[xd->sb_index][xd->mb_index][xd->b_index]; |
642 case BLOCK_SIZE_SB8X4: | 664 case BLOCK_8X4: |
643 return &x->sb8x4_context[xd->sb_index][xd->mb_index][xd->b_index]; | 665 return &x->sb8x4_context[xd->sb_index][xd->mb_index][xd->b_index]; |
644 case BLOCK_SIZE_SB4X8: | 666 case BLOCK_4X8: |
645 return &x->sb4x8_context[xd->sb_index][xd->mb_index][xd->b_index]; | 667 return &x->sb4x8_context[xd->sb_index][xd->mb_index][xd->b_index]; |
646 case BLOCK_SIZE_AB4X4: | 668 case BLOCK_4X4: |
647 return &x->ab4x4_context[xd->sb_index][xd->mb_index][xd->b_index]; | 669 return &x->ab4x4_context[xd->sb_index][xd->mb_index][xd->b_index]; |
648 default: | 670 default: |
649 assert(0); | 671 assert(0); |
650 return NULL ; | 672 return NULL ; |
651 } | 673 } |
652 } | 674 } |
653 | 675 |
654 static BLOCK_SIZE_TYPE *get_sb_partitioning(MACROBLOCK *x, | 676 static BLOCK_SIZE *get_sb_partitioning(MACROBLOCK *x, BLOCK_SIZE bsize) { |
655 BLOCK_SIZE_TYPE bsize) { | 677 MACROBLOCKD *const xd = &x->e_mbd; |
656 MACROBLOCKD *xd = &x->e_mbd; | |
657 switch (bsize) { | 678 switch (bsize) { |
658 case BLOCK_SIZE_SB64X64: | 679 case BLOCK_64X64: |
659 return &x->sb64_partitioning; | 680 return &x->sb64_partitioning; |
660 case BLOCK_SIZE_SB32X32: | 681 case BLOCK_32X32: |
661 return &x->sb_partitioning[xd->sb_index]; | 682 return &x->sb_partitioning[xd->sb_index]; |
662 case BLOCK_SIZE_MB16X16: | 683 case BLOCK_16X16: |
663 return &x->mb_partitioning[xd->sb_index][xd->mb_index]; | 684 return &x->mb_partitioning[xd->sb_index][xd->mb_index]; |
664 case BLOCK_SIZE_SB8X8: | 685 case BLOCK_8X8: |
665 return &x->b_partitioning[xd->sb_index][xd->mb_index][xd->b_index]; | 686 return &x->b_partitioning[xd->sb_index][xd->mb_index][xd->b_index]; |
666 default: | 687 default: |
667 assert(0); | 688 assert(0); |
668 return NULL ; | 689 return NULL ; |
669 } | 690 } |
670 } | 691 } |
671 | 692 |
672 static void restore_context(VP9_COMP *cpi, int mi_row, int mi_col, | 693 static void restore_context(VP9_COMP *cpi, int mi_row, int mi_col, |
673 ENTROPY_CONTEXT a[16 * MAX_MB_PLANE], | 694 ENTROPY_CONTEXT a[16 * MAX_MB_PLANE], |
674 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], | 695 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], |
675 PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8], | 696 PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8], |
676 BLOCK_SIZE_TYPE bsize) { | 697 BLOCK_SIZE bsize) { |
677 VP9_COMMON * const cm = &cpi->common; | 698 VP9_COMMON *const cm = &cpi->common; |
678 MACROBLOCK * const x = &cpi->mb; | 699 MACROBLOCK *const x = &cpi->mb; |
679 MACROBLOCKD * const xd = &x->e_mbd; | 700 MACROBLOCKD *const xd = &x->e_mbd; |
680 int p; | 701 int p; |
681 int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; | 702 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; |
682 int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; | 703 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; |
683 int mi_width = num_8x8_blocks_wide_lookup[bsize]; | 704 int mi_width = num_8x8_blocks_wide_lookup[bsize]; |
684 int mi_height = num_8x8_blocks_high_lookup[bsize]; | 705 int mi_height = num_8x8_blocks_high_lookup[bsize]; |
685 for (p = 0; p < MAX_MB_PLANE; p++) { | 706 for (p = 0; p < MAX_MB_PLANE; p++) { |
686 vpx_memcpy( | 707 vpx_memcpy( |
687 cm->above_context[p] + ((mi_col * 2) >> xd->plane[p].subsampling_x), | 708 cm->above_context[p] + ((mi_col * 2) >> xd->plane[p].subsampling_x), |
688 a + num_4x4_blocks_wide * p, | 709 a + num_4x4_blocks_wide * p, |
689 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide) >> | 710 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide) >> |
690 xd->plane[p].subsampling_x); | 711 xd->plane[p].subsampling_x); |
691 vpx_memcpy( | 712 vpx_memcpy( |
692 cm->left_context[p] | 713 cm->left_context[p] |
693 + ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y), | 714 + ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y), |
694 l + num_4x4_blocks_high * p, | 715 l + num_4x4_blocks_high * p, |
695 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >> | 716 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >> |
696 xd->plane[p].subsampling_y); | 717 xd->plane[p].subsampling_y); |
697 } | 718 } |
698 vpx_memcpy(cm->above_seg_context + mi_col, sa, | 719 vpx_memcpy(cm->above_seg_context + mi_col, sa, |
699 sizeof(PARTITION_CONTEXT) * mi_width); | 720 sizeof(PARTITION_CONTEXT) * mi_width); |
700 vpx_memcpy(cm->left_seg_context + (mi_row & MI_MASK), sl, | 721 vpx_memcpy(cm->left_seg_context + (mi_row & MI_MASK), sl, |
701 sizeof(PARTITION_CONTEXT) * mi_height); | 722 sizeof(PARTITION_CONTEXT) * mi_height); |
702 } | 723 } |
703 static void save_context(VP9_COMP *cpi, int mi_row, int mi_col, | 724 static void save_context(VP9_COMP *cpi, int mi_row, int mi_col, |
704 ENTROPY_CONTEXT a[16 * MAX_MB_PLANE], | 725 ENTROPY_CONTEXT a[16 * MAX_MB_PLANE], |
705 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], | 726 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], |
706 PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8], | 727 PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8], |
707 BLOCK_SIZE_TYPE bsize) { | 728 BLOCK_SIZE bsize) { |
708 VP9_COMMON * const cm = &cpi->common; | 729 const VP9_COMMON *const cm = &cpi->common; |
709 MACROBLOCK * const x = &cpi->mb; | 730 const MACROBLOCK *const x = &cpi->mb; |
710 MACROBLOCKD * const xd = &x->e_mbd; | 731 const MACROBLOCKD *const xd = &x->e_mbd; |
711 int p; | 732 int p; |
712 int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; | 733 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; |
713 int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; | 734 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; |
714 int mi_width = num_8x8_blocks_wide_lookup[bsize]; | 735 int mi_width = num_8x8_blocks_wide_lookup[bsize]; |
715 int mi_height = num_8x8_blocks_high_lookup[bsize]; | 736 int mi_height = num_8x8_blocks_high_lookup[bsize]; |
716 | 737 |
717 // buffer the above/left context information of the block in search. | 738 // buffer the above/left context information of the block in search. |
718 for (p = 0; p < MAX_MB_PLANE; ++p) { | 739 for (p = 0; p < MAX_MB_PLANE; ++p) { |
719 vpx_memcpy( | 740 vpx_memcpy( |
720 a + num_4x4_blocks_wide * p, | 741 a + num_4x4_blocks_wide * p, |
721 cm->above_context[p] + (mi_col * 2 >> xd->plane[p].subsampling_x), | 742 cm->above_context[p] + (mi_col * 2 >> xd->plane[p].subsampling_x), |
722 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide) >> | 743 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide) >> |
723 xd->plane[p].subsampling_x); | 744 xd->plane[p].subsampling_x); |
724 vpx_memcpy( | 745 vpx_memcpy( |
725 l + num_4x4_blocks_high * p, | 746 l + num_4x4_blocks_high * p, |
726 cm->left_context[p] | 747 cm->left_context[p] |
727 + ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y), | 748 + ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y), |
728 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >> | 749 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >> |
729 xd->plane[p].subsampling_y); | 750 xd->plane[p].subsampling_y); |
730 } | 751 } |
731 vpx_memcpy(sa, cm->above_seg_context + mi_col, | 752 vpx_memcpy(sa, cm->above_seg_context + mi_col, |
732 sizeof(PARTITION_CONTEXT) * mi_width); | 753 sizeof(PARTITION_CONTEXT) * mi_width); |
733 vpx_memcpy(sl, cm->left_seg_context + (mi_row & MI_MASK), | 754 vpx_memcpy(sl, cm->left_seg_context + (mi_row & MI_MASK), |
734 sizeof(PARTITION_CONTEXT) * mi_height); | 755 sizeof(PARTITION_CONTEXT) * mi_height); |
735 } | 756 } |
736 | 757 |
737 static void encode_b(VP9_COMP *cpi, TOKENEXTRA **tp, int mi_row, int mi_col, | 758 static void encode_b(VP9_COMP *cpi, TOKENEXTRA **tp, int mi_row, int mi_col, |
738 int output_enabled, BLOCK_SIZE_TYPE bsize, int sub_index) { | 759 int output_enabled, BLOCK_SIZE bsize, int sub_index) { |
739 VP9_COMMON * const cm = &cpi->common; | 760 VP9_COMMON * const cm = &cpi->common; |
740 MACROBLOCK * const x = &cpi->mb; | 761 MACROBLOCK * const x = &cpi->mb; |
741 MACROBLOCKD * const xd = &x->e_mbd; | 762 MACROBLOCKD * const xd = &x->e_mbd; |
742 | 763 |
743 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 764 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
744 return; | 765 return; |
745 | 766 |
746 if (sub_index != -1) | 767 if (sub_index != -1) |
747 *(get_sb_index(xd, bsize)) = sub_index; | 768 *(get_sb_index(xd, bsize)) = sub_index; |
748 | 769 |
749 if (bsize < BLOCK_SIZE_SB8X8) | 770 if (bsize < BLOCK_8X8) { |
| 771 // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 |
| 772 // there is nothing to be done. |
750 if (xd->ab_index > 0) | 773 if (xd->ab_index > 0) |
751 return; | 774 return; |
| 775 } |
752 set_offsets(cpi, mi_row, mi_col, bsize); | 776 set_offsets(cpi, mi_row, mi_col, bsize); |
753 update_state(cpi, get_block_context(x, bsize), bsize, output_enabled); | 777 update_state(cpi, get_block_context(x, bsize), bsize, output_enabled); |
754 encode_superblock(cpi, tp, output_enabled, mi_row, mi_col, bsize); | 778 encode_superblock(cpi, tp, output_enabled, mi_row, mi_col, bsize); |
755 | 779 |
756 if (output_enabled) { | 780 if (output_enabled) { |
757 update_stats(cpi, mi_row, mi_col); | 781 update_stats(cpi); |
758 | 782 |
759 (*tp)->token = EOSB_TOKEN; | 783 (*tp)->token = EOSB_TOKEN; |
760 (*tp)++; | 784 (*tp)++; |
761 } | 785 } |
762 } | 786 } |
763 | 787 |
764 static void encode_sb(VP9_COMP *cpi, TOKENEXTRA **tp, int mi_row, int mi_col, | 788 static void encode_sb(VP9_COMP *cpi, TOKENEXTRA **tp, int mi_row, int mi_col, |
765 int output_enabled, BLOCK_SIZE_TYPE bsize) { | 789 int output_enabled, BLOCK_SIZE bsize) { |
766 VP9_COMMON * const cm = &cpi->common; | 790 VP9_COMMON * const cm = &cpi->common; |
767 MACROBLOCK * const x = &cpi->mb; | 791 MACROBLOCK * const x = &cpi->mb; |
768 MACROBLOCKD * const xd = &x->e_mbd; | 792 MACROBLOCKD * const xd = &x->e_mbd; |
769 BLOCK_SIZE_TYPE c1 = BLOCK_SIZE_SB8X8; | 793 BLOCK_SIZE c1 = BLOCK_8X8; |
770 const int bsl = b_width_log2(bsize), bs = (1 << bsl) / 4; | 794 const int bsl = b_width_log2(bsize), bs = (1 << bsl) / 4; |
771 int UNINITIALIZED_IS_SAFE(pl); | 795 int UNINITIALIZED_IS_SAFE(pl); |
772 PARTITION_TYPE partition; | 796 PARTITION_TYPE partition; |
773 BLOCK_SIZE_TYPE subsize; | 797 BLOCK_SIZE subsize; |
774 int i; | 798 int i; |
775 | 799 |
776 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 800 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
777 return; | 801 return; |
778 | 802 |
779 c1 = BLOCK_SIZE_AB4X4; | 803 c1 = BLOCK_4X4; |
780 if (bsize >= BLOCK_SIZE_SB8X8) { | 804 if (bsize >= BLOCK_8X8) { |
781 set_partition_seg_context(cm, xd, mi_row, mi_col); | 805 set_partition_seg_context(cm, xd, mi_row, mi_col); |
782 pl = partition_plane_context(xd, bsize); | 806 pl = partition_plane_context(xd, bsize); |
783 c1 = *(get_sb_partitioning(x, bsize)); | 807 c1 = *(get_sb_partitioning(x, bsize)); |
784 } | 808 } |
785 partition = partition_lookup[bsl][c1]; | 809 partition = partition_lookup[bsl][c1]; |
786 | 810 |
787 switch (partition) { | 811 switch (partition) { |
788 case PARTITION_NONE: | 812 case PARTITION_NONE: |
789 if (output_enabled && bsize >= BLOCK_SIZE_SB8X8) | 813 if (output_enabled && bsize >= BLOCK_8X8) |
790 cpi->partition_count[pl][PARTITION_NONE]++; | 814 cpi->partition_count[pl][PARTITION_NONE]++; |
791 encode_b(cpi, tp, mi_row, mi_col, output_enabled, c1, -1); | 815 encode_b(cpi, tp, mi_row, mi_col, output_enabled, c1, -1); |
792 break; | 816 break; |
793 case PARTITION_VERT: | 817 case PARTITION_VERT: |
794 if (output_enabled) | 818 if (output_enabled) |
795 cpi->partition_count[pl][PARTITION_VERT]++; | 819 cpi->partition_count[pl][PARTITION_VERT]++; |
796 encode_b(cpi, tp, mi_row, mi_col, output_enabled, c1, 0); | 820 encode_b(cpi, tp, mi_row, mi_col, output_enabled, c1, 0); |
797 encode_b(cpi, tp, mi_row, mi_col + bs, output_enabled, c1, 1); | 821 encode_b(cpi, tp, mi_row, mi_col + bs, output_enabled, c1, 1); |
798 break; | 822 break; |
799 case PARTITION_HORZ: | 823 case PARTITION_HORZ: |
(...skipping 14 matching lines...) Expand all Loading... |
814 *(get_sb_index(xd, subsize)) = i; | 838 *(get_sb_index(xd, subsize)) = i; |
815 encode_sb(cpi, tp, mi_row + y_idx * bs, mi_col + x_idx * bs, | 839 encode_sb(cpi, tp, mi_row + y_idx * bs, mi_col + x_idx * bs, |
816 output_enabled, subsize); | 840 output_enabled, subsize); |
817 } | 841 } |
818 break; | 842 break; |
819 default: | 843 default: |
820 assert(0); | 844 assert(0); |
821 break; | 845 break; |
822 } | 846 } |
823 | 847 |
824 if (partition != PARTITION_SPLIT || bsize == BLOCK_SIZE_SB8X8) { | 848 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) { |
825 set_partition_seg_context(cm, xd, mi_row, mi_col); | 849 set_partition_seg_context(cm, xd, mi_row, mi_col); |
826 update_partition_context(xd, c1, bsize); | 850 update_partition_context(xd, c1, bsize); |
827 } | 851 } |
828 } | 852 } |
829 | 853 |
830 static void set_partitioning(VP9_COMP *cpi, MODE_INFO *m, | 854 static void set_partitioning(VP9_COMP *cpi, MODE_INFO *m, BLOCK_SIZE bsize) { |
831 BLOCK_SIZE_TYPE bsize) { | |
832 VP9_COMMON *const cm = &cpi->common; | 855 VP9_COMMON *const cm = &cpi->common; |
833 const int mis = cm->mode_info_stride; | 856 const int mis = cm->mode_info_stride; |
834 int block_row, block_col; | 857 int block_row, block_col; |
835 for (block_row = 0; block_row < 8; ++block_row) { | 858 for (block_row = 0; block_row < 8; ++block_row) { |
836 for (block_col = 0; block_col < 8; ++block_col) { | 859 for (block_col = 0; block_col < 8; ++block_col) { |
837 m[block_row * mis + block_col].mbmi.sb_type = bsize; | 860 m[block_row * mis + block_col].mbmi.sb_type = bsize; |
838 } | 861 } |
839 } | 862 } |
840 } | 863 } |
841 static void copy_partitioning(VP9_COMP *cpi, MODE_INFO *m, MODE_INFO *p) { | 864 static void copy_partitioning(VP9_COMP *cpi, MODE_INFO *m, MODE_INFO *p) { |
842 VP9_COMMON *const cm = &cpi->common; | 865 VP9_COMMON *const cm = &cpi->common; |
843 const int mis = cm->mode_info_stride; | 866 const int mis = cm->mode_info_stride; |
844 int block_row, block_col; | 867 int block_row, block_col; |
845 for (block_row = 0; block_row < 8; ++block_row) { | 868 for (block_row = 0; block_row < 8; ++block_row) { |
846 for (block_col = 0; block_col < 8; ++block_col) { | 869 for (block_col = 0; block_col < 8; ++block_col) { |
847 m[block_row * mis + block_col].mbmi.sb_type = | 870 m[block_row * mis + block_col].mbmi.sb_type = |
848 p[block_row * mis + block_col].mbmi.sb_type; | 871 p[block_row * mis + block_col].mbmi.sb_type; |
849 } | 872 } |
850 } | 873 } |
851 } | 874 } |
852 | 875 |
853 static void set_block_size(VP9_COMMON * const cm, MODE_INFO *m, | 876 static void set_block_size(VP9_COMMON * const cm, MODE_INFO *m, |
854 BLOCK_SIZE_TYPE bsize, int mis, int mi_row, | 877 BLOCK_SIZE bsize, int mis, int mi_row, |
855 int mi_col) { | 878 int mi_col) { |
856 int row, col; | 879 int row, col; |
857 int bwl = b_width_log2(bsize); | 880 int bwl = b_width_log2(bsize); |
858 int bhl = b_height_log2(bsize); | 881 int bhl = b_height_log2(bsize); |
859 int bsl = (bwl > bhl ? bwl : bhl); | 882 int bsl = (bwl > bhl ? bwl : bhl); |
860 | 883 |
861 int bs = (1 << bsl) / 2; // | 884 int bs = (1 << bsl) / 2; // Block size in units of 8 pels. |
862 MODE_INFO *m2 = m + mi_row * mis + mi_col; | 885 MODE_INFO *m2 = m + mi_row * mis + mi_col; |
863 for (row = 0; row < bs; row++) { | 886 for (row = 0; row < bs; row++) { |
864 for (col = 0; col < bs; col++) { | 887 for (col = 0; col < bs; col++) { |
865 if (mi_row + row >= cm->mi_rows || mi_col + col >= cm->mi_cols) | 888 if (mi_row + row >= cm->mi_rows || mi_col + col >= cm->mi_cols) |
866 continue; | 889 continue; |
867 m2[row * mis + col].mbmi.sb_type = bsize; | 890 m2[row * mis + col].mbmi.sb_type = bsize; |
868 } | 891 } |
869 } | 892 } |
870 } | 893 } |
871 | 894 |
(...skipping 24 matching lines...) Expand all Loading... |
896 partition_variance *vt; | 919 partition_variance *vt; |
897 var *split[4]; | 920 var *split[4]; |
898 } vt_node; | 921 } vt_node; |
899 | 922 |
900 typedef enum { | 923 typedef enum { |
901 V16X16, | 924 V16X16, |
902 V32X32, | 925 V32X32, |
903 V64X64, | 926 V64X64, |
904 } TREE_LEVEL; | 927 } TREE_LEVEL; |
905 | 928 |
906 static void tree_to_node(void *data, BLOCK_SIZE_TYPE block_size, vt_node *node)
{ | 929 static void tree_to_node(void *data, BLOCK_SIZE bsize, vt_node *node) { |
907 int i; | 930 int i; |
908 switch (block_size) { | 931 switch (bsize) { |
909 case BLOCK_SIZE_SB64X64: { | 932 case BLOCK_64X64: { |
910 v64x64 *vt = (v64x64 *) data; | 933 v64x64 *vt = (v64x64 *) data; |
911 node->vt = &vt->vt; | 934 node->vt = &vt->vt; |
912 for (i = 0; i < 4; i++) | 935 for (i = 0; i < 4; i++) |
913 node->split[i] = &vt->split[i].vt.none; | 936 node->split[i] = &vt->split[i].vt.none; |
914 break; | 937 break; |
915 } | 938 } |
916 case BLOCK_SIZE_SB32X32: { | 939 case BLOCK_32X32: { |
917 v32x32 *vt = (v32x32 *) data; | 940 v32x32 *vt = (v32x32 *) data; |
918 node->vt = &vt->vt; | 941 node->vt = &vt->vt; |
919 for (i = 0; i < 4; i++) | 942 for (i = 0; i < 4; i++) |
920 node->split[i] = &vt->split[i].vt.none; | 943 node->split[i] = &vt->split[i].vt.none; |
921 break; | 944 break; |
922 } | 945 } |
923 case BLOCK_SIZE_MB16X16: { | 946 case BLOCK_16X16: { |
924 v16x16 *vt = (v16x16 *) data; | 947 v16x16 *vt = (v16x16 *) data; |
925 node->vt = &vt->vt; | 948 node->vt = &vt->vt; |
926 for (i = 0; i < 4; i++) | 949 for (i = 0; i < 4; i++) |
927 node->split[i] = &vt->split[i].vt.none; | 950 node->split[i] = &vt->split[i].vt.none; |
928 break; | 951 break; |
929 } | 952 } |
930 case BLOCK_SIZE_SB8X8: { | 953 case BLOCK_8X8: { |
931 v8x8 *vt = (v8x8 *) data; | 954 v8x8 *vt = (v8x8 *) data; |
932 node->vt = &vt->vt; | 955 node->vt = &vt->vt; |
933 for (i = 0; i < 4; i++) | 956 for (i = 0; i < 4; i++) |
934 node->split[i] = &vt->split[i]; | 957 node->split[i] = &vt->split[i]; |
935 break; | 958 break; |
936 } | 959 } |
937 default: | 960 default: |
938 node->vt = 0; | 961 node->vt = 0; |
939 for (i = 0; i < 4; i++) | 962 for (i = 0; i < 4; i++) |
940 node->split[i] = 0; | 963 node->split[i] = 0; |
(...skipping 14 matching lines...) Expand all Loading... |
955 v->variance = 0; | 978 v->variance = 0; |
956 } | 979 } |
957 | 980 |
958 // Combine 2 variance structures by summing the sum_error, sum_square_error, | 981 // Combine 2 variance structures by summing the sum_error, sum_square_error, |
959 // and counts and then calculating the new variance. | 982 // and counts and then calculating the new variance. |
960 void sum_2_variances(var *r, var *a, var*b) { | 983 void sum_2_variances(var *r, var *a, var*b) { |
961 fill_variance(r, a->sum_square_error + b->sum_square_error, | 984 fill_variance(r, a->sum_square_error + b->sum_square_error, |
962 a->sum_error + b->sum_error, a->count + b->count); | 985 a->sum_error + b->sum_error, a->count + b->count); |
963 } | 986 } |
964 | 987 |
965 static void fill_variance_tree(void *data, BLOCK_SIZE_TYPE block_size) { | 988 static void fill_variance_tree(void *data, BLOCK_SIZE bsize) { |
966 vt_node node; | 989 vt_node node; |
967 tree_to_node(data, block_size, &node); | 990 tree_to_node(data, bsize, &node); |
968 sum_2_variances(&node.vt->horz[0], node.split[0], node.split[1]); | 991 sum_2_variances(&node.vt->horz[0], node.split[0], node.split[1]); |
969 sum_2_variances(&node.vt->horz[1], node.split[2], node.split[3]); | 992 sum_2_variances(&node.vt->horz[1], node.split[2], node.split[3]); |
970 sum_2_variances(&node.vt->vert[0], node.split[0], node.split[2]); | 993 sum_2_variances(&node.vt->vert[0], node.split[0], node.split[2]); |
971 sum_2_variances(&node.vt->vert[1], node.split[1], node.split[3]); | 994 sum_2_variances(&node.vt->vert[1], node.split[1], node.split[3]); |
972 sum_2_variances(&node.vt->none, &node.vt->vert[0], &node.vt->vert[1]); | 995 sum_2_variances(&node.vt->none, &node.vt->vert[0], &node.vt->vert[1]); |
973 } | 996 } |
974 | 997 |
975 #if PERFORM_RANDOM_PARTITIONING | 998 #if PERFORM_RANDOM_PARTITIONING |
976 static int set_vt_partitioning(VP9_COMP *cpi, void *data, MODE_INFO *m, | 999 static int set_vt_partitioning(VP9_COMP *cpi, void *data, MODE_INFO *m, |
977 BLOCK_SIZE_TYPE block_size, int mi_row, | 1000 BLOCK_SIZE block_size, int mi_row, |
978 int mi_col, int mi_size) { | 1001 int mi_col, int mi_size) { |
979 VP9_COMMON * const cm = &cpi->common; | 1002 VP9_COMMON * const cm = &cpi->common; |
980 vt_node vt; | 1003 vt_node vt; |
981 const int mis = cm->mode_info_stride; | 1004 const int mis = cm->mode_info_stride; |
982 int64_t threshold = 4 * cpi->common.base_qindex * cpi->common.base_qindex; | 1005 int64_t threshold = 4 * cpi->common.base_qindex * cpi->common.base_qindex; |
983 | 1006 |
984 tree_to_node(data, block_size, &vt); | 1007 tree_to_node(data, block_size, &vt); |
985 | 1008 |
986 // split none is available only if we have more than half a block size | 1009 // split none is available only if we have more than half a block size |
987 // in width and height inside the visible image | 1010 // in width and height inside the visible image |
(...skipping 15 matching lines...) Expand all Loading... |
1003 if (mi_col + mi_size < cm->mi_cols && vt.vt->horz[0].variance < threshold | 1026 if (mi_col + mi_size < cm->mi_cols && vt.vt->horz[0].variance < threshold |
1004 && (rand() & 3) < 1) { | 1027 && (rand() & 3) < 1) { |
1005 set_block_size(cm, m, get_subsize(block_size, PARTITION_HORZ), mis, mi_row, | 1028 set_block_size(cm, m, get_subsize(block_size, PARTITION_HORZ), mis, mi_row, |
1006 mi_col); | 1029 mi_col); |
1007 return 1; | 1030 return 1; |
1008 } | 1031 } |
1009 | 1032 |
1010 return 0; | 1033 return 0; |
1011 } | 1034 } |
1012 | 1035 |
1013 #else | 1036 #else // !PERFORM_RANDOM_PARTITIONING |
1014 | 1037 |
1015 static int set_vt_partitioning(VP9_COMP *cpi, void *data, MODE_INFO *m, | 1038 static int set_vt_partitioning(VP9_COMP *cpi, void *data, MODE_INFO *m, |
1016 BLOCK_SIZE_TYPE block_size, int mi_row, | 1039 BLOCK_SIZE bsize, int mi_row, |
1017 int mi_col, int mi_size) { | 1040 int mi_col, int mi_size) { |
1018 VP9_COMMON * const cm = &cpi->common; | 1041 VP9_COMMON * const cm = &cpi->common; |
1019 vt_node vt; | 1042 vt_node vt; |
1020 const int mis = cm->mode_info_stride; | 1043 const int mis = cm->mode_info_stride; |
1021 int64_t threshold = 50 * cpi->common.base_qindex; | 1044 int64_t threshold = 50 * cpi->common.base_qindex; |
1022 | 1045 |
1023 tree_to_node(data, block_size, &vt); | 1046 tree_to_node(data, bsize, &vt); |
1024 | 1047 |
1025 // split none is available only if we have more than half a block size | 1048 // split none is available only if we have more than half a block size |
1026 // in width and height inside the visible image | 1049 // in width and height inside the visible image |
1027 if (mi_col + mi_size < cm->mi_cols && mi_row + mi_size < cm->mi_rows | 1050 if (mi_col + mi_size < cm->mi_cols && mi_row + mi_size < cm->mi_rows |
1028 && vt.vt->none.variance < threshold) { | 1051 && vt.vt->none.variance < threshold) { |
1029 set_block_size(cm, m, block_size, mis, mi_row, mi_col); | 1052 set_block_size(cm, m, bsize, mis, mi_row, mi_col); |
1030 return 1; | 1053 return 1; |
1031 } | 1054 } |
1032 | 1055 |
1033 // vertical split is available on all but the bottom border | 1056 // vertical split is available on all but the bottom border |
1034 if (mi_row + mi_size < cm->mi_rows && vt.vt->vert[0].variance < threshold | 1057 if (mi_row + mi_size < cm->mi_rows && vt.vt->vert[0].variance < threshold |
1035 && vt.vt->vert[1].variance < threshold) { | 1058 && vt.vt->vert[1].variance < threshold) { |
1036 set_block_size(cm, m, get_subsize(block_size, PARTITION_VERT), mis, mi_row, | 1059 set_block_size(cm, m, get_subsize(bsize, PARTITION_VERT), mis, mi_row, |
1037 mi_col); | 1060 mi_col); |
1038 return 1; | 1061 return 1; |
1039 } | 1062 } |
1040 | 1063 |
1041 // horizontal split is available on all but the right border | 1064 // horizontal split is available on all but the right border |
1042 if (mi_col + mi_size < cm->mi_cols && vt.vt->horz[0].variance < threshold | 1065 if (mi_col + mi_size < cm->mi_cols && vt.vt->horz[0].variance < threshold |
1043 && vt.vt->horz[1].variance < threshold) { | 1066 && vt.vt->horz[1].variance < threshold) { |
1044 set_block_size(cm, m, get_subsize(block_size, PARTITION_HORZ), mis, mi_row, | 1067 set_block_size(cm, m, get_subsize(bsize, PARTITION_HORZ), mis, mi_row, |
1045 mi_col); | 1068 mi_col); |
1046 return 1; | 1069 return 1; |
1047 } | 1070 } |
1048 | 1071 |
1049 return 0; | 1072 return 0; |
1050 } | 1073 } |
1051 #endif | 1074 #endif // PERFORM_RANDOM_PARTITIONING |
1052 | 1075 |
1053 static void choose_partitioning(VP9_COMP *cpi, MODE_INFO *m, int mi_row, | 1076 static void choose_partitioning(VP9_COMP *cpi, MODE_INFO *m, int mi_row, |
1054 int mi_col) { | 1077 int mi_col) { |
1055 VP9_COMMON * const cm = &cpi->common; | 1078 VP9_COMMON * const cm = &cpi->common; |
1056 MACROBLOCK *x = &cpi->mb; | 1079 MACROBLOCK *x = &cpi->mb; |
1057 MACROBLOCKD *xd = &cpi->mb.e_mbd; | 1080 MACROBLOCKD *xd = &cpi->mb.e_mbd; |
1058 const int mis = cm->mode_info_stride; | 1081 const int mis = cm->mode_info_stride; |
1059 // TODO(JBB): More experimentation or testing of this threshold; | 1082 // TODO(JBB): More experimentation or testing of this threshold; |
1060 int64_t threshold = 4; | 1083 int64_t threshold = 4; |
1061 int i, j, k; | 1084 int i, j, k; |
1062 v64x64 vt; | 1085 v64x64 vt; |
1063 unsigned char * s; | 1086 unsigned char * s; |
1064 int sp; | 1087 int sp; |
1065 const unsigned char * d; | 1088 const unsigned char * d; |
1066 int dp; | 1089 int dp; |
1067 int pixels_wide = 64, pixels_high = 64; | 1090 int pixels_wide = 64, pixels_high = 64; |
1068 | 1091 |
1069 vpx_memset(&vt, 0, sizeof(vt)); | 1092 vp9_zero(vt); |
1070 | 1093 set_offsets(cpi, mi_row, mi_col, BLOCK_64X64); |
1071 set_offsets(cpi, mi_row, mi_col, BLOCK_SIZE_SB64X64); | |
1072 | 1094 |
1073 if (xd->mb_to_right_edge < 0) | 1095 if (xd->mb_to_right_edge < 0) |
1074 pixels_wide += (xd->mb_to_right_edge >> 3); | 1096 pixels_wide += (xd->mb_to_right_edge >> 3); |
1075 | 1097 |
1076 if (xd->mb_to_bottom_edge < 0) | 1098 if (xd->mb_to_bottom_edge < 0) |
1077 pixels_high += (xd->mb_to_bottom_edge >> 3); | 1099 pixels_high += (xd->mb_to_bottom_edge >> 3); |
1078 | 1100 |
1079 s = x->plane[0].src.buf; | 1101 s = x->plane[0].src.buf; |
1080 sp = x->plane[0].src.stride; | 1102 sp = x->plane[0].src.stride; |
1081 | 1103 |
1082 // TODO(JBB): Clearly the higher the quantizer the fewer partitions we want | 1104 // TODO(JBB): Clearly the higher the quantizer the fewer partitions we want |
1083 // but this needs more experimentation. | 1105 // but this needs more experimentation. |
1084 threshold = threshold * cpi->common.base_qindex * cpi->common.base_qindex; | 1106 threshold = threshold * cpi->common.base_qindex * cpi->common.base_qindex; |
1085 | 1107 |
1086 d = vp9_64x64_zeros; | 1108 d = vp9_64x64_zeros; |
1087 dp = 64; | 1109 dp = 64; |
1088 if (cm->frame_type != KEY_FRAME) { | 1110 if (cm->frame_type != KEY_FRAME) { |
1089 int_mv nearest_mv, near_mv; | 1111 int_mv nearest_mv, near_mv; |
1090 YV12_BUFFER_CONFIG *ref_fb = &cm->yv12_fb[0]; | 1112 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, LAST_FRAME)]; |
| 1113 YV12_BUFFER_CONFIG *ref_fb = &cm->yv12_fb[idx]; |
1091 YV12_BUFFER_CONFIG *second_ref_fb = NULL; | 1114 YV12_BUFFER_CONFIG *second_ref_fb = NULL; |
1092 | 1115 |
1093 setup_pre_planes(xd, 0, ref_fb, mi_row, mi_col, | 1116 setup_pre_planes(xd, 0, ref_fb, mi_row, mi_col, |
1094 &xd->scale_factor[0]); | 1117 &xd->scale_factor[0]); |
1095 setup_pre_planes(xd, 1, second_ref_fb, mi_row, mi_col, | 1118 setup_pre_planes(xd, 1, second_ref_fb, mi_row, mi_col, |
1096 &xd->scale_factor[1]); | 1119 &xd->scale_factor[1]); |
1097 xd->mode_info_context->mbmi.ref_frame[0] = LAST_FRAME; | 1120 xd->mode_info_context->mbmi.ref_frame[0] = LAST_FRAME; |
1098 xd->mode_info_context->mbmi.sb_type = BLOCK_SIZE_SB64X64; | 1121 xd->mode_info_context->mbmi.sb_type = BLOCK_64X64; |
1099 vp9_find_best_ref_mvs(xd, m->mbmi.ref_mvs[m->mbmi.ref_frame[0]], | 1122 vp9_find_best_ref_mvs(xd, m->mbmi.ref_mvs[m->mbmi.ref_frame[0]], |
1100 &nearest_mv, &near_mv); | 1123 &nearest_mv, &near_mv); |
1101 | 1124 |
1102 xd->mode_info_context->mbmi.mv[0] = nearest_mv; | 1125 xd->mode_info_context->mbmi.mv[0] = nearest_mv; |
1103 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, BLOCK_SIZE_SB64X64); | 1126 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, BLOCK_64X64); |
1104 d = xd->plane[0].dst.buf; | 1127 d = xd->plane[0].dst.buf; |
1105 dp = xd->plane[0].dst.stride; | 1128 dp = xd->plane[0].dst.stride; |
1106 | |
1107 } | 1129 } |
1108 | 1130 |
1109 // Fill in the entire tree of 8x8 variances for splits. | 1131 // Fill in the entire tree of 8x8 variances for splits. |
1110 for (i = 0; i < 4; i++) { | 1132 for (i = 0; i < 4; i++) { |
1111 const int x32_idx = ((i & 1) << 5); | 1133 const int x32_idx = ((i & 1) << 5); |
1112 const int y32_idx = ((i >> 1) << 5); | 1134 const int y32_idx = ((i >> 1) << 5); |
1113 for (j = 0; j < 4; j++) { | 1135 for (j = 0; j < 4; j++) { |
1114 const int x16_idx = x32_idx + ((j & 1) << 4); | 1136 const int x16_idx = x32_idx + ((j & 1) << 4); |
1115 const int y16_idx = y32_idx + ((j >> 1) << 4); | 1137 const int y16_idx = y32_idx + ((j >> 1) << 4); |
1116 v16x16 *vst = &vt.split[i].split[j]; | 1138 v16x16 *vst = &vt.split[i].split[j]; |
1117 for (k = 0; k < 4; k++) { | 1139 for (k = 0; k < 4; k++) { |
1118 int x_idx = x16_idx + ((k & 1) << 3); | 1140 int x_idx = x16_idx + ((k & 1) << 3); |
1119 int y_idx = y16_idx + ((k >> 1) << 3); | 1141 int y_idx = y16_idx + ((k >> 1) << 3); |
1120 unsigned int sse = 0; | 1142 unsigned int sse = 0; |
1121 int sum = 0; | 1143 int sum = 0; |
1122 if (x_idx < pixels_wide && y_idx < pixels_high) | 1144 if (x_idx < pixels_wide && y_idx < pixels_high) |
1123 vp9_get_sse_sum_8x8(s + y_idx * sp + x_idx, sp, | 1145 vp9_get_sse_sum_8x8(s + y_idx * sp + x_idx, sp, |
1124 d + y_idx * dp + x_idx, dp, &sse, &sum); | 1146 d + y_idx * dp + x_idx, dp, &sse, &sum); |
1125 fill_variance(&vst->split[k].vt.none, sse, sum, 64); | 1147 fill_variance(&vst->split[k].vt.none, sse, sum, 64); |
1126 } | 1148 } |
1127 } | 1149 } |
1128 } | 1150 } |
1129 // Fill the rest of the variance tree by summing the split partition | 1151 // Fill the rest of the variance tree by summing the split partition |
1130 // values. | 1152 // values. |
1131 for (i = 0; i < 4; i++) { | 1153 for (i = 0; i < 4; i++) { |
1132 for (j = 0; j < 4; j++) { | 1154 for (j = 0; j < 4; j++) { |
1133 fill_variance_tree(&vt.split[i].split[j], BLOCK_SIZE_MB16X16); | 1155 fill_variance_tree(&vt.split[i].split[j], BLOCK_16X16); |
1134 } | 1156 } |
1135 fill_variance_tree(&vt.split[i], BLOCK_SIZE_SB32X32); | 1157 fill_variance_tree(&vt.split[i], BLOCK_32X32); |
1136 } | 1158 } |
1137 fill_variance_tree(&vt, BLOCK_SIZE_SB64X64); | 1159 fill_variance_tree(&vt, BLOCK_64X64); |
1138 // Now go through the entire structure, splitting every block size until | 1160 // Now go through the entire structure, splitting every block size until |
1139 // we get to one that's got a variance lower than our threshold, or we | 1161 // we get to one that's got a variance lower than our threshold, or we |
1140 // hit 8x8. | 1162 // hit 8x8. |
1141 if (!set_vt_partitioning(cpi, &vt, m, BLOCK_SIZE_SB64X64, mi_row, mi_col, | 1163 if (!set_vt_partitioning(cpi, &vt, m, BLOCK_64X64, mi_row, mi_col, |
1142 4)) { | 1164 4)) { |
1143 for (i = 0; i < 4; ++i) { | 1165 for (i = 0; i < 4; ++i) { |
1144 const int x32_idx = ((i & 1) << 2); | 1166 const int x32_idx = ((i & 1) << 2); |
1145 const int y32_idx = ((i >> 1) << 2); | 1167 const int y32_idx = ((i >> 1) << 2); |
1146 if (!set_vt_partitioning(cpi, &vt.split[i], m, BLOCK_SIZE_SB32X32, | 1168 if (!set_vt_partitioning(cpi, &vt.split[i], m, BLOCK_32X32, |
1147 (mi_row + y32_idx), (mi_col + x32_idx), 2)) { | 1169 (mi_row + y32_idx), (mi_col + x32_idx), 2)) { |
1148 for (j = 0; j < 4; ++j) { | 1170 for (j = 0; j < 4; ++j) { |
1149 const int x16_idx = ((j & 1) << 1); | 1171 const int x16_idx = ((j & 1) << 1); |
1150 const int y16_idx = ((j >> 1) << 1); | 1172 const int y16_idx = ((j >> 1) << 1); |
1151 if (!set_vt_partitioning(cpi, &vt.split[i].split[j], m, | 1173 if (!set_vt_partitioning(cpi, &vt.split[i].split[j], m, |
1152 BLOCK_SIZE_MB16X16, | 1174 BLOCK_16X16, |
1153 (mi_row + y32_idx + y16_idx), | 1175 (mi_row + y32_idx + y16_idx), |
1154 (mi_col + x32_idx + x16_idx), 1)) { | 1176 (mi_col + x32_idx + x16_idx), 1)) { |
1155 for (k = 0; k < 4; ++k) { | 1177 for (k = 0; k < 4; ++k) { |
1156 const int x8_idx = (k & 1); | 1178 const int x8_idx = (k & 1); |
1157 const int y8_idx = (k >> 1); | 1179 const int y8_idx = (k >> 1); |
1158 set_block_size(cm, m, BLOCK_SIZE_SB8X8, mis, | 1180 set_block_size(cm, m, BLOCK_8X8, mis, |
1159 (mi_row + y32_idx + y16_idx + y8_idx), | 1181 (mi_row + y32_idx + y16_idx + y8_idx), |
1160 (mi_col + x32_idx + x16_idx + x8_idx)); | 1182 (mi_col + x32_idx + x16_idx + x8_idx)); |
1161 } | 1183 } |
1162 } | 1184 } |
1163 } | 1185 } |
1164 } | 1186 } |
1165 } | 1187 } |
1166 } | 1188 } |
1167 } | 1189 } |
| 1190 |
1168 static void rd_use_partition(VP9_COMP *cpi, MODE_INFO *m, TOKENEXTRA **tp, | 1191 static void rd_use_partition(VP9_COMP *cpi, MODE_INFO *m, TOKENEXTRA **tp, |
1169 int mi_row, int mi_col, BLOCK_SIZE_TYPE bsize, | 1192 int mi_row, int mi_col, BLOCK_SIZE bsize, |
1170 int *rate, int64_t *dist, int do_recon) { | 1193 int *rate, int64_t *dist, int do_recon) { |
1171 VP9_COMMON * const cm = &cpi->common; | 1194 VP9_COMMON * const cm = &cpi->common; |
1172 MACROBLOCK * const x = &cpi->mb; | 1195 MACROBLOCK * const x = &cpi->mb; |
1173 MACROBLOCKD *xd = &cpi->mb.e_mbd; | 1196 MACROBLOCKD *xd = &cpi->mb.e_mbd; |
1174 const int mis = cm->mode_info_stride; | 1197 const int mis = cm->mode_info_stride; |
1175 int bsl = b_width_log2(bsize); | 1198 int bsl = b_width_log2(bsize); |
1176 int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; | 1199 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; |
1177 int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; | 1200 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; |
1178 int ms = num_4x4_blocks_wide / 2; | 1201 int ms = num_4x4_blocks_wide / 2; |
1179 int mh = num_4x4_blocks_high / 2; | 1202 int mh = num_4x4_blocks_high / 2; |
1180 int bss = (1 << bsl) / 4; | 1203 int bss = (1 << bsl) / 4; |
1181 int i, pl; | 1204 int i, pl; |
1182 PARTITION_TYPE partition = PARTITION_NONE; | 1205 PARTITION_TYPE partition = PARTITION_NONE; |
1183 BLOCK_SIZE_TYPE subsize; | 1206 BLOCK_SIZE subsize; |
1184 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; | 1207 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; |
1185 PARTITION_CONTEXT sl[8], sa[8]; | 1208 PARTITION_CONTEXT sl[8], sa[8]; |
1186 int last_part_rate = INT_MAX; | 1209 int last_part_rate = INT_MAX; |
1187 int64_t last_part_dist = INT_MAX; | 1210 int64_t last_part_dist = INT_MAX; |
1188 int split_rate = INT_MAX; | 1211 int split_rate = INT_MAX; |
1189 int64_t split_dist = INT_MAX; | 1212 int64_t split_dist = INT_MAX; |
1190 int none_rate = INT_MAX; | 1213 int none_rate = INT_MAX; |
1191 int64_t none_dist = INT_MAX; | 1214 int64_t none_dist = INT_MAX; |
1192 int chosen_rate = INT_MAX; | 1215 int chosen_rate = INT_MAX; |
1193 int64_t chosen_dist = INT_MAX; | 1216 int64_t chosen_dist = INT_MAX; |
1194 BLOCK_SIZE_TYPE sub_subsize = BLOCK_SIZE_AB4X4; | 1217 BLOCK_SIZE sub_subsize = BLOCK_4X4; |
1195 int splits_below = 0; | 1218 int splits_below = 0; |
1196 BLOCK_SIZE_TYPE bs_type = m->mbmi.sb_type; | 1219 BLOCK_SIZE bs_type = m->mbmi.sb_type; |
1197 | 1220 |
1198 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 1221 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
1199 return; | 1222 return; |
1200 | 1223 |
1201 partition = partition_lookup[bsl][bs_type]; | 1224 partition = partition_lookup[bsl][bs_type]; |
1202 | 1225 |
1203 subsize = get_subsize(bsize, partition); | 1226 subsize = get_subsize(bsize, partition); |
1204 | 1227 |
1205 if (bsize < BLOCK_SIZE_SB8X8) { | 1228 if (bsize < BLOCK_8X8) { |
| 1229 // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 |
| 1230 // there is nothing to be done. |
1206 if (xd->ab_index != 0) { | 1231 if (xd->ab_index != 0) { |
1207 *rate = 0; | 1232 *rate = 0; |
1208 *dist = 0; | 1233 *dist = 0; |
1209 return; | 1234 return; |
1210 } | 1235 } |
1211 } else { | 1236 } else { |
1212 *(get_sb_partitioning(x, bsize)) = subsize; | 1237 *(get_sb_partitioning(x, bsize)) = subsize; |
1213 } | 1238 } |
1214 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1239 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1215 | 1240 |
| 1241 x->fast_ms = 0; |
| 1242 x->pred_mv.as_int = 0; |
| 1243 x->subblock_ref = 0; |
| 1244 |
1216 if (cpi->sf.adjust_partitioning_from_last_frame) { | 1245 if (cpi->sf.adjust_partitioning_from_last_frame) { |
1217 // Check if any of the sub blocks are further split. | 1246 // Check if any of the sub blocks are further split. |
1218 if (partition == PARTITION_SPLIT && subsize > BLOCK_SIZE_SB8X8) { | 1247 if (partition == PARTITION_SPLIT && subsize > BLOCK_8X8) { |
1219 sub_subsize = get_subsize(subsize, PARTITION_SPLIT); | 1248 sub_subsize = get_subsize(subsize, PARTITION_SPLIT); |
1220 splits_below = 1; | 1249 splits_below = 1; |
1221 for (i = 0; i < 4; i++) { | 1250 for (i = 0; i < 4; i++) { |
1222 int jj = i >> 1, ii = i & 0x01; | 1251 int jj = i >> 1, ii = i & 0x01; |
1223 if (m[jj * bss * mis + ii * bss].mbmi.sb_type >= sub_subsize) { | 1252 if (m[jj * bss * mis + ii * bss].mbmi.sb_type >= sub_subsize) { |
1224 splits_below = 0; | 1253 splits_below = 0; |
1225 } | 1254 } |
1226 } | 1255 } |
1227 } | 1256 } |
1228 | 1257 |
(...skipping 19 matching lines...) Expand all Loading... |
1248 switch (partition) { | 1277 switch (partition) { |
1249 case PARTITION_NONE: | 1278 case PARTITION_NONE: |
1250 pick_sb_modes(cpi, mi_row, mi_col, &last_part_rate, &last_part_dist, | 1279 pick_sb_modes(cpi, mi_row, mi_col, &last_part_rate, &last_part_dist, |
1251 bsize, get_block_context(x, bsize), INT64_MAX); | 1280 bsize, get_block_context(x, bsize), INT64_MAX); |
1252 break; | 1281 break; |
1253 case PARTITION_HORZ: | 1282 case PARTITION_HORZ: |
1254 *(get_sb_index(xd, subsize)) = 0; | 1283 *(get_sb_index(xd, subsize)) = 0; |
1255 pick_sb_modes(cpi, mi_row, mi_col, &last_part_rate, &last_part_dist, | 1284 pick_sb_modes(cpi, mi_row, mi_col, &last_part_rate, &last_part_dist, |
1256 subsize, get_block_context(x, subsize), INT64_MAX); | 1285 subsize, get_block_context(x, subsize), INT64_MAX); |
1257 if (last_part_rate != INT_MAX && | 1286 if (last_part_rate != INT_MAX && |
1258 bsize >= BLOCK_SIZE_SB8X8 && mi_row + (mh >> 1) < cm->mi_rows) { | 1287 bsize >= BLOCK_8X8 && mi_row + (mh >> 1) < cm->mi_rows) { |
1259 int rt = 0; | 1288 int rt = 0; |
1260 int64_t dt = 0; | 1289 int64_t dt = 0; |
1261 update_state(cpi, get_block_context(x, subsize), subsize, 0); | 1290 update_state(cpi, get_block_context(x, subsize), subsize, 0); |
1262 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); | 1291 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); |
1263 *(get_sb_index(xd, subsize)) = 1; | 1292 *(get_sb_index(xd, subsize)) = 1; |
1264 pick_sb_modes(cpi, mi_row + (ms >> 1), mi_col, &rt, &dt, subsize, | 1293 pick_sb_modes(cpi, mi_row + (ms >> 1), mi_col, &rt, &dt, subsize, |
1265 get_block_context(x, subsize), INT64_MAX); | 1294 get_block_context(x, subsize), INT64_MAX); |
1266 if (rt == INT_MAX || dt == INT_MAX) { | 1295 if (rt == INT_MAX || dt == INT_MAX) { |
1267 last_part_rate = INT_MAX; | 1296 last_part_rate = INT_MAX; |
1268 last_part_dist = INT_MAX; | 1297 last_part_dist = INT_MAX; |
1269 break; | 1298 break; |
1270 } | 1299 } |
1271 | 1300 |
1272 last_part_rate += rt; | 1301 last_part_rate += rt; |
1273 last_part_dist += dt; | 1302 last_part_dist += dt; |
1274 } | 1303 } |
1275 break; | 1304 break; |
1276 case PARTITION_VERT: | 1305 case PARTITION_VERT: |
1277 *(get_sb_index(xd, subsize)) = 0; | 1306 *(get_sb_index(xd, subsize)) = 0; |
1278 pick_sb_modes(cpi, mi_row, mi_col, &last_part_rate, &last_part_dist, | 1307 pick_sb_modes(cpi, mi_row, mi_col, &last_part_rate, &last_part_dist, |
1279 subsize, get_block_context(x, subsize), INT64_MAX); | 1308 subsize, get_block_context(x, subsize), INT64_MAX); |
1280 if (last_part_rate != INT_MAX && | 1309 if (last_part_rate != INT_MAX && |
1281 bsize >= BLOCK_SIZE_SB8X8 && mi_col + (ms >> 1) < cm->mi_cols) { | 1310 bsize >= BLOCK_8X8 && mi_col + (ms >> 1) < cm->mi_cols) { |
1282 int rt = 0; | 1311 int rt = 0; |
1283 int64_t dt = 0; | 1312 int64_t dt = 0; |
1284 update_state(cpi, get_block_context(x, subsize), subsize, 0); | 1313 update_state(cpi, get_block_context(x, subsize), subsize, 0); |
1285 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); | 1314 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); |
1286 *(get_sb_index(xd, subsize)) = 1; | 1315 *(get_sb_index(xd, subsize)) = 1; |
1287 pick_sb_modes(cpi, mi_row, mi_col + (ms >> 1), &rt, &dt, subsize, | 1316 pick_sb_modes(cpi, mi_row, mi_col + (ms >> 1), &rt, &dt, subsize, |
1288 get_block_context(x, subsize), INT64_MAX); | 1317 get_block_context(x, subsize), INT64_MAX); |
1289 if (rt == INT_MAX || dt == INT_MAX) { | 1318 if (rt == INT_MAX || dt == INT_MAX) { |
1290 last_part_rate = INT_MAX; | 1319 last_part_rate = INT_MAX; |
1291 last_part_dist = INT_MAX; | 1320 last_part_dist = INT_MAX; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1324 break; | 1353 break; |
1325 default: | 1354 default: |
1326 assert(0); | 1355 assert(0); |
1327 } | 1356 } |
1328 set_partition_seg_context(cm, xd, mi_row, mi_col); | 1357 set_partition_seg_context(cm, xd, mi_row, mi_col); |
1329 pl = partition_plane_context(xd, bsize); | 1358 pl = partition_plane_context(xd, bsize); |
1330 if (last_part_rate < INT_MAX) | 1359 if (last_part_rate < INT_MAX) |
1331 last_part_rate += x->partition_cost[pl][partition]; | 1360 last_part_rate += x->partition_cost[pl][partition]; |
1332 | 1361 |
1333 if (cpi->sf.adjust_partitioning_from_last_frame | 1362 if (cpi->sf.adjust_partitioning_from_last_frame |
1334 && partition != PARTITION_SPLIT && bsize > BLOCK_SIZE_SB8X8 | 1363 && partition != PARTITION_SPLIT && bsize > BLOCK_8X8 |
1335 && (mi_row + ms < cm->mi_rows || mi_row + (ms >> 1) == cm->mi_rows) | 1364 && (mi_row + ms < cm->mi_rows || mi_row + (ms >> 1) == cm->mi_rows) |
1336 && (mi_col + ms < cm->mi_cols || mi_col + (ms >> 1) == cm->mi_cols)) { | 1365 && (mi_col + ms < cm->mi_cols || mi_col + (ms >> 1) == cm->mi_cols)) { |
1337 BLOCK_SIZE_TYPE split_subsize = get_subsize(bsize, PARTITION_SPLIT); | 1366 BLOCK_SIZE split_subsize = get_subsize(bsize, PARTITION_SPLIT); |
1338 split_rate = 0; | 1367 split_rate = 0; |
1339 split_dist = 0; | 1368 split_dist = 0; |
1340 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1369 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1341 | 1370 |
1342 // Split partition. | 1371 // Split partition. |
1343 for (i = 0; i < 4; i++) { | 1372 for (i = 0; i < 4; i++) { |
1344 int x_idx = (i & 1) * (num_4x4_blocks_wide >> 2); | 1373 int x_idx = (i & 1) * (num_4x4_blocks_wide >> 2); |
1345 int y_idx = (i >> 1) * (num_4x4_blocks_wide >> 2); | 1374 int y_idx = (i >> 1) * (num_4x4_blocks_wide >> 2); |
1346 int rt = 0; | 1375 int rt = 0; |
1347 int64_t dt = 0; | 1376 int64_t dt = 0; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1387 | 1416 |
1388 chosen_rate = split_rate; | 1417 chosen_rate = split_rate; |
1389 chosen_dist = split_dist; | 1418 chosen_dist = split_dist; |
1390 } | 1419 } |
1391 } | 1420 } |
1392 | 1421 |
1393 // If last_part is better set the partitioning to that... | 1422 // If last_part is better set the partitioning to that... |
1394 if (RDCOST(x->rdmult, x->rddiv, last_part_rate, last_part_dist) | 1423 if (RDCOST(x->rdmult, x->rddiv, last_part_rate, last_part_dist) |
1395 < RDCOST(x->rdmult, x->rddiv, chosen_rate, chosen_dist)) { | 1424 < RDCOST(x->rdmult, x->rddiv, chosen_rate, chosen_dist)) { |
1396 m->mbmi.sb_type = bsize; | 1425 m->mbmi.sb_type = bsize; |
1397 if (bsize >= BLOCK_SIZE_SB8X8) | 1426 if (bsize >= BLOCK_8X8) |
1398 *(get_sb_partitioning(x, bsize)) = subsize; | 1427 *(get_sb_partitioning(x, bsize)) = subsize; |
1399 chosen_rate = last_part_rate; | 1428 chosen_rate = last_part_rate; |
1400 chosen_dist = last_part_dist; | 1429 chosen_dist = last_part_dist; |
1401 } | 1430 } |
1402 // If none was better set the partitioning to that... | 1431 // If none was better set the partitioning to that... |
1403 if (RDCOST(x->rdmult, x->rddiv, chosen_rate, chosen_dist) | 1432 if (RDCOST(x->rdmult, x->rddiv, chosen_rate, chosen_dist) |
1404 > RDCOST(x->rdmult, x->rddiv, none_rate, none_dist)) { | 1433 > RDCOST(x->rdmult, x->rddiv, none_rate, none_dist)) { |
1405 if (bsize >= BLOCK_SIZE_SB8X8) | 1434 if (bsize >= BLOCK_8X8) |
1406 *(get_sb_partitioning(x, bsize)) = bsize; | 1435 *(get_sb_partitioning(x, bsize)) = bsize; |
1407 chosen_rate = none_rate; | 1436 chosen_rate = none_rate; |
1408 chosen_dist = none_dist; | 1437 chosen_dist = none_dist; |
1409 } | 1438 } |
1410 | 1439 |
1411 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1440 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1412 | 1441 |
1413 // We must have chosen a partitioning and encoding or we'll fail later on. | 1442 // We must have chosen a partitioning and encoding or we'll fail later on. |
1414 // No other opportunities for success. | 1443 // No other opportunities for success. |
1415 if ( bsize == BLOCK_SIZE_SB64X64) | 1444 if ( bsize == BLOCK_64X64) |
1416 assert(chosen_rate < INT_MAX && chosen_dist < INT_MAX); | 1445 assert(chosen_rate < INT_MAX && chosen_dist < INT_MAX); |
1417 | 1446 |
1418 if (do_recon) | 1447 if (do_recon) |
1419 encode_sb(cpi, tp, mi_row, mi_col, bsize == BLOCK_SIZE_SB64X64, bsize); | 1448 encode_sb(cpi, tp, mi_row, mi_col, bsize == BLOCK_64X64, bsize); |
1420 | 1449 |
1421 *rate = chosen_rate; | 1450 *rate = chosen_rate; |
1422 *dist = chosen_dist; | 1451 *dist = chosen_dist; |
1423 } | 1452 } |
1424 | 1453 |
| 1454 static const BLOCK_SIZE min_partition_size[BLOCK_SIZES] = { |
| 1455 BLOCK_4X4, BLOCK_4X4, BLOCK_4X4, BLOCK_4X4, |
| 1456 BLOCK_4X4, BLOCK_4X4, BLOCK_8X8, BLOCK_8X8, |
| 1457 BLOCK_8X8, BLOCK_16X16, BLOCK_16X16, BLOCK_16X16, BLOCK_16X16 |
| 1458 }; |
| 1459 |
| 1460 static const BLOCK_SIZE max_partition_size[BLOCK_SIZES] = { |
| 1461 BLOCK_8X8, BLOCK_16X16, BLOCK_16X16, BLOCK_16X16, |
| 1462 BLOCK_32X32, BLOCK_32X32, BLOCK_32X32, BLOCK_64X64, |
| 1463 BLOCK_64X64, BLOCK_64X64, BLOCK_64X64, BLOCK_64X64, BLOCK_64X64 |
| 1464 }; |
| 1465 |
| 1466 // Look at all the mode_info entries for blocks that are part of this |
| 1467 // partition and find the min and max values for sb_type. |
| 1468 // At the moment this is designed to work on a 64x64 SB but could be |
| 1469 // adjusted to use a size parameter. |
| 1470 // |
| 1471 // The min and max are assumed to have been initialized prior to calling this |
| 1472 // function so repeat calls can accumulate a min and max of more than one sb64. |
| 1473 static void get_sb_partition_size_range(VP9_COMP *cpi, MODE_INFO * mi, |
| 1474 BLOCK_SIZE *min_block_size, |
| 1475 BLOCK_SIZE *max_block_size ) { |
| 1476 MACROBLOCKD *const xd = &cpi->mb.e_mbd; |
| 1477 int sb_width_in_blocks = MI_BLOCK_SIZE; |
| 1478 int sb_height_in_blocks = MI_BLOCK_SIZE; |
| 1479 int i, j; |
| 1480 int index = 0; |
| 1481 |
| 1482 // Check the sb_type for each block that belongs to this region. |
| 1483 for (i = 0; i < sb_height_in_blocks; ++i) { |
| 1484 for (j = 0; j < sb_width_in_blocks; ++j) { |
| 1485 *min_block_size = MIN(*min_block_size, mi[index + j].mbmi.sb_type); |
| 1486 *max_block_size = MAX(*max_block_size, mi[index + j].mbmi.sb_type); |
| 1487 } |
| 1488 index += xd->mode_info_stride; |
| 1489 } |
| 1490 } |
| 1491 |
| 1492 // Look at neighboring blocks and set a min and max partition size based on |
| 1493 // what they chose. |
| 1494 static void rd_auto_partition_range(VP9_COMP *cpi, |
| 1495 BLOCK_SIZE *min_block_size, |
| 1496 BLOCK_SIZE *max_block_size) { |
| 1497 MACROBLOCKD *const xd = &cpi->mb.e_mbd; |
| 1498 MODE_INFO *mi = xd->mode_info_context; |
| 1499 MODE_INFO *above_sb64_mi; |
| 1500 MODE_INFO *left_sb64_mi; |
| 1501 const MB_MODE_INFO *const above_mbmi = &mi[-xd->mode_info_stride].mbmi; |
| 1502 const MB_MODE_INFO *const left_mbmi = &mi[-1].mbmi; |
| 1503 const int left_in_image = xd->left_available && left_mbmi->in_image; |
| 1504 const int above_in_image = xd->up_available && above_mbmi->in_image; |
| 1505 |
| 1506 // Frequency check |
| 1507 if (cpi->sf.auto_min_max_partition_count <= 0) { |
| 1508 cpi->sf.auto_min_max_partition_count = |
| 1509 cpi->sf.auto_min_max_partition_interval; |
| 1510 *min_block_size = BLOCK_4X4; |
| 1511 *max_block_size = BLOCK_64X64; |
| 1512 return; |
| 1513 } else { |
| 1514 --cpi->sf.auto_min_max_partition_count; |
| 1515 } |
| 1516 |
| 1517 // Set default values if not left or above neighbour |
| 1518 if (!left_in_image && !above_in_image) { |
| 1519 *min_block_size = BLOCK_4X4; |
| 1520 *max_block_size = BLOCK_64X64; |
| 1521 } else { |
| 1522 // Default "min to max" and "max to min" |
| 1523 *min_block_size = BLOCK_64X64; |
| 1524 *max_block_size = BLOCK_4X4; |
| 1525 |
| 1526 // Find the min and max partition sizes used in the left SB64 |
| 1527 if (left_in_image) { |
| 1528 left_sb64_mi = &mi[-MI_BLOCK_SIZE]; |
| 1529 get_sb_partition_size_range(cpi, left_sb64_mi, |
| 1530 min_block_size, max_block_size); |
| 1531 } |
| 1532 |
| 1533 // Find the min and max partition sizes used in the above SB64 taking |
| 1534 // the values found for left as a starting point. |
| 1535 if (above_in_image) { |
| 1536 above_sb64_mi = &mi[-xd->mode_info_stride * MI_BLOCK_SIZE]; |
| 1537 get_sb_partition_size_range(cpi, above_sb64_mi, |
| 1538 min_block_size, max_block_size); |
| 1539 } |
| 1540 |
| 1541 // give a bit of leaway either side of the observed min and max |
| 1542 *min_block_size = min_partition_size[*min_block_size]; |
| 1543 *max_block_size = max_partition_size[*max_block_size]; |
| 1544 } |
| 1545 } |
| 1546 |
| 1547 static void compute_fast_motion_search_level(VP9_COMP *cpi, BLOCK_SIZE bsize) { |
| 1548 VP9_COMMON *const cm = &cpi->common; |
| 1549 MACROBLOCK *const x = &cpi->mb; |
| 1550 MACROBLOCKD *const xd = &x->e_mbd; |
| 1551 |
| 1552 // Only use 8x8 result for non HD videos. |
| 1553 // int use_8x8 = (MIN(cpi->common.width, cpi->common.height) < 720) ? 1 : 0; |
| 1554 int use_8x8 = 1; |
| 1555 |
| 1556 if (cm->frame_type && !cpi->is_src_frame_alt_ref && |
| 1557 ((use_8x8 && bsize == BLOCK_16X16) || |
| 1558 bsize == BLOCK_32X32 || bsize == BLOCK_64X64)) { |
| 1559 int ref0 = 0, ref1 = 0, ref2 = 0, ref3 = 0; |
| 1560 PICK_MODE_CONTEXT *block_context = NULL; |
| 1561 |
| 1562 if (bsize == BLOCK_16X16) { |
| 1563 block_context = x->sb8x8_context[xd->sb_index][xd->mb_index]; |
| 1564 } else if (bsize == BLOCK_32X32) { |
| 1565 block_context = x->mb_context[xd->sb_index]; |
| 1566 } else if (bsize == BLOCK_64X64) { |
| 1567 block_context = x->sb32_context; |
| 1568 } |
| 1569 |
| 1570 if (block_context) { |
| 1571 ref0 = block_context[0].mic.mbmi.ref_frame[0]; |
| 1572 ref1 = block_context[1].mic.mbmi.ref_frame[0]; |
| 1573 ref2 = block_context[2].mic.mbmi.ref_frame[0]; |
| 1574 ref3 = block_context[3].mic.mbmi.ref_frame[0]; |
| 1575 } |
| 1576 |
| 1577 // Currently, only consider 4 inter reference frames. |
| 1578 if (ref0 && ref1 && ref2 && ref3) { |
| 1579 int d01, d23, d02, d13; |
| 1580 |
| 1581 // Motion vectors for the four subblocks. |
| 1582 int16_t mvr0 = block_context[0].mic.mbmi.mv[0].as_mv.row; |
| 1583 int16_t mvc0 = block_context[0].mic.mbmi.mv[0].as_mv.col; |
| 1584 int16_t mvr1 = block_context[1].mic.mbmi.mv[0].as_mv.row; |
| 1585 int16_t mvc1 = block_context[1].mic.mbmi.mv[0].as_mv.col; |
| 1586 int16_t mvr2 = block_context[2].mic.mbmi.mv[0].as_mv.row; |
| 1587 int16_t mvc2 = block_context[2].mic.mbmi.mv[0].as_mv.col; |
| 1588 int16_t mvr3 = block_context[3].mic.mbmi.mv[0].as_mv.row; |
| 1589 int16_t mvc3 = block_context[3].mic.mbmi.mv[0].as_mv.col; |
| 1590 |
| 1591 // Adjust sign if ref is alt_ref. |
| 1592 if (cm->ref_frame_sign_bias[ref0]) { |
| 1593 mvr0 *= -1; |
| 1594 mvc0 *= -1; |
| 1595 } |
| 1596 |
| 1597 if (cm->ref_frame_sign_bias[ref1]) { |
| 1598 mvr1 *= -1; |
| 1599 mvc1 *= -1; |
| 1600 } |
| 1601 |
| 1602 if (cm->ref_frame_sign_bias[ref2]) { |
| 1603 mvr2 *= -1; |
| 1604 mvc2 *= -1; |
| 1605 } |
| 1606 |
| 1607 if (cm->ref_frame_sign_bias[ref3]) { |
| 1608 mvr3 *= -1; |
| 1609 mvc3 *= -1; |
| 1610 } |
| 1611 |
| 1612 // Calculate mv distances. |
| 1613 d01 = MAX(abs(mvr0 - mvr1), abs(mvc0 - mvc1)); |
| 1614 d23 = MAX(abs(mvr2 - mvr3), abs(mvc2 - mvc3)); |
| 1615 d02 = MAX(abs(mvr0 - mvr2), abs(mvc0 - mvc2)); |
| 1616 d13 = MAX(abs(mvr1 - mvr3), abs(mvc1 - mvc3)); |
| 1617 |
| 1618 if (d01 < FAST_MOTION_MV_THRESH && d23 < FAST_MOTION_MV_THRESH && |
| 1619 d02 < FAST_MOTION_MV_THRESH && d13 < FAST_MOTION_MV_THRESH) { |
| 1620 // Set fast motion search level. |
| 1621 x->fast_ms = 1; |
| 1622 |
| 1623 // Calculate prediction MV. |
| 1624 x->pred_mv.as_mv.row = (mvr0 + mvr1 + mvr2 + mvr3) >> 2; |
| 1625 x->pred_mv.as_mv.col = (mvc0 + mvc1 + mvc2 + mvc3) >> 2; |
| 1626 |
| 1627 if (ref0 == ref1 && ref1 == ref2 && ref2 == ref3 && |
| 1628 d01 < 2 && d23 < 2 && d02 < 2 && d13 < 2) { |
| 1629 // Set fast motion search level. |
| 1630 x->fast_ms = 2; |
| 1631 |
| 1632 if (!d01 && !d23 && !d02 && !d13) { |
| 1633 x->fast_ms = 3; |
| 1634 x->subblock_ref = ref0; |
| 1635 } |
| 1636 } |
| 1637 } |
| 1638 } |
| 1639 } |
| 1640 } |
1425 | 1641 |
1426 // TODO(jingning,jimbankoski,rbultje): properly skip partition types that are | 1642 // TODO(jingning,jimbankoski,rbultje): properly skip partition types that are |
1427 // unlikely to be selected depending on previously rate-distortion optimization | 1643 // unlikely to be selected depending on previous rate-distortion optimization |
1428 // results, for encoding speed-up. | 1644 // results, for encoding speed-up. |
1429 static void rd_pick_partition(VP9_COMP *cpi, TOKENEXTRA **tp, int mi_row, | 1645 static void rd_pick_partition(VP9_COMP *cpi, TOKENEXTRA **tp, int mi_row, |
1430 int mi_col, BLOCK_SIZE_TYPE bsize, int *rate, | 1646 int mi_col, BLOCK_SIZE bsize, int *rate, |
1431 int64_t *dist, int do_recon, int64_t best_rd) { | 1647 int64_t *dist, int do_recon, int64_t best_rd) { |
1432 VP9_COMMON * const cm = &cpi->common; | 1648 VP9_COMMON * const cm = &cpi->common; |
1433 MACROBLOCK * const x = &cpi->mb; | 1649 MACROBLOCK * const x = &cpi->mb; |
1434 MACROBLOCKD * const xd = &x->e_mbd; | 1650 MACROBLOCKD * const xd = &x->e_mbd; |
1435 int bsl = b_width_log2(bsize), bs = 1 << bsl; | 1651 int bsl = b_width_log2(bsize), bs = 1 << bsl; |
1436 int ms = bs / 2; | 1652 int ms = bs / 2; |
1437 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; | 1653 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; |
1438 PARTITION_CONTEXT sl[8], sa[8]; | 1654 PARTITION_CONTEXT sl[8], sa[8]; |
1439 TOKENEXTRA *tp_orig = *tp; | 1655 TOKENEXTRA *tp_orig = *tp; |
1440 int i, pl; | 1656 int i, pl; |
1441 BLOCK_SIZE_TYPE subsize; | 1657 BLOCK_SIZE subsize; |
1442 int srate = INT_MAX; | 1658 int this_rate, sum_rate = 0, best_rate = INT_MAX; |
1443 int64_t sdist = INT_MAX; | 1659 int64_t this_dist, sum_dist = 0, best_dist = INT64_MAX; |
1444 | 1660 int64_t sum_rd = 0; |
| 1661 int do_split = bsize >= BLOCK_8X8; |
| 1662 int do_rect = 1; |
| 1663 // Override skipping rectangular partition operations for edge blocks |
| 1664 const int force_horz_split = (mi_row + (ms >> 1) >= cm->mi_rows); |
| 1665 const int force_vert_split = (mi_col + (ms >> 1) >= cm->mi_cols); |
| 1666 |
| 1667 int partition_none_allowed = !force_horz_split && !force_vert_split; |
| 1668 int partition_horz_allowed = !force_vert_split && bsize >= BLOCK_8X8; |
| 1669 int partition_vert_allowed = !force_horz_split && bsize >= BLOCK_8X8; |
| 1670 |
| 1671 int partition_split_done = 0; |
1445 (void) *tp_orig; | 1672 (void) *tp_orig; |
1446 | 1673 |
1447 if (bsize < BLOCK_SIZE_SB8X8) | 1674 if (bsize < BLOCK_8X8) { |
| 1675 // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 |
| 1676 // there is nothing to be done. |
1448 if (xd->ab_index != 0) { | 1677 if (xd->ab_index != 0) { |
1449 *rate = 0; | 1678 *rate = 0; |
1450 *dist = 0; | 1679 *dist = 0; |
1451 return; | 1680 return; |
1452 } | 1681 } |
| 1682 } |
1453 assert(mi_height_log2(bsize) == mi_width_log2(bsize)); | 1683 assert(mi_height_log2(bsize) == mi_width_log2(bsize)); |
1454 | 1684 |
| 1685 // Determine partition types in search according to the speed features. |
| 1686 // The threshold set here has to be of square block size. |
| 1687 if (cpi->sf.auto_min_max_partition_size) { |
| 1688 partition_none_allowed &= (bsize <= cpi->sf.max_partition_size && |
| 1689 bsize >= cpi->sf.min_partition_size); |
| 1690 partition_horz_allowed &= ((bsize <= cpi->sf.max_partition_size && |
| 1691 bsize > cpi->sf.min_partition_size) || |
| 1692 force_horz_split); |
| 1693 partition_vert_allowed &= ((bsize <= cpi->sf.max_partition_size && |
| 1694 bsize > cpi->sf.min_partition_size) || |
| 1695 force_vert_split); |
| 1696 do_split &= bsize > cpi->sf.min_partition_size; |
| 1697 } |
| 1698 if (cpi->sf.use_square_partition_only) { |
| 1699 partition_horz_allowed &= force_horz_split; |
| 1700 partition_vert_allowed &= force_vert_split; |
| 1701 } |
| 1702 |
1455 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1703 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1456 | 1704 |
| 1705 if (cpi->sf.disable_split_var_thresh && partition_none_allowed) { |
| 1706 unsigned int source_variancey; |
| 1707 vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col); |
| 1708 source_variancey = get_sby_perpixel_variance(cpi, x, bsize); |
| 1709 if (source_variancey < cpi->sf.disable_split_var_thresh) { |
| 1710 do_split = 0; |
| 1711 if (source_variancey < cpi->sf.disable_split_var_thresh / 2) |
| 1712 do_rect = 0; |
| 1713 } |
| 1714 } |
| 1715 |
| 1716 // PARTITION_NONE |
| 1717 if (partition_none_allowed) { |
| 1718 pick_sb_modes(cpi, mi_row, mi_col, &this_rate, &this_dist, bsize, |
| 1719 get_block_context(x, bsize), best_rd); |
| 1720 if (this_rate != INT_MAX) { |
| 1721 if (bsize >= BLOCK_8X8) { |
| 1722 set_partition_seg_context(cm, xd, mi_row, mi_col); |
| 1723 pl = partition_plane_context(xd, bsize); |
| 1724 this_rate += x->partition_cost[pl][PARTITION_NONE]; |
| 1725 } |
| 1726 sum_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_dist); |
| 1727 if (sum_rd < best_rd) { |
| 1728 best_rate = this_rate; |
| 1729 best_dist = this_dist; |
| 1730 best_rd = sum_rd; |
| 1731 if (bsize >= BLOCK_8X8) |
| 1732 *(get_sb_partitioning(x, bsize)) = bsize; |
| 1733 } |
| 1734 } |
| 1735 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
| 1736 } |
| 1737 |
1457 // PARTITION_SPLIT | 1738 // PARTITION_SPLIT |
1458 if (!cpi->sf.use_partitions_greater_than | 1739 sum_rd = 0; |
1459 || (cpi->sf.use_partitions_greater_than | 1740 // TODO(jingning): use the motion vectors given by the above search as |
1460 && bsize > cpi->sf.greater_than_block_size)) { | 1741 // the starting point of motion search in the following partition type check. |
1461 if (bsize > BLOCK_SIZE_SB8X8) { | 1742 if (do_split) { |
1462 int r4 = 0; | 1743 subsize = get_subsize(bsize, PARTITION_SPLIT); |
1463 int64_t d4 = 0, sum_rd = 0; | 1744 for (i = 0; i < 4 && sum_rd < best_rd; ++i) { |
1464 subsize = get_subsize(bsize, PARTITION_SPLIT); | 1745 int x_idx = (i & 1) * (ms >> 1); |
1465 | 1746 int y_idx = (i >> 1) * (ms >> 1); |
1466 for (i = 0; i < 4 && sum_rd < best_rd; ++i) { | 1747 |
1467 int x_idx = (i & 1) * (ms >> 1); | 1748 if ((mi_row + y_idx >= cm->mi_rows) || |
1468 int y_idx = (i >> 1) * (ms >> 1); | 1749 (mi_col + x_idx >= cm->mi_cols)) |
1469 int r = 0; | 1750 continue; |
1470 int64_t d = 0; | 1751 |
1471 | 1752 *(get_sb_index(xd, subsize)) = i; |
1472 if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) | 1753 |
1473 continue; | 1754 rd_pick_partition(cpi, tp, mi_row + y_idx, mi_col + x_idx, subsize, |
1474 | 1755 &this_rate, &this_dist, i != 3, best_rd - sum_rd); |
1475 *(get_sb_index(xd, subsize)) = i; | 1756 |
1476 rd_pick_partition(cpi, tp, mi_row + y_idx, mi_col + x_idx, subsize, &r, | 1757 if (this_rate == INT_MAX) { |
1477 &d, i != 3, best_rd - sum_rd); | 1758 sum_rd = INT64_MAX; |
1478 | 1759 } else { |
1479 if (r == INT_MAX) { | 1760 sum_rate += this_rate; |
1480 r4 = INT_MAX; | 1761 sum_dist += this_dist; |
1481 sum_rd = INT64_MAX; | 1762 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
1482 } else { | 1763 } |
1483 r4 += r; | 1764 } |
1484 d4 += d; | 1765 if (sum_rd < best_rd && i == 4) { |
1485 sum_rd = RDCOST(x->rdmult, x->rddiv, r4, d4); | |
1486 } | |
1487 } | |
1488 set_partition_seg_context(cm, xd, mi_row, mi_col); | 1766 set_partition_seg_context(cm, xd, mi_row, mi_col); |
1489 pl = partition_plane_context(xd, bsize); | 1767 pl = partition_plane_context(xd, bsize); |
1490 if (r4 != INT_MAX && i == 4) { | 1768 sum_rate += x->partition_cost[pl][PARTITION_SPLIT]; |
1491 r4 += x->partition_cost[pl][PARTITION_SPLIT]; | 1769 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
| 1770 if (sum_rd < best_rd) { |
| 1771 best_rate = sum_rate; |
| 1772 best_dist = sum_dist; |
| 1773 best_rd = sum_rd; |
1492 *(get_sb_partitioning(x, bsize)) = subsize; | 1774 *(get_sb_partitioning(x, bsize)) = subsize; |
1493 assert(r4 >= 0); | 1775 } else { |
1494 assert(d4 >= 0); | 1776 // skip rectangular partition test when larger block size |
1495 srate = r4; | 1777 // gives better rd cost |
1496 sdist = d4; | 1778 if (cpi->sf.less_rectangular_check) |
1497 best_rd = MIN(best_rd, RDCOST(x->rdmult, x->rddiv, r4, d4)); | 1779 do_rect &= !partition_none_allowed; |
1498 } | 1780 } |
1499 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1781 } |
1500 } | 1782 partition_split_done = 1; |
| 1783 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1501 } | 1784 } |
1502 | 1785 |
1503 x->fast_ms = 0; | 1786 x->fast_ms = 0; |
1504 x->pred_mv.as_int = 0; | 1787 x->pred_mv.as_int = 0; |
1505 x->subblock_ref = 0; | 1788 x->subblock_ref = 0; |
1506 | 1789 |
1507 // Use 4 subblocks' motion estimation results to speed up current | 1790 if (partition_split_done && |
1508 // partition's checking. | 1791 cpi->sf.using_small_partition_info) { |
1509 if (cpi->sf.using_small_partition_info) { | 1792 compute_fast_motion_search_level(cpi, bsize); |
1510 // Only use 8x8 result for non HD videos. | 1793 } |
1511 // int use_8x8 = (MIN(cpi->common.width, cpi->common.height) < 720) ? 1 : 0; | 1794 |
1512 int use_8x8 = 1; | 1795 // PARTITION_HORZ |
1513 | 1796 if (partition_horz_allowed && do_rect) { |
1514 if (cm->frame_type && !cpi->is_src_frame_alt_ref && | 1797 subsize = get_subsize(bsize, PARTITION_HORZ); |
1515 ((use_8x8 && bsize == BLOCK_SIZE_MB16X16) || | 1798 *(get_sb_index(xd, subsize)) = 0; |
1516 bsize == BLOCK_SIZE_SB32X32 || bsize == BLOCK_SIZE_SB64X64)) { | 1799 pick_sb_modes(cpi, mi_row, mi_col, &sum_rate, &sum_dist, subsize, |
1517 int ref0 = 0, ref1 = 0, ref2 = 0, ref3 = 0; | 1800 get_block_context(x, subsize), best_rd); |
1518 | 1801 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
1519 if (bsize == BLOCK_SIZE_MB16X16) { | 1802 |
1520 ref0 = x->sb8x8_context[xd->sb_index][xd->mb_index][0].mic.mbmi. | 1803 if (sum_rd < best_rd && mi_row + (ms >> 1) < cm->mi_rows) { |
1521 ref_frame[0]; | 1804 update_state(cpi, get_block_context(x, subsize), subsize, 0); |
1522 ref1 = x->sb8x8_context[xd->sb_index][xd->mb_index][1].mic.mbmi. | 1805 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); |
1523 ref_frame[0]; | 1806 |
1524 ref2 = x->sb8x8_context[xd->sb_index][xd->mb_index][2].mic.mbmi. | 1807 *(get_sb_index(xd, subsize)) = 1; |
1525 ref_frame[0]; | 1808 pick_sb_modes(cpi, mi_row + (ms >> 1), mi_col, &this_rate, |
1526 ref3 = x->sb8x8_context[xd->sb_index][xd->mb_index][3].mic.mbmi. | 1809 &this_dist, subsize, get_block_context(x, subsize), |
1527 ref_frame[0]; | 1810 best_rd - sum_rd); |
1528 } else if (bsize == BLOCK_SIZE_SB32X32) { | 1811 if (this_rate == INT_MAX) { |
1529 ref0 = x->mb_context[xd->sb_index][0].mic.mbmi.ref_frame[0]; | 1812 sum_rd = INT64_MAX; |
1530 ref1 = x->mb_context[xd->sb_index][1].mic.mbmi.ref_frame[0]; | 1813 } else { |
1531 ref2 = x->mb_context[xd->sb_index][2].mic.mbmi.ref_frame[0]; | 1814 sum_rate += this_rate; |
1532 ref3 = x->mb_context[xd->sb_index][3].mic.mbmi.ref_frame[0]; | 1815 sum_dist += this_dist; |
1533 } else if (bsize == BLOCK_SIZE_SB64X64) { | 1816 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
1534 ref0 = x->sb32_context[0].mic.mbmi.ref_frame[0]; | 1817 } |
1535 ref1 = x->sb32_context[1].mic.mbmi.ref_frame[0]; | 1818 } |
1536 ref2 = x->sb32_context[2].mic.mbmi.ref_frame[0]; | 1819 if (sum_rd < best_rd) { |
1537 ref3 = x->sb32_context[3].mic.mbmi.ref_frame[0]; | |
1538 } | |
1539 | |
1540 // Currently, only consider 4 inter ref frames. | |
1541 if (ref0 && ref1 && ref2 && ref3) { | |
1542 int16_t mvr0 = 0, mvc0 = 0, mvr1 = 0, mvc1 = 0, mvr2 = 0, mvc2 = 0, | |
1543 mvr3 = 0, mvc3 = 0; | |
1544 int d01, d23, d02, d13; // motion vector distance between 2 blocks | |
1545 | |
1546 // Get each subblock's motion vectors. | |
1547 if (bsize == BLOCK_SIZE_MB16X16) { | |
1548 mvr0 = x->sb8x8_context[xd->sb_index][xd->mb_index][0].mic.mbmi.mv[0]. | |
1549 as_mv.row; | |
1550 mvc0 = x->sb8x8_context[xd->sb_index][xd->mb_index][0].mic.mbmi.mv[0]. | |
1551 as_mv.col; | |
1552 mvr1 = x->sb8x8_context[xd->sb_index][xd->mb_index][1].mic.mbmi.mv[0]. | |
1553 as_mv.row; | |
1554 mvc1 = x->sb8x8_context[xd->sb_index][xd->mb_index][1].mic.mbmi.mv[0]. | |
1555 as_mv.col; | |
1556 mvr2 = x->sb8x8_context[xd->sb_index][xd->mb_index][2].mic.mbmi.mv[0]. | |
1557 as_mv.row; | |
1558 mvc2 = x->sb8x8_context[xd->sb_index][xd->mb_index][2].mic.mbmi.mv[0]. | |
1559 as_mv.col; | |
1560 mvr3 = x->sb8x8_context[xd->sb_index][xd->mb_index][3].mic.mbmi.mv[0]. | |
1561 as_mv.row; | |
1562 mvc3 = x->sb8x8_context[xd->sb_index][xd->mb_index][3].mic.mbmi.mv[0]. | |
1563 as_mv.col; | |
1564 } else if (bsize == BLOCK_SIZE_SB32X32) { | |
1565 mvr0 = x->mb_context[xd->sb_index][0].mic.mbmi.mv[0].as_mv.row; | |
1566 mvc0 = x->mb_context[xd->sb_index][0].mic.mbmi.mv[0].as_mv.col; | |
1567 mvr1 = x->mb_context[xd->sb_index][1].mic.mbmi.mv[0].as_mv.row; | |
1568 mvc1 = x->mb_context[xd->sb_index][1].mic.mbmi.mv[0].as_mv.col; | |
1569 mvr2 = x->mb_context[xd->sb_index][2].mic.mbmi.mv[0].as_mv.row; | |
1570 mvc2 = x->mb_context[xd->sb_index][2].mic.mbmi.mv[0].as_mv.col; | |
1571 mvr3 = x->mb_context[xd->sb_index][3].mic.mbmi.mv[0].as_mv.row; | |
1572 mvc3 = x->mb_context[xd->sb_index][3].mic.mbmi.mv[0].as_mv.col; | |
1573 } else if (bsize == BLOCK_SIZE_SB64X64) { | |
1574 mvr0 = x->sb32_context[0].mic.mbmi.mv[0].as_mv.row; | |
1575 mvc0 = x->sb32_context[0].mic.mbmi.mv[0].as_mv.col; | |
1576 mvr1 = x->sb32_context[1].mic.mbmi.mv[0].as_mv.row; | |
1577 mvc1 = x->sb32_context[1].mic.mbmi.mv[0].as_mv.col; | |
1578 mvr2 = x->sb32_context[2].mic.mbmi.mv[0].as_mv.row; | |
1579 mvc2 = x->sb32_context[2].mic.mbmi.mv[0].as_mv.col; | |
1580 mvr3 = x->sb32_context[3].mic.mbmi.mv[0].as_mv.row; | |
1581 mvc3 = x->sb32_context[3].mic.mbmi.mv[0].as_mv.col; | |
1582 } | |
1583 | |
1584 // Adjust sign if ref is alt_ref | |
1585 if (cm->ref_frame_sign_bias[ref0]) { | |
1586 mvr0 *= -1; | |
1587 mvc0 *= -1; | |
1588 } | |
1589 | |
1590 if (cm->ref_frame_sign_bias[ref1]) { | |
1591 mvr1 *= -1; | |
1592 mvc1 *= -1; | |
1593 } | |
1594 | |
1595 if (cm->ref_frame_sign_bias[ref2]) { | |
1596 mvr2 *= -1; | |
1597 mvc2 *= -1; | |
1598 } | |
1599 | |
1600 if (cm->ref_frame_sign_bias[ref3]) { | |
1601 mvr3 *= -1; | |
1602 mvc3 *= -1; | |
1603 } | |
1604 | |
1605 // Calculate mv distances. | |
1606 d01 = MAX(abs(mvr0 - mvr1), abs(mvc0 - mvc1)); | |
1607 d23 = MAX(abs(mvr2 - mvr3), abs(mvc2 - mvc3)); | |
1608 d02 = MAX(abs(mvr0 - mvr2), abs(mvc0 - mvc2)); | |
1609 d13 = MAX(abs(mvr1 - mvr3), abs(mvc1 - mvc3)); | |
1610 | |
1611 if (d01 < 24 && d23 < 24 && d02 < 24 && d13 < 24) { | |
1612 // Set fast motion search level. | |
1613 x->fast_ms = 1; | |
1614 | |
1615 // Calculate prediction MV | |
1616 x->pred_mv.as_mv.row = (mvr0 + mvr1 + mvr2 + mvr3) >> 2; | |
1617 x->pred_mv.as_mv.col = (mvc0 + mvc1 + mvc2 + mvc3) >> 2; | |
1618 | |
1619 if (ref0 == ref1 && ref1 == ref2 && ref2 == ref3 && | |
1620 d01 < 2 && d23 < 2 && d02 < 2 && d13 < 2) { | |
1621 // Set fast motion search level. | |
1622 x->fast_ms = 2; | |
1623 | |
1624 if (!d01 && !d23 && !d02 && !d13) { | |
1625 x->fast_ms = 3; | |
1626 x->subblock_ref = ref0; | |
1627 } | |
1628 } | |
1629 } | |
1630 } | |
1631 } | |
1632 } | |
1633 | |
1634 if (!cpi->sf.use_partitions_less_than | |
1635 || (cpi->sf.use_partitions_less_than | |
1636 && bsize <= cpi->sf.less_than_block_size)) { | |
1637 int larger_is_better = 0; | |
1638 // PARTITION_NONE | |
1639 if ((mi_row + (ms >> 1) < cm->mi_rows) && | |
1640 (mi_col + (ms >> 1) < cm->mi_cols)) { | |
1641 int r; | |
1642 int64_t d; | |
1643 pick_sb_modes(cpi, mi_row, mi_col, &r, &d, bsize, | |
1644 get_block_context(x, bsize), best_rd); | |
1645 if (r != INT_MAX && bsize >= BLOCK_SIZE_SB8X8) { | |
1646 set_partition_seg_context(cm, xd, mi_row, mi_col); | |
1647 pl = partition_plane_context(xd, bsize); | |
1648 r += x->partition_cost[pl][PARTITION_NONE]; | |
1649 } | |
1650 | |
1651 if (r != INT_MAX && | |
1652 (bsize == BLOCK_SIZE_SB8X8 || | |
1653 RDCOST(x->rdmult, x->rddiv, r, d) < | |
1654 RDCOST(x->rdmult, x->rddiv, srate, sdist))) { | |
1655 best_rd = MIN(best_rd, RDCOST(x->rdmult, x->rddiv, r, d)); | |
1656 srate = r; | |
1657 sdist = d; | |
1658 larger_is_better = 1; | |
1659 if (bsize >= BLOCK_SIZE_SB8X8) | |
1660 *(get_sb_partitioning(x, bsize)) = bsize; | |
1661 } | |
1662 } | |
1663 | |
1664 if (bsize == BLOCK_SIZE_SB8X8) { | |
1665 int r4 = 0; | |
1666 int64_t d4 = 0, sum_rd = 0; | |
1667 subsize = get_subsize(bsize, PARTITION_SPLIT); | |
1668 | |
1669 for (i = 0; i < 4 && sum_rd < best_rd; ++i) { | |
1670 int x_idx = (i & 1) * (ms >> 1); | |
1671 int y_idx = (i >> 1) * (ms >> 1); | |
1672 int r = 0; | |
1673 int64_t d = 0; | |
1674 | |
1675 if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) | |
1676 continue; | |
1677 | |
1678 *(get_sb_index(xd, subsize)) = i; | |
1679 rd_pick_partition(cpi, tp, mi_row + y_idx, mi_col + x_idx, subsize, &r, | |
1680 &d, i != 3, best_rd - sum_rd); | |
1681 | |
1682 if (r == INT_MAX) { | |
1683 r4 = INT_MAX; | |
1684 sum_rd = INT64_MAX; | |
1685 } else { | |
1686 r4 += r; | |
1687 d4 += d; | |
1688 sum_rd = RDCOST(x->rdmult, x->rddiv, r4, d4); | |
1689 } | |
1690 } | |
1691 set_partition_seg_context(cm, xd, mi_row, mi_col); | 1820 set_partition_seg_context(cm, xd, mi_row, mi_col); |
1692 pl = partition_plane_context(xd, bsize); | 1821 pl = partition_plane_context(xd, bsize); |
1693 if (r4 != INT_MAX && i == 4) { | 1822 sum_rate += x->partition_cost[pl][PARTITION_HORZ]; |
1694 r4 += x->partition_cost[pl][PARTITION_SPLIT]; | 1823 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
1695 if (RDCOST(x->rdmult, x->rddiv, r4, d4) < | 1824 if (sum_rd < best_rd) { |
1696 RDCOST(x->rdmult, x->rddiv, srate, sdist)) { | 1825 best_rd = sum_rd; |
1697 srate = r4; | 1826 best_rate = sum_rate; |
1698 sdist = d4; | 1827 best_dist = sum_dist; |
1699 larger_is_better = 0; | 1828 *(get_sb_partitioning(x, bsize)) = subsize; |
1700 *(get_sb_partitioning(x, bsize)) = subsize; | 1829 } |
1701 best_rd = MIN(best_rd, RDCOST(x->rdmult, x->rddiv, r4, d4)); | 1830 } |
1702 } | 1831 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1703 } | 1832 } |
1704 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1833 |
1705 } | 1834 // PARTITION_VERT |
1706 | 1835 if (partition_vert_allowed && do_rect) { |
1707 if (!cpi->sf.use_square_partition_only && | 1836 subsize = get_subsize(bsize, PARTITION_VERT); |
1708 (!cpi->sf.less_rectangular_check ||!larger_is_better)) { | 1837 |
1709 // PARTITION_HORZ | 1838 *(get_sb_index(xd, subsize)) = 0; |
1710 if (bsize >= BLOCK_SIZE_SB8X8 && mi_col + (ms >> 1) < cm->mi_cols) { | 1839 pick_sb_modes(cpi, mi_row, mi_col, &sum_rate, &sum_dist, subsize, |
1711 int r2, r = 0; | 1840 get_block_context(x, subsize), best_rd); |
1712 int64_t d2, d = 0, h_rd; | 1841 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
1713 subsize = get_subsize(bsize, PARTITION_HORZ); | 1842 if (sum_rd < best_rd && mi_col + (ms >> 1) < cm->mi_cols) { |
1714 *(get_sb_index(xd, subsize)) = 0; | 1843 update_state(cpi, get_block_context(x, subsize), subsize, 0); |
1715 pick_sb_modes(cpi, mi_row, mi_col, &r2, &d2, subsize, | 1844 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); |
1716 get_block_context(x, subsize), best_rd); | 1845 |
1717 h_rd = RDCOST(x->rdmult, x->rddiv, r2, d2); | 1846 *(get_sb_index(xd, subsize)) = 1; |
1718 | 1847 pick_sb_modes(cpi, mi_row, mi_col + (ms >> 1), &this_rate, |
1719 if (r2 != INT_MAX && h_rd < best_rd && | 1848 &this_dist, subsize, get_block_context(x, subsize), |
1720 mi_row + (ms >> 1) < cm->mi_rows) { | 1849 best_rd - sum_rd); |
1721 update_state(cpi, get_block_context(x, subsize), subsize, 0); | 1850 if (this_rate == INT_MAX) { |
1722 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); | 1851 sum_rd = INT64_MAX; |
1723 | 1852 } else { |
1724 *(get_sb_index(xd, subsize)) = 1; | 1853 sum_rate += this_rate; |
1725 pick_sb_modes(cpi, mi_row + (ms >> 1), mi_col, &r, &d, subsize, | 1854 sum_dist += this_dist; |
1726 get_block_context(x, subsize), best_rd - h_rd); | 1855 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
1727 if (r == INT_MAX) { | 1856 } |
1728 r2 = INT_MAX; | 1857 } |
1729 } else { | 1858 if (sum_rd < best_rd) { |
1730 r2 += r; | 1859 set_partition_seg_context(cm, xd, mi_row, mi_col); |
1731 d2 += d; | 1860 pl = partition_plane_context(xd, bsize); |
1732 } | 1861 sum_rate += x->partition_cost[pl][PARTITION_VERT]; |
1733 } | 1862 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
1734 set_partition_seg_context(cm, xd, mi_row, mi_col); | 1863 if (sum_rd < best_rd) { |
1735 pl = partition_plane_context(xd, bsize); | 1864 best_rate = sum_rate; |
1736 if (r2 < INT_MAX) | 1865 best_dist = sum_dist; |
1737 r2 += x->partition_cost[pl][PARTITION_HORZ]; | 1866 best_rd = sum_rd; |
1738 if (r2 != INT_MAX && RDCOST(x->rdmult, x->rddiv, r2, d2) | 1867 *(get_sb_partitioning(x, bsize)) = subsize; |
1739 < RDCOST(x->rdmult, x->rddiv, srate, sdist)) { | 1868 } |
1740 best_rd = MIN(best_rd, RDCOST(x->rdmult, x->rddiv, r2, d2)); | 1869 } |
1741 srate = r2; | 1870 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1742 sdist = d2; | 1871 } |
1743 *(get_sb_partitioning(x, bsize)) = subsize; | 1872 |
1744 } | 1873 |
1745 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1874 *rate = best_rate; |
1746 } | 1875 *dist = best_dist; |
1747 | 1876 |
1748 // PARTITION_VERT | 1877 if (best_rate < INT_MAX && best_dist < INT64_MAX && do_recon) |
1749 if (bsize >= BLOCK_SIZE_SB8X8 && mi_row + (ms >> 1) < cm->mi_rows) { | 1878 encode_sb(cpi, tp, mi_row, mi_col, bsize == BLOCK_64X64, bsize); |
1750 int r2; | 1879 if (bsize == BLOCK_64X64) { |
1751 int64_t d2, v_rd; | |
1752 subsize = get_subsize(bsize, PARTITION_VERT); | |
1753 *(get_sb_index(xd, subsize)) = 0; | |
1754 pick_sb_modes(cpi, mi_row, mi_col, &r2, &d2, subsize, | |
1755 get_block_context(x, subsize), best_rd); | |
1756 v_rd = RDCOST(x->rdmult, x->rddiv, r2, d2); | |
1757 if (r2 != INT_MAX && v_rd < best_rd && | |
1758 mi_col + (ms >> 1) < cm->mi_cols) { | |
1759 int r = 0; | |
1760 int64_t d = 0; | |
1761 update_state(cpi, get_block_context(x, subsize), subsize, 0); | |
1762 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); | |
1763 | |
1764 *(get_sb_index(xd, subsize)) = 1; | |
1765 pick_sb_modes(cpi, mi_row, mi_col + (ms >> 1), &r, &d, subsize, | |
1766 get_block_context(x, subsize), best_rd - v_rd); | |
1767 if (r == INT_MAX) { | |
1768 r2 = INT_MAX; | |
1769 } else { | |
1770 r2 += r; | |
1771 d2 += d; | |
1772 } | |
1773 } | |
1774 set_partition_seg_context(cm, xd, mi_row, mi_col); | |
1775 pl = partition_plane_context(xd, bsize); | |
1776 if (r2 < INT_MAX) | |
1777 r2 += x->partition_cost[pl][PARTITION_VERT]; | |
1778 if (r2 != INT_MAX && | |
1779 RDCOST(x->rdmult, x->rddiv, r2, d2) | |
1780 < RDCOST(x->rdmult, x->rddiv, srate, sdist)) { | |
1781 srate = r2; | |
1782 sdist = d2; | |
1783 *(get_sb_partitioning(x, bsize)) = subsize; | |
1784 } | |
1785 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | |
1786 } | |
1787 } | |
1788 } | |
1789 *rate = srate; | |
1790 *dist = sdist; | |
1791 | |
1792 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | |
1793 | |
1794 if (srate < INT_MAX && sdist < INT_MAX && do_recon) | |
1795 encode_sb(cpi, tp, mi_row, mi_col, bsize == BLOCK_SIZE_SB64X64, bsize); | |
1796 | |
1797 if (bsize == BLOCK_SIZE_SB64X64) { | |
1798 assert(tp_orig < *tp); | 1880 assert(tp_orig < *tp); |
1799 assert(srate < INT_MAX); | 1881 assert(best_rate < INT_MAX); |
1800 assert(sdist < INT_MAX); | 1882 assert(best_dist < INT_MAX); |
1801 } else { | 1883 } else { |
1802 assert(tp_orig == *tp); | 1884 assert(tp_orig == *tp); |
1803 } | 1885 } |
1804 } | 1886 } |
1805 | 1887 |
1806 // Examines 64x64 block and chooses a best reference frame | 1888 // Examines 64x64 block and chooses a best reference frame |
1807 static void rd_pick_reference_frame(VP9_COMP *cpi, TOKENEXTRA **tp, int mi_row, | 1889 static void rd_pick_reference_frame(VP9_COMP *cpi, int mi_row, int mi_col) { |
1808 int mi_col, int *rate, int64_t *dist) { | |
1809 VP9_COMMON * const cm = &cpi->common; | 1890 VP9_COMMON * const cm = &cpi->common; |
1810 MACROBLOCK * const x = &cpi->mb; | 1891 MACROBLOCK * const x = &cpi->mb; |
1811 MACROBLOCKD * const xd = &x->e_mbd; | 1892 MACROBLOCKD * const xd = &x->e_mbd; |
1812 int bsl = b_width_log2(BLOCK_SIZE_SB64X64), bs = 1 << bsl; | 1893 int bsl = b_width_log2(BLOCK_64X64), bs = 1 << bsl; |
1813 int ms = bs / 2; | 1894 int ms = bs / 2; |
1814 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; | 1895 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; |
1815 PARTITION_CONTEXT sl[8], sa[8]; | 1896 PARTITION_CONTEXT sl[8], sa[8]; |
1816 int pl; | 1897 int pl; |
1817 int r; | 1898 int r; |
1818 int64_t d; | 1899 int64_t d; |
1819 | 1900 |
1820 save_context(cpi, mi_row, mi_col, a, l, sa, sl, BLOCK_SIZE_SB64X64); | 1901 save_context(cpi, mi_row, mi_col, a, l, sa, sl, BLOCK_64X64); |
1821 | 1902 |
1822 // Default is non mask (all reference frames allowed. | 1903 // Default is non mask (all reference frames allowed. |
1823 cpi->ref_frame_mask = 0; | 1904 cpi->ref_frame_mask = 0; |
1824 | 1905 |
1825 // Do RD search for 64x64. | 1906 // Do RD search for 64x64. |
1826 if ((mi_row + (ms >> 1) < cm->mi_rows) && | 1907 if ((mi_row + (ms >> 1) < cm->mi_rows) && |
1827 (mi_col + (ms >> 1) < cm->mi_cols)) { | 1908 (mi_col + (ms >> 1) < cm->mi_cols)) { |
1828 cpi->set_ref_frame_mask = 1; | 1909 cpi->set_ref_frame_mask = 1; |
1829 pick_sb_modes(cpi, mi_row, mi_col, &r, &d, BLOCK_SIZE_SB64X64, | 1910 pick_sb_modes(cpi, mi_row, mi_col, &r, &d, BLOCK_64X64, |
1830 get_block_context(x, BLOCK_SIZE_SB64X64), INT64_MAX); | 1911 get_block_context(x, BLOCK_64X64), INT64_MAX); |
1831 set_partition_seg_context(cm, xd, mi_row, mi_col); | 1912 set_partition_seg_context(cm, xd, mi_row, mi_col); |
1832 pl = partition_plane_context(xd, BLOCK_SIZE_SB64X64); | 1913 pl = partition_plane_context(xd, BLOCK_64X64); |
1833 r += x->partition_cost[pl][PARTITION_NONE]; | 1914 r += x->partition_cost[pl][PARTITION_NONE]; |
1834 | 1915 |
1835 *(get_sb_partitioning(x, BLOCK_SIZE_SB64X64)) = BLOCK_SIZE_SB64X64; | 1916 *(get_sb_partitioning(x, BLOCK_64X64)) = BLOCK_64X64; |
1836 cpi->set_ref_frame_mask = 0; | 1917 cpi->set_ref_frame_mask = 0; |
1837 } | 1918 } |
1838 | 1919 |
1839 *rate = r; | 1920 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, BLOCK_64X64); |
1840 *dist = d; | |
1841 // RDCOST(x->rdmult, x->rddiv, r, d) | |
1842 | |
1843 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, BLOCK_SIZE_SB64X64); | |
1844 | |
1845 /*if (srate < INT_MAX && sdist < INT_MAX) | |
1846 encode_sb(cpi, tp, mi_row, mi_col, 1, BLOCK_SIZE_SB64X64); | |
1847 | |
1848 if (bsize == BLOCK_SIZE_SB64X64) { | |
1849 assert(tp_orig < *tp); | |
1850 assert(srate < INT_MAX); | |
1851 assert(sdist < INT_MAX); | |
1852 } else { | |
1853 assert(tp_orig == *tp); | |
1854 } | |
1855 */ | |
1856 } | 1921 } |
1857 | 1922 |
1858 static void encode_sb_row(VP9_COMP *cpi, int mi_row, TOKENEXTRA **tp, | 1923 static void encode_sb_row(VP9_COMP *cpi, int mi_row, TOKENEXTRA **tp, |
1859 int *totalrate) { | 1924 int *totalrate) { |
1860 VP9_COMMON * const cm = &cpi->common; | 1925 VP9_COMMON * const cm = &cpi->common; |
1861 int mi_col; | 1926 int mi_col; |
1862 | 1927 |
1863 // Initialize the left context for the new SB row | 1928 // Initialize the left context for the new SB row |
1864 vpx_memset(&cm->left_context, 0, sizeof(cm->left_context)); | 1929 vpx_memset(&cm->left_context, 0, sizeof(cm->left_context)); |
1865 vpx_memset(cm->left_seg_context, 0, sizeof(cm->left_seg_context)); | 1930 vpx_memset(cm->left_seg_context, 0, sizeof(cm->left_seg_context)); |
1866 | 1931 |
1867 // Code each SB in the row | 1932 // Code each SB in the row |
1868 for (mi_col = cm->cur_tile_mi_col_start; mi_col < cm->cur_tile_mi_col_end; | 1933 for (mi_col = cm->cur_tile_mi_col_start; mi_col < cm->cur_tile_mi_col_end; |
1869 mi_col += MI_BLOCK_SIZE) { | 1934 mi_col += MI_BLOCK_SIZE) { |
1870 int dummy_rate; | 1935 int dummy_rate; |
1871 int64_t dummy_dist; | 1936 int64_t dummy_dist; |
1872 | 1937 |
1873 // Initialize a mask of modes that we will not consider; | 1938 // Initialize a mask of modes that we will not consider; |
1874 // cpi->unused_mode_skip_mask = 0x0000000AAE17F800 (test no golden) | 1939 // cpi->unused_mode_skip_mask = 0x0000000AAE17F800 (test no golden) |
1875 if (cpi->common.frame_type == KEY_FRAME) | 1940 if (cpi->common.frame_type == KEY_FRAME) |
1876 cpi->unused_mode_skip_mask = 0; | 1941 cpi->unused_mode_skip_mask = 0; |
1877 else | 1942 else |
1878 cpi->unused_mode_skip_mask = 0xFFFFFFFFFFFFFE00; | 1943 cpi->unused_mode_skip_mask = 0xFFFFFFFFFFFFFE00; |
1879 | 1944 |
1880 if (cpi->sf.reference_masking) { | 1945 if (cpi->sf.reference_masking) |
1881 rd_pick_reference_frame(cpi, tp, mi_row, mi_col, | 1946 rd_pick_reference_frame(cpi, mi_row, mi_col); |
1882 &dummy_rate, &dummy_dist); | |
1883 } | |
1884 | 1947 |
1885 if (cpi->sf.partition_by_variance || cpi->sf.use_lastframe_partitioning || | 1948 if (cpi->sf.partition_by_variance || cpi->sf.use_lastframe_partitioning || |
1886 cpi->sf.use_one_partition_size_always ) { | 1949 cpi->sf.use_one_partition_size_always ) { |
1887 const int idx_str = cm->mode_info_stride * mi_row + mi_col; | 1950 const int idx_str = cm->mode_info_stride * mi_row + mi_col; |
1888 MODE_INFO *m = cm->mi + idx_str; | 1951 MODE_INFO *m = cm->mi + idx_str; |
1889 MODE_INFO *p = cm->prev_mi + idx_str; | 1952 MODE_INFO *p = cm->prev_mi + idx_str; |
1890 | 1953 |
| 1954 cpi->mb.source_variance = UINT_MAX; |
1891 if (cpi->sf.use_one_partition_size_always) { | 1955 if (cpi->sf.use_one_partition_size_always) { |
1892 set_offsets(cpi, mi_row, mi_col, BLOCK_SIZE_SB64X64); | 1956 set_offsets(cpi, mi_row, mi_col, BLOCK_64X64); |
1893 set_partitioning(cpi, m, cpi->sf.always_this_block_size); | 1957 set_partitioning(cpi, m, cpi->sf.always_this_block_size); |
1894 rd_use_partition(cpi, m, tp, mi_row, mi_col, BLOCK_SIZE_SB64X64, | 1958 rd_use_partition(cpi, m, tp, mi_row, mi_col, BLOCK_64X64, |
1895 &dummy_rate, &dummy_dist, 1); | 1959 &dummy_rate, &dummy_dist, 1); |
1896 } else if (cpi->sf.partition_by_variance) { | 1960 } else if (cpi->sf.partition_by_variance) { |
1897 choose_partitioning(cpi, cm->mi, mi_row, mi_col); | 1961 choose_partitioning(cpi, cm->mi, mi_row, mi_col); |
1898 rd_use_partition(cpi, m, tp, mi_row, mi_col, BLOCK_SIZE_SB64X64, | 1962 rd_use_partition(cpi, m, tp, mi_row, mi_col, BLOCK_64X64, |
1899 &dummy_rate, &dummy_dist, 1); | 1963 &dummy_rate, &dummy_dist, 1); |
1900 } else { | 1964 } else { |
1901 if ((cpi->common.current_video_frame | 1965 if ((cpi->common.current_video_frame |
1902 % cpi->sf.last_partitioning_redo_frequency) == 0 | 1966 % cpi->sf.last_partitioning_redo_frequency) == 0 |
1903 || cm->prev_mi == 0 | 1967 || cm->prev_mi == 0 |
1904 || cpi->common.show_frame == 0 | 1968 || cpi->common.show_frame == 0 |
1905 || cpi->common.frame_type == KEY_FRAME | 1969 || cpi->common.frame_type == KEY_FRAME |
1906 || cpi->is_src_frame_alt_ref) { | 1970 || cpi->is_src_frame_alt_ref) { |
1907 rd_pick_partition(cpi, tp, mi_row, mi_col, BLOCK_SIZE_SB64X64, | 1971 // If required set upper and lower partition size limits |
| 1972 if (cpi->sf.auto_min_max_partition_size) { |
| 1973 set_offsets(cpi, mi_row, mi_col, BLOCK_64X64); |
| 1974 rd_auto_partition_range(cpi, |
| 1975 &cpi->sf.min_partition_size, |
| 1976 &cpi->sf.max_partition_size); |
| 1977 } |
| 1978 rd_pick_partition(cpi, tp, mi_row, mi_col, BLOCK_64X64, |
1908 &dummy_rate, &dummy_dist, 1, INT64_MAX); | 1979 &dummy_rate, &dummy_dist, 1, INT64_MAX); |
1909 } else { | 1980 } else { |
1910 copy_partitioning(cpi, m, p); | 1981 copy_partitioning(cpi, m, p); |
1911 rd_use_partition(cpi, m, tp, mi_row, mi_col, BLOCK_SIZE_SB64X64, | 1982 rd_use_partition(cpi, m, tp, mi_row, mi_col, BLOCK_64X64, |
1912 &dummy_rate, &dummy_dist, 1); | 1983 &dummy_rate, &dummy_dist, 1); |
1913 } | 1984 } |
1914 } | 1985 } |
1915 } else { | 1986 } else { |
1916 rd_pick_partition(cpi, tp, mi_row, mi_col, BLOCK_SIZE_SB64X64, | 1987 // If required set upper and lower partition size limits |
| 1988 if (cpi->sf.auto_min_max_partition_size) { |
| 1989 set_offsets(cpi, mi_row, mi_col, BLOCK_64X64); |
| 1990 rd_auto_partition_range(cpi, &cpi->sf.min_partition_size, |
| 1991 &cpi->sf.max_partition_size); |
| 1992 } |
| 1993 |
| 1994 rd_pick_partition(cpi, tp, mi_row, mi_col, BLOCK_64X64, |
1917 &dummy_rate, &dummy_dist, 1, INT64_MAX); | 1995 &dummy_rate, &dummy_dist, 1, INT64_MAX); |
1918 } | 1996 } |
1919 } | 1997 } |
1920 } | 1998 } |
1921 | 1999 |
1922 static void init_encode_frame_mb_context(VP9_COMP *cpi) { | 2000 static void init_encode_frame_mb_context(VP9_COMP *cpi) { |
1923 MACROBLOCK *const x = &cpi->mb; | 2001 MACROBLOCK *const x = &cpi->mb; |
1924 VP9_COMMON *const cm = &cpi->common; | 2002 VP9_COMMON *const cm = &cpi->common; |
1925 MACROBLOCKD *const xd = &x->e_mbd; | 2003 MACROBLOCKD *const xd = &x->e_mbd; |
1926 const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); | 2004 const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1967 } | 2045 } |
1968 | 2046 |
1969 static void switch_lossless_mode(VP9_COMP *cpi, int lossless) { | 2047 static void switch_lossless_mode(VP9_COMP *cpi, int lossless) { |
1970 if (lossless) { | 2048 if (lossless) { |
1971 // printf("Switching to lossless\n"); | 2049 // printf("Switching to lossless\n"); |
1972 cpi->mb.fwd_txm8x4 = vp9_short_walsh8x4; | 2050 cpi->mb.fwd_txm8x4 = vp9_short_walsh8x4; |
1973 cpi->mb.fwd_txm4x4 = vp9_short_walsh4x4; | 2051 cpi->mb.fwd_txm4x4 = vp9_short_walsh4x4; |
1974 cpi->mb.e_mbd.inv_txm4x4_1_add = vp9_short_iwalsh4x4_1_add; | 2052 cpi->mb.e_mbd.inv_txm4x4_1_add = vp9_short_iwalsh4x4_1_add; |
1975 cpi->mb.e_mbd.inv_txm4x4_add = vp9_short_iwalsh4x4_add; | 2053 cpi->mb.e_mbd.inv_txm4x4_add = vp9_short_iwalsh4x4_add; |
1976 cpi->mb.optimize = 0; | 2054 cpi->mb.optimize = 0; |
1977 cpi->mb.e_mbd.lf.filter_level = 0; | 2055 cpi->common.lf.filter_level = 0; |
1978 cpi->zbin_mode_boost_enabled = 0; | 2056 cpi->zbin_mode_boost_enabled = 0; |
1979 cpi->common.tx_mode = ONLY_4X4; | 2057 cpi->common.tx_mode = ONLY_4X4; |
1980 } else { | 2058 } else { |
1981 // printf("Not lossless\n"); | 2059 // printf("Not lossless\n"); |
1982 cpi->mb.fwd_txm8x4 = vp9_short_fdct8x4; | 2060 cpi->mb.fwd_txm8x4 = vp9_short_fdct8x4; |
1983 cpi->mb.fwd_txm4x4 = vp9_short_fdct4x4; | 2061 cpi->mb.fwd_txm4x4 = vp9_short_fdct4x4; |
1984 cpi->mb.e_mbd.inv_txm4x4_1_add = vp9_short_idct4x4_1_add; | 2062 cpi->mb.e_mbd.inv_txm4x4_1_add = vp9_short_idct4x4_1_add; |
1985 cpi->mb.e_mbd.inv_txm4x4_add = vp9_short_idct4x4_add; | 2063 cpi->mb.e_mbd.inv_txm4x4_add = vp9_short_idct4x4_add; |
1986 } | 2064 } |
1987 } | 2065 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2039 switch_tx_mode(cpi); | 2117 switch_tx_mode(cpi); |
2040 | 2118 |
2041 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { | 2119 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { |
2042 // Initialize encode frame context. | 2120 // Initialize encode frame context. |
2043 init_encode_frame_mb_context(cpi); | 2121 init_encode_frame_mb_context(cpi); |
2044 | 2122 |
2045 // Build a frame level activity map | 2123 // Build a frame level activity map |
2046 build_activity_map(cpi); | 2124 build_activity_map(cpi); |
2047 } | 2125 } |
2048 | 2126 |
2049 // re-initencode frame context. | 2127 // Re-initialize encode frame context. |
2050 init_encode_frame_mb_context(cpi); | 2128 init_encode_frame_mb_context(cpi); |
2051 | 2129 |
2052 vp9_zero(cpi->rd_comp_pred_diff); | 2130 vp9_zero(cpi->rd_comp_pred_diff); |
2053 vp9_zero(cpi->rd_filter_diff); | 2131 vp9_zero(cpi->rd_filter_diff); |
2054 vp9_zero(cpi->rd_tx_select_diff); | 2132 vp9_zero(cpi->rd_tx_select_diff); |
2055 vp9_zero(cpi->rd_tx_select_threshes); | 2133 vp9_zero(cpi->rd_tx_select_threshes); |
2056 | 2134 |
2057 set_prev_mi(cm); | 2135 set_prev_mi(cm); |
2058 | 2136 |
2059 { | 2137 { |
(...skipping 19 matching lines...) Expand all Loading... |
2079 mi_row < cm->cur_tile_mi_row_end; mi_row += 8) | 2157 mi_row < cm->cur_tile_mi_row_end; mi_row += 8) |
2080 encode_sb_row(cpi, mi_row, &tp, &totalrate); | 2158 encode_sb_row(cpi, mi_row, &tp, &totalrate); |
2081 | 2159 |
2082 cpi->tok_count[tile_row][tile_col] = (unsigned int)(tp - tp_old); | 2160 cpi->tok_count[tile_row][tile_col] = (unsigned int)(tp - tp_old); |
2083 assert(tp - cpi->tok <= get_token_alloc(cm->mb_rows, cm->mb_cols)); | 2161 assert(tp - cpi->tok <= get_token_alloc(cm->mb_rows, cm->mb_cols)); |
2084 } | 2162 } |
2085 } | 2163 } |
2086 } | 2164 } |
2087 | 2165 |
2088 vpx_usec_timer_mark(&emr_timer); | 2166 vpx_usec_timer_mark(&emr_timer); |
2089 cpi->time_encode_mb_row += vpx_usec_timer_elapsed(&emr_timer); | 2167 cpi->time_encode_sb_row += vpx_usec_timer_elapsed(&emr_timer); |
2090 } | 2168 } |
2091 | 2169 |
2092 if (cpi->sf.skip_encode_sb) { | 2170 if (cpi->sf.skip_encode_sb) { |
2093 int j; | 2171 int j; |
2094 unsigned int intra_count = 0, inter_count = 0; | 2172 unsigned int intra_count = 0, inter_count = 0; |
2095 for (j = 0; j < INTRA_INTER_CONTEXTS; ++j) { | 2173 for (j = 0; j < INTRA_INTER_CONTEXTS; ++j) { |
2096 intra_count += cpi->intra_inter_count[j][0]; | 2174 intra_count += cpi->intra_inter_count[j][0]; |
2097 inter_count += cpi->intra_inter_count[j][1]; | 2175 inter_count += cpi->intra_inter_count[j][1]; |
2098 } | 2176 } |
2099 cpi->sf.skip_encode_frame = ((intra_count << 2) < inter_count); | 2177 cpi->sf.skip_encode_frame = ((intra_count << 2) < inter_count); |
2100 cpi->sf.skip_encode_frame &= (cm->frame_type != KEY_FRAME); | 2178 cpi->sf.skip_encode_frame &= (cm->frame_type != KEY_FRAME); |
2101 cpi->sf.skip_encode_frame &= cm->show_frame; | 2179 cpi->sf.skip_encode_frame &= cm->show_frame; |
2102 } else { | 2180 } else { |
2103 cpi->sf.skip_encode_frame = 0; | 2181 cpi->sf.skip_encode_frame = 0; |
2104 } | 2182 } |
2105 | 2183 |
2106 // 256 rate units to the bit, | 2184 // 256 rate units to the bit, |
2107 // projected_frame_size in units of BYTES | 2185 // projected_frame_size in units of BYTES |
2108 cpi->projected_frame_size = totalrate >> 8; | 2186 cpi->projected_frame_size = totalrate >> 8; |
2109 | 2187 |
2110 #if 0 | 2188 #if 0 |
2111 // Keep record of the total distortion this time around for future use | 2189 // Keep record of the total distortion this time around for future use |
2112 cpi->last_frame_distortion = cpi->frame_distortion; | 2190 cpi->last_frame_distortion = cpi->frame_distortion; |
2113 #endif | 2191 #endif |
2114 | 2192 |
2115 } | 2193 } |
2116 | 2194 |
2117 static int check_dual_ref_flags(VP9_COMP *cpi) { | 2195 static int check_dual_ref_flags(VP9_COMP *cpi) { |
2118 MACROBLOCKD *xd = &cpi->mb.e_mbd; | 2196 const int ref_flags = cpi->ref_frame_flags; |
2119 int ref_flags = cpi->ref_frame_flags; | |
2120 | 2197 |
2121 if (vp9_segfeature_active(&xd->seg, 1, SEG_LVL_REF_FRAME)) { | 2198 if (vp9_segfeature_active(&cpi->common.seg, 1, SEG_LVL_REF_FRAME)) { |
2122 return 0; | 2199 return 0; |
2123 } else { | 2200 } else { |
2124 return (!!(ref_flags & VP9_GOLD_FLAG) + !!(ref_flags & VP9_LAST_FLAG) | 2201 return (!!(ref_flags & VP9_GOLD_FLAG) + !!(ref_flags & VP9_LAST_FLAG) |
2125 + !!(ref_flags & VP9_ALT_FLAG)) >= 2; | 2202 + !!(ref_flags & VP9_ALT_FLAG)) >= 2; |
2126 } | 2203 } |
2127 } | 2204 } |
2128 | 2205 |
2129 static int get_skip_flag(MODE_INFO *mi, int mis, int ymbs, int xmbs) { | 2206 static int get_skip_flag(MODE_INFO *mi, int mis, int ymbs, int xmbs) { |
2130 int x, y; | 2207 int x, y; |
2131 | 2208 |
2132 for (y = 0; y < ymbs; y++) { | 2209 for (y = 0; y < ymbs; y++) { |
2133 for (x = 0; x < xmbs; x++) { | 2210 for (x = 0; x < xmbs; x++) { |
2134 if (!mi[y * mis + x].mbmi.mb_skip_coeff) | 2211 if (!mi[y * mis + x].mbmi.skip_coeff) |
2135 return 0; | 2212 return 0; |
2136 } | 2213 } |
2137 } | 2214 } |
2138 | 2215 |
2139 return 1; | 2216 return 1; |
2140 } | 2217 } |
2141 | 2218 |
2142 static void set_txfm_flag(MODE_INFO *mi, int mis, int ymbs, int xmbs, | 2219 static void set_txfm_flag(MODE_INFO *mi, int mis, int ymbs, int xmbs, |
2143 TX_SIZE txfm_size) { | 2220 TX_SIZE txfm_size) { |
2144 int x, y; | 2221 int x, y; |
2145 | 2222 |
2146 for (y = 0; y < ymbs; y++) { | 2223 for (y = 0; y < ymbs; y++) { |
2147 for (x = 0; x < xmbs; x++) | 2224 for (x = 0; x < xmbs; x++) |
2148 mi[y * mis + x].mbmi.txfm_size = txfm_size; | 2225 mi[y * mis + x].mbmi.txfm_size = txfm_size; |
2149 } | 2226 } |
2150 } | 2227 } |
2151 | 2228 |
2152 static void reset_skip_txfm_size_b(VP9_COMP *cpi, MODE_INFO *mi, int mis, | 2229 static void reset_skip_txfm_size_b(VP9_COMP *cpi, MODE_INFO *mi, int mis, |
2153 TX_SIZE txfm_max, int bw, int bh, int mi_row, | 2230 TX_SIZE max_tx_size, int bw, int bh, |
2154 int mi_col, BLOCK_SIZE_TYPE bsize) { | 2231 int mi_row, int mi_col, BLOCK_SIZE bsize) { |
2155 VP9_COMMON * const cm = &cpi->common; | 2232 VP9_COMMON *const cm = &cpi->common; |
2156 MB_MODE_INFO * const mbmi = &mi->mbmi; | 2233 MB_MODE_INFO *const mbmi = &mi->mbmi; |
2157 | 2234 |
2158 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 2235 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
2159 return; | 2236 return; |
2160 | 2237 |
2161 if (mbmi->txfm_size > txfm_max) { | 2238 if (mbmi->txfm_size > max_tx_size) { |
2162 MACROBLOCK * const x = &cpi->mb; | 2239 MACROBLOCK * const x = &cpi->mb; |
2163 MACROBLOCKD * const xd = &x->e_mbd; | 2240 MACROBLOCKD * const xd = &x->e_mbd; |
2164 const int ymbs = MIN(bh, cm->mi_rows - mi_row); | 2241 const int ymbs = MIN(bh, cm->mi_rows - mi_row); |
2165 const int xmbs = MIN(bw, cm->mi_cols - mi_col); | 2242 const int xmbs = MIN(bw, cm->mi_cols - mi_col); |
2166 | 2243 |
2167 xd->mode_info_context = mi; | 2244 xd->mode_info_context = mi; |
2168 assert(vp9_segfeature_active(&xd->seg, mbmi->segment_id, SEG_LVL_SKIP) || | 2245 assert(vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP) || |
2169 get_skip_flag(mi, mis, ymbs, xmbs)); | 2246 get_skip_flag(mi, mis, ymbs, xmbs)); |
2170 set_txfm_flag(mi, mis, ymbs, xmbs, txfm_max); | 2247 set_txfm_flag(mi, mis, ymbs, xmbs, max_tx_size); |
2171 } | 2248 } |
2172 } | 2249 } |
2173 | 2250 |
2174 static void reset_skip_txfm_size_sb(VP9_COMP *cpi, MODE_INFO *mi, | 2251 static void reset_skip_txfm_size_sb(VP9_COMP *cpi, MODE_INFO *mi, |
2175 TX_SIZE txfm_max, int mi_row, int mi_col, | 2252 TX_SIZE max_tx_size, int mi_row, int mi_col, |
2176 BLOCK_SIZE_TYPE bsize) { | 2253 BLOCK_SIZE bsize) { |
2177 VP9_COMMON * const cm = &cpi->common; | 2254 const VP9_COMMON *const cm = &cpi->common; |
2178 const int mis = cm->mode_info_stride; | 2255 const int mis = cm->mode_info_stride; |
2179 int bwl, bhl; | 2256 int bw, bh; |
2180 const int bsl = mi_width_log2(bsize), bs = 1 << (bsl - 1); | 2257 const int bs = num_8x8_blocks_wide_lookup[bsize], hbs = bs / 2; |
2181 | 2258 |
2182 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 2259 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
2183 return; | 2260 return; |
2184 | 2261 |
2185 bwl = mi_width_log2(mi->mbmi.sb_type); | 2262 bw = num_8x8_blocks_wide_lookup[mi->mbmi.sb_type]; |
2186 bhl = mi_height_log2(mi->mbmi.sb_type); | 2263 bh = num_8x8_blocks_high_lookup[mi->mbmi.sb_type]; |
2187 | 2264 |
2188 if (bwl == bsl && bhl == bsl) { | 2265 if (bw == bs && bh == bs) { |
2189 reset_skip_txfm_size_b(cpi, mi, mis, txfm_max, 1 << bsl, 1 << bsl, mi_row, | 2266 reset_skip_txfm_size_b(cpi, mi, mis, max_tx_size, bs, bs, mi_row, |
2190 mi_col, bsize); | 2267 mi_col, bsize); |
2191 } else if (bwl == bsl && bhl < bsl) { | 2268 } else if (bw == bs && bh < bs) { |
2192 reset_skip_txfm_size_b(cpi, mi, mis, txfm_max, 1 << bsl, bs, mi_row, mi_col, | 2269 reset_skip_txfm_size_b(cpi, mi, mis, max_tx_size, bs, hbs, mi_row, mi_col, |
2193 bsize); | 2270 bsize); |
2194 reset_skip_txfm_size_b(cpi, mi + bs * mis, mis, txfm_max, 1 << bsl, bs, | 2271 reset_skip_txfm_size_b(cpi, mi + hbs * mis, mis, max_tx_size, bs, hbs, |
2195 mi_row + bs, mi_col, bsize); | 2272 mi_row + hbs, mi_col, bsize); |
2196 } else if (bwl < bsl && bhl == bsl) { | 2273 } else if (bw < bs && bh == bs) { |
2197 reset_skip_txfm_size_b(cpi, mi, mis, txfm_max, bs, 1 << bsl, mi_row, mi_col, | 2274 reset_skip_txfm_size_b(cpi, mi, mis, max_tx_size, hbs, bs, mi_row, mi_col, |
2198 bsize); | 2275 bsize); |
2199 reset_skip_txfm_size_b(cpi, mi + bs, mis, txfm_max, bs, 1 << bsl, mi_row, | 2276 reset_skip_txfm_size_b(cpi, mi + hbs, mis, max_tx_size, hbs, bs, mi_row, |
2200 mi_col + bs, bsize); | 2277 mi_col + hbs, bsize); |
2201 } else { | 2278 } else { |
2202 BLOCK_SIZE_TYPE subsize; | 2279 const BLOCK_SIZE subsize = subsize_lookup[PARTITION_SPLIT][bsize]; |
2203 int n; | 2280 int n; |
2204 | 2281 |
2205 assert(bwl < bsl && bhl < bsl); | 2282 assert(bw < bs && bh < bs); |
2206 if (bsize == BLOCK_SIZE_SB64X64) { | |
2207 subsize = BLOCK_SIZE_SB32X32; | |
2208 } else if (bsize == BLOCK_SIZE_SB32X32) { | |
2209 subsize = BLOCK_SIZE_MB16X16; | |
2210 } else { | |
2211 assert(bsize == BLOCK_SIZE_MB16X16); | |
2212 subsize = BLOCK_SIZE_SB8X8; | |
2213 } | |
2214 | 2283 |
2215 for (n = 0; n < 4; n++) { | 2284 for (n = 0; n < 4; n++) { |
2216 const int y_idx = n >> 1, x_idx = n & 0x01; | 2285 const int mi_dc = hbs * (n & 1); |
| 2286 const int mi_dr = hbs * (n >> 1); |
2217 | 2287 |
2218 reset_skip_txfm_size_sb(cpi, mi + y_idx * bs * mis + x_idx * bs, txfm_max, | 2288 reset_skip_txfm_size_sb(cpi, &mi[mi_dr * mis + mi_dc], max_tx_size, |
2219 mi_row + y_idx * bs, mi_col + x_idx * bs, | 2289 mi_row + mi_dr, mi_col + mi_dc, subsize); |
2220 subsize); | |
2221 } | 2290 } |
2222 } | 2291 } |
2223 } | 2292 } |
2224 | 2293 |
2225 static void reset_skip_txfm_size(VP9_COMP *cpi, TX_SIZE txfm_max) { | 2294 static void reset_skip_txfm_size(VP9_COMP *cpi, TX_SIZE txfm_max) { |
2226 VP9_COMMON * const cm = &cpi->common; | 2295 VP9_COMMON * const cm = &cpi->common; |
2227 int mi_row, mi_col; | 2296 int mi_row, mi_col; |
2228 const int mis = cm->mode_info_stride; | 2297 const int mis = cm->mode_info_stride; |
2229 MODE_INFO *mi, *mi_ptr = cm->mi; | 2298 MODE_INFO *mi, *mi_ptr = cm->mi; |
2230 | 2299 |
2231 for (mi_row = 0; mi_row < cm->mi_rows; mi_row += 8, mi_ptr += 8 * mis) { | 2300 for (mi_row = 0; mi_row < cm->mi_rows; mi_row += 8, mi_ptr += 8 * mis) { |
2232 mi = mi_ptr; | 2301 mi = mi_ptr; |
2233 for (mi_col = 0; mi_col < cm->mi_cols; mi_col += 8, mi += 8) { | 2302 for (mi_col = 0; mi_col < cm->mi_cols; mi_col += 8, mi += 8) |
2234 reset_skip_txfm_size_sb(cpi, mi, txfm_max, mi_row, mi_col, | 2303 reset_skip_txfm_size_sb(cpi, mi, txfm_max, mi_row, mi_col, BLOCK_64X64); |
2235 BLOCK_SIZE_SB64X64); | |
2236 } | |
2237 } | 2304 } |
2238 } | 2305 } |
2239 | 2306 |
2240 static int get_frame_type(VP9_COMP *cpi) { | 2307 static int get_frame_type(VP9_COMP *cpi) { |
2241 int frame_type; | 2308 int frame_type; |
2242 if (cpi->common.frame_type == KEY_FRAME) | 2309 if (cpi->common.frame_type == KEY_FRAME) |
2243 frame_type = 0; | 2310 frame_type = 0; |
2244 else if (cpi->is_src_frame_alt_ref && cpi->refresh_golden_frame) | 2311 else if (cpi->is_src_frame_alt_ref && cpi->refresh_golden_frame) |
2245 frame_type = 3; | 2312 frame_type = 3; |
2246 else if (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) | 2313 else if (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) |
(...skipping 13 matching lines...) Expand all Loading... |
2260 cpi->common.tx_mode = ALLOW_32X32; | 2327 cpi->common.tx_mode = ALLOW_32X32; |
2261 } else if (cpi->sf.tx_size_search_method == USE_FULL_RD) { | 2328 } else if (cpi->sf.tx_size_search_method == USE_FULL_RD) { |
2262 int frame_type = get_frame_type(cpi); | 2329 int frame_type = get_frame_type(cpi); |
2263 cpi->common.tx_mode = | 2330 cpi->common.tx_mode = |
2264 cpi->rd_tx_select_threshes[frame_type][ALLOW_32X32] | 2331 cpi->rd_tx_select_threshes[frame_type][ALLOW_32X32] |
2265 > cpi->rd_tx_select_threshes[frame_type][TX_MODE_SELECT] ? | 2332 > cpi->rd_tx_select_threshes[frame_type][TX_MODE_SELECT] ? |
2266 ALLOW_32X32 : TX_MODE_SELECT; | 2333 ALLOW_32X32 : TX_MODE_SELECT; |
2267 } else { | 2334 } else { |
2268 unsigned int total = 0; | 2335 unsigned int total = 0; |
2269 int i; | 2336 int i; |
2270 for (i = 0; i < TX_SIZE_MAX_SB; ++i) | 2337 for (i = 0; i < TX_SIZES; ++i) |
2271 total += cpi->txfm_stepdown_count[i]; | 2338 total += cpi->txfm_stepdown_count[i]; |
2272 if (total) { | 2339 if (total) { |
2273 double fraction = (double)cpi->txfm_stepdown_count[0] / total; | 2340 double fraction = (double)cpi->txfm_stepdown_count[0] / total; |
2274 cpi->common.tx_mode = fraction > 0.90 ? ALLOW_32X32 : TX_MODE_SELECT; | 2341 cpi->common.tx_mode = fraction > 0.90 ? ALLOW_32X32 : TX_MODE_SELECT; |
2275 // printf("fraction = %f\n", fraction); | 2342 // printf("fraction = %f\n", fraction); |
2276 } // else keep unchanged | 2343 } // else keep unchanged |
2277 } | 2344 } |
2278 } | 2345 } |
2279 } | 2346 } |
2280 | 2347 |
2281 void vp9_encode_frame(VP9_COMP *cpi) { | 2348 void vp9_encode_frame(VP9_COMP *cpi) { |
2282 VP9_COMMON * const cm = &cpi->common; | 2349 VP9_COMMON * const cm = &cpi->common; |
2283 | 2350 |
2284 // In the longer term the encoder should be generalized to match the | 2351 // In the longer term the encoder should be generalized to match the |
2285 // decoder such that we allow compound where one of the 3 buffers has a | 2352 // decoder such that we allow compound where one of the 3 buffers has a |
2286 // different sign bias and that buffer is then the fixed ref. However, this | 2353 // different sign bias and that buffer is then the fixed ref. However, this |
2287 // requires further work in the rd loop. For now the only supported encoder | 2354 // requires further work in the rd loop. For now the only supported encoder |
2288 // side behaviour is where the ALT ref buffer has opposite sign bias to | 2355 // side behavior is where the ALT ref buffer has opposite sign bias to |
2289 // the other two. | 2356 // the other two. |
2290 if ((cm->ref_frame_sign_bias[ALTREF_FRAME] | 2357 if ((cm->ref_frame_sign_bias[ALTREF_FRAME] |
2291 == cm->ref_frame_sign_bias[GOLDEN_FRAME]) | 2358 == cm->ref_frame_sign_bias[GOLDEN_FRAME]) |
2292 || (cm->ref_frame_sign_bias[ALTREF_FRAME] | 2359 || (cm->ref_frame_sign_bias[ALTREF_FRAME] |
2293 == cm->ref_frame_sign_bias[LAST_FRAME])) { | 2360 == cm->ref_frame_sign_bias[LAST_FRAME])) { |
2294 cm->allow_comp_inter_inter = 0; | 2361 cm->allow_comp_inter_inter = 0; |
2295 } else { | 2362 } else { |
2296 cm->allow_comp_inter_inter = 1; | 2363 cm->allow_comp_inter_inter = 1; |
2297 cm->comp_fixed_ref = ALTREF_FRAME; | 2364 cm->comp_fixed_ref = ALTREF_FRAME; |
2298 cm->comp_var_ref[0] = LAST_FRAME; | 2365 cm->comp_var_ref[0] = LAST_FRAME; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2331 /* filter type selection */ | 2398 /* filter type selection */ |
2332 // FIXME(rbultje) for some odd reason, we often select smooth_filter | 2399 // FIXME(rbultje) for some odd reason, we often select smooth_filter |
2333 // as default filter for ARF overlay frames. This is a REALLY BAD | 2400 // as default filter for ARF overlay frames. This is a REALLY BAD |
2334 // IDEA so we explicitly disable it here. | 2401 // IDEA so we explicitly disable it here. |
2335 if (frame_type != 3 && | 2402 if (frame_type != 3 && |
2336 cpi->rd_filter_threshes[frame_type][1] > | 2403 cpi->rd_filter_threshes[frame_type][1] > |
2337 cpi->rd_filter_threshes[frame_type][0] && | 2404 cpi->rd_filter_threshes[frame_type][0] && |
2338 cpi->rd_filter_threshes[frame_type][1] > | 2405 cpi->rd_filter_threshes[frame_type][1] > |
2339 cpi->rd_filter_threshes[frame_type][2] && | 2406 cpi->rd_filter_threshes[frame_type][2] && |
2340 cpi->rd_filter_threshes[frame_type][1] > | 2407 cpi->rd_filter_threshes[frame_type][1] > |
2341 cpi->rd_filter_threshes[frame_type][VP9_SWITCHABLE_FILTERS]) { | 2408 cpi->rd_filter_threshes[frame_type][SWITCHABLE_FILTERS]) { |
2342 filter_type = vp9_switchable_interp[1]; | 2409 filter_type = EIGHTTAP_SMOOTH; |
2343 } else if (cpi->rd_filter_threshes[frame_type][2] > | 2410 } else if (cpi->rd_filter_threshes[frame_type][2] > |
2344 cpi->rd_filter_threshes[frame_type][0] && | 2411 cpi->rd_filter_threshes[frame_type][0] && |
2345 cpi->rd_filter_threshes[frame_type][2] > | 2412 cpi->rd_filter_threshes[frame_type][2] > |
2346 cpi->rd_filter_threshes[frame_type][VP9_SWITCHABLE_FILTERS]) { | 2413 cpi->rd_filter_threshes[frame_type][SWITCHABLE_FILTERS]) { |
2347 filter_type = vp9_switchable_interp[2]; | 2414 filter_type = EIGHTTAP_SHARP; |
2348 } else if (cpi->rd_filter_threshes[frame_type][0] > | 2415 } else if (cpi->rd_filter_threshes[frame_type][0] > |
2349 cpi->rd_filter_threshes[frame_type][VP9_SWITCHABLE_FILTERS]) { | 2416 cpi->rd_filter_threshes[frame_type][SWITCHABLE_FILTERS]) { |
2350 filter_type = vp9_switchable_interp[0]; | 2417 filter_type = EIGHTTAP; |
2351 } else { | 2418 } else { |
2352 filter_type = SWITCHABLE; | 2419 filter_type = SWITCHABLE; |
2353 } | 2420 } |
2354 | 2421 |
2355 /* transform size (4x4, 8x8, 16x16 or select-per-mb) selection */ | |
2356 | |
2357 cpi->mb.e_mbd.lossless = 0; | 2422 cpi->mb.e_mbd.lossless = 0; |
2358 if (cpi->oxcf.lossless) { | 2423 if (cpi->oxcf.lossless) { |
2359 cpi->mb.e_mbd.lossless = 1; | 2424 cpi->mb.e_mbd.lossless = 1; |
2360 } | 2425 } |
2361 | 2426 |
| 2427 /* transform size selection (4x4, 8x8, 16x16 or select-per-mb) */ |
2362 select_tx_mode(cpi); | 2428 select_tx_mode(cpi); |
2363 cpi->common.comp_pred_mode = pred_type; | 2429 cpi->common.comp_pred_mode = pred_type; |
2364 cpi->common.mcomp_filter_type = filter_type; | 2430 cpi->common.mcomp_filter_type = filter_type; |
2365 encode_frame_internal(cpi); | 2431 encode_frame_internal(cpi); |
2366 | 2432 |
2367 for (i = 0; i < NB_PREDICTION_TYPES; ++i) { | 2433 for (i = 0; i < NB_PREDICTION_TYPES; ++i) { |
2368 const int diff = (int) (cpi->rd_comp_pred_diff[i] / cpi->common.MBs); | 2434 const int diff = (int) (cpi->rd_comp_pred_diff[i] / cpi->common.MBs); |
2369 cpi->rd_prediction_type_threshes[frame_type][i] += diff; | 2435 cpi->rd_prediction_type_threshes[frame_type][i] += diff; |
2370 cpi->rd_prediction_type_threshes[frame_type][i] >>= 1; | 2436 cpi->rd_prediction_type_threshes[frame_type][i] >>= 1; |
2371 } | 2437 } |
2372 | 2438 |
2373 for (i = 0; i <= VP9_SWITCHABLE_FILTERS; i++) { | 2439 for (i = 0; i <= SWITCHABLE_FILTERS; i++) { |
2374 const int64_t diff = cpi->rd_filter_diff[i] / cpi->common.MBs; | 2440 const int64_t diff = cpi->rd_filter_diff[i] / cpi->common.MBs; |
2375 cpi->rd_filter_threshes[frame_type][i] = | 2441 cpi->rd_filter_threshes[frame_type][i] = |
2376 (cpi->rd_filter_threshes[frame_type][i] + diff) / 2; | 2442 (cpi->rd_filter_threshes[frame_type][i] + diff) / 2; |
2377 } | 2443 } |
2378 | 2444 |
2379 for (i = 0; i < NB_TXFM_MODES; ++i) { | 2445 for (i = 0; i < TX_MODES; ++i) { |
2380 int64_t pd = cpi->rd_tx_select_diff[i]; | 2446 int64_t pd = cpi->rd_tx_select_diff[i]; |
2381 int diff; | 2447 int diff; |
2382 if (i == TX_MODE_SELECT) | 2448 if (i == TX_MODE_SELECT) |
2383 pd -= RDCOST(cpi->mb.rdmult, cpi->mb.rddiv, | 2449 pd -= RDCOST(cpi->mb.rdmult, cpi->mb.rddiv, |
2384 2048 * (TX_SIZE_MAX_SB - 1), 0); | 2450 2048 * (TX_SIZES - 1), 0); |
2385 diff = (int) (pd / cpi->common.MBs); | 2451 diff = (int) (pd / cpi->common.MBs); |
2386 cpi->rd_tx_select_threshes[frame_type][i] += diff; | 2452 cpi->rd_tx_select_threshes[frame_type][i] += diff; |
2387 cpi->rd_tx_select_threshes[frame_type][i] /= 2; | 2453 cpi->rd_tx_select_threshes[frame_type][i] /= 2; |
2388 } | 2454 } |
2389 | 2455 |
2390 if (cpi->common.comp_pred_mode == HYBRID_PREDICTION) { | 2456 if (cpi->common.comp_pred_mode == HYBRID_PREDICTION) { |
2391 int single_count_zero = 0; | 2457 int single_count_zero = 0; |
2392 int comp_count_zero = 0; | 2458 int comp_count_zero = 0; |
2393 | 2459 |
2394 for (i = 0; i < COMP_INTER_CONTEXTS; i++) { | 2460 for (i = 0; i < COMP_INTER_CONTEXTS; i++) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2439 cpi->common.tx_mode = ALLOW_16X16; | 2505 cpi->common.tx_mode = ALLOW_16X16; |
2440 reset_skip_txfm_size(cpi, TX_16X16); | 2506 reset_skip_txfm_size(cpi, TX_16X16); |
2441 } | 2507 } |
2442 } | 2508 } |
2443 } else { | 2509 } else { |
2444 encode_frame_internal(cpi); | 2510 encode_frame_internal(cpi); |
2445 } | 2511 } |
2446 | 2512 |
2447 } | 2513 } |
2448 | 2514 |
2449 static void sum_intra_stats(VP9_COMP *cpi, MACROBLOCK *x) { | 2515 static void sum_intra_stats(VP9_COMP *cpi, const MODE_INFO *mi) { |
2450 const MACROBLOCKD *xd = &x->e_mbd; | 2516 const MB_PREDICTION_MODE y_mode = mi->mbmi.mode; |
2451 const MB_PREDICTION_MODE m = xd->mode_info_context->mbmi.mode; | 2517 const MB_PREDICTION_MODE uv_mode = mi->mbmi.uv_mode; |
2452 const MB_PREDICTION_MODE uvm = xd->mode_info_context->mbmi.uv_mode; | 2518 const BLOCK_SIZE bsize = mi->mbmi.sb_type; |
2453 | 2519 |
2454 ++cpi->y_uv_mode_count[m][uvm]; | 2520 ++cpi->y_uv_mode_count[y_mode][uv_mode]; |
2455 if (xd->mode_info_context->mbmi.sb_type >= BLOCK_SIZE_SB8X8) { | 2521 |
2456 const BLOCK_SIZE_TYPE bsize = xd->mode_info_context->mbmi.sb_type; | 2522 if (bsize < BLOCK_8X8) { |
2457 const int bwl = b_width_log2(bsize), bhl = b_height_log2(bsize); | 2523 int idx, idy; |
2458 const int bsl = MIN(bwl, bhl); | 2524 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; |
2459 ++cpi->y_mode_count[MIN(bsl, 3)][m]; | 2525 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; |
| 2526 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) |
| 2527 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) |
| 2528 ++cpi->y_mode_count[0][mi->bmi[idy * 2 + idx].as_mode]; |
2460 } else { | 2529 } else { |
2461 int idx, idy; | 2530 ++cpi->y_mode_count[size_group_lookup[bsize]][y_mode]; |
2462 int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[ | |
2463 xd->mode_info_context->mbmi.sb_type]; | |
2464 int num_4x4_blocks_high = num_4x4_blocks_high_lookup[ | |
2465 xd->mode_info_context->mbmi.sb_type]; | |
2466 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { | |
2467 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { | |
2468 int m = xd->mode_info_context->bmi[idy * 2 + idx].as_mode; | |
2469 ++cpi->y_mode_count[0][m]; | |
2470 } | |
2471 } | |
2472 } | 2531 } |
2473 } | 2532 } |
2474 | 2533 |
2475 // Experimental stub function to create a per MB zbin adjustment based on | 2534 // Experimental stub function to create a per MB zbin adjustment based on |
2476 // some previously calculated measure of MB activity. | 2535 // some previously calculated measure of MB activity. |
2477 static void adjust_act_zbin(VP9_COMP *cpi, MACROBLOCK *x) { | 2536 static void adjust_act_zbin(VP9_COMP *cpi, MACROBLOCK *x) { |
2478 #if USE_ACT_INDEX | 2537 #if USE_ACT_INDEX |
2479 x->act_zbin_adj = *(x->mb_activity_ptr); | 2538 x->act_zbin_adj = *(x->mb_activity_ptr); |
2480 #else | 2539 #else |
2481 int64_t a; | 2540 int64_t a; |
2482 int64_t b; | 2541 int64_t b; |
2483 int64_t act = *(x->mb_activity_ptr); | 2542 int64_t act = *(x->mb_activity_ptr); |
2484 | 2543 |
2485 // Apply the masking to the RD multiplier. | 2544 // Apply the masking to the RD multiplier. |
2486 a = act + 4 * cpi->activity_avg; | 2545 a = act + 4 * cpi->activity_avg; |
2487 b = 4 * act + cpi->activity_avg; | 2546 b = 4 * act + cpi->activity_avg; |
2488 | 2547 |
2489 if (act > cpi->activity_avg) | 2548 if (act > cpi->activity_avg) |
2490 x->act_zbin_adj = (int) (((int64_t) b + (a >> 1)) / a) - 1; | 2549 x->act_zbin_adj = (int) (((int64_t) b + (a >> 1)) / a) - 1; |
2491 else | 2550 else |
2492 x->act_zbin_adj = 1 - (int) (((int64_t) a + (b >> 1)) / b); | 2551 x->act_zbin_adj = 1 - (int) (((int64_t) a + (b >> 1)) / b); |
2493 #endif | 2552 #endif |
2494 } | 2553 } |
2495 | 2554 |
2496 static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, | 2555 static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, |
2497 int mi_row, int mi_col, BLOCK_SIZE_TYPE bsize) { | 2556 int mi_row, int mi_col, BLOCK_SIZE bsize) { |
2498 VP9_COMMON * const cm = &cpi->common; | 2557 VP9_COMMON * const cm = &cpi->common; |
2499 MACROBLOCK * const x = &cpi->mb; | 2558 MACROBLOCK * const x = &cpi->mb; |
2500 MACROBLOCKD * const xd = &x->e_mbd; | 2559 MACROBLOCKD * const xd = &x->e_mbd; |
2501 MODE_INFO *mi = xd->mode_info_context; | 2560 MODE_INFO *mi = xd->mode_info_context; |
2502 MB_MODE_INFO *mbmi = &mi->mbmi; | 2561 MB_MODE_INFO *mbmi = &mi->mbmi; |
2503 unsigned int segment_id = mbmi->segment_id; | 2562 unsigned int segment_id = mbmi->segment_id; |
2504 const int mis = cm->mode_info_stride; | 2563 const int mis = cm->mode_info_stride; |
2505 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; | 2564 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; |
2506 const int mi_height = num_8x8_blocks_high_lookup[bsize]; | 2565 const int mi_height = num_8x8_blocks_high_lookup[bsize]; |
2507 x->rd_search = 0; | 2566 x->use_lp32x32fdct = cpi->sf.use_lp32x32fdct; |
2508 x->skip_encode = (!output_enabled && cpi->sf.skip_encode_frame && | 2567 x->skip_encode = (!output_enabled && cpi->sf.skip_encode_frame && |
2509 xd->q_index < QIDX_SKIP_THRESH); | 2568 xd->q_index < QIDX_SKIP_THRESH); |
2510 if (x->skip_encode) | 2569 if (x->skip_encode) |
2511 return; | 2570 return; |
2512 | 2571 |
2513 if (cm->frame_type == KEY_FRAME) { | 2572 if (cm->frame_type == KEY_FRAME) { |
2514 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { | 2573 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { |
2515 adjust_act_zbin(cpi, x); | 2574 adjust_act_zbin(cpi, x); |
2516 vp9_update_zbin_extra(cpi, x); | 2575 vp9_update_zbin_extra(cpi, x); |
2517 } | 2576 } |
2518 } else { | 2577 } else { |
2519 vp9_setup_interp_filters(xd, mbmi->interp_filter, cm); | 2578 vp9_setup_interp_filters(xd, mbmi->interp_filter, cm); |
2520 | 2579 |
2521 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { | 2580 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { |
2522 // Adjust the zbin based on this MB rate. | 2581 // Adjust the zbin based on this MB rate. |
2523 adjust_act_zbin(cpi, x); | 2582 adjust_act_zbin(cpi, x); |
2524 } | 2583 } |
2525 | 2584 |
2526 // Experimental code. Special case for gf and arf zeromv modes. | 2585 // Experimental code. Special case for gf and arf zeromv modes. |
2527 // Increase zbin size to suppress noise | 2586 // Increase zbin size to suppress noise |
2528 cpi->zbin_mode_boost = 0; | 2587 cpi->zbin_mode_boost = 0; |
2529 if (cpi->zbin_mode_boost_enabled) { | 2588 if (cpi->zbin_mode_boost_enabled) { |
2530 if (mbmi->ref_frame[0] != INTRA_FRAME) { | 2589 if (is_inter_block(mbmi)) { |
2531 if (mbmi->mode == ZEROMV) { | 2590 if (mbmi->mode == ZEROMV) { |
2532 if (mbmi->ref_frame[0] != LAST_FRAME) | 2591 if (mbmi->ref_frame[0] != LAST_FRAME) |
2533 cpi->zbin_mode_boost = GF_ZEROMV_ZBIN_BOOST; | 2592 cpi->zbin_mode_boost = GF_ZEROMV_ZBIN_BOOST; |
2534 else | 2593 else |
2535 cpi->zbin_mode_boost = LF_ZEROMV_ZBIN_BOOST; | 2594 cpi->zbin_mode_boost = LF_ZEROMV_ZBIN_BOOST; |
2536 } else if (mbmi->sb_type < BLOCK_SIZE_SB8X8) { | 2595 } else if (mbmi->sb_type < BLOCK_8X8) { |
2537 cpi->zbin_mode_boost = SPLIT_MV_ZBIN_BOOST; | 2596 cpi->zbin_mode_boost = SPLIT_MV_ZBIN_BOOST; |
2538 } else { | 2597 } else { |
2539 cpi->zbin_mode_boost = MV_ZBIN_BOOST; | 2598 cpi->zbin_mode_boost = MV_ZBIN_BOOST; |
2540 } | 2599 } |
2541 } else { | 2600 } else { |
2542 cpi->zbin_mode_boost = INTRA_ZBIN_BOOST; | 2601 cpi->zbin_mode_boost = INTRA_ZBIN_BOOST; |
2543 } | 2602 } |
2544 } | 2603 } |
2545 | 2604 |
2546 vp9_update_zbin_extra(cpi, x); | 2605 vp9_update_zbin_extra(cpi, x); |
2547 } | 2606 } |
2548 | 2607 |
2549 if (mbmi->ref_frame[0] == INTRA_FRAME) { | 2608 if (!is_inter_block(mbmi)) { |
2550 vp9_encode_intra_block_y( | 2609 vp9_encode_intra_block_y(x, MAX(bsize, BLOCK_8X8)); |
2551 cm, x, (bsize < BLOCK_SIZE_SB8X8) ? BLOCK_SIZE_SB8X8 : bsize); | 2610 vp9_encode_intra_block_uv(x, MAX(bsize, BLOCK_8X8)); |
2552 vp9_encode_intra_block_uv( | |
2553 cm, x, (bsize < BLOCK_SIZE_SB8X8) ? BLOCK_SIZE_SB8X8 : bsize); | |
2554 if (output_enabled) | 2611 if (output_enabled) |
2555 sum_intra_stats(cpi, x); | 2612 sum_intra_stats(cpi, mi); |
2556 } else { | 2613 } else { |
2557 int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, mbmi->ref_frame[0])]; | 2614 int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, mbmi->ref_frame[0])]; |
2558 YV12_BUFFER_CONFIG *ref_fb = &cm->yv12_fb[idx]; | 2615 YV12_BUFFER_CONFIG *ref_fb = &cm->yv12_fb[idx]; |
2559 YV12_BUFFER_CONFIG *second_ref_fb = NULL; | 2616 YV12_BUFFER_CONFIG *second_ref_fb = NULL; |
2560 if (mbmi->ref_frame[1] > 0) { | 2617 if (mbmi->ref_frame[1] > 0) { |
2561 idx = cm->ref_frame_map[get_ref_frame_idx(cpi, mbmi->ref_frame[1])]; | 2618 idx = cm->ref_frame_map[get_ref_frame_idx(cpi, mbmi->ref_frame[1])]; |
2562 second_ref_fb = &cm->yv12_fb[idx]; | 2619 second_ref_fb = &cm->yv12_fb[idx]; |
2563 } | 2620 } |
2564 | 2621 |
2565 assert(cm->frame_type != KEY_FRAME); | 2622 assert(cm->frame_type != KEY_FRAME); |
2566 | 2623 |
2567 setup_pre_planes(xd, 0, ref_fb, mi_row, mi_col, | 2624 setup_pre_planes(xd, 0, ref_fb, mi_row, mi_col, |
2568 &xd->scale_factor[0]); | 2625 &xd->scale_factor[0]); |
2569 setup_pre_planes(xd, 1, second_ref_fb, mi_row, mi_col, | 2626 setup_pre_planes(xd, 1, second_ref_fb, mi_row, mi_col, |
2570 &xd->scale_factor[1]); | 2627 &xd->scale_factor[1]); |
2571 | 2628 |
2572 | 2629 |
2573 vp9_build_inter_predictors_sb( | 2630 vp9_build_inter_predictors_sb(xd, mi_row, mi_col, MAX(bsize, BLOCK_8X8)); |
2574 xd, mi_row, mi_col, | |
2575 bsize < BLOCK_SIZE_SB8X8 ? BLOCK_SIZE_SB8X8 : bsize); | |
2576 } | 2631 } |
2577 | 2632 |
2578 if (xd->mode_info_context->mbmi.ref_frame[0] == INTRA_FRAME) { | 2633 if (!is_inter_block(mbmi)) { |
2579 vp9_tokenize_sb(cpi, t, !output_enabled, | 2634 vp9_tokenize_sb(cpi, t, !output_enabled, MAX(bsize, BLOCK_8X8)); |
2580 (bsize < BLOCK_SIZE_SB8X8) ? BLOCK_SIZE_SB8X8 : bsize); | |
2581 } else if (!x->skip) { | 2635 } else if (!x->skip) { |
2582 vp9_encode_sb(cm, x, (bsize < BLOCK_SIZE_SB8X8) ? BLOCK_SIZE_SB8X8 : bsize); | 2636 vp9_encode_sb(x, MAX(bsize, BLOCK_8X8)); |
2583 vp9_tokenize_sb(cpi, t, !output_enabled, | 2637 vp9_tokenize_sb(cpi, t, !output_enabled, MAX(bsize, BLOCK_8X8)); |
2584 (bsize < BLOCK_SIZE_SB8X8) ? BLOCK_SIZE_SB8X8 : bsize); | |
2585 } else { | 2638 } else { |
2586 int mb_skip_context = xd->left_available ? (mi - 1)->mbmi.mb_skip_coeff : 0; | 2639 int mb_skip_context = xd->left_available ? (mi - 1)->mbmi.skip_coeff : 0; |
2587 mb_skip_context += (mi - mis)->mbmi.mb_skip_coeff; | 2640 mb_skip_context += (mi - mis)->mbmi.skip_coeff; |
2588 | 2641 |
2589 mbmi->mb_skip_coeff = 1; | 2642 mbmi->skip_coeff = 1; |
2590 if (output_enabled) | 2643 if (output_enabled) |
2591 cm->counts.mbskip[mb_skip_context][1]++; | 2644 cm->counts.mbskip[mb_skip_context][1]++; |
2592 vp9_reset_sb_tokens_context( | 2645 reset_skip_context(xd, MAX(bsize, BLOCK_8X8)); |
2593 xd, (bsize < BLOCK_SIZE_SB8X8) ? BLOCK_SIZE_SB8X8 : bsize); | |
2594 } | 2646 } |
2595 | 2647 |
2596 // copy skip flag on all mb_mode_info contexts in this SB | 2648 // copy skip flag on all mb_mode_info contexts in this SB |
2597 // if this was a skip at this txfm size | 2649 // if this was a skip at this txfm size |
2598 vp9_set_pred_flag_mbskip(cm, bsize, mi_row, mi_col, mi->mbmi.mb_skip_coeff); | 2650 vp9_set_pred_flag_mbskip(cm, bsize, mi_row, mi_col, mi->mbmi.skip_coeff); |
2599 | 2651 |
2600 if (output_enabled) { | 2652 if (output_enabled) { |
2601 if (cm->tx_mode == TX_MODE_SELECT && | 2653 if (cm->tx_mode == TX_MODE_SELECT && |
2602 mbmi->sb_type >= BLOCK_SIZE_SB8X8 && | 2654 mbmi->sb_type >= BLOCK_8X8 && |
2603 !(mbmi->ref_frame[0] != INTRA_FRAME && | 2655 !(is_inter_block(mbmi) && |
2604 (mbmi->mb_skip_coeff || | 2656 (mbmi->skip_coeff || |
2605 vp9_segfeature_active(&xd->seg, segment_id, SEG_LVL_SKIP)))) { | 2657 vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)))) { |
2606 const uint8_t context = vp9_get_pred_context_tx_size(xd); | 2658 const uint8_t context = vp9_get_pred_context_tx_size(xd); |
2607 update_tx_counts(bsize, context, mbmi->txfm_size, &cm->counts.tx); | 2659 update_tx_counts(bsize, context, mbmi->txfm_size, &cm->counts.tx); |
2608 } else { | 2660 } else { |
2609 int x, y; | 2661 int x, y; |
2610 TX_SIZE sz = (cm->tx_mode == TX_MODE_SELECT) ? TX_32X32 : cm->tx_mode; | 2662 TX_SIZE sz = (cm->tx_mode == TX_MODE_SELECT) ? TX_32X32 : cm->tx_mode; |
2611 // The new intra coding scheme requires no change of transform size | 2663 // The new intra coding scheme requires no change of transform size |
2612 if (mi->mbmi.ref_frame[0] != INTRA_FRAME) { | 2664 if (is_inter_block(&mi->mbmi)) { |
2613 if (sz == TX_32X32 && bsize < BLOCK_SIZE_SB32X32) | 2665 if (sz == TX_32X32 && bsize < BLOCK_32X32) |
2614 sz = TX_16X16; | 2666 sz = TX_16X16; |
2615 if (sz == TX_16X16 && bsize < BLOCK_SIZE_MB16X16) | 2667 if (sz == TX_16X16 && bsize < BLOCK_16X16) |
2616 sz = TX_8X8; | 2668 sz = TX_8X8; |
2617 if (sz == TX_8X8 && bsize < BLOCK_SIZE_SB8X8) | 2669 if (sz == TX_8X8 && bsize < BLOCK_8X8) |
2618 sz = TX_4X4; | 2670 sz = TX_4X4; |
2619 } else if (bsize >= BLOCK_SIZE_SB8X8) { | 2671 } else if (bsize >= BLOCK_8X8) { |
2620 sz = mbmi->txfm_size; | 2672 sz = mbmi->txfm_size; |
2621 } else { | 2673 } else { |
2622 sz = TX_4X4; | 2674 sz = TX_4X4; |
2623 } | 2675 } |
2624 | 2676 |
2625 for (y = 0; y < mi_height; y++) { | 2677 for (y = 0; y < mi_height; y++) { |
2626 for (x = 0; x < mi_width; x++) { | 2678 for (x = 0; x < mi_width; x++) { |
2627 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) { | 2679 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) { |
2628 mi[mis * y + x].mbmi.txfm_size = sz; | 2680 mi[mis * y + x].mbmi.txfm_size = sz; |
2629 } | 2681 } |
2630 } | 2682 } |
2631 } | 2683 } |
2632 } | 2684 } |
2633 } | 2685 } |
2634 } | 2686 } |
OLD | NEW |