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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 #define ALTREF_HIGH_PRECISION_MV 1 // Whether to use high precision mv | 58 #define ALTREF_HIGH_PRECISION_MV 1 // Whether to use high precision mv |
59 // for altref computation. | 59 // for altref computation. |
60 #define HIGH_PRECISION_MV_QTHRESH 200 // Q threshold for high precision | 60 #define HIGH_PRECISION_MV_QTHRESH 200 // Q threshold for high precision |
61 // mv. Choose a very high value for | 61 // mv. Choose a very high value for |
62 // now so that HIGH_PRECISION is always | 62 // now so that HIGH_PRECISION is always |
63 // chosen. | 63 // chosen. |
64 | 64 |
65 // #define OUTPUT_YUV_REC | 65 // #define OUTPUT_YUV_REC |
66 | 66 |
| 67 #ifdef OUTPUT_YUV_DENOISED |
| 68 FILE *yuv_denoised_file; |
| 69 #endif |
67 #ifdef OUTPUT_YUV_SRC | 70 #ifdef OUTPUT_YUV_SRC |
68 FILE *yuv_file; | 71 FILE *yuv_file; |
69 #endif | 72 #endif |
70 #ifdef OUTPUT_YUV_REC | 73 #ifdef OUTPUT_YUV_REC |
71 FILE *yuv_rec_file; | 74 FILE *yuv_rec_file; |
72 #endif | 75 #endif |
73 | 76 |
74 #if 0 | 77 #if 0 |
75 FILE *framepsnr; | 78 FILE *framepsnr; |
76 FILE *kf_list; | 79 FILE *kf_list; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 183 |
181 vp9_free_frame_buffer(&cpi->last_frame_uf); | 184 vp9_free_frame_buffer(&cpi->last_frame_uf); |
182 vp9_free_frame_buffer(&cpi->scaled_source); | 185 vp9_free_frame_buffer(&cpi->scaled_source); |
183 vp9_free_frame_buffer(&cpi->scaled_last_source); | 186 vp9_free_frame_buffer(&cpi->scaled_last_source); |
184 vp9_free_frame_buffer(&cpi->alt_ref_buffer); | 187 vp9_free_frame_buffer(&cpi->alt_ref_buffer); |
185 vp9_lookahead_destroy(cpi->lookahead); | 188 vp9_lookahead_destroy(cpi->lookahead); |
186 | 189 |
187 vpx_free(cpi->tok); | 190 vpx_free(cpi->tok); |
188 cpi->tok = 0; | 191 cpi->tok = 0; |
189 | 192 |
190 vp9_free_pc_tree(&cpi->mb); | 193 vp9_free_pc_tree(cpi); |
191 | 194 |
192 for (i = 0; i < cpi->svc.number_spatial_layers; ++i) { | 195 for (i = 0; i < cpi->svc.number_spatial_layers; ++i) { |
193 LAYER_CONTEXT *const lc = &cpi->svc.layer_context[i]; | 196 LAYER_CONTEXT *const lc = &cpi->svc.layer_context[i]; |
194 vpx_free(lc->rc_twopass_stats_in.buf); | 197 vpx_free(lc->rc_twopass_stats_in.buf); |
195 lc->rc_twopass_stats_in.buf = NULL; | 198 lc->rc_twopass_stats_in.buf = NULL; |
196 lc->rc_twopass_stats_in.sz = 0; | 199 lc->rc_twopass_stats_in.sz = 0; |
197 } | 200 } |
198 } | 201 } |
199 | 202 |
200 static void save_coding_context(VP9_COMP *cpi) { | 203 static void save_coding_context(VP9_COMP *cpi) { |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 int i; | 389 int i; |
387 for (i = 0; i < MAX_MODES; ++i) | 390 for (i = 0; i < MAX_MODES; ++i) |
388 cpi->mode_chosen_counts[i] = 0; | 391 cpi->mode_chosen_counts[i] = 0; |
389 #endif | 392 #endif |
390 | 393 |
391 vp9_set_speed_features(cpi); | 394 vp9_set_speed_features(cpi); |
392 | 395 |
393 // Set rd thresholds based on mode and speed setting | 396 // Set rd thresholds based on mode and speed setting |
394 vp9_set_rd_speed_thresholds(cpi); | 397 vp9_set_rd_speed_thresholds(cpi); |
395 vp9_set_rd_speed_thresholds_sub8x8(cpi); | 398 vp9_set_rd_speed_thresholds_sub8x8(cpi); |
396 | |
397 cpi->mb.fwd_txm4x4 = vp9_fdct4x4; | |
398 if (cpi->oxcf.lossless || cpi->mb.e_mbd.lossless) { | |
399 cpi->mb.fwd_txm4x4 = vp9_fwht4x4; | |
400 } | |
401 } | 399 } |
402 | 400 |
403 static void alloc_raw_frame_buffers(VP9_COMP *cpi) { | 401 static void alloc_raw_frame_buffers(VP9_COMP *cpi) { |
404 VP9_COMMON *cm = &cpi->common; | 402 VP9_COMMON *cm = &cpi->common; |
405 const VP9EncoderConfig *oxcf = &cpi->oxcf; | 403 const VP9EncoderConfig *oxcf = &cpi->oxcf; |
406 | 404 |
407 cpi->lookahead = vp9_lookahead_init(oxcf->width, oxcf->height, | 405 cpi->lookahead = vp9_lookahead_init(oxcf->width, oxcf->height, |
408 cm->subsampling_x, cm->subsampling_y, | 406 cm->subsampling_x, cm->subsampling_y, |
409 oxcf->lag_in_frames); | 407 oxcf->lag_in_frames); |
410 if (!cpi->lookahead) | 408 if (!cpi->lookahead) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 "Failed to allocate scaled last source buffer"); | 446 "Failed to allocate scaled last source buffer"); |
449 | 447 |
450 vpx_free(cpi->tok); | 448 vpx_free(cpi->tok); |
451 | 449 |
452 { | 450 { |
453 unsigned int tokens = get_token_alloc(cm->mb_rows, cm->mb_cols); | 451 unsigned int tokens = get_token_alloc(cm->mb_rows, cm->mb_cols); |
454 | 452 |
455 CHECK_MEM_ERROR(cm, cpi->tok, vpx_calloc(tokens, sizeof(*cpi->tok))); | 453 CHECK_MEM_ERROR(cm, cpi->tok, vpx_calloc(tokens, sizeof(*cpi->tok))); |
456 } | 454 } |
457 | 455 |
458 vp9_setup_pc_tree(&cpi->common, &cpi->mb); | 456 vp9_setup_pc_tree(&cpi->common, cpi); |
459 } | 457 } |
460 | 458 |
461 static void update_frame_size(VP9_COMP *cpi) { | 459 static void update_frame_size(VP9_COMP *cpi) { |
462 VP9_COMMON *const cm = &cpi->common; | 460 VP9_COMMON *const cm = &cpi->common; |
463 MACROBLOCKD *const xd = &cpi->mb.e_mbd; | 461 MACROBLOCKD *const xd = &cpi->mb.e_mbd; |
464 | 462 |
465 vp9_update_frame_size(cm); | 463 vp9_update_frame_size(cm); |
466 | 464 |
467 // Update size of buffers local to this frame | 465 // Update size of buffers local to this frame |
468 if (vp9_realloc_frame_buffer(&cpi->last_frame_uf, | 466 if (vp9_realloc_frame_buffer(&cpi->last_frame_uf, |
(...skipping 13 matching lines...) Expand all Loading... |
482 if (vp9_realloc_frame_buffer(&cpi->scaled_last_source, | 480 if (vp9_realloc_frame_buffer(&cpi->scaled_last_source, |
483 cm->width, cm->height, | 481 cm->width, cm->height, |
484 cm->subsampling_x, cm->subsampling_y, | 482 cm->subsampling_x, cm->subsampling_y, |
485 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) | 483 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) |
486 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 484 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
487 "Failed to reallocate scaled last source buffer"); | 485 "Failed to reallocate scaled last source buffer"); |
488 | 486 |
489 { | 487 { |
490 int y_stride = cpi->scaled_source.y_stride; | 488 int y_stride = cpi->scaled_source.y_stride; |
491 | 489 |
492 if (cpi->sf.search_method == NSTEP) { | 490 if (cpi->sf.mv.search_method == NSTEP) { |
493 vp9_init3smotion_compensation(&cpi->ss_cfg, y_stride); | 491 vp9_init3smotion_compensation(&cpi->ss_cfg, y_stride); |
494 } else if (cpi->sf.search_method == DIAMOND) { | 492 } else if (cpi->sf.mv.search_method == DIAMOND) { |
495 vp9_init_dsmotion_compensation(&cpi->ss_cfg, y_stride); | 493 vp9_init_dsmotion_compensation(&cpi->ss_cfg, y_stride); |
496 } | 494 } |
497 } | 495 } |
498 | 496 |
499 init_macroblockd(cm, xd); | 497 init_macroblockd(cm, xd); |
500 } | 498 } |
501 | 499 |
502 void vp9_new_framerate(VP9_COMP *cpi, double framerate) { | 500 void vp9_new_framerate(VP9_COMP *cpi, double framerate) { |
503 cpi->oxcf.framerate = framerate < 0.1 ? 30 : framerate; | 501 cpi->oxcf.framerate = framerate < 0.1 ? 30 : framerate; |
504 vp9_rc_update_framerate(cpi); | 502 vp9_rc_update_framerate(cpi); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 cm->subsampling_x = 0; | 534 cm->subsampling_x = 0; |
537 cm->subsampling_y = 0; | 535 cm->subsampling_y = 0; |
538 vp9_alloc_compressor_data(cpi); | 536 vp9_alloc_compressor_data(cpi); |
539 | 537 |
540 // Spatial scalability. | 538 // Spatial scalability. |
541 cpi->svc.number_spatial_layers = oxcf->ss_number_layers; | 539 cpi->svc.number_spatial_layers = oxcf->ss_number_layers; |
542 // Temporal scalability. | 540 // Temporal scalability. |
543 cpi->svc.number_temporal_layers = oxcf->ts_number_layers; | 541 cpi->svc.number_temporal_layers = oxcf->ts_number_layers; |
544 | 542 |
545 if ((cpi->svc.number_temporal_layers > 1 && | 543 if ((cpi->svc.number_temporal_layers > 1 && |
546 cpi->oxcf.rc_mode == RC_MODE_CBR) || | 544 cpi->oxcf.rc_mode == VPX_CBR) || |
547 (cpi->svc.number_spatial_layers > 1 && | 545 (cpi->svc.number_spatial_layers > 1 && |
548 cpi->oxcf.mode == TWO_PASS_SECOND_BEST)) { | 546 cpi->oxcf.mode == TWO_PASS_SECOND_BEST)) { |
549 vp9_init_layer_context(cpi); | 547 vp9_init_layer_context(cpi); |
550 } | 548 } |
551 | 549 |
552 // change includes all joint functionality | 550 // change includes all joint functionality |
553 vp9_change_config(cpi, oxcf); | 551 vp9_change_config(cpi, oxcf); |
554 | 552 |
555 cpi->static_mb_pct = 0; | 553 cpi->static_mb_pct = 0; |
556 | 554 |
(...skipping 29 matching lines...) Expand all Loading... |
586 cm->profile = oxcf->profile; | 584 cm->profile = oxcf->profile; |
587 cm->bit_depth = oxcf->bit_depth; | 585 cm->bit_depth = oxcf->bit_depth; |
588 | 586 |
589 if (cm->profile <= PROFILE_1) | 587 if (cm->profile <= PROFILE_1) |
590 assert(cm->bit_depth == BITS_8); | 588 assert(cm->bit_depth == BITS_8); |
591 else | 589 else |
592 assert(cm->bit_depth > BITS_8); | 590 assert(cm->bit_depth > BITS_8); |
593 | 591 |
594 cpi->oxcf = *oxcf; | 592 cpi->oxcf = *oxcf; |
595 cpi->pass = get_pass(cpi->oxcf.mode); | 593 cpi->pass = get_pass(cpi->oxcf.mode); |
596 if (cpi->oxcf.mode == REALTIME) | |
597 cpi->oxcf.play_alternate = 0; | |
598 | 594 |
599 cpi->oxcf.lossless = oxcf->lossless; | |
600 if (cpi->oxcf.lossless) { | |
601 // In lossless mode, make sure right quantizer range and correct transform | |
602 // is set. | |
603 cpi->oxcf.worst_allowed_q = 0; | |
604 cpi->oxcf.best_allowed_q = 0; | |
605 cpi->mb.e_mbd.itxm_add = vp9_iwht4x4_add; | |
606 } else { | |
607 cpi->mb.e_mbd.itxm_add = vp9_idct4x4_add; | |
608 } | |
609 rc->baseline_gf_interval = DEFAULT_GF_INTERVAL; | 595 rc->baseline_gf_interval = DEFAULT_GF_INTERVAL; |
610 cpi->ref_frame_flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG; | 596 cpi->ref_frame_flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG; |
611 | 597 |
612 cpi->refresh_golden_frame = 0; | 598 cpi->refresh_golden_frame = 0; |
613 cpi->refresh_last_frame = 1; | 599 cpi->refresh_last_frame = 1; |
614 cm->refresh_frame_context = 1; | 600 cm->refresh_frame_context = 1; |
615 cm->reset_frame_context = 0; | 601 cm->reset_frame_context = 0; |
616 | 602 |
617 vp9_reset_segment_features(&cm->seg); | 603 vp9_reset_segment_features(&cm->seg); |
618 set_high_precision_mv(cpi, 0); | 604 set_high_precision_mv(cpi, 0); |
619 | 605 |
620 { | 606 { |
621 int i; | 607 int i; |
622 | 608 |
623 for (i = 0; i < MAX_SEGMENTS; i++) | 609 for (i = 0; i < MAX_SEGMENTS; i++) |
624 cpi->segment_encode_breakout[i] = cpi->oxcf.encode_breakout; | 610 cpi->segment_encode_breakout[i] = cpi->oxcf.encode_breakout; |
625 } | 611 } |
626 cpi->encode_breakout = cpi->oxcf.encode_breakout; | 612 cpi->encode_breakout = cpi->oxcf.encode_breakout; |
627 | 613 |
628 // local file playback mode == really big buffer | 614 // local file playback mode == really big buffer |
629 if (cpi->oxcf.rc_mode == RC_MODE_VBR) { | 615 if (cpi->oxcf.rc_mode == VPX_VBR) { |
630 cpi->oxcf.starting_buffer_level = 60000; | 616 cpi->oxcf.starting_buffer_level_ms = 60000; |
631 cpi->oxcf.optimal_buffer_level = 60000; | 617 cpi->oxcf.optimal_buffer_level_ms = 60000; |
632 cpi->oxcf.maximum_buffer_size = 240000; | 618 cpi->oxcf.maximum_buffer_size_ms = 240000; |
633 } | 619 } |
634 | 620 |
635 // Convert target bandwidth from Kbit/s to Bit/s | 621 rc->starting_buffer_level = vp9_rescale(cpi->oxcf.starting_buffer_level_ms, |
636 cpi->oxcf.target_bandwidth *= 1000; | 622 cpi->oxcf.target_bandwidth, 1000); |
637 | |
638 cpi->oxcf.starting_buffer_level = | |
639 vp9_rescale(cpi->oxcf.starting_buffer_level, | |
640 cpi->oxcf.target_bandwidth, 1000); | |
641 | 623 |
642 // Set or reset optimal and maximum buffer levels. | 624 // Set or reset optimal and maximum buffer levels. |
643 if (cpi->oxcf.optimal_buffer_level == 0) | 625 if (cpi->oxcf.optimal_buffer_level_ms == 0) |
644 cpi->oxcf.optimal_buffer_level = cpi->oxcf.target_bandwidth / 8; | 626 rc->optimal_buffer_level = cpi->oxcf.target_bandwidth / 8; |
645 else | 627 else |
646 cpi->oxcf.optimal_buffer_level = | 628 rc->optimal_buffer_level = vp9_rescale(cpi->oxcf.optimal_buffer_level_ms, |
647 vp9_rescale(cpi->oxcf.optimal_buffer_level, | 629 cpi->oxcf.target_bandwidth, 1000); |
648 cpi->oxcf.target_bandwidth, 1000); | |
649 | 630 |
650 if (cpi->oxcf.maximum_buffer_size == 0) | 631 if (cpi->oxcf.maximum_buffer_size_ms == 0) |
651 cpi->oxcf.maximum_buffer_size = cpi->oxcf.target_bandwidth / 8; | 632 rc->maximum_buffer_size = cpi->oxcf.target_bandwidth / 8; |
652 else | 633 else |
653 cpi->oxcf.maximum_buffer_size = | 634 rc->maximum_buffer_size = vp9_rescale(cpi->oxcf.maximum_buffer_size_ms, |
654 vp9_rescale(cpi->oxcf.maximum_buffer_size, | 635 cpi->oxcf.target_bandwidth, 1000); |
655 cpi->oxcf.target_bandwidth, 1000); | |
656 // Under a configuration change, where maximum_buffer_size may change, | 636 // Under a configuration change, where maximum_buffer_size may change, |
657 // keep buffer level clipped to the maximum allowed buffer size. | 637 // keep buffer level clipped to the maximum allowed buffer size. |
658 rc->bits_off_target = MIN(rc->bits_off_target, cpi->oxcf.maximum_buffer_size); | 638 rc->bits_off_target = MIN(rc->bits_off_target, rc->maximum_buffer_size); |
659 rc->buffer_level = MIN(rc->buffer_level, cpi->oxcf.maximum_buffer_size); | 639 rc->buffer_level = MIN(rc->buffer_level, rc->maximum_buffer_size); |
660 | 640 |
661 // Set up frame rate and related parameters rate control values. | 641 // Set up frame rate and related parameters rate control values. |
662 vp9_new_framerate(cpi, cpi->oxcf.framerate); | 642 vp9_new_framerate(cpi, cpi->oxcf.framerate); |
663 | 643 |
664 // Set absolute upper and lower quality limits | 644 // Set absolute upper and lower quality limits |
665 rc->worst_quality = cpi->oxcf.worst_allowed_q; | 645 rc->worst_quality = cpi->oxcf.worst_allowed_q; |
666 rc->best_quality = cpi->oxcf.best_allowed_q; | 646 rc->best_quality = cpi->oxcf.best_allowed_q; |
667 | 647 |
668 cm->interp_filter = DEFAULT_INTERP_FILTER; | 648 cm->interp_filter = DEFAULT_INTERP_FILTER; |
669 | 649 |
670 cm->display_width = cpi->oxcf.width; | 650 cm->display_width = cpi->oxcf.width; |
671 cm->display_height = cpi->oxcf.height; | 651 cm->display_height = cpi->oxcf.height; |
672 | 652 |
673 if (cpi->initial_width) { | 653 if (cpi->initial_width) { |
674 // Increasing the size of the frame beyond the first seen frame, or some | 654 // Increasing the size of the frame beyond the first seen frame, or some |
675 // otherwise signaled maximum size, is not supported. | 655 // otherwise signaled maximum size, is not supported. |
676 // TODO(jkoleszar): exit gracefully. | 656 // TODO(jkoleszar): exit gracefully. |
677 assert(cm->width <= cpi->initial_width); | 657 assert(cm->width <= cpi->initial_width); |
678 assert(cm->height <= cpi->initial_height); | 658 assert(cm->height <= cpi->initial_height); |
679 } | 659 } |
680 update_frame_size(cpi); | 660 update_frame_size(cpi); |
681 | 661 |
682 if ((cpi->svc.number_temporal_layers > 1 && | 662 if ((cpi->svc.number_temporal_layers > 1 && |
683 cpi->oxcf.rc_mode == RC_MODE_CBR) || | 663 cpi->oxcf.rc_mode == VPX_CBR) || |
684 (cpi->svc.number_spatial_layers > 1 && cpi->pass == 2)) { | 664 (cpi->svc.number_spatial_layers > 1 && cpi->pass == 2)) { |
685 vp9_update_layer_context_change_config(cpi, | 665 vp9_update_layer_context_change_config(cpi, |
686 (int)cpi->oxcf.target_bandwidth); | 666 (int)cpi->oxcf.target_bandwidth); |
687 } | 667 } |
688 | 668 |
689 #if CONFIG_MULTIPLE_ARF | 669 #if CONFIG_MULTIPLE_ARF |
690 vp9_zero(cpi->alt_ref_source); | 670 vp9_zero(cpi->alt_ref_source); |
691 #else | 671 #else |
692 cpi->alt_ref_source = NULL; | 672 cpi->alt_ref_source = NULL; |
693 #endif | 673 #endif |
694 rc->is_src_frame_alt_ref = 0; | 674 rc->is_src_frame_alt_ref = 0; |
695 | 675 |
696 #if 0 | 676 #if 0 |
697 // Experimental RD Code | 677 // Experimental RD Code |
698 cpi->frame_distortion = 0; | 678 cpi->frame_distortion = 0; |
699 cpi->last_frame_distortion = 0; | 679 cpi->last_frame_distortion = 0; |
700 #endif | 680 #endif |
701 | 681 |
702 set_tile_limits(cpi); | 682 set_tile_limits(cpi); |
703 | 683 |
704 cpi->ext_refresh_frame_flags_pending = 0; | 684 cpi->ext_refresh_frame_flags_pending = 0; |
705 cpi->ext_refresh_frame_context_pending = 0; | 685 cpi->ext_refresh_frame_context_pending = 0; |
| 686 |
| 687 #if CONFIG_DENOISING |
| 688 vp9_denoiser_alloc(&(cpi->denoiser), cm->width, cm->height, |
| 689 // TODO(tkopp) An unrelated bug causes |
| 690 // cm->subsampling_{x,y} to be uninitialized at this point |
| 691 // in execution. For now we assume YUV-420, which is x/y |
| 692 // subsampling of 1. |
| 693 1, 1, |
| 694 // cm->subsampling_x, cm->subsampling_y, |
| 695 VP9_ENC_BORDER_IN_PIXELS); |
| 696 #endif |
706 } | 697 } |
707 | 698 |
708 #ifndef M_LOG2_E | 699 #ifndef M_LOG2_E |
709 #define M_LOG2_E 0.693147180559945309417 | 700 #define M_LOG2_E 0.693147180559945309417 |
710 #endif | 701 #endif |
711 #define log2f(x) (log (x) / (float) M_LOG2_E) | 702 #define log2f(x) (log (x) / (float) M_LOG2_E) |
712 | 703 |
713 static void cal_nmvjointsadcost(int *mvjointsadcost) { | 704 static void cal_nmvjointsadcost(int *mvjointsadcost) { |
714 mvjointsadcost[0] = 600; | 705 mvjointsadcost[0] = 600; |
715 mvjointsadcost[1] = 300; | 706 mvjointsadcost[1] = 300; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 cpi->mb.nmvsadcost[0] = &cpi->mb.nmvsadcosts[0][MV_MAX]; | 862 cpi->mb.nmvsadcost[0] = &cpi->mb.nmvsadcosts[0][MV_MAX]; |
872 cpi->mb.nmvsadcost[1] = &cpi->mb.nmvsadcosts[1][MV_MAX]; | 863 cpi->mb.nmvsadcost[1] = &cpi->mb.nmvsadcosts[1][MV_MAX]; |
873 cal_nmvsadcosts(cpi->mb.nmvsadcost); | 864 cal_nmvsadcosts(cpi->mb.nmvsadcost); |
874 | 865 |
875 cpi->mb.nmvcost_hp[0] = &cpi->mb.nmvcosts_hp[0][MV_MAX]; | 866 cpi->mb.nmvcost_hp[0] = &cpi->mb.nmvcosts_hp[0][MV_MAX]; |
876 cpi->mb.nmvcost_hp[1] = &cpi->mb.nmvcosts_hp[1][MV_MAX]; | 867 cpi->mb.nmvcost_hp[1] = &cpi->mb.nmvcosts_hp[1][MV_MAX]; |
877 cpi->mb.nmvsadcost_hp[0] = &cpi->mb.nmvsadcosts_hp[0][MV_MAX]; | 868 cpi->mb.nmvsadcost_hp[0] = &cpi->mb.nmvsadcosts_hp[0][MV_MAX]; |
878 cpi->mb.nmvsadcost_hp[1] = &cpi->mb.nmvsadcosts_hp[1][MV_MAX]; | 869 cpi->mb.nmvsadcost_hp[1] = &cpi->mb.nmvsadcosts_hp[1][MV_MAX]; |
879 cal_nmvsadcosts_hp(cpi->mb.nmvsadcost_hp); | 870 cal_nmvsadcosts_hp(cpi->mb.nmvsadcost_hp); |
880 | 871 |
| 872 #ifdef OUTPUT_YUV_DENOISED |
| 873 yuv_denoised_file = fopen("denoised.yuv", "ab"); |
| 874 #endif |
881 #ifdef OUTPUT_YUV_SRC | 875 #ifdef OUTPUT_YUV_SRC |
882 yuv_file = fopen("bd.yuv", "ab"); | 876 yuv_file = fopen("bd.yuv", "ab"); |
883 #endif | 877 #endif |
884 #ifdef OUTPUT_YUV_REC | 878 #ifdef OUTPUT_YUV_REC |
885 yuv_rec_file = fopen("rec.yuv", "wb"); | 879 yuv_rec_file = fopen("rec.yuv", "wb"); |
886 #endif | 880 #endif |
887 | 881 |
888 #if 0 | 882 #if 0 |
889 framepsnr = fopen("framepsnr.stt", "a"); | 883 framepsnr = fopen("framepsnr.stt", "a"); |
890 kf_list = fopen("kf_list.stt", "w"); | 884 kf_list = fopen("kf_list.stt", "w"); |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000); | 1095 printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000); |
1102 printf("\n_frames recive_data encod_mb_row compress_frame Total\n"); | 1096 printf("\n_frames recive_data encod_mb_row compress_frame Total\n"); |
1103 printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame, | 1097 printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame, |
1104 cpi->time_receive_data / 1000, cpi->time_encode_sb_row / 1000, | 1098 cpi->time_receive_data / 1000, cpi->time_encode_sb_row / 1000, |
1105 cpi->time_compress_data / 1000, | 1099 cpi->time_compress_data / 1000, |
1106 (cpi->time_receive_data + cpi->time_compress_data) / 1000); | 1100 (cpi->time_receive_data + cpi->time_compress_data) / 1000); |
1107 } | 1101 } |
1108 #endif | 1102 #endif |
1109 } | 1103 } |
1110 | 1104 |
| 1105 #if CONFIG_DENOISING |
| 1106 vp9_denoiser_free(&(cpi->denoiser)); |
| 1107 #endif |
| 1108 |
1111 dealloc_compressor_data(cpi); | 1109 dealloc_compressor_data(cpi); |
1112 vpx_free(cpi->tok); | 1110 vpx_free(cpi->tok); |
1113 | 1111 |
1114 for (i = 0; i < sizeof(cpi->mbgraph_stats) / | 1112 for (i = 0; i < sizeof(cpi->mbgraph_stats) / |
1115 sizeof(cpi->mbgraph_stats[0]); ++i) { | 1113 sizeof(cpi->mbgraph_stats[0]); ++i) { |
1116 vpx_free(cpi->mbgraph_stats[i].mb_stats); | 1114 vpx_free(cpi->mbgraph_stats[i].mb_stats); |
1117 } | 1115 } |
1118 | 1116 |
1119 vp9_remove_common(&cpi->common); | 1117 vp9_remove_common(&cpi->common); |
1120 vpx_free(cpi); | 1118 vpx_free(cpi); |
1121 | 1119 |
| 1120 #ifdef OUTPUT_YUV_DENOISED |
| 1121 fclose(yuv_denoised_file); |
| 1122 #endif |
1122 #ifdef OUTPUT_YUV_SRC | 1123 #ifdef OUTPUT_YUV_SRC |
1123 fclose(yuv_file); | 1124 fclose(yuv_file); |
1124 #endif | 1125 #endif |
1125 #ifdef OUTPUT_YUV_REC | 1126 #ifdef OUTPUT_YUV_REC |
1126 fclose(yuv_rec_file); | 1127 fclose(yuv_rec_file); |
1127 #endif | 1128 #endif |
1128 | 1129 |
1129 #if 0 | 1130 #if 0 |
1130 | 1131 |
1131 if (keyfile) | 1132 if (keyfile) |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 } | 1294 } |
1294 } | 1295 } |
1295 | 1296 |
1296 int vp9_update_entropy(VP9_COMP * cpi, int update) { | 1297 int vp9_update_entropy(VP9_COMP * cpi, int update) { |
1297 cpi->ext_refresh_frame_context = update; | 1298 cpi->ext_refresh_frame_context = update; |
1298 cpi->ext_refresh_frame_context_pending = 1; | 1299 cpi->ext_refresh_frame_context_pending = 1; |
1299 return 0; | 1300 return 0; |
1300 } | 1301 } |
1301 | 1302 |
1302 | 1303 |
1303 #ifdef OUTPUT_YUV_SRC | 1304 #if defined(OUTPUT_YUV_SRC) || defined(OUTPUT_YUV_DENOISED) |
1304 void vp9_write_yuv_frame(YV12_BUFFER_CONFIG *s) { | 1305 void vp9_write_yuv_frame(YV12_BUFFER_CONFIG *s, FILE *f) { |
1305 uint8_t *src = s->y_buffer; | 1306 uint8_t *src = s->y_buffer; |
1306 int h = s->y_height; | 1307 int h = s->y_height; |
1307 | 1308 |
1308 do { | 1309 do { |
1309 fwrite(src, s->y_width, 1, yuv_file); | 1310 fwrite(src, s->y_width, 1, f); |
1310 src += s->y_stride; | 1311 src += s->y_stride; |
1311 } while (--h); | 1312 } while (--h); |
1312 | 1313 |
1313 src = s->u_buffer; | 1314 src = s->u_buffer; |
1314 h = s->uv_height; | 1315 h = s->uv_height; |
1315 | 1316 |
1316 do { | 1317 do { |
1317 fwrite(src, s->uv_width, 1, yuv_file); | 1318 fwrite(src, s->uv_width, 1, f); |
1318 src += s->uv_stride; | 1319 src += s->uv_stride; |
1319 } while (--h); | 1320 } while (--h); |
1320 | 1321 |
1321 src = s->v_buffer; | 1322 src = s->v_buffer; |
1322 h = s->uv_height; | 1323 h = s->uv_height; |
1323 | 1324 |
1324 do { | 1325 do { |
1325 fwrite(src, s->uv_width, 1, yuv_file); | 1326 fwrite(src, s->uv_width, 1, f); |
1326 src += s->uv_stride; | 1327 src += s->uv_stride; |
1327 } while (--h); | 1328 } while (--h); |
1328 } | 1329 } |
1329 #endif | 1330 #endif |
1330 | 1331 |
1331 #ifdef OUTPUT_YUV_REC | 1332 #ifdef OUTPUT_YUV_REC |
1332 void vp9_write_yuv_rec_frame(VP9_COMMON *cm) { | 1333 void vp9_write_yuv_rec_frame(VP9_COMMON *cm) { |
1333 YV12_BUFFER_CONFIG *s = cm->frame_to_show; | 1334 YV12_BUFFER_CONFIG *s = cm->frame_to_show; |
1334 uint8_t *src = s->y_buffer; | 1335 uint8_t *src = s->y_buffer; |
1335 int h = cm->height; | 1336 int h = cm->height; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1407 const int dst_w = dst->y_crop_width; | 1408 const int dst_w = dst->y_crop_width; |
1408 const int dst_h = dst->y_crop_height; | 1409 const int dst_h = dst->y_crop_height; |
1409 const uint8_t *const srcs[4] = {src->y_buffer, src->u_buffer, src->v_buffer, | 1410 const uint8_t *const srcs[4] = {src->y_buffer, src->u_buffer, src->v_buffer, |
1410 src->alpha_buffer}; | 1411 src->alpha_buffer}; |
1411 const int src_strides[4] = {src->y_stride, src->uv_stride, src->uv_stride, | 1412 const int src_strides[4] = {src->y_stride, src->uv_stride, src->uv_stride, |
1412 src->alpha_stride}; | 1413 src->alpha_stride}; |
1413 uint8_t *const dsts[4] = {dst->y_buffer, dst->u_buffer, dst->v_buffer, | 1414 uint8_t *const dsts[4] = {dst->y_buffer, dst->u_buffer, dst->v_buffer, |
1414 dst->alpha_buffer}; | 1415 dst->alpha_buffer}; |
1415 const int dst_strides[4] = {dst->y_stride, dst->uv_stride, dst->uv_stride, | 1416 const int dst_strides[4] = {dst->y_stride, dst->uv_stride, dst->uv_stride, |
1416 dst->alpha_stride}; | 1417 dst->alpha_stride}; |
| 1418 const InterpKernel *const kernel = vp9_get_interp_kernel(EIGHTTAP); |
1417 int x, y, i; | 1419 int x, y, i; |
1418 | 1420 |
1419 for (y = 0; y < dst_h; y += 16) { | 1421 for (y = 0; y < dst_h; y += 16) { |
1420 for (x = 0; x < dst_w; x += 16) { | 1422 for (x = 0; x < dst_w; x += 16) { |
1421 for (i = 0; i < MAX_MB_PLANE; ++i) { | 1423 for (i = 0; i < MAX_MB_PLANE; ++i) { |
1422 const int factor = (i == 0 || i == 3 ? 1 : 2); | 1424 const int factor = (i == 0 || i == 3 ? 1 : 2); |
1423 const int x_q4 = x * (16 / factor) * src_w / dst_w; | 1425 const int x_q4 = x * (16 / factor) * src_w / dst_w; |
1424 const int y_q4 = y * (16 / factor) * src_h / dst_h; | 1426 const int y_q4 = y * (16 / factor) * src_h / dst_h; |
1425 const int src_stride = src_strides[i]; | 1427 const int src_stride = src_strides[i]; |
1426 const int dst_stride = dst_strides[i]; | 1428 const int dst_stride = dst_strides[i]; |
1427 const uint8_t *src_ptr = srcs[i] + (y / factor) * src_h / dst_h * | 1429 const uint8_t *src_ptr = srcs[i] + (y / factor) * src_h / dst_h * |
1428 src_stride + (x / factor) * src_w / dst_w; | 1430 src_stride + (x / factor) * src_w / dst_w; |
1429 uint8_t *dst_ptr = dsts[i] + (y / factor) * dst_stride + (x / factor); | 1431 uint8_t *dst_ptr = dsts[i] + (y / factor) * dst_stride + (x / factor); |
1430 | 1432 |
1431 vp9_convolve8(src_ptr, src_stride, dst_ptr, dst_stride, | 1433 vp9_convolve8(src_ptr, src_stride, dst_ptr, dst_stride, |
1432 vp9_sub_pel_filters_8[x_q4 & 0xf], 16 * src_w / dst_w, | 1434 kernel[x_q4 & 0xf], 16 * src_w / dst_w, |
1433 vp9_sub_pel_filters_8[y_q4 & 0xf], 16 * src_h / dst_h, | 1435 kernel[y_q4 & 0xf], 16 * src_h / dst_h, |
1434 16 / factor, 16 / factor); | 1436 16 / factor, 16 / factor); |
1435 } | 1437 } |
1436 } | 1438 } |
1437 } | 1439 } |
1438 | 1440 |
1439 // TODO(hkuang): Call C version explicitly | 1441 // TODO(hkuang): Call C version explicitly |
1440 // as neon version only expand border size 32. | 1442 // as neon version only expand border size 32. |
1441 vp8_yv12_extend_frame_borders_c(dst); | 1443 vp8_yv12_extend_frame_borders_c(dst); |
1442 } | 1444 } |
1443 | 1445 |
1444 static int find_fp_qindex() { | |
1445 int i; | |
1446 | |
1447 for (i = 0; i < QINDEX_RANGE; i++) { | |
1448 if (vp9_convert_qindex_to_q(i) >= 30.0) { | |
1449 break; | |
1450 } | |
1451 } | |
1452 | |
1453 if (i == QINDEX_RANGE) | |
1454 i--; | |
1455 | |
1456 return i; | |
1457 } | |
1458 | |
1459 #define WRITE_RECON_BUFFER 0 | 1446 #define WRITE_RECON_BUFFER 0 |
1460 #if WRITE_RECON_BUFFER | 1447 #if WRITE_RECON_BUFFER |
1461 void write_cx_frame_to_file(YV12_BUFFER_CONFIG *frame, int this_frame) { | 1448 void write_cx_frame_to_file(YV12_BUFFER_CONFIG *frame, int this_frame) { |
1462 FILE *yframe; | 1449 FILE *yframe; |
1463 int i; | 1450 int i; |
1464 char filename[255]; | 1451 char filename[255]; |
1465 | 1452 |
1466 snprintf(filename, sizeof(filename), "cx\\y%04d.raw", this_frame); | 1453 snprintf(filename, sizeof(filename), "cx\\y%04d.raw", this_frame); |
1467 yframe = fopen(filename, "wb"); | 1454 yframe = fopen(filename, "wb"); |
1468 | 1455 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1508 // Yes if either recode mode 1 is selected or mode 2 is selected | 1495 // Yes if either recode mode 1 is selected or mode 2 is selected |
1509 // and the frame is a key frame, golden frame or alt_ref_frame | 1496 // and the frame is a key frame, golden frame or alt_ref_frame |
1510 } else if ((cpi->sf.recode_loop == ALLOW_RECODE) || | 1497 } else if ((cpi->sf.recode_loop == ALLOW_RECODE) || |
1511 ((cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF) && | 1498 ((cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF) && |
1512 (cm->frame_type == KEY_FRAME || | 1499 (cm->frame_type == KEY_FRAME || |
1513 cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame))) { | 1500 cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame))) { |
1514 // General over and under shoot tests | 1501 // General over and under shoot tests |
1515 if ((rc->projected_frame_size > high_limit && q < maxq) || | 1502 if ((rc->projected_frame_size > high_limit && q < maxq) || |
1516 (rc->projected_frame_size < low_limit && q > minq)) { | 1503 (rc->projected_frame_size < low_limit && q > minq)) { |
1517 force_recode = 1; | 1504 force_recode = 1; |
1518 } else if (cpi->oxcf.rc_mode == RC_MODE_CONSTRAINED_QUALITY) { | 1505 } else if (cpi->oxcf.rc_mode == VPX_CQ) { |
1519 // Deal with frame undershoot and whether or not we are | 1506 // Deal with frame undershoot and whether or not we are |
1520 // below the automatically set cq level. | 1507 // below the automatically set cq level. |
1521 if (q > oxcf->cq_level && | 1508 if (q > oxcf->cq_level && |
1522 rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { | 1509 rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { |
1523 force_recode = 1; | 1510 force_recode = 1; |
1524 } | 1511 } |
1525 } | 1512 } |
1526 } | 1513 } |
1527 return force_recode; | 1514 return force_recode; |
1528 } | 1515 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1577 if (cpi->refresh_golden_frame) { | 1564 if (cpi->refresh_golden_frame) { |
1578 ref_cnt_fb(cm->frame_bufs, | 1565 ref_cnt_fb(cm->frame_bufs, |
1579 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx); | 1566 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx); |
1580 } | 1567 } |
1581 } | 1568 } |
1582 | 1569 |
1583 if (cpi->refresh_last_frame) { | 1570 if (cpi->refresh_last_frame) { |
1584 ref_cnt_fb(cm->frame_bufs, | 1571 ref_cnt_fb(cm->frame_bufs, |
1585 &cm->ref_frame_map[cpi->lst_fb_idx], cm->new_fb_idx); | 1572 &cm->ref_frame_map[cpi->lst_fb_idx], cm->new_fb_idx); |
1586 } | 1573 } |
| 1574 #if CONFIG_DENOISING |
| 1575 vp9_denoiser_update_frame_info(&cpi->denoiser, |
| 1576 *cpi->Source, |
| 1577 cpi->common.frame_type, |
| 1578 cpi->refresh_alt_ref_frame, |
| 1579 cpi->refresh_golden_frame, |
| 1580 cpi->refresh_last_frame); |
| 1581 #endif |
1587 } | 1582 } |
1588 | 1583 |
1589 static void loopfilter_frame(VP9_COMP *cpi, VP9_COMMON *cm) { | 1584 static void loopfilter_frame(VP9_COMP *cpi, VP9_COMMON *cm) { |
1590 MACROBLOCKD *xd = &cpi->mb.e_mbd; | 1585 MACROBLOCKD *xd = &cpi->mb.e_mbd; |
1591 struct loopfilter *lf = &cm->lf; | 1586 struct loopfilter *lf = &cm->lf; |
1592 if (xd->lossless) { | 1587 if (xd->lossless) { |
1593 lf->filter_level = 0; | 1588 lf->filter_level = 0; |
1594 } else { | 1589 } else { |
1595 struct vpx_usec_timer timer; | 1590 struct vpx_usec_timer timer; |
1596 | 1591 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1681 "%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf" | 1676 "%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf" |
1682 "%6d %6d %5d %5d %5d " | 1677 "%6d %6d %5d %5d %5d " |
1683 "%10"PRId64" %10.3lf" | 1678 "%10"PRId64" %10.3lf" |
1684 "%10lf %8u %10d %10d %10d\n", | 1679 "%10lf %8u %10d %10d %10d\n", |
1685 cpi->common.current_video_frame, cpi->rc.this_frame_target, | 1680 cpi->common.current_video_frame, cpi->rc.this_frame_target, |
1686 cpi->rc.projected_frame_size, | 1681 cpi->rc.projected_frame_size, |
1687 cpi->rc.projected_frame_size / cpi->common.MBs, | 1682 cpi->rc.projected_frame_size / cpi->common.MBs, |
1688 (cpi->rc.projected_frame_size - cpi->rc.this_frame_target), | 1683 (cpi->rc.projected_frame_size - cpi->rc.this_frame_target), |
1689 cpi->rc.vbr_bits_off_target, | 1684 cpi->rc.vbr_bits_off_target, |
1690 cpi->rc.total_target_vs_actual, | 1685 cpi->rc.total_target_vs_actual, |
1691 (cpi->oxcf.starting_buffer_level - cpi->rc.bits_off_target), | 1686 (cpi->rc.starting_buffer_level - cpi->rc.bits_off_target), |
1692 cpi->rc.total_actual_bits, cm->base_qindex, | 1687 cpi->rc.total_actual_bits, cm->base_qindex, |
1693 vp9_convert_qindex_to_q(cm->base_qindex), | 1688 vp9_convert_qindex_to_q(cm->base_qindex), |
1694 (double)vp9_dc_quant(cm->base_qindex, 0) / 4.0, | 1689 (double)vp9_dc_quant(cm->base_qindex, 0) / 4.0, |
1695 cpi->rc.avg_q, | 1690 cpi->rc.avg_q, |
1696 vp9_convert_qindex_to_q(cpi->rc.ni_av_qi), | 1691 vp9_convert_qindex_to_q(cpi->rc.ni_av_qi), |
1697 vp9_convert_qindex_to_q(cpi->oxcf.cq_level), | 1692 vp9_convert_qindex_to_q(cpi->oxcf.cq_level), |
1698 cpi->refresh_last_frame, cpi->refresh_golden_frame, | 1693 cpi->refresh_last_frame, cpi->refresh_golden_frame, |
1699 cpi->refresh_alt_ref_frame, cm->frame_type, cpi->rc.gfu_boost, | 1694 cpi->refresh_alt_ref_frame, cm->frame_type, cpi->rc.gfu_boost, |
1700 cpi->twopass.bits_left, | 1695 cpi->twopass.bits_left, |
1701 cpi->twopass.total_left_stats.coded_error, | 1696 cpi->twopass.total_left_stats.coded_error, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1803 if (!cpi->sf.use_nonrd_pick_mode) | 1798 if (!cpi->sf.use_nonrd_pick_mode) |
1804 vp9_pack_bitstream(cpi, dest, size); | 1799 vp9_pack_bitstream(cpi, dest, size); |
1805 | 1800 |
1806 rc->projected_frame_size = (int)(*size) << 3; | 1801 rc->projected_frame_size = (int)(*size) << 3; |
1807 restore_coding_context(cpi); | 1802 restore_coding_context(cpi); |
1808 | 1803 |
1809 if (frame_over_shoot_limit == 0) | 1804 if (frame_over_shoot_limit == 0) |
1810 frame_over_shoot_limit = 1; | 1805 frame_over_shoot_limit = 1; |
1811 } | 1806 } |
1812 | 1807 |
1813 if (cpi->oxcf.rc_mode == RC_MODE_CONSTANT_QUALITY) { | 1808 if (cpi->oxcf.rc_mode == VPX_Q) { |
1814 loop = 0; | 1809 loop = 0; |
1815 } else { | 1810 } else { |
1816 if ((cm->frame_type == KEY_FRAME) && | 1811 if ((cm->frame_type == KEY_FRAME) && |
1817 rc->this_key_frame_forced && | 1812 rc->this_key_frame_forced && |
1818 (rc->projected_frame_size < rc->max_frame_bandwidth)) { | 1813 (rc->projected_frame_size < rc->max_frame_bandwidth)) { |
1819 int last_q = q; | 1814 int last_q = q; |
1820 int kf_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm)); | 1815 int kf_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm)); |
1821 | 1816 |
1822 int high_err_target = cpi->ambient_err; | 1817 int high_err_target = cpi->ambient_err; |
1823 int low_err_target = cpi->ambient_err >> 1; | 1818 int low_err_target = cpi->ambient_err >> 1; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1901 vp9_rc_update_rate_correction_factors(cpi, 1); | 1896 vp9_rc_update_rate_correction_factors(cpi, 1); |
1902 q = (q_high + q_low) / 2; | 1897 q = (q_high + q_low) / 2; |
1903 } else { | 1898 } else { |
1904 vp9_rc_update_rate_correction_factors(cpi, 0); | 1899 vp9_rc_update_rate_correction_factors(cpi, 0); |
1905 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, | 1900 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, |
1906 bottom_index, top_index); | 1901 bottom_index, top_index); |
1907 // Special case reset for qlow for constrained quality. | 1902 // Special case reset for qlow for constrained quality. |
1908 // This should only trigger where there is very substantial | 1903 // This should only trigger where there is very substantial |
1909 // undershoot on a frame and the auto cq level is above | 1904 // undershoot on a frame and the auto cq level is above |
1910 // the user passsed in value. | 1905 // the user passsed in value. |
1911 if (cpi->oxcf.rc_mode == RC_MODE_CONSTRAINED_QUALITY && | 1906 if (cpi->oxcf.rc_mode == VPX_CQ && |
1912 q < q_low) { | 1907 q < q_low) { |
1913 q_low = q; | 1908 q_low = q; |
1914 } | 1909 } |
1915 | 1910 |
1916 while (q > q_high && retries < 10) { | 1911 while (q > q_high && retries < 10) { |
1917 vp9_rc_update_rate_correction_factors(cpi, 0); | 1912 vp9_rc_update_rate_correction_factors(cpi, 0); |
1918 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, | 1913 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, |
1919 bottom_index, top_index); | 1914 bottom_index, top_index); |
1920 retries++; | 1915 retries++; |
1921 } | 1916 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2042 | 2037 |
2043 // Current default encoder behavior for the altref sign bias. | 2038 // Current default encoder behavior for the altref sign bias. |
2044 cm->ref_frame_sign_bias[ALTREF_FRAME] = cpi->rc.source_alt_ref_active; | 2039 cm->ref_frame_sign_bias[ALTREF_FRAME] = cpi->rc.source_alt_ref_active; |
2045 | 2040 |
2046 // Set default state for segment based loop filter update flags. | 2041 // Set default state for segment based loop filter update flags. |
2047 cm->lf.mode_ref_delta_update = 0; | 2042 cm->lf.mode_ref_delta_update = 0; |
2048 | 2043 |
2049 // Initialize cpi->mv_step_param to default based on max resolution. | 2044 // Initialize cpi->mv_step_param to default based on max resolution. |
2050 cpi->mv_step_param = vp9_init_search_range(sf, max_mv_def); | 2045 cpi->mv_step_param = vp9_init_search_range(sf, max_mv_def); |
2051 // Initialize cpi->max_mv_magnitude and cpi->mv_step_param if appropriate. | 2046 // Initialize cpi->max_mv_magnitude and cpi->mv_step_param if appropriate. |
2052 if (sf->auto_mv_step_size) { | 2047 if (sf->mv.auto_mv_step_size) { |
2053 if (frame_is_intra_only(cm)) { | 2048 if (frame_is_intra_only(cm)) { |
2054 // Initialize max_mv_magnitude for use in the first INTER frame | 2049 // Initialize max_mv_magnitude for use in the first INTER frame |
2055 // after a key/intra-only frame. | 2050 // after a key/intra-only frame. |
2056 cpi->max_mv_magnitude = max_mv_def; | 2051 cpi->max_mv_magnitude = max_mv_def; |
2057 } else { | 2052 } else { |
2058 if (cm->show_frame) | 2053 if (cm->show_frame) |
2059 // Allow mv_steps to correspond to twice the max mv magnitude found | 2054 // Allow mv_steps to correspond to twice the max mv magnitude found |
2060 // in the previous frame, capped by the default max_mv_magnitude based | 2055 // in the previous frame, capped by the default max_mv_magnitude based |
2061 // on resolution. | 2056 // on resolution. |
2062 cpi->mv_step_param = vp9_init_search_range(sf, MIN(max_mv_def, 2 * | 2057 cpi->mv_step_param = vp9_init_search_range(sf, MIN(max_mv_def, 2 * |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2099 // Configure experimental use of segmentation for enhanced coding of | 2094 // Configure experimental use of segmentation for enhanced coding of |
2100 // static regions if indicated. | 2095 // static regions if indicated. |
2101 // Only allowed in second pass of two pass (as requires lagged coding) | 2096 // Only allowed in second pass of two pass (as requires lagged coding) |
2102 // and if the relevant speed feature flag is set. | 2097 // and if the relevant speed feature flag is set. |
2103 if (cpi->pass == 2 && cpi->sf.static_segmentation) | 2098 if (cpi->pass == 2 && cpi->sf.static_segmentation) |
2104 configure_static_seg_features(cpi); | 2099 configure_static_seg_features(cpi); |
2105 | 2100 |
2106 // For 1 pass CBR, check if we are dropping this frame. | 2101 // For 1 pass CBR, check if we are dropping this frame. |
2107 // Never drop on key frame. | 2102 // Never drop on key frame. |
2108 if (cpi->pass == 0 && | 2103 if (cpi->pass == 0 && |
2109 cpi->oxcf.rc_mode == RC_MODE_CBR && | 2104 cpi->oxcf.rc_mode == VPX_CBR && |
2110 cm->frame_type != KEY_FRAME) { | 2105 cm->frame_type != KEY_FRAME) { |
2111 if (vp9_rc_drop_frame(cpi)) { | 2106 if (vp9_rc_drop_frame(cpi)) { |
2112 vp9_rc_postencode_update_drop_frame(cpi); | 2107 vp9_rc_postencode_update_drop_frame(cpi); |
2113 ++cm->current_video_frame; | 2108 ++cm->current_video_frame; |
2114 return; | 2109 return; |
2115 } | 2110 } |
2116 } | 2111 } |
2117 | 2112 |
2118 vp9_clear_system_state(); | 2113 vp9_clear_system_state(); |
2119 | 2114 |
2120 vp9_zero(cpi->rd.tx_select_threshes); | |
2121 | |
2122 #if CONFIG_VP9_POSTPROC | 2115 #if CONFIG_VP9_POSTPROC |
2123 if (cpi->oxcf.noise_sensitivity > 0) { | 2116 if (cpi->oxcf.noise_sensitivity > 0) { |
2124 int l = 0; | 2117 int l = 0; |
2125 switch (cpi->oxcf.noise_sensitivity) { | 2118 switch (cpi->oxcf.noise_sensitivity) { |
2126 case 1: | 2119 case 1: |
2127 l = 20; | 2120 l = 20; |
2128 break; | 2121 break; |
2129 case 2: | 2122 case 2: |
2130 l = 40; | 2123 l = 40; |
2131 break; | 2124 break; |
2132 case 3: | 2125 case 3: |
2133 l = 60; | 2126 l = 60; |
2134 break; | 2127 break; |
2135 case 4: | 2128 case 4: |
2136 case 5: | 2129 case 5: |
2137 l = 100; | 2130 l = 100; |
2138 break; | 2131 break; |
2139 case 6: | 2132 case 6: |
2140 l = 150; | 2133 l = 150; |
2141 break; | 2134 break; |
2142 } | 2135 } |
2143 vp9_denoise(cpi->Source, cpi->Source, l); | 2136 vp9_denoise(cpi->Source, cpi->Source, l); |
2144 } | 2137 } |
2145 #endif | 2138 #endif |
2146 | 2139 |
| 2140 #ifdef OUTPUT_YUV_DENOISED |
| 2141 vp9_write_yuv_frame(&cpi->denoiser.running_avg_y[INTRA_FRAME], |
| 2142 yuv_denoised_file); |
| 2143 #endif |
2147 #ifdef OUTPUT_YUV_SRC | 2144 #ifdef OUTPUT_YUV_SRC |
2148 vp9_write_yuv_frame(cpi->Source); | 2145 vp9_write_yuv_frame(cpi->Source, yuv_file); |
2149 #endif | 2146 #endif |
2150 | 2147 |
2151 set_speed_features(cpi); | 2148 set_speed_features(cpi); |
2152 | 2149 |
2153 // Decide q and q bounds. | 2150 // Decide q and q bounds. |
2154 q = vp9_rc_pick_q_and_bounds(cpi, &bottom_index, &top_index); | 2151 q = vp9_rc_pick_q_and_bounds(cpi, &bottom_index, &top_index); |
2155 | 2152 |
2156 if (!frame_is_intra_only(cm)) { | 2153 if (!frame_is_intra_only(cm)) { |
2157 cm->interp_filter = DEFAULT_INTERP_FILTER; | 2154 cm->interp_filter = DEFAULT_INTERP_FILTER; |
2158 /* TODO: Decide this more intelligently */ | 2155 /* TODO: Decide this more intelligently */ |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2297 } | 2294 } |
2298 | 2295 |
2299 static void SvcEncode(VP9_COMP *cpi, size_t *size, uint8_t *dest, | 2296 static void SvcEncode(VP9_COMP *cpi, size_t *size, uint8_t *dest, |
2300 unsigned int *frame_flags) { | 2297 unsigned int *frame_flags) { |
2301 vp9_rc_get_svc_params(cpi); | 2298 vp9_rc_get_svc_params(cpi); |
2302 encode_frame_to_data_rate(cpi, size, dest, frame_flags); | 2299 encode_frame_to_data_rate(cpi, size, dest, frame_flags); |
2303 } | 2300 } |
2304 | 2301 |
2305 static void Pass0Encode(VP9_COMP *cpi, size_t *size, uint8_t *dest, | 2302 static void Pass0Encode(VP9_COMP *cpi, size_t *size, uint8_t *dest, |
2306 unsigned int *frame_flags) { | 2303 unsigned int *frame_flags) { |
2307 if (cpi->oxcf.rc_mode == RC_MODE_CBR) { | 2304 if (cpi->oxcf.rc_mode == VPX_CBR) { |
2308 vp9_rc_get_one_pass_cbr_params(cpi); | 2305 vp9_rc_get_one_pass_cbr_params(cpi); |
2309 } else { | 2306 } else { |
2310 vp9_rc_get_one_pass_vbr_params(cpi); | 2307 vp9_rc_get_one_pass_vbr_params(cpi); |
2311 } | 2308 } |
2312 encode_frame_to_data_rate(cpi, size, dest, frame_flags); | 2309 encode_frame_to_data_rate(cpi, size, dest, frame_flags); |
2313 } | 2310 } |
2314 | 2311 |
2315 static void Pass1Encode(VP9_COMP *cpi, size_t *size, uint8_t *dest, | |
2316 unsigned int *frame_flags) { | |
2317 (void) size; | |
2318 (void) dest; | |
2319 (void) frame_flags; | |
2320 | |
2321 vp9_rc_get_first_pass_params(cpi); | |
2322 vp9_set_quantizer(&cpi->common, find_fp_qindex()); | |
2323 vp9_first_pass(cpi); | |
2324 } | |
2325 | |
2326 static void Pass2Encode(VP9_COMP *cpi, size_t *size, | 2312 static void Pass2Encode(VP9_COMP *cpi, size_t *size, |
2327 uint8_t *dest, unsigned int *frame_flags) { | 2313 uint8_t *dest, unsigned int *frame_flags) { |
2328 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED; | 2314 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED; |
2329 | 2315 |
2330 vp9_rc_get_second_pass_params(cpi); | 2316 vp9_rc_get_second_pass_params(cpi); |
2331 encode_frame_to_data_rate(cpi, size, dest, frame_flags); | 2317 encode_frame_to_data_rate(cpi, size, dest, frame_flags); |
2332 | 2318 |
2333 vp9_twopass_postencode_update(cpi); | 2319 vp9_twopass_postencode_update(cpi); |
2334 } | 2320 } |
2335 | 2321 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2457 set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV); | 2443 set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV); |
2458 | 2444 |
2459 // Normal defaults | 2445 // Normal defaults |
2460 cm->reset_frame_context = 0; | 2446 cm->reset_frame_context = 0; |
2461 cm->refresh_frame_context = 1; | 2447 cm->refresh_frame_context = 1; |
2462 cpi->refresh_last_frame = 1; | 2448 cpi->refresh_last_frame = 1; |
2463 cpi->refresh_golden_frame = 0; | 2449 cpi->refresh_golden_frame = 0; |
2464 cpi->refresh_alt_ref_frame = 0; | 2450 cpi->refresh_alt_ref_frame = 0; |
2465 | 2451 |
2466 // Should we code an alternate reference frame. | 2452 // Should we code an alternate reference frame. |
2467 if (cpi->oxcf.play_alternate && rc->source_alt_ref_pending) { | 2453 if (is_altref_enabled(&cpi->oxcf) && rc->source_alt_ref_pending) { |
2468 int frames_to_arf; | 2454 int frames_to_arf; |
2469 | 2455 |
2470 #if CONFIG_MULTIPLE_ARF | 2456 #if CONFIG_MULTIPLE_ARF |
2471 assert(!cpi->multi_arf_enabled || | 2457 assert(!cpi->multi_arf_enabled || |
2472 cpi->frame_coding_order[cpi->sequence_number] < 0); | 2458 cpi->frame_coding_order[cpi->sequence_number] < 0); |
2473 | 2459 |
2474 if (cpi->multi_arf_enabled && (cpi->pass == 2)) | 2460 if (cpi->multi_arf_enabled && (cpi->pass == 2)) |
2475 frames_to_arf = (-cpi->frame_coding_order[cpi->sequence_number]) | 2461 frames_to_arf = (-cpi->frame_coding_order[cpi->sequence_number]) |
2476 - cpi->next_frame_in_order; | 2462 - cpi->next_frame_in_order; |
2477 else | 2463 else |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2588 cpi->first_time_stamp_ever = cpi->source->ts_start; | 2574 cpi->first_time_stamp_ever = cpi->source->ts_start; |
2589 cpi->last_end_time_stamp_seen = cpi->source->ts_start; | 2575 cpi->last_end_time_stamp_seen = cpi->source->ts_start; |
2590 } | 2576 } |
2591 | 2577 |
2592 // adjust frame rates based on timestamps given | 2578 // adjust frame rates based on timestamps given |
2593 if (cm->show_frame) { | 2579 if (cm->show_frame) { |
2594 adjust_frame_rate(cpi); | 2580 adjust_frame_rate(cpi); |
2595 } | 2581 } |
2596 | 2582 |
2597 if (cpi->svc.number_temporal_layers > 1 && | 2583 if (cpi->svc.number_temporal_layers > 1 && |
2598 cpi->oxcf.rc_mode == RC_MODE_CBR) { | 2584 cpi->oxcf.rc_mode == VPX_CBR) { |
2599 vp9_update_temporal_layer_framerate(cpi); | 2585 vp9_update_temporal_layer_framerate(cpi); |
2600 vp9_restore_layer_context(cpi); | 2586 vp9_restore_layer_context(cpi); |
2601 } | 2587 } |
2602 | 2588 |
2603 // start with a 0 size frame | 2589 // start with a 0 size frame |
2604 *size = 0; | 2590 *size = 0; |
2605 | 2591 |
2606 // Clear down mmx registers | 2592 // Clear down mmx registers |
2607 vp9_clear_system_state(); | 2593 vp9_clear_system_state(); |
2608 | 2594 |
(...skipping 12 matching lines...) Expand all Loading... |
2621 (cpi->pass == 2)) { | 2607 (cpi->pass == 2)) { |
2622 cpi->alt_fb_idx = cpi->arf_buffer_idx[cpi->sequence_number]; | 2608 cpi->alt_fb_idx = cpi->arf_buffer_idx[cpi->sequence_number]; |
2623 } | 2609 } |
2624 #endif | 2610 #endif |
2625 | 2611 |
2626 cpi->frame_flags = *frame_flags; | 2612 cpi->frame_flags = *frame_flags; |
2627 | 2613 |
2628 if (cpi->pass == 2 && | 2614 if (cpi->pass == 2 && |
2629 cm->current_video_frame == 0 && | 2615 cm->current_video_frame == 0 && |
2630 cpi->oxcf.allow_spatial_resampling && | 2616 cpi->oxcf.allow_spatial_resampling && |
2631 cpi->oxcf.rc_mode == RC_MODE_VBR) { | 2617 cpi->oxcf.rc_mode == VPX_VBR) { |
2632 // Internal scaling is triggered on the first frame. | 2618 // Internal scaling is triggered on the first frame. |
2633 vp9_set_size_literal(cpi, cpi->oxcf.scaled_frame_width, | 2619 vp9_set_size_literal(cpi, cpi->oxcf.scaled_frame_width, |
2634 cpi->oxcf.scaled_frame_height); | 2620 cpi->oxcf.scaled_frame_height); |
2635 } | 2621 } |
2636 | 2622 |
2637 // Reset the frame pointers to the current frame size | 2623 // Reset the frame pointers to the current frame size |
2638 vp9_realloc_frame_buffer(get_frame_new_buffer(cm), | 2624 vp9_realloc_frame_buffer(get_frame_new_buffer(cm), |
2639 cm->width, cm->height, | 2625 cm->width, cm->height, |
2640 cm->subsampling_x, cm->subsampling_y, | 2626 cm->subsampling_x, cm->subsampling_y, |
2641 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL); | 2627 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL); |
(...skipping 13 matching lines...) Expand all Loading... |
2655 } | 2641 } |
2656 | 2642 |
2657 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); | 2643 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); |
2658 | 2644 |
2659 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { | 2645 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
2660 vp9_vaq_init(); | 2646 vp9_vaq_init(); |
2661 } | 2647 } |
2662 | 2648 |
2663 if (cpi->pass == 1 && | 2649 if (cpi->pass == 1 && |
2664 (!cpi->use_svc || cpi->svc.number_temporal_layers == 1)) { | 2650 (!cpi->use_svc || cpi->svc.number_temporal_layers == 1)) { |
2665 Pass1Encode(cpi, size, dest, frame_flags); | 2651 const int lossless = is_lossless_requested(&cpi->oxcf); |
| 2652 cpi->mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vp9_fdct4x4; |
| 2653 cpi->mb.itxm_add = lossless ? vp9_iwht4x4_add : vp9_idct4x4_add; |
| 2654 vp9_first_pass(cpi); |
2666 } else if (cpi->pass == 2 && | 2655 } else if (cpi->pass == 2 && |
2667 (!cpi->use_svc || cpi->svc.number_temporal_layers == 1)) { | 2656 (!cpi->use_svc || cpi->svc.number_temporal_layers == 1)) { |
2668 Pass2Encode(cpi, size, dest, frame_flags); | 2657 Pass2Encode(cpi, size, dest, frame_flags); |
2669 } else if (cpi->use_svc) { | 2658 } else if (cpi->use_svc) { |
2670 SvcEncode(cpi, size, dest, frame_flags); | 2659 SvcEncode(cpi, size, dest, frame_flags); |
2671 } else { | 2660 } else { |
2672 // One pass encode | 2661 // One pass encode |
2673 Pass0Encode(cpi, size, dest, frame_flags); | 2662 Pass0Encode(cpi, size, dest, frame_flags); |
2674 } | 2663 } |
2675 | 2664 |
2676 if (cm->refresh_frame_context) | 2665 if (cm->refresh_frame_context) |
2677 cm->frame_contexts[cm->frame_context_idx] = cm->fc; | 2666 cm->frame_contexts[cm->frame_context_idx] = cm->fc; |
2678 | 2667 |
2679 // Frame was dropped, release scaled references. | 2668 // Frame was dropped, release scaled references. |
2680 if (*size == 0) { | 2669 if (*size == 0) { |
2681 release_scaled_references(cpi); | 2670 release_scaled_references(cpi); |
2682 } | 2671 } |
2683 | 2672 |
2684 if (*size > 0) { | 2673 if (*size > 0) { |
2685 cpi->droppable = !frame_is_reference(cpi); | 2674 cpi->droppable = !frame_is_reference(cpi); |
2686 } | 2675 } |
2687 | 2676 |
2688 // Save layer specific state. | 2677 // Save layer specific state. |
2689 if ((cpi->svc.number_temporal_layers > 1 && | 2678 if ((cpi->svc.number_temporal_layers > 1 && |
2690 cpi->oxcf.rc_mode == RC_MODE_CBR) || | 2679 cpi->oxcf.rc_mode == VPX_CBR) || |
2691 (cpi->svc.number_spatial_layers > 1 && cpi->pass == 2)) { | 2680 (cpi->svc.number_spatial_layers > 1 && cpi->pass == 2)) { |
2692 vp9_save_layer_context(cpi); | 2681 vp9_save_layer_context(cpi); |
2693 } | 2682 } |
2694 | 2683 |
2695 vpx_usec_timer_mark(&cmptimer); | 2684 vpx_usec_timer_mark(&cmptimer); |
2696 cpi->time_compress_data += vpx_usec_timer_elapsed(&cmptimer); | 2685 cpi->time_compress_data += vpx_usec_timer_elapsed(&cmptimer); |
2697 | 2686 |
2698 if (cpi->b_calculate_psnr && cpi->pass != 1 && cm->show_frame) | 2687 if (cpi->b_calculate_psnr && cpi->pass != 1 && cm->show_frame) |
2699 generate_psnr_packet(cpi); | 2688 generate_psnr_packet(cpi); |
2700 | 2689 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2887 assert(a->y_crop_height == b->y_crop_height); | 2876 assert(a->y_crop_height == b->y_crop_height); |
2888 | 2877 |
2889 return (int)get_sse(a->y_buffer, a->y_stride, b->y_buffer, b->y_stride, | 2878 return (int)get_sse(a->y_buffer, a->y_stride, b->y_buffer, b->y_stride, |
2890 a->y_crop_width, a->y_crop_height); | 2879 a->y_crop_width, a->y_crop_height); |
2891 } | 2880 } |
2892 | 2881 |
2893 | 2882 |
2894 int vp9_get_quantizer(VP9_COMP *cpi) { | 2883 int vp9_get_quantizer(VP9_COMP *cpi) { |
2895 return cpi->common.base_qindex; | 2884 return cpi->common.base_qindex; |
2896 } | 2885 } |
OLD | NEW |