decodframe.c 54.9 KB
Newer Older
#else
            for (j = 0; j < COEF_BANDS; j++)
#endif
                for (k = 0; k < PREV_COEF_CONTEXTS; k++)
                {
#if CONFIG_EXPANDED_COEF_CONTEXT
                    if (k >= 3 && ((i == 0 && j == 1) ||
                                   (i > 0 && j == 0)))
                        continue;
#endif
                    for (l = 0; l < ENTROPY_NODES; l++)
                    {

                        vp8_prob *const p = pc->fc.coef_probs_8x8 [i][j][k] + l;

                        if (vp8_read(bc, COEF_UPDATE_PROB_8X8))
                        {
#if CONFIG_NEWUPDATE
                            *p = read_prob_diff_update(bc, *p);
#else
                            *p = (vp8_prob)vp8_read_literal(bc, 8);
#endif
                        }
                    }
John Koleszar's avatar
John Koleszar committed
int vp8_decode_frame(VP8D_COMP *pbi)
{
    vp8_reader *const bc = & pbi->bc;
    VP8_COMMON *const pc = & pbi->common;
    MACROBLOCKD *const xd  = & pbi->mb;
    const unsigned char *data = (const unsigned char *)pbi->Source;
    const unsigned char *data_end = data + pbi->source_sz;
    ptrdiff_t first_partition_length_in_bytes = 0;
Yaowu Xu's avatar
Yaowu Xu committed

John Koleszar's avatar
John Koleszar committed
    int mb_row;
    int i, j;
    /* start with no corruption of current frame */
    xd->corrupted = 0;
    pc->yv12_fb[pc->new_fb_idx].corrupted = 0;

    if (data_end - data < 3)
John Koleszar's avatar
John Koleszar committed
    {
        vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
                           "Truncated packet");
        pc->last_frame_type = pc->frame_type;
        pc->frame_type = (FRAME_TYPE)(data[0] & 1);
        pc->version = (data[0] >> 1) & 7;
        pc->show_frame = (data[0] >> 4) & 1;
        first_partition_length_in_bytes =
            (data[0] | (data[1] << 8) | (data[2] << 16)) >> 5;
        if ((data + first_partition_length_in_bytes > data_end
            || data + first_partition_length_in_bytes < data))
            vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
                               "Truncated packet or corrupt partition 0 length");
        vp8_setup_version(pc);
        if (pc->frame_type == KEY_FRAME)
John Koleszar's avatar
John Koleszar committed
        {
            const int Width = pc->Width;
            const int Height = pc->Height;

            /* vet via sync code */
            /* When error concealment is enabled we should only check the sync
             * code if we have enough bits available
             */
            if (data + 3 < data_end)
John Koleszar's avatar
John Koleszar committed
            {
                if (data[0] != 0x9d || data[1] != 0x01 || data[2] != 0x2a)
                    vpx_internal_error(&pc->error, VPX_CODEC_UNSUP_BITSTREAM,
                                   "Invalid frame sync code");
            /* If error concealment is enabled we should only parse the new size
             * if we have enough data. Otherwise we will end up with the wrong
             * size.
             */
            if (data + 6 < data_end)
John Koleszar's avatar
John Koleszar committed
            {
                pc->Width = (data[3] | (data[4] << 8)) & 0x3fff;
                pc->horiz_scale = data[4] >> 6;
                pc->Height = (data[5] | (data[6] << 8)) & 0x3fff;
                pc->vert_scale = data[6] >> 6;
John Koleszar's avatar
John Koleszar committed
            }
            data += 7;

            if (Width != pc->Width  ||  Height != pc->Height)
            {
                if (pc->Width <= 0)
                {
                    pc->Width = Width;
                    vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
                                       "Invalid frame width");
                }

                if (pc->Height <= 0)
                {
                    pc->Height = Height;
                    vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
                                       "Invalid frame height");
                }
                if (vp8_alloc_frame_buffers(pc, pc->Width, pc->Height))
                    vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
                                       "Failed to allocate frame buffers");
            }
    if ((!pbi->decoded_key_frame && pc->frame_type != KEY_FRAME) ||
        pc->Width == 0 || pc->Height == 0)
