OLD | NEW |
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL); | 73 setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL); |
74 } | 74 } |
75 | 75 |
76 vp9_set_mv_search_range(x, &ref_mv.as_mv); | 76 vp9_set_mv_search_range(x, &ref_mv.as_mv); |
77 | 77 |
78 // TODO(jingning) exploiting adaptive motion search control in non-RD | 78 // TODO(jingning) exploiting adaptive motion search control in non-RD |
79 // mode decision too. | 79 // mode decision too. |
80 step_param = 6; | 80 step_param = 6; |
81 further_steps = (cpi->sf.max_step_search_steps - 1) - step_param; | 81 further_steps = (cpi->sf.max_step_search_steps - 1) - step_param; |
82 | 82 |
83 for (i = LAST_FRAME; i <= ALTREF_FRAME && cpi->common.show_frame; ++i) { | 83 for (i = LAST_FRAME; i <= LAST_FRAME && cpi->common.show_frame; ++i) { |
84 if ((x->pred_mv_sad[ref] >> 3) > x->pred_mv_sad[i]) { | 84 if ((x->pred_mv_sad[ref] >> 3) > x->pred_mv_sad[i]) { |
85 tmp_mv->as_int = INVALID_MV; | 85 tmp_mv->as_int = INVALID_MV; |
86 | 86 |
87 if (scaled_ref_frame) { | 87 if (scaled_ref_frame) { |
88 int i; | 88 int i; |
89 for (i = 0; i < MAX_MB_PLANE; i++) | 89 for (i = 0; i < MAX_MB_PLANE; i++) |
90 xd->plane[i].pre[0] = backup_yv12[i]; | 90 xd->plane[i].pre[0] = backup_yv12[i]; |
91 } | 91 } |
92 return INT_MAX; | 92 return INT_MAX; |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 mvp_full = mbmi->ref_mvs[ref][x->mv_best_ref_index[ref]].as_mv; | 96 mvp_full = mbmi->ref_mvs[ref][x->mv_best_ref_index[ref]].as_mv; |
97 | 97 |
98 mvp_full.col >>= 3; | 98 mvp_full.col >>= 3; |
99 mvp_full.row >>= 3; | 99 mvp_full.row >>= 3; |
100 | 100 |
101 bestsme = vp9_full_pixel_diamond(cpi, x, &mvp_full, step_param, | 101 vp9_full_pixel_diamond(cpi, x, &mvp_full, step_param, sadpb, further_steps, 1, |
102 sadpb, further_steps, 1, | 102 &cpi->fn_ptr[bsize], &ref_mv.as_mv, &tmp_mv->as_mv); |
103 &cpi->fn_ptr[bsize], | |
104 &ref_mv.as_mv, tmp_mv); | |
105 | |
106 x->mv_col_min = tmp_col_min; | 103 x->mv_col_min = tmp_col_min; |
107 x->mv_col_max = tmp_col_max; | 104 x->mv_col_max = tmp_col_max; |
108 x->mv_row_min = tmp_row_min; | 105 x->mv_row_min = tmp_row_min; |
109 x->mv_row_max = tmp_row_max; | 106 x->mv_row_max = tmp_row_max; |
110 | 107 |
111 if (scaled_ref_frame) { | 108 if (scaled_ref_frame) { |
112 int i; | 109 int i; |
113 for (i = 0; i < MAX_MB_PLANE; i++) | 110 for (i = 0; i < MAX_MB_PLANE; i++) |
114 xd->plane[i].pre[0] = backup_yv12[i]; | 111 xd->plane[i].pre[0] = backup_yv12[i]; |
115 } | 112 } |
116 | 113 |
117 // TODO(jingning) This step can be merged into full pixel search step in the | 114 // TODO(jingning) This step can be merged into full pixel search step in the |
118 // re-designed log-diamond search | 115 // re-designed log-diamond search |
119 buf_offset = tmp_mv->as_mv.row * stride + tmp_mv->as_mv.col; | 116 buf_offset = tmp_mv->as_mv.row * stride + tmp_mv->as_mv.col; |
120 | 117 |
121 // Find sad for current vector. | 118 // Find sad for current vector. |
122 bestsme = cpi->fn_ptr[bsize].sdf(x->plane[0].src.buf, x->plane[0].src.stride, | 119 bestsme = cpi->fn_ptr[bsize].sdf(x->plane[0].src.buf, x->plane[0].src.stride, |
123 xd->plane[0].pre[0].buf + buf_offset, | 120 xd->plane[0].pre[0].buf + buf_offset, |
124 stride, 0x7fffffff); | 121 stride, 0x7fffffff); |
125 | 122 |
126 // scale to 1/8 pixel resolution | 123 // scale to 1/8 pixel resolution |
127 tmp_mv->as_mv.row = tmp_mv->as_mv.row << 3; | 124 tmp_mv->as_mv.row = tmp_mv->as_mv.row * 8; |
128 tmp_mv->as_mv.col = tmp_mv->as_mv.col << 3; | 125 tmp_mv->as_mv.col = tmp_mv->as_mv.col * 8; |
129 | 126 |
130 // calculate the bit cost on motion vector | 127 // calculate the bit cost on motion vector |
131 *rate_mv = vp9_mv_bit_cost(&tmp_mv->as_mv, &ref_mv.as_mv, | 128 *rate_mv = vp9_mv_bit_cost(&tmp_mv->as_mv, &ref_mv.as_mv, |
132 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); | 129 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); |
133 | 130 |
134 | 131 |
135 return bestsme; | 132 return bestsme; |
136 } | 133 } |
137 | 134 |
138 // TODO(jingning) placeholder for inter-frame non-RD mode decision. | 135 // TODO(jingning) placeholder for inter-frame non-RD mode decision. |
139 // this needs various further optimizations. to be continued.. | 136 // this needs various further optimizations. to be continued.. |
140 int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, | 137 int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, |
141 const TileInfo *const tile, | 138 const TileInfo *const tile, |
142 int mi_row, int mi_col, | 139 int mi_row, int mi_col, |
143 int *returnrate, | 140 int *returnrate, |
144 int64_t *returndistortion, | 141 int64_t *returndistortion, |
145 BLOCK_SIZE bsize, | 142 BLOCK_SIZE bsize) { |
146 PICK_MODE_CONTEXT *ctx) { | |
147 MACROBLOCKD *xd = &x->e_mbd; | 143 MACROBLOCKD *xd = &x->e_mbd; |
148 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; | 144 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; |
149 const BLOCK_SIZE block_size = get_plane_block_size(bsize, &xd->plane[0]); | 145 const BLOCK_SIZE block_size = get_plane_block_size(bsize, &xd->plane[0]); |
150 MB_PREDICTION_MODE this_mode; | 146 MB_PREDICTION_MODE this_mode; |
151 MV_REFERENCE_FRAME ref_frame; | 147 MV_REFERENCE_FRAME ref_frame; |
152 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; | 148 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; |
153 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; | 149 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; |
154 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, | 150 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, |
155 VP9_ALT_FLAG }; | 151 VP9_ALT_FLAG }; |
156 int64_t best_rd = INT64_MAX; | 152 int64_t best_rd = INT64_MAX; |
157 int64_t this_rd; | 153 int64_t this_rd; |
| 154 int64_t cost[4]= { 0, 100, 150, 205 }; |
158 | 155 |
159 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; | 156 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; |
160 | 157 |
161 x->skip = 0; | 158 x->skip = 0; |
162 if (cpi->active_map_enabled && x->active_ptr[0] == 0) | 159 if (cpi->active_map_enabled && x->active_ptr[0] == 0) |
163 x->skip = 1; | 160 x->skip = 1; |
164 | 161 |
165 // initialize mode decisions | 162 // initialize mode decisions |
166 *returnrate = INT_MAX; | 163 *returnrate = INT_MAX; |
167 vpx_memset(mbmi, 0, sizeof(MB_MODE_INFO)); | 164 vpx_memset(mbmi, 0, sizeof(MB_MODE_INFO)); |
168 mbmi->sb_type = bsize; | 165 mbmi->sb_type = bsize; |
169 mbmi->ref_frame[0] = NONE; | 166 mbmi->ref_frame[0] = NONE; |
170 mbmi->ref_frame[1] = NONE; | 167 mbmi->ref_frame[1] = NONE; |
171 mbmi->tx_size = MIN(max_txsize_lookup[bsize], | 168 mbmi->tx_size = MIN(max_txsize_lookup[bsize], |
172 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); | 169 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); |
| 170 mbmi->interp_filter = cpi->common.interp_filter == SWITCHABLE ? |
| 171 EIGHTTAP : cpi->common.interp_filter; |
| 172 mbmi->skip = 0; |
| 173 mbmi->segment_id = 0; |
173 | 174 |
174 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { | 175 for (ref_frame = LAST_FRAME; ref_frame <= LAST_FRAME ; ++ref_frame) { |
175 x->pred_mv_sad[ref_frame] = INT_MAX; | 176 x->pred_mv_sad[ref_frame] = INT_MAX; |
176 if (cpi->ref_frame_flags & flag_list[ref_frame]) { | 177 if (cpi->ref_frame_flags & flag_list[ref_frame]) { |
177 vp9_setup_buffer_inter(cpi, x, tile, | 178 vp9_setup_buffer_inter(cpi, x, tile, |
178 ref_frame, block_size, mi_row, mi_col, | 179 ref_frame, block_size, mi_row, mi_col, |
179 frame_mv[NEARESTMV], frame_mv[NEARMV], yv12_mb); | 180 frame_mv[NEARESTMV], frame_mv[NEARMV], yv12_mb); |
180 } | 181 } |
181 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; | 182 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; |
182 frame_mv[ZEROMV][ref_frame].as_int = 0; | 183 frame_mv[ZEROMV][ref_frame].as_int = 0; |
183 } | 184 } |
184 | 185 |
185 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { | 186 for (ref_frame = LAST_FRAME; ref_frame <= LAST_FRAME ; ++ref_frame) { |
186 int rate_mv = 0; | 187 int rate_mv = 0; |
187 | 188 |
188 if (!(cpi->ref_frame_flags & flag_list[ref_frame])) | 189 if (!(cpi->ref_frame_flags & flag_list[ref_frame])) |
189 continue; | 190 continue; |
190 | 191 |
191 // Select prediction reference frames. | 192 // Select prediction reference frames. |
192 xd->plane[0].pre[0] = yv12_mb[ref_frame][0]; | 193 xd->plane[0].pre[0] = yv12_mb[ref_frame][0]; |
193 | 194 |
194 | |
195 x->mode_sad[ref_frame][INTER_OFFSET(NEWMV)] = | |
196 full_pixel_motion_search(cpi, x, tile, bsize, mi_row, mi_col, | |
197 &frame_mv[NEWMV][ref_frame], &rate_mv); | |
198 | |
199 if (frame_mv[NEWMV][ref_frame].as_int == INVALID_MV) | |
200 continue; | |
201 | |
202 clamp_mv2(&frame_mv[NEARESTMV][ref_frame].as_mv, xd); | 195 clamp_mv2(&frame_mv[NEARESTMV][ref_frame].as_mv, xd); |
203 clamp_mv2(&frame_mv[NEARMV][ref_frame].as_mv, xd); | 196 clamp_mv2(&frame_mv[NEARMV][ref_frame].as_mv, xd); |
204 | 197 |
205 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { | 198 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { |
206 int rate = x->inter_mode_cost[mbmi->mode_context[ref_frame]] | 199 int rate = cost[INTER_OFFSET(this_mode)]; |
207 [INTER_OFFSET(this_mode)]; | 200 int64_t dist; |
208 int64_t dist = x->mode_sad[ref_frame][INTER_OFFSET(this_mode)] * | 201 |
209 x->mode_sad[ref_frame][INTER_OFFSET(this_mode)]; | 202 if (this_mode == NEWMV) { |
210 this_rd = RDCOST(x->rdmult, x->rddiv, rate, dist); | 203 if (this_rd < 300) |
| 204 continue; |
| 205 |
| 206 x->mode_sad[ref_frame][INTER_OFFSET(NEWMV)] = |
| 207 full_pixel_motion_search(cpi, x, tile, bsize, mi_row, mi_col, |
| 208 &frame_mv[NEWMV][ref_frame], &rate_mv); |
| 209 |
| 210 if (frame_mv[NEWMV][ref_frame].as_int == INVALID_MV) |
| 211 continue; |
| 212 } |
| 213 |
| 214 dist = x->mode_sad[ref_frame][INTER_OFFSET(this_mode)]; |
| 215 this_rd = rate + dist; |
211 | 216 |
212 if (this_rd < best_rd) { | 217 if (this_rd < best_rd) { |
213 best_rd = this_rd; | 218 best_rd = this_rd; |
214 mbmi->mode = this_mode; | 219 mbmi->mode = this_mode; |
215 mbmi->ref_frame[0] = ref_frame; | 220 mbmi->ref_frame[0] = ref_frame; |
216 mbmi->mv[0].as_int = frame_mv[this_mode][ref_frame].as_int; | 221 mbmi->mv[0].as_int = frame_mv[this_mode][ref_frame].as_int; |
| 222 xd->mi_8x8[0]->bmi[0].as_mv[0].as_int = mbmi->mv[0].as_int; |
| 223 mbmi->uv_mode = this_mode; |
217 } | 224 } |
218 } | 225 } |
219 } | 226 } |
220 | 227 |
221 // TODO(jingning) sub-pixel motion search, if NEWMV is chosen | 228 // TODO(jingning) sub-pixel motion search, if NEWMV is chosen |
222 | 229 |
223 // TODO(jingning) intra prediction search, if the best SAD is above a certain | 230 // TODO(jingning) intra prediction search, if the best SAD is above a certain |
224 // threshold. | 231 // threshold. |
225 | 232 |
226 // store mode decisions | |
227 ctx->mic = *xd->mi_8x8[0]; | |
228 | |
229 return INT64_MAX; | 233 return INT64_MAX; |
230 } | 234 } |
OLD | NEW |