918 lines · 31.8 KB · C
RawDownload
/* *  Copyright (c) 2010 The WebM project authors. All Rights Reserved. * *  Use of this source code is governed by a BSD-style license *  that can be found in the LICENSE file in the root of the source *  tree. An additional intellectual property rights grant can be found *  in the file PATENTS.  All contributing project authors may *  be found in the AUTHORS file in the root of the source tree. */  #include "vpx_config.h"#include "vpx_rtcd.h"#if !defined(WIN32) && CONFIG_OS_SUPPORT == 1# include <unistd.h>#endif#include "onyxd_int.h"#include "vpx_mem/vpx_mem.h"#include "vp8/common/threading.h" #include "vp8/common/loopfilter.h"#include "vp8/common/extend.h"#include "vpx_ports/vpx_timer.h"#include "detokenize.h"#include "vp8/common/reconintra4x4.h"#include "vp8/common/reconinter.h"#include "vp8/common/setupintrarecon.h"#if CONFIG_ERROR_CONCEALMENT#include "error_concealment.h"#endif #define CALLOC_ARRAY(p, n) CHECK_MEM_ERROR((p), vpx_calloc(sizeof(*(p)), (n)))#define CALLOC_ARRAY_ALIGNED(p, n, algn) do {                      \  CHECK_MEM_ERROR((p), vpx_memalign((algn), sizeof(*(p)) * (n)));  \  memset((p), 0, (n) * sizeof(*(p)));                              \} while (0)  extern void vp8_mb_init_dequantizer(VP8D_COMP *pbi, MACROBLOCKD *xd); static void setup_decoding_thread_data(VP8D_COMP *pbi, MACROBLOCKD *xd, MB_ROW_DEC *mbrd, int count){    VP8_COMMON *const pc = & pbi->common;    int i;     for (i = 0; i < count; i++)    {        MACROBLOCKD *mbd = &mbrd[i].mbd;        mbd->subpixel_predict        = xd->subpixel_predict;        mbd->subpixel_predict8x4     = xd->subpixel_predict8x4;        mbd->subpixel_predict8x8     = xd->subpixel_predict8x8;        mbd->subpixel_predict16x16   = xd->subpixel_predict16x16;         mbd->mode_info_context = pc->mi   + pc->mode_info_stride * (i + 1);        mbd->mode_info_stride  = pc->mode_info_stride;         mbd->frame_type = pc->frame_type;        mbd->pre = xd->pre;        mbd->dst = xd->dst;         mbd->segmentation_enabled    = xd->segmentation_enabled;        mbd->mb_segement_abs_delta     = xd->mb_segement_abs_delta;        vpx_memcpy(mbd->segment_feature_data, xd->segment_feature_data, sizeof(xd->segment_feature_data));         /*signed char ref_lf_deltas[MAX_REF_LF_DELTAS];*/        vpx_memcpy(mbd->ref_lf_deltas, xd->ref_lf_deltas, sizeof(xd->ref_lf_deltas));        /*signed char mode_lf_deltas[MAX_MODE_LF_DELTAS];*/        vpx_memcpy(mbd->mode_lf_deltas, xd->mode_lf_deltas, sizeof(xd->mode_lf_deltas));        /*unsigned char mode_ref_lf_delta_enabled;        unsigned char mode_ref_lf_delta_update;*/        mbd->mode_ref_lf_delta_enabled    = xd->mode_ref_lf_delta_enabled;        mbd->mode_ref_lf_delta_update    = xd->mode_ref_lf_delta_update;         mbd->current_bc = &pbi->mbc[0];         vpx_memcpy(mbd->dequant_y1_dc, xd->dequant_y1_dc, sizeof(xd->dequant_y1_dc));        vpx_memcpy(mbd->dequant_y1, xd->dequant_y1, sizeof(xd->dequant_y1));        vpx_memcpy(mbd->dequant_y2, xd->dequant_y2, sizeof(xd->dequant_y2));        vpx_memcpy(mbd->dequant_uv, xd->dequant_uv, sizeof(xd->dequant_uv));         mbd->fullpixel_mask = 0xffffffff;         if (pc->full_pixel)            mbd->fullpixel_mask = 0xfffffff8;     }     for (i = 0; i < pc->mb_rows; i++)        pbi->mt_current_mb_col[i] = -1;} static void mt_decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd,                                 unsigned int mb_idx){    MB_PREDICTION_MODE mode;    int i;#if CONFIG_ERROR_CONCEALMENT    int corruption_detected = 0;#endif     if (xd->mode_info_context->mbmi.mb_skip_coeff)    {        vp8_reset_mb_tokens_context(xd);    }    else if (!vp8dx_bool_error(xd->current_bc))    {        int eobtotal;        eobtotal = vp8_decode_mb_tokens(pbi, xd);         /* Special case:  Force the loopfilter to skip when eobtotal is zero */        xd->mode_info_context->mbmi.mb_skip_coeff = (eobtotal==0);    }     mode = xd->mode_info_context->mbmi.mode;     if (xd->segmentation_enabled)        vp8_mb_init_dequantizer(pbi, xd);  #if CONFIG_ERROR_CONCEALMENT     if(pbi->ec_active)    {        int throw_residual;        /* When we have independent partitions we can apply residual even         * though other partitions within the frame are corrupt.         */        throw_residual = (!pbi->independent_partitions &&                          pbi->frame_corrupt_residual);        throw_residual = (throw_residual || vp8dx_bool_error(xd->current_bc));         if ((mb_idx >= pbi->mvs_corrupt_from_mb || throw_residual))        {            /* MB with corrupt residuals or corrupt mode/motion vectors.             * Better to use the predictor as reconstruction.             */            pbi->frame_corrupt_residual = 1;            vpx_memset(xd->qcoeff, 0, sizeof(xd->qcoeff));            vp8_conceal_corrupt_mb(xd);              corruption_detected = 1;             /* force idct to be skipped for B_PRED and use the             * prediction only for reconstruction             * */            vpx_memset(xd->eobs, 0, 25);        }    }#endif     /* do prediction */    if (xd->mode_info_context->mbmi.ref_frame == INTRA_FRAME)    {        vp8_build_intra_predictors_mbuv_s(xd,                                          xd->recon_above[1],                                          xd->recon_above[2],                                          xd->recon_left[1],                                          xd->recon_left[2],                                          xd->recon_left_stride[1],                                          xd->dst.u_buffer, xd->dst.v_buffer,                                          xd->dst.uv_stride);         if (mode != B_PRED)        {            vp8_build_intra_predictors_mby_s(xd,                                                 xd->recon_above[0],                                                 xd->recon_left[0],                                                 xd->recon_left_stride[0],                                                 xd->dst.y_buffer,                                                 xd->dst.y_stride);        }        else        {            short *DQC = xd->dequant_y1;            int dst_stride = xd->dst.y_stride;             /* clear out residual eob info */            if(xd->mode_info_context->mbmi.mb_skip_coeff)                vpx_memset(xd->eobs, 0, 25);             intra_prediction_down_copy(xd, xd->recon_above[0] + 16);             for (i = 0; i < 16; i++)            {                BLOCKD *b = &xd->block[i];                unsigned char *dst = xd->dst.y_buffer + b->offset;                B_PREDICTION_MODE b_mode =                    xd->mode_info_context->bmi[i].as_mode;                unsigned char *Above;                unsigned char *yleft;                int left_stride;                unsigned char top_left;                 /*Caution: For some b_mode, it needs 8 pixels (4 above + 4 above-right).*/                if (i < 4 && pbi->common.filter_level)                    Above = xd->recon_above[0] + b->offset;                else                    Above = dst - dst_stride;                 if (i%4==0 && pbi->common.filter_level)                {                    yleft = xd->recon_left[0] + i;                    left_stride = 1;                }                else                {                    yleft = dst - 1;                    left_stride = dst_stride;                }                 if ((i==4 || i==8 || i==12) && pbi->common.filter_level)                    top_left = *(xd->recon_left[0] + i - 1);                else                    top_left = Above[-1];                 vp8_intra4x4_predict(Above, yleft, left_stride,                                     b_mode, dst, dst_stride, top_left);                 if (xd->eobs[i] )                {                    if (xd->eobs[i] > 1)                    {                        vp8_dequant_idct_add(b->qcoeff, DQC, dst, dst_stride);                    }                    else                    {                        vp8_dc_only_idct_add(b->qcoeff[0] * DQC[0],                                             dst, dst_stride, dst, dst_stride);                        ((int *)b->qcoeff)[0] = 0;                    }                }            }        }    }    else    {        vp8_build_inter_predictors_mb(xd);    }  #if CONFIG_ERROR_CONCEALMENT    if (corruption_detected)    {        return;    }#endif     if(!xd->mode_info_context->mbmi.mb_skip_coeff)    {        /* dequantization and idct */        if (mode != B_PRED)        {            short *DQC = xd->dequant_y1;             if (mode != SPLITMV)            {                BLOCKD *b = &xd->block[24];                 /* do 2nd order transform on the dc block */                if (xd->eobs[24] > 1)                {                    vp8_dequantize_b(b, xd->dequant_y2);                     vp8_short_inv_walsh4x4(&b->dqcoeff[0],                        xd->qcoeff);                    ((int *)b->qcoeff)[0] = 0;                    ((int *)b->qcoeff)[1] = 0;                    ((int *)b->qcoeff)[2] = 0;                    ((int *)b->qcoeff)[3] = 0;                    ((int *)b->qcoeff)[4] = 0;                    ((int *)b->qcoeff)[5] = 0;                    ((int *)b->qcoeff)[6] = 0;                    ((int *)b->qcoeff)[7] = 0;                }                else                {                    b->dqcoeff[0] = b->qcoeff[0] * xd->dequant_y2[0];                    vp8_short_inv_walsh4x4_1(&b->dqcoeff[0],                        xd->qcoeff);                    ((int *)b->qcoeff)[0] = 0;                }                 /* override the dc dequant constant in order to preserve the                 * dc components                 */                DQC = xd->dequant_y1_dc;            }             vp8_dequant_idct_add_y_block                            (xd->qcoeff, DQC,                             xd->dst.y_buffer,                             xd->dst.y_stride, xd->eobs);        }         vp8_dequant_idct_add_uv_block                        (xd->qcoeff+16*16, xd->dequant_uv,                         xd->dst.u_buffer, xd->dst.v_buffer,                         xd->dst.uv_stride, xd->eobs+16);    }} static void mt_decode_mb_rows(VP8D_COMP *pbi, MACROBLOCKD *xd, int start_mb_row){    volatile const int *last_row_current_mb_col;    volatile int *current_mb_col;    int mb_row;    VP8_COMMON *pc = &pbi->common;    const int nsync = pbi->sync_range;    const int first_row_no_sync_above = pc->mb_cols + nsync;    int num_part = 1 << pbi->common.multi_token_partition;    int last_mb_row = start_mb_row;     YV12_BUFFER_CONFIG *yv12_fb_new = pbi->dec_fb_ref[INTRA_FRAME];    YV12_BUFFER_CONFIG *yv12_fb_lst = pbi->dec_fb_ref[LAST_FRAME];     int recon_y_stride = yv12_fb_new->y_stride;    int recon_uv_stride = yv12_fb_new->uv_stride;     unsigned char *ref_buffer[MAX_REF_FRAMES][3];    unsigned char *dst_buffer[3];    int i;    int ref_fb_corrupted[MAX_REF_FRAMES];     ref_fb_corrupted[INTRA_FRAME] = 0;     for(i = 1; i < MAX_REF_FRAMES; i++)    {        YV12_BUFFER_CONFIG *this_fb = pbi->dec_fb_ref[i];         ref_buffer[i][0] = this_fb->y_buffer;        ref_buffer[i][1] = this_fb->u_buffer;        ref_buffer[i][2] = this_fb->v_buffer;         ref_fb_corrupted[i] = this_fb->corrupted;    }     dst_buffer[0] = yv12_fb_new->y_buffer;    dst_buffer[1] = yv12_fb_new->u_buffer;    dst_buffer[2] = yv12_fb_new->v_buffer;     xd->up_available = (start_mb_row != 0);     for (mb_row = start_mb_row; mb_row < pc->mb_rows; mb_row += (pbi->decoding_thread_count + 1))    {       int i;       int recon_yoffset, recon_uvoffset;       int mb_col;       int filter_level;       loop_filter_info_n *lfi_n = &pc->lf_info;        /* save last row processed by this thread */       last_mb_row = mb_row;       /* select bool coder for current partition */       xd->current_bc =  &pbi->mbc[mb_row%num_part];        if (mb_row > 0)           last_row_current_mb_col = &pbi->mt_current_mb_col[mb_row -1];       else           last_row_current_mb_col = &first_row_no_sync_above;        current_mb_col = &pbi->mt_current_mb_col[mb_row];        recon_yoffset = mb_row * recon_y_stride * 16;       recon_uvoffset = mb_row * recon_uv_stride * 8;        /* reset contexts */       xd->above_context = pc->above_context;       vpx_memset(xd->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES));        xd->left_available = 0;        xd->mb_to_top_edge = -((mb_row * 16)) << 3;       xd->mb_to_bottom_edge = ((pc->mb_rows - 1 - mb_row) * 16) << 3;        if (pbi->common.filter_level)       {          xd->recon_above[0] = pbi->mt_yabove_row[mb_row] + 0*16 +32;          xd->recon_above[1] = pbi->mt_uabove_row[mb_row] + 0*8 +16;          xd->recon_above[2] = pbi->mt_vabove_row[mb_row] + 0*8 +16;           xd->recon_left[0] = pbi->mt_yleft_col[mb_row];          xd->recon_left[1] = pbi->mt_uleft_col[mb_row];          xd->recon_left[2] = pbi->mt_vleft_col[mb_row];           /* TODO: move to outside row loop */          xd->recon_left_stride[0] = 1;          xd->recon_left_stride[1] = 1;       }       else       {          xd->recon_above[0] = dst_buffer[0] + recon_yoffset;          xd->recon_above[1] = dst_buffer[1] + recon_uvoffset;          xd->recon_above[2] = dst_buffer[2] + recon_uvoffset;           xd->recon_left[0] = xd->recon_above[0] - 1;          xd->recon_left[1] = xd->recon_above[1] - 1;          xd->recon_left[2] = xd->recon_above[2] - 1;           xd->recon_above[0] -= xd->dst.y_stride;          xd->recon_above[1] -= xd->dst.uv_stride;          xd->recon_above[2] -= xd->dst.uv_stride;           /* TODO: move to outside row loop */          xd->recon_left_stride[0] = xd->dst.y_stride;          xd->recon_left_stride[1] = xd->dst.uv_stride;           setup_intra_recon_left(xd->recon_left[0], xd->recon_left[1],                                 xd->recon_left[2], xd->dst.y_stride,                                 xd->dst.uv_stride);       }        for (mb_col = 0; mb_col < pc->mb_cols; mb_col++)       {           *current_mb_col = mb_col - 1;            if ((mb_col & (nsync - 1)) == 0)           {               while (mb_col > (*last_row_current_mb_col - nsync))               {                   x86_pause_hint();                   thread_sleep(0);               }           }            /* Distance of MB to the various image edges.            * These are specified to 8th pel as they are always            * compared to values that are in 1/8th pel units.            */           xd->mb_to_left_edge = -((mb_col * 16) << 3);           xd->mb_to_right_edge = ((pc->mb_cols - 1 - mb_col) * 16) << 3;     #if CONFIG_ERROR_CONCEALMENT           {               int corrupt_residual =                           (!pbi->independent_partitions &&                           pbi->frame_corrupt_residual) ||                           vp8dx_bool_error(xd->current_bc);               if (pbi->ec_active &&                   (xd->mode_info_context->mbmi.ref_frame ==                                                    INTRA_FRAME) &&                   corrupt_residual)               {                   /* We have an intra block with corrupt                    * coefficients, better to conceal with an inter                    * block.                    * Interpolate MVs from neighboring MBs                    *                    * Note that for the first mb with corrupt                    * residual in a frame, we might not discover                    * that before decoding the residual. That                    * happens after this check, and therefore no                    * inter concealment will be done.                    */                   vp8_interpolate_motion(xd,                                          mb_row, mb_col,                                          pc->mb_rows, pc->mb_cols,                                          pc->mode_info_stride);               }           }    #endif             xd->dst.y_buffer = dst_buffer[0] + recon_yoffset;           xd->dst.u_buffer = dst_buffer[1] + recon_uvoffset;           xd->dst.v_buffer = dst_buffer[2] + recon_uvoffset;            xd->pre.y_buffer = ref_buffer[xd->mode_info_context->mbmi.ref_frame][0] + recon_yoffset;           xd->pre.u_buffer = ref_buffer[xd->mode_info_context->mbmi.ref_frame][1] + recon_uvoffset;           xd->pre.v_buffer = ref_buffer[xd->mode_info_context->mbmi.ref_frame][2] + recon_uvoffset;            /* propagate errors from reference frames */           xd->corrupted |= ref_fb_corrupted[xd->mode_info_context->mbmi.ref_frame];            mt_decode_macroblock(pbi, xd, 0);            xd->left_available = 1;            /* check if the boolean decoder has suffered an error */           xd->corrupted |= vp8dx_bool_error(xd->current_bc);            xd->recon_above[0] += 16;           xd->recon_above[1] += 8;           xd->recon_above[2] += 8;            if (!pbi->common.filter_level)           {              xd->recon_left[0] += 16;              xd->recon_left[1] += 8;              xd->recon_left[2] += 8;           }            if (pbi->common.filter_level)           {               int skip_lf = (xd->mode_info_context->mbmi.mode != B_PRED &&                               xd->mode_info_context->mbmi.mode != SPLITMV &&                               xd->mode_info_context->mbmi.mb_skip_coeff);                const int mode_index = lfi_n->mode_lf_lut[xd->mode_info_context->mbmi.mode];               const int seg = xd->mode_info_context->mbmi.segment_id;

Lines 1–500 of 918.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t