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

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

Issue 1019863002: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_mcomp.c ('k') | source/libvpx/vp9/encoder/vp9_rd.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) 2014 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2014 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 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 608
609 typedef struct { 609 typedef struct {
610 MV_REFERENCE_FRAME ref_frame; 610 MV_REFERENCE_FRAME ref_frame;
611 PREDICTION_MODE pred_mode; 611 PREDICTION_MODE pred_mode;
612 } REF_MODE; 612 } REF_MODE;
613 613
614 #define RT_INTER_MODES 8 614 #define RT_INTER_MODES 8
615 static const REF_MODE ref_mode_set[RT_INTER_MODES] = { 615 static const REF_MODE ref_mode_set[RT_INTER_MODES] = {
616 {LAST_FRAME, ZEROMV}, 616 {LAST_FRAME, ZEROMV},
617 {LAST_FRAME, NEARESTMV}, 617 {LAST_FRAME, NEARESTMV},
618 {GOLDEN_FRAME, ZEROMV},
618 {LAST_FRAME, NEARMV}, 619 {LAST_FRAME, NEARMV},
619 {LAST_FRAME, NEWMV}, 620 {LAST_FRAME, NEWMV},
620 {GOLDEN_FRAME, ZEROMV},
621 {GOLDEN_FRAME, NEARESTMV}, 621 {GOLDEN_FRAME, NEARESTMV},
622 {GOLDEN_FRAME, NEARMV}, 622 {GOLDEN_FRAME, NEARMV},
623 {GOLDEN_FRAME, NEWMV} 623 {GOLDEN_FRAME, NEWMV}
624 }; 624 };
625 625
626 // TODO(jingning) placeholder for inter-frame non-RD mode decision. 626 // TODO(jingning) placeholder for inter-frame non-RD mode decision.
627 // this needs various further optimizations. to be continued.. 627 // this needs various further optimizations. to be continued..
628 void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, 628 void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
629 TileDataEnc *tile_data, 629 TileDataEnc *tile_data,
630 int mi_row, int mi_col, RD_COST *rd_cost, 630 int mi_row, int mi_col, RD_COST *rd_cost,
631 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) { 631 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) {
632 VP9_COMMON *const cm = &cpi->common; 632 VP9_COMMON *const cm = &cpi->common;
633 TileInfo *const tile_info = &tile_data->tile_info; 633 TileInfo *const tile_info = &tile_data->tile_info;
634 MACROBLOCKD *const xd = &x->e_mbd; 634 MACROBLOCKD *const xd = &x->e_mbd;
635 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; 635 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi;
636 struct macroblockd_plane *const pd = &xd->plane[0]; 636 struct macroblockd_plane *const pd = &xd->plane[0];
637 PREDICTION_MODE best_mode = ZEROMV; 637 PREDICTION_MODE best_mode = ZEROMV;
638 MV_REFERENCE_FRAME ref_frame, best_ref_frame = LAST_FRAME; 638 MV_REFERENCE_FRAME ref_frame, best_ref_frame = LAST_FRAME;
639 MV_REFERENCE_FRAME usable_ref_frame;
639 TX_SIZE best_tx_size = TX_SIZES; 640 TX_SIZE best_tx_size = TX_SIZES;
640 INTERP_FILTER best_pred_filter = EIGHTTAP; 641 INTERP_FILTER best_pred_filter = EIGHTTAP;
641 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; 642 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES];
642 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; 643 struct buf_2d yv12_mb[4][MAX_MB_PLANE];
643 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, 644 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
644 VP9_ALT_FLAG }; 645 VP9_ALT_FLAG };
645 RD_COST this_rdc, best_rdc; 646 RD_COST this_rdc, best_rdc;
646 uint8_t skip_txfm = 0, best_mode_skip_txfm = 0; 647 uint8_t skip_txfm = 0, best_mode_skip_txfm = 0;
647 // var_y and sse_y are saved to be used in skipping checking 648 // var_y and sse_y are saved to be used in skipping checking
648 unsigned int var_y = UINT_MAX; 649 unsigned int var_y = UINT_MAX;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 filter_ref = cm->interp_filter; 712 filter_ref = cm->interp_filter;
712 713
713 // initialize mode decisions 714 // initialize mode decisions
714 vp9_rd_cost_reset(&best_rdc); 715 vp9_rd_cost_reset(&best_rdc);
715 vp9_rd_cost_reset(rd_cost); 716 vp9_rd_cost_reset(rd_cost);
716 mbmi->sb_type = bsize; 717 mbmi->sb_type = bsize;
717 mbmi->ref_frame[0] = NONE; 718 mbmi->ref_frame[0] = NONE;
718 mbmi->ref_frame[1] = NONE; 719 mbmi->ref_frame[1] = NONE;
719 mbmi->tx_size = MIN(max_txsize_lookup[bsize], 720 mbmi->tx_size = MIN(max_txsize_lookup[bsize],
720 tx_mode_to_biggest_tx_size[cm->tx_mode]); 721 tx_mode_to_biggest_tx_size[cm->tx_mode]);
721 mbmi->interp_filter = cm->interp_filter == SWITCHABLE ?
722 EIGHTTAP : cm->interp_filter;
723 722
724 #if CONFIG_VP9_TEMPORAL_DENOISING 723 #if CONFIG_VP9_TEMPORAL_DENOISING
725 vp9_denoiser_reset_frame_stats(ctx); 724 vp9_denoiser_reset_frame_stats(ctx);
726 #endif 725 #endif
727 726 if (cpi->rc.frames_since_golden == 0) {
728 for (ref_frame = LAST_FRAME; ref_frame <= GOLDEN_FRAME; ++ref_frame) { 727 ref_frame_skip_mask |= (1 << GOLDEN_FRAME);
728 usable_ref_frame = LAST_FRAME;
729 } else {
730 usable_ref_frame = GOLDEN_FRAME;
731 }
732 for (ref_frame = LAST_FRAME; ref_frame <= usable_ref_frame; ++ref_frame) {
729 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame); 733 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame);
730 734
731 x->pred_mv_sad[ref_frame] = INT_MAX; 735 x->pred_mv_sad[ref_frame] = INT_MAX;
732 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; 736 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV;
733 frame_mv[ZEROMV][ref_frame].as_int = 0; 737 frame_mv[ZEROMV][ref_frame].as_int = 0;
734 738
735 if ((cpi->ref_frame_flags & flag_list[ref_frame]) && (yv12 != NULL)) { 739 if ((cpi->ref_frame_flags & flag_list[ref_frame]) && (yv12 != NULL)) {
736 int_mv *const candidates = mbmi->ref_mvs[ref_frame]; 740 int_mv *const candidates = mbmi->ref_mvs[ref_frame];
737 const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf; 741 const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf;
738 742
(...skipping 14 matching lines...) Expand all
753 &frame_mv[NEARMV][ref_frame]); 757 &frame_mv[NEARMV][ref_frame]);
754 758
755 if (!vp9_is_scaled(sf) && bsize >= BLOCK_8X8) 759 if (!vp9_is_scaled(sf) && bsize >= BLOCK_8X8)
756 vp9_mv_pred(cpi, x, yv12_mb[ref_frame][0].buf, yv12->y_stride, 760 vp9_mv_pred(cpi, x, yv12_mb[ref_frame][0].buf, yv12->y_stride,
757 ref_frame, bsize); 761 ref_frame, bsize);
758 } else { 762 } else {
759 ref_frame_skip_mask |= (1 << ref_frame); 763 ref_frame_skip_mask |= (1 << ref_frame);
760 } 764 }
761 } 765 }
762 766
763 if (cpi->rc.frames_since_golden == 0)
764 ref_frame_skip_mask |= (1 << GOLDEN_FRAME);
765
766 for (idx = 0; idx < RT_INTER_MODES; ++idx) { 767 for (idx = 0; idx < RT_INTER_MODES; ++idx) {
767 int rate_mv = 0; 768 int rate_mv = 0;
768 int mode_rd_thresh; 769 int mode_rd_thresh;
769 int mode_index; 770 int mode_index;
770 int i; 771 int i;
771 PREDICTION_MODE this_mode = ref_mode_set[idx].pred_mode; 772 PREDICTION_MODE this_mode = ref_mode_set[idx].pred_mode;
773 if (!(cpi->sf.inter_mode_mask[bsize] & (1 << this_mode)))
774 continue;
772 775
773 ref_frame = ref_mode_set[idx].ref_frame; 776 ref_frame = ref_mode_set[idx].ref_frame;
774 mode_index = mode_idx[ref_frame][INTER_OFFSET(this_mode)]; 777 if (!(cpi->ref_frame_flags & flag_list[ref_frame]))
778 continue;
779 if (const_motion[ref_frame] && this_mode == NEARMV)
780 continue;
775 781
776 i = (ref_frame == LAST_FRAME) ? GOLDEN_FRAME : LAST_FRAME; 782 i = (ref_frame == LAST_FRAME) ? GOLDEN_FRAME : LAST_FRAME;
777
778 if (!(cpi->ref_frame_flags & flag_list[ref_frame]))
779 continue;
780
781 if (cpi->ref_frame_flags & flag_list[i]) 783 if (cpi->ref_frame_flags & flag_list[i])
782 if (x->pred_mv_sad[ref_frame] > (x->pred_mv_sad[i] << 1)) 784 if (x->pred_mv_sad[ref_frame] > (x->pred_mv_sad[i] << 1))
783 ref_frame_skip_mask |= (1 << ref_frame); 785 ref_frame_skip_mask |= (1 << ref_frame);
784
785 if (ref_frame_skip_mask & (1 << ref_frame)) 786 if (ref_frame_skip_mask & (1 << ref_frame))
786 continue; 787 continue;
787 788
788 // Select prediction reference frames. 789 // Select prediction reference frames.
789 for (i = 0; i < MAX_MB_PLANE; i++) 790 for (i = 0; i < MAX_MB_PLANE; i++)
790 xd->plane[i].pre[0] = yv12_mb[ref_frame][i]; 791 xd->plane[i].pre[0] = yv12_mb[ref_frame][i];
791 792
792 clamp_mv2(&frame_mv[NEARESTMV][ref_frame].as_mv, xd);
793 clamp_mv2(&frame_mv[NEARMV][ref_frame].as_mv, xd);
794
795 mbmi->ref_frame[0] = ref_frame; 793 mbmi->ref_frame[0] = ref_frame;
796 set_ref_ptrs(cm, xd, ref_frame, NONE); 794 set_ref_ptrs(cm, xd, ref_frame, NONE);
797 795
798 if (const_motion[ref_frame] && this_mode == NEARMV) 796 mode_index = mode_idx[ref_frame][INTER_OFFSET(this_mode)];
799 continue;
800
801 if (!(cpi->sf.inter_mode_mask[bsize] & (1 << this_mode)))
802 continue;
803
804 mode_rd_thresh = best_mode_skip_txfm ? 797 mode_rd_thresh = best_mode_skip_txfm ?
805 rd_threshes[mode_index] << 1 : rd_threshes[mode_index]; 798 rd_threshes[mode_index] << 1 : rd_threshes[mode_index];
806 if (rd_less_than_thresh(best_rdc.rdcost, mode_rd_thresh, 799 if (rd_less_than_thresh(best_rdc.rdcost, mode_rd_thresh,
807 rd_thresh_freq_fact[mode_index])) 800 rd_thresh_freq_fact[mode_index]))
808 continue; 801 continue;
809 802
810 if (this_mode == NEWMV) { 803 if (this_mode == NEWMV) {
811 if (cpi->sf.partition_search_type != VAR_BASED_PARTITION
812 && best_rdc.rdcost < (int64_t) (1 << num_pels_log2_lookup[bsize]))
813 continue;
814 if (ref_frame > LAST_FRAME) { 804 if (ref_frame > LAST_FRAME) {
815 int tmp_sad; 805 int tmp_sad;
816 int dis, cost_list[5]; 806 int dis, cost_list[5];
817 807
818 if (bsize < BLOCK_16X16) 808 if (bsize < BLOCK_16X16)
819 continue; 809 continue;
820 810
821 tmp_sad = vp9_int_pro_motion_estimation(cpi, x, bsize); 811 tmp_sad = vp9_int_pro_motion_estimation(cpi, x, bsize);
822 if (tmp_sad > x->pred_mv_sad[LAST_FRAME]) 812 if (tmp_sad > x->pred_mv_sad[LAST_FRAME])
823 continue; 813 continue;
(...skipping 14 matching lines...) Expand all
838 cpi->sf.mv.subpel_iters_per_step, 828 cpi->sf.mv.subpel_iters_per_step,
839 cond_cost_list(cpi, cost_list), 829 cond_cost_list(cpi, cost_list),
840 x->nmvjointcost, x->mvcost, &dis, 830 x->nmvjointcost, x->mvcost, &dis,
841 &x->pred_sse[ref_frame], NULL, 0, 0); 831 &x->pred_sse[ref_frame], NULL, 0, 0);
842 } else if (!combined_motion_search(cpi, x, bsize, mi_row, mi_col, 832 } else if (!combined_motion_search(cpi, x, bsize, mi_row, mi_col,
843 &frame_mv[NEWMV][ref_frame], &rate_mv, best_rdc.rdcost)) { 833 &frame_mv[NEWMV][ref_frame], &rate_mv, best_rdc.rdcost)) {
844 continue; 834 continue;
845 } 835 }
846 } 836 }
847 837
848 if (this_mode != NEARESTMV && frame_mv[this_mode][ref_frame].as_int == 838 if (this_mode != NEARESTMV &&
849 frame_mv[NEARESTMV][ref_frame].as_int) 839 frame_mv[this_mode][ref_frame].as_int ==
840 frame_mv[NEARESTMV][ref_frame].as_int)
850 continue; 841 continue;
851 842
852 mbmi->mode = this_mode; 843 mbmi->mode = this_mode;
853 mbmi->mv[0].as_int = frame_mv[this_mode][ref_frame].as_int; 844 mbmi->mv[0].as_int = frame_mv[this_mode][ref_frame].as_int;
854 845
855 // Search for the best prediction filter type, when the resulting 846 // Search for the best prediction filter type, when the resulting
856 // motion vector is at sub-pixel accuracy level for luma component, i.e., 847 // motion vector is at sub-pixel accuracy level for luma component, i.e.,
857 // the last three bits are all zeros. 848 // the last three bits are all zeros.
858 if (reuse_inter_pred) { 849 if (reuse_inter_pred) {
859 if (!this_mode_pred) { 850 if (!this_mode_pred) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 pd->dst.stride = bw; 894 pd->dst.stride = bw;
904 } 895 }
905 } 896 }
906 } 897 }
907 } 898 }
908 899
909 if (reuse_inter_pred && this_mode_pred != current_pred) 900 if (reuse_inter_pred && this_mode_pred != current_pred)
910 free_pred_buffer(current_pred); 901 free_pred_buffer(current_pred);
911 902
912 mbmi->interp_filter = best_filter; 903 mbmi->interp_filter = best_filter;
913 mbmi->tx_size = pf_tx_size[mbmi->interp_filter]; 904 mbmi->tx_size = pf_tx_size[best_filter];
914 this_rdc.rate = pf_rate[mbmi->interp_filter]; 905 this_rdc.rate = pf_rate[best_filter];
915 this_rdc.dist = pf_dist[mbmi->interp_filter]; 906 this_rdc.dist = pf_dist[best_filter];
916 var_y = pf_var[mbmi->interp_filter]; 907 var_y = pf_var[best_filter];
917 sse_y = pf_sse[mbmi->interp_filter]; 908 sse_y = pf_sse[best_filter];
918 x->skip_txfm[0] = skip_txfm; 909 x->skip_txfm[0] = skip_txfm;
919 } else { 910 } else {
920 mbmi->interp_filter = (filter_ref == SWITCHABLE) ? EIGHTTAP : filter_ref; 911 mbmi->interp_filter = (filter_ref == SWITCHABLE) ? EIGHTTAP : filter_ref;
921 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize); 912 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize);
922 model_rd_for_sb_y(cpi, bsize, x, xd, &this_rdc.rate, &this_rdc.dist, 913 model_rd_for_sb_y(cpi, bsize, x, xd, &this_rdc.rate, &this_rdc.dist,
923 &var_y, &sse_y); 914 &var_y, &sse_y);
924 this_rdc.rate += 915 this_rdc.rate +=
925 cm->interp_filter == SWITCHABLE ? 916 cm->interp_filter == SWITCHABLE ?
926 vp9_get_switchable_rate(cpi, xd) : 0; 917 vp9_get_switchable_rate(cpi, xd) : 0;
927 } 918 }
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 xd->mi[0].bmi[block + 2] = bsi[best_ref_frame][block]; 1356 xd->mi[0].bmi[block + 2] = bsi[best_ref_frame][block];
1366 } 1357 }
1367 } 1358 }
1368 mbmi->mode = xd->mi[0].bmi[3].as_mode; 1359 mbmi->mode = xd->mi[0].bmi[3].as_mode;
1369 ctx->mic = *(xd->mi[0].src_mi); 1360 ctx->mic = *(xd->mi[0].src_mi);
1370 ctx->skip_txfm[0] = 0; 1361 ctx->skip_txfm[0] = 0;
1371 ctx->skip = 0; 1362 ctx->skip = 0;
1372 // Dummy assignment for speed -5. No effect in speed -6. 1363 // Dummy assignment for speed -5. No effect in speed -6.
1373 rd_cost->rdcost = best_rd; 1364 rd_cost->rdcost = best_rd;
1374 } 1365 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_mcomp.c ('k') | source/libvpx/vp9/encoder/vp9_rd.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698