John Koleszar's avatar
John Koleszar committed
    {
        return -1;
    }

    init_frame(pbi);

Johann's avatar
Johann committed
    if (vp8dx_start_decode(bc, data, data_end - data))
John Koleszar's avatar
John Koleszar committed
        vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
                           "Failed to allocate bool decoder 0");
    if (pc->frame_type == KEY_FRAME) {
        pc->clr_type    = (YUV_TYPE)vp8_read_bit(bc);
        pc->clamp_type  = (CLAMP_TYPE)vp8_read_bit(bc);
    }

    /* Is segmentation enabled */
John Koleszar's avatar
John Koleszar committed
    xd->segmentation_enabled = (unsigned char)vp8_read_bit(bc);
John Koleszar's avatar
John Koleszar committed
    if (xd->segmentation_enabled)
    {
Paul Wilkins's avatar
Paul Wilkins committed
        // Read whether or not the segmentation map is being explicitly
        // updated this frame.
John Koleszar's avatar
John Koleszar committed
        xd->update_mb_segmentation_map = (unsigned char)vp8_read_bit(bc);
Paul Wilkins's avatar
Paul Wilkins committed

        // If so what method will be used.
        if ( xd->update_mb_segmentation_map )
            pc->temporal_update = (unsigned char)vp8_read_bit(bc);
Paul Wilkins's avatar
Paul Wilkins committed

        // Is the segment data being updated
John Koleszar's avatar
John Koleszar committed
        xd->update_mb_segmentation_data = (unsigned char)vp8_read_bit(bc);

        if (xd->update_mb_segmentation_data)
        {
Paul Wilkins's avatar
Paul Wilkins committed
            xd->mb_segment_abs_delta = (unsigned char)vp8_read_bit(bc);
Paul Wilkins's avatar
Paul Wilkins committed
            clearall_segfeatures( xd );
            // For each segmentation...
            for (i = 0; i < MAX_MB_SEGMENTS; i++)
            {
                // For each of the segments features...
                for (j = 0; j < SEG_LVL_MAX; j++)
John Koleszar's avatar
John Koleszar committed
                {

#if CONFIG_FEATUREUPDATES
                    // feature updated?
                    if (vp8_read_bit(bc))
                    {
                        int active=1;

                        if ( segfeature_active( xd, i, j ))
                            active=vp8_read_bit(bc);

                        // Is the feature enabled
                        if (active)
                        {
                            // Update the feature data and mask
                            enable_segfeature(xd, i, j);

                            data = (signed char)vp8_read_literal(
                                                bc, seg_feature_data_bits(j));

                            // Is the segment data signed..
                            if ( is_segfeature_signed(j) )
                            {
                                if (vp8_read_bit(bc))
                                    data = - data;
                            }
                        }
                        else
                            data = 0;

                        set_segdata(xd, i, j, data);
                    }

#else
Paul Wilkins's avatar
Paul Wilkins committed
                    // Is the feature enabled
John Koleszar's avatar
John Koleszar committed
                    if (vp8_read_bit(bc))
                    {
Paul Wilkins's avatar
Paul Wilkins committed
                        // Update the feature data and mask
                        enable_segfeature(xd, i, j);
                        data = (signed char)vp8_read_literal(
                                            bc, seg_feature_data_bits(j));

Paul Wilkins's avatar
Paul Wilkins committed
                        // Is the segment data signed..
                        if ( is_segfeature_signed(j) )
Paul Wilkins's avatar
Paul Wilkins committed
                        {
                            if (vp8_read_bit(bc))
                                data = - data;
Paul Wilkins's avatar
Paul Wilkins committed
                        }
John Koleszar's avatar
John Koleszar committed
                    }
                    else
                        data = 0;

                    set_segdata(xd, i, j, data);
#endif
John Koleszar's avatar
John Koleszar committed
                }
            }
        }

        if (xd->update_mb_segmentation_map)
        {
            // Which macro block level features are enabled
            vpx_memset(xd->mb_segment_tree_probs, 255,
                       sizeof(xd->mb_segment_tree_probs));
            vpx_memset(pc->segment_pred_probs, 255,
                       sizeof(pc->segment_pred_probs));

            // Read the probs used to decode the segment id for each macro
            // block.
John Koleszar's avatar
John Koleszar committed
            for (i = 0; i < MB_FEATURE_TREE_PROBS; i++)
            {
                // If not explicitly set value is defaulted to 255 by
                //memset above
John Koleszar's avatar
John Koleszar committed
                if (vp8_read_bit(bc))
                    xd->mb_segment_tree_probs[i] =
                        (vp8_prob)vp8_read_literal(bc, 8);
John Koleszar's avatar
John Koleszar committed
            }
            // If predictive coding of segment map is enabled read the
            // prediction probabilities.
            if ( pc->temporal_update )
            {
                // Read the prediction probs needed to decode the segment id
                // when predictive coding enabled
                for (i = 0; i < PREDICTION_PROBS; i++)
                {
                    // If not explicitly set value is defaulted to 255 by
                    // memset above
                    if (vp8_read_bit(bc))
                        pc->segment_pred_probs[i] =
                            (vp8_prob)vp8_read_literal(bc, 8);
                }
            }
    // Read common prediction model status flag probability updates for the
    // reference frame
    if ( pc->frame_type == KEY_FRAME )
    {
        // Set the prediction probabilities to defaults
        pc->ref_pred_probs[0] = 120;
        pc->ref_pred_probs[1] = 80;
        pc->ref_pred_probs[2] = 40;
    }
    else
    {
        for (i = 0; i < PREDICTION_PROBS; i++)
        {
            if ( vp8_read_bit(bc) )
                pc->ref_pred_probs[i] = (vp8_prob)vp8_read_literal(bc, 8);
        }
    }

    /* Read the loop filter level and type */
    pc->txfm_mode = (TXFM_MODE) vp8_read_bit(bc);

John Koleszar's avatar
John Koleszar committed
    pc->filter_type = (LOOPFILTERTYPE) vp8_read_bit(bc);
    pc->filter_level = vp8_read_literal(bc, 6);
    pc->sharpness_level = vp8_read_literal(bc, 3);

    /* Read in loop filter deltas applied at the MB level based on mode or ref frame. */
John Koleszar's avatar
John Koleszar committed
    xd->mode_ref_lf_delta_update = 0;
    xd->mode_ref_lf_delta_enabled = (unsigned char)vp8_read_bit(bc);

    if (xd->mode_ref_lf_delta_enabled)
    {
        /* Do the deltas need to be updated */
John Koleszar's avatar
John Koleszar committed
        xd->mode_ref_lf_delta_update = (unsigned char)vp8_read_bit(bc);

        if (xd->mode_ref_lf_delta_update)
        {
            /* Send update */
John Koleszar's avatar
John Koleszar committed
            for (i = 0; i < MAX_REF_LF_DELTAS; i++)
            {
                if (vp8_read_bit(bc))
                {
                    /*sign = vp8_read_bit( bc );*/
John Koleszar's avatar
John Koleszar committed
                    xd->ref_lf_deltas[i] = (signed char)vp8_read_literal(bc, 6);

                    if (vp8_read_bit(bc))        /* Apply sign */
John Koleszar's avatar
John Koleszar committed
                        xd->ref_lf_deltas[i] = xd->ref_lf_deltas[i] * -1;
                }
            }

            /* Send update */
John Koleszar's avatar
John Koleszar committed
            for (i = 0; i < MAX_MODE_LF_DELTAS; i++)
            {
                if (vp8_read_bit(bc))
                {
                    /*sign = vp8_read_bit( bc );*/
John Koleszar's avatar
John Koleszar committed
                    xd->mode_lf_deltas[i] = (signed char)vp8_read_literal(bc, 6);

                    if (vp8_read_bit(bc))        /* Apply sign */
John Koleszar's avatar
John Koleszar committed
                        xd->mode_lf_deltas[i] = xd->mode_lf_deltas[i] * -1;
                }
            }
        }
    }

Paul Wilkins's avatar
Paul Wilkins committed
    setup_token_decoder(pbi, data + first_partition_length_in_bytes);

John Koleszar's avatar
John Koleszar committed
    xd->current_bc = &pbi->bc2;

    /* Read the default quantizers. */
John Koleszar's avatar
John Koleszar committed
    {
        int Q, q_update;

        Q = vp8_read_literal(bc, QINDEX_BITS);  /* AC 1st order Q = default */
John Koleszar's avatar
John Koleszar committed
        pc->base_qindex = Q;
        q_update = 0;
        pc->y1dc_delta_q = get_delta_q(bc, pc->y1dc_delta_q, &q_update);
        pc->y2dc_delta_q = get_delta_q(bc, pc->y2dc_delta_q, &q_update);
        pc->y2ac_delta_q = get_delta_q(bc, pc->y2ac_delta_q, &q_update);
        pc->uvdc_delta_q = get_delta_q(bc, pc->uvdc_delta_q, &q_update);
        pc->uvac_delta_q = get_delta_q(bc, pc->uvac_delta_q, &q_update);

        if (q_update)
            vp8cx_init_de_quantizer(pbi);

        /* MB level dequantizer setup */
John Koleszar's avatar
John Koleszar committed
        mb_init_dequantizer(pbi, &pbi->mb);
    }

    /* Determine if the golden frame or ARF buffer should be updated and how.
     * For all non key frames the GF and ARF refresh flags and sign bias
     * flags must be set explicitly.
     */
John Koleszar's avatar
John Koleszar committed
    if (pc->frame_type != KEY_FRAME)
    {
        /* Should the GF or ARF be updated from the current frame */
John Koleszar's avatar
John Koleszar committed
        pc->refresh_golden_frame = vp8_read_bit(bc);
        pc->refresh_alt_ref_frame = vp8_read_bit(bc);

        if(pc->refresh_alt_ref_frame)
            vpx_memcpy(&pc->fc, &pc->lfc_a, sizeof(pc->fc));
            vpx_memcpy( pc->fc.vp8_mode_contexts,
                        pc->fc.mode_context_a,
                        sizeof(pc->fc.vp8_mode_contexts));
            vpx_memcpy(&pc->fc, &pc->lfc, sizeof(pc->fc));
            vpx_memcpy( pc->fc.vp8_mode_contexts,
                        pc->fc.mode_context,
                        sizeof(pc->fc.vp8_mode_contexts));
        /* Buffer to buffer copy flags. */
John Koleszar's avatar
John Koleszar committed
        pc->copy_buffer_to_gf = 0;

        if (!pc->refresh_golden_frame)
            pc->copy_buffer_to_gf = vp8_read_literal(bc, 2);

        pc->copy_buffer_to_arf = 0;

        if (!pc->refresh_alt_ref_frame)
            pc->copy_buffer_to_arf = vp8_read_literal(bc, 2);

        pc->ref_frame_sign_bias[GOLDEN_FRAME] = vp8_read_bit(bc);
        pc->ref_frame_sign_bias[ALTREF_FRAME] = vp8_read_bit(bc);

#if CONFIG_HIGH_PRECISION_MV
        /* Is high precision mv allowed */
        xd->allow_high_precision_mv = (unsigned char)vp8_read_bit(bc);
#endif
#if CONFIG_ENHANCED_INTERP
        // Read the type of subpel filter to use
        pc->mcomp_filter_type = vp8_read_literal(bc, 2);
        /* To enable choice of different interploation filters */
        if (pc->mcomp_filter_type == SIXTAP)
        {
            xd->subpixel_predict      = SUBPIX_INVOKE(RTCD_VTABLE(subpix), sixtap4x4);
            xd->subpixel_predict8x4   = SUBPIX_INVOKE(RTCD_VTABLE(subpix), sixtap8x4);
            xd->subpixel_predict8x8   = SUBPIX_INVOKE(RTCD_VTABLE(subpix), sixtap8x8);
            xd->subpixel_predict16x16 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), sixtap16x16);
            xd->subpixel_predict_avg  = SUBPIX_INVOKE(RTCD_VTABLE(subpix), sixtap_avg4x4);
            xd->subpixel_predict_avg8x8 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), sixtap_avg8x8);
            xd->subpixel_predict_avg16x16 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), sixtap_avg16x16);
        }
        else if (pc->mcomp_filter_type == EIGHTTAP)
        {
            xd->subpixel_predict      = SUBPIX_INVOKE(RTCD_VTABLE(subpix), eighttap4x4);
            xd->subpixel_predict8x4   = SUBPIX_INVOKE(RTCD_VTABLE(subpix), eighttap8x4);
            xd->subpixel_predict8x8   = SUBPIX_INVOKE(RTCD_VTABLE(subpix), eighttap8x8);
            xd->subpixel_predict16x16 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), eighttap16x16);
            xd->subpixel_predict_avg  = SUBPIX_INVOKE(RTCD_VTABLE(subpix), eighttap_avg4x4);
            xd->subpixel_predict_avg8x8 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), eighttap_avg8x8);
            xd->subpixel_predict_avg16x16 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), eighttap_avg16x16);
        }
        else if (pc->mcomp_filter_type == EIGHTTAP_SHARP)
        {
            xd->subpixel_predict      = SUBPIX_INVOKE(RTCD_VTABLE(subpix), eighttap4x4_sharp);
            xd->subpixel_predict8x4   = SUBPIX_INVOKE(RTCD_VTABLE(subpix), eighttap8x4_sharp);
            xd->subpixel_predict8x8   = SUBPIX_INVOKE(RTCD_VTABLE(subpix), eighttap8x8_sharp);
            xd->subpixel_predict16x16 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), eighttap16x16_sharp);
            xd->subpixel_predict_avg  = SUBPIX_INVOKE(RTCD_VTABLE(subpix), eighttap_avg4x4_sharp);
            xd->subpixel_predict_avg8x8 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), eighttap_avg8x8_sharp);
            xd->subpixel_predict_avg16x16 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), eighttap_avg16x16_sharp);
        }
        else
        {
            xd->subpixel_predict      = SUBPIX_INVOKE(RTCD_VTABLE(subpix), bilinear4x4);
            xd->subpixel_predict8x4   = SUBPIX_INVOKE(RTCD_VTABLE(subpix), bilinear8x4);
            xd->subpixel_predict8x8   = SUBPIX_INVOKE(RTCD_VTABLE(subpix), bilinear8x8);
            xd->subpixel_predict16x16 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), bilinear16x16);
            xd->subpixel_predict_avg  = SUBPIX_INVOKE(RTCD_VTABLE(subpix), bilinear_avg4x4);
            xd->subpixel_predict_avg8x8 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), bilinear_avg8x8);
            xd->subpixel_predict_avg16x16 = SUBPIX_INVOKE(RTCD_VTABLE(subpix), bilinear_avg16x16);
        }
