OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 18 matching lines...) Expand all Loading... |
29 seg->enabled = 0; | 29 seg->enabled = 0; |
30 seg->update_map = 0; | 30 seg->update_map = 0; |
31 seg->update_data = 0; | 31 seg->update_data = 0; |
32 } | 32 } |
33 | 33 |
34 void vp9_set_segment_data(struct segmentation *seg, | 34 void vp9_set_segment_data(struct segmentation *seg, |
35 signed char *feature_data, | 35 signed char *feature_data, |
36 unsigned char abs_delta) { | 36 unsigned char abs_delta) { |
37 seg->abs_delta = abs_delta; | 37 seg->abs_delta = abs_delta; |
38 | 38 |
39 vpx_memcpy(seg->feature_data, feature_data, sizeof(seg->feature_data)); | 39 memcpy(seg->feature_data, feature_data, sizeof(seg->feature_data)); |
40 } | 40 } |
41 void vp9_disable_segfeature(struct segmentation *seg, int segment_id, | 41 void vp9_disable_segfeature(struct segmentation *seg, int segment_id, |
42 SEG_LVL_FEATURES feature_id) { | 42 SEG_LVL_FEATURES feature_id) { |
43 seg->feature_mask[segment_id] &= ~(1 << feature_id); | 43 seg->feature_mask[segment_id] &= ~(1 << feature_id); |
44 } | 44 } |
45 | 45 |
46 void vp9_clear_segdata(struct segmentation *seg, int segment_id, | 46 void vp9_clear_segdata(struct segmentation *seg, int segment_id, |
47 SEG_LVL_FEATURES feature_id) { | 47 SEG_LVL_FEATURES feature_id) { |
48 seg->feature_data[segment_id][feature_id] = 0; | 48 seg->feature_data[segment_id][feature_id] = 0; |
49 } | 49 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 segcounts[5] * vp9_cost_one(probs[5]); | 100 segcounts[5] * vp9_cost_one(probs[5]); |
101 if (c67 > 0) | 101 if (c67 > 0) |
102 cost += segcounts[6] * vp9_cost_zero(probs[6]) + | 102 cost += segcounts[6] * vp9_cost_zero(probs[6]) + |
103 segcounts[7] * vp9_cost_one(probs[6]); | 103 segcounts[7] * vp9_cost_one(probs[6]); |
104 } | 104 } |
105 | 105 |
106 return cost; | 106 return cost; |
107 } | 107 } |
108 | 108 |
109 static void count_segs(const VP9_COMMON *cm, MACROBLOCKD *xd, | 109 static void count_segs(const VP9_COMMON *cm, MACROBLOCKD *xd, |
110 const TileInfo *tile, MODE_INFO *mi, | 110 const TileInfo *tile, MODE_INFO **mi, |
111 int *no_pred_segcounts, | 111 int *no_pred_segcounts, |
112 int (*temporal_predictor_count)[2], | 112 int (*temporal_predictor_count)[2], |
113 int *t_unpred_seg_counts, | 113 int *t_unpred_seg_counts, |
114 int bw, int bh, int mi_row, int mi_col) { | 114 int bw, int bh, int mi_row, int mi_col) { |
115 int segment_id; | 115 int segment_id; |
116 | 116 |
117 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 117 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
118 return; | 118 return; |
119 | 119 |
120 xd->mi = mi; | 120 xd->mi = mi; |
121 segment_id = xd->mi[0].src_mi->mbmi.segment_id; | 121 segment_id = xd->mi[0]->mbmi.segment_id; |
122 | 122 |
123 set_mi_row_col(xd, tile, mi_row, bh, mi_col, bw, cm->mi_rows, cm->mi_cols); | 123 set_mi_row_col(xd, tile, mi_row, bh, mi_col, bw, cm->mi_rows, cm->mi_cols); |
124 | 124 |
125 // Count the number of hits on each segment with no prediction | 125 // Count the number of hits on each segment with no prediction |
126 no_pred_segcounts[segment_id]++; | 126 no_pred_segcounts[segment_id]++; |
127 | 127 |
128 // Temporal prediction not allowed on key frames | 128 // Temporal prediction not allowed on key frames |
129 if (cm->frame_type != KEY_FRAME) { | 129 if (cm->frame_type != KEY_FRAME) { |
130 const BLOCK_SIZE bsize = xd->mi[0].src_mi->mbmi.sb_type; | 130 const BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type; |
131 // Test to see if the segment id matches the predicted value. | 131 // Test to see if the segment id matches the predicted value. |
132 const int pred_segment_id = vp9_get_segment_id(cm, cm->last_frame_seg_map, | 132 const int pred_segment_id = vp9_get_segment_id(cm, cm->last_frame_seg_map, |
133 bsize, mi_row, mi_col); | 133 bsize, mi_row, mi_col); |
134 const int pred_flag = pred_segment_id == segment_id; | 134 const int pred_flag = pred_segment_id == segment_id; |
135 const int pred_context = vp9_get_pred_context_seg_id(xd); | 135 const int pred_context = vp9_get_pred_context_seg_id(xd); |
136 | 136 |
137 // Store the prediction status for this mb and update counts | 137 // Store the prediction status for this mb and update counts |
138 // as appropriate | 138 // as appropriate |
139 xd->mi[0].src_mi->mbmi.seg_id_predicted = pred_flag; | 139 xd->mi[0]->mbmi.seg_id_predicted = pred_flag; |
140 temporal_predictor_count[pred_context][pred_flag]++; | 140 temporal_predictor_count[pred_context][pred_flag]++; |
141 | 141 |
142 // Update the "unpredicted" segment count | 142 // Update the "unpredicted" segment count |
143 if (!pred_flag) | 143 if (!pred_flag) |
144 t_unpred_seg_counts[segment_id]++; | 144 t_unpred_seg_counts[segment_id]++; |
145 } | 145 } |
146 } | 146 } |
147 | 147 |
148 static void count_segs_sb(const VP9_COMMON *cm, MACROBLOCKD *xd, | 148 static void count_segs_sb(const VP9_COMMON *cm, MACROBLOCKD *xd, |
149 const TileInfo *tile, MODE_INFO *mi, | 149 const TileInfo *tile, MODE_INFO **mi, |
150 int *no_pred_segcounts, | 150 int *no_pred_segcounts, |
151 int (*temporal_predictor_count)[2], | 151 int (*temporal_predictor_count)[2], |
152 int *t_unpred_seg_counts, | 152 int *t_unpred_seg_counts, |
153 int mi_row, int mi_col, | 153 int mi_row, int mi_col, |
154 BLOCK_SIZE bsize) { | 154 BLOCK_SIZE bsize) { |
155 const int mis = cm->mi_stride; | 155 const int mis = cm->mi_stride; |
156 int bw, bh; | 156 int bw, bh; |
157 const int bs = num_8x8_blocks_wide_lookup[bsize], hbs = bs / 2; | 157 const int bs = num_8x8_blocks_wide_lookup[bsize], hbs = bs / 2; |
158 | 158 |
159 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 159 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
160 return; | 160 return; |
161 | 161 |
162 bw = num_8x8_blocks_wide_lookup[mi[0].src_mi->mbmi.sb_type]; | 162 bw = num_8x8_blocks_wide_lookup[mi[0]->mbmi.sb_type]; |
163 bh = num_8x8_blocks_high_lookup[mi[0].src_mi->mbmi.sb_type]; | 163 bh = num_8x8_blocks_high_lookup[mi[0]->mbmi.sb_type]; |
164 | 164 |
165 if (bw == bs && bh == bs) { | 165 if (bw == bs && bh == bs) { |
166 count_segs(cm, xd, tile, mi, no_pred_segcounts, temporal_predictor_count, | 166 count_segs(cm, xd, tile, mi, no_pred_segcounts, temporal_predictor_count, |
167 t_unpred_seg_counts, bs, bs, mi_row, mi_col); | 167 t_unpred_seg_counts, bs, bs, mi_row, mi_col); |
168 } else if (bw == bs && bh < bs) { | 168 } else if (bw == bs && bh < bs) { |
169 count_segs(cm, xd, tile, mi, no_pred_segcounts, temporal_predictor_count, | 169 count_segs(cm, xd, tile, mi, no_pred_segcounts, temporal_predictor_count, |
170 t_unpred_seg_counts, bs, hbs, mi_row, mi_col); | 170 t_unpred_seg_counts, bs, hbs, mi_row, mi_col); |
171 count_segs(cm, xd, tile, mi + hbs * mis, no_pred_segcounts, | 171 count_segs(cm, xd, tile, mi + hbs * mis, no_pred_segcounts, |
172 temporal_predictor_count, t_unpred_seg_counts, bs, hbs, | 172 temporal_predictor_count, t_unpred_seg_counts, bs, hbs, |
173 mi_row + hbs, mi_col); | 173 mi_row + hbs, mi_col); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 int temporal_predictor_count[PREDICTION_PROBS][2] = { { 0 } }; | 206 int temporal_predictor_count[PREDICTION_PROBS][2] = { { 0 } }; |
207 int no_pred_segcounts[MAX_SEGMENTS] = { 0 }; | 207 int no_pred_segcounts[MAX_SEGMENTS] = { 0 }; |
208 int t_unpred_seg_counts[MAX_SEGMENTS] = { 0 }; | 208 int t_unpred_seg_counts[MAX_SEGMENTS] = { 0 }; |
209 | 209 |
210 vp9_prob no_pred_tree[SEG_TREE_PROBS]; | 210 vp9_prob no_pred_tree[SEG_TREE_PROBS]; |
211 vp9_prob t_pred_tree[SEG_TREE_PROBS]; | 211 vp9_prob t_pred_tree[SEG_TREE_PROBS]; |
212 vp9_prob t_nopred_prob[PREDICTION_PROBS]; | 212 vp9_prob t_nopred_prob[PREDICTION_PROBS]; |
213 | 213 |
214 // Set default state for the segment tree probabilities and the | 214 // Set default state for the segment tree probabilities and the |
215 // temporal coding probabilities | 215 // temporal coding probabilities |
216 vpx_memset(seg->tree_probs, 255, sizeof(seg->tree_probs)); | 216 memset(seg->tree_probs, 255, sizeof(seg->tree_probs)); |
217 vpx_memset(seg->pred_probs, 255, sizeof(seg->pred_probs)); | 217 memset(seg->pred_probs, 255, sizeof(seg->pred_probs)); |
218 | 218 |
219 // First of all generate stats regarding how well the last segment map | 219 // First of all generate stats regarding how well the last segment map |
220 // predicts this one | 220 // predicts this one |
221 for (tile_col = 0; tile_col < 1 << cm->log2_tile_cols; tile_col++) { | 221 for (tile_col = 0; tile_col < 1 << cm->log2_tile_cols; tile_col++) { |
222 TileInfo tile; | 222 TileInfo tile; |
223 MODE_INFO *mi_ptr; | 223 MODE_INFO **mi_ptr; |
224 vp9_tile_init(&tile, cm, 0, tile_col); | 224 vp9_tile_init(&tile, cm, 0, tile_col); |
225 | 225 |
226 mi_ptr = cm->mi + tile.mi_col_start; | 226 mi_ptr = cm->mi_grid_visible + tile.mi_col_start; |
227 for (mi_row = 0; mi_row < cm->mi_rows; | 227 for (mi_row = 0; mi_row < cm->mi_rows; |
228 mi_row += 8, mi_ptr += 8 * cm->mi_stride) { | 228 mi_row += 8, mi_ptr += 8 * cm->mi_stride) { |
229 MODE_INFO *mi = mi_ptr; | 229 MODE_INFO **mi = mi_ptr; |
230 for (mi_col = tile.mi_col_start; mi_col < tile.mi_col_end; | 230 for (mi_col = tile.mi_col_start; mi_col < tile.mi_col_end; |
231 mi_col += 8, mi += 8) | 231 mi_col += 8, mi += 8) |
232 count_segs_sb(cm, xd, &tile, mi, no_pred_segcounts, | 232 count_segs_sb(cm, xd, &tile, mi, no_pred_segcounts, |
233 temporal_predictor_count, t_unpred_seg_counts, | 233 temporal_predictor_count, t_unpred_seg_counts, |
234 mi_row, mi_col, BLOCK_64X64); | 234 mi_row, mi_col, BLOCK_64X64); |
235 } | 235 } |
236 } | 236 } |
237 | 237 |
238 // Work out probability tree for coding segments without prediction | 238 // Work out probability tree for coding segments without prediction |
239 // and the cost. | 239 // and the cost. |
(...skipping 16 matching lines...) Expand all Loading... |
256 | 256 |
257 // Add in the predictor signaling cost | 257 // Add in the predictor signaling cost |
258 t_pred_cost += count0 * vp9_cost_zero(t_nopred_prob[i]) + | 258 t_pred_cost += count0 * vp9_cost_zero(t_nopred_prob[i]) + |
259 count1 * vp9_cost_one(t_nopred_prob[i]); | 259 count1 * vp9_cost_one(t_nopred_prob[i]); |
260 } | 260 } |
261 } | 261 } |
262 | 262 |
263 // Now choose which coding method to use. | 263 // Now choose which coding method to use. |
264 if (t_pred_cost < no_pred_cost) { | 264 if (t_pred_cost < no_pred_cost) { |
265 seg->temporal_update = 1; | 265 seg->temporal_update = 1; |
266 vpx_memcpy(seg->tree_probs, t_pred_tree, sizeof(t_pred_tree)); | 266 memcpy(seg->tree_probs, t_pred_tree, sizeof(t_pred_tree)); |
267 vpx_memcpy(seg->pred_probs, t_nopred_prob, sizeof(t_nopred_prob)); | 267 memcpy(seg->pred_probs, t_nopred_prob, sizeof(t_nopred_prob)); |
268 } else { | 268 } else { |
269 seg->temporal_update = 0; | 269 seg->temporal_update = 0; |
270 vpx_memcpy(seg->tree_probs, no_pred_tree, sizeof(no_pred_tree)); | 270 memcpy(seg->tree_probs, no_pred_tree, sizeof(no_pred_tree)); |
271 } | 271 } |
272 } | 272 } |
273 | 273 |
274 void vp9_reset_segment_features(struct segmentation *seg) { | 274 void vp9_reset_segment_features(struct segmentation *seg) { |
275 // Set up default state for MB feature flags | 275 // Set up default state for MB feature flags |
276 seg->enabled = 0; | 276 seg->enabled = 0; |
277 seg->update_map = 0; | 277 seg->update_map = 0; |
278 seg->update_data = 0; | 278 seg->update_data = 0; |
279 vpx_memset(seg->tree_probs, 255, sizeof(seg->tree_probs)); | 279 memset(seg->tree_probs, 255, sizeof(seg->tree_probs)); |
280 vp9_clearall_segfeatures(seg); | 280 vp9_clearall_segfeatures(seg); |
281 } | 281 } |
OLD | NEW |