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

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

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

Powered by Google App Engine
This is Rietveld 408576698