John Koleszar's avatar
John Koleszar committed
    }

    pc->refresh_entropy_probs = vp8_read_bit(bc);
    if (pc->refresh_entropy_probs == 0)
    {
        vpx_memcpy(&pc->lfc, &pc->fc, sizeof(pc->fc));
    }

    pc->refresh_last_frame = pc->frame_type == KEY_FRAME  ||  vp8_read_bit(bc);

    if (0)
    {
        FILE *z = fopen("decodestats.stt", "a");
        fprintf(z, "%6d F:%d,G:%d,A:%d,L:%d,Q:%d\n",
                pc->current_video_frame,
                pc->frame_type,
                pc->refresh_golden_frame,
                pc->refresh_alt_ref_frame,
                pc->refresh_last_frame,
                pc->base_qindex);
        fclose(z);
    }

#if CONFIG_ADAPTIVE_ENTROPY
    vp8_copy(pbi->common.fc.pre_coef_probs, pbi->common.fc.coef_probs);
    vp8_copy(pbi->common.fc.pre_coef_probs_8x8, pbi->common.fc.coef_probs_8x8);
    vp8_copy(pbi->common.fc.pre_ymode_prob, pbi->common.fc.ymode_prob);
    vp8_copy(pbi->common.fc.pre_uv_mode_prob, pbi->common.fc.uv_mode_prob);
    vp8_copy(pbi->common.fc.pre_bmode_prob, pbi->common.fc.bmode_prob);
    vp8_copy(pbi->common.fc.pre_i8x8_mode_prob, pbi->common.fc.i8x8_mode_prob);
    vp8_copy(pbi->common.fc.pre_sub_mv_ref_prob, pbi->common.fc.sub_mv_ref_prob);
    vp8_copy(pbi->common.fc.pre_mbsplit_prob, pbi->common.fc.mbsplit_prob);
    vp8_copy(pbi->common.fc.pre_mvc, pbi->common.fc.mvc);
