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

Side by Side Diff: source/libvpx/vp8/encoder/rdopt.c

Issue 7671004: Update libvpx snapshot to v0.9.7-p1 (Cayuga). (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/libvpx/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp8/encoder/rdopt.h ('k') | source/libvpx/vp8/encoder/sad_c.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 13 matching lines...) Expand all
24 #include "vp8/common/reconinter.h" 24 #include "vp8/common/reconinter.h"
25 #include "vp8/common/reconintra.h" 25 #include "vp8/common/reconintra.h"
26 #include "vp8/common/reconintra4x4.h" 26 #include "vp8/common/reconintra4x4.h"
27 #include "vp8/common/findnearmv.h" 27 #include "vp8/common/findnearmv.h"
28 #include "encodemb.h" 28 #include "encodemb.h"
29 #include "quantize.h" 29 #include "quantize.h"
30 #include "vp8/common/idct.h" 30 #include "vp8/common/idct.h"
31 #include "vp8/common/g_common.h" 31 #include "vp8/common/g_common.h"
32 #include "variance.h" 32 #include "variance.h"
33 #include "mcomp.h" 33 #include "mcomp.h"
34 34 #include "rdopt.h"
35 #include "vpx_mem/vpx_mem.h" 35 #include "vpx_mem/vpx_mem.h"
36 #include "dct.h" 36 #include "dct.h"
37 #include "vp8/common/systemdependent.h" 37 #include "vp8/common/systemdependent.h"
38 38
39 #if CONFIG_RUNTIME_CPU_DETECT 39 #if CONFIG_RUNTIME_CPU_DETECT
40 #define IF_RTCD(x) (x) 40 #define IF_RTCD(x) (x)
41 #else 41 #else
42 #define IF_RTCD(x) NULL 42 #define IF_RTCD(x) NULL
43 #endif 43 #endif
44 44
45 45
46 extern void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x); 46 extern void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x);
47 extern void vp8_update_zbin_extra(VP8_COMP *cpi, MACROBLOCK *x); 47 extern void vp8_update_zbin_extra(VP8_COMP *cpi, MACROBLOCK *x);
48 48
49
50 #define RDCOST(RM,DM,R,D) ( ((128+(R)*(RM)) >> 8) + (DM)*(D) )
51
52 #define MAXF(a,b) (((a) > (b)) ? (a) : (b)) 49 #define MAXF(a,b) (((a) > (b)) ? (a) : (b))
53 50
54
55
56 static const int auto_speed_thresh[17] = 51 static const int auto_speed_thresh[17] =
57 { 52 {
58 1000, 53 1000,
59 200, 54 200,
60 150, 55 150,
61 130, 56 130,
62 150, 57 150,
63 125, 58 125,
64 120, 59 120,
65 115, 60 115,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 ALTREF_FRAME, 127 ALTREF_FRAME,
133 128
134 LAST_FRAME, 129 LAST_FRAME,
135 GOLDEN_FRAME, 130 GOLDEN_FRAME,
136 ALTREF_FRAME, 131 ALTREF_FRAME,
137 132
138 INTRA_FRAME, 133 INTRA_FRAME,
139 }; 134 };
140 135
141 static void fill_token_costs( 136 static void fill_token_costs(
142 unsigned int c [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coe f_tokens], 137 unsigned int c [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENT ROPY_TOKENS],
143 const vp8_prob p [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coe f_tokens-1] 138 const vp8_prob p [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY _NODES]
144 ) 139 )
145 { 140 {
146 int i, j, k; 141 int i, j, k;
147 142
148 143
149 for (i = 0; i < BLOCK_TYPES; i++) 144 for (i = 0; i < BLOCK_TYPES; i++)
150 for (j = 0; j < COEF_BANDS; j++) 145 for (j = 0; j < COEF_BANDS; j++)
151 for (k = 0; k < PREV_COEF_CONTEXTS; k++) 146 for (k = 0; k < PREV_COEF_CONTEXTS; k++)
152 147
153 vp8_cost_tokens((int *)(c [i][j][k]), p [i][j][k], vp8_coef_tree ); 148 vp8_cost_tokens((int *)(c [i][j][k]), p [i][j][k], vp8_coef_tree );
154 149
155 } 150 }
156 151
157 static int rd_iifactor [ 32 ] = { 4, 4, 3, 2, 1, 0, 0, 0, 152 static int rd_iifactor [ 32 ] = { 4, 4, 3, 2, 1, 0, 0, 0,
158 0, 0, 0, 0, 0, 0, 0, 0, 153 0, 0, 0, 0, 0, 0, 0, 0,
159 0, 0, 0, 0, 0, 0, 0, 0, 154 0, 0, 0, 0, 0, 0, 0, 0,
160 0, 0, 0, 0, 0, 0, 0, 0, 155 0, 0, 0, 0, 0, 0, 0, 0,
161 }; 156 };
162 157
163
164 /* values are now correlated to quantizer */ 158 /* values are now correlated to quantizer */
165 static int sad_per_bit16lut[QINDEX_RANGE] = 159 static int sad_per_bit16lut[QINDEX_RANGE] =
166 { 160 {
161 2, 2, 2, 2, 2, 2, 2, 2,
162 2, 2, 2, 2, 2, 2, 2, 2,
163 3, 3, 3, 3, 3, 3, 3, 3,
164 3, 3, 3, 3, 3, 3, 4, 4,
165 4, 4, 4, 4, 4, 4, 4, 4,
166 4, 4, 5, 5, 5, 5, 5, 5,
167 5, 5, 5, 5, 5, 5, 6, 6, 167 5, 5, 5, 5, 5, 5, 6, 6,
168 6, 6, 6, 6, 6, 7, 7, 7, 168 6, 6, 6, 6, 6, 6, 6, 6,
169 7, 7, 7, 7, 8, 8, 8, 8, 169 6, 6, 7, 7, 7, 7, 7, 7,
170 8, 8, 8, 8, 8, 8, 9, 9, 170 7, 7, 7, 7, 7, 7, 8, 8,
171 9, 9, 9, 9, 10, 10, 10, 10, 171 8, 8, 8, 8, 8, 8, 8, 8,
172 10, 10, 11, 11, 11, 11, 11, 11, 172 8, 8, 9, 9, 9, 9, 9, 9,
173 12, 12, 12, 12, 12, 12, 12, 13, 173 9, 9, 9, 9, 9, 9, 10, 10,
174 13, 13, 13, 13, 13, 14, 14, 14, 174 10, 10, 10, 10, 10, 10, 11, 11,
175 14, 14, 15, 15, 15, 15, 15, 15, 175 11, 11, 11, 11, 12, 12, 12, 12,
176 16, 16, 16, 16, 16, 16, 17, 17, 176 12, 12, 13, 13, 13, 13, 14, 14
177 17, 17, 17, 17, 17, 18, 18, 18,
178 18, 18, 19, 19, 19, 19, 19, 19,
179 20, 20, 20, 21, 21, 21, 21, 22,
180 22, 22, 23, 23, 23, 24, 24, 24,
181 25, 25, 26, 26, 27, 27, 27, 28,
182 28, 28, 29, 29, 30, 30, 31, 31
183 }; 177 };
184 static int sad_per_bit4lut[QINDEX_RANGE] = 178 static int sad_per_bit4lut[QINDEX_RANGE] =
185 { 179 {
186 5, 5, 5, 5, 5, 5, 7, 7, 180 2, 2, 2, 2, 2, 2, 3, 3,
181 3, 3, 3, 3, 3, 3, 3, 3,
182 3, 3, 3, 3, 4, 4, 4, 4,
183 4, 4, 4, 4, 4, 4, 5, 5,
184 5, 5, 5, 5, 6, 6, 6, 6,
185 6, 6, 6, 6, 6, 6, 6, 6,
186 7, 7, 7, 7, 7, 7, 7, 7,
187 7, 7, 7, 7, 7, 8, 8, 8, 187 7, 7, 7, 7, 7, 8, 8, 8,
188 8, 8, 8, 8, 10, 10, 10, 10, 188 8, 8, 9, 9, 9, 9, 9, 9,
189 10, 10, 10, 10, 10, 10, 11, 11, 189 10, 10, 10, 10, 10, 10, 10, 10,
190 11, 11, 11, 11, 13, 13, 13, 13, 190 11, 11, 11, 11, 11, 11, 11, 11,
191 13, 13, 14, 14, 14, 14, 14, 14, 191 12, 12, 12, 12, 12, 12, 12, 12,
192 16, 16, 16, 16, 16, 16, 16, 17, 192 13, 13, 13, 13, 13, 13, 13, 14,
193 17, 17, 17, 17, 17, 19, 19, 19, 193 14, 14, 14, 14, 15, 15, 15, 15,
194 19, 19, 20, 20, 20, 20, 20, 20, 194 16, 16, 16, 16, 17, 17, 17, 18,
195 22, 22, 22, 22, 22, 22, 23, 23, 195 18, 18, 19, 19, 19, 20, 20, 20,
196 23, 23, 23, 23, 23, 25, 25, 25,
197 25, 25, 26, 26, 26, 26, 26, 26,
198 28, 28, 28, 29, 29, 29, 29, 31,
199 31, 31, 32, 32, 32, 34, 34, 34,
200 35, 35, 37, 37, 38, 38, 38, 40,
201 40, 40, 41, 41, 43, 43, 44, 44,
202 }; 196 };
203 197
204 void vp8cx_initialize_me_consts(VP8_COMP *cpi, int QIndex) 198 void vp8cx_initialize_me_consts(VP8_COMP *cpi, int QIndex)
205 { 199 {
206 cpi->mb.sadperbit16 = sad_per_bit16lut[QIndex]; 200 cpi->mb.sadperbit16 = sad_per_bit16lut[QIndex];
207 cpi->mb.sadperbit4 = sad_per_bit4lut[QIndex]; 201 cpi->mb.sadperbit4 = sad_per_bit4lut[QIndex];
208 } 202 }
209 203
210 void vp8_initialize_rd_consts(VP8_COMP *cpi, int Qvalue) 204 void vp8_initialize_rd_consts(VP8_COMP *cpi, int Qvalue)
211 { 205 {
212 int q; 206 int q;
213 int i; 207 int i;
214 double capped_q = (Qvalue < 160) ? (double)Qvalue : 160.0; 208 double capped_q = (Qvalue < 160) ? (double)Qvalue : 160.0;
215 double rdconst = 3.00; 209 double rdconst = 2.70;
216 210
217 vp8_clear_system_state(); //__asm emms; 211 vp8_clear_system_state(); //__asm emms;
218 212
219 // Further tests required to see if optimum is different 213 // Further tests required to see if optimum is different
220 // for key frames, golden frames and arf frames. 214 // for key frames, golden frames and arf frames.
221 // if (cpi->common.refresh_golden_frame || 215 // if (cpi->common.refresh_golden_frame ||
222 // cpi->common.refresh_alt_ref_frame) 216 // cpi->common.refresh_alt_ref_frame)
223 cpi->RDMULT = (int)(rdconst * (capped_q * capped_q)); 217 cpi->RDMULT = (int)(rdconst * (capped_q * capped_q));
224 218
225 // Extend rate multiplier along side quantizer zbin increases 219 // Extend rate multiplier along side quantizer zbin increases
226 if (cpi->zbin_over_quant > 0) 220 if (cpi->zbin_over_quant > 0)
227 { 221 {
228 double oq_factor; 222 double oq_factor;
229 double modq; 223 double modq;
230 224
231 // Experimental code using the same basic equation as used for Q above 225 // Experimental code using the same basic equation as used for Q above
232 // The units of cpi->zbin_over_quant are 1/128 of Q bin size 226 // The units of cpi->zbin_over_quant are 1/128 of Q bin size
233 oq_factor = 1.0 + ((double)0.0015625 * cpi->zbin_over_quant); 227 oq_factor = 1.0 + ((double)0.0015625 * cpi->zbin_over_quant);
234 modq = (int)((double)capped_q * oq_factor); 228 modq = (int)((double)capped_q * oq_factor);
235 cpi->RDMULT = (int)(rdconst * (modq * modq)); 229 cpi->RDMULT = (int)(rdconst * (modq * modq));
236 } 230 }
237 231
238 if (cpi->pass == 2 && (cpi->common.frame_type != KEY_FRAME)) 232 if (cpi->pass == 2 && (cpi->common.frame_type != KEY_FRAME))
239 { 233 {
240 if (cpi->next_iiratio > 31) 234 if (cpi->twopass.next_iiratio > 31)
241 cpi->RDMULT += (cpi->RDMULT * rd_iifactor[31]) >> 4; 235 cpi->RDMULT += (cpi->RDMULT * rd_iifactor[31]) >> 4;
242 else 236 else
243 cpi->RDMULT += (cpi->RDMULT * rd_iifactor[cpi->next_iiratio]) >> 4; 237 cpi->RDMULT +=
238 (cpi->RDMULT * rd_iifactor[cpi->twopass.next_iiratio]) >> 4;
244 } 239 }
245 240
246 cpi->mb.errorperbit = (cpi->RDMULT / 100); 241 cpi->mb.errorperbit = (cpi->RDMULT / 110);
247 cpi->mb.errorperbit += (cpi->mb.errorperbit==0); 242 cpi->mb.errorperbit += (cpi->mb.errorperbit==0);
248 243
249 vp8_set_speed_features(cpi); 244 vp8_set_speed_features(cpi);
250 245
251 if (cpi->common.simpler_lpf)
252 cpi->common.filter_type = SIMPLE_LOOPFILTER;
253
254 q = (int)pow(Qvalue, 1.25); 246 q = (int)pow(Qvalue, 1.25);
255 247
256 if (q < 8) 248 if (q < 8)
257 q = 8; 249 q = 8;
258 250
259 if (cpi->RDMULT > 1000) 251 if (cpi->RDMULT > 1000)
260 { 252 {
261 cpi->RDDIV = 1; 253 cpi->RDDIV = 1;
262 cpi->RDMULT /= 100; 254 cpi->RDMULT /= 100;
263 255
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 cpi->mb.token_costs, 290 cpi->mb.token_costs,
299 (const vp8_prob( *)[8][3][11]) cpi->common.fc.coef_probs 291 (const vp8_prob( *)[8][3][11]) cpi->common.fc.coef_probs
300 ); 292 );
301 293
302 vp8_init_mode_costs(cpi); 294 vp8_init_mode_costs(cpi);
303 295
304 } 296 }
305 297
306 void vp8_auto_select_speed(VP8_COMP *cpi) 298 void vp8_auto_select_speed(VP8_COMP *cpi)
307 { 299 {
308 int used = cpi->oxcf.cpu_used;
309
310 int milliseconds_for_compress = (int)(1000000 / cpi->oxcf.frame_rate); 300 int milliseconds_for_compress = (int)(1000000 / cpi->oxcf.frame_rate);
311 301
312 milliseconds_for_compress = milliseconds_for_compress * (16 - cpi->oxcf.cpu_ used) / 16; 302 milliseconds_for_compress = milliseconds_for_compress * (16 - cpi->oxcf.cpu_ used) / 16;
313 303
314 #if 0 304 #if 0
315 305
316 if (0) 306 if (0)
317 { 307 {
318 FILE *f; 308 FILE *f;
319 309
320 f = fopen("speed.stt", "a"); 310 f = fopen("speed.stt", "a");
321 fprintf(f, " %8ld %10ld %10ld %10ld\n", 311 fprintf(f, " %8ld %10ld %10ld %10ld\n",
322 cpi->common.current_video_frame, cpi->Speed, milliseconds_for_co mpress, cpi->avg_pick_mode_time); 312 cpi->common.current_video_frame, cpi->Speed, milliseconds_for_co mpress, cpi->avg_pick_mode_time);
323 fclose(f); 313 fclose(f);
324 } 314 }
325 315
326 #endif 316 #endif
327 317
328 /* 318 /*
329 // this is done during parameter valid check 319 // this is done during parameter valid check
330 if( used > 16) 320 if( cpi->oxcf.cpu_used > 16)
331 used = 16; 321 cpi->oxcf.cpu_used = 16;
332 if( used < -16) 322 if( cpi->oxcf.cpu_used < -16)
333 used = -16; 323 cpi->oxcf.cpu_used = -16;
334 */ 324 */
335 325
336 if (cpi->avg_pick_mode_time < milliseconds_for_compress && (cpi->avg_encode_ time - cpi->avg_pick_mode_time) < milliseconds_for_compress) 326 if (cpi->avg_pick_mode_time < milliseconds_for_compress && (cpi->avg_encode_ time - cpi->avg_pick_mode_time) < milliseconds_for_compress)
337 { 327 {
338 if (cpi->avg_pick_mode_time == 0) 328 if (cpi->avg_pick_mode_time == 0)
339 { 329 {
340 cpi->Speed = 4; 330 cpi->Speed = 4;
341 } 331 }
342 else 332 else
343 { 333 {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 vp8_build_uvmvs(&x->e_mbd, 0); 448 vp8_build_uvmvs(&x->e_mbd, 0);
459 mv_row = x->e_mbd.block[16].bmi.mv.as_mv.row; 449 mv_row = x->e_mbd.block[16].bmi.mv.as_mv.row;
460 mv_col = x->e_mbd.block[16].bmi.mv.as_mv.col; 450 mv_col = x->e_mbd.block[16].bmi.mv.as_mv.col;
461 451
462 offset = (mv_row >> 3) * pre_stride + (mv_col >> 3); 452 offset = (mv_row >> 3) * pre_stride + (mv_col >> 3);
463 uptr = x->e_mbd.pre.u_buffer + offset; 453 uptr = x->e_mbd.pre.u_buffer + offset;
464 vptr = x->e_mbd.pre.v_buffer + offset; 454 vptr = x->e_mbd.pre.v_buffer + offset;
465 455
466 if ((mv_row | mv_col) & 7) 456 if ((mv_row | mv_col) & 7)
467 { 457 {
468 VARIANCE_INVOKE(rtcd, subpixvar8x8)(uptr, pre_stride, mv_col & 7, mv_row & 7, upred_ptr, uv_stride, &sse2); 458 VARIANCE_INVOKE(rtcd, subpixvar8x8)(uptr, pre_stride,
469 VARIANCE_INVOKE(rtcd, subpixvar8x8)(vptr, pre_stride, mv_col & 7, mv_row & 7, vpred_ptr, uv_stride, &sse1); 459 mv_col & 7, mv_row & 7, upred_ptr, uv_stride, &sse2);
460 VARIANCE_INVOKE(rtcd, subpixvar8x8)(vptr, pre_stride,
461 mv_col & 7, mv_row & 7, vpred_ptr, uv_stride, &sse1);
470 sse2 += sse1; 462 sse2 += sse1;
471 } 463 }
472 else 464 else
473 { 465 {
474 VARIANCE_INVOKE(rtcd, subpixvar8x8)(uptr, pre_stride, mv_col & 7, mv_row & 7, upred_ptr, uv_stride, &sse2); 466 VARIANCE_INVOKE(rtcd, var8x8)(uptr, pre_stride,
475 VARIANCE_INVOKE(rtcd, subpixvar8x8)(vptr, pre_stride, mv_col & 7, mv_row & 7, vpred_ptr, uv_stride, &sse1); 467 upred_ptr, uv_stride, &sse2);
468 VARIANCE_INVOKE(rtcd, var8x8)(vptr, pre_stride,
469 vpred_ptr, uv_stride, &sse1);
476 sse2 += sse1; 470 sse2 += sse1;
477 } 471 }
478
479 return sse2; 472 return sse2;
480 473
481 } 474 }
482 475
483 #if !(CONFIG_REALTIME_ONLY)
484 static int cost_coeffs(MACROBLOCK *mb, BLOCKD *b, int type, ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l) 476 static int cost_coeffs(MACROBLOCK *mb, BLOCKD *b, int type, ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l)
485 { 477 {
486 int c = !type; /* start at coef 0, unless Y with Y2 */ 478 int c = !type; /* start at coef 0, unless Y with Y2 */
487 int eob = b->eob; 479 int eob = b->eob;
488 int pt ; /* surrounding block/prev coef predictor */ 480 int pt ; /* surrounding block/prev coef predictor */
489 int cost = 0; 481 int cost = 0;
490 short *qcoeff_ptr = b->qcoeff; 482 short *qcoeff_ptr = b->qcoeff;
491 483
492 VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l); 484 VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
493 485
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 const vp8_encodemb_rtcd_vtable_t *rtcd) 536 const vp8_encodemb_rtcd_vtable_t *rtcd)
545 { 537 {
546 int b; 538 int b;
547 MACROBLOCKD *const x = &mb->e_mbd; 539 MACROBLOCKD *const x = &mb->e_mbd;
548 BLOCK *const mb_y2 = mb->block + 24; 540 BLOCK *const mb_y2 = mb->block + 24;
549 BLOCKD *const x_y2 = x->block + 24; 541 BLOCKD *const x_y2 = x->block + 24;
550 short *Y2DCPtr = mb_y2->src_diff; 542 short *Y2DCPtr = mb_y2->src_diff;
551 BLOCK *beptr; 543 BLOCK *beptr;
552 int d; 544 int d;
553 545
554 ENCODEMB_INVOKE(rtcd, submby)( mb->src_diff, mb->src.y_buffer, 546 ENCODEMB_INVOKE(rtcd, submby)( mb->src_diff, *(mb->block[0].base_src),
555 mb->e_mbd.predictor, mb->src.y_stride ); 547 mb->e_mbd.predictor, mb->block[0].src_stride );
556 548
557 // Fdct and building the 2nd order block 549 // Fdct and building the 2nd order block
558 for (beptr = mb->block; beptr < mb->block + 16; beptr += 2) 550 for (beptr = mb->block; beptr < mb->block + 16; beptr += 2)
559 { 551 {
560 mb->vp8_short_fdct8x4(beptr->src_diff, beptr->coeff, 32); 552 mb->vp8_short_fdct8x4(beptr->src_diff, beptr->coeff, 32);
561 *Y2DCPtr++ = beptr->coeff[0]; 553 *Y2DCPtr++ = beptr->coeff[0];
562 *Y2DCPtr++ = beptr->coeff[16]; 554 *Y2DCPtr++ = beptr->coeff[16];
563 } 555 }
564 556
565 // 2nd order fdct 557 // 2nd order fdct
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 DECLARE_ALIGNED_ARRAY(16, unsigned char, best_predictor, 16*4); 614 DECLARE_ALIGNED_ARRAY(16, unsigned char, best_predictor, 16*4);
623 DECLARE_ALIGNED_ARRAY(16, short, best_dqcoeff, 16); 615 DECLARE_ALIGNED_ARRAY(16, short, best_dqcoeff, 16);
624 616
625 for (mode = B_DC_PRED; mode <= B_HU_PRED; mode++) 617 for (mode = B_DC_PRED; mode <= B_HU_PRED; mode++)
626 { 618 {
627 int this_rd; 619 int this_rd;
628 int ratey; 620 int ratey;
629 621
630 rate = bmode_costs[mode]; 622 rate = bmode_costs[mode];
631 623
632 vp8_predict_intra4x4(b, mode, b->predictor); 624 RECON_INVOKE(&cpi->rtcd.common->recon, intra4x4_predict)
625 (b, mode, b->predictor);
633 ENCODEMB_INVOKE(IF_RTCD(&cpi->rtcd.encodemb), subb)(be, b, 16); 626 ENCODEMB_INVOKE(IF_RTCD(&cpi->rtcd.encodemb), subb)(be, b, 16);
634 x->vp8_short_fdct4x4(be->src_diff, be->coeff, 32); 627 x->vp8_short_fdct4x4(be->src_diff, be->coeff, 32);
635 x->quantize_b(be, b); 628 x->quantize_b(be, b);
636 629
637 tempa = ta; 630 tempa = ta;
638 templ = tl; 631 templ = tl;
639 632
640 ratey = cost_coeffs(x, b, PLANE_TYPE_Y_WITH_DC, &tempa, &templ); 633 ratey = cost_coeffs(x, b, PLANE_TYPE_Y_WITH_DC, &tempa, &templ);
641 rate += ratey; 634 rate += ratey;
642 distortion = ENCODEMB_INVOKE(IF_RTCD(&cpi->rtcd.encodemb), berr)(be->coe ff, b->dqcoeff) >> 2; 635 distortion = ENCODEMB_INVOKE(IF_RTCD(&cpi->rtcd.encodemb), berr)(be->coe ff, b->dqcoeff) >> 2;
643 636
644 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion); 637 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
645 638
646 if (this_rd < best_rd) 639 if (this_rd < best_rd)
647 { 640 {
648 *bestrate = rate; 641 *bestrate = rate;
649 *bestratey = ratey; 642 *bestratey = ratey;
650 *bestdistortion = distortion; 643 *bestdistortion = distortion;
651 best_rd = this_rd; 644 best_rd = this_rd;
652 *best_mode = mode; 645 *best_mode = mode;
653 *a = tempa; 646 *a = tempa;
654 *l = templ; 647 *l = templ;
655 copy_predictor(best_predictor, b->predictor); 648 copy_predictor(best_predictor, b->predictor);
656 vpx_memcpy(best_dqcoeff, b->dqcoeff, 32); 649 vpx_memcpy(best_dqcoeff, b->dqcoeff, 32);
657 } 650 }
658 } 651 }
659 652 b->bmi.as_mode = (B_PREDICTION_MODE)(*best_mode);
660 b->bmi.mode = (B_PREDICTION_MODE)(*best_mode);
661 653
662 IDCT_INVOKE(IF_RTCD(&cpi->rtcd.common->idct), idct16)(best_dqcoeff, b->diff, 32); 654 IDCT_INVOKE(IF_RTCD(&cpi->rtcd.common->idct), idct16)(best_dqcoeff, b->diff, 32);
663 RECON_INVOKE(IF_RTCD(&cpi->rtcd.common->recon), recon)(best_predictor, b->di ff, *(b->base_dst) + b->dst, b->dst_stride); 655 RECON_INVOKE(IF_RTCD(&cpi->rtcd.common->recon), recon)(best_predictor, b->di ff, *(b->base_dst) + b->dst, b->dst_stride);
664 656
665 return best_rd; 657 return best_rd;
666 } 658 }
667 659
668 int vp8_rd_pick_intra4x4mby_modes(VP8_COMP *cpi, MACROBLOCK *mb, int *Rate, 660 static int rd_pick_intra4x4mby_modes(VP8_COMP *cpi, MACROBLOCK *mb, int *Rate,
669 int *rate_y, int *Distortion, int best_rd) 661 int *rate_y, int *Distortion, int best_rd)
670 { 662 {
671 MACROBLOCKD *const xd = &mb->e_mbd; 663 MACROBLOCKD *const xd = &mb->e_mbd;
672 int i; 664 int i;
673 int cost = mb->mbmode_cost [xd->frame_type] [B_PRED]; 665 int cost = mb->mbmode_cost [xd->frame_type] [B_PRED];
674 int distortion = 0; 666 int distortion = 0;
675 int tot_rate_y = 0; 667 int tot_rate_y = 0;
676 long long total_rd = 0; 668 int64_t total_rd = 0;
677 ENTROPY_CONTEXT_PLANES t_above, t_left; 669 ENTROPY_CONTEXT_PLANES t_above, t_left;
678 ENTROPY_CONTEXT *ta; 670 ENTROPY_CONTEXT *ta;
679 ENTROPY_CONTEXT *tl; 671 ENTROPY_CONTEXT *tl;
680 unsigned int *bmode_costs; 672 unsigned int *bmode_costs;
681 673
682 vpx_memcpy(&t_above, mb->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES) ); 674 vpx_memcpy(&t_above, mb->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES) );
683 vpx_memcpy(&t_left, mb->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES)); 675 vpx_memcpy(&t_left, mb->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES));
684 676
685 ta = (ENTROPY_CONTEXT *)&t_above; 677 ta = (ENTROPY_CONTEXT *)&t_above;
686 tl = (ENTROPY_CONTEXT *)&t_left; 678 tl = (ENTROPY_CONTEXT *)&t_left;
687 679
688 vp8_intra_prediction_down_copy(xd); 680 vp8_intra_prediction_down_copy(xd);
689 681
690 bmode_costs = mb->inter_bmode_costs; 682 bmode_costs = mb->inter_bmode_costs;
691 683
692 for (i = 0; i < 16; i++) 684 for (i = 0; i < 16; i++)
693 { 685 {
694 MODE_INFO *const mic = xd->mode_info_context; 686 MODE_INFO *const mic = xd->mode_info_context;
695 const int mis = xd->mode_info_stride; 687 const int mis = xd->mode_info_stride;
696 B_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_mode); 688 B_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_mode);
697 int UNINITIALIZED_IS_SAFE(r), UNINITIALIZED_IS_SAFE(ry), UNINITIALIZED_I S_SAFE(d); 689 int UNINITIALIZED_IS_SAFE(r), UNINITIALIZED_IS_SAFE(ry), UNINITIALIZED_I S_SAFE(d);
698 690
699 if (mb->e_mbd.frame_type == KEY_FRAME) 691 if (mb->e_mbd.frame_type == KEY_FRAME)
700 { 692 {
701 const B_PREDICTION_MODE A = vp8_above_bmi(mic, i, mis)->mode; 693 const B_PREDICTION_MODE A = above_block_mode(mic, i, mis);
702 const B_PREDICTION_MODE L = vp8_left_bmi(mic, i)->mode; 694 const B_PREDICTION_MODE L = left_block_mode(mic, i);
703 695
704 bmode_costs = mb->bmode_costs[A][L]; 696 bmode_costs = mb->bmode_costs[A][L];
705 } 697 }
706 698
707 total_rd += rd_pick_intra4x4block( 699 total_rd += rd_pick_intra4x4block(
708 cpi, mb, mb->block + i, xd->block + i, &best_mode, bmode_costs, 700 cpi, mb, mb->block + i, xd->block + i, &best_mode, bmode_costs,
709 ta + vp8_block2above[i], 701 ta + vp8_block2above[i],
710 tl + vp8_block2left[i], &r, &ry, &d); 702 tl + vp8_block2left[i], &r, &ry, &d);
711 703
712 cost += r; 704 cost += r;
713 distortion += d; 705 distortion += d;
714 tot_rate_y += ry; 706 tot_rate_y += ry;
715 mic->bmi[i].mode = xd->block[i].bmi.mode = best_mode;
716 707
717 if(total_rd >= (long long)best_rd) 708 mic->bmi[i].as_mode = best_mode;
709
710 if(total_rd >= (int64_t)best_rd)
718 break; 711 break;
719 } 712 }
720 713
721 if(total_rd >= (long long)best_rd) 714 if(total_rd >= (int64_t)best_rd)
722 return INT_MAX; 715 return INT_MAX;
723 716
724 *Rate = cost; 717 *Rate = cost;
725 *rate_y += tot_rate_y; 718 *rate_y += tot_rate_y;
726 *Distortion = distortion; 719 *Distortion = distortion;
727 720
728 return RDCOST(mb->rdmult, mb->rddiv, cost, distortion); 721 return RDCOST(mb->rdmult, mb->rddiv, cost, distortion);
729 } 722 }
730 int vp8_rd_pick_intra16x16mby_mode(VP8_COMP *cpi, 723
731 MACROBLOCK *x, 724
732 int *Rate, 725 static int rd_pick_intra16x16mby_mode(VP8_COMP *cpi,
733 int *rate_y, 726 MACROBLOCK *x,
734 int *Distortion) 727 int *Rate,
728 int *rate_y,
729 int *Distortion)
735 { 730 {
736 MB_PREDICTION_MODE mode; 731 MB_PREDICTION_MODE mode;
737 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected); 732 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected);
738 int rate, ratey; 733 int rate, ratey;
739 int distortion; 734 int distortion;
740 int best_rd = INT_MAX; 735 int best_rd = INT_MAX;
741 int this_rd; 736 int this_rd;
742 737
743 //Y Search for 16x16 intra prediction mode 738 //Y Search for 16x16 intra prediction mode
744 for (mode = DC_PRED; mode <= TM_PRED; mode++) 739 for (mode = DC_PRED; mode <= TM_PRED; mode++)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 vp8_build_uvmvs(&x->e_mbd, fullpixel); 791 vp8_build_uvmvs(&x->e_mbd, fullpixel);
797 vp8_encode_inter16x16uvrd(IF_RTCD(&cpi->rtcd), x); 792 vp8_encode_inter16x16uvrd(IF_RTCD(&cpi->rtcd), x);
798 793
799 794
800 *rate = rd_cost_mbuv(x); 795 *rate = rd_cost_mbuv(x);
801 *distortion = ENCODEMB_INVOKE(&cpi->rtcd.encodemb, mbuverr)(x) / 4; 796 *distortion = ENCODEMB_INVOKE(&cpi->rtcd.encodemb, mbuverr)(x) / 4;
802 797
803 return RDCOST(x->rdmult, x->rddiv, *rate, *distortion); 798 return RDCOST(x->rdmult, x->rddiv, *rate, *distortion);
804 } 799 }
805 800
806 int vp8_rd_pick_intra_mbuv_mode(VP8_COMP *cpi, MACROBLOCK *x, int *rate, int *ra te_tokenonly, int *distortion) 801 static void rd_pick_intra_mbuv_mode(VP8_COMP *cpi, MACROBLOCK *x, int *rate, int *rate_tokenonly, int *distortion)
807 { 802 {
808 MB_PREDICTION_MODE mode; 803 MB_PREDICTION_MODE mode;
809 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected); 804 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected);
810 int best_rd = INT_MAX; 805 int best_rd = INT_MAX;
811 int UNINITIALIZED_IS_SAFE(d), UNINITIALIZED_IS_SAFE(r); 806 int UNINITIALIZED_IS_SAFE(d), UNINITIALIZED_IS_SAFE(r);
812 int rate_to; 807 int rate_to;
813 808
814 for (mode = DC_PRED; mode <= TM_PRED; mode++) 809 for (mode = DC_PRED; mode <= TM_PRED; mode++)
815 { 810 {
816 int rate; 811 int rate;
817 int distortion; 812 int distortion;
818 int this_rd; 813 int this_rd;
819 814
820 x->e_mbd.mode_info_context->mbmi.uv_mode = mode; 815 x->e_mbd.mode_info_context->mbmi.uv_mode = mode;
821 vp8_build_intra_predictors_mbuv(&x->e_mbd); 816 RECON_INVOKE(&cpi->rtcd.common->recon, build_intra_predictors_mbuv)
817 (&x->e_mbd);
822 ENCODEMB_INVOKE(IF_RTCD(&cpi->rtcd.encodemb), submbuv)(x->src_diff, 818 ENCODEMB_INVOKE(IF_RTCD(&cpi->rtcd.encodemb), submbuv)(x->src_diff,
823 x->src.u_buffer, x->src.v_buffer, x->e_mbd.predictor, 819 x->src.u_buffer, x->src.v_buffer, x->e_mbd.predictor,
824 x->src.uv_stride); 820 x->src.uv_stride);
825 vp8_transform_mbuv(x); 821 vp8_transform_mbuv(x);
826 vp8_quantize_mbuv(x); 822 vp8_quantize_mbuv(x);
827 823
828 rate_to = rd_cost_mbuv(x); 824 rate_to = rd_cost_mbuv(x);
829 rate = rate_to + x->intra_uv_mode_cost[x->e_mbd.frame_type][x->e_mbd.mod e_info_context->mbmi.uv_mode]; 825 rate = rate_to + x->intra_uv_mode_cost[x->e_mbd.frame_type][x->e_mbd.mod e_info_context->mbmi.uv_mode];
830 826
831 distortion = ENCODEMB_INVOKE(&cpi->rtcd.encodemb, mbuverr)(x) / 4; 827 distortion = ENCODEMB_INVOKE(&cpi->rtcd.encodemb, mbuverr)(x) / 4;
832 828
833 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion); 829 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
834 830
835 if (this_rd < best_rd) 831 if (this_rd < best_rd)
836 { 832 {
837 best_rd = this_rd; 833 best_rd = this_rd;
838 d = distortion; 834 d = distortion;
839 r = rate; 835 r = rate;
840 *rate_tokenonly = rate_to; 836 *rate_tokenonly = rate_to;
841 mode_selected = mode; 837 mode_selected = mode;
842 } 838 }
843 } 839 }
844 840
845 *rate = r; 841 *rate = r;
846 *distortion = d; 842 *distortion = d;
847 843
848 x->e_mbd.mode_info_context->mbmi.uv_mode = mode_selected; 844 x->e_mbd.mode_info_context->mbmi.uv_mode = mode_selected;
849 return best_rd;
850 } 845 }
851 #endif
852 846
853 int vp8_cost_mv_ref(MB_PREDICTION_MODE m, const int near_mv_ref_ct[4]) 847 int vp8_cost_mv_ref(MB_PREDICTION_MODE m, const int near_mv_ref_ct[4])
854 { 848 {
855 vp8_prob p [VP8_MVREFS-1]; 849 vp8_prob p [VP8_MVREFS-1];
856 assert(NEARESTMV <= m && m <= SPLITMV); 850 assert(NEARESTMV <= m && m <= SPLITMV);
857 vp8_mv_ref_probs(p, near_mv_ref_ct); 851 vp8_mv_ref_probs(p, near_mv_ref_ct);
858 return vp8_cost_token(vp8_mv_ref_tree, p, 852 return vp8_cost_token(vp8_mv_ref_tree, p,
859 vp8_mv_ref_encoding_array - NEARESTMV + m); 853 vp8_mv_ref_encoding_array - NEARESTMV + m);
860 } 854 }
861 855
862 void vp8_set_mbmode_and_mvs(MACROBLOCK *x, MB_PREDICTION_MODE mb, MV *mv) 856 void vp8_set_mbmode_and_mvs(MACROBLOCK *x, MB_PREDICTION_MODE mb, int_mv *mv)
863 { 857 {
864 int i;
865
866 x->e_mbd.mode_info_context->mbmi.mode = mb; 858 x->e_mbd.mode_info_context->mbmi.mode = mb;
867 x->e_mbd.mode_info_context->mbmi.mv.as_mv.row = mv->row; 859 x->e_mbd.mode_info_context->mbmi.mv.as_int = mv->as_int;
868 x->e_mbd.mode_info_context->mbmi.mv.as_mv.col = mv->col;
869
870 for (i = 0; i < 16; i++)
871 {
872 B_MODE_INFO *bmi = &x->e_mbd.block[i].bmi;
873 bmi->mode = (B_PREDICTION_MODE) mb;
874 bmi->mv.as_mv.row = mv->row;
875 bmi->mv.as_mv.col = mv->col;
876 }
877 } 860 }
878 861
879 #if !(CONFIG_REALTIME_ONLY)
880 static int labels2mode( 862 static int labels2mode(
881 MACROBLOCK *x, 863 MACROBLOCK *x,
882 int const *labelings, int which_label, 864 int const *labelings, int which_label,
883 B_PREDICTION_MODE this_mode, 865 B_PREDICTION_MODE this_mode,
884 MV *this_mv, MV *best_ref_mv, 866 int_mv *this_mv, int_mv *best_ref_mv,
885 int *mvcost[2] 867 int *mvcost[2]
886 ) 868 )
887 { 869 {
888 MACROBLOCKD *const xd = & x->e_mbd; 870 MACROBLOCKD *const xd = & x->e_mbd;
889 MODE_INFO *const mic = xd->mode_info_context; 871 MODE_INFO *const mic = xd->mode_info_context;
890 const int mis = xd->mode_info_stride; 872 const int mis = xd->mode_info_stride;
891 873
892 int cost = 0; 874 int cost = 0;
893 int thismvcost = 0; 875 int thismvcost = 0;
894 876
(...skipping 20 matching lines...) Expand all
915 else 897 else
916 { 898 {
917 // the only time we should do costing for new motion vector or mode 899 // the only time we should do costing for new motion vector or mode
918 // is when we are on a new label (jbb May 08, 2007) 900 // is when we are on a new label (jbb May 08, 2007)
919 switch (m = this_mode) 901 switch (m = this_mode)
920 { 902 {
921 case NEW4X4 : 903 case NEW4X4 :
922 thismvcost = vp8_mv_bit_cost(this_mv, best_ref_mv, mvcost, 102) ; 904 thismvcost = vp8_mv_bit_cost(this_mv, best_ref_mv, mvcost, 102) ;
923 break; 905 break;
924 case LEFT4X4: 906 case LEFT4X4:
925 *this_mv = col ? d[-1].bmi.mv.as_mv : vp8_left_bmi(mic, i)->mv.a s_mv; 907 this_mv->as_int = col ? d[-1].bmi.mv.as_int : left_block_mv(mic, i);
926 break; 908 break;
927 case ABOVE4X4: 909 case ABOVE4X4:
928 *this_mv = row ? d[-4].bmi.mv.as_mv : vp8_above_bmi(mic, i, mis) ->mv.as_mv; 910 this_mv->as_int = row ? d[-4].bmi.mv.as_int : above_block_mv(mic , i, mis);
929 break; 911 break;
930 case ZERO4X4: 912 case ZERO4X4:
931 this_mv->row = this_mv->col = 0; 913 this_mv->as_int = 0;
932 break; 914 break;
933 default: 915 default:
934 break; 916 break;
935 } 917 }
936 918
937 if (m == ABOVE4X4) // replace above with left if same 919 if (m == ABOVE4X4) // replace above with left if same
938 { 920 {
939 const MV mv = col ? d[-1].bmi.mv.as_mv : vp8_left_bmi(mic, i)->m v.as_mv; 921 int_mv left_mv;
940 922
941 if (mv.row == this_mv->row && mv.col == this_mv->col) 923 left_mv.as_int = col ? d[-1].bmi.mv.as_int :
924 left_block_mv(mic, i);
925
926 if (left_mv.as_int == this_mv->as_int)
942 m = LEFT4X4; 927 m = LEFT4X4;
943 } 928 }
944 929
945 cost = x->inter_bmode_costs[ m]; 930 cost = x->inter_bmode_costs[ m];
946 } 931 }
947 932
948 d->bmi.mode = m; 933 d->bmi.mv.as_int = this_mv->as_int;
949 d->bmi.mv.as_mv = *this_mv; 934
935 x->partition_info->bmi[i].mode = m;
936 x->partition_info->bmi[i].mv.as_int = this_mv->as_int;
950 937
951 } 938 }
952 while (++i < 16); 939 while (++i < 16);
953 940
954 cost += thismvcost ; 941 cost += thismvcost ;
955 return cost; 942 return cost;
956 } 943 }
957 944
958 static int rdcost_mbsegment_y(MACROBLOCK *mb, const int *labels, 945 static int rdcost_mbsegment_y(MACROBLOCK *mb, const int *labels,
959 int which_label, ENTROPY_CONTEXT *ta, 946 int which_label, ENTROPY_CONTEXT *ta,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 986
1000 return distortion; 987 return distortion;
1001 } 988 }
1002 989
1003 990
1004 static const unsigned int segmentation_to_sseshift[4] = {3, 3, 2, 0}; 991 static const unsigned int segmentation_to_sseshift[4] = {3, 3, 2, 0};
1005 992
1006 993
1007 typedef struct 994 typedef struct
1008 { 995 {
1009 MV *ref_mv; 996 int_mv *ref_mv;
1010 MV *mvp; 997 int_mv mvp;
1011 998
1012 int segment_rd; 999 int segment_rd;
1013 int segment_num; 1000 int segment_num;
1014 int r; 1001 int r;
1015 int d; 1002 int d;
1016 int segment_yrate; 1003 int segment_yrate;
1017 B_PREDICTION_MODE modes[16]; 1004 B_PREDICTION_MODE modes[16];
1018 int_mv mvs[16]; 1005 int_mv mvs[16];
1019 unsigned char eobs[16]; 1006 unsigned char eobs[16];
1020 1007
1021 int mvthresh; 1008 int mvthresh;
1022 int *mdcounts; 1009 int *mdcounts;
1023 1010
1024 MV sv_mvp[4]; // save 4 mvp from 8x8 1011 int_mv sv_mvp[4]; // save 4 mvp from 8x8
1025 int sv_istep[2]; // save 2 initial step_param for 16x8/8x16 1012 int sv_istep[2]; // save 2 initial step_param for 16x8/8x16
1026 1013
1027 } BEST_SEG_INFO; 1014 } BEST_SEG_INFO;
1028 1015
1029 1016
1030 static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x, 1017 static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
1031 BEST_SEG_INFO *bsi, unsigned int segmentation) 1018 BEST_SEG_INFO *bsi, unsigned int segmentation)
1032 { 1019 {
1033 int i; 1020 int i;
1034 int const *labels; 1021 int const *labels;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 label_mv_thresh = 1 * bsi->mvthresh / label_count ; 1063 label_mv_thresh = 1 * bsi->mvthresh / label_count ;
1077 1064
1078 // Segmentation method overheads 1065 // Segmentation method overheads
1079 rate = vp8_cost_token(vp8_mbsplit_tree, vp8_mbsplit_probs, vp8_mbsplit_encod ings + segmentation); 1066 rate = vp8_cost_token(vp8_mbsplit_tree, vp8_mbsplit_probs, vp8_mbsplit_encod ings + segmentation);
1080 rate += vp8_cost_mv_ref(SPLITMV, bsi->mdcounts); 1067 rate += vp8_cost_mv_ref(SPLITMV, bsi->mdcounts);
1081 this_segment_rd += RDCOST(x->rdmult, x->rddiv, rate, 0); 1068 this_segment_rd += RDCOST(x->rdmult, x->rddiv, rate, 0);
1082 br += rate; 1069 br += rate;
1083 1070
1084 for (i = 0; i < label_count; i++) 1071 for (i = 0; i < label_count; i++)
1085 { 1072 {
1086 MV mode_mv[B_MODE_COUNT]; 1073 int_mv mode_mv[B_MODE_COUNT];
1087 int best_label_rd = INT_MAX; 1074 int best_label_rd = INT_MAX;
1088 B_PREDICTION_MODE mode_selected = ZERO4X4; 1075 B_PREDICTION_MODE mode_selected = ZERO4X4;
1089 int bestlabelyrate = 0; 1076 int bestlabelyrate = 0;
1090 1077
1091 // search for the best motion vector on this segment 1078 // search for the best motion vector on this segment
1092 for (this_mode = LEFT4X4; this_mode <= NEW4X4 ; this_mode ++) 1079 for (this_mode = LEFT4X4; this_mode <= NEW4X4 ; this_mode ++)
1093 { 1080 {
1094 int this_rd; 1081 int this_rd;
1095 int distortion; 1082 int distortion;
1096 int labelyrate; 1083 int labelyrate;
1097 ENTROPY_CONTEXT_PLANES t_above_s, t_left_s; 1084 ENTROPY_CONTEXT_PLANES t_above_s, t_left_s;
1098 ENTROPY_CONTEXT *ta_s; 1085 ENTROPY_CONTEXT *ta_s;
1099 ENTROPY_CONTEXT *tl_s; 1086 ENTROPY_CONTEXT *tl_s;
1100 1087
1101 vpx_memcpy(&t_above_s, &t_above, sizeof(ENTROPY_CONTEXT_PLANES)); 1088 vpx_memcpy(&t_above_s, &t_above, sizeof(ENTROPY_CONTEXT_PLANES));
1102 vpx_memcpy(&t_left_s, &t_left, sizeof(ENTROPY_CONTEXT_PLANES)); 1089 vpx_memcpy(&t_left_s, &t_left, sizeof(ENTROPY_CONTEXT_PLANES));
1103 1090
1104 ta_s = (ENTROPY_CONTEXT *)&t_above_s; 1091 ta_s = (ENTROPY_CONTEXT *)&t_above_s;
1105 tl_s = (ENTROPY_CONTEXT *)&t_left_s; 1092 tl_s = (ENTROPY_CONTEXT *)&t_left_s;
1106 1093
1107 if (this_mode == NEW4X4) 1094 if (this_mode == NEW4X4)
1108 { 1095 {
1109 int sseshift; 1096 int sseshift;
1110 int num00; 1097 int num00;
1111 int step_param = 0; 1098 int step_param = 0;
1112 int further_steps; 1099 int further_steps;
1113 int n; 1100 int n;
1114 int thissme; 1101 int thissme;
1115 int bestsme = INT_MAX; 1102 int bestsme = INT_MAX;
1116 MV temp_mv; 1103 int_mv temp_mv;
1117 BLOCK *c; 1104 BLOCK *c;
1118 BLOCKD *e; 1105 BLOCKD *e;
1119 1106
1120 // Is the best so far sufficiently good that we cant justify doi ng and new motion search. 1107 // Is the best so far sufficiently good that we cant justify doi ng and new motion search.
1121 if (best_label_rd < label_mv_thresh) 1108 if (best_label_rd < label_mv_thresh)
1122 break; 1109 break;
1123 1110
1124 if(cpi->compressor_speed) 1111 if(cpi->compressor_speed)
1125 { 1112 {
1126 if (segmentation == BLOCK_8X16 || segmentation == BLOCK_16X8 ) 1113 if (segmentation == BLOCK_8X16 || segmentation == BLOCK_16X8 )
1127 { 1114 {
1128 bsi->mvp = &bsi->sv_mvp[i]; 1115 bsi->mvp.as_int = bsi->sv_mvp[i].as_int;
1129 if (i==1 && segmentation == BLOCK_16X8) bsi->mvp = &bsi- >sv_mvp[2]; 1116 if (i==1 && segmentation == BLOCK_16X8)
1117 bsi->mvp.as_int = bsi->sv_mvp[2].as_int;
1130 1118
1131 step_param = bsi->sv_istep[i]; 1119 step_param = bsi->sv_istep[i];
1132 } 1120 }
1133 1121
1134 // use previous block's result as next block's MV predictor. 1122 // use previous block's result as next block's MV predictor.
1135 if (segmentation == BLOCK_4X4 && i>0) 1123 if (segmentation == BLOCK_4X4 && i>0)
1136 { 1124 {
1137 bsi->mvp = &(x->e_mbd.block[i-1].bmi.mv.as_mv); 1125 bsi->mvp.as_int = x->e_mbd.block[i-1].bmi.mv.as_int;
1138 if (i==4 || i==8 || i==12) bsi->mvp = &(x->e_mbd.block[i -4].bmi.mv.as_mv); 1126 if (i==4 || i==8 || i==12)
1127 bsi->mvp.as_int = x->e_mbd.block[i-4].bmi.mv.as_int;
1139 step_param = 2; 1128 step_param = 2;
1140 } 1129 }
1141 } 1130 }
1142 1131
1143 further_steps = (MAX_MVSEARCH_STEPS - 1) - step_param; 1132 further_steps = (MAX_MVSEARCH_STEPS - 1) - step_param;
1144 1133
1145 { 1134 {
1146 int sadpb = x->sadperbit4; 1135 int sadpb = x->sadperbit4;
1136 int_mv mvp_full;
1137
1138 mvp_full.as_mv.row = bsi->mvp.as_mv.row >>3;
1139 mvp_full.as_mv.col = bsi->mvp.as_mv.col >>3;
1147 1140
1148 // find first label 1141 // find first label
1149 n = vp8_mbsplit_offset[segmentation][i]; 1142 n = vp8_mbsplit_offset[segmentation][i];
1150 1143
1151 c = &x->block[n]; 1144 c = &x->block[n];
1152 e = &x->e_mbd.block[n]; 1145 e = &x->e_mbd.block[n];
1153 1146
1154 if (cpi->sf.search_method == HEX)
1155 bestsme = vp8_hex_search(x, c, e, bsi->ref_mv,
1156 &mode_mv[NEW4X4], step_param, s adpb, &num00, v_fn_ptr, x->mvsadcost, x->mvcost, bsi->ref_mv);
1157
1158 else
1159 { 1147 {
1160 bestsme = cpi->diamond_search_sad(x, c, e, bsi->mvp, 1148 bestsme = cpi->diamond_search_sad(x, c, e, &mvp_full,
1161 &mode_mv[NEW4X4], step _param, 1149 &mode_mv[NEW4X4], step_param,
1162 sadpb / 2, &num00, v_f n_ptr, x->mvsadcost, x->mvcost, bsi->ref_mv); 1150 sadpb, &num00, v_fn_ptr,
1151 x->mvcost, bsi->ref_mv);
1163 1152
1164 n = num00; 1153 n = num00;
1165 num00 = 0; 1154 num00 = 0;
1166 1155
1167 while (n < further_steps) 1156 while (n < further_steps)
1168 { 1157 {
1169 n++; 1158 n++;
1170 1159
1171 if (num00) 1160 if (num00)
1172 num00--; 1161 num00--;
1173 else 1162 else
1174 { 1163 {
1175 thissme = cpi->diamond_search_sad(x, c, e, bsi-> mvp, 1164 thissme = cpi->diamond_search_sad(x, c, e,
1176 &temp_mv, step _param + n, 1165 &mvp_full, &temp_mv,
1177 sadpb / 2, &nu m00, v_fn_ptr, x->mvsadcost, x->mvcost, bsi->ref_mv); 1166 step_param + n, sadpb,
1167 &num00, v_fn_ptr,
1168 x->mvcost, bsi->ref_mv);
1178 1169
1179 if (thissme < bestsme) 1170 if (thissme < bestsme)
1180 { 1171 {
1181 bestsme = thissme; 1172 bestsme = thissme;
1182 mode_mv[NEW4X4].row = temp_mv.row; 1173 mode_mv[NEW4X4].as_int = temp_mv.as_int;
1183 mode_mv[NEW4X4].col = temp_mv.col;
1184 } 1174 }
1185 } 1175 }
1186 } 1176 }
1187 } 1177 }
1188 1178
1189 sseshift = segmentation_to_sseshift[segmentation]; 1179 sseshift = segmentation_to_sseshift[segmentation];
1190 1180
1191 // Should we do a full search (best quality only) 1181 // Should we do a full search (best quality only)
1192 if ((cpi->compressor_speed == 0) && (bestsme >> sseshift) > 4000) 1182 if ((cpi->compressor_speed == 0) && (bestsme >> sseshift) > 4000)
1193 { 1183 {
1194 thissme = cpi->full_search_sad(x, c, e, bsi->mvp, 1184 /* Check if mvp_full is within the range. */
1195 sadpb / 4, 16, v_fn_ptr, x->mvcost, x->mvsadcost,bsi->ref_mv); 1185 vp8_clamp_mv(&mvp_full, x->mv_col_min, x->mv_col_max, x- >mv_row_min, x->mv_row_max);
1186
1187 thissme = cpi->full_search_sad(x, c, e, &mvp_full,
1188 sadpb, 16, v_fn_ptr,
1189 x->mvcost, bsi->ref_mv);
1196 1190
1197 if (thissme < bestsme) 1191 if (thissme < bestsme)
1198 { 1192 {
1199 bestsme = thissme; 1193 bestsme = thissme;
1200 mode_mv[NEW4X4] = e->bmi.mv.as_mv; 1194 mode_mv[NEW4X4].as_int = e->bmi.mv.as_int;
1201 } 1195 }
1202 else 1196 else
1203 { 1197 {
1204 // The full search result is actually worse so re-in state the previous best vector 1198 // The full search result is actually worse so re-in state the previous best vector
1205 e->bmi.mv.as_mv = mode_mv[NEW4X4]; 1199 e->bmi.mv.as_int = mode_mv[NEW4X4].as_int;
1206 } 1200 }
1207 } 1201 }
1208 } 1202 }
1209 1203
1210 if (bestsme < INT_MAX) 1204 if (bestsme < INT_MAX)
1211 { 1205 {
1212 if (!cpi->common.full_pixel) 1206 int distortion;
1213 cpi->find_fractional_mv_step(x, c, e, &mode_mv[NEW4X4], 1207 unsigned int sse;
1214 bsi->ref_mv, x->errorperbit / 2, v_fn_ptr, x->mvcost); 1208 cpi->find_fractional_mv_step(x, c, e, &mode_mv[NEW4X4],
1215 else 1209 bsi->ref_mv, x->errorperbit, v_fn_ptr, x->mvcost,
1216 vp8_skip_fractional_mv_step(x, c, e, &mode_mv[NEW4X4], 1210 &distortion, &sse);
1217 bsi->ref_mv, x->errorperbit, v_fn_ptr, x->mvcost); 1211
1218 } 1212 }
1219 } /* NEW4X4 */ 1213 } /* NEW4X4 */
1220 1214
1221 rate = labels2mode(x, labels, i, this_mode, &mode_mv[this_mode], 1215 rate = labels2mode(x, labels, i, this_mode, &mode_mv[this_mode],
1222 bsi->ref_mv, x->mvcost); 1216 bsi->ref_mv, x->mvcost);
1223 1217
1224 // Trap vectors that reach beyond the UMV borders 1218 // Trap vectors that reach beyond the UMV borders
1225 if (((mode_mv[this_mode].row >> 3) < x->mv_row_min) || ((mode_mv[thi s_mode].row >> 3) > x->mv_row_max) || 1219 if (((mode_mv[this_mode].as_mv.row >> 3) < x->mv_row_min) || ((mode_ mv[this_mode].as_mv.row >> 3) > x->mv_row_max) ||
1226 ((mode_mv[this_mode].col >> 3) < x->mv_col_min) || ((mode_mv[thi s_mode].col >> 3) > x->mv_col_max)) 1220 ((mode_mv[this_mode].as_mv.col >> 3) < x->mv_col_min) || ((mode_ mv[this_mode].as_mv.col >> 3) > x->mv_col_max))
1227 { 1221 {
1228 continue; 1222 continue;
1229 } 1223 }
1230 1224
1231 distortion = vp8_encode_inter_mb_segment(x, labels, i, IF_RTCD(&cpi- >rtcd.encodemb)) / 4; 1225 distortion = vp8_encode_inter_mb_segment(x, labels, i, IF_RTCD(&cpi- >rtcd.encodemb)) / 4;
1232 1226
1233 labelyrate = rdcost_mbsegment_y(x, labels, i, ta_s, tl_s); 1227 labelyrate = rdcost_mbsegment_y(x, labels, i, ta_s, tl_s);
1234 rate += labelyrate; 1228 rate += labelyrate;
1235 1229
1236 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion); 1230 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 bsi->d = bd; 1265 bsi->d = bd;
1272 bsi->segment_yrate = segmentyrate; 1266 bsi->segment_yrate = segmentyrate;
1273 bsi->segment_rd = this_segment_rd; 1267 bsi->segment_rd = this_segment_rd;
1274 bsi->segment_num = segmentation; 1268 bsi->segment_num = segmentation;
1275 1269
1276 // store everything needed to come back to this!! 1270 // store everything needed to come back to this!!
1277 for (i = 0; i < 16; i++) 1271 for (i = 0; i < 16; i++)
1278 { 1272 {
1279 BLOCKD *bd = &x->e_mbd.block[i]; 1273 BLOCKD *bd = &x->e_mbd.block[i];
1280 1274
1281 bsi->mvs[i].as_mv = bd->bmi.mv.as_mv; 1275 bsi->mvs[i].as_mv = x->partition_info->bmi[i].mv.as_mv;
1282 bsi->modes[i] = bd->bmi.mode; 1276 bsi->modes[i] = x->partition_info->bmi[i].mode;
1283 bsi->eobs[i] = bd->eob; 1277 bsi->eobs[i] = bd->eob;
1284 } 1278 }
1285 } 1279 }
1286 } 1280 }
1287 1281
1288 static __inline 1282 static __inline
1289 void vp8_cal_step_param(int sr, int *sp) 1283 void vp8_cal_step_param(int sr, int *sp)
1290 { 1284 {
1291 int step = 0; 1285 int step = 0;
1292 1286
1293 if (sr > MAX_FIRST_STEP) sr = MAX_FIRST_STEP; 1287 if (sr > MAX_FIRST_STEP) sr = MAX_FIRST_STEP;
1294 else if (sr < 1) sr = 1; 1288 else if (sr < 1) sr = 1;
1295 1289
1296 while (sr>>=1) 1290 while (sr>>=1)
1297 step++; 1291 step++;
1298 1292
1299 *sp = MAX_MVSEARCH_STEPS - 1 - step; 1293 *sp = MAX_MVSEARCH_STEPS - 1 - step;
1300 } 1294 }
1301 1295
1302 static int vp8_rd_pick_best_mbsegmentation(VP8_COMP *cpi, MACROBLOCK *x, 1296 static int vp8_rd_pick_best_mbsegmentation(VP8_COMP *cpi, MACROBLOCK *x,
1303 MV *best_ref_mv, int best_rd, 1297 int_mv *best_ref_mv, int best_rd,
1304 int *mdcounts, int *returntotrate, 1298 int *mdcounts, int *returntotrate,
1305 int *returnyrate, int *returndistorti on, 1299 int *returnyrate, int *returndistorti on,
1306 int mvthresh) 1300 int mvthresh)
1307 { 1301 {
1308 int i; 1302 int i;
1309 BEST_SEG_INFO bsi; 1303 BEST_SEG_INFO bsi;
1310 1304
1311 vpx_memset(&bsi, 0, sizeof(bsi)); 1305 vpx_memset(&bsi, 0, sizeof(bsi));
1312 1306
1313 bsi.segment_rd = best_rd; 1307 bsi.segment_rd = best_rd;
1314 bsi.ref_mv = best_ref_mv; 1308 bsi.ref_mv = best_ref_mv;
1315 bsi.mvp = best_ref_mv; 1309 bsi.mvp.as_int = best_ref_mv->as_int;
1316 bsi.mvthresh = mvthresh; 1310 bsi.mvthresh = mvthresh;
1317 bsi.mdcounts = mdcounts; 1311 bsi.mdcounts = mdcounts;
1318 1312
1319 for(i = 0; i < 16; i++) 1313 for(i = 0; i < 16; i++)
1320 { 1314 {
1321 bsi.modes[i] = ZERO4X4; 1315 bsi.modes[i] = ZERO4X4;
1322 } 1316 }
1323 1317
1324 if(cpi->compressor_speed == 0) 1318 if(cpi->compressor_speed == 0)
1325 { 1319 {
1326 /* for now, we will keep the original segmentation order 1320 /* for now, we will keep the original segmentation order
1327 when in best quality mode */ 1321 when in best quality mode */
1328 rd_check_segment(cpi, x, &bsi, BLOCK_16X8); 1322 rd_check_segment(cpi, x, &bsi, BLOCK_16X8);
1329 rd_check_segment(cpi, x, &bsi, BLOCK_8X16); 1323 rd_check_segment(cpi, x, &bsi, BLOCK_8X16);
1330 rd_check_segment(cpi, x, &bsi, BLOCK_8X8); 1324 rd_check_segment(cpi, x, &bsi, BLOCK_8X8);
1331 rd_check_segment(cpi, x, &bsi, BLOCK_4X4); 1325 rd_check_segment(cpi, x, &bsi, BLOCK_4X4);
1332 } 1326 }
1333 else 1327 else
1334 { 1328 {
1335 int sr; 1329 int sr;
1336 1330
1337 rd_check_segment(cpi, x, &bsi, BLOCK_8X8); 1331 rd_check_segment(cpi, x, &bsi, BLOCK_8X8);
1338 1332
1339 if (bsi.segment_rd < best_rd) 1333 if (bsi.segment_rd < best_rd)
1340 { 1334 {
1341 int col_min = (best_ref_mv->col - MAX_FULL_PEL_VAL) >>3; 1335 int col_min = (best_ref_mv->as_mv.col>>3) - MAX_FULL_PEL_VAL + ((bes t_ref_mv->as_mv.col & 7)?1:0);
1342 int col_max = (best_ref_mv->col + MAX_FULL_PEL_VAL) >>3; 1336 int row_min = (best_ref_mv->as_mv.row>>3) - MAX_FULL_PEL_VAL + ((bes t_ref_mv->as_mv.row & 7)?1:0);
1343 int row_min = (best_ref_mv->row - MAX_FULL_PEL_VAL) >>3; 1337 int col_max = (best_ref_mv->as_mv.col>>3) + MAX_FULL_PEL_VAL;
1344 int row_max = (best_ref_mv->row + MAX_FULL_PEL_VAL) >>3; 1338 int row_max = (best_ref_mv->as_mv.row>>3) + MAX_FULL_PEL_VAL;
1345 1339
1346 int tmp_col_min = x->mv_col_min; 1340 int tmp_col_min = x->mv_col_min;
1347 int tmp_col_max = x->mv_col_max; 1341 int tmp_col_max = x->mv_col_max;
1348 int tmp_row_min = x->mv_row_min; 1342 int tmp_row_min = x->mv_row_min;
1349 int tmp_row_max = x->mv_row_max; 1343 int tmp_row_max = x->mv_row_max;
1350 1344
1351 /* Get intersection of UMV window and valid MV window to reduce # of checks in diamond search. */ 1345 /* Get intersection of UMV window and valid MV window to reduce # of checks in diamond search. */
1352 if (x->mv_col_min < col_min ) 1346 if (x->mv_col_min < col_min )
1353 x->mv_col_min = col_min; 1347 x->mv_col_min = col_min;
1354 if (x->mv_col_max > col_max ) 1348 if (x->mv_col_max > col_max )
1355 x->mv_col_max = col_max; 1349 x->mv_col_max = col_max;
1356 if (x->mv_row_min < row_min ) 1350 if (x->mv_row_min < row_min )
1357 x->mv_row_min = row_min; 1351 x->mv_row_min = row_min;
1358 if (x->mv_row_max > row_max ) 1352 if (x->mv_row_max > row_max )
1359 x->mv_row_max = row_max; 1353 x->mv_row_max = row_max;
1360 1354
1361 /* Get 8x8 result */ 1355 /* Get 8x8 result */
1362 bsi.sv_mvp[0] = bsi.mvs[0].as_mv; 1356 bsi.sv_mvp[0].as_int = bsi.mvs[0].as_int;
1363 bsi.sv_mvp[1] = bsi.mvs[2].as_mv; 1357 bsi.sv_mvp[1].as_int = bsi.mvs[2].as_int;
1364 bsi.sv_mvp[2] = bsi.mvs[8].as_mv; 1358 bsi.sv_mvp[2].as_int = bsi.mvs[8].as_int;
1365 bsi.sv_mvp[3] = bsi.mvs[10].as_mv; 1359 bsi.sv_mvp[3].as_int = bsi.mvs[10].as_int;
1366 1360
1367 /* Use 8x8 result as 16x8/8x16's predictor MV. Adjust search range a ccording to the closeness of 2 MV. */ 1361 /* Use 8x8 result as 16x8/8x16's predictor MV. Adjust search range a ccording to the closeness of 2 MV. */
1368 /* block 8X16 */ 1362 /* block 8X16 */
1369 { 1363 {
1370 sr = MAXF((abs(bsi.sv_mvp[0].row - bsi.sv_mvp[2].row))>>3, (abs( bsi.sv_mvp[0].col - bsi.sv_mvp[2].col))>>3); 1364 sr = MAXF((abs(bsi.sv_mvp[0].as_mv.row - bsi.sv_mvp[2].as_mv.row ))>>3, (abs(bsi.sv_mvp[0].as_mv.col - bsi.sv_mvp[2].as_mv.col))>>3);
1371 vp8_cal_step_param(sr, &bsi.sv_istep[0]); 1365 vp8_cal_step_param(sr, &bsi.sv_istep[0]);
1372 1366
1373 sr = MAXF((abs(bsi.sv_mvp[1].row - bsi.sv_mvp[3].row))>>3, (abs( bsi.sv_mvp[1].col - bsi.sv_mvp[3].col))>>3); 1367 sr = MAXF((abs(bsi.sv_mvp[1].as_mv.row - bsi.sv_mvp[3].as_mv.row ))>>3, (abs(bsi.sv_mvp[1].as_mv.col - bsi.sv_mvp[3].as_mv.col))>>3);
1374 vp8_cal_step_param(sr, &bsi.sv_istep[1]); 1368 vp8_cal_step_param(sr, &bsi.sv_istep[1]);
1375 1369
1376 rd_check_segment(cpi, x, &bsi, BLOCK_8X16); 1370 rd_check_segment(cpi, x, &bsi, BLOCK_8X16);
1377 } 1371 }
1378 1372
1379 /* block 16X8 */ 1373 /* block 16X8 */
1380 { 1374 {
1381 sr = MAXF((abs(bsi.sv_mvp[0].row - bsi.sv_mvp[1].row))>>3, (abs( bsi.sv_mvp[0].col - bsi.sv_mvp[1].col))>>3); 1375 sr = MAXF((abs(bsi.sv_mvp[0].as_mv.row - bsi.sv_mvp[1].as_mv.row ))>>3, (abs(bsi.sv_mvp[0].as_mv.col - bsi.sv_mvp[1].as_mv.col))>>3);
1382 vp8_cal_step_param(sr, &bsi.sv_istep[0]); 1376 vp8_cal_step_param(sr, &bsi.sv_istep[0]);
1383 1377
1384 sr = MAXF((abs(bsi.sv_mvp[2].row - bsi.sv_mvp[3].row))>>3, (abs( bsi.sv_mvp[2].col - bsi.sv_mvp[3].col))>>3); 1378 sr = MAXF((abs(bsi.sv_mvp[2].as_mv.row - bsi.sv_mvp[3].as_mv.row ))>>3, (abs(bsi.sv_mvp[2].as_mv.col - bsi.sv_mvp[3].as_mv.col))>>3);
1385 vp8_cal_step_param(sr, &bsi.sv_istep[1]); 1379 vp8_cal_step_param(sr, &bsi.sv_istep[1]);
1386 1380
1387 rd_check_segment(cpi, x, &bsi, BLOCK_16X8); 1381 rd_check_segment(cpi, x, &bsi, BLOCK_16X8);
1388 } 1382 }
1389 1383
1390 /* If 8x8 is better than 16x8/8x16, then do 4x4 search */ 1384 /* If 8x8 is better than 16x8/8x16, then do 4x4 search */
1391 /* Not skip 4x4 if speed=0 (good quality) */ 1385 /* Not skip 4x4 if speed=0 (good quality) */
1392 if (cpi->sf.no_skip_block4x4_search || bsi.segment_num == BLOCK_8X8) /* || (sv_segment_rd8x8-bsi.segment_rd) < sv_segment_rd8x8>>5) */ 1386 if (cpi->sf.no_skip_block4x4_search || bsi.segment_num == BLOCK_8X8) /* || (sv_segment_rd8x8-bsi.segment_rd) < sv_segment_rd8x8>>5) */
1393 { 1387 {
1394 bsi.mvp = &bsi.sv_mvp[0]; 1388 bsi.mvp.as_int = bsi.sv_mvp[0].as_int;
1395 rd_check_segment(cpi, x, &bsi, BLOCK_4X4); 1389 rd_check_segment(cpi, x, &bsi, BLOCK_4X4);
1396 } 1390 }
1397 1391
1398 /* restore UMV window */ 1392 /* restore UMV window */
1399 x->mv_col_min = tmp_col_min; 1393 x->mv_col_min = tmp_col_min;
1400 x->mv_col_max = tmp_col_max; 1394 x->mv_col_max = tmp_col_max;
1401 x->mv_row_min = tmp_row_min; 1395 x->mv_row_min = tmp_row_min;
1402 x->mv_row_max = tmp_row_max; 1396 x->mv_row_max = tmp_row_max;
1403 } 1397 }
1404 } 1398 }
1405 1399
1406 /* set it to the best */ 1400 /* set it to the best */
1407 for (i = 0; i < 16; i++) 1401 for (i = 0; i < 16; i++)
1408 { 1402 {
1409 BLOCKD *bd = &x->e_mbd.block[i]; 1403 BLOCKD *bd = &x->e_mbd.block[i];
1410 1404
1411 bd->bmi.mv.as_mv = bsi.mvs[i].as_mv; 1405 bd->bmi.mv.as_int = bsi.mvs[i].as_int;
1412 bd->bmi.mode = bsi.modes[i];
1413 bd->eob = bsi.eobs[i]; 1406 bd->eob = bsi.eobs[i];
1414 } 1407 }
1415 1408
1416 *returntotrate = bsi.r; 1409 *returntotrate = bsi.r;
1417 *returndistortion = bsi.d; 1410 *returndistortion = bsi.d;
1418 *returnyrate = bsi.segment_yrate; 1411 *returnyrate = bsi.segment_yrate;
1419 1412
1420 /* save partitions */ 1413 /* save partitions */
1421 x->e_mbd.mode_info_context->mbmi.partitioning = bsi.segment_num; 1414 x->e_mbd.mode_info_context->mbmi.partitioning = bsi.segment_num;
1422 x->partition_info->count = vp8_mbsplit_count[bsi.segment_num]; 1415 x->partition_info->count = vp8_mbsplit_count[bsi.segment_num];
1423 1416
1424 for (i = 0; i < x->partition_info->count; i++) 1417 for (i = 0; i < x->partition_info->count; i++)
1425 { 1418 {
1426 int j; 1419 int j;
1427 1420
1428 j = vp8_mbsplit_offset[bsi.segment_num][i]; 1421 j = vp8_mbsplit_offset[bsi.segment_num][i];
1429 1422
1430 x->partition_info->bmi[i].mode = x->e_mbd.block[j].bmi.mode; 1423 x->partition_info->bmi[i].mode = bsi.modes[j];
1431 x->partition_info->bmi[i].mv.as_mv = x->e_mbd.block[j].bmi.mv.as_mv; 1424 x->partition_info->bmi[i].mv.as_mv = bsi.mvs[j].as_mv;
1432 } 1425 }
1426 /*
1427 * used to set x->e_mbd.mode_info_context->mbmi.mv.as_int
1428 */
1429 x->partition_info->bmi[15].mv.as_int = bsi.mvs[15].as_int;
1433 1430
1434 return bsi.segment_rd; 1431 return bsi.segment_rd;
1435 } 1432 }
1436 #endif
1437 1433
1438 static void swap(int *x,int *y) 1434 static void insertsortmv(int arr[], int len)
1439 { 1435 {
1440 int tmp; 1436 int i, j, k;
1441 1437
1442 tmp = *x; 1438 for ( i = 1 ; i <= len-1 ; i++ )
1443 *x = *y; 1439 {
1444 *y = tmp; 1440 for ( j = 0 ; j < i ; j++ )
1441 {
1442 if ( arr[j] > arr[i] )
1443 {
1444 int temp;
1445
1446 temp = arr[i];
1447
1448 for ( k = i; k >j; k--)
1449 arr[k] = arr[k - 1] ;
1450
1451 arr[j] = temp ;
1452 }
1453 }
1454 }
1445 } 1455 }
1446 1456
1447 static void quicksortmv(int arr[],int left, int right) 1457 static void insertsortsad(int arr[],int idx[], int len)
1448 { 1458 {
1449 int lidx,ridx,pivot; 1459 int i, j, k;
1450 1460
1451 lidx = left; 1461 for ( i = 1 ; i <= len-1 ; i++ )
1452 ridx = right; 1462 {
1463 for ( j = 0 ; j < i ; j++ )
1464 {
1465 if ( arr[j] > arr[i] )
1466 {
1467 int temp, tempi;
1453 1468
1454 if( left < right) 1469 temp = arr[i];
1455 { 1470 tempi = idx[i];
1456 pivot = (left + right)/2;
1457 1471
1458 while(lidx <=pivot && ridx >=pivot) 1472 for ( k = i; k >j; k--)
1459 { 1473 {
1460 while(arr[lidx] < arr[pivot] && lidx <= pivot) 1474 arr[k] = arr[k - 1] ;
1461 lidx++; 1475 idx[k] = idx[k - 1];
1462 while(arr[ridx] > arr[pivot] && ridx >= pivot) 1476 }
1463 ridx--;
1464 swap(&arr[lidx], &arr[ridx]);
1465 lidx++;
1466 ridx--;
1467 if(lidx-1 == pivot)
1468 {
1469 ridx++;
1470 pivot = ridx;
1471 }
1472 else if(ridx+1 == pivot)
1473 {
1474 lidx--;
1475 pivot = lidx;
1476 }
1477 }
1478 quicksortmv(arr, left, pivot - 1);
1479 quicksortmv(arr, pivot + 1, right);
1480 }
1481 }
1482 1477
1483 static void quicksortsad(int arr[],int idx[], int left, int right) 1478 arr[j] = temp ;
1484 { 1479 idx[j] = tempi;
1485 int lidx,ridx,pivot; 1480 }
1486 1481 }
1487 lidx = left; 1482 }
1488 ridx = right;
1489
1490 if( left < right)
1491 {
1492 pivot = (left + right)/2;
1493
1494 while(lidx <=pivot && ridx >=pivot)
1495 {
1496 while(arr[lidx] < arr[pivot] && lidx <= pivot)
1497 lidx++;
1498 while(arr[ridx] > arr[pivot] && ridx >= pivot)
1499 ridx--;
1500 swap(&arr[lidx], &arr[ridx]);
1501 swap(&idx[lidx], &idx[ridx]);
1502 lidx++;
1503 ridx--;
1504 if(lidx-1 == pivot)
1505 {
1506 ridx++;
1507 pivot = ridx;
1508 }
1509 else if(ridx+1 == pivot)
1510 {
1511 lidx--;
1512 pivot = lidx;
1513 }
1514 }
1515 quicksortsad(arr, idx, left, pivot - 1);
1516 quicksortsad(arr, idx, pivot + 1, right);
1517 }
1518 } 1483 }
1519 1484
1520 //The improved MV prediction 1485 //The improved MV prediction
1521 void vp8_mv_pred 1486 void vp8_mv_pred
1522 ( 1487 (
1523 VP8_COMP *cpi, 1488 VP8_COMP *cpi,
1524 MACROBLOCKD *xd, 1489 MACROBLOCKD *xd,
1525 const MODE_INFO *here, 1490 const MODE_INFO *here,
1526 MV *mvp, 1491 int_mv *mvp,
1527 int refframe, 1492 int refframe,
1528 int *ref_frame_sign_bias, 1493 int *ref_frame_sign_bias,
1529 int *sr, 1494 int *sr,
1530 int near_sadidx[] 1495 int near_sadidx[]
1531 ) 1496 )
1532 { 1497 {
1533 const MODE_INFO *above = here - xd->mode_info_stride; 1498 const MODE_INFO *above = here - xd->mode_info_stride;
1534 const MODE_INFO *left = here - 1; 1499 const MODE_INFO *left = here - 1;
1535 const MODE_INFO *aboveleft = above - 1; 1500 const MODE_INFO *aboveleft = above - 1;
1536 int_mv near_mvs[8]; 1501 int_mv near_mvs[8];
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 } 1608 }
1644 1609
1645 if(!find) 1610 if(!find)
1646 { 1611 {
1647 for(i=0; i<vcnt; i++) 1612 for(i=0; i<vcnt; i++)
1648 { 1613 {
1649 mvx[i] = near_mvs[i].as_mv.row; 1614 mvx[i] = near_mvs[i].as_mv.row;
1650 mvy[i] = near_mvs[i].as_mv.col; 1615 mvy[i] = near_mvs[i].as_mv.col;
1651 } 1616 }
1652 1617
1653 quicksortmv (mvx, 0, vcnt-1); 1618 insertsortmv(mvx, vcnt);
1654 quicksortmv (mvy, 0, vcnt-1); 1619 insertsortmv(mvy, vcnt);
1655 mv.as_mv.row = mvx[vcnt/2]; 1620 mv.as_mv.row = mvx[vcnt/2];
1656 mv.as_mv.col = mvy[vcnt/2]; 1621 mv.as_mv.col = mvy[vcnt/2];
1657 1622
1658 find = 1; 1623 find = 1;
1659 //sr is set to 0 to allow calling function to decide the search rang e. 1624 //sr is set to 0 to allow calling function to decide the search rang e.
1660 *sr = 0; 1625 *sr = 0;
1661 } 1626 }
1662 } 1627 }
1663 1628
1664 /* Set up return values */ 1629 /* Set up return values */
1665 *mvp = mv.as_mv; 1630 mvp->as_int = mv.as_int;
1666 vp8_clamp_mv(mvp, xd); 1631 vp8_clamp_mv2(mvp, xd);
1667 } 1632 }
1668 1633
1669 void vp8_cal_sad(VP8_COMP *cpi, MACROBLOCKD *xd, MACROBLOCK *x, int recon_yoffse t, int near_sadidx[]) 1634 void vp8_cal_sad(VP8_COMP *cpi, MACROBLOCKD *xd, MACROBLOCK *x, int recon_yoffse t, int near_sadidx[])
1670 { 1635 {
1671 1636
1672 int near_sad[8] = {0}; // 0-cf above, 1-cf left, 2-cf aboveleft, 3-lf curren t, 4-lf above, 5-lf left, 6-lf right, 7-lf below 1637 int near_sad[8] = {0}; // 0-cf above, 1-cf left, 2-cf aboveleft, 3-lf curren t, 4-lf above, 5-lf left, 6-lf right, 7-lf below
1638 BLOCK *b = &x->block[0];
1639 unsigned char *src_y_ptr = *(b->base_src);
1673 1640
1674 //calculate sad for current frame 3 nearby MBs. 1641 //calculate sad for current frame 3 nearby MBs.
1675 if( xd->mb_to_top_edge==0 && xd->mb_to_left_edge ==0) 1642 if( xd->mb_to_top_edge==0 && xd->mb_to_left_edge ==0)
1676 { 1643 {
1677 near_sad[0] = near_sad[1] = near_sad[2] = INT_MAX; 1644 near_sad[0] = near_sad[1] = near_sad[2] = INT_MAX;
1678 }else if(xd->mb_to_top_edge==0) 1645 }else if(xd->mb_to_top_edge==0)
1679 { //only has left MB for sad calculation. 1646 { //only has left MB for sad calculation.
1680 near_sad[0] = near_sad[2] = INT_MAX; 1647 near_sad[0] = near_sad[2] = INT_MAX;
1681 near_sad[1] = cpi->fn_ptr[BLOCK_16X16].sdf(x->src.y_buffer, x->src.y_str ide, xd->dst.y_buffer - 16,xd->dst.y_stride, 0x7fffffff); 1648 near_sad[1] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, xd- >dst.y_buffer - 16,xd->dst.y_stride, 0x7fffffff);
1682 }else if(xd->mb_to_left_edge ==0) 1649 }else if(xd->mb_to_left_edge ==0)
1683 { //only has left MB for sad calculation. 1650 { //only has left MB for sad calculation.
1684 near_sad[1] = near_sad[2] = INT_MAX; 1651 near_sad[1] = near_sad[2] = INT_MAX;
1685 near_sad[0] = cpi->fn_ptr[BLOCK_16X16].sdf(x->src.y_buffer, x->src.y_str ide, xd->dst.y_buffer - xd->dst.y_stride *16,xd->dst.y_stride, 0x7fffffff); 1652 near_sad[0] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, xd- >dst.y_buffer - xd->dst.y_stride *16,xd->dst.y_stride, 0x7fffffff);
1686 }else 1653 }else
1687 { 1654 {
1688 near_sad[0] = cpi->fn_ptr[BLOCK_16X16].sdf(x->src.y_buffer, x->src.y_str ide, xd->dst.y_buffer - xd->dst.y_stride *16,xd->dst.y_stride, 0x7fffffff); 1655 near_sad[0] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, xd- >dst.y_buffer - xd->dst.y_stride *16,xd->dst.y_stride, 0x7fffffff);
1689 near_sad[1] = cpi->fn_ptr[BLOCK_16X16].sdf(x->src.y_buffer, x->src.y_str ide, xd->dst.y_buffer - 16,xd->dst.y_stride, 0x7fffffff); 1656 near_sad[1] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, xd- >dst.y_buffer - 16,xd->dst.y_stride, 0x7fffffff);
1690 near_sad[2] = cpi->fn_ptr[BLOCK_16X16].sdf(x->src.y_buffer, x->src.y_str ide, xd->dst.y_buffer - xd->dst.y_stride *16 -16,xd->dst.y_stride, 0x7fffffff); 1657 near_sad[2] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, xd- >dst.y_buffer - xd->dst.y_stride *16 -16,xd->dst.y_stride, 0x7fffffff);
1691 } 1658 }
1692 1659
1693 if(cpi->common.last_frame_type != KEY_FRAME) 1660 if(cpi->common.last_frame_type != KEY_FRAME)
1694 { 1661 {
1695 //calculate sad for last frame 5 nearby MBs. 1662 //calculate sad for last frame 5 nearby MBs.
1696 unsigned char *pre_y_buffer = cpi->common.yv12_fb[cpi->common.lst_fb_idx ].y_buffer + recon_yoffset; 1663 unsigned char *pre_y_buffer = cpi->common.yv12_fb[cpi->common.lst_fb_idx ].y_buffer + recon_yoffset;
1697 int pre_y_stride = cpi->common.yv12_fb[cpi->common.lst_fb_idx].y_stride; 1664 int pre_y_stride = cpi->common.yv12_fb[cpi->common.lst_fb_idx].y_stride;
1698 1665
1699 if(xd->mb_to_top_edge==0) near_sad[4] = INT_MAX; 1666 if(xd->mb_to_top_edge==0) near_sad[4] = INT_MAX;
1700 if(xd->mb_to_left_edge ==0) near_sad[5] = INT_MAX; 1667 if(xd->mb_to_left_edge ==0) near_sad[5] = INT_MAX;
1701 if(xd->mb_to_right_edge ==0) near_sad[6] = INT_MAX; 1668 if(xd->mb_to_right_edge ==0) near_sad[6] = INT_MAX;
1702 if(xd->mb_to_bottom_edge==0) near_sad[7] = INT_MAX; 1669 if(xd->mb_to_bottom_edge==0) near_sad[7] = INT_MAX;
1703 1670
1704 if(near_sad[4] != INT_MAX) 1671 if(near_sad[4] != INT_MAX)
1705 near_sad[4] = cpi->fn_ptr[BLOCK_16X16].sdf(x->src.y_buffer, x->src.y _stride, pre_y_buffer - pre_y_stride *16, pre_y_stride, 0x7fffffff); 1672 near_sad[4] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, pre_y_buffer - pre_y_stride *16, pre_y_stride, 0x7fffffff);
1706 if(near_sad[5] != INT_MAX) 1673 if(near_sad[5] != INT_MAX)
1707 near_sad[5] = cpi->fn_ptr[BLOCK_16X16].sdf(x->src.y_buffer, x->src.y _stride, pre_y_buffer - 16, pre_y_stride, 0x7fffffff); 1674 near_sad[5] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, pre_y_buffer - 16, pre_y_stride, 0x7fffffff);
1708 near_sad[3] = cpi->fn_ptr[BLOCK_16X16].sdf(x->src.y_buffer, x->src.y_str ide, pre_y_buffer, pre_y_stride, 0x7fffffff); 1675 near_sad[3] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, pre _y_buffer, pre_y_stride, 0x7fffffff);
1709 if(near_sad[6] != INT_MAX) 1676 if(near_sad[6] != INT_MAX)
1710 near_sad[6] = cpi->fn_ptr[BLOCK_16X16].sdf(x->src.y_buffer, x->src.y _stride, pre_y_buffer + 16, pre_y_stride, 0x7fffffff); 1677 near_sad[6] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, pre_y_buffer + 16, pre_y_stride, 0x7fffffff);
1711 if(near_sad[7] != INT_MAX) 1678 if(near_sad[7] != INT_MAX)
1712 near_sad[7] = cpi->fn_ptr[BLOCK_16X16].sdf(x->src.y_buffer, x->src.y _stride, pre_y_buffer + pre_y_stride *16, pre_y_stride, 0x7fffffff); 1679 near_sad[7] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, pre_y_buffer + pre_y_stride *16, pre_y_stride, 0x7fffffff);
1713 } 1680 }
1714 1681
1715 if(cpi->common.last_frame_type != KEY_FRAME) 1682 if(cpi->common.last_frame_type != KEY_FRAME)
1716 { 1683 {
1717 quicksortsad(near_sad, near_sadidx, 0, 7); 1684 insertsortsad(near_sad, near_sadidx, 8);
1718 }else 1685 }else
1719 { 1686 {
1720 quicksortsad(near_sad, near_sadidx, 0, 2); 1687 insertsortsad(near_sad, near_sadidx, 3);
1721 } 1688 }
1722 } 1689 }
1723 1690
1724 #if !(CONFIG_REALTIME_ONLY) 1691 static void rd_update_mvcount(VP8_COMP *cpi, MACROBLOCK *x, int_mv *best_ref_mv)
1725 int vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int recon_uvoffset, int *returnrate, int *returndistortion, int *returnintra) 1692 {
1693 if (x->e_mbd.mode_info_context->mbmi.mode == SPLITMV)
1694 {
1695 int i;
1696
1697 for (i = 0; i < x->partition_info->count; i++)
1698 {
1699 if (x->partition_info->bmi[i].mode == NEW4X4)
1700 {
1701 cpi->MVcount[0][mv_max+((x->partition_info->bmi[i].mv.as_mv.row
1702 - best_ref_mv->as_mv.row) >> 1)]++;
1703 cpi->MVcount[1][mv_max+((x->partition_info->bmi[i].mv.as_mv.col
1704 - best_ref_mv->as_mv.col) >> 1)]++;
1705 }
1706 }
1707 }
1708 else if (x->e_mbd.mode_info_context->mbmi.mode == NEWMV)
1709 {
1710 cpi->MVcount[0][mv_max+((x->e_mbd.mode_info_context->mbmi.mv.as_mv.row
1711 - best_ref_mv->as_mv.row) >> 1)]++;
1712 cpi->MVcount[1][mv_max+((x->e_mbd.mode_info_context->mbmi.mv.as_mv.col
1713 - best_ref_mv->as_mv.col) >> 1)]++;
1714 }
1715 }
1716
1717 void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int recon_uvoffset, int *returnrate, int *returndistortion, int *returnintra)
1726 { 1718 {
1727 BLOCK *b = &x->block[0]; 1719 BLOCK *b = &x->block[0];
1728 BLOCKD *d = &x->e_mbd.block[0]; 1720 BLOCKD *d = &x->e_mbd.block[0];
1729 MACROBLOCKD *xd = &x->e_mbd; 1721 MACROBLOCKD *xd = &x->e_mbd;
1730 B_MODE_INFO best_bmodes[16]; 1722 union b_mode_info best_bmodes[16];
1731 MB_MODE_INFO best_mbmode; 1723 MB_MODE_INFO best_mbmode;
1732 PARTITION_INFO best_partition; 1724 PARTITION_INFO best_partition;
1733 MV best_ref_mv; 1725 int_mv best_ref_mv;
1734 MV mode_mv[MB_MODE_COUNT]; 1726 int_mv mode_mv[MB_MODE_COUNT];
1735 MB_PREDICTION_MODE this_mode; 1727 MB_PREDICTION_MODE this_mode;
1736 int num00; 1728 int num00;
1737 int best_mode_index = 0; 1729 int best_mode_index = 0;
1738 1730
1739 int i; 1731 int i;
1740 int mode_index; 1732 int mode_index;
1741 int mdcounts[4]; 1733 int mdcounts[4];
1742 int rate; 1734 int rate;
1743 int distortion; 1735 int distortion;
1744 int best_rd = INT_MAX; // 1 << 30; 1736 int best_rd = INT_MAX;
1745 int ref_frame_cost[MAX_REF_FRAMES]; 1737 int best_intra_rd = INT_MAX;
1746 int rate2, distortion2; 1738 int rate2, distortion2;
1747 int uv_intra_rate, uv_intra_distortion, uv_intra_rate_tokenonly; 1739 int uv_intra_rate, uv_intra_distortion, uv_intra_rate_tokenonly;
1748 int rate_y, UNINITIALIZED_IS_SAFE(rate_uv); 1740 int rate_y, UNINITIALIZED_IS_SAFE(rate_uv);
1749 int distortion_uv; 1741 int distortion_uv;
1750 int best_yrd = INT_MAX; 1742 int best_yrd = INT_MAX;
1751 1743
1752 //int all_rds[MAX_MODES]; // Experimental debug code. 1744 //int all_rds[MAX_MODES]; // Experimental debug code.
1753 //int all_rates[MAX_MODES]; 1745 //int all_rates[MAX_MODES];
1754 //int all_dist[MAX_MODES]; 1746 //int all_dist[MAX_MODES];
1755 //int intermodecost[MAX_MODES]; 1747 //int intermodecost[MAX_MODES];
1756 1748
1757 MB_PREDICTION_MODE uv_intra_mode; 1749 MB_PREDICTION_MODE uv_intra_mode;
1758 1750 int_mv mvp;
1759 int force_no_skip = 0;
1760
1761 MV mvp;
1762 int near_sadidx[8] = {0, 1, 2, 3, 4, 5, 6, 7}; 1751 int near_sadidx[8] = {0, 1, 2, 3, 4, 5, 6, 7};
1763 int saddone=0; 1752 int saddone=0;
1764 int sr=0; //search range got from mv_pred(). It uses step_param levels. ( 0-7) 1753 int sr=0; //search range got from mv_pred(). It uses step_param levels. ( 0-7)
1765 1754
1766 MV frame_nearest_mv[4]; 1755 int_mv frame_nearest_mv[4];
1767 MV frame_near_mv[4]; 1756 int_mv frame_near_mv[4];
1768 MV frame_best_ref_mv[4]; 1757 int_mv frame_best_ref_mv[4];
1769 int frame_mdcounts[4][4]; 1758 int frame_mdcounts[4][4];
1770 int frame_lf_or_gf[4]; 1759 int frame_lf_or_gf[4];
1771 unsigned char *y_buffer[4]; 1760 unsigned char *y_buffer[4];
1772 unsigned char *u_buffer[4]; 1761 unsigned char *u_buffer[4];
1773 unsigned char *v_buffer[4]; 1762 unsigned char *v_buffer[4];
1774 1763
1775 vpx_memset(&best_mbmode, 0, sizeof(best_mbmode)); 1764 vpx_memset(&best_mbmode, 0, sizeof(best_mbmode));
1765 vpx_memset(&best_bmodes, 0, sizeof(best_bmodes));
1776 1766
1777 if (cpi->ref_frame_flags & VP8_LAST_FLAG) 1767 if (cpi->ref_frame_flags & VP8_LAST_FLAG)
1778 { 1768 {
1779 YV12_BUFFER_CONFIG *lst_yv12 = &cpi->common.yv12_fb[cpi->common.lst_fb_i dx]; 1769 YV12_BUFFER_CONFIG *lst_yv12 = &cpi->common.yv12_fb[cpi->common.lst_fb_i dx];
1780 1770
1781 vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context, &frame_nearest_ mv[LAST_FRAME], &frame_near_mv[LAST_FRAME], 1771 vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context, &frame_nearest_ mv[LAST_FRAME], &frame_near_mv[LAST_FRAME],
1782 &frame_best_ref_mv[LAST_FRAME], frame_mdcounts[LAST_FR AME], LAST_FRAME, cpi->common.ref_frame_sign_bias); 1772 &frame_best_ref_mv[LAST_FRAME], frame_mdcounts[LAST_FR AME], LAST_FRAME, cpi->common.ref_frame_sign_bias);
1783 1773
1784 y_buffer[LAST_FRAME] = lst_yv12->y_buffer + recon_yoffset; 1774 y_buffer[LAST_FRAME] = lst_yv12->y_buffer + recon_yoffset;
1785 u_buffer[LAST_FRAME] = lst_yv12->u_buffer + recon_uvoffset; 1775 u_buffer[LAST_FRAME] = lst_yv12->u_buffer + recon_uvoffset;
(...skipping 28 matching lines...) Expand all
1814 v_buffer[ALTREF_FRAME] = alt_yv12->v_buffer + recon_uvoffset; 1804 v_buffer[ALTREF_FRAME] = alt_yv12->v_buffer + recon_uvoffset;
1815 1805
1816 frame_lf_or_gf[ALTREF_FRAME] = 1; 1806 frame_lf_or_gf[ALTREF_FRAME] = 1;
1817 } 1807 }
1818 1808
1819 *returnintra = INT_MAX; 1809 *returnintra = INT_MAX;
1820 cpi->mbs_tested_so_far++; // Count of the number of MBs tested so f ar this frame 1810 cpi->mbs_tested_so_far++; // Count of the number of MBs tested so f ar this frame
1821 1811
1822 x->skip = 0; 1812 x->skip = 0;
1823 1813
1824 ref_frame_cost[INTRA_FRAME] = vp8_cost_zero(cpi->prob_intra_coded);
1825
1826 // Special case treatment when GF and ARF are not sensible options for refer ence
1827 if (cpi->ref_frame_flags == VP8_LAST_FLAG)
1828 {
1829 ref_frame_cost[LAST_FRAME] = vp8_cost_one(cpi->prob_intra_coded)
1830 + vp8_cost_zero(255);
1831 ref_frame_cost[GOLDEN_FRAME] = vp8_cost_one(cpi->prob_intra_coded)
1832 + vp8_cost_one(255)
1833 + vp8_cost_zero(128);
1834 ref_frame_cost[ALTREF_FRAME] = vp8_cost_one(cpi->prob_intra_coded)
1835 + vp8_cost_one(255)
1836 + vp8_cost_one(128);
1837 }
1838 else
1839 {
1840 ref_frame_cost[LAST_FRAME] = vp8_cost_one(cpi->prob_intra_coded)
1841 + vp8_cost_zero(cpi->prob_last_coded);
1842 ref_frame_cost[GOLDEN_FRAME] = vp8_cost_one(cpi->prob_intra_coded)
1843 + vp8_cost_one(cpi->prob_last_coded)
1844 + vp8_cost_zero(cpi->prob_gf_coded);
1845 ref_frame_cost[ALTREF_FRAME] = vp8_cost_one(cpi->prob_intra_coded)
1846 + vp8_cost_one(cpi->prob_last_coded)
1847 + vp8_cost_one(cpi->prob_gf_coded);
1848 }
1849
1850 vpx_memset(mode_mv, 0, sizeof(mode_mv)); 1814 vpx_memset(mode_mv, 0, sizeof(mode_mv));
1851 1815
1852 x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME; 1816 x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME;
1853 vp8_rd_pick_intra_mbuv_mode(cpi, x, &uv_intra_rate, &uv_intra_rate_tokenonly , &uv_intra_distortion); 1817 rd_pick_intra_mbuv_mode(cpi, x, &uv_intra_rate, &uv_intra_rate_tokenonly, &u v_intra_distortion);
1854 uv_intra_mode = x->e_mbd.mode_info_context->mbmi.uv_mode; 1818 uv_intra_mode = x->e_mbd.mode_info_context->mbmi.uv_mode;
1855 1819
1856 for (mode_index = 0; mode_index < MAX_MODES; mode_index++) 1820 for (mode_index = 0; mode_index < MAX_MODES; mode_index++)
1857 { 1821 {
1858 int this_rd = INT_MAX; 1822 int this_rd = INT_MAX;
1859 int lf_or_gf = 0; // Lat Frame (01) or gf/arf (1) 1823 int lf_or_gf = 0; // Lat Frame (01) or gf/arf (1)
1860 int disable_skip = 0; 1824 int disable_skip = 0;
1861 int other_cost = 0; 1825 int other_cost = 0;
1862 1826
1863 force_no_skip = 0;
1864
1865 // Experimental debug code. 1827 // Experimental debug code.
1866 // Record of rd values recorded for this MB. -1 indicates not measured 1828 // Record of rd values recorded for this MB. -1 indicates not measured
1867 //all_rds[mode_index] = -1; 1829 //all_rds[mode_index] = -1;
1868 //all_rates[mode_index] = -1; 1830 //all_rates[mode_index] = -1;
1869 //all_dist[mode_index] = -1; 1831 //all_dist[mode_index] = -1;
1870 //intermodecost[mode_index] = -1; 1832 //intermodecost[mode_index] = -1;
1871 1833
1872 // Test best rd so far against threshold for trying this mode. 1834 // Test best rd so far against threshold for trying this mode.
1873 if (best_rd <= cpi->rd_threshes[mode_index]) 1835 if (best_rd <= cpi->rd_threshes[mode_index])
1874 continue; 1836 continue;
(...skipping 23 matching lines...) Expand all
1898 x->e_mbd.pre.y_buffer = y_buffer[x->e_mbd.mode_info_context->mbmi.re f_frame]; 1860 x->e_mbd.pre.y_buffer = y_buffer[x->e_mbd.mode_info_context->mbmi.re f_frame];
1899 x->e_mbd.pre.u_buffer = u_buffer[x->e_mbd.mode_info_context->mbmi.re f_frame]; 1861 x->e_mbd.pre.u_buffer = u_buffer[x->e_mbd.mode_info_context->mbmi.re f_frame];
1900 x->e_mbd.pre.v_buffer = v_buffer[x->e_mbd.mode_info_context->mbmi.re f_frame]; 1862 x->e_mbd.pre.v_buffer = v_buffer[x->e_mbd.mode_info_context->mbmi.re f_frame];
1901 mode_mv[NEARESTMV] = frame_nearest_mv[x->e_mbd.mode_info_context->mb mi.ref_frame]; 1863 mode_mv[NEARESTMV] = frame_nearest_mv[x->e_mbd.mode_info_context->mb mi.ref_frame];
1902 mode_mv[NEARMV] = frame_near_mv[x->e_mbd.mode_info_context->mbmi.ref _frame]; 1864 mode_mv[NEARMV] = frame_near_mv[x->e_mbd.mode_info_context->mbmi.ref _frame];
1903 best_ref_mv = frame_best_ref_mv[x->e_mbd.mode_info_context->mbmi.ref _frame]; 1865 best_ref_mv = frame_best_ref_mv[x->e_mbd.mode_info_context->mbmi.ref _frame];
1904 vpx_memcpy(mdcounts, frame_mdcounts[x->e_mbd.mode_info_context->mbmi .ref_frame], sizeof(mdcounts)); 1866 vpx_memcpy(mdcounts, frame_mdcounts[x->e_mbd.mode_info_context->mbmi .ref_frame], sizeof(mdcounts));
1905 lf_or_gf = frame_lf_or_gf[x->e_mbd.mode_info_context->mbmi.ref_frame ]; 1867 lf_or_gf = frame_lf_or_gf[x->e_mbd.mode_info_context->mbmi.ref_frame ];
1906 } 1868 }
1907 1869
1908 if(x->e_mbd.mode_info_context->mbmi.mode == NEWMV)
1909 {
1910 if(!saddone)
1911 {
1912 vp8_cal_sad(cpi,xd,x, recon_yoffset ,&near_sadidx[0] );
1913 saddone = 1;
1914 }
1915
1916 vp8_mv_pred(cpi, &x->e_mbd, x->e_mbd.mode_info_context, &mvp,
1917 x->e_mbd.mode_info_context->mbmi.ref_frame, cpi->common. ref_frame_sign_bias, &sr, &near_sadidx[0]);
1918
1919 /* adjust mvp to make sure it is within MV range */
1920 if(mvp.row > best_ref_mv.row + MAX_FULL_PEL_VAL)
1921 mvp.row = best_ref_mv.row + MAX_FULL_PEL_VAL;
1922 else if(mvp.row < best_ref_mv.row - MAX_FULL_PEL_VAL)
1923 mvp.row = best_ref_mv.row - MAX_FULL_PEL_VAL;
1924 if(mvp.col > best_ref_mv.col + MAX_FULL_PEL_VAL)
1925 mvp.col = best_ref_mv.col + MAX_FULL_PEL_VAL;
1926 else if(mvp.col < best_ref_mv.col - MAX_FULL_PEL_VAL)
1927 mvp.col = best_ref_mv.col - MAX_FULL_PEL_VAL;
1928 }
1929
1930 // Check to see if the testing frequency for this mode is at its max 1870 // Check to see if the testing frequency for this mode is at its max
1931 // If so then prevent it from being tested and increase the threshold fo r its testing 1871 // If so then prevent it from being tested and increase the threshold fo r its testing
1932 if (cpi->mode_test_hit_counts[mode_index] && (cpi->mode_check_freq[mode_ index] > 1)) 1872 if (cpi->mode_test_hit_counts[mode_index] && (cpi->mode_check_freq[mode_ index] > 1))
1933 { 1873 {
1934 if (cpi->mbs_tested_so_far <= cpi->mode_check_freq[mode_index] * cp i->mode_test_hit_counts[mode_index]) 1874 if (cpi->mbs_tested_so_far <= cpi->mode_check_freq[mode_index] * cp i->mode_test_hit_counts[mode_index])
1935 { 1875 {
1936 // Increase the threshold for coding this mode to make it less l ikely to be chosen 1876 // Increase the threshold for coding this mode to make it less l ikely to be chosen
1937 cpi->rd_thresh_mult[mode_index] += 4; 1877 cpi->rd_thresh_mult[mode_index] += 4;
1938 1878
1939 if (cpi->rd_thresh_mult[mode_index] > MAX_THRESHMULT) 1879 if (cpi->rd_thresh_mult[mode_index] > MAX_THRESHMULT)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1971 vp8_update_zbin_extra(cpi, x); 1911 vp8_update_zbin_extra(cpi, x);
1972 } 1912 }
1973 1913
1974 switch (this_mode) 1914 switch (this_mode)
1975 { 1915 {
1976 case B_PRED: 1916 case B_PRED:
1977 { 1917 {
1978 int tmp_rd; 1918 int tmp_rd;
1979 1919
1980 // Note the rate value returned here includes the cost of coding the BPRED mode : x->mbmode_cost[x->e_mbd.frame_type][BPRED]; 1920 // Note the rate value returned here includes the cost of coding the BPRED mode : x->mbmode_cost[x->e_mbd.frame_type][BPRED];
1981 tmp_rd = vp8_rd_pick_intra4x4mby_modes(cpi, x, &rate, &rate_y, &dist ortion, best_yrd); 1921 tmp_rd = rd_pick_intra4x4mby_modes(cpi, x, &rate, &rate_y, &distorti on, best_yrd);
1982 rate2 += rate; 1922 rate2 += rate;
1983 distortion2 += distortion; 1923 distortion2 += distortion;
1984 1924
1985 if(tmp_rd < best_yrd) 1925 if(tmp_rd < best_yrd)
1986 { 1926 {
1987 rate2 += uv_intra_rate; 1927 rate2 += uv_intra_rate;
1988 rate_uv = uv_intra_rate_tokenonly; 1928 rate_uv = uv_intra_rate_tokenonly;
1989 distortion2 += uv_intra_distortion; 1929 distortion2 += uv_intra_distortion;
1990 distortion_uv = uv_intra_distortion; 1930 distortion_uv = uv_intra_distortion;
1991 } 1931 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2038 rate2 += rate_y; 1978 rate2 += rate_y;
2039 distortion2 += distortion; 1979 distortion2 += distortion;
2040 rate2 += x->mbmode_cost[x->e_mbd.frame_type][x->e_mbd.mode_info_cont ext->mbmi.mode]; 1980 rate2 += x->mbmode_cost[x->e_mbd.frame_type][x->e_mbd.mode_info_cont ext->mbmi.mode];
2041 rate2 += uv_intra_rate; 1981 rate2 += uv_intra_rate;
2042 rate_uv = uv_intra_rate_tokenonly; 1982 rate_uv = uv_intra_rate_tokenonly;
2043 distortion2 += uv_intra_distortion; 1983 distortion2 += uv_intra_distortion;
2044 distortion_uv = uv_intra_distortion; 1984 distortion_uv = uv_intra_distortion;
2045 break; 1985 break;
2046 1986
2047 case NEWMV: 1987 case NEWMV:
1988 {
1989 int thissme;
1990 int bestsme = INT_MAX;
1991 int step_param = cpi->sf.first_step;
1992 int further_steps;
1993 int n;
1994 int do_refine=1; /* If last step (1-away) of n-step search doesn't pick the center point as the best match,
1995 we will do a final 1-away diamond refining sea rch */
2048 1996
2049 // Decrement full search counter 1997 int sadpb = x->sadperbit16;
2050 if (cpi->check_freq[lf_or_gf] > 0) 1998 int_mv mvp_full;
2051 cpi->check_freq[lf_or_gf] --;
2052 1999
2000 int col_min = (best_ref_mv.as_mv.col>>3) - MAX_FULL_PEL_VAL + ((best _ref_mv.as_mv.col & 7)?1:0);
2001 int row_min = (best_ref_mv.as_mv.row>>3) - MAX_FULL_PEL_VAL + ((best _ref_mv.as_mv.row & 7)?1:0);
2002 int col_max = (best_ref_mv.as_mv.col>>3) + MAX_FULL_PEL_VAL;
2003 int row_max = (best_ref_mv.as_mv.row>>3) + MAX_FULL_PEL_VAL;
2004
2005 int tmp_col_min = x->mv_col_min;
2006 int tmp_col_max = x->mv_col_max;
2007 int tmp_row_min = x->mv_row_min;
2008 int tmp_row_max = x->mv_row_max;
2009
2010 if(!saddone)
2053 { 2011 {
2054 int thissme; 2012 vp8_cal_sad(cpi,xd,x, recon_yoffset ,&near_sadidx[0] );
2055 int bestsme = INT_MAX; 2013 saddone = 1;
2056 int step_param = cpi->sf.first_step; 2014 }
2057 int search_range;
2058 int further_steps;
2059 int n;
2060 2015
2061 int col_min = (best_ref_mv.col - MAX_FULL_PEL_VAL) >>3; 2016 vp8_mv_pred(cpi, &x->e_mbd, x->e_mbd.mode_info_context, &mvp,
2062 int col_max = (best_ref_mv.col + MAX_FULL_PEL_VAL) >>3; 2017 x->e_mbd.mode_info_context->mbmi.ref_frame, cpi->common. ref_frame_sign_bias, &sr, &near_sadidx[0]);
2063 int row_min = (best_ref_mv.row - MAX_FULL_PEL_VAL) >>3;
2064 int row_max = (best_ref_mv.row + MAX_FULL_PEL_VAL) >>3;
2065 2018
2066 int tmp_col_min = x->mv_col_min; 2019 mvp_full.as_mv.col = mvp.as_mv.col>>3;
2067 int tmp_col_max = x->mv_col_max; 2020 mvp_full.as_mv.row = mvp.as_mv.row>>3;
2068 int tmp_row_min = x->mv_row_min;
2069 int tmp_row_max = x->mv_row_max;
2070 2021
2071 // Get intersection of UMV window and valid MV window to reduce # of checks in diamond search. 2022 // Get intersection of UMV window and valid MV window to reduce # of checks in diamond search.
2072 if (x->mv_col_min < col_min ) 2023 if (x->mv_col_min < col_min )
2073 x->mv_col_min = col_min; 2024 x->mv_col_min = col_min;
2074 if (x->mv_col_max > col_max ) 2025 if (x->mv_col_max > col_max )
2075 x->mv_col_max = col_max; 2026 x->mv_col_max = col_max;
2076 if (x->mv_row_min < row_min ) 2027 if (x->mv_row_min < row_min )
2077 x->mv_row_min = row_min; 2028 x->mv_row_min = row_min;
2078 if (x->mv_row_max > row_max ) 2029 if (x->mv_row_max > row_max )
2079 x->mv_row_max = row_max; 2030 x->mv_row_max = row_max;
2080 2031
2081 //adjust search range according to sr from mv prediction 2032 //adjust search range according to sr from mv prediction
2082 if(sr > step_param) 2033 if(sr > step_param)
2083 step_param = sr; 2034 step_param = sr;
2084 2035
2085 // Work out how long a search we should do 2036 // Initial step/diamond search
2086 search_range = MAXF(abs(best_ref_mv.col), abs(best_ref_mv.row)) >> 3; 2037 {
2038 bestsme = cpi->diamond_search_sad(x, b, d, &mvp_full, &d->bmi.mv ,
2039 step_param, sadpb, &num00,
2040 &cpi->fn_ptr[BLOCK_16X16],
2041 x->mvcost, &best_ref_mv);
2042 mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
2087 2043
2088 if (search_range >= x->vector_range) 2044 // Further step/diamond searches as necessary
2089 x->vector_range = search_range; 2045 n = 0;
2090 else if (x->vector_range > cpi->sf.min_fs_radius) 2046 further_steps = (cpi->sf.max_step_search_steps - 1) - step_param ;
2091 x->vector_range--;
2092 2047
2093 // Initial step/diamond search 2048 n = num00;
2049 num00 = 0;
2050
2051 /* If there won't be more n-step search, check to see if refinin g search is needed. */
2052 if (n > further_steps)
2053 do_refine = 0;
2054
2055 while (n < further_steps)
2094 { 2056 {
2095 int sadpb = x->sadperbit16; 2057 n++;
2096 2058
2097 if (cpi->sf.search_method == HEX) 2059 if (num00)
2098 { 2060 num00--;
2099 bestsme = vp8_hex_search(x, b, d, &best_ref_mv, &d->bmi. mv.as_mv, step_param, sadpb/*x->errorperbit*/, &num00, &cpi->fn_ptr[BLOCK_16X16] , x->mvsadcost, x->mvcost, &best_ref_mv);
2100 mode_mv[NEWMV].row = d->bmi.mv.as_mv.row;
2101 mode_mv[NEWMV].col = d->bmi.mv.as_mv.col;
2102 }
2103 else 2061 else
2104 { 2062 {
2105 bestsme = cpi->diamond_search_sad(x, b, d, &mvp, &d->bmi .mv.as_mv, step_param, sadpb / 2/*x->errorperbit*/, &num00, &cpi->fn_ptr[BLOCK_1 6X16], x->mvsadcost, x->mvcost, &best_ref_mv); //sadpb < 9 2063 thissme = cpi->diamond_search_sad(x, b, d, &mvp_full,
2106 mode_mv[NEWMV].row = d->bmi.mv.as_mv.row; 2064 &d->bmi.mv, step_param + n, sadpb, &num00,
2107 mode_mv[NEWMV].col = d->bmi.mv.as_mv.col; 2065 &cpi->fn_ptr[BLOCK_16X16], x->mvcost,
2066 &best_ref_mv);
2108 2067
2109 // Further step/diamond searches as necessary 2068 /* check to see if refining search is needed. */
2110 n = 0; 2069 if (num00 > (further_steps-n))
2111 further_steps = (cpi->sf.max_step_search_steps - 1) - st ep_param; 2070 do_refine = 0;
2112 2071
2113 n = num00; 2072 if (thissme < bestsme)
2114 num00 = 0;
2115
2116 while (n < further_steps)
2117 { 2073 {
2118 n++; 2074 bestsme = thissme;
2119 2075 mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
2120 if (num00) 2076 }
2121 num00--; 2077 else
2122 else 2078 {
2123 { 2079 d->bmi.mv.as_int = mode_mv[NEWMV].as_int;
2124 thissme = cpi->diamond_search_sad(x, b, d, &mvp, &d->bmi.mv.as_mv, step_param + n, sadpb / 4/*x->errorperbit*/, &num00, &cpi->fn _ptr[BLOCK_16X16], x->mvsadcost, x->mvcost, &best_ref_mv); //sadpb = 9
2125
2126 if (thissme < bestsme)
2127 {
2128 bestsme = thissme;
2129 mode_mv[NEWMV].row = d->bmi.mv.as_mv.row;
2130 mode_mv[NEWMV].col = d->bmi.mv.as_mv.col;
2131 }
2132 else
2133 {
2134 d->bmi.mv.as_mv.row = mode_mv[NEWMV].row;
2135 d->bmi.mv.as_mv.col = mode_mv[NEWMV].col;
2136 }
2137 }
2138 } 2080 }
2139 } 2081 }
2082 }
2083 }
2140 2084
2085 /* final 1-away diamond refining search */
2086 if (do_refine == 1)
2087 {
2088 int search_range;
2089
2090 //It seems not a good way to set search_range. Need further inve stigation.
2091 //search_range = MAXF(abs((mvp.row>>3) - d->bmi.mv.as_mv.row), a bs((mvp.col>>3) - d->bmi.mv.as_mv.col));
2092 search_range = 8;
2093
2094 //thissme = cpi->full_search_sad(x, b, d, &d->bmi.mv.as_mv, sadp b, search_range, &cpi->fn_ptr[BLOCK_16X16], x->mvcost, &best_ref_mv);
2095 thissme = cpi->refining_search_sad(x, b, d, &d->bmi.mv, sadpb,
2096 search_range, &cpi->fn_ptr[BLOCK_16X16],
2097 x->mvcost, &best_ref_mv);
2098
2099 if (thissme < bestsme)
2100 {
2101 bestsme = thissme;
2102 mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
2141 } 2103 }
2104 else
2105 {
2106 d->bmi.mv.as_int = mode_mv[NEWMV].as_int;
2107 }
2108 }
2142 2109
2143 // Should we do a full search 2110 x->mv_col_min = tmp_col_min;
2144 if (!cpi->check_freq[lf_or_gf] || cpi->do_full[lf_or_gf]) 2111 x->mv_col_max = tmp_col_max;
2145 { 2112 x->mv_row_min = tmp_row_min;
2146 int thissme; 2113 x->mv_row_max = tmp_row_max;
2147 int full_flag_thresh = 0;
2148 MV full_mvp;
2149 2114
2150 full_mvp.row = d->bmi.mv.as_mv.row <<3; // use diamond se arch result as full search staring point 2115 if (bestsme < INT_MAX)
2151 full_mvp.col = d->bmi.mv.as_mv.col <<3; 2116 {
2117 int dis; /* TODO: use dis in distortion calculation later. */
2118 unsigned int sse;
2119 cpi->find_fractional_mv_step(x, b, d, &d->bmi.mv, &best_ref_mv,
2120 x->errorperbit,
2121 &cpi->fn_ptr[BLOCK_16X16],
2122 x->mvcost, &dis, &sse);
2123 }
2152 2124
2153 // Update x->vector_range based on best vector found in step search 2125 mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
2154 search_range = MAXF(abs((mvp.row>>3) - d->bmi.mv.as_mv.row), abs((mvp.col>>3) - d->bmi.mv.as_mv.col));
2155 //search_range *= 1.4; //didn't improve PSNR
2156 2126
2157 if (search_range > x->vector_range) 2127 // Add the new motion vector cost to our rolling cost variable
2158 x->vector_range = search_range; 2128 rate2 += vp8_mv_bit_cost(&mode_mv[NEWMV], &best_ref_mv, x->mvcost, 9 6);
2159 else 2129 }
2160 search_range = x->vector_range;
2161
2162 // Apply limits
2163 search_range = (search_range > cpi->sf.max_fs_radius) ? cpi- >sf.max_fs_radius : search_range;
2164
2165 //add this to reduce full search range.
2166 if(sr<=3 && search_range > 8) search_range = 8;
2167
2168 {
2169 int sadpb = x->sadperbit16 >> 2;
2170 thissme = cpi->full_search_sad(x, b, d, &full_mvp, sadpb , search_range, &cpi->fn_ptr[BLOCK_16X16], x->mvcost, x->mvsadcost,&best_ref_mv) ;
2171 }
2172
2173 // Barrier threshold to initiating full search
2174 // full_flag_thresh = 10 + (thissme >> 7);
2175 if ((thissme + full_flag_thresh) < bestsme)
2176 {
2177 cpi->do_full[lf_or_gf] ++;
2178 bestsme = thissme;
2179 }
2180 else if (thissme < bestsme)
2181 bestsme = thissme;
2182 else
2183 {
2184 cpi->do_full[lf_or_gf] = cpi->do_full[lf_or_gf] >> 1;
2185 cpi->check_freq[lf_or_gf] = cpi->sf.full_freq[lf_or_gf];
2186
2187 // The full search result is actually worse so re-instat e the previous best vector
2188 d->bmi.mv.as_mv.row = mode_mv[NEWMV].row;
2189 d->bmi.mv.as_mv.col = mode_mv[NEWMV].col;
2190 }
2191 }
2192
2193 x->mv_col_min = tmp_col_min;
2194 x->mv_col_max = tmp_col_max;
2195 x->mv_row_min = tmp_row_min;
2196 x->mv_row_max = tmp_row_max;
2197
2198 if (bestsme < INT_MAX)
2199 // cpi->find_fractional_mv_step(x,b,d,&d->bmi.mv.as_mv,&best _ref_mv,x->errorperbit/2,cpi->fn_ptr.svf,cpi->fn_ptr.vf,x->mvcost); // normal m vc=11
2200 cpi->find_fractional_mv_step(x, b, d, &d->bmi.mv.as_mv, &bes t_ref_mv, x->errorperbit / 4, &cpi->fn_ptr[BLOCK_16X16], x->mvcost);
2201
2202 mode_mv[NEWMV].row = d->bmi.mv.as_mv.row;
2203 mode_mv[NEWMV].col = d->bmi.mv.as_mv.col;
2204
2205 // Add the new motion vector cost to our rolling cost variable
2206 rate2 += vp8_mv_bit_cost(&mode_mv[NEWMV], &best_ref_mv, x->mvcos t, 96);
2207
2208 }
2209 2130
2210 case NEARESTMV: 2131 case NEARESTMV:
2211 case NEARMV: 2132 case NEARMV:
2212
2213 // Clip "next_nearest" so that it does not extend to far out of imag e 2133 // Clip "next_nearest" so that it does not extend to far out of imag e
2214 if (mode_mv[this_mode].col < (xd->mb_to_left_edge - LEFT_TOP_MARGIN) ) 2134 vp8_clamp_mv2(&mode_mv[this_mode], xd);
2215 mode_mv[this_mode].col = xd->mb_to_left_edge - LEFT_TOP_MARGIN;
2216 else if (mode_mv[this_mode].col > xd->mb_to_right_edge + RIGHT_BOTTO M_MARGIN)
2217 mode_mv[this_mode].col = xd->mb_to_right_edge + RIGHT_BOTTOM_MAR GIN;
2218
2219 if (mode_mv[this_mode].row < (xd->mb_to_top_edge - LEFT_TOP_MARGIN))
2220 mode_mv[this_mode].row = xd->mb_to_top_edge - LEFT_TOP_MARGIN;
2221 else if (mode_mv[this_mode].row > xd->mb_to_bottom_edge + RIGHT_BOTT OM_MARGIN)
2222 mode_mv[this_mode].row = xd->mb_to_bottom_edge + RIGHT_BOTTOM_MA RGIN;
2223 2135
2224 // Do not bother proceeding if the vector (from newmv,nearest or nea r) is 0,0 as this should then be coded using the zeromv mode. 2136 // Do not bother proceeding if the vector (from newmv,nearest or nea r) is 0,0 as this should then be coded using the zeromv mode.
2225 if (((this_mode == NEARMV) || (this_mode == NEARESTMV)) && 2137 if (((this_mode == NEARMV) || (this_mode == NEARESTMV)) && (mode_mv[ this_mode].as_int == 0))
2226 ((mode_mv[this_mode].row == 0) && (mode_mv[this_mode].col == 0)) )
2227 continue; 2138 continue;
2228 2139
2229 case ZEROMV: 2140 case ZEROMV:
2230 2141
2231 mv_selected:
2232
2233 // Trap vectors that reach beyond the UMV borders 2142 // Trap vectors that reach beyond the UMV borders
2234 // Note that ALL New MV, Nearest MV Near MV and Zero MV code drops t hrough to this point 2143 // Note that ALL New MV, Nearest MV Near MV and Zero MV code drops t hrough to this point
2235 // because of the lack of break statements in the previous two cases . 2144 // because of the lack of break statements in the previous two cases .
2236 if (((mode_mv[this_mode].row >> 3) < x->mv_row_min) || ((mode_mv[thi s_mode].row >> 3) > x->mv_row_max) || 2145 if (((mode_mv[this_mode].as_mv.row >> 3) < x->mv_row_min) || ((mode_ mv[this_mode].as_mv.row >> 3) > x->mv_row_max) ||
2237 ((mode_mv[this_mode].col >> 3) < x->mv_col_min) || ((mode_mv[thi s_mode].col >> 3) > x->mv_col_max)) 2146 ((mode_mv[this_mode].as_mv.col >> 3) < x->mv_col_min) || ((mode_ mv[this_mode].as_mv.col >> 3) > x->mv_col_max))
2238 continue; 2147 continue;
2239 2148
2240 vp8_set_mbmode_and_mvs(x, this_mode, &mode_mv[this_mode]); 2149 vp8_set_mbmode_and_mvs(x, this_mode, &mode_mv[this_mode]);
2241 vp8_build_inter_predictors_mby(&x->e_mbd); 2150 vp8_build_inter16x16_predictors_mby(&x->e_mbd);
2242 2151
2243 if (cpi->active_map_enabled && x->active_ptr[0] == 0) { 2152 if (cpi->active_map_enabled && x->active_ptr[0] == 0) {
2244 x->skip = 1; 2153 x->skip = 1;
2245 } 2154 }
2246 else if (x->encode_breakout) 2155 else if (x->encode_breakout)
2247 { 2156 {
2248 int sum, sse; 2157 unsigned int sse;
2158 unsigned int var;
2249 int threshold = (xd->block[0].dequant[1] 2159 int threshold = (xd->block[0].dequant[1]
2250 * xd->block[0].dequant[1] >>4); 2160 * xd->block[0].dequant[1] >>4);
2251 2161
2252 if(threshold < x->encode_breakout) 2162 if(threshold < x->encode_breakout)
2253 threshold = x->encode_breakout; 2163 threshold = x->encode_breakout;
2254 2164
2255 VARIANCE_INVOKE(&cpi->rtcd.variance, get16x16var) 2165 var = VARIANCE_INVOKE(&cpi->rtcd.variance, var16x16)
2256 (x->src.y_buffer, x->src.y_stride, 2166 (*(b->base_src), b->src_stride,
2257 x->e_mbd.predictor, 16, (unsigned int *)(&sse), &sum); 2167 x->e_mbd.predictor, 16, &sse);
2258 2168
2259 if (sse < threshold) 2169 if (sse < threshold)
2260 { 2170 {
2261 // Check u and v to make sure skip is ok 2171 unsigned int q2dc = xd->block[24].dequant[0];
2262 int sse2 = 0;
2263 /* If theres is no codeable 2nd order dc 2172 /* If theres is no codeable 2nd order dc
2264 or a very small uniform pixel change change */ 2173 or a very small uniform pixel change change */
2265 if (abs(sum) < (xd->block[24].dequant[0]<<2)|| 2174 if ((sse - var < q2dc * q2dc >>4) ||
2266 ((sum * sum>>8) > sse && abs(sum) <128)) 2175 (sse /2 > var && sse-var < 64))
2267 { 2176 {
2268 sse2 = VP8_UVSSE(x, IF_RTCD(&cpi->rtcd.variance)); 2177 // Check u and v to make sure skip is ok
2269 2178 int sse2= VP8_UVSSE(x, IF_RTCD(&cpi->rtcd.variance));
2270 if (sse2 * 2 < threshold) 2179 if (sse2 * 2 < threshold)
2271 { 2180 {
2272 x->skip = 1; 2181 x->skip = 1;
2273 distortion2 = sse + sse2; 2182 distortion2 = sse + sse2;
2274 rate2 = 500; 2183 rate2 = 500;
2275 2184
2276 /* for best_yrd calculation */ 2185 /* for best_yrd calculation */
2277 rate_uv = 0; 2186 rate_uv = 0;
2278 distortion_uv = sse2; 2187 distortion_uv = sse2;
2279 2188
2280 disable_skip = 1; 2189 disable_skip = 1;
2281 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, 2190 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distort ion2);
2282 distortion2);
2283 2191
2284 break; 2192 break;
2285 } 2193 }
2286 } 2194 }
2287 } 2195 }
2288 } 2196 }
2289 2197
2290 2198
2291 //intermodecost[mode_index] = vp8_cost_mv_ref(this_mode, mdcounts); // Experimental debug code 2199 //intermodecost[mode_index] = vp8_cost_mv_ref(this_mode, mdcounts); // Experimental debug code
2292 2200
(...skipping 17 matching lines...) Expand all
2310 2218
2311 // Where skip is allowable add in the default per mb cost for the no ski p case. 2219 // Where skip is allowable add in the default per mb cost for the no ski p case.
2312 // where we then decide to skip we have to delete this and replace it wi th the 2220 // where we then decide to skip we have to delete this and replace it wi th the
2313 // cost of signallying a skip 2221 // cost of signallying a skip
2314 if (cpi->common.mb_no_coeff_skip) 2222 if (cpi->common.mb_no_coeff_skip)
2315 { 2223 {
2316 other_cost += vp8_cost_bit(cpi->prob_skip_false, 0); 2224 other_cost += vp8_cost_bit(cpi->prob_skip_false, 0);
2317 rate2 += other_cost; 2225 rate2 += other_cost;
2318 } 2226 }
2319 2227
2320 // Estimate the reference frame signaling cost and add it to the rolling cost variable. 2228 /* Estimate the reference frame signaling cost and add it
2321 rate2 += ref_frame_cost[x->e_mbd.mode_info_context->mbmi.ref_frame]; 2229 * to the rolling cost variable.
2230 */
2231 rate2 +=
2232 x->e_mbd.ref_frame_cost[x->e_mbd.mode_info_context->mbmi.ref_frame];
2322 2233
2323 if (!disable_skip) 2234 if (!disable_skip)
2324 { 2235 {
2325 // Test for the condition where skip block will be activated because there are no non zero coefficients and make any necessary adjustment for rate 2236 // Test for the condition where skip block will be activated because there are no non zero coefficients and make any necessary adjustment for rate
2326 if (cpi->common.mb_no_coeff_skip) 2237 if (cpi->common.mb_no_coeff_skip)
2327 { 2238 {
2328 int tteob; 2239 int tteob;
2329 2240
2330 tteob = 0; 2241 tteob = 0;
2331 2242
(...skipping 22 matching lines...) Expand all
2354 } 2265 }
2355 // Calculate the final RD estimate for this mode 2266 // Calculate the final RD estimate for this mode
2356 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); 2267 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2);
2357 } 2268 }
2358 2269
2359 // Experimental debug code. 2270 // Experimental debug code.
2360 //all_rds[mode_index] = this_rd; 2271 //all_rds[mode_index] = this_rd;
2361 //all_rates[mode_index] = rate2; 2272 //all_rates[mode_index] = rate2;
2362 //all_dist[mode_index] = distortion2; 2273 //all_dist[mode_index] = distortion2;
2363 2274
2364 if ((x->e_mbd.mode_info_context->mbmi.ref_frame == INTRA_FRAME) && (thi s_rd < *returnintra)) 2275 // Keep record of best intra distortion
2276 if ((x->e_mbd.mode_info_context->mbmi.ref_frame == INTRA_FRAME) &&
2277 (this_rd < best_intra_rd) )
2365 { 2278 {
2366 *returnintra = this_rd ; 2279 best_intra_rd = this_rd;
2280 *returnintra = distortion2 ;
2367 } 2281 }
2368 2282
2369 // Did this mode help.. i.i is it the new best mode 2283 // Did this mode help.. i.i is it the new best mode
2370 if (this_rd < best_rd || x->skip) 2284 if (this_rd < best_rd || x->skip)
2371 { 2285 {
2372 // Note index of best mode so far 2286 // Note index of best mode so far
2373 best_mode_index = mode_index; 2287 best_mode_index = mode_index;
2374 x->e_mbd.mode_info_context->mbmi.force_no_skip = force_no_skip;
2375 2288
2376 if (this_mode <= B_PRED) 2289 if (this_mode <= B_PRED)
2377 { 2290 {
2378 x->e_mbd.mode_info_context->mbmi.uv_mode = uv_intra_mode; 2291 x->e_mbd.mode_info_context->mbmi.uv_mode = uv_intra_mode;
2292 /* required for left and above block mv */
2293 x->e_mbd.mode_info_context->mbmi.mv.as_int = 0;
2379 } 2294 }
2380 2295
2381 other_cost += ref_frame_cost[x->e_mbd.mode_info_context->mbmi.ref_fr ame]; 2296 other_cost +=
2297 x->e_mbd.ref_frame_cost[x->e_mbd.mode_info_context->mbmi.ref_frame];
2382 2298
2383 /* Calculate the final y RD estimate for this mode */ 2299 /* Calculate the final y RD estimate for this mode */
2384 best_yrd = RDCOST(x->rdmult, x->rddiv, (rate2-rate_uv-other_cost), 2300 best_yrd = RDCOST(x->rdmult, x->rddiv, (rate2-rate_uv-other_cost),
2385 (distortion2-distortion_uv)); 2301 (distortion2-distortion_uv));
2386 2302
2387 *returnrate = rate2; 2303 *returnrate = rate2;
2388 *returndistortion = distortion2; 2304 *returndistortion = distortion2;
2389 best_rd = this_rd; 2305 best_rd = this_rd;
2390 vpx_memcpy(&best_mbmode, &x->e_mbd.mode_info_context->mbmi, sizeof(M B_MODE_INFO)); 2306 vpx_memcpy(&best_mbmode, &x->e_mbd.mode_info_context->mbmi, sizeof(M B_MODE_INFO));
2391 vpx_memcpy(&best_partition, x->partition_info, sizeof(PARTITION_INFO )); 2307 vpx_memcpy(&best_partition, x->partition_info, sizeof(PARTITION_INFO ));
2392 2308
2393 for (i = 0; i < 16; i++) 2309 if ((this_mode == B_PRED) || (this_mode == SPLITMV))
2394 { 2310 for (i = 0; i < 16; i++)
2395 vpx_memcpy(&best_bmodes[i], &x->e_mbd.block[i].bmi, sizeof(B_MOD E_INFO)); 2311 {
2396 } 2312 best_bmodes[i] = x->e_mbd.block[i].bmi;
2313 }
2314
2397 2315
2398 // Testing this mode gave rise to an improvement in best error score . Lower threshold a bit for next time 2316 // Testing this mode gave rise to an improvement in best error score . Lower threshold a bit for next time
2399 cpi->rd_thresh_mult[mode_index] = (cpi->rd_thresh_mult[mode_index] > = (MIN_THRESHMULT + 2)) ? cpi->rd_thresh_mult[mode_index] - 2 : MIN_THRESHMULT; 2317 cpi->rd_thresh_mult[mode_index] = (cpi->rd_thresh_mult[mode_index] > = (MIN_THRESHMULT + 2)) ? cpi->rd_thresh_mult[mode_index] - 2 : MIN_THRESHMULT;
2400 cpi->rd_threshes[mode_index] = (cpi->rd_baseline_thresh[mode_index] >> 7) * cpi->rd_thresh_mult[mode_index]; 2318 cpi->rd_threshes[mode_index] = (cpi->rd_baseline_thresh[mode_index] >> 7) * cpi->rd_thresh_mult[mode_index];
2401 } 2319 }
2402 2320
2403 // If the mode did not help improve the best error case then raise the t hreshold for testing that mode next time around. 2321 // If the mode did not help improve the best error case then raise the t hreshold for testing that mode next time around.
2404 else 2322 else
2405 { 2323 {
2406 cpi->rd_thresh_mult[mode_index] += 4; 2324 cpi->rd_thresh_mult[mode_index] += 4;
(...skipping 28 matching lines...) Expand all
2435 cpi->rd_thresh_mult[THR_NEWG] = (cpi->rd_thresh_mult[THR_NEWG] >= (M IN_THRESHMULT+best_adjustment)) ? cpi->rd_thresh_mult[THR_NEWG]-best_adjustment: MIN_THRESHMULT; 2353 cpi->rd_thresh_mult[THR_NEWG] = (cpi->rd_thresh_mult[THR_NEWG] >= (M IN_THRESHMULT+best_adjustment)) ? cpi->rd_thresh_mult[THR_NEWG]-best_adjustment: MIN_THRESHMULT;
2436 cpi->rd_threshes[THR_NEWG] = (cpi->rd_baseline_thresh[THR_NEWG] >> 7 ) * cpi->rd_thresh_mult[THR_NEWG]; 2354 cpi->rd_threshes[THR_NEWG] = (cpi->rd_baseline_thresh[THR_NEWG] >> 7 ) * cpi->rd_thresh_mult[THR_NEWG];
2437 2355
2438 best_adjustment = 4; //(cpi->rd_thresh_mult[THR_NEWA] >> 4); 2356 best_adjustment = 4; //(cpi->rd_thresh_mult[THR_NEWA] >> 4);
2439 cpi->rd_thresh_mult[THR_NEWA] = (cpi->rd_thresh_mult[THR_NEWA] >= (M IN_THRESHMULT+best_adjustment)) ? cpi->rd_thresh_mult[THR_NEWA]-best_adjustment: MIN_THRESHMULT; 2357 cpi->rd_thresh_mult[THR_NEWA] = (cpi->rd_thresh_mult[THR_NEWA] >= (M IN_THRESHMULT+best_adjustment)) ? cpi->rd_thresh_mult[THR_NEWA]-best_adjustment: MIN_THRESHMULT;
2440 cpi->rd_threshes[THR_NEWA] = (cpi->rd_baseline_thresh[THR_NEWA] >> 7 ) * cpi->rd_thresh_mult[THR_NEWA]; 2358 cpi->rd_threshes[THR_NEWA] = (cpi->rd_baseline_thresh[THR_NEWA] >> 7 ) * cpi->rd_thresh_mult[THR_NEWA];
2441 }*/ 2359 }*/
2442 2360
2443 } 2361 }
2444 2362
2445 // If we have chosen new mv or split then decay the full search check count more quickly.
2446 if ((vp8_mode_order[best_mode_index] == NEWMV) || (vp8_mode_order[best_mode_ index] == SPLITMV))
2447 {
2448 int lf_or_gf = (vp8_ref_frame_order[best_mode_index] == LAST_FRAME) ? 0 : 1;
2449
2450 if (cpi->check_freq[lf_or_gf] && !cpi->do_full[lf_or_gf])
2451 {
2452 cpi->check_freq[lf_or_gf] --;
2453 }
2454 }
2455
2456 // Keep a record of best mode index that we chose
2457 cpi->last_best_mode_index = best_mode_index;
2458
2459 // Note how often each mode chosen as best 2363 // Note how often each mode chosen as best
2460 cpi->mode_chosen_counts[best_mode_index] ++; 2364 cpi->mode_chosen_counts[best_mode_index] ++;
2461 2365
2462 2366
2463 if (cpi->is_src_frame_alt_ref && (best_mbmode.mode != ZEROMV || best_mbmode. ref_frame != ALTREF_FRAME)) 2367 if (cpi->is_src_frame_alt_ref &&
2368 (best_mbmode.mode != ZEROMV || best_mbmode.ref_frame != ALTREF_FRAME))
2464 { 2369 {
2465 best_mbmode.mode = ZEROMV; 2370 x->e_mbd.mode_info_context->mbmi.mode = ZEROMV;
2466 best_mbmode.ref_frame = ALTREF_FRAME; 2371 x->e_mbd.mode_info_context->mbmi.ref_frame = ALTREF_FRAME;
2467 best_mbmode.mv.as_int = 0; 2372 x->e_mbd.mode_info_context->mbmi.mv.as_int = 0;
2468 best_mbmode.uv_mode = 0; 2373 x->e_mbd.mode_info_context->mbmi.uv_mode = DC_PRED;
2469 best_mbmode.mb_skip_coeff = (cpi->common.mb_no_coeff_skip) ? 1 : 0; 2374 x->e_mbd.mode_info_context->mbmi.mb_skip_coeff =
2470 best_mbmode.partitioning = 0; 2375 (cpi->common.mb_no_coeff_skip) ? 1 : 0;
2471 best_mbmode.dc_diff = 0; 2376 x->e_mbd.mode_info_context->mbmi.partitioning = 0;
2472 2377
2473 vpx_memcpy(&x->e_mbd.mode_info_context->mbmi, &best_mbmode, sizeof(MB_MO DE_INFO)); 2378 return;
2474 vpx_memcpy(x->partition_info, &best_partition, sizeof(PARTITION_INFO));
2475
2476 for (i = 0; i < 16; i++)
2477 {
2478 vpx_memset(&x->e_mbd.block[i].bmi, 0, sizeof(B_MODE_INFO));
2479 }
2480
2481 x->e_mbd.mode_info_context->mbmi.mv.as_int = 0;
2482
2483 return best_rd;
2484 } 2379 }
2485 2380
2486 2381
2487 if(best_mbmode.mode <= B_PRED) 2382 // macroblock modes
2383 vpx_memcpy(&x->e_mbd.mode_info_context->mbmi, &best_mbmode, sizeof(MB_MODE_I NFO));
2384
2385 if (best_mbmode.mode == B_PRED)
2488 { 2386 {
2489 int i;
2490 for (i = 0; i < 16; i++) 2387 for (i = 0; i < 16; i++)
2491 { 2388 x->e_mbd.block[i].bmi.as_mode = best_bmodes[i].as_mode;
2492 best_bmodes[i].mv.as_int = 0;
2493 }
2494 } 2389 }
2495 2390
2496 // macroblock modes 2391 if (best_mbmode.mode == SPLITMV)
2497 vpx_memcpy(&x->e_mbd.mode_info_context->mbmi, &best_mbmode, sizeof(MB_MODE_I NFO)); 2392 {
2498 vpx_memcpy(x->partition_info, &best_partition, sizeof(PARTITION_INFO)); 2393 for (i = 0; i < 16; i++)
2394 x->e_mbd.block[i].bmi.mv.as_int = best_bmodes[i].mv.as_int;
2499 2395
2500 for (i = 0; i < 16; i++) 2396 vpx_memcpy(x->partition_info, &best_partition, sizeof(PARTITION_INFO));
2501 { 2397
2502 vpx_memcpy(&x->e_mbd.block[i].bmi, &best_bmodes[i], sizeof(B_MODE_INFO)) ; 2398 x->e_mbd.mode_info_context->mbmi.mv.as_int =
2399 x->partition_info->bmi[15].mv.as_int;
2503 } 2400 }
2504 2401
2505 x->e_mbd.mode_info_context->mbmi.mv.as_mv = x->e_mbd.block[15].bmi.mv.as_mv; 2402 rd_update_mvcount(cpi, x, &frame_best_ref_mv[xd->mode_info_context->mbmi.ref _frame]);
2506 2403
2507 return best_rd;
2508 } 2404 }
2509 #endif 2405
2406 void vp8_rd_pick_intra_mode(VP8_COMP *cpi, MACROBLOCK *x, int *rate_)
2407 {
2408 int error4x4, error16x16;
2409 int rate4x4, rate16x16 = 0, rateuv;
2410 int dist4x4, dist16x16, distuv;
2411 int rate;
2412 int rate4x4_tokenonly = 0;
2413 int rate16x16_tokenonly = 0;
2414 int rateuv_tokenonly = 0;
2415
2416 x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME;
2417
2418 rd_pick_intra_mbuv_mode(cpi, x, &rateuv, &rateuv_tokenonly, &distuv);
2419 rate = rateuv;
2420
2421 error16x16 = rd_pick_intra16x16mby_mode(cpi, x,
2422 &rate16x16, &rate16x16_tokenonly,
2423 &dist16x16);
2424
2425 error4x4 = rd_pick_intra4x4mby_modes(cpi, x,
2426 &rate4x4, &rate4x4_tokenonly,
2427 &dist4x4, error16x16);
2428
2429 if (error4x4 < error16x16)
2430 {
2431 x->e_mbd.mode_info_context->mbmi.mode = B_PRED;
2432 rate += rate4x4;
2433 }
2434 else
2435 {
2436 rate += rate16x16;
2437 }
2438
2439 *rate_ = rate;
2440 }
OLDNEW
« no previous file with comments | « source/libvpx/vp8/encoder/rdopt.h ('k') | source/libvpx/vp8/encoder/sad_c.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698