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 |
11 #include <assert.h> | 11 #include <assert.h> |
12 | 12 |
13 #include "vp9/common/vp9_common.h" | 13 #include "vp9/common/vp9_common.h" |
14 #include "vp9/common/vp9_entropy.h" | 14 #include "vp9/common/vp9_entropy.h" |
15 #include "vp9/common/vp9_entropymode.h" | 15 #include "vp9/common/vp9_entropymode.h" |
16 #include "vp9/common/vp9_entropymv.h" | 16 #include "vp9/common/vp9_entropymv.h" |
17 #include "vp9/common/vp9_findnearmv.h" | 17 #include "vp9/common/vp9_findnearmv.h" |
18 #include "vp9/common/vp9_mvref_common.h" | 18 #include "vp9/common/vp9_mvref_common.h" |
19 #include "vp9/common/vp9_pred_common.h" | 19 #include "vp9/common/vp9_pred_common.h" |
20 #include "vp9/common/vp9_reconinter.h" | 20 #include "vp9/common/vp9_reconinter.h" |
21 #include "vp9/common/vp9_seg_common.h" | 21 #include "vp9/common/vp9_seg_common.h" |
22 | 22 |
| 23 #include "vp9/decoder/vp9_dboolhuff.h" |
23 #include "vp9/decoder/vp9_decodemv.h" | 24 #include "vp9/decoder/vp9_decodemv.h" |
24 #include "vp9/decoder/vp9_decodframe.h" | 25 #include "vp9/decoder/vp9_decodeframe.h" |
25 #include "vp9/decoder/vp9_onyxd_int.h" | 26 #include "vp9/decoder/vp9_onyxd_int.h" |
26 #include "vp9/decoder/vp9_treereader.h" | |
27 | 27 |
28 static MB_PREDICTION_MODE read_intra_mode(vp9_reader *r, const vp9_prob *p) { | 28 static MB_PREDICTION_MODE read_intra_mode(vp9_reader *r, const vp9_prob *p) { |
29 return (MB_PREDICTION_MODE)treed_read(r, vp9_intra_mode_tree, p); | 29 return (MB_PREDICTION_MODE)vp9_read_tree(r, vp9_intra_mode_tree, p); |
30 } | 30 } |
31 | 31 |
32 static MB_PREDICTION_MODE read_intra_mode_y(VP9_COMMON *cm, vp9_reader *r, | 32 static MB_PREDICTION_MODE read_intra_mode_y(VP9_COMMON *cm, vp9_reader *r, |
33 int size_group) { | 33 int size_group) { |
34 const MB_PREDICTION_MODE y_mode = read_intra_mode(r, | 34 const MB_PREDICTION_MODE y_mode = read_intra_mode(r, |
35 cm->fc.y_mode_prob[size_group]); | 35 cm->fc.y_mode_prob[size_group]); |
36 if (!cm->frame_parallel_decoding_mode) | 36 if (!cm->frame_parallel_decoding_mode) |
37 ++cm->counts.y_mode[size_group][y_mode]; | 37 ++cm->counts.y_mode[size_group][y_mode]; |
38 return y_mode; | 38 return y_mode; |
39 } | 39 } |
40 | 40 |
41 static MB_PREDICTION_MODE read_intra_mode_uv(VP9_COMMON *cm, vp9_reader *r, | 41 static MB_PREDICTION_MODE read_intra_mode_uv(VP9_COMMON *cm, vp9_reader *r, |
42 MB_PREDICTION_MODE y_mode) { | 42 MB_PREDICTION_MODE y_mode) { |
43 const MB_PREDICTION_MODE uv_mode = read_intra_mode(r, | 43 const MB_PREDICTION_MODE uv_mode = read_intra_mode(r, |
44 cm->fc.uv_mode_prob[y_mode]); | 44 cm->fc.uv_mode_prob[y_mode]); |
45 if (!cm->frame_parallel_decoding_mode) | 45 if (!cm->frame_parallel_decoding_mode) |
46 ++cm->counts.uv_mode[y_mode][uv_mode]; | 46 ++cm->counts.uv_mode[y_mode][uv_mode]; |
47 return uv_mode; | 47 return uv_mode; |
48 } | 48 } |
49 | 49 |
50 static MB_PREDICTION_MODE read_inter_mode(VP9_COMMON *cm, vp9_reader *r, | 50 static MB_PREDICTION_MODE read_inter_mode(VP9_COMMON *cm, vp9_reader *r, |
51 uint8_t context) { | 51 int ctx) { |
52 const MB_PREDICTION_MODE mode = treed_read(r, vp9_inter_mode_tree, | 52 const int mode = vp9_read_tree(r, vp9_inter_mode_tree, |
53 cm->fc.inter_mode_probs[context]); | 53 cm->fc.inter_mode_probs[ctx]); |
54 if (!cm->frame_parallel_decoding_mode) | 54 if (!cm->frame_parallel_decoding_mode) |
55 ++cm->counts.inter_mode[context][inter_mode_offset(mode)]; | 55 ++cm->counts.inter_mode[ctx][mode]; |
56 return mode; | 56 |
| 57 return NEARESTMV + mode; |
57 } | 58 } |
58 | 59 |
59 static int read_segment_id(vp9_reader *r, const struct segmentation *seg) { | 60 static int read_segment_id(vp9_reader *r, const struct segmentation *seg) { |
60 return treed_read(r, vp9_segment_tree, seg->tree_probs); | 61 return vp9_read_tree(r, vp9_segment_tree, seg->tree_probs); |
61 } | 62 } |
62 | 63 |
63 static TX_SIZE read_selected_tx_size(VP9_COMMON *cm, MACROBLOCKD *xd, | 64 static TX_SIZE read_selected_tx_size(VP9_COMMON *cm, MACROBLOCKD *xd, |
64 BLOCK_SIZE bsize, vp9_reader *r) { | 65 TX_SIZE max_tx_size, vp9_reader *r) { |
65 const uint8_t context = vp9_get_pred_context_tx_size(xd); | 66 const int ctx = vp9_get_tx_size_context(xd); |
66 const vp9_prob *tx_probs = get_tx_probs(bsize, context, &cm->fc.tx_probs); | 67 const vp9_prob *tx_probs = get_tx_probs(max_tx_size, ctx, &cm->fc.tx_probs); |
67 TX_SIZE tx_size = vp9_read(r, tx_probs[0]); | 68 TX_SIZE tx_size = vp9_read(r, tx_probs[0]); |
68 if (tx_size != TX_4X4 && bsize >= BLOCK_16X16) { | 69 if (tx_size != TX_4X4 && max_tx_size >= TX_16X16) { |
69 tx_size += vp9_read(r, tx_probs[1]); | 70 tx_size += vp9_read(r, tx_probs[1]); |
70 if (tx_size != TX_8X8 && bsize >= BLOCK_32X32) | 71 if (tx_size != TX_8X8 && max_tx_size >= TX_32X32) |
71 tx_size += vp9_read(r, tx_probs[2]); | 72 tx_size += vp9_read(r, tx_probs[2]); |
72 } | 73 } |
73 | 74 |
74 if (!cm->frame_parallel_decoding_mode) | 75 if (!cm->frame_parallel_decoding_mode) |
75 ++get_tx_counts(bsize, context, &cm->counts.tx)[tx_size]; | 76 ++get_tx_counts(max_tx_size, ctx, &cm->counts.tx)[tx_size]; |
76 return tx_size; | 77 return tx_size; |
77 } | 78 } |
78 | 79 |
79 static TX_SIZE read_tx_size(VP9_COMMON *const cm, MACROBLOCKD *const xd, | 80 static TX_SIZE read_tx_size(VP9_COMMON *cm, MACROBLOCKD *xd, TX_MODE tx_mode, |
80 TX_MODE tx_mode, BLOCK_SIZE bsize, int allow_select, | 81 BLOCK_SIZE bsize, int allow_select, vp9_reader *r) { |
81 vp9_reader *r) { | 82 const TX_SIZE max_tx_size = max_txsize_lookup[bsize]; |
82 if (allow_select && tx_mode == TX_MODE_SELECT && bsize >= BLOCK_8X8) { | 83 if (allow_select && tx_mode == TX_MODE_SELECT && bsize >= BLOCK_8X8) |
83 return read_selected_tx_size(cm, xd, bsize, r); | 84 return read_selected_tx_size(cm, xd, max_tx_size, r); |
84 } else { | 85 else |
85 const TX_SIZE max_tx_size_block = max_txsize_lookup[bsize]; | 86 return MIN(max_tx_size, tx_mode_to_biggest_tx_size[tx_mode]); |
86 const TX_SIZE max_tx_size_txmode = tx_mode_to_biggest_tx_size[tx_mode]; | |
87 return MIN(max_tx_size_block, max_tx_size_txmode); | |
88 } | |
89 } | 87 } |
90 | 88 |
91 static void set_segment_id(VP9_COMMON *cm, BLOCK_SIZE bsize, | 89 static void set_segment_id(VP9_COMMON *cm, BLOCK_SIZE bsize, |
92 int mi_row, int mi_col, int segment_id) { | 90 int mi_row, int mi_col, int segment_id) { |
93 const int mi_offset = mi_row * cm->mi_cols + mi_col; | 91 const int mi_offset = mi_row * cm->mi_cols + mi_col; |
94 const int bw = 1 << mi_width_log2(bsize); | 92 const int bw = num_8x8_blocks_wide_lookup[bsize]; |
95 const int bh = 1 << mi_height_log2(bsize); | 93 const int bh = num_8x8_blocks_high_lookup[bsize]; |
96 const int xmis = MIN(cm->mi_cols - mi_col, bw); | 94 const int xmis = MIN(cm->mi_cols - mi_col, bw); |
97 const int ymis = MIN(cm->mi_rows - mi_row, bh); | 95 const int ymis = MIN(cm->mi_rows - mi_row, bh); |
98 int x, y; | 96 int x, y; |
99 | 97 |
100 assert(segment_id >= 0 && segment_id < MAX_SEGMENTS); | 98 assert(segment_id >= 0 && segment_id < MAX_SEGMENTS); |
101 | 99 |
102 for (y = 0; y < ymis; y++) | 100 for (y = 0; y < ymis; y++) |
103 for (x = 0; x < xmis; x++) | 101 for (x = 0; x < xmis; x++) |
104 cm->last_frame_seg_map[mi_offset + y * cm->mi_cols + x] = segment_id; | 102 cm->last_frame_seg_map[mi_offset + y * cm->mi_cols + x] = segment_id; |
105 } | 103 } |
(...skipping 12 matching lines...) Expand all Loading... |
118 return 0; | 116 return 0; |
119 | 117 |
120 segment_id = read_segment_id(r, seg); | 118 segment_id = read_segment_id(r, seg); |
121 set_segment_id(cm, bsize, mi_row, mi_col, segment_id); | 119 set_segment_id(cm, bsize, mi_row, mi_col, segment_id); |
122 return segment_id; | 120 return segment_id; |
123 } | 121 } |
124 | 122 |
125 static int read_inter_segment_id(VP9_COMMON *const cm, MACROBLOCKD *const xd, | 123 static int read_inter_segment_id(VP9_COMMON *const cm, MACROBLOCKD *const xd, |
126 int mi_row, int mi_col, vp9_reader *r) { | 124 int mi_row, int mi_col, vp9_reader *r) { |
127 struct segmentation *const seg = &cm->seg; | 125 struct segmentation *const seg = &cm->seg; |
128 const BLOCK_SIZE bsize = xd->mi_8x8[0]->mbmi.sb_type; | 126 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
129 int pred_segment_id, segment_id; | 127 const BLOCK_SIZE bsize = mbmi->sb_type; |
| 128 int predicted_segment_id, segment_id; |
130 | 129 |
131 if (!seg->enabled) | 130 if (!seg->enabled) |
132 return 0; // Default for disabled segmentation | 131 return 0; // Default for disabled segmentation |
133 | 132 |
134 pred_segment_id = vp9_get_segment_id(cm, cm->last_frame_seg_map, | 133 predicted_segment_id = vp9_get_segment_id(cm, cm->last_frame_seg_map, |
135 bsize, mi_row, mi_col); | 134 bsize, mi_row, mi_col); |
136 if (!seg->update_map) | 135 if (!seg->update_map) |
137 return pred_segment_id; | 136 return predicted_segment_id; |
138 | 137 |
139 if (seg->temporal_update) { | 138 if (seg->temporal_update) { |
140 const vp9_prob pred_prob = vp9_get_pred_prob_seg_id(seg, xd); | 139 const vp9_prob pred_prob = vp9_get_pred_prob_seg_id(seg, xd); |
141 const int pred_flag = vp9_read(r, pred_prob); | 140 mbmi->seg_id_predicted = vp9_read(r, pred_prob); |
142 vp9_set_pred_flag_seg_id(xd, pred_flag); | 141 segment_id = mbmi->seg_id_predicted ? predicted_segment_id |
143 segment_id = pred_flag ? pred_segment_id | 142 : read_segment_id(r, seg); |
144 : read_segment_id(r, seg); | |
145 } else { | 143 } else { |
146 segment_id = read_segment_id(r, seg); | 144 segment_id = read_segment_id(r, seg); |
147 } | 145 } |
148 set_segment_id(cm, bsize, mi_row, mi_col, segment_id); | 146 set_segment_id(cm, bsize, mi_row, mi_col, segment_id); |
149 return segment_id; | 147 return segment_id; |
150 } | 148 } |
151 | 149 |
152 static uint8_t read_skip_coeff(VP9_COMMON *const cm, MACROBLOCKD *const xd, | 150 static int read_skip_coeff(VP9_COMMON *cm, const MACROBLOCKD *xd, |
153 int segment_id, vp9_reader *r) { | 151 int segment_id, vp9_reader *r) { |
154 int skip_coeff = vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP); | 152 if (vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)) { |
155 if (!skip_coeff) { | 153 return 1; |
156 const int ctx = vp9_get_pred_context_mbskip(xd); | 154 } else { |
157 skip_coeff = vp9_read(r, vp9_get_pred_prob_mbskip(cm, xd)); | 155 const int ctx = vp9_get_skip_context(xd); |
| 156 const int skip = vp9_read(r, cm->fc.mbskip_probs[ctx]); |
158 if (!cm->frame_parallel_decoding_mode) | 157 if (!cm->frame_parallel_decoding_mode) |
159 ++cm->counts.mbskip[ctx][skip_coeff]; | 158 ++cm->counts.mbskip[ctx][skip]; |
| 159 return skip; |
160 } | 160 } |
161 return skip_coeff; | |
162 } | 161 } |
163 | 162 |
164 static void read_intra_frame_mode_info(VP9_COMMON *const cm, | 163 static void read_intra_frame_mode_info(VP9_COMMON *const cm, |
165 MACROBLOCKD *const xd, | 164 MACROBLOCKD *const xd, |
166 MODE_INFO *const m, | |
167 int mi_row, int mi_col, vp9_reader *r) { | 165 int mi_row, int mi_col, vp9_reader *r) { |
168 MB_MODE_INFO *const mbmi = &m->mbmi; | 166 MODE_INFO *const mi = xd->mi_8x8[0]; |
169 const BLOCK_SIZE bsize = mbmi->sb_type; | 167 MB_MODE_INFO *const mbmi = &mi->mbmi; |
170 const MODE_INFO *above_mi = xd->mi_8x8[-cm->mode_info_stride]; | 168 const MODE_INFO *above_mi = xd->mi_8x8[-cm->mode_info_stride]; |
171 const MODE_INFO *left_mi = xd->left_available ? xd->mi_8x8[-1] : NULL; | 169 const MODE_INFO *left_mi = xd->left_available ? xd->mi_8x8[-1] : NULL; |
| 170 const BLOCK_SIZE bsize = mbmi->sb_type; |
172 | 171 |
173 mbmi->segment_id = read_intra_segment_id(cm, xd, mi_row, mi_col, r); | 172 mbmi->segment_id = read_intra_segment_id(cm, xd, mi_row, mi_col, r); |
174 mbmi->skip_coeff = read_skip_coeff(cm, xd, mbmi->segment_id, r); | 173 mbmi->skip_coeff = read_skip_coeff(cm, xd, mbmi->segment_id, r); |
175 mbmi->tx_size = read_tx_size(cm, xd, cm->tx_mode, bsize, 1, r); | 174 mbmi->tx_size = read_tx_size(cm, xd, cm->tx_mode, bsize, 1, r); |
176 mbmi->ref_frame[0] = INTRA_FRAME; | 175 mbmi->ref_frame[0] = INTRA_FRAME; |
177 mbmi->ref_frame[1] = NONE; | 176 mbmi->ref_frame[1] = NONE; |
178 | 177 |
179 if (bsize >= BLOCK_8X8) { | 178 if (bsize >= BLOCK_8X8) { |
180 const MB_PREDICTION_MODE A = above_block_mode(m, above_mi, 0); | 179 const MB_PREDICTION_MODE A = above_block_mode(mi, above_mi, 0); |
181 const MB_PREDICTION_MODE L = left_block_mode(m, left_mi, 0); | 180 const MB_PREDICTION_MODE L = left_block_mode(mi, left_mi, 0); |
182 mbmi->mode = read_intra_mode(r, vp9_kf_y_mode_prob[A][L]); | 181 mbmi->mode = read_intra_mode(r, vp9_kf_y_mode_prob[A][L]); |
183 } else { | 182 } else { |
184 // Only 4x4, 4x8, 8x4 blocks | 183 // Only 4x4, 4x8, 8x4 blocks |
185 const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize]; // 1 or 2 | 184 const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize]; // 1 or 2 |
186 const int num_4x4_h = num_4x4_blocks_high_lookup[bsize]; // 1 or 2 | 185 const int num_4x4_h = num_4x4_blocks_high_lookup[bsize]; // 1 or 2 |
187 int idx, idy; | 186 int idx, idy; |
188 | 187 |
189 for (idy = 0; idy < 2; idy += num_4x4_h) { | 188 for (idy = 0; idy < 2; idy += num_4x4_h) { |
190 for (idx = 0; idx < 2; idx += num_4x4_w) { | 189 for (idx = 0; idx < 2; idx += num_4x4_w) { |
191 const int ib = idy * 2 + idx; | 190 const int ib = idy * 2 + idx; |
192 const MB_PREDICTION_MODE A = above_block_mode(m, above_mi, ib); | 191 const MB_PREDICTION_MODE A = above_block_mode(mi, above_mi, ib); |
193 const MB_PREDICTION_MODE L = left_block_mode(m, left_mi, ib); | 192 const MB_PREDICTION_MODE L = left_block_mode(mi, left_mi, ib); |
194 const MB_PREDICTION_MODE b_mode = read_intra_mode(r, | 193 const MB_PREDICTION_MODE b_mode = read_intra_mode(r, |
195 vp9_kf_y_mode_prob[A][L]); | 194 vp9_kf_y_mode_prob[A][L]); |
196 m->bmi[ib].as_mode = b_mode; | 195 mi->bmi[ib].as_mode = b_mode; |
197 if (num_4x4_h == 2) | 196 if (num_4x4_h == 2) |
198 m->bmi[ib + 2].as_mode = b_mode; | 197 mi->bmi[ib + 2].as_mode = b_mode; |
199 if (num_4x4_w == 2) | 198 if (num_4x4_w == 2) |
200 m->bmi[ib + 1].as_mode = b_mode; | 199 mi->bmi[ib + 1].as_mode = b_mode; |
201 } | 200 } |
202 } | 201 } |
203 | 202 |
204 mbmi->mode = m->bmi[3].as_mode; | 203 mbmi->mode = mi->bmi[3].as_mode; |
205 } | 204 } |
206 | 205 |
207 mbmi->uv_mode = read_intra_mode(r, vp9_kf_uv_mode_prob[mbmi->mode]); | 206 mbmi->uv_mode = read_intra_mode(r, vp9_kf_uv_mode_prob[mbmi->mode]); |
208 } | 207 } |
209 | 208 |
210 static int read_mv_component(vp9_reader *r, | 209 static int read_mv_component(vp9_reader *r, |
211 const nmv_component *mvcomp, int usehp) { | 210 const nmv_component *mvcomp, int usehp) { |
212 int mag, d, fr, hp; | 211 int mag, d, fr, hp; |
213 const int sign = vp9_read(r, mvcomp->sign); | 212 const int sign = vp9_read(r, mvcomp->sign); |
214 const int mv_class = treed_read(r, vp9_mv_class_tree, mvcomp->classes); | 213 const int mv_class = vp9_read_tree(r, vp9_mv_class_tree, mvcomp->classes); |
215 const int class0 = mv_class == MV_CLASS_0; | 214 const int class0 = mv_class == MV_CLASS_0; |
216 | 215 |
217 // Integer part | 216 // Integer part |
218 if (class0) { | 217 if (class0) { |
219 d = treed_read(r, vp9_mv_class0_tree, mvcomp->class0); | 218 d = vp9_read_tree(r, vp9_mv_class0_tree, mvcomp->class0); |
220 } else { | 219 } else { |
221 int i; | 220 int i; |
222 const int n = mv_class + CLASS0_BITS - 1; // number of bits | 221 const int n = mv_class + CLASS0_BITS - 1; // number of bits |
223 | 222 |
224 d = 0; | 223 d = 0; |
225 for (i = 0; i < n; ++i) | 224 for (i = 0; i < n; ++i) |
226 d |= vp9_read(r, mvcomp->bits[i]) << i; | 225 d |= vp9_read(r, mvcomp->bits[i]) << i; |
227 } | 226 } |
228 | 227 |
229 // Fractional part | 228 // Fractional part |
230 fr = treed_read(r, vp9_mv_fp_tree, | 229 fr = vp9_read_tree(r, vp9_mv_fp_tree, class0 ? mvcomp->class0_fp[d] |
231 class0 ? mvcomp->class0_fp[d] : mvcomp->fp); | 230 : mvcomp->fp); |
232 | 231 |
233 | 232 |
234 // High precision part (if hp is not used, the default value of the hp is 1) | 233 // High precision part (if hp is not used, the default value of the hp is 1) |
235 hp = usehp ? vp9_read(r, class0 ? mvcomp->class0_hp : mvcomp->hp) | 234 hp = usehp ? vp9_read(r, class0 ? mvcomp->class0_hp : mvcomp->hp) |
236 : 1; | 235 : 1; |
237 | 236 |
238 // Result | 237 // Result |
239 mag = vp9_get_mv_mag(mv_class, (d << 3) | (fr << 1) | hp) + 1; | 238 mag = vp9_get_mv_mag(mv_class, (d << 3) | (fr << 1) | hp) + 1; |
240 return sign ? -mag : mag; | 239 return sign ? -mag : mag; |
241 } | 240 } |
242 | 241 |
243 static INLINE void read_mv(vp9_reader *r, MV *mv, const MV *ref, | 242 static INLINE void read_mv(vp9_reader *r, MV *mv, const MV *ref, |
244 const nmv_context *ctx, | 243 const nmv_context *ctx, |
245 nmv_context_counts *counts, int allow_hp) { | 244 nmv_context_counts *counts, int allow_hp) { |
246 const MV_JOINT_TYPE j = treed_read(r, vp9_mv_joint_tree, ctx->joints); | 245 const MV_JOINT_TYPE j = vp9_read_tree(r, vp9_mv_joint_tree, ctx->joints); |
247 const int use_hp = allow_hp && vp9_use_mv_hp(ref); | 246 const int use_hp = allow_hp && vp9_use_mv_hp(ref); |
248 MV diff = {0, 0}; | 247 MV diff = {0, 0}; |
249 | 248 |
250 if (mv_joint_vertical(j)) | 249 if (mv_joint_vertical(j)) |
251 diff.row = read_mv_component(r, &ctx->comps[0], use_hp); | 250 diff.row = read_mv_component(r, &ctx->comps[0], use_hp); |
252 | 251 |
253 if (mv_joint_horizontal(j)) | 252 if (mv_joint_horizontal(j)) |
254 diff.col = read_mv_component(r, &ctx->comps[1], use_hp); | 253 diff.col = read_mv_component(r, &ctx->comps[1], use_hp); |
255 | 254 |
256 vp9_inc_mv(&diff, counts); | 255 vp9_inc_mv(&diff, counts); |
257 | 256 |
258 mv->row = ref->row + diff.row; | 257 mv->row = ref->row + diff.row; |
259 mv->col = ref->col + diff.col; | 258 mv->col = ref->col + diff.col; |
260 } | 259 } |
261 | 260 |
| 261 static REFERENCE_MODE read_reference_mode(VP9_COMMON *cm, const MACROBLOCKD *xd, |
| 262 vp9_reader *r) { |
| 263 const int ctx = vp9_get_reference_mode_context(cm, xd); |
| 264 const int mode = vp9_read(r, cm->fc.comp_inter_prob[ctx]); |
| 265 if (!cm->frame_parallel_decoding_mode) |
| 266 ++cm->counts.comp_inter[ctx][mode]; |
| 267 return mode; // SINGLE_REFERENCE or COMPOUND_REFERENCE |
| 268 } |
| 269 |
262 // Read the referncence frame | 270 // Read the referncence frame |
263 static void read_ref_frames(VP9_COMMON *const cm, MACROBLOCKD *const xd, | 271 static void read_ref_frames(VP9_COMMON *const cm, MACROBLOCKD *const xd, |
264 vp9_reader *r, | 272 vp9_reader *r, |
265 int segment_id, MV_REFERENCE_FRAME ref_frame[2]) { | 273 int segment_id, MV_REFERENCE_FRAME ref_frame[2]) { |
266 FRAME_CONTEXT *const fc = &cm->fc; | 274 FRAME_CONTEXT *const fc = &cm->fc; |
267 FRAME_COUNTS *const counts = &cm->counts; | 275 FRAME_COUNTS *const counts = &cm->counts; |
268 | 276 |
269 if (vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) { | 277 if (vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) { |
270 ref_frame[0] = vp9_get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME); | 278 ref_frame[0] = vp9_get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME); |
271 ref_frame[1] = NONE; | 279 ref_frame[1] = NONE; |
272 } else { | 280 } else { |
273 const int comp_ctx = vp9_get_pred_context_comp_inter_inter(cm, xd); | 281 const REFERENCE_MODE mode = (cm->reference_mode == REFERENCE_MODE_SELECT) |
274 int is_comp; | 282 ? read_reference_mode(cm, xd, r) |
275 | 283 : cm->reference_mode; |
276 if (cm->comp_pred_mode == HYBRID_PREDICTION) { | |
277 is_comp = vp9_read(r, fc->comp_inter_prob[comp_ctx]); | |
278 if (!cm->frame_parallel_decoding_mode) | |
279 ++counts->comp_inter[comp_ctx][is_comp]; | |
280 } else { | |
281 is_comp = cm->comp_pred_mode == COMP_PREDICTION_ONLY; | |
282 } | |
283 | 284 |
284 // FIXME(rbultje) I'm pretty sure this breaks segmentation ref frame coding | 285 // FIXME(rbultje) I'm pretty sure this breaks segmentation ref frame coding |
285 if (is_comp) { | 286 if (mode == COMPOUND_REFERENCE) { |
286 const int fix_ref_idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref]; | 287 const int idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref]; |
287 const int ref_ctx = vp9_get_pred_context_comp_ref_p(cm, xd); | 288 const int ctx = vp9_get_pred_context_comp_ref_p(cm, xd); |
288 const int b = vp9_read(r, fc->comp_ref_prob[ref_ctx]); | 289 const int bit = vp9_read(r, fc->comp_ref_prob[ctx]); |
289 if (!cm->frame_parallel_decoding_mode) | 290 if (!cm->frame_parallel_decoding_mode) |
290 ++counts->comp_ref[ref_ctx][b]; | 291 ++counts->comp_ref[ctx][bit]; |
291 ref_frame[fix_ref_idx] = cm->comp_fixed_ref; | 292 ref_frame[idx] = cm->comp_fixed_ref; |
292 ref_frame[!fix_ref_idx] = cm->comp_var_ref[b]; | 293 ref_frame[!idx] = cm->comp_var_ref[bit]; |
293 } else { | 294 } else if (mode == SINGLE_REFERENCE) { |
294 const int ctx0 = vp9_get_pred_context_single_ref_p1(xd); | 295 const int ctx0 = vp9_get_pred_context_single_ref_p1(xd); |
295 const int bit0 = vp9_read(r, fc->single_ref_prob[ctx0][0]); | 296 const int bit0 = vp9_read(r, fc->single_ref_prob[ctx0][0]); |
296 if (!cm->frame_parallel_decoding_mode) | 297 if (!cm->frame_parallel_decoding_mode) |
297 ++counts->single_ref[ctx0][0][bit0]; | 298 ++counts->single_ref[ctx0][0][bit0]; |
298 if (bit0) { | 299 if (bit0) { |
299 const int ctx1 = vp9_get_pred_context_single_ref_p2(xd); | 300 const int ctx1 = vp9_get_pred_context_single_ref_p2(xd); |
300 const int bit1 = vp9_read(r, fc->single_ref_prob[ctx1][1]); | 301 const int bit1 = vp9_read(r, fc->single_ref_prob[ctx1][1]); |
301 ref_frame[0] = bit1 ? ALTREF_FRAME : GOLDEN_FRAME; | |
302 if (!cm->frame_parallel_decoding_mode) | 302 if (!cm->frame_parallel_decoding_mode) |
303 ++counts->single_ref[ctx1][1][bit1]; | 303 ++counts->single_ref[ctx1][1][bit1]; |
| 304 ref_frame[0] = bit1 ? ALTREF_FRAME : GOLDEN_FRAME; |
304 } else { | 305 } else { |
305 ref_frame[0] = LAST_FRAME; | 306 ref_frame[0] = LAST_FRAME; |
306 } | 307 } |
307 | 308 |
308 ref_frame[1] = NONE; | 309 ref_frame[1] = NONE; |
| 310 } else { |
| 311 assert(0 && "Invalid prediction mode."); |
309 } | 312 } |
310 } | 313 } |
311 } | 314 } |
312 | 315 |
313 | 316 |
314 static INLINE INTERPOLATION_TYPE read_switchable_filter_type( | 317 static INLINE INTERPOLATION_TYPE read_switchable_filter_type( |
315 VP9_COMMON *const cm, MACROBLOCKD *const xd, vp9_reader *r) { | 318 VP9_COMMON *const cm, MACROBLOCKD *const xd, vp9_reader *r) { |
316 const int ctx = vp9_get_pred_context_switchable_interp(xd); | 319 const int ctx = vp9_get_pred_context_switchable_interp(xd); |
317 const int type = treed_read(r, vp9_switchable_interp_tree, | 320 const int type = vp9_read_tree(r, vp9_switchable_interp_tree, |
318 cm->fc.switchable_interp_prob[ctx]); | 321 cm->fc.switchable_interp_prob[ctx]); |
319 if (!cm->frame_parallel_decoding_mode) | 322 if (!cm->frame_parallel_decoding_mode) |
320 ++cm->counts.switchable_interp[ctx][type]; | 323 ++cm->counts.switchable_interp[ctx][type]; |
321 return type; | 324 return type; |
322 } | 325 } |
323 | 326 |
324 static void read_intra_block_mode_info(VP9_COMMON *const cm, MODE_INFO *mi, | 327 static void read_intra_block_mode_info(VP9_COMMON *const cm, MODE_INFO *mi, |
325 vp9_reader *r) { | 328 vp9_reader *r) { |
326 MB_MODE_INFO *const mbmi = &mi->mbmi; | 329 MB_MODE_INFO *const mbmi = &mi->mbmi; |
327 const BLOCK_SIZE bsize = mi->mbmi.sb_type; | 330 const BLOCK_SIZE bsize = mi->mbmi.sb_type; |
328 | 331 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 } | 400 } |
398 return ret; | 401 return ret; |
399 } | 402 } |
400 | 403 |
401 static int read_is_inter_block(VP9_COMMON *const cm, MACROBLOCKD *const xd, | 404 static int read_is_inter_block(VP9_COMMON *const cm, MACROBLOCKD *const xd, |
402 int segment_id, vp9_reader *r) { | 405 int segment_id, vp9_reader *r) { |
403 if (vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) { | 406 if (vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) { |
404 return vp9_get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME) != | 407 return vp9_get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME) != |
405 INTRA_FRAME; | 408 INTRA_FRAME; |
406 } else { | 409 } else { |
407 const int ctx = vp9_get_pred_context_intra_inter(xd); | 410 const int ctx = vp9_get_intra_inter_context(xd); |
408 const int is_inter = vp9_read(r, vp9_get_pred_prob_intra_inter(cm, xd)); | 411 const int is_inter = vp9_read(r, cm->fc.intra_inter_prob[ctx]); |
409 if (!cm->frame_parallel_decoding_mode) | 412 if (!cm->frame_parallel_decoding_mode) |
410 ++cm->counts.intra_inter[ctx][is_inter]; | 413 ++cm->counts.intra_inter[ctx][is_inter]; |
411 return is_inter; | 414 return is_inter; |
412 } | 415 } |
413 } | 416 } |
414 | 417 |
415 static void read_inter_block_mode_info(VP9_COMMON *const cm, | 418 static void read_inter_block_mode_info(VP9_COMMON *const cm, |
416 MACROBLOCKD *const xd, | 419 MACROBLOCKD *const xd, |
417 const TileInfo *const tile, | 420 const TileInfo *const tile, |
418 MODE_INFO *const mi, | 421 MODE_INFO *const mi, |
419 int mi_row, int mi_col, vp9_reader *r) { | 422 int mi_row, int mi_col, vp9_reader *r) { |
420 MB_MODE_INFO *const mbmi = &mi->mbmi; | 423 MB_MODE_INFO *const mbmi = &mi->mbmi; |
421 const BLOCK_SIZE bsize = mbmi->sb_type; | 424 const BLOCK_SIZE bsize = mbmi->sb_type; |
422 const int allow_hp = cm->allow_high_precision_mv; | 425 const int allow_hp = cm->allow_high_precision_mv; |
423 | 426 |
424 int_mv nearest[2], nearmv[2], best[2]; | 427 int_mv nearest[2], nearmv[2], best[2]; |
425 uint8_t inter_mode_ctx; | 428 int inter_mode_ctx, ref, is_compound; |
426 MV_REFERENCE_FRAME ref0; | |
427 int is_compound; | |
428 | 429 |
429 mbmi->uv_mode = DC_PRED; | |
430 read_ref_frames(cm, xd, r, mbmi->segment_id, mbmi->ref_frame); | 430 read_ref_frames(cm, xd, r, mbmi->segment_id, mbmi->ref_frame); |
431 ref0 = mbmi->ref_frame[0]; | |
432 is_compound = has_second_ref(mbmi); | 431 is_compound = has_second_ref(mbmi); |
433 | 432 |
434 vp9_find_mv_refs(cm, xd, tile, mi, xd->last_mi, ref0, mbmi->ref_mvs[ref0], | 433 for (ref = 0; ref < 1 + is_compound; ++ref) { |
435 mi_row, mi_col); | 434 const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref]; |
| 435 vp9_find_mv_refs(cm, xd, tile, mi, xd->last_mi, frame, mbmi->ref_mvs[frame], |
| 436 mi_row, mi_col); |
| 437 } |
436 | 438 |
437 inter_mode_ctx = mbmi->mode_context[ref0]; | 439 inter_mode_ctx = mbmi->mode_context[mbmi->ref_frame[0]]; |
438 | 440 |
439 if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { | 441 if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { |
440 mbmi->mode = ZEROMV; | 442 mbmi->mode = ZEROMV; |
441 if (bsize < BLOCK_8X8) { | 443 if (bsize < BLOCK_8X8) { |
442 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, | 444 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, |
443 "Invalid usage of segement feature on small blocks"); | 445 "Invalid usage of segement feature on small blocks"); |
444 return; | 446 return; |
445 } | 447 } |
446 } else { | 448 } else { |
447 if (bsize >= BLOCK_8X8) | 449 if (bsize >= BLOCK_8X8) |
448 mbmi->mode = read_inter_mode(cm, r, inter_mode_ctx); | 450 mbmi->mode = read_inter_mode(cm, r, inter_mode_ctx); |
449 } | 451 } |
450 | 452 |
451 // nearest, nearby | |
452 if (bsize < BLOCK_8X8 || mbmi->mode != ZEROMV) { | 453 if (bsize < BLOCK_8X8 || mbmi->mode != ZEROMV) { |
453 vp9_find_best_ref_mvs(xd, allow_hp, | 454 for (ref = 0; ref < 1 + is_compound; ++ref) { |
454 mbmi->ref_mvs[ref0], &nearest[0], &nearmv[0]); | 455 vp9_find_best_ref_mvs(xd, allow_hp, mbmi->ref_mvs[mbmi->ref_frame[ref]], |
455 best[0].as_int = nearest[0].as_int; | 456 &nearest[ref], &nearmv[ref]); |
456 } | 457 best[ref].as_int = nearest[ref].as_int; |
457 | |
458 if (is_compound) { | |
459 const MV_REFERENCE_FRAME ref1 = mbmi->ref_frame[1]; | |
460 vp9_find_mv_refs(cm, xd, tile, mi, xd->last_mi, | |
461 ref1, mbmi->ref_mvs[ref1], mi_row, mi_col); | |
462 | |
463 if (bsize < BLOCK_8X8 || mbmi->mode != ZEROMV) { | |
464 vp9_find_best_ref_mvs(xd, allow_hp, | |
465 mbmi->ref_mvs[ref1], &nearest[1], &nearmv[1]); | |
466 best[1].as_int = nearest[1].as_int; | |
467 } | 458 } |
468 } | 459 } |
469 | 460 |
470 mbmi->interp_filter = (cm->mcomp_filter_type == SWITCHABLE) | 461 mbmi->interp_filter = (cm->mcomp_filter_type == SWITCHABLE) |
471 ? read_switchable_filter_type(cm, xd, r) | 462 ? read_switchable_filter_type(cm, xd, r) |
472 : cm->mcomp_filter_type; | 463 : cm->mcomp_filter_type; |
473 | 464 |
474 if (bsize < BLOCK_8X8) { | 465 if (bsize < BLOCK_8X8) { |
475 const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize]; // 1 or 2 | 466 const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize]; // 1 or 2 |
476 const int num_4x4_h = num_4x4_blocks_high_lookup[bsize]; // 1 or 2 | 467 const int num_4x4_h = num_4x4_blocks_high_lookup[bsize]; // 1 or 2 |
477 int idx, idy; | 468 int idx, idy; |
478 int b_mode; | 469 int b_mode; |
479 for (idy = 0; idy < 2; idy += num_4x4_h) { | 470 for (idy = 0; idy < 2; idy += num_4x4_h) { |
480 for (idx = 0; idx < 2; idx += num_4x4_w) { | 471 for (idx = 0; idx < 2; idx += num_4x4_w) { |
481 int_mv block[2]; | 472 int_mv block[2]; |
482 const int j = idy * 2 + idx; | 473 const int j = idy * 2 + idx; |
483 b_mode = read_inter_mode(cm, r, inter_mode_ctx); | 474 b_mode = read_inter_mode(cm, r, inter_mode_ctx); |
484 | 475 |
485 if (b_mode == NEARESTMV || b_mode == NEARMV) { | 476 if (b_mode == NEARESTMV || b_mode == NEARMV) |
486 vp9_append_sub8x8_mvs_for_idx(cm, xd, tile, &nearest[0], | 477 for (ref = 0; ref < 1 + is_compound; ++ref) |
487 &nearmv[0], j, 0, | 478 vp9_append_sub8x8_mvs_for_idx(cm, xd, tile, j, ref, mi_row, mi_col, |
488 mi_row, mi_col); | 479 &nearest[ref], &nearmv[ref]); |
489 | |
490 if (is_compound) | |
491 vp9_append_sub8x8_mvs_for_idx(cm, xd, tile, &nearest[1], | |
492 &nearmv[1], j, 1, | |
493 mi_row, mi_col); | |
494 } | |
495 | 480 |
496 if (!assign_mv(cm, b_mode, block, best, nearest, nearmv, | 481 if (!assign_mv(cm, b_mode, block, best, nearest, nearmv, |
497 is_compound, allow_hp, r)) { | 482 is_compound, allow_hp, r)) { |
498 xd->corrupted |= 1; | 483 xd->corrupted |= 1; |
499 break; | 484 break; |
500 }; | 485 }; |
501 | 486 |
502 | |
503 mi->bmi[j].as_mv[0].as_int = block[0].as_int; | 487 mi->bmi[j].as_mv[0].as_int = block[0].as_int; |
504 if (is_compound) | 488 if (is_compound) |
505 mi->bmi[j].as_mv[1].as_int = block[1].as_int; | 489 mi->bmi[j].as_mv[1].as_int = block[1].as_int; |
506 | 490 |
507 if (num_4x4_h == 2) | 491 if (num_4x4_h == 2) |
508 mi->bmi[j + 2] = mi->bmi[j]; | 492 mi->bmi[j + 2] = mi->bmi[j]; |
509 if (num_4x4_w == 2) | 493 if (num_4x4_w == 2) |
510 mi->bmi[j + 1] = mi->bmi[j]; | 494 mi->bmi[j + 1] = mi->bmi[j]; |
511 } | 495 } |
512 } | 496 } |
513 | 497 |
514 mi->mbmi.mode = b_mode; | 498 mi->mbmi.mode = b_mode; |
515 | 499 |
516 mbmi->mv[0].as_int = mi->bmi[3].as_mv[0].as_int; | 500 mbmi->mv[0].as_int = mi->bmi[3].as_mv[0].as_int; |
517 mbmi->mv[1].as_int = mi->bmi[3].as_mv[1].as_int; | 501 mbmi->mv[1].as_int = mi->bmi[3].as_mv[1].as_int; |
518 } else { | 502 } else { |
519 xd->corrupted |= !assign_mv(cm, mbmi->mode, mbmi->mv, | 503 xd->corrupted |= !assign_mv(cm, mbmi->mode, mbmi->mv, |
520 best, nearest, nearmv, | 504 best, nearest, nearmv, |
521 is_compound, allow_hp, r); | 505 is_compound, allow_hp, r); |
522 } | 506 } |
523 } | 507 } |
524 | 508 |
525 static void read_inter_frame_mode_info(VP9_COMMON *const cm, | 509 static void read_inter_frame_mode_info(VP9_COMMON *const cm, |
526 MACROBLOCKD *const xd, | 510 MACROBLOCKD *const xd, |
527 const TileInfo *const tile, | 511 const TileInfo *const tile, |
528 MODE_INFO *const mi, | |
529 int mi_row, int mi_col, vp9_reader *r) { | 512 int mi_row, int mi_col, vp9_reader *r) { |
| 513 MODE_INFO *const mi = xd->mi_8x8[0]; |
530 MB_MODE_INFO *const mbmi = &mi->mbmi; | 514 MB_MODE_INFO *const mbmi = &mi->mbmi; |
531 int inter_block; | 515 int inter_block; |
532 | 516 |
533 mbmi->mv[0].as_int = 0; | 517 mbmi->mv[0].as_int = 0; |
534 mbmi->mv[1].as_int = 0; | 518 mbmi->mv[1].as_int = 0; |
535 mbmi->segment_id = read_inter_segment_id(cm, xd, mi_row, mi_col, r); | 519 mbmi->segment_id = read_inter_segment_id(cm, xd, mi_row, mi_col, r); |
536 mbmi->skip_coeff = read_skip_coeff(cm, xd, mbmi->segment_id, r); | 520 mbmi->skip_coeff = read_skip_coeff(cm, xd, mbmi->segment_id, r); |
537 inter_block = read_is_inter_block(cm, xd, mbmi->segment_id, r); | 521 inter_block = read_is_inter_block(cm, xd, mbmi->segment_id, r); |
538 mbmi->tx_size = read_tx_size(cm, xd, cm->tx_mode, mbmi->sb_type, | 522 mbmi->tx_size = read_tx_size(cm, xd, cm->tx_mode, mbmi->sb_type, |
539 !mbmi->skip_coeff || !inter_block, r); | 523 !mbmi->skip_coeff || !inter_block, r); |
540 | 524 |
541 if (inter_block) | 525 if (inter_block) |
542 read_inter_block_mode_info(cm, xd, tile, mi, mi_row, mi_col, r); | 526 read_inter_block_mode_info(cm, xd, tile, mi, mi_row, mi_col, r); |
543 else | 527 else |
544 read_intra_block_mode_info(cm, mi, r); | 528 read_intra_block_mode_info(cm, mi, r); |
545 } | 529 } |
546 | 530 |
547 void vp9_read_mode_info(VP9_COMMON *cm, MACROBLOCKD *xd, | 531 void vp9_read_mode_info(VP9_COMMON *cm, MACROBLOCKD *xd, const TileInfo *tile, |
548 const TileInfo *const tile, | |
549 int mi_row, int mi_col, vp9_reader *r) { | 532 int mi_row, int mi_col, vp9_reader *r) { |
550 MODE_INFO *const mi = xd->mi_8x8[0]; | |
551 const BLOCK_SIZE bsize = mi->mbmi.sb_type; | |
552 const int bw = 1 << mi_width_log2(bsize); | |
553 const int bh = 1 << mi_height_log2(bsize); | |
554 const int y_mis = MIN(bh, cm->mi_rows - mi_row); | |
555 const int x_mis = MIN(bw, cm->mi_cols - mi_col); | |
556 int x, y, z; | |
557 | |
558 if (frame_is_intra_only(cm)) | 533 if (frame_is_intra_only(cm)) |
559 read_intra_frame_mode_info(cm, xd, mi, mi_row, mi_col, r); | 534 read_intra_frame_mode_info(cm, xd, mi_row, mi_col, r); |
560 else | 535 else |
561 read_inter_frame_mode_info(cm, xd, tile, mi, mi_row, mi_col, r); | 536 read_inter_frame_mode_info(cm, xd, tile, mi_row, mi_col, r); |
562 | |
563 for (y = 0, z = 0; y < y_mis; y++, z += cm->mode_info_stride) { | |
564 for (x = !y; x < x_mis; x++) { | |
565 xd->mi_8x8[z + x] = mi; | |
566 } | |
567 } | |
568 } | 537 } |
OLD | NEW |