#if CONFIG_HIGH_PRECISION_MV
    vp8_copy(pbi->common.fc.pre_mvc_hp, pbi->common.fc.mvc_hp);
#endif
    vp8_zero(pbi->common.fc.coef_counts);
    vp8_zero(pbi->common.fc.coef_counts_8x8);
    vp8_zero(pbi->common.fc.ymode_counts);
    vp8_zero(pbi->common.fc.uv_mode_counts);
    vp8_zero(pbi->common.fc.bmode_counts);
    vp8_zero(pbi->common.fc.i8x8_mode_counts);
    vp8_zero(pbi->common.fc.sub_mv_ref_counts);
    vp8_zero(pbi->common.fc.mbsplit_counts);
    vp8_zero(pbi->common.fc.MVcount);
#if CONFIG_HIGH_PRECISION_MV
    vp8_zero(pbi->common.fc.MVcount_hp);
#endif
    vp8_zero(pbi->common.fc.mv_ref_ct);
    vp8_zero(pbi->common.fc.mv_ref_ct_a);
#endif  /* CONFIG_ADAPTIVE_ENTROPY */
#if CONFIG_NEWUPDATE && COEFUPDATETYPE == 2
    read_coef_probs2(pbi);
#elif CONFIG_NEWUPDATE && COEFUPDATETYPE == 3
    read_coef_probs3(pbi);
