| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 int uv_block_width, | 37 int uv_block_width, |
| 38 int uv_block_height, | 38 int uv_block_height, |
| 39 int mv_row, | 39 int mv_row, |
| 40 int mv_col, | 40 int mv_col, |
| 41 uint8_t *pred, | 41 uint8_t *pred, |
| 42 struct scale_factors *scale, | 42 struct scale_factors *scale, |
| 43 int x, int y) { | 43 int x, int y) { |
| 44 const int which_mv = 0; | 44 const int which_mv = 0; |
| 45 const MV mv = { mv_row, mv_col }; | 45 const MV mv = { mv_row, mv_col }; |
| 46 const InterpKernel *const kernel = | 46 const InterpKernel *const kernel = |
| 47 vp9_get_interp_kernel(xd->mi[0]->mbmi.interp_filter); | 47 vp9_get_interp_kernel(xd->mi[0].src_mi->mbmi.interp_filter); |
| 48 | 48 |
| 49 enum mv_precision mv_precision_uv; | 49 enum mv_precision mv_precision_uv; |
| 50 int uv_stride; | 50 int uv_stride; |
| 51 if (uv_block_width == 8) { | 51 if (uv_block_width == 8) { |
| 52 uv_stride = (stride + 1) >> 1; | 52 uv_stride = (stride + 1) >> 1; |
| 53 mv_precision_uv = MV_PRECISION_Q4; | 53 mv_precision_uv = MV_PRECISION_Q4; |
| 54 } else { | 54 } else { |
| 55 uv_stride = stride; | 55 uv_stride = stride; |
| 56 mv_precision_uv = MV_PRECISION_Q3; | 56 mv_precision_uv = MV_PRECISION_Q3; |
| 57 } | 57 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 const MV_SPEED_FEATURES *const mv_sf = &cpi->sf.mv; | 142 const MV_SPEED_FEATURES *const mv_sf = &cpi->sf.mv; |
| 143 int step_param; | 143 int step_param; |
| 144 int sadpb = x->sadperbit16; | 144 int sadpb = x->sadperbit16; |
| 145 int bestsme = INT_MAX; | 145 int bestsme = INT_MAX; |
| 146 int distortion; | 146 int distortion; |
| 147 unsigned int sse; | 147 unsigned int sse; |
| 148 int sad_list[5]; | 148 int sad_list[5]; |
| 149 | 149 |
| 150 MV best_ref_mv1 = {0, 0}; | 150 MV best_ref_mv1 = {0, 0}; |
| 151 MV best_ref_mv1_full; /* full-pixel value of best_ref_mv1 */ | 151 MV best_ref_mv1_full; /* full-pixel value of best_ref_mv1 */ |
| 152 MV *ref_mv = &x->e_mbd.mi[0]->bmi[0].as_mv[0].as_mv; | 152 MV *ref_mv = &x->e_mbd.mi[0].src_mi->bmi[0].as_mv[0].as_mv; |
| 153 | 153 |
| 154 // Save input state | 154 // Save input state |
| 155 struct buf_2d src = x->plane[0].src; | 155 struct buf_2d src = x->plane[0].src; |
| 156 struct buf_2d pre = xd->plane[0].pre[0]; | 156 struct buf_2d pre = xd->plane[0].pre[0]; |
| 157 | 157 |
| 158 best_ref_mv1_full.col = best_ref_mv1.col >> 3; | 158 best_ref_mv1_full.col = best_ref_mv1.col >> 3; |
| 159 best_ref_mv1_full.row = best_ref_mv1.row >> 3; | 159 best_ref_mv1_full.row = best_ref_mv1.row >> 3; |
| 160 | 160 |
| 161 // Setup frame pointers | 161 // Setup frame pointers |
| 162 x->plane[0].src.buf = arf_frame_buf; | 162 x->plane[0].src.buf = arf_frame_buf; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 193 static void temporal_filter_iterate_c(VP9_COMP *cpi, | 193 static void temporal_filter_iterate_c(VP9_COMP *cpi, |
| 194 YV12_BUFFER_CONFIG **frames, | 194 YV12_BUFFER_CONFIG **frames, |
| 195 int frame_count, | 195 int frame_count, |
| 196 int alt_ref_index, | 196 int alt_ref_index, |
| 197 int strength, | 197 int strength, |
| 198 struct scale_factors *scale) { | 198 struct scale_factors *scale) { |
| 199 int byte; | 199 int byte; |
| 200 int frame; | 200 int frame; |
| 201 int mb_col, mb_row; | 201 int mb_col, mb_row; |
| 202 unsigned int filter_weight; | 202 unsigned int filter_weight; |
| 203 int mb_cols = cpi->common.mb_cols; | 203 int mb_cols = (frames[alt_ref_index]->y_crop_width + 15) >> 4; |
| 204 int mb_rows = cpi->common.mb_rows; | 204 int mb_rows = (frames[alt_ref_index]->y_crop_height + 15) >> 4; |
| 205 int mb_y_offset = 0; | 205 int mb_y_offset = 0; |
| 206 int mb_uv_offset = 0; | 206 int mb_uv_offset = 0; |
| 207 DECLARE_ALIGNED_ARRAY(16, unsigned int, accumulator, 16 * 16 * 3); | 207 DECLARE_ALIGNED_ARRAY(16, unsigned int, accumulator, 16 * 16 * 3); |
| 208 DECLARE_ALIGNED_ARRAY(16, uint16_t, count, 16 * 16 * 3); | 208 DECLARE_ALIGNED_ARRAY(16, uint16_t, count, 16 * 16 * 3); |
| 209 MACROBLOCKD *mbd = &cpi->mb.e_mbd; | 209 MACROBLOCKD *mbd = &cpi->mb.e_mbd; |
| 210 YV12_BUFFER_CONFIG *f = frames[alt_ref_index]; | 210 YV12_BUFFER_CONFIG *f = frames[alt_ref_index]; |
| 211 uint8_t *dst1, *dst2; | 211 uint8_t *dst1, *dst2; |
| 212 DECLARE_ALIGNED_ARRAY(16, uint8_t, predictor, 16 * 16 * 3); | 212 DECLARE_ALIGNED_ARRAY(16, uint8_t, predictor, 16 * 16 * 3); |
| 213 const int mb_uv_height = 16 >> mbd->plane[1].subsampling_y; | 213 const int mb_uv_height = 16 >> mbd->plane[1].subsampling_y; |
| 214 const int mb_uv_width = 16 >> mbd->plane[1].subsampling_x; | 214 const int mb_uv_width = 16 >> mbd->plane[1].subsampling_x; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 226 // A 6/8 tap filter is used for motion search. This requires 2 pixels | 226 // A 6/8 tap filter is used for motion search. This requires 2 pixels |
| 227 // before and 3 pixels after. So the largest Y mv on a border would | 227 // before and 3 pixels after. So the largest Y mv on a border would |
| 228 // then be 16 - VP9_INTERP_EXTEND. The UV blocks are half the size of the | 228 // then be 16 - VP9_INTERP_EXTEND. The UV blocks are half the size of the |
| 229 // Y and therefore only extended by 8. The largest mv that a UV block | 229 // Y and therefore only extended by 8. The largest mv that a UV block |
| 230 // can support is 8 - VP9_INTERP_EXTEND. A UV mv is half of a Y mv. | 230 // can support is 8 - VP9_INTERP_EXTEND. A UV mv is half of a Y mv. |
| 231 // (16 - VP9_INTERP_EXTEND) >> 1 which is greater than | 231 // (16 - VP9_INTERP_EXTEND) >> 1 which is greater than |
| 232 // 8 - VP9_INTERP_EXTEND. | 232 // 8 - VP9_INTERP_EXTEND. |
| 233 // To keep the mv in play for both Y and UV planes the max that it | 233 // To keep the mv in play for both Y and UV planes the max that it |
| 234 // can be on a border is therefore 16 - (2*VP9_INTERP_EXTEND+1). | 234 // can be on a border is therefore 16 - (2*VP9_INTERP_EXTEND+1). |
| 235 cpi->mb.mv_row_min = -((mb_row * 16) + (17 - 2 * VP9_INTERP_EXTEND)); | 235 cpi->mb.mv_row_min = -((mb_row * 16) + (17 - 2 * VP9_INTERP_EXTEND)); |
| 236 cpi->mb.mv_row_max = ((cpi->common.mb_rows - 1 - mb_row) * 16) | 236 cpi->mb.mv_row_max = ((mb_rows - 1 - mb_row) * 16) |
| 237 + (17 - 2 * VP9_INTERP_EXTEND); | 237 + (17 - 2 * VP9_INTERP_EXTEND); |
| 238 | 238 |
| 239 for (mb_col = 0; mb_col < mb_cols; mb_col++) { | 239 for (mb_col = 0; mb_col < mb_cols; mb_col++) { |
| 240 int i, j, k; | 240 int i, j, k; |
| 241 int stride; | 241 int stride; |
| 242 | 242 |
| 243 vpx_memset(accumulator, 0, 16 * 16 * 3 * sizeof(accumulator[0])); | 243 vpx_memset(accumulator, 0, 16 * 16 * 3 * sizeof(accumulator[0])); |
| 244 vpx_memset(count, 0, 16 * 16 * 3 * sizeof(count[0])); | 244 vpx_memset(count, 0, 16 * 16 * 3 * sizeof(count[0])); |
| 245 | 245 |
| 246 cpi->mb.mv_col_min = -((mb_col * 16) + (17 - 2 * VP9_INTERP_EXTEND)); | 246 cpi->mb.mv_col_min = -((mb_col * 16) + (17 - 2 * VP9_INTERP_EXTEND)); |
| 247 cpi->mb.mv_col_max = ((cpi->common.mb_cols - 1 - mb_col) * 16) | 247 cpi->mb.mv_col_max = ((mb_cols - 1 - mb_col) * 16) |
| 248 + (17 - 2 * VP9_INTERP_EXTEND); | 248 + (17 - 2 * VP9_INTERP_EXTEND); |
| 249 | 249 |
| 250 for (frame = 0; frame < frame_count; frame++) { | 250 for (frame = 0; frame < frame_count; frame++) { |
| 251 const int thresh_low = 10000; | 251 const int thresh_low = 10000; |
| 252 const int thresh_high = 20000; | 252 const int thresh_high = 20000; |
| 253 | 253 |
| 254 if (frames[frame] == NULL) | 254 if (frames[frame] == NULL) |
| 255 continue; | 255 continue; |
| 256 | 256 |
| 257 mbd->mi[0]->bmi[0].as_mv[0].as_mv.row = 0; | 257 mbd->mi[0].src_mi->bmi[0].as_mv[0].as_mv.row = 0; |
| 258 mbd->mi[0]->bmi[0].as_mv[0].as_mv.col = 0; | 258 mbd->mi[0].src_mi->bmi[0].as_mv[0].as_mv.col = 0; |
| 259 | 259 |
| 260 if (frame == alt_ref_index) { | 260 if (frame == alt_ref_index) { |
| 261 filter_weight = 2; | 261 filter_weight = 2; |
| 262 } else { | 262 } else { |
| 263 // Find best match in this frame by MC | 263 // Find best match in this frame by MC |
| 264 int err = temporal_filter_find_matching_mb_c(cpi, | 264 int err = temporal_filter_find_matching_mb_c(cpi, |
| 265 frames[alt_ref_index]->y_buffer + mb_y_offset, | 265 frames[alt_ref_index]->y_buffer + mb_y_offset, |
| 266 frames[frame]->y_buffer + mb_y_offset, | 266 frames[frame]->y_buffer + mb_y_offset, |
| 267 frames[frame]->y_stride); | 267 frames[frame]->y_stride); |
| 268 | 268 |
| 269 // Assign higher weight to matching MB if it's error | 269 // Assign higher weight to matching MB if it's error |
| 270 // score is lower. If not applying MC default behavior | 270 // score is lower. If not applying MC default behavior |
| 271 // is to weight all MBs equal. | 271 // is to weight all MBs equal. |
| 272 filter_weight = err < thresh_low | 272 filter_weight = err < thresh_low |
| 273 ? 2 : err < thresh_high ? 1 : 0; | 273 ? 2 : err < thresh_high ? 1 : 0; |
| 274 } | 274 } |
| 275 | 275 |
| 276 if (filter_weight != 0) { | 276 if (filter_weight != 0) { |
| 277 // Construct the predictors | 277 // Construct the predictors |
| 278 temporal_filter_predictors_mb_c(mbd, | 278 temporal_filter_predictors_mb_c(mbd, |
| 279 frames[frame]->y_buffer + mb_y_offset, | 279 frames[frame]->y_buffer + mb_y_offset, |
| 280 frames[frame]->u_buffer + mb_uv_offset, | 280 frames[frame]->u_buffer + mb_uv_offset, |
| 281 frames[frame]->v_buffer + mb_uv_offset, | 281 frames[frame]->v_buffer + mb_uv_offset, |
| 282 frames[frame]->y_stride, | 282 frames[frame]->y_stride, |
| 283 mb_uv_width, mb_uv_height, | 283 mb_uv_width, mb_uv_height, |
| 284 mbd->mi[0]->bmi[0].as_mv[0].as_mv.row, | 284 mbd->mi[0].src_mi->bmi[0].as_mv[0].as_mv.row, |
| 285 mbd->mi[0]->bmi[0].as_mv[0].as_mv.col, | 285 mbd->mi[0].src_mi->bmi[0].as_mv[0].as_mv.col, |
| 286 predictor, scale, | 286 predictor, scale, |
| 287 mb_col * 16, mb_row * 16); | 287 mb_col * 16, mb_row * 16); |
| 288 | 288 |
| 289 // Apply the filter (YUV) | 289 // Apply the filter (YUV) |
| 290 vp9_temporal_filter_apply(f->y_buffer + mb_y_offset, f->y_stride, | 290 vp9_temporal_filter_apply(f->y_buffer + mb_y_offset, f->y_stride, |
| 291 predictor, 16, 16, | 291 predictor, 16, 16, |
| 292 strength, filter_weight, | 292 strength, filter_weight, |
| 293 accumulator, count); | 293 accumulator, count); |
| 294 vp9_temporal_filter_apply(f->u_buffer + mb_uv_offset, f->uv_stride, | 294 vp9_temporal_filter_apply(f->u_buffer + mb_uv_offset, f->uv_stride, |
| 295 predictor + 256, | 295 predictor + 256, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 // than forward: e.g. len=6 ==> bbbAff, len=7 ==> bbbAfff. | 382 // than forward: e.g. len=6 ==> bbbAff, len=7 ==> bbbAfff. |
| 383 if (frames_bwd < distance) | 383 if (frames_bwd < distance) |
| 384 frames_bwd += (oxcf->arnr_max_frames + 1) & 0x1; | 384 frames_bwd += (oxcf->arnr_max_frames + 1) & 0x1; |
| 385 | 385 |
| 386 // Set the baseline active filter size. | 386 // Set the baseline active filter size. |
| 387 frames = frames_bwd + 1 + frames_fwd; | 387 frames = frames_bwd + 1 + frames_fwd; |
| 388 | 388 |
| 389 // Adjust the strength based on active max q. | 389 // Adjust the strength based on active max q. |
| 390 if (cpi->common.current_video_frame > 1) | 390 if (cpi->common.current_video_frame > 1) |
| 391 q = ((int)vp9_convert_qindex_to_q( | 391 q = ((int)vp9_convert_qindex_to_q( |
| 392 cpi->rc.avg_frame_qindex[INTER_FRAME])); | 392 cpi->rc.avg_frame_qindex[INTER_FRAME], cpi->common.bit_depth)); |
| 393 else | 393 else |
| 394 q = ((int)vp9_convert_qindex_to_q( | 394 q = ((int)vp9_convert_qindex_to_q( |
| 395 cpi->rc.avg_frame_qindex[KEY_FRAME])); | 395 cpi->rc.avg_frame_qindex[KEY_FRAME], cpi->common.bit_depth)); |
| 396 if (q > 16) { | 396 if (q > 16) { |
| 397 strength = oxcf->arnr_strength; | 397 strength = oxcf->arnr_strength; |
| 398 } else { | 398 } else { |
| 399 strength = oxcf->arnr_strength - ((16 - q) / 2); | 399 strength = oxcf->arnr_strength - ((16 - q) / 2); |
| 400 if (strength < 0) | 400 if (strength < 0) |
| 401 strength = 0; | 401 strength = 0; |
| 402 } | 402 } |
| 403 | 403 |
| 404 // Adjust number of frames in filter and strength based on gf boost level. | 404 // Adjust number of frames in filter and strength based on gf boost level. |
| 405 if (frames > group_boost / 150) { | 405 if (frames > group_boost / 150) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 struct lookahead_entry *buf = vp9_lookahead_peek(cpi->lookahead, | 447 struct lookahead_entry *buf = vp9_lookahead_peek(cpi->lookahead, |
| 448 which_buffer); | 448 which_buffer); |
| 449 frames[frames_to_blur - 1 - frame] = &buf->img; | 449 frames[frames_to_blur - 1 - frame] = &buf->img; |
| 450 } | 450 } |
| 451 | 451 |
| 452 // Setup scaling factors. Scaling on each of the arnr frames is not supported | 452 // Setup scaling factors. Scaling on each of the arnr frames is not supported |
| 453 if (is_two_pass_svc(cpi)) { | 453 if (is_two_pass_svc(cpi)) { |
| 454 // In spatial svc the scaling factors might be less then 1/2. So we will use | 454 // In spatial svc the scaling factors might be less then 1/2. So we will use |
| 455 // non-normative scaling. | 455 // non-normative scaling. |
| 456 int frame_used = 0; | 456 int frame_used = 0; |
| 457 #if CONFIG_VP9_HIGHBITDEPTH |
| 458 vp9_setup_scale_factors_for_frame(&sf, |
| 459 get_frame_new_buffer(cm)->y_crop_width, |
| 460 get_frame_new_buffer(cm)->y_crop_height, |
| 461 get_frame_new_buffer(cm)->y_crop_width, |
| 462 get_frame_new_buffer(cm)->y_crop_height, |
| 463 cm->use_highbitdepth); |
| 464 #else |
| 457 vp9_setup_scale_factors_for_frame(&sf, | 465 vp9_setup_scale_factors_for_frame(&sf, |
| 458 get_frame_new_buffer(cm)->y_crop_width, | 466 get_frame_new_buffer(cm)->y_crop_width, |
| 459 get_frame_new_buffer(cm)->y_crop_height, | 467 get_frame_new_buffer(cm)->y_crop_height, |
| 460 get_frame_new_buffer(cm)->y_crop_width, | 468 get_frame_new_buffer(cm)->y_crop_width, |
| 461 get_frame_new_buffer(cm)->y_crop_height); | 469 get_frame_new_buffer(cm)->y_crop_height); |
| 462 | 470 #endif |
| 463 for (frame = 0; frame < frames_to_blur; ++frame) { | 471 for (frame = 0; frame < frames_to_blur; ++frame) { |
| 464 if (cm->mi_cols * MI_SIZE != frames[frame]->y_width || | 472 if (cm->mi_cols * MI_SIZE != frames[frame]->y_width || |
| 465 cm->mi_rows * MI_SIZE != frames[frame]->y_height) { | 473 cm->mi_rows * MI_SIZE != frames[frame]->y_height) { |
| 466 if (vp9_realloc_frame_buffer(&cpi->svc.scaled_frames[frame_used], | 474 if (vp9_realloc_frame_buffer(&cpi->svc.scaled_frames[frame_used], |
| 467 cm->width, cm->height, | 475 cm->width, cm->height, |
| 468 cm->subsampling_x, cm->subsampling_y, | 476 cm->subsampling_x, cm->subsampling_y, |
| 469 #if CONFIG_VP9_HIGHBITDEPTH | 477 #if CONFIG_VP9_HIGHBITDEPTH |
| 470 cm->use_highbitdepth, | 478 cm->use_highbitdepth, |
| 471 #endif | 479 #endif |
| 472 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, | 480 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, |
| 473 NULL)) | 481 NULL)) |
| 474 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 482 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 475 "Failed to reallocate alt_ref_buffer"); | 483 "Failed to reallocate alt_ref_buffer"); |
| 476 | 484 |
| 477 frames[frame] = vp9_scale_if_required(cm, frames[frame], | 485 frames[frame] = vp9_scale_if_required(cm, frames[frame], |
| 478 &cpi->svc.scaled_frames[frame_used]); | 486 &cpi->svc.scaled_frames[frame_used]); |
| 479 ++frame_used; | 487 ++frame_used; |
| 480 } | 488 } |
| 481 } | 489 } |
| 482 } else { | 490 } else { |
| 491 // ARF is produced at the native frame size and resized when coded. |
| 492 #if CONFIG_VP9_HIGHBITDEPTH |
| 483 vp9_setup_scale_factors_for_frame(&sf, | 493 vp9_setup_scale_factors_for_frame(&sf, |
| 484 get_frame_new_buffer(cm)->y_crop_width, | 494 frames[0]->y_crop_width, |
| 485 get_frame_new_buffer(cm)->y_crop_height, | 495 frames[0]->y_crop_height, |
| 486 cm->width, cm->height); | 496 frames[0]->y_crop_width, |
| 497 frames[0]->y_crop_height, |
| 498 cm->use_highbitdepth); |
| 499 #else |
| 500 vp9_setup_scale_factors_for_frame(&sf, |
| 501 frames[0]->y_crop_width, |
| 502 frames[0]->y_crop_height, |
| 503 frames[0]->y_crop_width, |
| 504 frames[0]->y_crop_height); |
| 505 #endif |
| 487 } | 506 } |
| 488 | 507 |
| 489 temporal_filter_iterate_c(cpi, frames, frames_to_blur, | 508 temporal_filter_iterate_c(cpi, frames, frames_to_blur, |
| 490 frames_to_blur_backward, strength, &sf); | 509 frames_to_blur_backward, strength, &sf); |
| 491 } | 510 } |
| OLD | NEW |