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

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

Issue 290653003: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 7 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 cpi->common.allow_high_precision_mv = allow_high_precision_mv; 108 cpi->common.allow_high_precision_mv = allow_high_precision_mv;
109 if (cpi->common.allow_high_precision_mv) { 109 if (cpi->common.allow_high_precision_mv) {
110 mb->mvcost = mb->nmvcost_hp; 110 mb->mvcost = mb->nmvcost_hp;
111 mb->mvsadcost = mb->nmvsadcost_hp; 111 mb->mvsadcost = mb->nmvsadcost_hp;
112 } else { 112 } else {
113 mb->mvcost = mb->nmvcost; 113 mb->mvcost = mb->nmvcost;
114 mb->mvsadcost = mb->nmvsadcost; 114 mb->mvsadcost = mb->nmvsadcost;
115 } 115 }
116 } 116 }
117 117
118 static void setup_key_frame(VP9_COMP *cpi) {
119 vp9_setup_past_independence(&cpi->common);
120
121 // All buffers are implicitly updated on key frames.
122 cpi->refresh_golden_frame = 1;
123 cpi->refresh_alt_ref_frame = 1;
124 }
125
126 static void setup_inter_frame(VP9_COMMON *cm) {
127 if (cm->error_resilient_mode || cm->intra_only)
128 vp9_setup_past_independence(cm);
129
130 assert(cm->frame_context_idx < FRAME_CONTEXTS);
131 cm->fc = cm->frame_contexts[cm->frame_context_idx];
132 }
133
134 static void setup_frame(VP9_COMP *cpi) { 118 static void setup_frame(VP9_COMP *cpi) {
135 VP9_COMMON *const cm = &cpi->common; 119 VP9_COMMON *const cm = &cpi->common;
136 // Set up entropy context depending on frame type. The decoder mandates 120 // Set up entropy context depending on frame type. The decoder mandates
137 // the use of the default context, index 0, for keyframes and inter 121 // the use of the default context, index 0, for keyframes and inter
138 // frames where the error_resilient_mode or intra_only flag is set. For 122 // frames where the error_resilient_mode or intra_only flag is set. For
139 // other inter-frames the encoder currently uses only two contexts; 123 // other inter-frames the encoder currently uses only two contexts;
140 // context 1 for ALTREF frames and context 0 for the others. 124 // context 1 for ALTREF frames and context 0 for the others.
125 if (frame_is_intra_only(cm) || cm->error_resilient_mode) {
126 vp9_setup_past_independence(cm);
127 } else {
128 if (!cpi->use_svc)
129 cm->frame_context_idx = cpi->refresh_alt_ref_frame;
130 }
131
141 if (cm->frame_type == KEY_FRAME) { 132 if (cm->frame_type == KEY_FRAME) {
142 setup_key_frame(cpi); 133 cpi->refresh_golden_frame = 1;
134 cpi->refresh_alt_ref_frame = 1;
143 } else { 135 } else {
144 if (!cm->intra_only && !cm->error_resilient_mode && !cpi->use_svc) 136 cm->fc = cm->frame_contexts[cm->frame_context_idx];
145 cm->frame_context_idx = cpi->refresh_alt_ref_frame;
146 setup_inter_frame(cm);
147 } 137 }
148 } 138 }
149 139
150
151
152 void vp9_initialize_enc() { 140 void vp9_initialize_enc() {
153 static int init_done = 0; 141 static int init_done = 0;
154 142
155 if (!init_done) { 143 if (!init_done) {
156 vp9_init_neighbors(); 144 vp9_init_neighbors();
157 vp9_init_quant_tables(); 145 vp9_init_quant_tables();
158 146
159 vp9_coef_tree_initialize(); 147 vp9_coef_tree_initialize();
160 vp9_tokenize_initialize(); 148 vp9_tokenize_initialize();
161 vp9_init_me_luts(); 149 vp9_init_me_luts();
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 double z = 256 * (2 * (log2f(8 * i) + .6)); 742 double z = 256 * (2 * (log2f(8 * i) + .6));
755 mvsadcost[0][i] = (int)z; 743 mvsadcost[0][i] = (int)z;
756 mvsadcost[1][i] = (int)z; 744 mvsadcost[1][i] = (int)z;
757 mvsadcost[0][-i] = (int)z; 745 mvsadcost[0][-i] = (int)z;
758 mvsadcost[1][-i] = (int)z; 746 mvsadcost[1][-i] = (int)z;
759 } while (++i <= MV_MAX); 747 } while (++i <= MV_MAX);
760 } 748 }
761 749
762 750
763 VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf) { 751 VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf) {
764 int i, j; 752 unsigned int i, j;
765 VP9_COMP *const cpi = vpx_memalign(32, sizeof(VP9_COMP)); 753 VP9_COMP *const cpi = vpx_memalign(32, sizeof(VP9_COMP));
766 VP9_COMMON *const cm = cpi != NULL ? &cpi->common : NULL; 754 VP9_COMMON *const cm = cpi != NULL ? &cpi->common : NULL;
767 755
768 if (!cm) 756 if (!cm)
769 return NULL; 757 return NULL;
770 758
771 vp9_zero(*cpi); 759 vp9_zero(*cpi);
772 760
773 if (setjmp(cm->error.jmp)) { 761 if (setjmp(cm->error.jmp)) {
774 cm->error.setjmp = 0; 762 cm->error.setjmp = 0;
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 vp9_init_quantizer(cpi); 1035 vp9_init_quantizer(cpi);
1048 1036
1049 vp9_loop_filter_init(cm); 1037 vp9_loop_filter_init(cm);
1050 1038
1051 cm->error.setjmp = 0; 1039 cm->error.setjmp = 0;
1052 1040
1053 return cpi; 1041 return cpi;
1054 } 1042 }
1055 1043
1056 void vp9_remove_compressor(VP9_COMP *cpi) { 1044 void vp9_remove_compressor(VP9_COMP *cpi) {
1057 int i; 1045 unsigned int i;
1058 1046
1059 if (!cpi) 1047 if (!cpi)
1060 return; 1048 return;
1061 1049
1062 if (cpi && (cpi->common.current_video_frame > 0)) { 1050 if (cpi && (cpi->common.current_video_frame > 0)) {
1063 #if CONFIG_INTERNAL_STATS 1051 #if CONFIG_INTERNAL_STATS
1064 1052
1065 vp9_clear_system_state(); 1053 vp9_clear_system_state();
1066 1054
1067 // printf("\n8x8-4x4:%d-%d\n", cpi->t8x8_count, cpi->t4x4_count); 1055 // printf("\n8x8-4x4:%d-%d\n", cpi->t8x8_count, cpi->t4x4_count);
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 1598
1611 vpx_usec_timer_start(&timer); 1599 vpx_usec_timer_start(&timer);
1612 1600
1613 vp9_pick_filter_level(cpi->Source, cpi, cpi->sf.lpf_pick); 1601 vp9_pick_filter_level(cpi->Source, cpi, cpi->sf.lpf_pick);
1614 1602
1615 vpx_usec_timer_mark(&timer); 1603 vpx_usec_timer_mark(&timer);
1616 cpi->time_pick_lpf += vpx_usec_timer_elapsed(&timer); 1604 cpi->time_pick_lpf += vpx_usec_timer_elapsed(&timer);
1617 } 1605 }
1618 1606
1619 if (lf->filter_level > 0) { 1607 if (lf->filter_level > 0) {
1620 vp9_loop_filter_frame(cm, xd, lf->filter_level, 0, 0); 1608 vp9_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0);
1621 } 1609 }
1622 1610
1623 vp9_extend_frame_inner_borders(cm->frame_to_show); 1611 vp9_extend_frame_inner_borders(cm->frame_to_show);
1624 } 1612 }
1625 1613
1626 void vp9_scale_references(VP9_COMP *cpi) { 1614 void vp9_scale_references(VP9_COMP *cpi) {
1627 VP9_COMMON *cm = &cpi->common; 1615 VP9_COMMON *cm = &cpi->common;
1628 MV_REFERENCE_FRAME ref_frame; 1616 MV_REFERENCE_FRAME ref_frame;
1629 1617
1630 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { 1618 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1730 fprintf(fmodes, "%5d ", cpi->mode_chosen_counts[i]); 1718 fprintf(fmodes, "%5d ", cpi->mode_chosen_counts[i]);
1731 1719
1732 fprintf(fmodes, "\n"); 1720 fprintf(fmodes, "\n");
1733 1721
1734 fclose(fmodes); 1722 fclose(fmodes);
1735 } 1723 }
1736 } 1724 }
1737 #endif 1725 #endif
1738 1726
1739 static void encode_without_recode_loop(VP9_COMP *cpi, 1727 static void encode_without_recode_loop(VP9_COMP *cpi,
1740 size_t *size,
1741 uint8_t *dest,
1742 int q) { 1728 int q) {
1743 VP9_COMMON *const cm = &cpi->common; 1729 VP9_COMMON *const cm = &cpi->common;
1744 vp9_clear_system_state(); 1730 vp9_clear_system_state();
1745 vp9_set_quantizer(cm, q); 1731 vp9_set_quantizer(cm, q);
1746 setup_frame(cpi); 1732 setup_frame(cpi);
1747 // Variance adaptive and in frame q adjustment experiments are mutually 1733 // Variance adaptive and in frame q adjustment experiments are mutually
1748 // exclusive. 1734 // exclusive.
1749 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { 1735 if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
1750 vp9_vaq_frame_setup(cpi); 1736 vp9_vaq_frame_setup(cpi);
1751 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { 1737 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) {
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
2167 // Decide q and q bounds. 2153 // Decide q and q bounds.
2168 q = vp9_rc_pick_q_and_bounds(cpi, &bottom_index, &top_index); 2154 q = vp9_rc_pick_q_and_bounds(cpi, &bottom_index, &top_index);
2169 2155
2170 if (!frame_is_intra_only(cm)) { 2156 if (!frame_is_intra_only(cm)) {
2171 cm->interp_filter = DEFAULT_INTERP_FILTER; 2157 cm->interp_filter = DEFAULT_INTERP_FILTER;
2172 /* TODO: Decide this more intelligently */ 2158 /* TODO: Decide this more intelligently */
2173 set_high_precision_mv(cpi, q < HIGH_PRECISION_MV_QTHRESH); 2159 set_high_precision_mv(cpi, q < HIGH_PRECISION_MV_QTHRESH);
2174 } 2160 }
2175 2161
2176 if (cpi->sf.recode_loop == DISALLOW_RECODE) { 2162 if (cpi->sf.recode_loop == DISALLOW_RECODE) {
2177 encode_without_recode_loop(cpi, size, dest, q); 2163 encode_without_recode_loop(cpi, q);
2178 } else { 2164 } else {
2179 encode_with_recode_loop(cpi, size, dest, q, bottom_index, top_index); 2165 encode_with_recode_loop(cpi, size, dest, q, bottom_index, top_index);
2180 } 2166 }
2181 2167
2182 // Special case code to reduce pulsing when key frames are forced at a 2168 // Special case code to reduce pulsing when key frames are forced at a
2183 // fixed interval. Note the reconstruction error if it is the frame before 2169 // fixed interval. Note the reconstruction error if it is the frame before
2184 // the force key frame 2170 // the force key frame
2185 if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) { 2171 if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) {
2186 cpi->ambient_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm)); 2172 cpi->ambient_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
2187 } 2173 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2229 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) 2215 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode)
2230 vp9_adapt_coef_probs(cm); 2216 vp9_adapt_coef_probs(cm);
2231 2217
2232 if (!frame_is_intra_only(cm)) { 2218 if (!frame_is_intra_only(cm)) {
2233 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) { 2219 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) {
2234 vp9_adapt_mode_probs(cm); 2220 vp9_adapt_mode_probs(cm);
2235 vp9_adapt_mv_probs(cm, cm->allow_high_precision_mv); 2221 vp9_adapt_mv_probs(cm, cm->allow_high_precision_mv);
2236 } 2222 }
2237 } 2223 }
2238 2224
2239 #if 0
2240 output_frame_level_debug_stats(cpi);
2241 #endif
2242 if (cpi->refresh_golden_frame == 1) 2225 if (cpi->refresh_golden_frame == 1)
2243 cpi->frame_flags |= FRAMEFLAGS_GOLDEN; 2226 cpi->frame_flags |= FRAMEFLAGS_GOLDEN;
2244 else 2227 else
2245 cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; 2228 cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN;
2246 2229
2247 if (cpi->refresh_alt_ref_frame == 1) 2230 if (cpi->refresh_alt_ref_frame == 1)
2248 cpi->frame_flags |= FRAMEFLAGS_ALTREF; 2231 cpi->frame_flags |= FRAMEFLAGS_ALTREF;
2249 else 2232 else
2250 cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; 2233 cpi->frame_flags &= ~FRAMEFLAGS_ALTREF;
2251 2234
2252 get_ref_frame_flags(cpi); 2235 get_ref_frame_flags(cpi);
2253 2236
2254 cm->last_frame_type = cm->frame_type; 2237 cm->last_frame_type = cm->frame_type;
2255 vp9_rc_postencode_update(cpi, *size); 2238 vp9_rc_postencode_update(cpi, *size);
2256 2239
2240 #if 0
2241 output_frame_level_debug_stats(cpi);
2242 #endif
2243
2257 if (cm->frame_type == KEY_FRAME) { 2244 if (cm->frame_type == KEY_FRAME) {
2258 // Tell the caller that the frame was coded as a key frame 2245 // Tell the caller that the frame was coded as a key frame
2259 *frame_flags = cpi->frame_flags | FRAMEFLAGS_KEY; 2246 *frame_flags = cpi->frame_flags | FRAMEFLAGS_KEY;
2260 2247
2261 #if CONFIG_MULTIPLE_ARF 2248 #if CONFIG_MULTIPLE_ARF
2262 // Reset the sequence number. 2249 // Reset the sequence number.
2263 if (cpi->multi_arf_enabled) { 2250 if (cpi->multi_arf_enabled) {
2264 cpi->sequence_number = 0; 2251 cpi->sequence_number = 0;
2265 cpi->frame_coding_order_period = cpi->new_frame_coding_order_period; 2252 cpi->frame_coding_order_period = cpi->new_frame_coding_order_period;
2266 cpi->new_frame_coding_order_period = -1; 2253 cpi->new_frame_coding_order_period = -1;
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
2783 } 2770 }
2784 } 2771 }
2785 2772
2786 #endif 2773 #endif
2787 return 0; 2774 return 0;
2788 } 2775 }
2789 2776
2790 int vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest, 2777 int vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest,
2791 vp9_ppflags_t *flags) { 2778 vp9_ppflags_t *flags) {
2792 VP9_COMMON *cm = &cpi->common; 2779 VP9_COMMON *cm = &cpi->common;
2780 #if !CONFIG_VP9_POSTPROC
2781 (void)flags;
2782 #endif
2793 2783
2794 if (!cm->show_frame) { 2784 if (!cm->show_frame) {
2795 return -1; 2785 return -1;
2796 } else { 2786 } else {
2797 int ret; 2787 int ret;
2798 #if CONFIG_VP9_POSTPROC 2788 #if CONFIG_VP9_POSTPROC
2799 ret = vp9_post_proc_frame(cm, dest, flags); 2789 ret = vp9_post_proc_frame(cm, dest, flags);
2800 #else 2790 #else
2801
2802 if (cm->frame_to_show) { 2791 if (cm->frame_to_show) {
2803 *dest = *cm->frame_to_show; 2792 *dest = *cm->frame_to_show;
2804 dest->y_width = cm->width; 2793 dest->y_width = cm->width;
2805 dest->y_height = cm->height; 2794 dest->y_height = cm->height;
2806 dest->uv_width = cm->width >> cm->subsampling_x; 2795 dest->uv_width = cm->width >> cm->subsampling_x;
2807 dest->uv_height = cm->height >> cm->subsampling_y; 2796 dest->uv_height = cm->height >> cm->subsampling_y;
2808 ret = 0; 2797 ret = 0;
2809 } else { 2798 } else {
2810 ret = -1; 2799 ret = -1;
2811 } 2800 }
2812
2813 #endif // !CONFIG_VP9_POSTPROC 2801 #endif // !CONFIG_VP9_POSTPROC
2814 vp9_clear_system_state(); 2802 vp9_clear_system_state();
2815 return ret; 2803 return ret;
2816 } 2804 }
2817 } 2805 }
2818 2806
2819 int vp9_set_roimap(VP9_COMP *cpi, unsigned char *map, unsigned int rows, 2807 int vp9_set_active_map(VP9_COMP *cpi, unsigned char *map, int rows, int cols) {
2820 unsigned int cols, int delta_q[MAX_SEGMENTS],
2821 int delta_lf[MAX_SEGMENTS],
2822 unsigned int threshold[MAX_SEGMENTS]) {
2823 signed char feature_data[SEG_LVL_MAX][MAX_SEGMENTS];
2824 struct segmentation *seg = &cpi->common.seg;
2825 const VP9_COMMON *const cm = &cpi->common;
2826 int i;
2827
2828 if (cm->mb_rows != rows || cm->mb_cols != cols)
2829 return -1;
2830
2831 if (!map) {
2832 vp9_disable_segmentation(seg);
2833 return 0;
2834 }
2835
2836 vpx_memcpy(cpi->segmentation_map, map, cm->mi_rows * cm->mi_cols);
2837
2838 // Activate segmentation.
2839 vp9_enable_segmentation(seg);
2840
2841 // Set up the quant, LF and breakout threshold segment data
2842 for (i = 0; i < MAX_SEGMENTS; i++) {
2843 feature_data[SEG_LVL_ALT_Q][i] = delta_q[i];
2844 feature_data[SEG_LVL_ALT_LF][i] = delta_lf[i];
2845 cpi->segment_encode_breakout[i] = threshold[i];
2846 }
2847
2848 // Enable the loop and quant changes in the feature mask
2849 for (i = 0; i < MAX_SEGMENTS; i++) {
2850 if (delta_q[i])
2851 vp9_enable_segfeature(seg, i, SEG_LVL_ALT_Q);
2852 else
2853 vp9_disable_segfeature(seg, i, SEG_LVL_ALT_Q);
2854
2855 if (delta_lf[i])
2856 vp9_enable_segfeature(seg, i, SEG_LVL_ALT_LF);
2857 else
2858 vp9_disable_segfeature(seg, i, SEG_LVL_ALT_LF);
2859 }
2860
2861 // Initialize the feature data structure
2862 // SEGMENT_DELTADATA 0, SEGMENT_ABSDATA 1
2863 vp9_set_segment_data(seg, &feature_data[0][0], SEGMENT_DELTADATA);
2864
2865 return 0;
2866 }
2867
2868 int vp9_set_active_map(VP9_COMP *cpi, unsigned char *map,
2869 unsigned int rows, unsigned int cols) {
2870 if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) { 2808 if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) {
2871 if (map) { 2809 if (map) {
2872 vpx_memcpy(cpi->active_map, map, rows * cols); 2810 vpx_memcpy(cpi->active_map, map, rows * cols);
2873 cpi->active_map_enabled = 1; 2811 cpi->active_map_enabled = 1;
2874 } else { 2812 } else {
2875 cpi->active_map_enabled = 0; 2813 cpi->active_map_enabled = 0;
2876 } 2814 }
2877 2815
2878 return 0; 2816 return 0;
2879 } else { 2817 } else {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
2949 assert(a->y_crop_height == b->y_crop_height); 2887 assert(a->y_crop_height == b->y_crop_height);
2950 2888
2951 return (int)get_sse(a->y_buffer, a->y_stride, b->y_buffer, b->y_stride, 2889 return (int)get_sse(a->y_buffer, a->y_stride, b->y_buffer, b->y_stride,
2952 a->y_crop_width, a->y_crop_height); 2890 a->y_crop_width, a->y_crop_height);
2953 } 2891 }
2954 2892
2955 2893
2956 int vp9_get_quantizer(VP9_COMP *cpi) { 2894 int vp9_get_quantizer(VP9_COMP *cpi) {
2957 return cpi->common.base_qindex; 2895 return cpi->common.base_qindex;
2958 } 2896 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698