#else
    read_coef_probs(pbi);
#endif
Yaowu Xu's avatar
Yaowu Xu committed

    vpx_memcpy(&xd->pre, &pc->yv12_fb[pc->lst_fb_idx], sizeof(YV12_BUFFER_CONFIG));
    vpx_memcpy(&xd->dst, &pc->yv12_fb[pc->new_fb_idx], sizeof(YV12_BUFFER_CONFIG));
    // Create the segmentation map structure and set to 0
    if (!pc->last_frame_seg_map)
       CHECK_MEM_ERROR(pc->last_frame_seg_map,
                       vpx_calloc((pc->mb_rows * pc->mb_cols), 1));
    /* set up frame new frame for intra coded blocks */
Paul Wilkins's avatar
Paul Wilkins committed
    vp8_setup_intra_recon(&pc->yv12_fb[pc->new_fb_idx]);
John Koleszar's avatar
John Koleszar committed

    vp8_setup_block_dptrs(xd);

    vp8_build_block_doffsets(xd);

    /* clear out the coeff buffer */
John Koleszar's avatar
John Koleszar committed
    vpx_memset(xd->qcoeff, 0, sizeof(xd->qcoeff));

    /* Read the mb_no_coeff_skip flag */
John Koleszar's avatar
John Koleszar committed
    pc->mb_no_coeff_skip = (int)vp8_read_bit(bc);

    vp8_decode_mode_mvs(pbi);
