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

Side by Side Diff: source/libvpx/vp9/encoder/vp9_temporal_filter.c

Issue 390713002: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: libvpx: Pull from upstream Created 6 years, 5 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
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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 &cpi->fn_ptr[BLOCK_16X16], 0, &best_ref_mv1, ref_mv); 171 &cpi->fn_ptr[BLOCK_16X16], 0, &best_ref_mv1, ref_mv);
172 172
173 // Ignore mv costing by sending NULL pointer instead of cost array 173 // Ignore mv costing by sending NULL pointer instead of cost array
174 bestsme = cpi->find_fractional_mv_step(x, ref_mv, 174 bestsme = cpi->find_fractional_mv_step(x, ref_mv,
175 &best_ref_mv1, 175 &best_ref_mv1,
176 cpi->common.allow_high_precision_mv, 176 cpi->common.allow_high_precision_mv,
177 x->errorperbit, 177 x->errorperbit,
178 &cpi->fn_ptr[BLOCK_16X16], 178 &cpi->fn_ptr[BLOCK_16X16],
179 0, mv_sf->subpel_iters_per_step, 179 0, mv_sf->subpel_iters_per_step,
180 NULL, NULL, 180 NULL, NULL,
181 &distortion, &sse); 181 &distortion, &sse, NULL, 0, 0);
182 182
183 // Restore input state 183 // Restore input state
184 x->plane[0].src = src; 184 x->plane[0].src = src;
185 xd->plane[0].pre[0] = pre; 185 xd->plane[0].pre[0] = pre;
186 186
187 return bestsme; 187 return bestsme;
188 } 188 }
189 189
190 static void temporal_filter_iterate_c(VP9_COMP *cpi, 190 static void temporal_filter_iterate_c(VP9_COMP *cpi,
191 int frame_count, 191 int frame_count,
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 } 348 }
349 mb_y_offset += 16 * (f->y_stride - mb_cols); 349 mb_y_offset += 16 * (f->y_stride - mb_cols);
350 mb_uv_offset += mb_uv_height * f->uv_stride - mb_uv_width * mb_cols; 350 mb_uv_offset += mb_uv_height * f->uv_stride - mb_uv_width * mb_cols;
351 } 351 }
352 352
353 // Restore input state 353 // Restore input state
354 for (i = 0; i < MAX_MB_PLANE; i++) 354 for (i = 0; i < MAX_MB_PLANE; i++)
355 mbd->plane[i].pre[0].buf = input_buffer[i]; 355 mbd->plane[i].pre[0].buf = input_buffer[i];
356 } 356 }
357 357
358 void vp9_temporal_filter_prepare(VP9_COMP *cpi, int distance) { 358 // Apply buffer limits and context specific adjustments to arnr filter.
359 VP9_COMMON *const cm = &cpi->common; 359 static void adjust_arnr_filter(VP9_COMP *cpi,
360 int frame = 0; 360 int distance, int group_boost) {
361 int frames_to_blur_backward = 0; 361 const int frames_after_arf =
362 int frames_to_blur_forward = 0; 362 vp9_lookahead_depth(cpi->lookahead) - distance - 1;
363 int frames_to_blur = 0; 363 int frames_fwd = (cpi->oxcf.arnr_max_frames - 1) >> 1;
364 int start_frame = 0; 364 int frames_bwd;
365 int strength = cpi->active_arnr_strength;
366 int blur_type = cpi->oxcf.arnr_type;
367 int max_frames = cpi->active_arnr_frames;
368 const int num_frames_backward = distance;
369 const int num_frames_forward = vp9_lookahead_depth(cpi->lookahead)
370 - (num_frames_backward + 1);
371 struct scale_factors sf;
372
373 switch (blur_type) {
374 case 1:
375 // Backward Blur
376 frames_to_blur_backward = num_frames_backward;
377
378 if (frames_to_blur_backward >= max_frames)
379 frames_to_blur_backward = max_frames - 1;
380
381 frames_to_blur = frames_to_blur_backward + 1;
382 break;
383
384 case 2:
385 // Forward Blur
386 frames_to_blur_forward = num_frames_forward;
387
388 if (frames_to_blur_forward >= max_frames)
389 frames_to_blur_forward = max_frames - 1;
390
391 frames_to_blur = frames_to_blur_forward + 1;
392 break;
393
394 case 3:
395 default:
396 // Center Blur
397 frames_to_blur_forward = num_frames_forward;
398 frames_to_blur_backward = num_frames_backward;
399
400 if (frames_to_blur_forward > frames_to_blur_backward)
401 frames_to_blur_forward = frames_to_blur_backward;
402
403 if (frames_to_blur_backward > frames_to_blur_forward)
404 frames_to_blur_backward = frames_to_blur_forward;
405
406 // When max_frames is even we have 1 more frame backward than forward
407 if (frames_to_blur_forward > (max_frames - 1) / 2)
408 frames_to_blur_forward = ((max_frames - 1) / 2);
409
410 if (frames_to_blur_backward > (max_frames / 2))
411 frames_to_blur_backward = (max_frames / 2);
412
413 frames_to_blur = frames_to_blur_backward + frames_to_blur_forward + 1;
414 break;
415 }
416
417 start_frame = distance + frames_to_blur_forward;
418
419 #ifdef DEBUGFWG
420 // DEBUG FWG
421 printf(
422 "max:%d FBCK:%d FFWD:%d ftb:%d ftbbck:%d ftbfwd:%d sei:%d lasei:%d "
423 "start:%d",
424 max_frames, num_frames_backward, num_frames_forward, frames_to_blur,
425 frames_to_blur_backward, frames_to_blur_forward, cpi->source_encode_index,
426 cpi->last_alt_ref_sei, start_frame);
427 #endif
428
429 // Setup scaling factors. Scaling on each of the arnr frames is not supported
430 vp9_setup_scale_factors_for_frame(&sf,
431 get_frame_new_buffer(cm)->y_crop_width,
432 get_frame_new_buffer(cm)->y_crop_height,
433 cm->width, cm->height);
434
435 // Setup frame pointers, NULL indicates frame not included in filter
436 vp9_zero(cpi->frames);
437 for (frame = 0; frame < frames_to_blur; frame++) {
438 int which_buffer = start_frame - frame;
439 struct lookahead_entry *buf = vp9_lookahead_peek(cpi->lookahead,
440 which_buffer);
441 cpi->frames[frames_to_blur - 1 - frame] = &buf->img;
442 }
443
444 temporal_filter_iterate_c(cpi, frames_to_blur, frames_to_blur_backward,
445 strength, &sf);
446 }
447
448 void vp9_configure_arnr_filter(VP9_COMP *cpi,
449 const unsigned int frames_to_arnr,
450 const int group_boost) {
451 int half_gf_int;
452 int frames_after_arf;
453 int frames_bwd = cpi->oxcf.arnr_max_frames - 1;
454 int frames_fwd = cpi->oxcf.arnr_max_frames - 1;
455 int q; 365 int q;
456 366
457 // Define the arnr filter width for this group of frames. We only 367 // Define the forward and backwards filter limits for this arnr group.
458 // filter frames that lie within a distance of half the GF interval 368 if (frames_fwd > frames_after_arf)
459 // from the ARF frame. We also have to trap cases where the filter 369 frames_fwd = frames_after_arf;
460 // extends beyond the end of the lookahead buffer. 370 if (frames_fwd > distance)
461 // Note: frames_to_arnr parameter is the offset of the arnr 371 frames_fwd = distance;
462 // frame from the current frame.
463 half_gf_int = cpi->rc.baseline_gf_interval >> 1;
464 frames_after_arf = vp9_lookahead_depth(cpi->lookahead)
465 - frames_to_arnr - 1;
466 372
467 switch (cpi->oxcf.arnr_type) { 373 frames_bwd = frames_fwd;
468 case 1: // Backward filter
469 frames_fwd = 0;
470 if (frames_bwd > half_gf_int)
471 frames_bwd = half_gf_int;
472 break;
473 374
474 case 2: // Forward filter 375 // For even length filter there is one more frame backward
475 if (frames_fwd > half_gf_int) 376 // than forward: e.g. len=6 ==> bbbAff, len=7 ==> bbbAfff.
476 frames_fwd = half_gf_int; 377 if (frames_bwd < distance)
477 if (frames_fwd > frames_after_arf) 378 frames_bwd += (cpi->oxcf.arnr_max_frames + 1) & 0x1;
478 frames_fwd = frames_after_arf;
479 frames_bwd = 0;
480 break;
481 379
482 case 3: // Centered filter 380 // Set the baseline active filter size.
483 default:
484 frames_fwd >>= 1;
485 if (frames_fwd > frames_after_arf)
486 frames_fwd = frames_after_arf;
487 if (frames_fwd > half_gf_int)
488 frames_fwd = half_gf_int;
489
490 frames_bwd = frames_fwd;
491
492 // For even length filter there is one more frame backward
493 // than forward: e.g. len=6 ==> bbbAff, len=7 ==> bbbAfff.
494 if (frames_bwd < half_gf_int)
495 frames_bwd += (cpi->oxcf.arnr_max_frames + 1) & 0x1;
496 break;
497 }
498
499 cpi->active_arnr_frames = frames_bwd + 1 + frames_fwd; 381 cpi->active_arnr_frames = frames_bwd + 1 + frames_fwd;
500 382
501 // Adjust the strength based on active max q 383 // Adjust the strength based on active max q.
502 if (cpi->common.current_video_frame > 1) 384 if (cpi->common.current_video_frame > 1)
503 q = ((int)vp9_convert_qindex_to_q( 385 q = ((int)vp9_convert_qindex_to_q(
504 cpi->rc.avg_frame_qindex[INTER_FRAME])); 386 cpi->rc.avg_frame_qindex[INTER_FRAME]));
505 else 387 else
506 q = ((int)vp9_convert_qindex_to_q( 388 q = ((int)vp9_convert_qindex_to_q(
507 cpi->rc.avg_frame_qindex[KEY_FRAME])); 389 cpi->rc.avg_frame_qindex[KEY_FRAME]));
508 if (q > 16) { 390 if (q > 16) {
509 cpi->active_arnr_strength = cpi->oxcf.arnr_strength; 391 cpi->active_arnr_strength = cpi->oxcf.arnr_strength;
510 } else { 392 } else {
511 cpi->active_arnr_strength = cpi->oxcf.arnr_strength - ((16 - q) / 2); 393 cpi->active_arnr_strength = cpi->oxcf.arnr_strength - ((16 - q) / 2);
512 if (cpi->active_arnr_strength < 0) 394 if (cpi->active_arnr_strength < 0)
513 cpi->active_arnr_strength = 0; 395 cpi->active_arnr_strength = 0;
514 } 396 }
515 397
516 // Adjust number of frames in filter and strength based on gf boost level. 398 // Adjust number of frames in filter and strength based on gf boost level.
517 if (cpi->active_arnr_frames > (group_boost / 150)) { 399 if (cpi->active_arnr_frames > (group_boost / 150)) {
518 cpi->active_arnr_frames = (group_boost / 150); 400 cpi->active_arnr_frames = (group_boost / 150);
519 cpi->active_arnr_frames += !(cpi->active_arnr_frames & 1); 401 cpi->active_arnr_frames += !(cpi->active_arnr_frames & 1);
520 } 402 }
521 if (cpi->active_arnr_strength > (group_boost / 300)) { 403 if (cpi->active_arnr_strength > (group_boost / 300)) {
522 cpi->active_arnr_strength = (group_boost / 300); 404 cpi->active_arnr_strength = (group_boost / 300);
523 } 405 }
406
407 // Adjustments for second level arf in multi arf case.
408 if (cpi->pass == 2 && cpi->multi_arf_allowed) {
409 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
410 if (gf_group->rf_level[gf_group->index] != GF_ARF_STD) {
411 cpi->active_arnr_strength >>= 1;
412 }
413 }
524 } 414 }
415
416 void vp9_temporal_filter(VP9_COMP *cpi, int distance) {
417 VP9_COMMON *const cm = &cpi->common;
418 RATE_CONTROL *const rc = &cpi->rc;
419 int frame;
420 int frames_to_blur;
421 int start_frame;
422 int strength;
423 int frames_to_blur_backward;
424 int frames_to_blur_forward;
425 struct scale_factors sf;
426
427 // Apply context specific adjustments to the arnr filter parameters.
428 adjust_arnr_filter(cpi, distance, rc->gfu_boost);
429 strength = cpi->active_arnr_strength;
430 frames_to_blur = cpi->active_arnr_frames;
431 frames_to_blur_backward = (frames_to_blur / 2);
432 frames_to_blur_forward = ((frames_to_blur - 1) / 2);
433 start_frame = distance + frames_to_blur_forward;
434
435 // Setup scaling factors. Scaling on each of the arnr frames not supported.
436 vp9_setup_scale_factors_for_frame(&sf,
437 get_frame_new_buffer(cm)->y_crop_width,
438 get_frame_new_buffer(cm)->y_crop_height,
439 cm->width, cm->height);
440
441 // Setup frame pointers, NULL indicates frame not included in filter.
442 vp9_zero(cpi->frames);
443 for (frame = 0; frame < frames_to_blur; ++frame) {
444 const int which_buffer = start_frame - frame;
445 struct lookahead_entry *buf = vp9_lookahead_peek(cpi->lookahead,
446 which_buffer);
447 cpi->frames[frames_to_blur - 1 - frame] = &buf->img;
448 }
449
450 temporal_filter_iterate_c(cpi, frames_to_blur, frames_to_blur_backward,
451 strength, &sf);
452 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_temporal_filter.h ('k') | source/libvpx/vp9/encoder/x86/vp9_quantize_ssse3_x86_64.asm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698