Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license |
michael@0 | 5 | * that can be found in the LICENSE file in the root of the source |
michael@0 | 6 | * tree. An additional intellectual property rights grant can be found |
michael@0 | 7 | * in the file PATENTS. All contributing project authors may |
michael@0 | 8 | * be found in the AUTHORS file in the root of the source tree. |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | |
michael@0 | 12 | #include "vpx_config.h" |
michael@0 | 13 | #include "vp8_rtcd.h" |
michael@0 | 14 | #include "./vpx_scale_rtcd.h" |
michael@0 | 15 | #include "onyxd_int.h" |
michael@0 | 16 | #include "vp8/common/header.h" |
michael@0 | 17 | #include "vp8/common/reconintra4x4.h" |
michael@0 | 18 | #include "vp8/common/reconinter.h" |
michael@0 | 19 | #include "detokenize.h" |
michael@0 | 20 | #include "vp8/common/invtrans.h" |
michael@0 | 21 | #include "vp8/common/alloccommon.h" |
michael@0 | 22 | #include "vp8/common/entropymode.h" |
michael@0 | 23 | #include "vp8/common/quant_common.h" |
michael@0 | 24 | #include "vpx_scale/vpx_scale.h" |
michael@0 | 25 | #include "vp8/common/setupintrarecon.h" |
michael@0 | 26 | |
michael@0 | 27 | #include "decodemv.h" |
michael@0 | 28 | #include "vp8/common/extend.h" |
michael@0 | 29 | #if CONFIG_ERROR_CONCEALMENT |
michael@0 | 30 | #include "error_concealment.h" |
michael@0 | 31 | #endif |
michael@0 | 32 | #include "vpx_mem/vpx_mem.h" |
michael@0 | 33 | #include "vp8/common/threading.h" |
michael@0 | 34 | #include "decoderthreading.h" |
michael@0 | 35 | #include "dboolhuff.h" |
michael@0 | 36 | |
michael@0 | 37 | #include <assert.h> |
michael@0 | 38 | #include <stdio.h> |
michael@0 | 39 | |
michael@0 | 40 | void vp8cx_init_de_quantizer(VP8D_COMP *pbi) |
michael@0 | 41 | { |
michael@0 | 42 | int Q; |
michael@0 | 43 | VP8_COMMON *const pc = & pbi->common; |
michael@0 | 44 | |
michael@0 | 45 | for (Q = 0; Q < QINDEX_RANGE; Q++) |
michael@0 | 46 | { |
michael@0 | 47 | pc->Y1dequant[Q][0] = (short)vp8_dc_quant(Q, pc->y1dc_delta_q); |
michael@0 | 48 | pc->Y2dequant[Q][0] = (short)vp8_dc2quant(Q, pc->y2dc_delta_q); |
michael@0 | 49 | pc->UVdequant[Q][0] = (short)vp8_dc_uv_quant(Q, pc->uvdc_delta_q); |
michael@0 | 50 | |
michael@0 | 51 | pc->Y1dequant[Q][1] = (short)vp8_ac_yquant(Q); |
michael@0 | 52 | pc->Y2dequant[Q][1] = (short)vp8_ac2quant(Q, pc->y2ac_delta_q); |
michael@0 | 53 | pc->UVdequant[Q][1] = (short)vp8_ac_uv_quant(Q, pc->uvac_delta_q); |
michael@0 | 54 | } |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | void vp8_mb_init_dequantizer(VP8D_COMP *pbi, MACROBLOCKD *xd) |
michael@0 | 58 | { |
michael@0 | 59 | int i; |
michael@0 | 60 | int QIndex; |
michael@0 | 61 | MB_MODE_INFO *mbmi = &xd->mode_info_context->mbmi; |
michael@0 | 62 | VP8_COMMON *const pc = & pbi->common; |
michael@0 | 63 | |
michael@0 | 64 | /* Decide whether to use the default or alternate baseline Q value. */ |
michael@0 | 65 | if (xd->segmentation_enabled) |
michael@0 | 66 | { |
michael@0 | 67 | /* Abs Value */ |
michael@0 | 68 | if (xd->mb_segement_abs_delta == SEGMENT_ABSDATA) |
michael@0 | 69 | QIndex = xd->segment_feature_data[MB_LVL_ALT_Q][mbmi->segment_id]; |
michael@0 | 70 | |
michael@0 | 71 | /* Delta Value */ |
michael@0 | 72 | else |
michael@0 | 73 | { |
michael@0 | 74 | QIndex = pc->base_qindex + xd->segment_feature_data[MB_LVL_ALT_Q][mbmi->segment_id]; |
michael@0 | 75 | QIndex = (QIndex >= 0) ? ((QIndex <= MAXQ) ? QIndex : MAXQ) : 0; /* Clamp to valid range */ |
michael@0 | 76 | } |
michael@0 | 77 | } |
michael@0 | 78 | else |
michael@0 | 79 | QIndex = pc->base_qindex; |
michael@0 | 80 | |
michael@0 | 81 | /* Set up the macroblock dequant constants */ |
michael@0 | 82 | xd->dequant_y1_dc[0] = 1; |
michael@0 | 83 | xd->dequant_y1[0] = pc->Y1dequant[QIndex][0]; |
michael@0 | 84 | xd->dequant_y2[0] = pc->Y2dequant[QIndex][0]; |
michael@0 | 85 | xd->dequant_uv[0] = pc->UVdequant[QIndex][0]; |
michael@0 | 86 | |
michael@0 | 87 | for (i = 1; i < 16; i++) |
michael@0 | 88 | { |
michael@0 | 89 | xd->dequant_y1_dc[i] = |
michael@0 | 90 | xd->dequant_y1[i] = pc->Y1dequant[QIndex][1]; |
michael@0 | 91 | xd->dequant_y2[i] = pc->Y2dequant[QIndex][1]; |
michael@0 | 92 | xd->dequant_uv[i] = pc->UVdequant[QIndex][1]; |
michael@0 | 93 | } |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | static void decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd, |
michael@0 | 97 | unsigned int mb_idx) |
michael@0 | 98 | { |
michael@0 | 99 | MB_PREDICTION_MODE mode; |
michael@0 | 100 | int i; |
michael@0 | 101 | #if CONFIG_ERROR_CONCEALMENT |
michael@0 | 102 | int corruption_detected = 0; |
michael@0 | 103 | #endif |
michael@0 | 104 | |
michael@0 | 105 | if (xd->mode_info_context->mbmi.mb_skip_coeff) |
michael@0 | 106 | { |
michael@0 | 107 | vp8_reset_mb_tokens_context(xd); |
michael@0 | 108 | } |
michael@0 | 109 | else if (!vp8dx_bool_error(xd->current_bc)) |
michael@0 | 110 | { |
michael@0 | 111 | int eobtotal; |
michael@0 | 112 | eobtotal = vp8_decode_mb_tokens(pbi, xd); |
michael@0 | 113 | |
michael@0 | 114 | /* Special case: Force the loopfilter to skip when eobtotal is zero */ |
michael@0 | 115 | xd->mode_info_context->mbmi.mb_skip_coeff = (eobtotal==0); |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | mode = xd->mode_info_context->mbmi.mode; |
michael@0 | 119 | |
michael@0 | 120 | if (xd->segmentation_enabled) |
michael@0 | 121 | vp8_mb_init_dequantizer(pbi, xd); |
michael@0 | 122 | |
michael@0 | 123 | |
michael@0 | 124 | #if CONFIG_ERROR_CONCEALMENT |
michael@0 | 125 | |
michael@0 | 126 | if(pbi->ec_active) |
michael@0 | 127 | { |
michael@0 | 128 | int throw_residual; |
michael@0 | 129 | /* When we have independent partitions we can apply residual even |
michael@0 | 130 | * though other partitions within the frame are corrupt. |
michael@0 | 131 | */ |
michael@0 | 132 | throw_residual = (!pbi->independent_partitions && |
michael@0 | 133 | pbi->frame_corrupt_residual); |
michael@0 | 134 | throw_residual = (throw_residual || vp8dx_bool_error(xd->current_bc)); |
michael@0 | 135 | |
michael@0 | 136 | if ((mb_idx >= pbi->mvs_corrupt_from_mb || throw_residual)) |
michael@0 | 137 | { |
michael@0 | 138 | /* MB with corrupt residuals or corrupt mode/motion vectors. |
michael@0 | 139 | * Better to use the predictor as reconstruction. |
michael@0 | 140 | */ |
michael@0 | 141 | pbi->frame_corrupt_residual = 1; |
michael@0 | 142 | vpx_memset(xd->qcoeff, 0, sizeof(xd->qcoeff)); |
michael@0 | 143 | vp8_conceal_corrupt_mb(xd); |
michael@0 | 144 | |
michael@0 | 145 | |
michael@0 | 146 | corruption_detected = 1; |
michael@0 | 147 | |
michael@0 | 148 | /* force idct to be skipped for B_PRED and use the |
michael@0 | 149 | * prediction only for reconstruction |
michael@0 | 150 | * */ |
michael@0 | 151 | vpx_memset(xd->eobs, 0, 25); |
michael@0 | 152 | } |
michael@0 | 153 | } |
michael@0 | 154 | #endif |
michael@0 | 155 | |
michael@0 | 156 | /* do prediction */ |
michael@0 | 157 | if (xd->mode_info_context->mbmi.ref_frame == INTRA_FRAME) |
michael@0 | 158 | { |
michael@0 | 159 | vp8_build_intra_predictors_mbuv_s(xd, |
michael@0 | 160 | xd->recon_above[1], |
michael@0 | 161 | xd->recon_above[2], |
michael@0 | 162 | xd->recon_left[1], |
michael@0 | 163 | xd->recon_left[2], |
michael@0 | 164 | xd->recon_left_stride[1], |
michael@0 | 165 | xd->dst.u_buffer, xd->dst.v_buffer, |
michael@0 | 166 | xd->dst.uv_stride); |
michael@0 | 167 | |
michael@0 | 168 | if (mode != B_PRED) |
michael@0 | 169 | { |
michael@0 | 170 | vp8_build_intra_predictors_mby_s(xd, |
michael@0 | 171 | xd->recon_above[0], |
michael@0 | 172 | xd->recon_left[0], |
michael@0 | 173 | xd->recon_left_stride[0], |
michael@0 | 174 | xd->dst.y_buffer, |
michael@0 | 175 | xd->dst.y_stride); |
michael@0 | 176 | } |
michael@0 | 177 | else |
michael@0 | 178 | { |
michael@0 | 179 | short *DQC = xd->dequant_y1; |
michael@0 | 180 | int dst_stride = xd->dst.y_stride; |
michael@0 | 181 | |
michael@0 | 182 | /* clear out residual eob info */ |
michael@0 | 183 | if(xd->mode_info_context->mbmi.mb_skip_coeff) |
michael@0 | 184 | vpx_memset(xd->eobs, 0, 25); |
michael@0 | 185 | |
michael@0 | 186 | intra_prediction_down_copy(xd, xd->recon_above[0] + 16); |
michael@0 | 187 | |
michael@0 | 188 | for (i = 0; i < 16; i++) |
michael@0 | 189 | { |
michael@0 | 190 | BLOCKD *b = &xd->block[i]; |
michael@0 | 191 | unsigned char *dst = xd->dst.y_buffer + b->offset; |
michael@0 | 192 | B_PREDICTION_MODE b_mode = |
michael@0 | 193 | xd->mode_info_context->bmi[i].as_mode; |
michael@0 | 194 | unsigned char *Above = dst - dst_stride; |
michael@0 | 195 | unsigned char *yleft = dst - 1; |
michael@0 | 196 | int left_stride = dst_stride; |
michael@0 | 197 | unsigned char top_left = Above[-1]; |
michael@0 | 198 | |
michael@0 | 199 | vp8_intra4x4_predict(Above, yleft, left_stride, b_mode, |
michael@0 | 200 | dst, dst_stride, top_left); |
michael@0 | 201 | |
michael@0 | 202 | if (xd->eobs[i]) |
michael@0 | 203 | { |
michael@0 | 204 | if (xd->eobs[i] > 1) |
michael@0 | 205 | { |
michael@0 | 206 | vp8_dequant_idct_add(b->qcoeff, DQC, dst, dst_stride); |
michael@0 | 207 | } |
michael@0 | 208 | else |
michael@0 | 209 | { |
michael@0 | 210 | vp8_dc_only_idct_add |
michael@0 | 211 | (b->qcoeff[0] * DQC[0], |
michael@0 | 212 | dst, dst_stride, |
michael@0 | 213 | dst, dst_stride); |
michael@0 | 214 | vpx_memset(b->qcoeff, 0, 2 * sizeof(b->qcoeff[0])); |
michael@0 | 215 | } |
michael@0 | 216 | } |
michael@0 | 217 | } |
michael@0 | 218 | } |
michael@0 | 219 | } |
michael@0 | 220 | else |
michael@0 | 221 | { |
michael@0 | 222 | vp8_build_inter_predictors_mb(xd); |
michael@0 | 223 | } |
michael@0 | 224 | |
michael@0 | 225 | |
michael@0 | 226 | #if CONFIG_ERROR_CONCEALMENT |
michael@0 | 227 | if (corruption_detected) |
michael@0 | 228 | { |
michael@0 | 229 | return; |
michael@0 | 230 | } |
michael@0 | 231 | #endif |
michael@0 | 232 | |
michael@0 | 233 | if(!xd->mode_info_context->mbmi.mb_skip_coeff) |
michael@0 | 234 | { |
michael@0 | 235 | /* dequantization and idct */ |
michael@0 | 236 | if (mode != B_PRED) |
michael@0 | 237 | { |
michael@0 | 238 | short *DQC = xd->dequant_y1; |
michael@0 | 239 | |
michael@0 | 240 | if (mode != SPLITMV) |
michael@0 | 241 | { |
michael@0 | 242 | BLOCKD *b = &xd->block[24]; |
michael@0 | 243 | |
michael@0 | 244 | /* do 2nd order transform on the dc block */ |
michael@0 | 245 | if (xd->eobs[24] > 1) |
michael@0 | 246 | { |
michael@0 | 247 | vp8_dequantize_b(b, xd->dequant_y2); |
michael@0 | 248 | |
michael@0 | 249 | vp8_short_inv_walsh4x4(&b->dqcoeff[0], |
michael@0 | 250 | xd->qcoeff); |
michael@0 | 251 | vpx_memset(b->qcoeff, 0, 16 * sizeof(b->qcoeff[0])); |
michael@0 | 252 | } |
michael@0 | 253 | else |
michael@0 | 254 | { |
michael@0 | 255 | b->dqcoeff[0] = b->qcoeff[0] * xd->dequant_y2[0]; |
michael@0 | 256 | vp8_short_inv_walsh4x4_1(&b->dqcoeff[0], |
michael@0 | 257 | xd->qcoeff); |
michael@0 | 258 | vpx_memset(b->qcoeff, 0, 2 * sizeof(b->qcoeff[0])); |
michael@0 | 259 | } |
michael@0 | 260 | |
michael@0 | 261 | /* override the dc dequant constant in order to preserve the |
michael@0 | 262 | * dc components |
michael@0 | 263 | */ |
michael@0 | 264 | DQC = xd->dequant_y1_dc; |
michael@0 | 265 | } |
michael@0 | 266 | |
michael@0 | 267 | vp8_dequant_idct_add_y_block |
michael@0 | 268 | (xd->qcoeff, DQC, |
michael@0 | 269 | xd->dst.y_buffer, |
michael@0 | 270 | xd->dst.y_stride, xd->eobs); |
michael@0 | 271 | } |
michael@0 | 272 | |
michael@0 | 273 | vp8_dequant_idct_add_uv_block |
michael@0 | 274 | (xd->qcoeff+16*16, xd->dequant_uv, |
michael@0 | 275 | xd->dst.u_buffer, xd->dst.v_buffer, |
michael@0 | 276 | xd->dst.uv_stride, xd->eobs+16); |
michael@0 | 277 | } |
michael@0 | 278 | } |
michael@0 | 279 | |
michael@0 | 280 | static int get_delta_q(vp8_reader *bc, int prev, int *q_update) |
michael@0 | 281 | { |
michael@0 | 282 | int ret_val = 0; |
michael@0 | 283 | |
michael@0 | 284 | if (vp8_read_bit(bc)) |
michael@0 | 285 | { |
michael@0 | 286 | ret_val = vp8_read_literal(bc, 4); |
michael@0 | 287 | |
michael@0 | 288 | if (vp8_read_bit(bc)) |
michael@0 | 289 | ret_val = -ret_val; |
michael@0 | 290 | } |
michael@0 | 291 | |
michael@0 | 292 | /* Trigger a quantizer update if the delta-q value has changed */ |
michael@0 | 293 | if (ret_val != prev) |
michael@0 | 294 | *q_update = 1; |
michael@0 | 295 | |
michael@0 | 296 | return ret_val; |
michael@0 | 297 | } |
michael@0 | 298 | |
michael@0 | 299 | #ifdef PACKET_TESTING |
michael@0 | 300 | #include <stdio.h> |
michael@0 | 301 | FILE *vpxlog = 0; |
michael@0 | 302 | #endif |
michael@0 | 303 | |
michael@0 | 304 | static void yv12_extend_frame_top_c(YV12_BUFFER_CONFIG *ybf) |
michael@0 | 305 | { |
michael@0 | 306 | int i; |
michael@0 | 307 | unsigned char *src_ptr1; |
michael@0 | 308 | unsigned char *dest_ptr1; |
michael@0 | 309 | |
michael@0 | 310 | unsigned int Border; |
michael@0 | 311 | int plane_stride; |
michael@0 | 312 | |
michael@0 | 313 | /***********/ |
michael@0 | 314 | /* Y Plane */ |
michael@0 | 315 | /***********/ |
michael@0 | 316 | Border = ybf->border; |
michael@0 | 317 | plane_stride = ybf->y_stride; |
michael@0 | 318 | src_ptr1 = ybf->y_buffer - Border; |
michael@0 | 319 | dest_ptr1 = src_ptr1 - (Border * plane_stride); |
michael@0 | 320 | |
michael@0 | 321 | for (i = 0; i < (int)Border; i++) |
michael@0 | 322 | { |
michael@0 | 323 | vpx_memcpy(dest_ptr1, src_ptr1, plane_stride); |
michael@0 | 324 | dest_ptr1 += plane_stride; |
michael@0 | 325 | } |
michael@0 | 326 | |
michael@0 | 327 | |
michael@0 | 328 | /***********/ |
michael@0 | 329 | /* U Plane */ |
michael@0 | 330 | /***********/ |
michael@0 | 331 | plane_stride = ybf->uv_stride; |
michael@0 | 332 | Border /= 2; |
michael@0 | 333 | src_ptr1 = ybf->u_buffer - Border; |
michael@0 | 334 | dest_ptr1 = src_ptr1 - (Border * plane_stride); |
michael@0 | 335 | |
michael@0 | 336 | for (i = 0; i < (int)(Border); i++) |
michael@0 | 337 | { |
michael@0 | 338 | vpx_memcpy(dest_ptr1, src_ptr1, plane_stride); |
michael@0 | 339 | dest_ptr1 += plane_stride; |
michael@0 | 340 | } |
michael@0 | 341 | |
michael@0 | 342 | /***********/ |
michael@0 | 343 | /* V Plane */ |
michael@0 | 344 | /***********/ |
michael@0 | 345 | |
michael@0 | 346 | src_ptr1 = ybf->v_buffer - Border; |
michael@0 | 347 | dest_ptr1 = src_ptr1 - (Border * plane_stride); |
michael@0 | 348 | |
michael@0 | 349 | for (i = 0; i < (int)(Border); i++) |
michael@0 | 350 | { |
michael@0 | 351 | vpx_memcpy(dest_ptr1, src_ptr1, plane_stride); |
michael@0 | 352 | dest_ptr1 += plane_stride; |
michael@0 | 353 | } |
michael@0 | 354 | } |
michael@0 | 355 | |
michael@0 | 356 | static void yv12_extend_frame_bottom_c(YV12_BUFFER_CONFIG *ybf) |
michael@0 | 357 | { |
michael@0 | 358 | int i; |
michael@0 | 359 | unsigned char *src_ptr1, *src_ptr2; |
michael@0 | 360 | unsigned char *dest_ptr2; |
michael@0 | 361 | |
michael@0 | 362 | unsigned int Border; |
michael@0 | 363 | int plane_stride; |
michael@0 | 364 | int plane_height; |
michael@0 | 365 | |
michael@0 | 366 | /***********/ |
michael@0 | 367 | /* Y Plane */ |
michael@0 | 368 | /***********/ |
michael@0 | 369 | Border = ybf->border; |
michael@0 | 370 | plane_stride = ybf->y_stride; |
michael@0 | 371 | plane_height = ybf->y_height; |
michael@0 | 372 | |
michael@0 | 373 | src_ptr1 = ybf->y_buffer - Border; |
michael@0 | 374 | src_ptr2 = src_ptr1 + (plane_height * plane_stride) - plane_stride; |
michael@0 | 375 | dest_ptr2 = src_ptr2 + plane_stride; |
michael@0 | 376 | |
michael@0 | 377 | for (i = 0; i < (int)Border; i++) |
michael@0 | 378 | { |
michael@0 | 379 | vpx_memcpy(dest_ptr2, src_ptr2, plane_stride); |
michael@0 | 380 | dest_ptr2 += plane_stride; |
michael@0 | 381 | } |
michael@0 | 382 | |
michael@0 | 383 | |
michael@0 | 384 | /***********/ |
michael@0 | 385 | /* U Plane */ |
michael@0 | 386 | /***********/ |
michael@0 | 387 | plane_stride = ybf->uv_stride; |
michael@0 | 388 | plane_height = ybf->uv_height; |
michael@0 | 389 | Border /= 2; |
michael@0 | 390 | |
michael@0 | 391 | src_ptr1 = ybf->u_buffer - Border; |
michael@0 | 392 | src_ptr2 = src_ptr1 + (plane_height * plane_stride) - plane_stride; |
michael@0 | 393 | dest_ptr2 = src_ptr2 + plane_stride; |
michael@0 | 394 | |
michael@0 | 395 | for (i = 0; i < (int)(Border); i++) |
michael@0 | 396 | { |
michael@0 | 397 | vpx_memcpy(dest_ptr2, src_ptr2, plane_stride); |
michael@0 | 398 | dest_ptr2 += plane_stride; |
michael@0 | 399 | } |
michael@0 | 400 | |
michael@0 | 401 | /***********/ |
michael@0 | 402 | /* V Plane */ |
michael@0 | 403 | /***********/ |
michael@0 | 404 | |
michael@0 | 405 | src_ptr1 = ybf->v_buffer - Border; |
michael@0 | 406 | src_ptr2 = src_ptr1 + (plane_height * plane_stride) - plane_stride; |
michael@0 | 407 | dest_ptr2 = src_ptr2 + plane_stride; |
michael@0 | 408 | |
michael@0 | 409 | for (i = 0; i < (int)(Border); i++) |
michael@0 | 410 | { |
michael@0 | 411 | vpx_memcpy(dest_ptr2, src_ptr2, plane_stride); |
michael@0 | 412 | dest_ptr2 += plane_stride; |
michael@0 | 413 | } |
michael@0 | 414 | } |
michael@0 | 415 | |
michael@0 | 416 | static void yv12_extend_frame_left_right_c(YV12_BUFFER_CONFIG *ybf, |
michael@0 | 417 | unsigned char *y_src, |
michael@0 | 418 | unsigned char *u_src, |
michael@0 | 419 | unsigned char *v_src) |
michael@0 | 420 | { |
michael@0 | 421 | int i; |
michael@0 | 422 | unsigned char *src_ptr1, *src_ptr2; |
michael@0 | 423 | unsigned char *dest_ptr1, *dest_ptr2; |
michael@0 | 424 | |
michael@0 | 425 | unsigned int Border; |
michael@0 | 426 | int plane_stride; |
michael@0 | 427 | int plane_height; |
michael@0 | 428 | int plane_width; |
michael@0 | 429 | |
michael@0 | 430 | /***********/ |
michael@0 | 431 | /* Y Plane */ |
michael@0 | 432 | /***********/ |
michael@0 | 433 | Border = ybf->border; |
michael@0 | 434 | plane_stride = ybf->y_stride; |
michael@0 | 435 | plane_height = 16; |
michael@0 | 436 | plane_width = ybf->y_width; |
michael@0 | 437 | |
michael@0 | 438 | /* copy the left and right most columns out */ |
michael@0 | 439 | src_ptr1 = y_src; |
michael@0 | 440 | src_ptr2 = src_ptr1 + plane_width - 1; |
michael@0 | 441 | dest_ptr1 = src_ptr1 - Border; |
michael@0 | 442 | dest_ptr2 = src_ptr2 + 1; |
michael@0 | 443 | |
michael@0 | 444 | for (i = 0; i < plane_height; i++) |
michael@0 | 445 | { |
michael@0 | 446 | vpx_memset(dest_ptr1, src_ptr1[0], Border); |
michael@0 | 447 | vpx_memset(dest_ptr2, src_ptr2[0], Border); |
michael@0 | 448 | src_ptr1 += plane_stride; |
michael@0 | 449 | src_ptr2 += plane_stride; |
michael@0 | 450 | dest_ptr1 += plane_stride; |
michael@0 | 451 | dest_ptr2 += plane_stride; |
michael@0 | 452 | } |
michael@0 | 453 | |
michael@0 | 454 | /***********/ |
michael@0 | 455 | /* U Plane */ |
michael@0 | 456 | /***********/ |
michael@0 | 457 | plane_stride = ybf->uv_stride; |
michael@0 | 458 | plane_height = 8; |
michael@0 | 459 | plane_width = ybf->uv_width; |
michael@0 | 460 | Border /= 2; |
michael@0 | 461 | |
michael@0 | 462 | /* copy the left and right most columns out */ |
michael@0 | 463 | src_ptr1 = u_src; |
michael@0 | 464 | src_ptr2 = src_ptr1 + plane_width - 1; |
michael@0 | 465 | dest_ptr1 = src_ptr1 - Border; |
michael@0 | 466 | dest_ptr2 = src_ptr2 + 1; |
michael@0 | 467 | |
michael@0 | 468 | for (i = 0; i < plane_height; i++) |
michael@0 | 469 | { |
michael@0 | 470 | vpx_memset(dest_ptr1, src_ptr1[0], Border); |
michael@0 | 471 | vpx_memset(dest_ptr2, src_ptr2[0], Border); |
michael@0 | 472 | src_ptr1 += plane_stride; |
michael@0 | 473 | src_ptr2 += plane_stride; |
michael@0 | 474 | dest_ptr1 += plane_stride; |
michael@0 | 475 | dest_ptr2 += plane_stride; |
michael@0 | 476 | } |
michael@0 | 477 | |
michael@0 | 478 | /***********/ |
michael@0 | 479 | /* V Plane */ |
michael@0 | 480 | /***********/ |
michael@0 | 481 | |
michael@0 | 482 | /* copy the left and right most columns out */ |
michael@0 | 483 | src_ptr1 = v_src; |
michael@0 | 484 | src_ptr2 = src_ptr1 + plane_width - 1; |
michael@0 | 485 | dest_ptr1 = src_ptr1 - Border; |
michael@0 | 486 | dest_ptr2 = src_ptr2 + 1; |
michael@0 | 487 | |
michael@0 | 488 | for (i = 0; i < plane_height; i++) |
michael@0 | 489 | { |
michael@0 | 490 | vpx_memset(dest_ptr1, src_ptr1[0], Border); |
michael@0 | 491 | vpx_memset(dest_ptr2, src_ptr2[0], Border); |
michael@0 | 492 | src_ptr1 += plane_stride; |
michael@0 | 493 | src_ptr2 += plane_stride; |
michael@0 | 494 | dest_ptr1 += plane_stride; |
michael@0 | 495 | dest_ptr2 += plane_stride; |
michael@0 | 496 | } |
michael@0 | 497 | } |
michael@0 | 498 | |
michael@0 | 499 | static void decode_mb_rows(VP8D_COMP *pbi) |
michael@0 | 500 | { |
michael@0 | 501 | VP8_COMMON *const pc = & pbi->common; |
michael@0 | 502 | MACROBLOCKD *const xd = & pbi->mb; |
michael@0 | 503 | |
michael@0 | 504 | MODE_INFO *lf_mic = xd->mode_info_context; |
michael@0 | 505 | |
michael@0 | 506 | int ibc = 0; |
michael@0 | 507 | int num_part = 1 << pc->multi_token_partition; |
michael@0 | 508 | |
michael@0 | 509 | int recon_yoffset, recon_uvoffset; |
michael@0 | 510 | int mb_row, mb_col; |
michael@0 | 511 | int mb_idx = 0; |
michael@0 | 512 | |
michael@0 | 513 | YV12_BUFFER_CONFIG *yv12_fb_new = pbi->dec_fb_ref[INTRA_FRAME]; |
michael@0 | 514 | |
michael@0 | 515 | int recon_y_stride = yv12_fb_new->y_stride; |
michael@0 | 516 | int recon_uv_stride = yv12_fb_new->uv_stride; |
michael@0 | 517 | |
michael@0 | 518 | unsigned char *ref_buffer[MAX_REF_FRAMES][3]; |
michael@0 | 519 | unsigned char *dst_buffer[3]; |
michael@0 | 520 | unsigned char *lf_dst[3]; |
michael@0 | 521 | unsigned char *eb_dst[3]; |
michael@0 | 522 | int i; |
michael@0 | 523 | int ref_fb_corrupted[MAX_REF_FRAMES]; |
michael@0 | 524 | |
michael@0 | 525 | ref_fb_corrupted[INTRA_FRAME] = 0; |
michael@0 | 526 | |
michael@0 | 527 | for(i = 1; i < MAX_REF_FRAMES; i++) |
michael@0 | 528 | { |
michael@0 | 529 | YV12_BUFFER_CONFIG *this_fb = pbi->dec_fb_ref[i]; |
michael@0 | 530 | |
michael@0 | 531 | ref_buffer[i][0] = this_fb->y_buffer; |
michael@0 | 532 | ref_buffer[i][1] = this_fb->u_buffer; |
michael@0 | 533 | ref_buffer[i][2] = this_fb->v_buffer; |
michael@0 | 534 | |
michael@0 | 535 | ref_fb_corrupted[i] = this_fb->corrupted; |
michael@0 | 536 | } |
michael@0 | 537 | |
michael@0 | 538 | /* Set up the buffer pointers */ |
michael@0 | 539 | eb_dst[0] = lf_dst[0] = dst_buffer[0] = yv12_fb_new->y_buffer; |
michael@0 | 540 | eb_dst[1] = lf_dst[1] = dst_buffer[1] = yv12_fb_new->u_buffer; |
michael@0 | 541 | eb_dst[2] = lf_dst[2] = dst_buffer[2] = yv12_fb_new->v_buffer; |
michael@0 | 542 | |
michael@0 | 543 | xd->up_available = 0; |
michael@0 | 544 | |
michael@0 | 545 | /* Initialize the loop filter for this frame. */ |
michael@0 | 546 | if(pc->filter_level) |
michael@0 | 547 | vp8_loop_filter_frame_init(pc, xd, pc->filter_level); |
michael@0 | 548 | |
michael@0 | 549 | vp8_setup_intra_recon_top_line(yv12_fb_new); |
michael@0 | 550 | |
michael@0 | 551 | /* Decode the individual macro block */ |
michael@0 | 552 | for (mb_row = 0; mb_row < pc->mb_rows; mb_row++) |
michael@0 | 553 | { |
michael@0 | 554 | if (num_part > 1) |
michael@0 | 555 | { |
michael@0 | 556 | xd->current_bc = & pbi->mbc[ibc]; |
michael@0 | 557 | ibc++; |
michael@0 | 558 | |
michael@0 | 559 | if (ibc == num_part) |
michael@0 | 560 | ibc = 0; |
michael@0 | 561 | } |
michael@0 | 562 | |
michael@0 | 563 | recon_yoffset = mb_row * recon_y_stride * 16; |
michael@0 | 564 | recon_uvoffset = mb_row * recon_uv_stride * 8; |
michael@0 | 565 | |
michael@0 | 566 | /* reset contexts */ |
michael@0 | 567 | xd->above_context = pc->above_context; |
michael@0 | 568 | vpx_memset(xd->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES)); |
michael@0 | 569 | |
michael@0 | 570 | xd->left_available = 0; |
michael@0 | 571 | |
michael@0 | 572 | xd->mb_to_top_edge = -((mb_row * 16) << 3); |
michael@0 | 573 | xd->mb_to_bottom_edge = ((pc->mb_rows - 1 - mb_row) * 16) << 3; |
michael@0 | 574 | |
michael@0 | 575 | xd->recon_above[0] = dst_buffer[0] + recon_yoffset; |
michael@0 | 576 | xd->recon_above[1] = dst_buffer[1] + recon_uvoffset; |
michael@0 | 577 | xd->recon_above[2] = dst_buffer[2] + recon_uvoffset; |
michael@0 | 578 | |
michael@0 | 579 | xd->recon_left[0] = xd->recon_above[0] - 1; |
michael@0 | 580 | xd->recon_left[1] = xd->recon_above[1] - 1; |
michael@0 | 581 | xd->recon_left[2] = xd->recon_above[2] - 1; |
michael@0 | 582 | |
michael@0 | 583 | xd->recon_above[0] -= xd->dst.y_stride; |
michael@0 | 584 | xd->recon_above[1] -= xd->dst.uv_stride; |
michael@0 | 585 | xd->recon_above[2] -= xd->dst.uv_stride; |
michael@0 | 586 | |
michael@0 | 587 | /* TODO: move to outside row loop */ |
michael@0 | 588 | xd->recon_left_stride[0] = xd->dst.y_stride; |
michael@0 | 589 | xd->recon_left_stride[1] = xd->dst.uv_stride; |
michael@0 | 590 | |
michael@0 | 591 | setup_intra_recon_left(xd->recon_left[0], xd->recon_left[1], |
michael@0 | 592 | xd->recon_left[2], xd->dst.y_stride, |
michael@0 | 593 | xd->dst.uv_stride); |
michael@0 | 594 | |
michael@0 | 595 | for (mb_col = 0; mb_col < pc->mb_cols; mb_col++) |
michael@0 | 596 | { |
michael@0 | 597 | /* Distance of Mb to the various image edges. |
michael@0 | 598 | * These are specified to 8th pel as they are always compared to values |
michael@0 | 599 | * that are in 1/8th pel units |
michael@0 | 600 | */ |
michael@0 | 601 | xd->mb_to_left_edge = -((mb_col * 16) << 3); |
michael@0 | 602 | xd->mb_to_right_edge = ((pc->mb_cols - 1 - mb_col) * 16) << 3; |
michael@0 | 603 | |
michael@0 | 604 | #if CONFIG_ERROR_CONCEALMENT |
michael@0 | 605 | { |
michael@0 | 606 | int corrupt_residual = (!pbi->independent_partitions && |
michael@0 | 607 | pbi->frame_corrupt_residual) || |
michael@0 | 608 | vp8dx_bool_error(xd->current_bc); |
michael@0 | 609 | if (pbi->ec_active && |
michael@0 | 610 | xd->mode_info_context->mbmi.ref_frame == INTRA_FRAME && |
michael@0 | 611 | corrupt_residual) |
michael@0 | 612 | { |
michael@0 | 613 | /* We have an intra block with corrupt coefficients, better to |
michael@0 | 614 | * conceal with an inter block. Interpolate MVs from neighboring |
michael@0 | 615 | * MBs. |
michael@0 | 616 | * |
michael@0 | 617 | * Note that for the first mb with corrupt residual in a frame, |
michael@0 | 618 | * we might not discover that before decoding the residual. That |
michael@0 | 619 | * happens after this check, and therefore no inter concealment |
michael@0 | 620 | * will be done. |
michael@0 | 621 | */ |
michael@0 | 622 | vp8_interpolate_motion(xd, |
michael@0 | 623 | mb_row, mb_col, |
michael@0 | 624 | pc->mb_rows, pc->mb_cols, |
michael@0 | 625 | pc->mode_info_stride); |
michael@0 | 626 | } |
michael@0 | 627 | } |
michael@0 | 628 | #endif |
michael@0 | 629 | |
michael@0 | 630 | xd->dst.y_buffer = dst_buffer[0] + recon_yoffset; |
michael@0 | 631 | xd->dst.u_buffer = dst_buffer[1] + recon_uvoffset; |
michael@0 | 632 | xd->dst.v_buffer = dst_buffer[2] + recon_uvoffset; |
michael@0 | 633 | |
michael@0 | 634 | xd->pre.y_buffer = ref_buffer[xd->mode_info_context->mbmi.ref_frame][0] + recon_yoffset; |
michael@0 | 635 | xd->pre.u_buffer = ref_buffer[xd->mode_info_context->mbmi.ref_frame][1] + recon_uvoffset; |
michael@0 | 636 | xd->pre.v_buffer = ref_buffer[xd->mode_info_context->mbmi.ref_frame][2] + recon_uvoffset; |
michael@0 | 637 | |
michael@0 | 638 | /* propagate errors from reference frames */ |
michael@0 | 639 | xd->corrupted |= ref_fb_corrupted[xd->mode_info_context->mbmi.ref_frame]; |
michael@0 | 640 | |
michael@0 | 641 | decode_macroblock(pbi, xd, mb_idx); |
michael@0 | 642 | |
michael@0 | 643 | mb_idx++; |
michael@0 | 644 | xd->left_available = 1; |
michael@0 | 645 | |
michael@0 | 646 | /* check if the boolean decoder has suffered an error */ |
michael@0 | 647 | xd->corrupted |= vp8dx_bool_error(xd->current_bc); |
michael@0 | 648 | |
michael@0 | 649 | xd->recon_above[0] += 16; |
michael@0 | 650 | xd->recon_above[1] += 8; |
michael@0 | 651 | xd->recon_above[2] += 8; |
michael@0 | 652 | xd->recon_left[0] += 16; |
michael@0 | 653 | xd->recon_left[1] += 8; |
michael@0 | 654 | xd->recon_left[2] += 8; |
michael@0 | 655 | |
michael@0 | 656 | recon_yoffset += 16; |
michael@0 | 657 | recon_uvoffset += 8; |
michael@0 | 658 | |
michael@0 | 659 | ++xd->mode_info_context; /* next mb */ |
michael@0 | 660 | |
michael@0 | 661 | xd->above_context++; |
michael@0 | 662 | } |
michael@0 | 663 | |
michael@0 | 664 | /* adjust to the next row of mbs */ |
michael@0 | 665 | vp8_extend_mb_row(yv12_fb_new, xd->dst.y_buffer + 16, |
michael@0 | 666 | xd->dst.u_buffer + 8, xd->dst.v_buffer + 8); |
michael@0 | 667 | |
michael@0 | 668 | ++xd->mode_info_context; /* skip prediction column */ |
michael@0 | 669 | xd->up_available = 1; |
michael@0 | 670 | |
michael@0 | 671 | if(pc->filter_level) |
michael@0 | 672 | { |
michael@0 | 673 | if(mb_row > 0) |
michael@0 | 674 | { |
michael@0 | 675 | if (pc->filter_type == NORMAL_LOOPFILTER) |
michael@0 | 676 | vp8_loop_filter_row_normal(pc, lf_mic, mb_row-1, |
michael@0 | 677 | recon_y_stride, recon_uv_stride, |
michael@0 | 678 | lf_dst[0], lf_dst[1], lf_dst[2]); |
michael@0 | 679 | else |
michael@0 | 680 | vp8_loop_filter_row_simple(pc, lf_mic, mb_row-1, |
michael@0 | 681 | recon_y_stride, recon_uv_stride, |
michael@0 | 682 | lf_dst[0], lf_dst[1], lf_dst[2]); |
michael@0 | 683 | |
michael@0 | 684 | if(mb_row > 1) |
michael@0 | 685 | { |
michael@0 | 686 | yv12_extend_frame_left_right_c(yv12_fb_new, |
michael@0 | 687 | eb_dst[0], |
michael@0 | 688 | eb_dst[1], |
michael@0 | 689 | eb_dst[2]); |
michael@0 | 690 | |
michael@0 | 691 | eb_dst[0] += recon_y_stride * 16; |
michael@0 | 692 | eb_dst[1] += recon_uv_stride * 8; |
michael@0 | 693 | eb_dst[2] += recon_uv_stride * 8; |
michael@0 | 694 | |
michael@0 | 695 | if(mb_row == 2) |
michael@0 | 696 | yv12_extend_frame_top_c(yv12_fb_new); |
michael@0 | 697 | |
michael@0 | 698 | } |
michael@0 | 699 | |
michael@0 | 700 | lf_dst[0] += recon_y_stride * 16; |
michael@0 | 701 | lf_dst[1] += recon_uv_stride * 8; |
michael@0 | 702 | lf_dst[2] += recon_uv_stride * 8; |
michael@0 | 703 | lf_mic += pc->mb_cols; |
michael@0 | 704 | lf_mic++; /* Skip border mb */ |
michael@0 | 705 | } |
michael@0 | 706 | } |
michael@0 | 707 | else |
michael@0 | 708 | { |
michael@0 | 709 | if(mb_row > 0) |
michael@0 | 710 | { |
michael@0 | 711 | /**/ |
michael@0 | 712 | yv12_extend_frame_left_right_c(yv12_fb_new, |
michael@0 | 713 | eb_dst[0], |
michael@0 | 714 | eb_dst[1], |
michael@0 | 715 | eb_dst[2]); |
michael@0 | 716 | |
michael@0 | 717 | eb_dst[0] += recon_y_stride * 16; |
michael@0 | 718 | eb_dst[1] += recon_uv_stride * 8; |
michael@0 | 719 | eb_dst[2] += recon_uv_stride * 8; |
michael@0 | 720 | |
michael@0 | 721 | if(mb_row == 1) |
michael@0 | 722 | yv12_extend_frame_top_c(yv12_fb_new); |
michael@0 | 723 | } |
michael@0 | 724 | } |
michael@0 | 725 | } |
michael@0 | 726 | |
michael@0 | 727 | if(pc->filter_level) |
michael@0 | 728 | { |
michael@0 | 729 | if (pc->filter_type == NORMAL_LOOPFILTER) |
michael@0 | 730 | vp8_loop_filter_row_normal(pc, lf_mic, mb_row-1, recon_y_stride, |
michael@0 | 731 | recon_uv_stride, lf_dst[0], lf_dst[1], |
michael@0 | 732 | lf_dst[2]); |
michael@0 | 733 | else |
michael@0 | 734 | vp8_loop_filter_row_simple(pc, lf_mic, mb_row-1, recon_y_stride, |
michael@0 | 735 | recon_uv_stride, lf_dst[0], lf_dst[1], |
michael@0 | 736 | lf_dst[2]); |
michael@0 | 737 | |
michael@0 | 738 | yv12_extend_frame_left_right_c(yv12_fb_new, |
michael@0 | 739 | eb_dst[0], |
michael@0 | 740 | eb_dst[1], |
michael@0 | 741 | eb_dst[2]); |
michael@0 | 742 | eb_dst[0] += recon_y_stride * 16; |
michael@0 | 743 | eb_dst[1] += recon_uv_stride * 8; |
michael@0 | 744 | eb_dst[2] += recon_uv_stride * 8; |
michael@0 | 745 | } |
michael@0 | 746 | yv12_extend_frame_left_right_c(yv12_fb_new, |
michael@0 | 747 | eb_dst[0], |
michael@0 | 748 | eb_dst[1], |
michael@0 | 749 | eb_dst[2]); |
michael@0 | 750 | |
michael@0 | 751 | yv12_extend_frame_bottom_c(yv12_fb_new); |
michael@0 | 752 | |
michael@0 | 753 | } |
michael@0 | 754 | |
michael@0 | 755 | static unsigned int read_partition_size(VP8D_COMP *pbi, |
michael@0 | 756 | const unsigned char *cx_size) |
michael@0 | 757 | { |
michael@0 | 758 | unsigned char temp[3]; |
michael@0 | 759 | if (pbi->decrypt_cb) |
michael@0 | 760 | { |
michael@0 | 761 | pbi->decrypt_cb(pbi->decrypt_state, cx_size, temp, 3); |
michael@0 | 762 | cx_size = temp; |
michael@0 | 763 | } |
michael@0 | 764 | return cx_size[0] + (cx_size[1] << 8) + (cx_size[2] << 16); |
michael@0 | 765 | } |
michael@0 | 766 | |
michael@0 | 767 | static int read_is_valid(const unsigned char *start, |
michael@0 | 768 | size_t len, |
michael@0 | 769 | const unsigned char *end) |
michael@0 | 770 | { |
michael@0 | 771 | return (start + len > start && start + len <= end); |
michael@0 | 772 | } |
michael@0 | 773 | |
michael@0 | 774 | static unsigned int read_available_partition_size( |
michael@0 | 775 | VP8D_COMP *pbi, |
michael@0 | 776 | const unsigned char *token_part_sizes, |
michael@0 | 777 | const unsigned char *fragment_start, |
michael@0 | 778 | const unsigned char *first_fragment_end, |
michael@0 | 779 | const unsigned char *fragment_end, |
michael@0 | 780 | int i, |
michael@0 | 781 | int num_part) |
michael@0 | 782 | { |
michael@0 | 783 | VP8_COMMON* pc = &pbi->common; |
michael@0 | 784 | const unsigned char *partition_size_ptr = token_part_sizes + i * 3; |
michael@0 | 785 | unsigned int partition_size = 0; |
michael@0 | 786 | ptrdiff_t bytes_left = fragment_end - fragment_start; |
michael@0 | 787 | /* Calculate the length of this partition. The last partition |
michael@0 | 788 | * size is implicit. If the partition size can't be read, then |
michael@0 | 789 | * either use the remaining data in the buffer (for EC mode) |
michael@0 | 790 | * or throw an error. |
michael@0 | 791 | */ |
michael@0 | 792 | if (i < num_part - 1) |
michael@0 | 793 | { |
michael@0 | 794 | if (read_is_valid(partition_size_ptr, 3, first_fragment_end)) |
michael@0 | 795 | partition_size = read_partition_size(pbi, partition_size_ptr); |
michael@0 | 796 | else if (pbi->ec_active) |
michael@0 | 797 | partition_size = (unsigned int)bytes_left; |
michael@0 | 798 | else |
michael@0 | 799 | vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, |
michael@0 | 800 | "Truncated partition size data"); |
michael@0 | 801 | } |
michael@0 | 802 | else |
michael@0 | 803 | partition_size = (unsigned int)bytes_left; |
michael@0 | 804 | |
michael@0 | 805 | /* Validate the calculated partition length. If the buffer |
michael@0 | 806 | * described by the partition can't be fully read, then restrict |
michael@0 | 807 | * it to the portion that can be (for EC mode) or throw an error. |
michael@0 | 808 | */ |
michael@0 | 809 | if (!read_is_valid(fragment_start, partition_size, fragment_end)) |
michael@0 | 810 | { |
michael@0 | 811 | if (pbi->ec_active) |
michael@0 | 812 | partition_size = (unsigned int)bytes_left; |
michael@0 | 813 | else |
michael@0 | 814 | vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, |
michael@0 | 815 | "Truncated packet or corrupt partition " |
michael@0 | 816 | "%d length", i + 1); |
michael@0 | 817 | } |
michael@0 | 818 | return partition_size; |
michael@0 | 819 | } |
michael@0 | 820 | |
michael@0 | 821 | |
michael@0 | 822 | static void setup_token_decoder(VP8D_COMP *pbi, |
michael@0 | 823 | const unsigned char* token_part_sizes) |
michael@0 | 824 | { |
michael@0 | 825 | vp8_reader *bool_decoder = &pbi->mbc[0]; |
michael@0 | 826 | unsigned int partition_idx; |
michael@0 | 827 | unsigned int fragment_idx; |
michael@0 | 828 | unsigned int num_token_partitions; |
michael@0 | 829 | const unsigned char *first_fragment_end = pbi->fragments.ptrs[0] + |
michael@0 | 830 | pbi->fragments.sizes[0]; |
michael@0 | 831 | |
michael@0 | 832 | TOKEN_PARTITION multi_token_partition = |
michael@0 | 833 | (TOKEN_PARTITION)vp8_read_literal(&pbi->mbc[8], 2); |
michael@0 | 834 | if (!vp8dx_bool_error(&pbi->mbc[8])) |
michael@0 | 835 | pbi->common.multi_token_partition = multi_token_partition; |
michael@0 | 836 | num_token_partitions = 1 << pbi->common.multi_token_partition; |
michael@0 | 837 | |
michael@0 | 838 | /* Check for partitions within the fragments and unpack the fragments |
michael@0 | 839 | * so that each fragment pointer points to its corresponding partition. */ |
michael@0 | 840 | for (fragment_idx = 0; fragment_idx < pbi->fragments.count; ++fragment_idx) |
michael@0 | 841 | { |
michael@0 | 842 | unsigned int fragment_size = pbi->fragments.sizes[fragment_idx]; |
michael@0 | 843 | const unsigned char *fragment_end = pbi->fragments.ptrs[fragment_idx] + |
michael@0 | 844 | fragment_size; |
michael@0 | 845 | /* Special case for handling the first partition since we have already |
michael@0 | 846 | * read its size. */ |
michael@0 | 847 | if (fragment_idx == 0) |
michael@0 | 848 | { |
michael@0 | 849 | /* Size of first partition + token partition sizes element */ |
michael@0 | 850 | ptrdiff_t ext_first_part_size = token_part_sizes - |
michael@0 | 851 | pbi->fragments.ptrs[0] + 3 * (num_token_partitions - 1); |
michael@0 | 852 | fragment_size -= (unsigned int)ext_first_part_size; |
michael@0 | 853 | if (fragment_size > 0) |
michael@0 | 854 | { |
michael@0 | 855 | pbi->fragments.sizes[0] = (unsigned int)ext_first_part_size; |
michael@0 | 856 | /* The fragment contains an additional partition. Move to |
michael@0 | 857 | * next. */ |
michael@0 | 858 | fragment_idx++; |
michael@0 | 859 | pbi->fragments.ptrs[fragment_idx] = pbi->fragments.ptrs[0] + |
michael@0 | 860 | pbi->fragments.sizes[0]; |
michael@0 | 861 | } |
michael@0 | 862 | } |
michael@0 | 863 | /* Split the chunk into partitions read from the bitstream */ |
michael@0 | 864 | while (fragment_size > 0) |
michael@0 | 865 | { |
michael@0 | 866 | ptrdiff_t partition_size = read_available_partition_size( |
michael@0 | 867 | pbi, |
michael@0 | 868 | token_part_sizes, |
michael@0 | 869 | pbi->fragments.ptrs[fragment_idx], |
michael@0 | 870 | first_fragment_end, |
michael@0 | 871 | fragment_end, |
michael@0 | 872 | fragment_idx - 1, |
michael@0 | 873 | num_token_partitions); |
michael@0 | 874 | pbi->fragments.sizes[fragment_idx] = (unsigned int)partition_size; |
michael@0 | 875 | fragment_size -= (unsigned int)partition_size; |
michael@0 | 876 | assert(fragment_idx <= num_token_partitions); |
michael@0 | 877 | if (fragment_size > 0) |
michael@0 | 878 | { |
michael@0 | 879 | /* The fragment contains an additional partition. |
michael@0 | 880 | * Move to next. */ |
michael@0 | 881 | fragment_idx++; |
michael@0 | 882 | pbi->fragments.ptrs[fragment_idx] = |
michael@0 | 883 | pbi->fragments.ptrs[fragment_idx - 1] + partition_size; |
michael@0 | 884 | } |
michael@0 | 885 | } |
michael@0 | 886 | } |
michael@0 | 887 | |
michael@0 | 888 | pbi->fragments.count = num_token_partitions + 1; |
michael@0 | 889 | |
michael@0 | 890 | for (partition_idx = 1; partition_idx < pbi->fragments.count; ++partition_idx) |
michael@0 | 891 | { |
michael@0 | 892 | if (vp8dx_start_decode(bool_decoder, |
michael@0 | 893 | pbi->fragments.ptrs[partition_idx], |
michael@0 | 894 | pbi->fragments.sizes[partition_idx], |
michael@0 | 895 | pbi->decrypt_cb, pbi->decrypt_state)) |
michael@0 | 896 | vpx_internal_error(&pbi->common.error, VPX_CODEC_MEM_ERROR, |
michael@0 | 897 | "Failed to allocate bool decoder %d", |
michael@0 | 898 | partition_idx); |
michael@0 | 899 | |
michael@0 | 900 | bool_decoder++; |
michael@0 | 901 | } |
michael@0 | 902 | |
michael@0 | 903 | #if CONFIG_MULTITHREAD |
michael@0 | 904 | /* Clamp number of decoder threads */ |
michael@0 | 905 | if (pbi->decoding_thread_count > num_token_partitions - 1) |
michael@0 | 906 | pbi->decoding_thread_count = num_token_partitions - 1; |
michael@0 | 907 | #endif |
michael@0 | 908 | } |
michael@0 | 909 | |
michael@0 | 910 | |
michael@0 | 911 | static void init_frame(VP8D_COMP *pbi) |
michael@0 | 912 | { |
michael@0 | 913 | VP8_COMMON *const pc = & pbi->common; |
michael@0 | 914 | MACROBLOCKD *const xd = & pbi->mb; |
michael@0 | 915 | |
michael@0 | 916 | if (pc->frame_type == KEY_FRAME) |
michael@0 | 917 | { |
michael@0 | 918 | /* Various keyframe initializations */ |
michael@0 | 919 | vpx_memcpy(pc->fc.mvc, vp8_default_mv_context, sizeof(vp8_default_mv_context)); |
michael@0 | 920 | |
michael@0 | 921 | vp8_init_mbmode_probs(pc); |
michael@0 | 922 | |
michael@0 | 923 | vp8_default_coef_probs(pc); |
michael@0 | 924 | |
michael@0 | 925 | /* reset the segment feature data to 0 with delta coding (Default state). */ |
michael@0 | 926 | vpx_memset(xd->segment_feature_data, 0, sizeof(xd->segment_feature_data)); |
michael@0 | 927 | xd->mb_segement_abs_delta = SEGMENT_DELTADATA; |
michael@0 | 928 | |
michael@0 | 929 | /* reset the mode ref deltasa for loop filter */ |
michael@0 | 930 | vpx_memset(xd->ref_lf_deltas, 0, sizeof(xd->ref_lf_deltas)); |
michael@0 | 931 | vpx_memset(xd->mode_lf_deltas, 0, sizeof(xd->mode_lf_deltas)); |
michael@0 | 932 | |
michael@0 | 933 | /* All buffers are implicitly updated on key frames. */ |
michael@0 | 934 | pc->refresh_golden_frame = 1; |
michael@0 | 935 | pc->refresh_alt_ref_frame = 1; |
michael@0 | 936 | pc->copy_buffer_to_gf = 0; |
michael@0 | 937 | pc->copy_buffer_to_arf = 0; |
michael@0 | 938 | |
michael@0 | 939 | /* Note that Golden and Altref modes cannot be used on a key frame so |
michael@0 | 940 | * ref_frame_sign_bias[] is undefined and meaningless |
michael@0 | 941 | */ |
michael@0 | 942 | pc->ref_frame_sign_bias[GOLDEN_FRAME] = 0; |
michael@0 | 943 | pc->ref_frame_sign_bias[ALTREF_FRAME] = 0; |
michael@0 | 944 | } |
michael@0 | 945 | else |
michael@0 | 946 | { |
michael@0 | 947 | /* To enable choice of different interploation filters */ |
michael@0 | 948 | if (!pc->use_bilinear_mc_filter) |
michael@0 | 949 | { |
michael@0 | 950 | xd->subpixel_predict = vp8_sixtap_predict4x4; |
michael@0 | 951 | xd->subpixel_predict8x4 = vp8_sixtap_predict8x4; |
michael@0 | 952 | xd->subpixel_predict8x8 = vp8_sixtap_predict8x8; |
michael@0 | 953 | xd->subpixel_predict16x16 = vp8_sixtap_predict16x16; |
michael@0 | 954 | } |
michael@0 | 955 | else |
michael@0 | 956 | { |
michael@0 | 957 | xd->subpixel_predict = vp8_bilinear_predict4x4; |
michael@0 | 958 | xd->subpixel_predict8x4 = vp8_bilinear_predict8x4; |
michael@0 | 959 | xd->subpixel_predict8x8 = vp8_bilinear_predict8x8; |
michael@0 | 960 | xd->subpixel_predict16x16 = vp8_bilinear_predict16x16; |
michael@0 | 961 | } |
michael@0 | 962 | |
michael@0 | 963 | if (pbi->decoded_key_frame && pbi->ec_enabled && !pbi->ec_active) |
michael@0 | 964 | pbi->ec_active = 1; |
michael@0 | 965 | } |
michael@0 | 966 | |
michael@0 | 967 | xd->left_context = &pc->left_context; |
michael@0 | 968 | xd->mode_info_context = pc->mi; |
michael@0 | 969 | xd->frame_type = pc->frame_type; |
michael@0 | 970 | xd->mode_info_context->mbmi.mode = DC_PRED; |
michael@0 | 971 | xd->mode_info_stride = pc->mode_info_stride; |
michael@0 | 972 | xd->corrupted = 0; /* init without corruption */ |
michael@0 | 973 | |
michael@0 | 974 | xd->fullpixel_mask = 0xffffffff; |
michael@0 | 975 | if(pc->full_pixel) |
michael@0 | 976 | xd->fullpixel_mask = 0xfffffff8; |
michael@0 | 977 | |
michael@0 | 978 | } |
michael@0 | 979 | |
michael@0 | 980 | int vp8_decode_frame(VP8D_COMP *pbi) |
michael@0 | 981 | { |
michael@0 | 982 | vp8_reader *const bc = &pbi->mbc[8]; |
michael@0 | 983 | VP8_COMMON *const pc = &pbi->common; |
michael@0 | 984 | MACROBLOCKD *const xd = &pbi->mb; |
michael@0 | 985 | const unsigned char *data = pbi->fragments.ptrs[0]; |
michael@0 | 986 | const unsigned char *data_end = data + pbi->fragments.sizes[0]; |
michael@0 | 987 | ptrdiff_t first_partition_length_in_bytes; |
michael@0 | 988 | |
michael@0 | 989 | int i, j, k, l; |
michael@0 | 990 | const int *const mb_feature_data_bits = vp8_mb_feature_data_bits; |
michael@0 | 991 | int corrupt_tokens = 0; |
michael@0 | 992 | int prev_independent_partitions = pbi->independent_partitions; |
michael@0 | 993 | |
michael@0 | 994 | YV12_BUFFER_CONFIG *yv12_fb_new = pbi->dec_fb_ref[INTRA_FRAME]; |
michael@0 | 995 | |
michael@0 | 996 | /* start with no corruption of current frame */ |
michael@0 | 997 | xd->corrupted = 0; |
michael@0 | 998 | yv12_fb_new->corrupted = 0; |
michael@0 | 999 | |
michael@0 | 1000 | if (data_end - data < 3) |
michael@0 | 1001 | { |
michael@0 | 1002 | if (!pbi->ec_active) |
michael@0 | 1003 | { |
michael@0 | 1004 | vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, |
michael@0 | 1005 | "Truncated packet"); |
michael@0 | 1006 | } |
michael@0 | 1007 | |
michael@0 | 1008 | /* Declare the missing frame as an inter frame since it will |
michael@0 | 1009 | be handled as an inter frame when we have estimated its |
michael@0 | 1010 | motion vectors. */ |
michael@0 | 1011 | pc->frame_type = INTER_FRAME; |
michael@0 | 1012 | pc->version = 0; |
michael@0 | 1013 | pc->show_frame = 1; |
michael@0 | 1014 | first_partition_length_in_bytes = 0; |
michael@0 | 1015 | } |
michael@0 | 1016 | else |
michael@0 | 1017 | { |
michael@0 | 1018 | unsigned char clear_buffer[10]; |
michael@0 | 1019 | const unsigned char *clear = data; |
michael@0 | 1020 | if (pbi->decrypt_cb) |
michael@0 | 1021 | { |
michael@0 | 1022 | int n = (int)(data_end - data); |
michael@0 | 1023 | if (n > 10) n = 10; |
michael@0 | 1024 | pbi->decrypt_cb(pbi->decrypt_state, data, clear_buffer, n); |
michael@0 | 1025 | clear = clear_buffer; |
michael@0 | 1026 | } |
michael@0 | 1027 | |
michael@0 | 1028 | pc->frame_type = (FRAME_TYPE)(clear[0] & 1); |
michael@0 | 1029 | pc->version = (clear[0] >> 1) & 7; |
michael@0 | 1030 | pc->show_frame = (clear[0] >> 4) & 1; |
michael@0 | 1031 | first_partition_length_in_bytes = |
michael@0 | 1032 | (clear[0] | (clear[1] << 8) | (clear[2] << 16)) >> 5; |
michael@0 | 1033 | |
michael@0 | 1034 | if (!pbi->ec_active && |
michael@0 | 1035 | (data + first_partition_length_in_bytes > data_end |
michael@0 | 1036 | || data + first_partition_length_in_bytes < data)) |
michael@0 | 1037 | vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, |
michael@0 | 1038 | "Truncated packet or corrupt partition 0 length"); |
michael@0 | 1039 | |
michael@0 | 1040 | data += 3; |
michael@0 | 1041 | clear += 3; |
michael@0 | 1042 | |
michael@0 | 1043 | vp8_setup_version(pc); |
michael@0 | 1044 | |
michael@0 | 1045 | |
michael@0 | 1046 | if (pc->frame_type == KEY_FRAME) |
michael@0 | 1047 | { |
michael@0 | 1048 | /* vet via sync code */ |
michael@0 | 1049 | /* When error concealment is enabled we should only check the sync |
michael@0 | 1050 | * code if we have enough bits available |
michael@0 | 1051 | */ |
michael@0 | 1052 | if (!pbi->ec_active || data + 3 < data_end) |
michael@0 | 1053 | { |
michael@0 | 1054 | if (clear[0] != 0x9d || clear[1] != 0x01 || clear[2] != 0x2a) |
michael@0 | 1055 | vpx_internal_error(&pc->error, VPX_CODEC_UNSUP_BITSTREAM, |
michael@0 | 1056 | "Invalid frame sync code"); |
michael@0 | 1057 | } |
michael@0 | 1058 | |
michael@0 | 1059 | /* If error concealment is enabled we should only parse the new size |
michael@0 | 1060 | * if we have enough data. Otherwise we will end up with the wrong |
michael@0 | 1061 | * size. |
michael@0 | 1062 | */ |
michael@0 | 1063 | if (!pbi->ec_active || data + 6 < data_end) |
michael@0 | 1064 | { |
michael@0 | 1065 | pc->Width = (clear[3] | (clear[4] << 8)) & 0x3fff; |
michael@0 | 1066 | pc->horiz_scale = clear[4] >> 6; |
michael@0 | 1067 | pc->Height = (clear[5] | (clear[6] << 8)) & 0x3fff; |
michael@0 | 1068 | pc->vert_scale = clear[6] >> 6; |
michael@0 | 1069 | } |
michael@0 | 1070 | data += 7; |
michael@0 | 1071 | clear += 7; |
michael@0 | 1072 | } |
michael@0 | 1073 | else |
michael@0 | 1074 | { |
michael@0 | 1075 | vpx_memcpy(&xd->pre, yv12_fb_new, sizeof(YV12_BUFFER_CONFIG)); |
michael@0 | 1076 | vpx_memcpy(&xd->dst, yv12_fb_new, sizeof(YV12_BUFFER_CONFIG)); |
michael@0 | 1077 | } |
michael@0 | 1078 | } |
michael@0 | 1079 | if ((!pbi->decoded_key_frame && pc->frame_type != KEY_FRAME)) |
michael@0 | 1080 | { |
michael@0 | 1081 | return -1; |
michael@0 | 1082 | } |
michael@0 | 1083 | |
michael@0 | 1084 | init_frame(pbi); |
michael@0 | 1085 | |
michael@0 | 1086 | if (vp8dx_start_decode(bc, data, (unsigned int)(data_end - data), |
michael@0 | 1087 | pbi->decrypt_cb, pbi->decrypt_state)) |
michael@0 | 1088 | vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR, |
michael@0 | 1089 | "Failed to allocate bool decoder 0"); |
michael@0 | 1090 | if (pc->frame_type == KEY_FRAME) { |
michael@0 | 1091 | (void)vp8_read_bit(bc); // colorspace |
michael@0 | 1092 | pc->clamp_type = (CLAMP_TYPE)vp8_read_bit(bc); |
michael@0 | 1093 | } |
michael@0 | 1094 | |
michael@0 | 1095 | /* Is segmentation enabled */ |
michael@0 | 1096 | xd->segmentation_enabled = (unsigned char)vp8_read_bit(bc); |
michael@0 | 1097 | |
michael@0 | 1098 | if (xd->segmentation_enabled) |
michael@0 | 1099 | { |
michael@0 | 1100 | /* Signal whether or not the segmentation map is being explicitly updated this frame. */ |
michael@0 | 1101 | xd->update_mb_segmentation_map = (unsigned char)vp8_read_bit(bc); |
michael@0 | 1102 | xd->update_mb_segmentation_data = (unsigned char)vp8_read_bit(bc); |
michael@0 | 1103 | |
michael@0 | 1104 | if (xd->update_mb_segmentation_data) |
michael@0 | 1105 | { |
michael@0 | 1106 | xd->mb_segement_abs_delta = (unsigned char)vp8_read_bit(bc); |
michael@0 | 1107 | |
michael@0 | 1108 | vpx_memset(xd->segment_feature_data, 0, sizeof(xd->segment_feature_data)); |
michael@0 | 1109 | |
michael@0 | 1110 | /* For each segmentation feature (Quant and loop filter level) */ |
michael@0 | 1111 | for (i = 0; i < MB_LVL_MAX; i++) |
michael@0 | 1112 | { |
michael@0 | 1113 | for (j = 0; j < MAX_MB_SEGMENTS; j++) |
michael@0 | 1114 | { |
michael@0 | 1115 | /* Frame level data */ |
michael@0 | 1116 | if (vp8_read_bit(bc)) |
michael@0 | 1117 | { |
michael@0 | 1118 | xd->segment_feature_data[i][j] = (signed char)vp8_read_literal(bc, mb_feature_data_bits[i]); |
michael@0 | 1119 | |
michael@0 | 1120 | if (vp8_read_bit(bc)) |
michael@0 | 1121 | xd->segment_feature_data[i][j] = -xd->segment_feature_data[i][j]; |
michael@0 | 1122 | } |
michael@0 | 1123 | else |
michael@0 | 1124 | xd->segment_feature_data[i][j] = 0; |
michael@0 | 1125 | } |
michael@0 | 1126 | } |
michael@0 | 1127 | } |
michael@0 | 1128 | |
michael@0 | 1129 | if (xd->update_mb_segmentation_map) |
michael@0 | 1130 | { |
michael@0 | 1131 | /* Which macro block level features are enabled */ |
michael@0 | 1132 | vpx_memset(xd->mb_segment_tree_probs, 255, sizeof(xd->mb_segment_tree_probs)); |
michael@0 | 1133 | |
michael@0 | 1134 | /* Read the probs used to decode the segment id for each macro block. */ |
michael@0 | 1135 | for (i = 0; i < MB_FEATURE_TREE_PROBS; i++) |
michael@0 | 1136 | { |
michael@0 | 1137 | /* If not explicitly set value is defaulted to 255 by memset above */ |
michael@0 | 1138 | if (vp8_read_bit(bc)) |
michael@0 | 1139 | xd->mb_segment_tree_probs[i] = (vp8_prob)vp8_read_literal(bc, 8); |
michael@0 | 1140 | } |
michael@0 | 1141 | } |
michael@0 | 1142 | } |
michael@0 | 1143 | else |
michael@0 | 1144 | { |
michael@0 | 1145 | /* No segmentation updates on this frame */ |
michael@0 | 1146 | xd->update_mb_segmentation_map = 0; |
michael@0 | 1147 | xd->update_mb_segmentation_data = 0; |
michael@0 | 1148 | } |
michael@0 | 1149 | |
michael@0 | 1150 | /* Read the loop filter level and type */ |
michael@0 | 1151 | pc->filter_type = (LOOPFILTERTYPE) vp8_read_bit(bc); |
michael@0 | 1152 | pc->filter_level = vp8_read_literal(bc, 6); |
michael@0 | 1153 | pc->sharpness_level = vp8_read_literal(bc, 3); |
michael@0 | 1154 | |
michael@0 | 1155 | /* Read in loop filter deltas applied at the MB level based on mode or ref frame. */ |
michael@0 | 1156 | xd->mode_ref_lf_delta_update = 0; |
michael@0 | 1157 | xd->mode_ref_lf_delta_enabled = (unsigned char)vp8_read_bit(bc); |
michael@0 | 1158 | |
michael@0 | 1159 | if (xd->mode_ref_lf_delta_enabled) |
michael@0 | 1160 | { |
michael@0 | 1161 | /* Do the deltas need to be updated */ |
michael@0 | 1162 | xd->mode_ref_lf_delta_update = (unsigned char)vp8_read_bit(bc); |
michael@0 | 1163 | |
michael@0 | 1164 | if (xd->mode_ref_lf_delta_update) |
michael@0 | 1165 | { |
michael@0 | 1166 | /* Send update */ |
michael@0 | 1167 | for (i = 0; i < MAX_REF_LF_DELTAS; i++) |
michael@0 | 1168 | { |
michael@0 | 1169 | if (vp8_read_bit(bc)) |
michael@0 | 1170 | { |
michael@0 | 1171 | /*sign = vp8_read_bit( bc );*/ |
michael@0 | 1172 | xd->ref_lf_deltas[i] = (signed char)vp8_read_literal(bc, 6); |
michael@0 | 1173 | |
michael@0 | 1174 | if (vp8_read_bit(bc)) /* Apply sign */ |
michael@0 | 1175 | xd->ref_lf_deltas[i] = xd->ref_lf_deltas[i] * -1; |
michael@0 | 1176 | } |
michael@0 | 1177 | } |
michael@0 | 1178 | |
michael@0 | 1179 | /* Send update */ |
michael@0 | 1180 | for (i = 0; i < MAX_MODE_LF_DELTAS; i++) |
michael@0 | 1181 | { |
michael@0 | 1182 | if (vp8_read_bit(bc)) |
michael@0 | 1183 | { |
michael@0 | 1184 | /*sign = vp8_read_bit( bc );*/ |
michael@0 | 1185 | xd->mode_lf_deltas[i] = (signed char)vp8_read_literal(bc, 6); |
michael@0 | 1186 | |
michael@0 | 1187 | if (vp8_read_bit(bc)) /* Apply sign */ |
michael@0 | 1188 | xd->mode_lf_deltas[i] = xd->mode_lf_deltas[i] * -1; |
michael@0 | 1189 | } |
michael@0 | 1190 | } |
michael@0 | 1191 | } |
michael@0 | 1192 | } |
michael@0 | 1193 | |
michael@0 | 1194 | setup_token_decoder(pbi, data + first_partition_length_in_bytes); |
michael@0 | 1195 | |
michael@0 | 1196 | xd->current_bc = &pbi->mbc[0]; |
michael@0 | 1197 | |
michael@0 | 1198 | /* Read the default quantizers. */ |
michael@0 | 1199 | { |
michael@0 | 1200 | int Q, q_update; |
michael@0 | 1201 | |
michael@0 | 1202 | Q = vp8_read_literal(bc, 7); /* AC 1st order Q = default */ |
michael@0 | 1203 | pc->base_qindex = Q; |
michael@0 | 1204 | q_update = 0; |
michael@0 | 1205 | pc->y1dc_delta_q = get_delta_q(bc, pc->y1dc_delta_q, &q_update); |
michael@0 | 1206 | pc->y2dc_delta_q = get_delta_q(bc, pc->y2dc_delta_q, &q_update); |
michael@0 | 1207 | pc->y2ac_delta_q = get_delta_q(bc, pc->y2ac_delta_q, &q_update); |
michael@0 | 1208 | pc->uvdc_delta_q = get_delta_q(bc, pc->uvdc_delta_q, &q_update); |
michael@0 | 1209 | pc->uvac_delta_q = get_delta_q(bc, pc->uvac_delta_q, &q_update); |
michael@0 | 1210 | |
michael@0 | 1211 | if (q_update) |
michael@0 | 1212 | vp8cx_init_de_quantizer(pbi); |
michael@0 | 1213 | |
michael@0 | 1214 | /* MB level dequantizer setup */ |
michael@0 | 1215 | vp8_mb_init_dequantizer(pbi, &pbi->mb); |
michael@0 | 1216 | } |
michael@0 | 1217 | |
michael@0 | 1218 | /* Determine if the golden frame or ARF buffer should be updated and how. |
michael@0 | 1219 | * For all non key frames the GF and ARF refresh flags and sign bias |
michael@0 | 1220 | * flags must be set explicitly. |
michael@0 | 1221 | */ |
michael@0 | 1222 | if (pc->frame_type != KEY_FRAME) |
michael@0 | 1223 | { |
michael@0 | 1224 | /* Should the GF or ARF be updated from the current frame */ |
michael@0 | 1225 | pc->refresh_golden_frame = vp8_read_bit(bc); |
michael@0 | 1226 | #if CONFIG_ERROR_CONCEALMENT |
michael@0 | 1227 | /* Assume we shouldn't refresh golden if the bit is missing */ |
michael@0 | 1228 | xd->corrupted |= vp8dx_bool_error(bc); |
michael@0 | 1229 | if (pbi->ec_active && xd->corrupted) |
michael@0 | 1230 | pc->refresh_golden_frame = 0; |
michael@0 | 1231 | #endif |
michael@0 | 1232 | |
michael@0 | 1233 | pc->refresh_alt_ref_frame = vp8_read_bit(bc); |
michael@0 | 1234 | #if CONFIG_ERROR_CONCEALMENT |
michael@0 | 1235 | /* Assume we shouldn't refresh altref if the bit is missing */ |
michael@0 | 1236 | xd->corrupted |= vp8dx_bool_error(bc); |
michael@0 | 1237 | if (pbi->ec_active && xd->corrupted) |
michael@0 | 1238 | pc->refresh_alt_ref_frame = 0; |
michael@0 | 1239 | #endif |
michael@0 | 1240 | |
michael@0 | 1241 | /* Buffer to buffer copy flags. */ |
michael@0 | 1242 | pc->copy_buffer_to_gf = 0; |
michael@0 | 1243 | |
michael@0 | 1244 | if (!pc->refresh_golden_frame) |
michael@0 | 1245 | pc->copy_buffer_to_gf = vp8_read_literal(bc, 2); |
michael@0 | 1246 | |
michael@0 | 1247 | #if CONFIG_ERROR_CONCEALMENT |
michael@0 | 1248 | /* Assume we shouldn't copy to the golden if the bit is missing */ |
michael@0 | 1249 | xd->corrupted |= vp8dx_bool_error(bc); |
michael@0 | 1250 | if (pbi->ec_active && xd->corrupted) |
michael@0 | 1251 | pc->copy_buffer_to_gf = 0; |
michael@0 | 1252 | #endif |
michael@0 | 1253 | |
michael@0 | 1254 | pc->copy_buffer_to_arf = 0; |
michael@0 | 1255 | |
michael@0 | 1256 | if (!pc->refresh_alt_ref_frame) |
michael@0 | 1257 | pc->copy_buffer_to_arf = vp8_read_literal(bc, 2); |
michael@0 | 1258 | |
michael@0 | 1259 | #if CONFIG_ERROR_CONCEALMENT |
michael@0 | 1260 | /* Assume we shouldn't copy to the alt-ref if the bit is missing */ |
michael@0 | 1261 | xd->corrupted |= vp8dx_bool_error(bc); |
michael@0 | 1262 | if (pbi->ec_active && xd->corrupted) |
michael@0 | 1263 | pc->copy_buffer_to_arf = 0; |
michael@0 | 1264 | #endif |
michael@0 | 1265 | |
michael@0 | 1266 | |
michael@0 | 1267 | pc->ref_frame_sign_bias[GOLDEN_FRAME] = vp8_read_bit(bc); |
michael@0 | 1268 | pc->ref_frame_sign_bias[ALTREF_FRAME] = vp8_read_bit(bc); |
michael@0 | 1269 | } |
michael@0 | 1270 | |
michael@0 | 1271 | pc->refresh_entropy_probs = vp8_read_bit(bc); |
michael@0 | 1272 | #if CONFIG_ERROR_CONCEALMENT |
michael@0 | 1273 | /* Assume we shouldn't refresh the probabilities if the bit is |
michael@0 | 1274 | * missing */ |
michael@0 | 1275 | xd->corrupted |= vp8dx_bool_error(bc); |
michael@0 | 1276 | if (pbi->ec_active && xd->corrupted) |
michael@0 | 1277 | pc->refresh_entropy_probs = 0; |
michael@0 | 1278 | #endif |
michael@0 | 1279 | if (pc->refresh_entropy_probs == 0) |
michael@0 | 1280 | { |
michael@0 | 1281 | vpx_memcpy(&pc->lfc, &pc->fc, sizeof(pc->fc)); |
michael@0 | 1282 | } |
michael@0 | 1283 | |
michael@0 | 1284 | pc->refresh_last_frame = pc->frame_type == KEY_FRAME || vp8_read_bit(bc); |
michael@0 | 1285 | |
michael@0 | 1286 | #if CONFIG_ERROR_CONCEALMENT |
michael@0 | 1287 | /* Assume we should refresh the last frame if the bit is missing */ |
michael@0 | 1288 | xd->corrupted |= vp8dx_bool_error(bc); |
michael@0 | 1289 | if (pbi->ec_active && xd->corrupted) |
michael@0 | 1290 | pc->refresh_last_frame = 1; |
michael@0 | 1291 | #endif |
michael@0 | 1292 | |
michael@0 | 1293 | if (0) |
michael@0 | 1294 | { |
michael@0 | 1295 | FILE *z = fopen("decodestats.stt", "a"); |
michael@0 | 1296 | fprintf(z, "%6d F:%d,G:%d,A:%d,L:%d,Q:%d\n", |
michael@0 | 1297 | pc->current_video_frame, |
michael@0 | 1298 | pc->frame_type, |
michael@0 | 1299 | pc->refresh_golden_frame, |
michael@0 | 1300 | pc->refresh_alt_ref_frame, |
michael@0 | 1301 | pc->refresh_last_frame, |
michael@0 | 1302 | pc->base_qindex); |
michael@0 | 1303 | fclose(z); |
michael@0 | 1304 | } |
michael@0 | 1305 | |
michael@0 | 1306 | { |
michael@0 | 1307 | pbi->independent_partitions = 1; |
michael@0 | 1308 | |
michael@0 | 1309 | /* read coef probability tree */ |
michael@0 | 1310 | for (i = 0; i < BLOCK_TYPES; i++) |
michael@0 | 1311 | for (j = 0; j < COEF_BANDS; j++) |
michael@0 | 1312 | for (k = 0; k < PREV_COEF_CONTEXTS; k++) |
michael@0 | 1313 | for (l = 0; l < ENTROPY_NODES; l++) |
michael@0 | 1314 | { |
michael@0 | 1315 | |
michael@0 | 1316 | vp8_prob *const p = pc->fc.coef_probs [i][j][k] + l; |
michael@0 | 1317 | |
michael@0 | 1318 | if (vp8_read(bc, vp8_coef_update_probs [i][j][k][l])) |
michael@0 | 1319 | { |
michael@0 | 1320 | *p = (vp8_prob)vp8_read_literal(bc, 8); |
michael@0 | 1321 | |
michael@0 | 1322 | } |
michael@0 | 1323 | if (k > 0 && *p != pc->fc.coef_probs[i][j][k-1][l]) |
michael@0 | 1324 | pbi->independent_partitions = 0; |
michael@0 | 1325 | |
michael@0 | 1326 | } |
michael@0 | 1327 | } |
michael@0 | 1328 | |
michael@0 | 1329 | /* clear out the coeff buffer */ |
michael@0 | 1330 | vpx_memset(xd->qcoeff, 0, sizeof(xd->qcoeff)); |
michael@0 | 1331 | |
michael@0 | 1332 | vp8_decode_mode_mvs(pbi); |
michael@0 | 1333 | |
michael@0 | 1334 | #if CONFIG_ERROR_CONCEALMENT |
michael@0 | 1335 | if (pbi->ec_active && |
michael@0 | 1336 | pbi->mvs_corrupt_from_mb < (unsigned int)pc->mb_cols * pc->mb_rows) |
michael@0 | 1337 | { |
michael@0 | 1338 | /* Motion vectors are missing in this frame. We will try to estimate |
michael@0 | 1339 | * them and then continue decoding the frame as usual */ |
michael@0 | 1340 | vp8_estimate_missing_mvs(pbi); |
michael@0 | 1341 | } |
michael@0 | 1342 | #endif |
michael@0 | 1343 | |
michael@0 | 1344 | vpx_memset(pc->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES) * pc->mb_cols); |
michael@0 | 1345 | pbi->frame_corrupt_residual = 0; |
michael@0 | 1346 | |
michael@0 | 1347 | #if CONFIG_MULTITHREAD |
michael@0 | 1348 | if (pbi->b_multithreaded_rd && pc->multi_token_partition != ONE_PARTITION) |
michael@0 | 1349 | { |
michael@0 | 1350 | unsigned int thread; |
michael@0 | 1351 | vp8mt_decode_mb_rows(pbi, xd); |
michael@0 | 1352 | vp8_yv12_extend_frame_borders(yv12_fb_new); |
michael@0 | 1353 | for (thread = 0; thread < pbi->decoding_thread_count; ++thread) |
michael@0 | 1354 | corrupt_tokens |= pbi->mb_row_di[thread].mbd.corrupted; |
michael@0 | 1355 | } |
michael@0 | 1356 | else |
michael@0 | 1357 | #endif |
michael@0 | 1358 | { |
michael@0 | 1359 | decode_mb_rows(pbi); |
michael@0 | 1360 | corrupt_tokens |= xd->corrupted; |
michael@0 | 1361 | } |
michael@0 | 1362 | |
michael@0 | 1363 | /* Collect information about decoder corruption. */ |
michael@0 | 1364 | /* 1. Check first boolean decoder for errors. */ |
michael@0 | 1365 | yv12_fb_new->corrupted = vp8dx_bool_error(bc); |
michael@0 | 1366 | /* 2. Check the macroblock information */ |
michael@0 | 1367 | yv12_fb_new->corrupted |= corrupt_tokens; |
michael@0 | 1368 | |
michael@0 | 1369 | if (!pbi->decoded_key_frame) |
michael@0 | 1370 | { |
michael@0 | 1371 | if (pc->frame_type == KEY_FRAME && |
michael@0 | 1372 | !yv12_fb_new->corrupted) |
michael@0 | 1373 | pbi->decoded_key_frame = 1; |
michael@0 | 1374 | else |
michael@0 | 1375 | vpx_internal_error(&pbi->common.error, VPX_CODEC_CORRUPT_FRAME, |
michael@0 | 1376 | "A stream must start with a complete key frame"); |
michael@0 | 1377 | } |
michael@0 | 1378 | |
michael@0 | 1379 | /* vpx_log("Decoder: Frame Decoded, Size Roughly:%d bytes \n",bc->pos+pbi->bc2.pos); */ |
michael@0 | 1380 | |
michael@0 | 1381 | if (pc->refresh_entropy_probs == 0) |
michael@0 | 1382 | { |
michael@0 | 1383 | vpx_memcpy(&pc->fc, &pc->lfc, sizeof(pc->fc)); |
michael@0 | 1384 | pbi->independent_partitions = prev_independent_partitions; |
michael@0 | 1385 | } |
michael@0 | 1386 | |
michael@0 | 1387 | #ifdef PACKET_TESTING |
michael@0 | 1388 | { |
michael@0 | 1389 | FILE *f = fopen("decompressor.VP8", "ab"); |
michael@0 | 1390 | unsigned int size = pbi->bc2.pos + pbi->bc.pos + 8; |
michael@0 | 1391 | fwrite((void *) &size, 4, 1, f); |
michael@0 | 1392 | fwrite((void *) pbi->Source, size, 1, f); |
michael@0 | 1393 | fclose(f); |
michael@0 | 1394 | } |
michael@0 | 1395 | #endif |
michael@0 | 1396 | |
michael@0 | 1397 | return 0; |
michael@0 | 1398 | } |