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

Side by Side Diff: source/libvpx/vp8/decoder/decodframe.c

Issue 7671004: Update libvpx snapshot to v0.9.7-p1 (Cayuga). (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/libvpx/
Patch Set: '' Created 9 years, 4 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
« no previous file with comments | « source/libvpx/vp8/decoder/decodemv.c ('k') | source/libvpx/vp8/decoder/detokenize.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) 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 11
12 #include "onyxd_int.h" 12 #include "onyxd_int.h"
13 #include "vp8/common/header.h" 13 #include "vp8/common/header.h"
14 #include "vp8/common/reconintra.h" 14 #include "vp8/common/reconintra.h"
15 #include "vp8/common/reconintra4x4.h" 15 #include "vp8/common/reconintra4x4.h"
16 #include "vp8/common/recon.h" 16 #include "vp8/common/recon.h"
17 #include "vp8/common/reconinter.h" 17 #include "vp8/common/reconinter.h"
18 #include "dequantize.h" 18 #include "dequantize.h"
19 #include "detokenize.h" 19 #include "detokenize.h"
20 #include "vp8/common/invtrans.h" 20 #include "vp8/common/invtrans.h"
21 #include "vp8/common/alloccommon.h" 21 #include "vp8/common/alloccommon.h"
22 #include "vp8/common/entropymode.h" 22 #include "vp8/common/entropymode.h"
23 #include "vp8/common/quant_common.h" 23 #include "vp8/common/quant_common.h"
24 #include "vpx_scale/vpxscale.h" 24 #include "vpx_scale/vpxscale.h"
25 #include "vpx_scale/yv12extend.h" 25 #include "vpx_scale/yv12extend.h"
26 #include "vp8/common/setupintrarecon.h" 26 #include "vp8/common/setupintrarecon.h"
27 27
28 #include "decodemv.h" 28 #include "decodemv.h"
29 #include "vp8/common/extend.h" 29 #include "vp8/common/extend.h"
30 #if CONFIG_ERROR_CONCEALMENT
31 #include "error_concealment.h"
32 #endif
30 #include "vpx_mem/vpx_mem.h" 33 #include "vpx_mem/vpx_mem.h"
31 #include "vp8/common/idct.h" 34 #include "vp8/common/idct.h"
32 #include "dequantize.h" 35 #include "dequantize.h"
33 #include "vp8/common/threading.h" 36 #include "vp8/common/threading.h"
34 #include "decoderthreading.h" 37 #include "decoderthreading.h"
35 #include "dboolhuff.h" 38 #include "dboolhuff.h"
36 39
37 #include <assert.h> 40 #include <assert.h>
38 #include <stdio.h> 41 #include <stdio.h>
39 42
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 #define RTCD_VTABLE(x) (&(pbi)->common.rtcd.x) 107 #define RTCD_VTABLE(x) (&(pbi)->common.rtcd.x)
105 #else 108 #else
106 #define RTCD_VTABLE(x) NULL 109 #define RTCD_VTABLE(x) NULL
107 #endif 110 #endif
108 111
109 /* skip_recon_mb() is Modified: Instead of writing the result to predictor buffe r and then copying it 112 /* skip_recon_mb() is Modified: Instead of writing the result to predictor buffe r and then copying it
110 * to dst buffer, we can write the result directly to dst buffer. This eliminat es unnecessary copy. 113 * to dst buffer, we can write the result directly to dst buffer. This eliminat es unnecessary copy.
111 */ 114 */
112 static void skip_recon_mb(VP8D_COMP *pbi, MACROBLOCKD *xd) 115 static void skip_recon_mb(VP8D_COMP *pbi, MACROBLOCKD *xd)
113 { 116 {
114 if (xd->frame_type == KEY_FRAME || xd->mode_info_context->mbmi.ref_frame = = INTRA_FRAME) 117 if (xd->mode_info_context->mbmi.ref_frame == INTRA_FRAME)
115 { 118 {
116 119 RECON_INVOKE(&pbi->common.rtcd.recon, build_intra_predictors_mbuv_s)(xd) ;
117 vp8_build_intra_predictors_mbuv_s(xd);
118 RECON_INVOKE(&pbi->common.rtcd.recon, 120 RECON_INVOKE(&pbi->common.rtcd.recon,
119 build_intra_predictors_mby_s)(xd); 121 build_intra_predictors_mby_s)(xd);
120 } 122 }
121 else 123 else
122 { 124 {
123 vp8_build_inter_predictors_mb_s(xd); 125 vp8_build_inter16x16_predictors_mb(xd, xd->dst.y_buffer,
126 xd->dst.u_buffer, xd->dst.v_buffer,
127 xd->dst.y_stride, xd->dst.uv_stride);
124 } 128 }
125 } 129 }
126 130
127 static void clamp_mv_to_umv_border(MV *mv, const MACROBLOCKD *xd) 131 static void clamp_mv_to_umv_border(MV *mv, const MACROBLOCKD *xd)
128 { 132 {
129 /* If the MV points so far into the UMV border that no visible pixels 133 /* If the MV points so far into the UMV border that no visible pixels
130 * are used for reconstruction, the subpel part of the MV can be 134 * are used for reconstruction, the subpel part of the MV can be
131 * discarded and the MV limited to 16 pixels with equivalent results. 135 * discarded and the MV limited to 16 pixels with equivalent results.
132 * 136 *
133 * This limit kicks in at 19 pixels for the top and left edges, for 137 * This limit kicks in at 19 pixels for the top and left edges, for
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 clamp_uvmv_to_umv_border(&xd->block[i].bmi.mv.as_mv, xd); 172 clamp_uvmv_to_umv_border(&xd->block[i].bmi.mv.as_mv, xd);
169 } 173 }
170 else 174 else
171 { 175 {
172 clamp_mv_to_umv_border(&xd->mode_info_context->mbmi.mv.as_mv, xd); 176 clamp_mv_to_umv_border(&xd->mode_info_context->mbmi.mv.as_mv, xd);
173 clamp_uvmv_to_umv_border(&xd->block[16].bmi.mv.as_mv, xd); 177 clamp_uvmv_to_umv_border(&xd->block[16].bmi.mv.as_mv, xd);
174 } 178 }
175 179
176 } 180 }
177 181
178 static void decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd) 182 static void decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd,
183 unsigned int mb_idx)
179 { 184 {
180 int eobtotal = 0; 185 int eobtotal = 0;
181 int i, do_clamp = xd->mode_info_context->mbmi.need_to_clamp_mvs; 186 int throw_residual = 0;
187 MB_PREDICTION_MODE mode;
188 int i;
182 189
183 if (xd->mode_info_context->mbmi.mb_skip_coeff) 190 if (xd->mode_info_context->mbmi.mb_skip_coeff)
184 { 191 {
185 vp8_reset_mb_tokens_context(xd); 192 vp8_reset_mb_tokens_context(xd);
186 } 193 }
187 else 194 else
188 { 195 {
189 eobtotal = vp8_decode_mb_tokens(pbi, xd); 196 eobtotal = vp8_decode_mb_tokens(pbi, xd);
190 } 197 }
191 198
192 /* Perform temporary clamping of the MV to be used for prediction */ 199 /* Perform temporary clamping of the MV to be used for prediction */
193 if (do_clamp) 200 if (xd->mode_info_context->mbmi.need_to_clamp_mvs)
194 { 201 {
195 clamp_mvs(xd); 202 clamp_mvs(xd);
196 } 203 }
197 204
198 xd->mode_info_context->mbmi.dc_diff = 1; 205 mode = xd->mode_info_context->mbmi.mode;
199 206
200 if (xd->mode_info_context->mbmi.mode != B_PRED && xd->mode_info_context->mbm i.mode != SPLITMV && eobtotal == 0) 207 if (eobtotal == 0 && mode != B_PRED && mode != SPLITMV &&
208 !vp8dx_bool_error(xd->current_bc))
201 { 209 {
202 xd->mode_info_context->mbmi.dc_diff = 0; 210 /* Special case: Force the loopfilter to skip when eobtotal and
211 * mb_skip_coeff are zero.
212 * */
213 xd->mode_info_context->mbmi.mb_skip_coeff = 1;
214
203 skip_recon_mb(pbi, xd); 215 skip_recon_mb(pbi, xd);
204 return; 216 return;
205 } 217 }
206 218
207 if (xd->segmentation_enabled) 219 if (xd->segmentation_enabled)
208 mb_init_dequantizer(pbi, xd); 220 mb_init_dequantizer(pbi, xd);
209 221
210 /* do prediction */ 222 /* do prediction */
211 if (xd->frame_type == KEY_FRAME || xd->mode_info_context->mbmi.ref_frame = = INTRA_FRAME) 223 if (xd->mode_info_context->mbmi.ref_frame == INTRA_FRAME)
212 { 224 {
213 vp8_build_intra_predictors_mbuv(xd); 225 RECON_INVOKE(&pbi->common.rtcd.recon, build_intra_predictors_mbuv)(xd);
214 226
215 if (xd->mode_info_context->mbmi.mode != B_PRED) 227 if (mode != B_PRED)
216 { 228 {
217 RECON_INVOKE(&pbi->common.rtcd.recon, 229 RECON_INVOKE(&pbi->common.rtcd.recon,
218 build_intra_predictors_mby)(xd); 230 build_intra_predictors_mby)(xd);
219 } else { 231 } else {
220 vp8_intra_prediction_down_copy(xd); 232 vp8_intra_prediction_down_copy(xd);
221 } 233 }
222 } 234 }
223 else 235 else
224 { 236 {
225 vp8_build_inter_predictors_mb(xd); 237 vp8_build_inter_predictors_mb(xd);
226 } 238 }
227 239
240 /* When we have independent partitions we can apply residual even
241 * though other partitions within the frame are corrupt.
242 */
243 throw_residual = (!pbi->independent_partitions &&
244 pbi->frame_corrupt_residual);
245 throw_residual = (throw_residual || vp8dx_bool_error(xd->current_bc));
246
247 #if CONFIG_ERROR_CONCEALMENT
248 if (pbi->ec_active &&
249 (mb_idx >= pbi->mvs_corrupt_from_mb || throw_residual))
250 {
251 /* MB with corrupt residuals or corrupt mode/motion vectors.
252 * Better to use the predictor as reconstruction.
253 */
254 pbi->frame_corrupt_residual = 1;
255 vpx_memset(xd->qcoeff, 0, sizeof(xd->qcoeff));
256 vp8_conceal_corrupt_mb(xd);
257 return;
258 }
259 #endif
260
228 /* dequantization and idct */ 261 /* dequantization and idct */
229 if (xd->mode_info_context->mbmi.mode != B_PRED && xd->mode_info_context->mbm i.mode != SPLITMV) 262 if (mode == B_PRED)
263 {
264 for (i = 0; i < 16; i++)
265 {
266 BLOCKD *b = &xd->block[i];
267 RECON_INVOKE(RTCD_VTABLE(recon), intra4x4_predict)
268 (b, b->bmi.as_mode, b->predictor);
269
270 if (xd->eobs[i] > 1)
271 {
272 DEQUANT_INVOKE(&pbi->dequant, idct_add)
273 (b->qcoeff, b->dequant, b->predictor,
274 *(b->base_dst) + b->dst, 16, b->dst_stride);
275 }
276 else
277 {
278 IDCT_INVOKE(RTCD_VTABLE(idct), idct1_scalar_add)
279 (b->qcoeff[0] * b->dequant[0], b->predictor,
280 *(b->base_dst) + b->dst, 16, b->dst_stride);
281 ((int *)b->qcoeff)[0] = 0;
282 }
283 }
284
285 }
286 else if (mode == SPLITMV)
287 {
288 DEQUANT_INVOKE (&pbi->dequant, idct_add_y_block)
289 (xd->qcoeff, xd->block[0].dequant,
290 xd->predictor, xd->dst.y_buffer,
291 xd->dst.y_stride, xd->eobs);
292 }
293 else
230 { 294 {
231 BLOCKD *b = &xd->block[24]; 295 BLOCKD *b = &xd->block[24];
296
232 DEQUANT_INVOKE(&pbi->dequant, block)(b); 297 DEQUANT_INVOKE(&pbi->dequant, block)(b);
233 298
234 /* do 2nd order transform on the dc block */ 299 /* do 2nd order transform on the dc block */
235 if (xd->eobs[24] > 1) 300 if (xd->eobs[24] > 1)
236 { 301 {
237 IDCT_INVOKE(RTCD_VTABLE(idct), iwalsh16)(&b->dqcoeff[0], b->diff); 302 IDCT_INVOKE(RTCD_VTABLE(idct), iwalsh16)(&b->dqcoeff[0], b->diff);
238 ((int *)b->qcoeff)[0] = 0; 303 ((int *)b->qcoeff)[0] = 0;
239 ((int *)b->qcoeff)[1] = 0; 304 ((int *)b->qcoeff)[1] = 0;
240 ((int *)b->qcoeff)[2] = 0; 305 ((int *)b->qcoeff)[2] = 0;
241 ((int *)b->qcoeff)[3] = 0; 306 ((int *)b->qcoeff)[3] = 0;
242 ((int *)b->qcoeff)[4] = 0; 307 ((int *)b->qcoeff)[4] = 0;
243 ((int *)b->qcoeff)[5] = 0; 308 ((int *)b->qcoeff)[5] = 0;
244 ((int *)b->qcoeff)[6] = 0; 309 ((int *)b->qcoeff)[6] = 0;
245 ((int *)b->qcoeff)[7] = 0; 310 ((int *)b->qcoeff)[7] = 0;
246 } 311 }
247 else 312 else
248 { 313 {
249 IDCT_INVOKE(RTCD_VTABLE(idct), iwalsh1)(&b->dqcoeff[0], b->diff); 314 IDCT_INVOKE(RTCD_VTABLE(idct), iwalsh1)(&b->dqcoeff[0], b->diff);
250 ((int *)b->qcoeff)[0] = 0; 315 ((int *)b->qcoeff)[0] = 0;
251 } 316 }
252 317
253 DEQUANT_INVOKE (&pbi->dequant, dc_idct_add_y_block) 318 DEQUANT_INVOKE (&pbi->dequant, dc_idct_add_y_block)
254 (xd->qcoeff, xd->block[0].dequant, 319 (xd->qcoeff, xd->block[0].dequant,
255 xd->predictor, xd->dst.y_buffer, 320 xd->predictor, xd->dst.y_buffer,
256 xd->dst.y_stride, xd->eobs, xd->block[24].diff); 321 xd->dst.y_stride, xd->eobs, xd->block[24].diff);
257 } 322 }
258 else if ((xd->frame_type == KEY_FRAME || xd->mode_info_context->mbmi.ref_f rame == INTRA_FRAME) && xd->mode_info_context->mbmi.mode == B_PRED)
259 {
260 for (i = 0; i < 16; i++)
261 {
262
263 BLOCKD *b = &xd->block[i];
264 vp8_predict_intra4x4(b, b->bmi.mode, b->predictor);
265
266 if (xd->eobs[i] > 1)
267 {
268 DEQUANT_INVOKE(&pbi->dequant, idct_add)
269 (b->qcoeff, b->dequant, b->predictor,
270 *(b->base_dst) + b->dst, 16, b->dst_stride);
271 }
272 else
273 {
274 IDCT_INVOKE(RTCD_VTABLE(idct), idct1_scalar_add)
275 (b->qcoeff[0] * b->dequant[0], b->predictor,
276 *(b->base_dst) + b->dst, 16, b->dst_stride);
277 ((int *)b->qcoeff)[0] = 0;
278 }
279 }
280
281 }
282 else
283 {
284 DEQUANT_INVOKE (&pbi->dequant, idct_add_y_block)
285 (xd->qcoeff, xd->block[0].dequant,
286 xd->predictor, xd->dst.y_buffer,
287 xd->dst.y_stride, xd->eobs);
288 }
289 323
290 DEQUANT_INVOKE (&pbi->dequant, idct_add_uv_block) 324 DEQUANT_INVOKE (&pbi->dequant, idct_add_uv_block)
291 (xd->qcoeff+16*16, xd->block[16].dequant, 325 (xd->qcoeff+16*16, xd->block[16].dequant,
292 xd->predictor+16*16, xd->dst.u_buffer, xd->dst.v_buffer, 326 xd->predictor+16*16, xd->dst.u_buffer, xd->dst.v_buffer,
293 xd->dst.uv_stride, xd->eobs+16); 327 xd->dst.uv_stride, xd->eobs+16);
294 } 328 }
295 329
296 330
297 static int get_delta_q(vp8_reader *bc, int prev, int *q_update) 331 static int get_delta_q(vp8_reader *bc, int prev, int *q_update)
298 { 332 {
(...skipping 17 matching lines...) Expand all
316 #ifdef PACKET_TESTING 350 #ifdef PACKET_TESTING
317 #include <stdio.h> 351 #include <stdio.h>
318 FILE *vpxlog = 0; 352 FILE *vpxlog = 0;
319 #endif 353 #endif
320 354
321 355
322 356
323 static void 357 static void
324 decode_mb_row(VP8D_COMP *pbi, VP8_COMMON *pc, int mb_row, MACROBLOCKD *xd) 358 decode_mb_row(VP8D_COMP *pbi, VP8_COMMON *pc, int mb_row, MACROBLOCKD *xd)
325 { 359 {
326
327 int i;
328 int recon_yoffset, recon_uvoffset; 360 int recon_yoffset, recon_uvoffset;
329 int mb_col; 361 int mb_col;
330 int ref_fb_idx = pc->lst_fb_idx; 362 int ref_fb_idx = pc->lst_fb_idx;
331 int dst_fb_idx = pc->new_fb_idx; 363 int dst_fb_idx = pc->new_fb_idx;
332 int recon_y_stride = pc->yv12_fb[ref_fb_idx].y_stride; 364 int recon_y_stride = pc->yv12_fb[ref_fb_idx].y_stride;
333 int recon_uv_stride = pc->yv12_fb[ref_fb_idx].uv_stride; 365 int recon_uv_stride = pc->yv12_fb[ref_fb_idx].uv_stride;
334 366
335 vpx_memset(&pc->left_context, 0, sizeof(pc->left_context)); 367 vpx_memset(&pc->left_context, 0, sizeof(pc->left_context));
336 recon_yoffset = mb_row * recon_y_stride * 16; 368 recon_yoffset = mb_row * recon_y_stride * 16;
337 recon_uvoffset = mb_row * recon_uv_stride * 8; 369 recon_uvoffset = mb_row * recon_uv_stride * 8;
338 /* reset above block coeffs */ 370 /* reset above block coeffs */
339 371
340 xd->above_context = pc->above_context; 372 xd->above_context = pc->above_context;
341 xd->up_available = (mb_row != 0); 373 xd->up_available = (mb_row != 0);
342 374
343 xd->mb_to_top_edge = -((mb_row * 16)) << 3; 375 xd->mb_to_top_edge = -((mb_row * 16)) << 3;
344 xd->mb_to_bottom_edge = ((pc->mb_rows - 1 - mb_row) * 16) << 3; 376 xd->mb_to_bottom_edge = ((pc->mb_rows - 1 - mb_row) * 16) << 3;
345 377
346 for (mb_col = 0; mb_col < pc->mb_cols; mb_col++) 378 for (mb_col = 0; mb_col < pc->mb_cols; mb_col++)
347 { 379 {
348
349 if (xd->mode_info_context->mbmi.mode == SPLITMV || xd->mode_info_context ->mbmi.mode == B_PRED)
350 {
351 for (i = 0; i < 16; i++)
352 {
353 BLOCKD *d = &xd->block[i];
354 vpx_memcpy(&d->bmi, &xd->mode_info_context->bmi[i], sizeof(B_MOD E_INFO));
355 }
356 }
357
358 /* Distance of Mb to the various image edges. 380 /* Distance of Mb to the various image edges.
359 * These are specified to 8th pel as they are always compared to values that are in 1/8th pel units 381 * These are specified to 8th pel as they are always compared to values
382 * that are in 1/8th pel units
360 */ 383 */
361 xd->mb_to_left_edge = -((mb_col * 16) << 3); 384 xd->mb_to_left_edge = -((mb_col * 16) << 3);
362 xd->mb_to_right_edge = ((pc->mb_cols - 1 - mb_col) * 16) << 3; 385 xd->mb_to_right_edge = ((pc->mb_cols - 1 - mb_col) * 16) << 3;
363 386
387 #if CONFIG_ERROR_CONCEALMENT
388 {
389 int corrupt_residual = (!pbi->independent_partitions &&
390 pbi->frame_corrupt_residual) ||
391 vp8dx_bool_error(xd->current_bc);
392 if (pbi->ec_active &&
393 xd->mode_info_context->mbmi.ref_frame == INTRA_FRAME &&
394 corrupt_residual)
395 {
396 /* We have an intra block with corrupt coefficients, better to
397 * conceal with an inter block. Interpolate MVs from neighboring
398 * MBs.
399 *
400 * Note that for the first mb with corrupt residual in a frame,
401 * we might not discover that before decoding the residual. That
402 * happens after this check, and therefore no inter concealment
403 * will be done.
404 */
405 vp8_interpolate_motion(xd,
406 mb_row, mb_col,
407 pc->mb_rows, pc->mb_cols,
408 pc->mode_info_stride);
409 }
410 }
411 #endif
412
413 update_blockd_bmi(xd);
414
364 xd->dst.y_buffer = pc->yv12_fb[dst_fb_idx].y_buffer + recon_yoffset; 415 xd->dst.y_buffer = pc->yv12_fb[dst_fb_idx].y_buffer + recon_yoffset;
365 xd->dst.u_buffer = pc->yv12_fb[dst_fb_idx].u_buffer + recon_uvoffset; 416 xd->dst.u_buffer = pc->yv12_fb[dst_fb_idx].u_buffer + recon_uvoffset;
366 xd->dst.v_buffer = pc->yv12_fb[dst_fb_idx].v_buffer + recon_uvoffset; 417 xd->dst.v_buffer = pc->yv12_fb[dst_fb_idx].v_buffer + recon_uvoffset;
367 418
368 xd->left_available = (mb_col != 0); 419 xd->left_available = (mb_col != 0);
369 420
370 /* Select the appropriate reference frame for this MB */ 421 /* Select the appropriate reference frame for this MB */
371 if (xd->mode_info_context->mbmi.ref_frame == LAST_FRAME) 422 if (xd->mode_info_context->mbmi.ref_frame == LAST_FRAME)
372 ref_fb_idx = pc->lst_fb_idx; 423 ref_fb_idx = pc->lst_fb_idx;
373 else if (xd->mode_info_context->mbmi.ref_frame == GOLDEN_FRAME) 424 else if (xd->mode_info_context->mbmi.ref_frame == GOLDEN_FRAME)
(...skipping 12 matching lines...) Expand all
386 } 437 }
387 438
388 vp8_build_uvmvs(xd, pc->full_pixel); 439 vp8_build_uvmvs(xd, pc->full_pixel);
389 440
390 /* 441 /*
391 if(pc->current_video_frame==0 &&mb_col==1 && mb_row==0) 442 if(pc->current_video_frame==0 &&mb_col==1 && mb_row==0)
392 pbi->debugoutput =1; 443 pbi->debugoutput =1;
393 else 444 else
394 pbi->debugoutput =0; 445 pbi->debugoutput =0;
395 */ 446 */
396 decode_macroblock(pbi, xd); 447 decode_macroblock(pbi, xd, mb_row * pc->mb_cols + mb_col);
397 448
398 /* check if the boolean decoder has suffered an error */ 449 /* check if the boolean decoder has suffered an error */
399 xd->corrupted |= vp8dx_bool_error(xd->current_bc); 450 xd->corrupted |= vp8dx_bool_error(xd->current_bc);
400 451
401 recon_yoffset += 16; 452 recon_yoffset += 16;
402 recon_uvoffset += 8; 453 recon_uvoffset += 8;
403 454
404 ++xd->mode_info_context; /* next mb */ 455 ++xd->mode_info_context; /* next mb */
405 456
406 xd->above_context++; 457 xd->above_context++;
(...skipping 10 matching lines...) Expand all
417 } 468 }
418 469
419 470
420 static unsigned int read_partition_size(const unsigned char *cx_size) 471 static unsigned int read_partition_size(const unsigned char *cx_size)
421 { 472 {
422 const unsigned int size = 473 const unsigned int size =
423 cx_size[0] + (cx_size[1] << 8) + (cx_size[2] << 16); 474 cx_size[0] + (cx_size[1] << 8) + (cx_size[2] << 16);
424 return size; 475 return size;
425 } 476 }
426 477
478 static void setup_token_decoder_partition_input(VP8D_COMP *pbi)
479 {
480 vp8_reader *bool_decoder = &pbi->bc2;
481 int part_idx = 1;
482
483 TOKEN_PARTITION multi_token_partition =
484 (TOKEN_PARTITION)vp8_read_literal(&pbi->bc, 2);
485 assert(vp8dx_bool_error(&pbi->bc) ||
486 multi_token_partition == pbi->common.multi_token_partition);
487 if (pbi->num_partitions > 2)
488 {
489 CHECK_MEM_ERROR(pbi->mbc, vpx_malloc((pbi->num_partitions - 1) *
490 sizeof(vp8_reader)));
491 bool_decoder = pbi->mbc;
492 }
493
494 for (; part_idx < pbi->num_partitions; ++part_idx)
495 {
496 if (vp8dx_start_decode(bool_decoder,
497 pbi->partitions[part_idx],
498 pbi->partition_sizes[part_idx]))
499 vpx_internal_error(&pbi->common.error, VPX_CODEC_MEM_ERROR,
500 "Failed to allocate bool decoder %d",
501 part_idx);
502
503 bool_decoder++;
504 }
505
506 #if CONFIG_MULTITHREAD
507 /* Clamp number of decoder threads */
508 if (pbi->decoding_thread_count > pbi->num_partitions - 1)
509 pbi->decoding_thread_count = pbi->num_partitions - 1;
510 #endif
511 }
512
513
514 static int read_is_valid(const unsigned char *start,
515 size_t len,
516 const unsigned char *end)
517 {
518 return (start + len > start && start + len <= end);
519 }
520
427 521
428 static void setup_token_decoder(VP8D_COMP *pbi, 522 static void setup_token_decoder(VP8D_COMP *pbi,
429 const unsigned char *cx_data) 523 const unsigned char *cx_data)
430 { 524 {
431 int num_part; 525 int num_part;
432 int i; 526 int i;
433 VP8_COMMON *pc = &pbi->common; 527 VP8_COMMON *pc = &pbi->common;
434 const unsigned char *user_data_end = pbi->Source + pbi->source_sz; 528 const unsigned char *user_data_end = pbi->Source + pbi->source_sz;
435 vp8_reader *bool_decoder; 529 vp8_reader *bool_decoder;
436 const unsigned char *partition; 530 const unsigned char *partition;
437 531
438 /* Parse number of token partitions to use */ 532 /* Parse number of token partitions to use */
439 pc->multi_token_partition = (TOKEN_PARTITION)vp8_read_literal(&pbi->bc, 2); 533 const TOKEN_PARTITION multi_token_partition =
534 (TOKEN_PARTITION)vp8_read_literal(&pbi->bc, 2);
535 /* Only update the multi_token_partition field if we are sure the value
536 * is correct. */
537 if (!pbi->ec_active || !vp8dx_bool_error(&pbi->bc))
538 pc->multi_token_partition = multi_token_partition;
539
440 num_part = 1 << pc->multi_token_partition; 540 num_part = 1 << pc->multi_token_partition;
441 541
442 /* Set up pointers to the first partition */ 542 /* Set up pointers to the first partition */
443 partition = cx_data; 543 partition = cx_data;
444 bool_decoder = &pbi->bc2; 544 bool_decoder = &pbi->bc2;
445 545
446 if (num_part > 1) 546 if (num_part > 1)
447 { 547 {
448 CHECK_MEM_ERROR(pbi->mbc, vpx_malloc(num_part * sizeof(vp8_reader))); 548 CHECK_MEM_ERROR(pbi->mbc, vpx_malloc(num_part * sizeof(vp8_reader)));
449 bool_decoder = pbi->mbc; 549 bool_decoder = pbi->mbc;
450 partition += 3 * (num_part - 1); 550 partition += 3 * (num_part - 1);
451 } 551 }
452 552
453 for (i = 0; i < num_part; i++) 553 for (i = 0; i < num_part; i++)
454 { 554 {
455 const unsigned char *partition_size_ptr = cx_data + i * 3; 555 const unsigned char *partition_size_ptr = cx_data + i * 3;
456 ptrdiff_t partition_size; 556 ptrdiff_t partition_size, bytes_left;
557
558 bytes_left = user_data_end - partition;
457 559
458 /* Calculate the length of this partition. The last partition 560 /* Calculate the length of this partition. The last partition
459 * size is implicit. 561 * size is implicit. If the partition size can't be read, then
562 * either use the remaining data in the buffer (for EC mode)
563 * or throw an error.
460 */ 564 */
461 if (i < num_part - 1) 565 if (i < num_part - 1)
462 { 566 {
463 partition_size = read_partition_size(partition_size_ptr); 567 if (read_is_valid(partition_size_ptr, 3, user_data_end))
568 partition_size = read_partition_size(partition_size_ptr);
569 else if (pbi->ec_active)
570 partition_size = bytes_left;
571 else
572 vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
573 "Truncated partition size data");
464 } 574 }
465 else 575 else
576 partition_size = bytes_left;
577
578 /* Validate the calculated partition length. If the buffer
579 * described by the partition can't be fully read, then restrict
580 * it to the portion that can be (for EC mode) or throw an error.
581 */
582 if (!read_is_valid(partition, partition_size, user_data_end))
466 { 583 {
467 partition_size = user_data_end - partition; 584 if (pbi->ec_active)
585 partition_size = bytes_left;
586 else
587 vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
588 "Truncated packet or corrupt partition "
589 "%d length", i + 1);
468 } 590 }
469 591
470 if (partition + partition_size > user_data_end
471 || partition + partition_size < partition)
472 vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
473 "Truncated packet or corrupt partition "
474 "%d length", i + 1);
475
476 if (vp8dx_start_decode(bool_decoder, partition, partition_size)) 592 if (vp8dx_start_decode(bool_decoder, partition, partition_size))
477 vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR, 593 vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
478 "Failed to allocate bool decoder %d", i + 1); 594 "Failed to allocate bool decoder %d", i + 1);
479 595
480 /* Advance to the next partition */ 596 /* Advance to the next partition */
481 partition += partition_size; 597 partition += partition_size;
482 bool_decoder++; 598 bool_decoder++;
483 } 599 }
484 600
485 #if CONFIG_MULTITHREAD 601 #if CONFIG_MULTITHREAD
486 /* Clamp number of decoder threads */ 602 /* Clamp number of decoder threads */
487 if (pbi->decoding_thread_count > num_part - 1) 603 if (pbi->decoding_thread_count > num_part - 1)
488 pbi->decoding_thread_count = num_part - 1; 604 pbi->decoding_thread_count = num_part - 1;
489 #endif 605 #endif
490 } 606 }
491 607
492 608
493 static void stop_token_decoder(VP8D_COMP *pbi) 609 static void stop_token_decoder(VP8D_COMP *pbi)
494 { 610 {
495 VP8_COMMON *pc = &pbi->common; 611 VP8_COMMON *pc = &pbi->common;
496 612
497 if (pc->multi_token_partition != ONE_PARTITION) 613 if (pc->multi_token_partition != ONE_PARTITION)
614 {
498 vpx_free(pbi->mbc); 615 vpx_free(pbi->mbc);
616 pbi->mbc = NULL;
617 }
499 } 618 }
500 619
501 static void init_frame(VP8D_COMP *pbi) 620 static void init_frame(VP8D_COMP *pbi)
502 { 621 {
503 VP8_COMMON *const pc = & pbi->common; 622 VP8_COMMON *const pc = & pbi->common;
504 MACROBLOCKD *const xd = & pbi->mb; 623 MACROBLOCKD *const xd = & pbi->mb;
505 624
506 if (pc->frame_type == KEY_FRAME) 625 if (pc->frame_type == KEY_FRAME)
507 { 626 {
508 /* Various keyframe initializations */ 627 /* Various keyframe initializations */
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 xd->subpixel_predict8x8 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), sixta p8x8); 667 xd->subpixel_predict8x8 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), sixta p8x8);
549 xd->subpixel_predict16x16 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), sixta p16x16); 668 xd->subpixel_predict16x16 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), sixta p16x16);
550 } 669 }
551 else 670 else
552 { 671 {
553 xd->subpixel_predict = SUBPIX_INVOKE(RTCD_VTABLE(subpix), bilin ear4x4); 672 xd->subpixel_predict = SUBPIX_INVOKE(RTCD_VTABLE(subpix), bilin ear4x4);
554 xd->subpixel_predict8x4 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), bilin ear8x4); 673 xd->subpixel_predict8x4 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), bilin ear8x4);
555 xd->subpixel_predict8x8 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), bilin ear8x8); 674 xd->subpixel_predict8x8 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), bilin ear8x8);
556 xd->subpixel_predict16x16 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), bilin ear16x16); 675 xd->subpixel_predict16x16 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), bilin ear16x16);
557 } 676 }
677
678 if (pbi->decoded_key_frame && pbi->ec_enabled && !pbi->ec_active)
679 pbi->ec_active = 1;
558 } 680 }
559 681
560 xd->left_context = &pc->left_context; 682 xd->left_context = &pc->left_context;
561 xd->mode_info_context = pc->mi; 683 xd->mode_info_context = pc->mi;
562 xd->frame_type = pc->frame_type; 684 xd->frame_type = pc->frame_type;
563 xd->mode_info_context->mbmi.mode = DC_PRED; 685 xd->mode_info_context->mbmi.mode = DC_PRED;
564 xd->mode_info_stride = pc->mode_info_stride; 686 xd->mode_info_stride = pc->mode_info_stride;
565 xd->corrupted = 0; /* init without corruption */ 687 xd->corrupted = 0; /* init without corruption */
566 } 688 }
567 689
568 int vp8_decode_frame(VP8D_COMP *pbi) 690 int vp8_decode_frame(VP8D_COMP *pbi)
569 { 691 {
570 vp8_reader *const bc = & pbi->bc; 692 vp8_reader *const bc = & pbi->bc;
571 VP8_COMMON *const pc = & pbi->common; 693 VP8_COMMON *const pc = & pbi->common;
572 MACROBLOCKD *const xd = & pbi->mb; 694 MACROBLOCKD *const xd = & pbi->mb;
573 const unsigned char *data = (const unsigned char *)pbi->Source; 695 const unsigned char *data = (const unsigned char *)pbi->Source;
574 const unsigned char *const data_end = data + pbi->source_sz; 696 const unsigned char *data_end = data + pbi->source_sz;
575 ptrdiff_t first_partition_length_in_bytes; 697 ptrdiff_t first_partition_length_in_bytes;
576 698
577 int mb_row; 699 int mb_row;
578 int i, j, k, l; 700 int i, j, k, l;
579 const int *const mb_feature_data_bits = vp8_mb_feature_data_bits; 701 const int *const mb_feature_data_bits = vp8_mb_feature_data_bits;
702 int corrupt_tokens = 0;
703 int prev_independent_partitions = pbi->independent_partitions;
704
705 if (pbi->input_partition)
706 {
707 data = pbi->partitions[0];
708 data_end = data + pbi->partition_sizes[0];
709 }
580 710
581 /* start with no corruption of current frame */ 711 /* start with no corruption of current frame */
582 xd->corrupted = 0; 712 xd->corrupted = 0;
583 pc->yv12_fb[pc->new_fb_idx].corrupted = 0; 713 pc->yv12_fb[pc->new_fb_idx].corrupted = 0;
584 714
585 if (data_end - data < 3) 715 if (data_end - data < 3)
586 vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, 716 {
587 "Truncated packet"); 717 if (pbi->ec_active)
588 pc->frame_type = (FRAME_TYPE)(data[0] & 1); 718 {
589 pc->version = (data[0] >> 1) & 7; 719 /* Declare the missing frame as an inter frame since it will
590 pc->show_frame = (data[0] >> 4) & 1; 720 be handled as an inter frame when we have estimated its
591 first_partition_length_in_bytes = 721 motion vectors. */
592 (data[0] | (data[1] << 8) | (data[2] << 16)) >> 5; 722 pc->frame_type = INTER_FRAME;
593 data += 3; 723 pc->version = 0;
724 pc->show_frame = 1;
725 first_partition_length_in_bytes = 0;
726 }
727 else
728 {
729 vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
730 "Truncated packet");
731 }
732 }
733 else
734 {
735 pc->frame_type = (FRAME_TYPE)(data[0] & 1);
736 pc->version = (data[0] >> 1) & 7;
737 pc->show_frame = (data[0] >> 4) & 1;
738 first_partition_length_in_bytes =
739 (data[0] | (data[1] << 8) | (data[2] << 16)) >> 5;
740 data += 3;
594 741
595 if (data + first_partition_length_in_bytes > data_end 742 if (!pbi->ec_active && (data + first_partition_length_in_bytes > data_en d
596 || data + first_partition_length_in_bytes < data) 743 || data + first_partition_length_in_bytes < data))
597 vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, 744 vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
598 "Truncated packet or corrupt partition 0 length"); 745 "Truncated packet or corrupt partition 0 length") ;
599 vp8_setup_version(pc); 746 vp8_setup_version(pc);
600 747
601 if (pc->frame_type == KEY_FRAME) 748 if (pc->frame_type == KEY_FRAME)
602 { 749 {
603 const int Width = pc->Width; 750 const int Width = pc->Width;
604 const int Height = pc->Height; 751 const int Height = pc->Height;
605 752
606 /* vet via sync code */ 753 /* vet via sync code */
607 if (data[0] != 0x9d || data[1] != 0x01 || data[2] != 0x2a) 754 /* When error concealment is enabled we should only check the sync
608 vpx_internal_error(&pc->error, VPX_CODEC_UNSUP_BITSTREAM, 755 * code if we have enough bits available
609 "Invalid frame sync code"); 756 */
610 757 if (!pbi->ec_active || data + 3 < data_end)
611 pc->Width = (data[3] | (data[4] << 8)) & 0x3fff;
612 pc->horiz_scale = data[4] >> 6;
613 pc->Height = (data[5] | (data[6] << 8)) & 0x3fff;
614 pc->vert_scale = data[6] >> 6;
615 data += 7;
616
617 if (Width != pc->Width || Height != pc->Height)
618 {
619 int prev_mb_rows = pc->mb_rows;
620
621 if (pc->Width <= 0)
622 { 758 {
623 pc->Width = Width; 759 if (data[0] != 0x9d || data[1] != 0x01 || data[2] != 0x2a)
624 vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, 760 vpx_internal_error(&pc->error, VPX_CODEC_UNSUP_BITSTREAM,
625 "Invalid frame width"); 761 "Invalid frame sync code");
626 } 762 }
627 763
628 if (pc->Height <= 0) 764 /* If error concealment is enabled we should only parse the new size
765 * if we have enough data. Otherwise we will end up with the wrong
766 * size.
767 */
768 if (!pbi->ec_active || data + 6 < data_end)
629 { 769 {
630 pc->Height = Height; 770 pc->Width = (data[3] | (data[4] << 8)) & 0x3fff;
631 vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, 771 pc->horiz_scale = data[4] >> 6;
632 "Invalid frame height"); 772 pc->Height = (data[5] | (data[6] << 8)) & 0x3fff;
773 pc->vert_scale = data[6] >> 6;
633 } 774 }
775 data += 7;
634 776
635 if (vp8_alloc_frame_buffers(pc, pc->Width, pc->Height)) 777 if (Width != pc->Width || Height != pc->Height)
636 vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR, 778 {
637 "Failed to allocate frame buffers"); 779 int prev_mb_rows = pc->mb_rows;
780
781 if (pc->Width <= 0)
782 {
783 pc->Width = Width;
784 vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
785 "Invalid frame width");
786 }
787
788 if (pc->Height <= 0)
789 {
790 pc->Height = Height;
791 vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
792 "Invalid frame height");
793 }
794
795 if (vp8_alloc_frame_buffers(pc, pc->Width, pc->Height))
796 vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
797 "Failed to allocate frame buffers");
798
799 #if CONFIG_ERROR_CONCEALMENT
800 pbi->overlaps = NULL;
801 if (pbi->ec_enabled)
802 {
803 if (vp8_alloc_overlap_lists(pbi))
804 vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
805 "Failed to allocate overlap lists "
806 "for error concealment");
807 }
808 #endif
638 809
639 #if CONFIG_MULTITHREAD 810 #if CONFIG_MULTITHREAD
640 if (pbi->b_multithreaded_rd) 811 if (pbi->b_multithreaded_rd)
641 vp8mt_alloc_temp_buffers(pbi, pc->Width, prev_mb_rows); 812 vp8mt_alloc_temp_buffers(pbi, pc->Width, prev_mb_rows);
642 #endif 813 #endif
814 }
643 } 815 }
644 } 816 }
645 817
646 if (pc->Width == 0 || pc->Height == 0) 818 if (pc->Width == 0 || pc->Height == 0)
647 { 819 {
648 return -1; 820 return -1;
649 } 821 }
650 822
651 init_frame(pbi); 823 init_frame(pbi);
652 824
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 /*sign = vp8_read_bit( bc );*/ 916 /*sign = vp8_read_bit( bc );*/
745 xd->mode_lf_deltas[i] = (signed char)vp8_read_literal(bc, 6) ; 917 xd->mode_lf_deltas[i] = (signed char)vp8_read_literal(bc, 6) ;
746 918
747 if (vp8_read_bit(bc)) /* Apply sign */ 919 if (vp8_read_bit(bc)) /* Apply sign */
748 xd->mode_lf_deltas[i] = xd->mode_lf_deltas[i] * -1; 920 xd->mode_lf_deltas[i] = xd->mode_lf_deltas[i] * -1;
749 } 921 }
750 } 922 }
751 } 923 }
752 } 924 }
753 925
754 setup_token_decoder(pbi, data + first_partition_length_in_bytes); 926 if (pbi->input_partition)
927 {
928 setup_token_decoder_partition_input(pbi);
929 }
930 else
931 {
932 setup_token_decoder(pbi, data + first_partition_length_in_bytes);
933 }
755 xd->current_bc = &pbi->bc2; 934 xd->current_bc = &pbi->bc2;
756 935
757 /* Read the default quantizers. */ 936 /* Read the default quantizers. */
758 { 937 {
759 int Q, q_update; 938 int Q, q_update;
760 939
761 Q = vp8_read_literal(bc, 7); /* AC 1st order Q = default */ 940 Q = vp8_read_literal(bc, 7); /* AC 1st order Q = default */
762 pc->base_qindex = Q; 941 pc->base_qindex = Q;
763 q_update = 0; 942 q_update = 0;
764 pc->y1dc_delta_q = get_delta_q(bc, pc->y1dc_delta_q, &q_update); 943 pc->y1dc_delta_q = get_delta_q(bc, pc->y1dc_delta_q, &q_update);
(...skipping 10 matching lines...) Expand all
775 } 954 }
776 955
777 /* Determine if the golden frame or ARF buffer should be updated and how. 956 /* Determine if the golden frame or ARF buffer should be updated and how.
778 * For all non key frames the GF and ARF refresh flags and sign bias 957 * For all non key frames the GF and ARF refresh flags and sign bias
779 * flags must be set explicitly. 958 * flags must be set explicitly.
780 */ 959 */
781 if (pc->frame_type != KEY_FRAME) 960 if (pc->frame_type != KEY_FRAME)
782 { 961 {
783 /* Should the GF or ARF be updated from the current frame */ 962 /* Should the GF or ARF be updated from the current frame */
784 pc->refresh_golden_frame = vp8_read_bit(bc); 963 pc->refresh_golden_frame = vp8_read_bit(bc);
964 #if CONFIG_ERROR_CONCEALMENT
965 /* Assume we shouldn't refresh golden if the bit is missing */
966 xd->corrupted |= vp8dx_bool_error(bc);
967 if (pbi->ec_active && xd->corrupted)
968 pc->refresh_golden_frame = 0;
969 #endif
970
785 pc->refresh_alt_ref_frame = vp8_read_bit(bc); 971 pc->refresh_alt_ref_frame = vp8_read_bit(bc);
972 #if CONFIG_ERROR_CONCEALMENT
973 /* Assume we shouldn't refresh altref if the bit is missing */
974 xd->corrupted |= vp8dx_bool_error(bc);
975 if (pbi->ec_active && xd->corrupted)
976 pc->refresh_alt_ref_frame = 0;
977 #endif
786 978
787 /* Buffer to buffer copy flags. */ 979 /* Buffer to buffer copy flags. */
788 pc->copy_buffer_to_gf = 0; 980 pc->copy_buffer_to_gf = 0;
789 981
790 if (!pc->refresh_golden_frame) 982 if (!pc->refresh_golden_frame)
791 pc->copy_buffer_to_gf = vp8_read_literal(bc, 2); 983 pc->copy_buffer_to_gf = vp8_read_literal(bc, 2);
792 984
793 pc->copy_buffer_to_arf = 0; 985 pc->copy_buffer_to_arf = 0;
794 986
795 if (!pc->refresh_alt_ref_frame) 987 if (!pc->refresh_alt_ref_frame)
796 pc->copy_buffer_to_arf = vp8_read_literal(bc, 2); 988 pc->copy_buffer_to_arf = vp8_read_literal(bc, 2);
797 989
798 pc->ref_frame_sign_bias[GOLDEN_FRAME] = vp8_read_bit(bc); 990 pc->ref_frame_sign_bias[GOLDEN_FRAME] = vp8_read_bit(bc);
799 pc->ref_frame_sign_bias[ALTREF_FRAME] = vp8_read_bit(bc); 991 pc->ref_frame_sign_bias[ALTREF_FRAME] = vp8_read_bit(bc);
800 } 992 }
801 993
802 pc->refresh_entropy_probs = vp8_read_bit(bc); 994 pc->refresh_entropy_probs = vp8_read_bit(bc);
803 if (pc->refresh_entropy_probs == 0) 995 if (pc->refresh_entropy_probs == 0)
804 { 996 {
805 vpx_memcpy(&pc->lfc, &pc->fc, sizeof(pc->fc)); 997 vpx_memcpy(&pc->lfc, &pc->fc, sizeof(pc->fc));
806 } 998 }
807 999
808 pc->refresh_last_frame = pc->frame_type == KEY_FRAME || vp8_read_bit(bc); 1000 pc->refresh_last_frame = pc->frame_type == KEY_FRAME || vp8_read_bit(bc);
809 1001
1002 #if CONFIG_ERROR_CONCEALMENT
1003 /* Assume we should refresh the last frame if the bit is missing */
1004 xd->corrupted |= vp8dx_bool_error(bc);
1005 if (pbi->ec_active && xd->corrupted)
1006 pc->refresh_last_frame = 1;
1007 #endif
1008
810 if (0) 1009 if (0)
811 { 1010 {
812 FILE *z = fopen("decodestats.stt", "a"); 1011 FILE *z = fopen("decodestats.stt", "a");
813 fprintf(z, "%6d F:%d,G:%d,A:%d,L:%d,Q:%d\n", 1012 fprintf(z, "%6d F:%d,G:%d,A:%d,L:%d,Q:%d\n",
814 pc->current_video_frame, 1013 pc->current_video_frame,
815 pc->frame_type, 1014 pc->frame_type,
816 pc->refresh_golden_frame, 1015 pc->refresh_golden_frame,
817 pc->refresh_alt_ref_frame, 1016 pc->refresh_alt_ref_frame,
818 pc->refresh_last_frame, 1017 pc->refresh_last_frame,
819 pc->base_qindex); 1018 pc->base_qindex);
820 fclose(z); 1019 fclose(z);
821 } 1020 }
822 1021
1022 {
1023 pbi->independent_partitions = 1;
823 1024
824 {
825 /* read coef probability tree */ 1025 /* read coef probability tree */
826
827 for (i = 0; i < BLOCK_TYPES; i++) 1026 for (i = 0; i < BLOCK_TYPES; i++)
828 for (j = 0; j < COEF_BANDS; j++) 1027 for (j = 0; j < COEF_BANDS; j++)
829 for (k = 0; k < PREV_COEF_CONTEXTS; k++) 1028 for (k = 0; k < PREV_COEF_CONTEXTS; k++)
830 for (l = 0; l < MAX_ENTROPY_TOKENS - 1; l++) 1029 for (l = 0; l < ENTROPY_NODES; l++)
831 { 1030 {
832 1031
833 vp8_prob *const p = pc->fc.coef_probs [i][j][k] + l; 1032 vp8_prob *const p = pc->fc.coef_probs [i][j][k] + l;
834 1033
835 if (vp8_read(bc, vp8_coef_update_probs [i][j][k][l])) 1034 if (vp8_read(bc, vp8_coef_update_probs [i][j][k][l]))
836 { 1035 {
837 *p = (vp8_prob)vp8_read_literal(bc, 8); 1036 *p = (vp8_prob)vp8_read_literal(bc, 8);
838 1037
839 } 1038 }
1039 if (k > 0 && *p != pc->fc.coef_probs[i][j][k-1][l])
1040 pbi->independent_partitions = 0;
1041
840 } 1042 }
841 } 1043 }
842 1044
843 vpx_memcpy(&xd->pre, &pc->yv12_fb[pc->lst_fb_idx], sizeof(YV12_BUFFER_CONFIG )); 1045 vpx_memcpy(&xd->pre, &pc->yv12_fb[pc->lst_fb_idx], sizeof(YV12_BUFFER_CONFIG ));
844 vpx_memcpy(&xd->dst, &pc->yv12_fb[pc->new_fb_idx], sizeof(YV12_BUFFER_CONFIG )); 1046 vpx_memcpy(&xd->dst, &pc->yv12_fb[pc->new_fb_idx], sizeof(YV12_BUFFER_CONFIG ));
845 1047
846 /* set up frame new frame for intra coded blocks */ 1048 /* set up frame new frame for intra coded blocks */
847 #if CONFIG_MULTITHREAD 1049 #if CONFIG_MULTITHREAD
848 if (!(pbi->b_multithreaded_rd) || pc->multi_token_partition == ONE_PARTITION || !(pc->filter_level)) 1050 if (!(pbi->b_multithreaded_rd) || pc->multi_token_partition == ONE_PARTITION || !(pc->filter_level))
849 #endif 1051 #endif
850 vp8_setup_intra_recon(&pc->yv12_fb[pc->new_fb_idx]); 1052 vp8_setup_intra_recon(&pc->yv12_fb[pc->new_fb_idx]);
851 1053
852 vp8_setup_block_dptrs(xd); 1054 vp8_setup_block_dptrs(xd);
853 1055
854 vp8_build_block_doffsets(xd); 1056 vp8_build_block_doffsets(xd);
855 1057
856 /* clear out the coeff buffer */ 1058 /* clear out the coeff buffer */
857 vpx_memset(xd->qcoeff, 0, sizeof(xd->qcoeff)); 1059 vpx_memset(xd->qcoeff, 0, sizeof(xd->qcoeff));
858 1060
859 /* Read the mb_no_coeff_skip flag */ 1061 /* Read the mb_no_coeff_skip flag */
860 pc->mb_no_coeff_skip = (int)vp8_read_bit(bc); 1062 pc->mb_no_coeff_skip = (int)vp8_read_bit(bc);
861 1063
862 1064
863 vp8_decode_mode_mvs(pbi); 1065 vp8_decode_mode_mvs(pbi);
864 1066
1067 #if CONFIG_ERROR_CONCEALMENT
1068 if (pbi->ec_active &&
1069 pbi->mvs_corrupt_from_mb < (unsigned int)pc->mb_cols * pc->mb_rows)
1070 {
1071 /* Motion vectors are missing in this frame. We will try to estimate
1072 * them and then continue decoding the frame as usual */
1073 vp8_estimate_missing_mvs(pbi);
1074 }
1075 #endif
1076
865 vpx_memset(pc->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES) * pc->mb_col s); 1077 vpx_memset(pc->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES) * pc->mb_col s);
866 1078
867 vpx_memcpy(&xd->block[0].bmi, &xd->mode_info_context->bmi[0], sizeof(B_MODE_ INFO));
868
869 #if CONFIG_MULTITHREAD 1079 #if CONFIG_MULTITHREAD
870 if (pbi->b_multithreaded_rd && pc->multi_token_partition != ONE_PARTITION) 1080 if (pbi->b_multithreaded_rd && pc->multi_token_partition != ONE_PARTITION)
871 { 1081 {
1082 int i;
1083 pbi->frame_corrupt_residual = 0;
872 vp8mt_decode_mb_rows(pbi, xd); 1084 vp8mt_decode_mb_rows(pbi, xd);
873 if(pbi->common.filter_level)
874 {
875 /*vp8_mt_loop_filter_frame(pbi);*/ /*cm, &pbi->mb, cm->filter_level) ;*/
876
877 pc->last_frame_type = pc->frame_type;
878 pc->last_filter_type = pc->filter_type;
879 pc->last_sharpness_level = pc->sharpness_level;
880 }
881 vp8_yv12_extend_frame_borders_ptr(&pc->yv12_fb[pc->new_fb_idx]); /*cm ->frame_to_show);*/ 1085 vp8_yv12_extend_frame_borders_ptr(&pc->yv12_fb[pc->new_fb_idx]); /*cm ->frame_to_show);*/
1086 for (i = 0; i < pbi->decoding_thread_count; ++i)
1087 corrupt_tokens |= pbi->mb_row_di[i].mbd.corrupted;
882 } 1088 }
883 else 1089 else
884 #endif 1090 #endif
885 { 1091 {
886 int ibc = 0; 1092 int ibc = 0;
887 int num_part = 1 << pc->multi_token_partition; 1093 int num_part = 1 << pc->multi_token_partition;
1094 pbi->frame_corrupt_residual = 0;
888 1095
889 /* Decode the individual macro block */ 1096 /* Decode the individual macro block */
890 for (mb_row = 0; mb_row < pc->mb_rows; mb_row++) 1097 for (mb_row = 0; mb_row < pc->mb_rows; mb_row++)
891 { 1098 {
892 1099
893 if (num_part > 1) 1100 if (num_part > 1)
894 { 1101 {
895 xd->current_bc = & pbi->mbc[ibc]; 1102 xd->current_bc = & pbi->mbc[ibc];
896 ibc++; 1103 ibc++;
897 1104
898 if (ibc == num_part) 1105 if (ibc == num_part)
899 ibc = 0; 1106 ibc = 0;
900 } 1107 }
901 1108
902 decode_mb_row(pbi, pc, mb_row, xd); 1109 decode_mb_row(pbi, pc, mb_row, xd);
903 } 1110 }
1111 corrupt_tokens |= xd->corrupted;
904 } 1112 }
905 1113
906
907 stop_token_decoder(pbi); 1114 stop_token_decoder(pbi);
908 1115
909 /* Collect information about decoder corruption. */ 1116 /* Collect information about decoder corruption. */
910 /* 1. Check first boolean decoder for errors. */ 1117 /* 1. Check first boolean decoder for errors. */
911 pc->yv12_fb[pc->new_fb_idx].corrupted = 1118 pc->yv12_fb[pc->new_fb_idx].corrupted = vp8dx_bool_error(bc);
912 vp8dx_bool_error(bc);
913 /* 2. Check the macroblock information */ 1119 /* 2. Check the macroblock information */
914 pc->yv12_fb[pc->new_fb_idx].corrupted |= 1120 pc->yv12_fb[pc->new_fb_idx].corrupted |= corrupt_tokens;
915 xd->corrupted; 1121
1122 if (!pbi->decoded_key_frame)
1123 {
1124 if (pc->frame_type == KEY_FRAME &&
1125 !pc->yv12_fb[pc->new_fb_idx].corrupted)
1126 pbi->decoded_key_frame = 1;
1127 else
1128 vpx_internal_error(&pbi->common.error, VPX_CODEC_CORRUPT_FRAME,
1129 "A stream must start with a complete key frame");
1130 }
916 1131
917 /* vpx_log("Decoder: Frame Decoded, Size Roughly:%d bytes \n",bc->pos+pbi-> bc2.pos); */ 1132 /* vpx_log("Decoder: Frame Decoded, Size Roughly:%d bytes \n",bc->pos+pbi-> bc2.pos); */
918 1133
919 /* If this was a kf or Gf note the Q used */ 1134 /* If this was a kf or Gf note the Q used */
920 if ((pc->frame_type == KEY_FRAME) || 1135 if ((pc->frame_type == KEY_FRAME) ||
921 pc->refresh_golden_frame || pc->refresh_alt_ref_frame) 1136 pc->refresh_golden_frame || pc->refresh_alt_ref_frame)
922 { 1137 {
923 pc->last_kf_gf_q = pc->base_qindex; 1138 pc->last_kf_gf_q = pc->base_qindex;
924 } 1139 }
925 1140
926 if (pc->refresh_entropy_probs == 0) 1141 if (pc->refresh_entropy_probs == 0)
927 { 1142 {
928 vpx_memcpy(&pc->fc, &pc->lfc, sizeof(pc->fc)); 1143 vpx_memcpy(&pc->fc, &pc->lfc, sizeof(pc->fc));
1144 pbi->independent_partitions = prev_independent_partitions;
929 } 1145 }
930 1146
931 #ifdef PACKET_TESTING 1147 #ifdef PACKET_TESTING
932 { 1148 {
933 FILE *f = fopen("decompressor.VP8", "ab"); 1149 FILE *f = fopen("decompressor.VP8", "ab");
934 unsigned int size = pbi->bc2.pos + pbi->bc.pos + 8; 1150 unsigned int size = pbi->bc2.pos + pbi->bc.pos + 8;
935 fwrite((void *) &size, 4, 1, f); 1151 fwrite((void *) &size, 4, 1, f);
936 fwrite((void *) pbi->Source, size, 1, f); 1152 fwrite((void *) pbi->Source, size, 1, f);
937 fclose(f); 1153 fclose(f);
938 } 1154 }
939 #endif 1155 #endif
940 1156
941 return 0; 1157 return 0;
942 } 1158 }
OLDNEW
« no previous file with comments | « source/libvpx/vp8/decoder/decodemv.c ('k') | source/libvpx/vp8/decoder/detokenize.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698