#if CONFIG_ADAPTIVE_ENTROPY == 0
    if (pc->frame_type != KEY_FRAME)
Yaowu Xu's avatar
Yaowu Xu committed
    {
        vp8_update_mode_context(&pbi->common);
    }
    vpx_memset(pc->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES) * pc->mb_cols);
    // Resset the macroblock mode info context to the start of the list
    xd->mode_info_context = pc->mi;

Adrian Grange's avatar
Adrian Grange committed
    /* Decode a row of superblocks */
    for (mb_row = 0; mb_row < pc->mb_rows; mb_row+=2)
Paul Wilkins's avatar
Paul Wilkins committed
    {
Adrian Grange's avatar
Adrian Grange committed
        decode_sb_row(pbi, pc, mb_row, xd);
John Koleszar's avatar
John Koleszar committed
    }
Paul Wilkins's avatar
Paul Wilkins committed
    corrupt_tokens |= xd->corrupted;
    /* Collect information about decoder corruption. */
    /* 1. Check first boolean decoder for errors. */
    pc->yv12_fb[pc->new_fb_idx].corrupted = vp8dx_bool_error(bc);
    /* 2. Check the macroblock information */
    pc->yv12_fb[pc->new_fb_idx].corrupted |= corrupt_tokens;

    if (!pbi->decoded_key_frame)
    {
        if (pc->frame_type == KEY_FRAME &&
            !pc->yv12_fb[pc->new_fb_idx].corrupted)
            pbi->decoded_key_frame = 1;
        else
            vpx_internal_error(&pbi->common.error, VPX_CODEC_CORRUPT_FRAME,
                               "A stream must start with a complete key frame");
    }
    /* vpx_log("Decoder: Frame Decoded, Size Roughly:%d bytes  \n",bc->pos+pbi->bc2.pos); */
#if CONFIG_ADAPTIVE_ENTROPY
    vp8_adapt_coef_probs(pc);
    if (pc->frame_type != KEY_FRAME)
    {
        vp8_adapt_mode_probs(pc);
        vp8_adapt_mv_probs(pc);
        vp8_update_mode_context(&pbi->common);
    /* If this was a kf or Gf note the Q used */
    if ((pc->frame_type == KEY_FRAME) ||
         pc->refresh_golden_frame || pc->refresh_alt_ref_frame)
    {
John Koleszar's avatar
John Koleszar committed
        pc->last_kf_gf_q = pc->base_qindex;
    if(pc->refresh_entropy_probs)
    {
        if(pc->refresh_alt_ref_frame)
            vpx_memcpy(&pc->lfc_a, &pc->fc, sizeof(pc->fc));
        else
            vpx_memcpy(&pc->lfc, &pc->fc, sizeof(pc->fc));
    }
John Koleszar's avatar
John Koleszar committed

#ifdef PACKET_TESTING
    {
        FILE *f = fopen("decompressor.VP8", "ab");
        unsigned int size = pbi->bc2.pos + pbi->bc.pos + 8;
        fwrite((void *) &size, 4, 1, f);
        fwrite((void *) pbi->Source, size, 1, f);
        fclose(f);
    }
#endif
    //printf("Frame %d Done\n", frame_count++);
John Koleszar's avatar
John Koleszar committed

    return 0;
}