Home | History | Annotate | Download | only in decoder
      1 /******************************************************************************
      2  *
      3  * Copyright (C) 2015 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at:
      8  *
      9  * http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  *
     17  *****************************************************************************
     18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
     19 */
     20 #include <stdio.h>
     21 #include <string.h>
     22 
     23 #include "iv_datatypedef.h"
     24 #include "iv.h"
     25 
     26 #include "impeg2_buf_mgr.h"
     27 #include "impeg2_disp_mgr.h"
     28 #include "impeg2_defs.h"
     29 #include "impeg2_platform_macros.h"
     30 #include "impeg2_inter_pred.h"
     31 #include "impeg2_idct.h"
     32 #include "impeg2_globals.h"
     33 #include "impeg2_mem_func.h"
     34 #include "impeg2_format_conv.h"
     35 #include "impeg2_macros.h"
     36 
     37 #include "ivd.h"
     38 #include "impeg2d.h"
     39 #include "impeg2d_bitstream.h"
     40 #include "impeg2d_structs.h"
     41 #include "impeg2d_vld_tables.h"
     42 #include "impeg2d_vld.h"
     43 #include "impeg2d_pic_proc.h"
     44 #include "impeg2d_debug.h"
     45 #include "impeg2d_mc.h"
     46 
     47 #define BLK_SIZE 8
     48 #define LUMA_BLK_SIZE (2 * (BLK_SIZE))
     49 #define CHROMA_BLK_SIZE (BLK_SIZE)
     50 
     51 
     52 /*******************************************************************************
     53 *
     54 *  Function Name   : impeg2d_dec_p_mb_params
     55 *
     56 *  Description     : Decodes the parameters for P
     57 *
     58 *  Arguments       :
     59 *  dec             : Decoder context
     60 *
     61 *  Values Returned : None
     62 *******************************************************************************/
     63 WORD32  impeg2d_dec_p_mb_params(dec_state_t *ps_dec)
     64 {
     65     stream_t *ps_stream = &ps_dec->s_bit_stream;
     66     UWORD16 u2_mb_addr_incr;
     67     UWORD16 u2_total_len;
     68     UWORD16 u2_len;
     69     UWORD16 u2_mb_type;
     70     UWORD32 u4_next_word;
     71     const dec_mb_params_t *ps_dec_mb_params;
     72     if(impeg2d_bit_stream_nxt(ps_stream,1) == 1)
     73     {
     74         impeg2d_bit_stream_flush(ps_stream,1);
     75 
     76     }
     77     else
     78     {
     79         u2_mb_addr_incr = impeg2d_get_mb_addr_incr(ps_stream);
     80         if(0 == ps_dec->u2_first_mb)
     81         {
     82             /****************************************************************/
     83             /* If the 2nd member of a field picture pair is a P picture and */
     84             /* the first one was an I picture, there cannot be any skipped  */
     85             /* MBs in the second field picture                              */
     86             /****************************************************************/
     87             /*
     88             if((dec->picture_structure != FRAME_PICTURE) &&
     89                 (dec->f->FieldFuncCall != 0) &&
     90                 (dec->las->u1_last_coded_vop_type == I))
     91             {
     92                 core0_err_handler((void *)(VOLParams),
     93                     ITTMPEG2_ERR_INVALID_MB_SKIP);
     94             }
     95             */
     96             /****************************************************************/
     97             /* In MPEG-2, the last MB of the row cannot be skipped and the  */
     98             /* MBAddrIncr cannot be such that it will take the current MB   */
     99             /* beyond the current row                                       */
    100             /* In MPEG-1, the slice could start and end anywhere and is not */
    101             /* restricted to a row like in MPEG-2. Hence this check should  */
    102             /* not be done for MPEG-1 streams.                              */
    103             /****************************************************************/
    104             if(ps_dec->u2_is_mpeg2 && ((ps_dec->u2_mb_x + u2_mb_addr_incr) > ps_dec->u2_num_horiz_mb) )
    105             {
    106                 u2_mb_addr_incr    = ps_dec->u2_num_horiz_mb - ps_dec->u2_mb_x;
    107             }
    108 
    109             impeg2d_dec_skip_mbs(ps_dec, (UWORD16)(u2_mb_addr_incr - 1));
    110         }
    111 
    112     }
    113     u4_next_word = (UWORD16)impeg2d_bit_stream_nxt(ps_stream,16);
    114     /*-----------------------------------------------------------------------*/
    115     /* MB type                                                               */
    116     /*-----------------------------------------------------------------------*/
    117     {
    118         u2_mb_type   = ps_dec->pu2_mb_type[BITS((UWORD16)u4_next_word,15,10)];
    119         u2_len      = BITS(u2_mb_type,15,8);
    120         u2_total_len = u2_len;
    121         u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << u2_len);
    122     }
    123     /*-----------------------------------------------------------------------*/
    124     /* motion type                                                           */
    125     /*-----------------------------------------------------------------------*/
    126     {
    127         if((u2_mb_type & MB_FORW_OR_BACK) &&  ps_dec->u2_read_motion_type)
    128         {
    129             WORD32 i4_motion_type;
    130             ps_dec->u2_motion_type = BITS((UWORD16)u4_next_word,15,14);
    131             u2_total_len        += MB_MOTION_TYPE_LEN;
    132             u4_next_word        = (UWORD16)LSW((UWORD16)u4_next_word << MB_MOTION_TYPE_LEN);
    133             i4_motion_type     = ps_dec->u2_motion_type;
    134 
    135             if((i4_motion_type == 0) ||
    136                 (i4_motion_type == 4) ||
    137                 (i4_motion_type >  7))
    138             {
    139                 //TODO : VANG Check for validity
    140                 i4_motion_type = 1;
    141             }
    142 
    143         }
    144     }
    145     /*-----------------------------------------------------------------------*/
    146     /* dct type                                                              */
    147     /*-----------------------------------------------------------------------*/
    148     {
    149         if((u2_mb_type & MB_CODED) && ps_dec->u2_read_dct_type)
    150         {
    151             ps_dec->u2_field_dct = BIT((UWORD16)u4_next_word,15);
    152             u2_total_len += MB_DCT_TYPE_LEN;
    153             u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << MB_DCT_TYPE_LEN);
    154         }
    155     }
    156     /*-----------------------------------------------------------------------*/
    157     /* Quant scale code                                                      */
    158     /*-----------------------------------------------------------------------*/
    159     if(u2_mb_type & MB_QUANT)
    160     {
    161         UWORD16 u2_quant_scale_code;
    162         u2_quant_scale_code = BITS((UWORD16)u4_next_word,15,11);
    163 
    164         ps_dec->u1_quant_scale = (ps_dec->u2_q_scale_type) ?
    165             gau1_impeg2_non_linear_quant_scale[u2_quant_scale_code] : (u2_quant_scale_code << 1);
    166         u2_total_len += MB_QUANT_SCALE_CODE_LEN;
    167     }
    168     impeg2d_bit_stream_flush(ps_stream,u2_total_len);
    169     /*-----------------------------------------------------------------------*/
    170     /* Set the function pointers                                             */
    171     /*-----------------------------------------------------------------------*/
    172     ps_dec->u2_coded_mb    = (UWORD16)(u2_mb_type & MB_CODED);
    173 
    174     if(u2_mb_type & MB_FORW_OR_BACK)
    175     {
    176 
    177         UWORD16 refPic      = !(u2_mb_type & MB_MV_FORW);
    178         UWORD16 index       = (ps_dec->u2_motion_type);
    179         ps_dec->u2_prev_intra_mb    = 0;
    180         ps_dec->e_mb_pred         = (e_pred_direction_t)refPic;
    181         ps_dec_mb_params = &ps_dec->ps_func_forw_or_back[index];
    182         ps_dec->s_mb_type = ps_dec_mb_params->s_mb_type;
    183         if(NULL == ps_dec_mb_params->pf_func_mb_params)
    184             return -1;
    185         ps_dec_mb_params->pf_func_mb_params(ps_dec);
    186 
    187     }
    188     else if(u2_mb_type & MB_TYPE_INTRA)
    189     {
    190         ps_dec->u2_prev_intra_mb    = 1;
    191         impeg2d_dec_intra_mb(ps_dec);
    192 
    193     }
    194     else
    195     {
    196         ps_dec->u2_prev_intra_mb    = 0;
    197         ps_dec->e_mb_pred = FORW;
    198         ps_dec->u2_motion_type = 0;
    199         impeg2d_dec_0mv_coded_mb(ps_dec);
    200     }
    201 
    202     /*-----------------------------------------------------------------------*/
    203     /* decode cbp                                                            */
    204     /*-----------------------------------------------------------------------*/
    205     if((u2_mb_type & MB_TYPE_INTRA))
    206     {
    207         ps_dec->u2_cbp  = 0x3f;
    208         ps_dec->u2_prev_intra_mb    = 1;
    209     }
    210     else
    211     {
    212         ps_dec->u2_prev_intra_mb  = 0;
    213         ps_dec->u2_def_dc_pred[Y_LUMA] = 128 << ps_dec->u2_intra_dc_precision;
    214         ps_dec->u2_def_dc_pred[U_CHROMA] = 128 << ps_dec->u2_intra_dc_precision;
    215         ps_dec->u2_def_dc_pred[V_CHROMA] = 128 << ps_dec->u2_intra_dc_precision;
    216         if((ps_dec->u2_coded_mb))
    217         {
    218             UWORD16 cbpValue;
    219             cbpValue  = gau2_impeg2d_cbp_code[impeg2d_bit_stream_nxt(ps_stream,MB_CBP_LEN)];
    220             ps_dec->u2_cbp  = cbpValue & 0xFF;
    221             impeg2d_bit_stream_flush(ps_stream,(cbpValue >> 8) & 0x0FF);
    222         }
    223         else
    224         {
    225             ps_dec->u2_cbp  = 0;
    226         }
    227     }
    228     return 0;
    229 }
    230 
    231 
    232 /*******************************************************************************
    233 *
    234 *  Function Name   : impeg2d_dec_pnb_mb_params
    235 *
    236 *  Description     : Decodes the parameters for P and B pictures
    237 *
    238 *  Arguments       :
    239 *  dec             : Decoder context
    240 *
    241 *  Values Returned : None
    242 *******************************************************************************/
    243 WORD32 impeg2d_dec_pnb_mb_params(dec_state_t *ps_dec)
    244 {
    245     stream_t *ps_stream = &ps_dec->s_bit_stream;
    246     UWORD16 u2_mb_addr_incr;
    247     UWORD16 u2_total_len;
    248     UWORD16 u2_len;
    249     UWORD16 u2_mb_type;
    250     UWORD32 u4_next_word;
    251     const dec_mb_params_t *ps_dec_mb_params;
    252     if(impeg2d_bit_stream_nxt(ps_stream,1) == 1)
    253     {
    254         impeg2d_bit_stream_flush(ps_stream,1);
    255 
    256     }
    257     else
    258     {
    259         u2_mb_addr_incr = impeg2d_get_mb_addr_incr(ps_stream);
    260 
    261         if(ps_dec->u2_first_mb)
    262         {
    263             /****************************************************************/
    264             /* Section 6.3.17                                               */
    265             /* The first MB of a slice cannot be skipped                    */
    266             /* But the mb_addr_incr can be > 1, because at the beginning of */
    267             /* a slice, it indicates the offset from the last MB in the     */
    268             /* previous row. Hence for the first slice in a row, the        */
    269             /* mb_addr_incr needs to be 1.                                  */
    270             /****************************************************************/
    271             /* MB_x is set to zero whenever MB_y changes.                   */
    272             ps_dec->u2_mb_x = u2_mb_addr_incr - 1;
    273             /* For error resilience */
    274             ps_dec->u2_mb_x = MIN(ps_dec->u2_mb_x, (ps_dec->u2_num_horiz_mb - 1));
    275 
    276             /****************************************************************/
    277             /* mb_addr_incr is forced to 1 because in this decoder it is used */
    278             /* more as an indicator of the number of MBs skipped than the   */
    279             /* as defined by the standard (Section 6.3.17)                  */
    280             /****************************************************************/
    281             u2_mb_addr_incr = 1;
    282             ps_dec->u2_first_mb = 0;
    283         }
    284         else
    285         {
    286             /****************************************************************/
    287             /* In MPEG-2, the last MB of the row cannot be skipped and the  */
    288             /* mb_addr_incr cannot be such that it will take the current MB   */
    289             /* beyond the current row                                       */
    290             /* In MPEG-1, the slice could start and end anywhere and is not */
    291             /* restricted to a row like in MPEG-2. Hence this check should  */
    292             /* not be done for MPEG-1 streams.                              */
    293             /****************************************************************/
    294             if(ps_dec->u2_is_mpeg2 &&
    295                 ((ps_dec->u2_mb_x + u2_mb_addr_incr) > ps_dec->u2_num_horiz_mb))
    296             {
    297                 u2_mb_addr_incr    = ps_dec->u2_num_horiz_mb - ps_dec->u2_mb_x;
    298             }
    299 
    300 
    301             impeg2d_dec_skip_mbs(ps_dec, (UWORD16)(u2_mb_addr_incr - 1));
    302         }
    303 
    304     }
    305     u4_next_word = (UWORD16)impeg2d_bit_stream_nxt(ps_stream,16);
    306     /*-----------------------------------------------------------------------*/
    307     /* MB type                                                               */
    308     /*-----------------------------------------------------------------------*/
    309     {
    310         u2_mb_type   = ps_dec->pu2_mb_type[BITS((UWORD16)u4_next_word,15,10)];
    311         u2_len      = BITS(u2_mb_type,15,8);
    312         u2_total_len = u2_len;
    313         u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << u2_len);
    314     }
    315     /*-----------------------------------------------------------------------*/
    316     /* motion type                                                           */
    317     /*-----------------------------------------------------------------------*/
    318     {
    319         WORD32 i4_motion_type = ps_dec->u2_motion_type;
    320 
    321         if((u2_mb_type & MB_FORW_OR_BACK) &&  ps_dec->u2_read_motion_type)
    322         {
    323             ps_dec->u2_motion_type = BITS((UWORD16)u4_next_word,15,14);
    324             u2_total_len += MB_MOTION_TYPE_LEN;
    325             u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << MB_MOTION_TYPE_LEN);
    326             i4_motion_type     = ps_dec->u2_motion_type;
    327 
    328         }
    329 
    330 
    331         if ((u2_mb_type & MB_FORW_OR_BACK) &&
    332             ((i4_motion_type == 0) ||
    333             (i4_motion_type == 3) ||
    334             (i4_motion_type == 4) ||
    335             (i4_motion_type >= 7)))
    336         {
    337             //TODO: VANG Check for validity
    338             i4_motion_type = 1;
    339         }
    340 
    341     }
    342     /*-----------------------------------------------------------------------*/
    343     /* dct type                                                              */
    344     /*-----------------------------------------------------------------------*/
    345     {
    346         if((u2_mb_type & MB_CODED) && ps_dec->u2_read_dct_type)
    347         {
    348             ps_dec->u2_field_dct = BIT((UWORD16)u4_next_word,15);
    349             u2_total_len += MB_DCT_TYPE_LEN;
    350             u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << MB_DCT_TYPE_LEN);
    351         }
    352     }
    353     /*-----------------------------------------------------------------------*/
    354     /* Quant scale code                                                      */
    355     /*-----------------------------------------------------------------------*/
    356     if(u2_mb_type & MB_QUANT)
    357     {
    358         UWORD16 u2_quant_scale_code;
    359         u2_quant_scale_code = BITS((UWORD16)u4_next_word,15,11);
    360 
    361         ps_dec->u1_quant_scale = (ps_dec->u2_q_scale_type) ?
    362             gau1_impeg2_non_linear_quant_scale[u2_quant_scale_code] : (u2_quant_scale_code << 1);
    363         u2_total_len += MB_QUANT_SCALE_CODE_LEN;
    364     }
    365     impeg2d_bit_stream_flush(ps_stream,u2_total_len);
    366     /*-----------------------------------------------------------------------*/
    367     /* Set the function pointers                                             */
    368     /*-----------------------------------------------------------------------*/
    369     ps_dec->u2_coded_mb    = (UWORD16)(u2_mb_type & MB_CODED);
    370 
    371     if(u2_mb_type & MB_BIDRECT)
    372     {
    373         UWORD16 u2_index       = (ps_dec->u2_motion_type);
    374 
    375         ps_dec->u2_prev_intra_mb    = 0;
    376         ps_dec->e_mb_pred         = BIDIRECT;
    377         ps_dec_mb_params = &ps_dec->ps_func_bi_direct[u2_index];
    378         ps_dec->s_mb_type = ps_dec_mb_params->s_mb_type;
    379         if(NULL == ps_dec_mb_params->pf_func_mb_params)
    380             return -1;
    381         ps_dec_mb_params->pf_func_mb_params(ps_dec);
    382     }
    383     else if(u2_mb_type & MB_FORW_OR_BACK)
    384     {
    385 
    386         UWORD16 u2_refPic      = !(u2_mb_type & MB_MV_FORW);
    387         UWORD16 u2_index       = (ps_dec->u2_motion_type);
    388         ps_dec->u2_prev_intra_mb    = 0;
    389         ps_dec->e_mb_pred         = (e_pred_direction_t)u2_refPic;
    390         ps_dec_mb_params = &ps_dec->ps_func_forw_or_back[u2_index];
    391         ps_dec->s_mb_type = ps_dec_mb_params->s_mb_type;
    392         if(NULL == ps_dec_mb_params->pf_func_mb_params)
    393             return -1;
    394         ps_dec_mb_params->pf_func_mb_params(ps_dec);
    395 
    396     }
    397     else if(u2_mb_type & MB_TYPE_INTRA)
    398     {
    399         ps_dec->u2_prev_intra_mb    = 1;
    400         impeg2d_dec_intra_mb(ps_dec);
    401 
    402     }
    403     else
    404     {
    405         ps_dec->u2_prev_intra_mb =0;
    406         ps_dec->e_mb_pred = FORW;
    407         ps_dec->u2_motion_type = 0;
    408         impeg2d_dec_0mv_coded_mb(ps_dec);
    409     }
    410 
    411     /*-----------------------------------------------------------------------*/
    412     /* decode cbp                                                            */
    413     /*-----------------------------------------------------------------------*/
    414     if((u2_mb_type & MB_TYPE_INTRA))
    415     {
    416         ps_dec->u2_cbp  = 0x3f;
    417         ps_dec->u2_prev_intra_mb    = 1;
    418     }
    419     else
    420     {
    421         ps_dec->u2_prev_intra_mb  = 0;
    422         ps_dec->u2_def_dc_pred[Y_LUMA] = 128 << ps_dec->u2_intra_dc_precision;
    423         ps_dec->u2_def_dc_pred[U_CHROMA] = 128 << ps_dec->u2_intra_dc_precision;
    424         ps_dec->u2_def_dc_pred[V_CHROMA] = 128 << ps_dec->u2_intra_dc_precision;
    425         if((ps_dec->u2_coded_mb))
    426         {
    427             UWORD16 cbpValue;
    428             cbpValue  = gau2_impeg2d_cbp_code[impeg2d_bit_stream_nxt(ps_stream,MB_CBP_LEN)];
    429             ps_dec->u2_cbp  = cbpValue & 0xFF;
    430             impeg2d_bit_stream_flush(ps_stream,(cbpValue >> 8) & 0x0FF);
    431         }
    432         else
    433         {
    434             ps_dec->u2_cbp  = 0;
    435         }
    436     }
    437     return 0;
    438 }
    439 
    440 /*******************************************************************************
    441 *  Function Name   : impeg2d_dec_p_b_slice
    442 *
    443 *  Description     : Decodes P and B slices
    444 *
    445 *  Arguments       :
    446 *  dec             : Decoder state
    447 *
    448 *  Values Returned : None
    449 *******************************************************************************/
    450 IMPEG2D_ERROR_CODES_T impeg2d_dec_p_b_slice(dec_state_t *ps_dec)
    451 {
    452     WORD16 *pi2_vld_out;
    453     UWORD32 i;
    454     yuv_buf_t *ps_cur_frm_buf      = &ps_dec->s_cur_frm_buf;
    455 
    456     UWORD32 u4_frm_offset          = 0;
    457     const dec_mb_params_t *ps_dec_mb_params;
    458     IMPEG2D_ERROR_CODES_T e_error   = (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
    459 
    460     pi2_vld_out = ps_dec->ai2_vld_buf;
    461     memset(ps_dec->ai2_pred_mv,0,sizeof(ps_dec->ai2_pred_mv));
    462 
    463     ps_dec->u2_prev_intra_mb    = 0;
    464     ps_dec->u2_first_mb       = 1;
    465 
    466     ps_dec->u2_picture_width = ps_dec->u2_frame_width;
    467 
    468     if(ps_dec->u2_picture_structure != FRAME_PICTURE)
    469     {
    470         ps_dec->u2_picture_width <<= 1;
    471         if(ps_dec->u2_picture_structure == BOTTOM_FIELD)
    472         {
    473             u4_frm_offset = ps_dec->u2_frame_width;
    474         }
    475     }
    476 
    477     do
    478     {
    479         UWORD32 u4_x_offset, u4_y_offset;
    480         WORD32 ret;
    481 
    482 
    483         UWORD32 u4_x_dst_offset = 0;
    484         UWORD32 u4_y_dst_offset = 0;
    485         UWORD8  *pu1_out_p;
    486         UWORD8  *pu1_pred;
    487         WORD32 u4_pred_strd;
    488 
    489         IMPEG2D_TRACE_MB_START(ps_dec->u2_mb_x, ps_dec->u2_mb_y);
    490 
    491 
    492         if(ps_dec->e_pic_type == B_PIC)
    493             ret = impeg2d_dec_pnb_mb_params(ps_dec);
    494         else
    495             ret = impeg2d_dec_p_mb_params(ps_dec);
    496 
    497         if(ret)
    498             return IMPEG2D_MB_TEX_DECODE_ERR;
    499         IMPEG2D_TRACE_MB_START(ps_dec->u2_mb_x, ps_dec->u2_mb_y);
    500 
    501         u4_x_dst_offset = u4_frm_offset + (ps_dec->u2_mb_x << 4);
    502         u4_y_dst_offset = (ps_dec->u2_mb_y << 4) * ps_dec->u2_picture_width;
    503         pu1_out_p = ps_cur_frm_buf->pu1_y + u4_x_dst_offset + u4_y_dst_offset;
    504         if(ps_dec->u2_prev_intra_mb == 0)
    505         {
    506             UWORD32 offset_x, offset_y, stride;
    507             UWORD16 index = (ps_dec->u2_motion_type);
    508             /*only for non intra mb's*/
    509             if(ps_dec->e_mb_pred == BIDIRECT)
    510             {
    511                 ps_dec_mb_params = &ps_dec->ps_func_bi_direct[index];
    512             }
    513             else
    514             {
    515                 ps_dec_mb_params = &ps_dec->ps_func_forw_or_back[index];
    516             }
    517 
    518             stride = ps_dec->u2_picture_width;
    519 
    520             offset_x = u4_frm_offset + (ps_dec->u2_mb_x << 4);
    521 
    522             offset_y = (ps_dec->u2_mb_y << 4);
    523 
    524             ps_dec->s_dest_buf.pu1_y = ps_cur_frm_buf->pu1_y + offset_y * stride + offset_x;
    525 
    526             stride = stride >> 1;
    527 
    528             ps_dec->s_dest_buf.pu1_u = ps_cur_frm_buf->pu1_u + (offset_y >> 1) * stride
    529                             + (offset_x >> 1);
    530 
    531             ps_dec->s_dest_buf.pu1_v = ps_cur_frm_buf->pu1_v + (offset_y >> 1) * stride
    532                             + (offset_x >> 1);
    533 
    534             PROFILE_DISABLE_MC_IF0
    535             ps_dec_mb_params->pf_mc(ps_dec);
    536 
    537         }
    538         for(i = 0; i < NUM_LUMA_BLKS; ++i)
    539         {
    540             if((ps_dec->u2_cbp & (1 << (BLOCKS_IN_MB - 1 - i))) != 0)
    541             {
    542                 e_error = ps_dec->pf_vld_inv_quant(ps_dec, pi2_vld_out, ps_dec->pu1_inv_scan_matrix,
    543                               ps_dec->u2_prev_intra_mb, Y_LUMA, 0);
    544                 if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
    545                 {
    546                     return e_error;
    547                 }
    548 
    549                 u4_x_offset = gai2_impeg2_blk_x_off[i];
    550 
    551                 if(ps_dec->u2_field_dct == 0)
    552                     u4_y_offset = gai2_impeg2_blk_y_off_frm[i] ;
    553                 else
    554                     u4_y_offset = gai2_impeg2_blk_y_off_fld[i] ;
    555 
    556 
    557 
    558 
    559 
    560                 IMPEG2D_IDCT_INP_STATISTICS(pi2_vld_out, ps_dec->u4_non_zero_cols, ps_dec->u4_non_zero_rows);
    561 
    562                 PROFILE_DISABLE_IDCT_IF0
    563                 {
    564                     WORD32 idx;
    565                     if(1 == (ps_dec->u4_non_zero_cols | ps_dec->u4_non_zero_rows))
    566                         idx = 0;
    567                     else
    568                         idx = 1;
    569 
    570                     if(0 == ps_dec->u2_prev_intra_mb)
    571                     {
    572                         pu1_pred = pu1_out_p + u4_y_offset * ps_dec->u2_picture_width + u4_x_offset;
    573                         u4_pred_strd = ps_dec->u2_picture_width << ps_dec->u2_field_dct;
    574                     }
    575                     else
    576                     {
    577                         pu1_pred = (UWORD8 *)gau1_impeg2_zerobuf;
    578                         u4_pred_strd = 8;
    579                     }
    580 
    581                     ps_dec->pf_idct_recon[idx * 2 + ps_dec->i4_last_value_one](pi2_vld_out,
    582                                                             ps_dec->ai2_idct_stg1,
    583                                                             pu1_pred,
    584                                                             pu1_out_p + u4_y_offset * ps_dec->u2_picture_width + u4_x_offset,
    585                                                             8,
    586                                                             u4_pred_strd,
    587                                                             ps_dec->u2_picture_width << ps_dec->u2_field_dct,
    588                                                             ~ps_dec->u4_non_zero_cols, ~ps_dec->u4_non_zero_rows);
    589                 }
    590             }
    591 
    592         }
    593 
    594         /* For U and V blocks, divide the x and y offsets by 2. */
    595         u4_x_dst_offset >>= 1;
    596         u4_y_dst_offset >>= 2;
    597 
    598 
    599         /* In case of chrominance blocks the DCT will be frame DCT */
    600         /* i = 0, U component and i = 1 is V componet */
    601         if((ps_dec->u2_cbp & 0x02) != 0)
    602         {
    603             pu1_out_p = ps_cur_frm_buf->pu1_u + u4_x_dst_offset + u4_y_dst_offset;
    604             e_error = ps_dec->pf_vld_inv_quant(ps_dec, pi2_vld_out, ps_dec->pu1_inv_scan_matrix,
    605                           ps_dec->u2_prev_intra_mb, U_CHROMA, 0);
    606             if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
    607             {
    608                 return e_error;
    609             }
    610 
    611 
    612             IMPEG2D_IDCT_INP_STATISTICS(pi2_vld_out, ps_dec->u4_non_zero_cols, ps_dec->u4_non_zero_rows);
    613 
    614             PROFILE_DISABLE_IDCT_IF0
    615             {
    616                 WORD32 idx;
    617                 if(1 == (ps_dec->u4_non_zero_cols | ps_dec->u4_non_zero_rows))
    618                     idx = 0;
    619                 else
    620                     idx = 1;
    621 
    622                 if(0 == ps_dec->u2_prev_intra_mb)
    623                 {
    624                     pu1_pred = pu1_out_p;
    625                     u4_pred_strd = ps_dec->u2_picture_width >> 1;
    626                 }
    627                 else
    628                 {
    629                     pu1_pred = (UWORD8 *)gau1_impeg2_zerobuf;
    630                     u4_pred_strd = 8;
    631                 }
    632 
    633                 ps_dec->pf_idct_recon[idx * 2 + ps_dec->i4_last_value_one](pi2_vld_out,
    634                                                         ps_dec->ai2_idct_stg1,
    635                                                         pu1_pred,
    636                                                         pu1_out_p,
    637                                                         8,
    638                                                         u4_pred_strd,
    639                                                         ps_dec->u2_picture_width >> 1,
    640                                                         ~ps_dec->u4_non_zero_cols, ~ps_dec->u4_non_zero_rows);
    641 
    642             }
    643 
    644         }
    645 
    646 
    647         if((ps_dec->u2_cbp & 0x01) != 0)
    648         {
    649             pu1_out_p = ps_cur_frm_buf->pu1_v + u4_x_dst_offset + u4_y_dst_offset;
    650             e_error = ps_dec->pf_vld_inv_quant(ps_dec, pi2_vld_out, ps_dec->pu1_inv_scan_matrix,
    651                           ps_dec->u2_prev_intra_mb, V_CHROMA, 0);
    652             if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
    653             {
    654                 return e_error;
    655             }
    656 
    657 
    658             IMPEG2D_IDCT_INP_STATISTICS(pi2_vld_out, ps_dec->u4_non_zero_cols, ps_dec->u4_non_zero_rows);
    659 
    660             PROFILE_DISABLE_IDCT_IF0
    661             {
    662                 WORD32 idx;
    663                 if(1 == (ps_dec->u4_non_zero_cols | ps_dec->u4_non_zero_rows))
    664                     idx = 0;
    665                 else
    666                     idx = 1;
    667                 if(0 == ps_dec->u2_prev_intra_mb)
    668                 {
    669                     pu1_pred = pu1_out_p;
    670                     u4_pred_strd = ps_dec->u2_picture_width >> 1;
    671                 }
    672                 else
    673                 {
    674                     pu1_pred = (UWORD8 *)gau1_impeg2_zerobuf;
    675                     u4_pred_strd = 8;
    676                 }
    677 
    678                 ps_dec->pf_idct_recon[idx * 2 + ps_dec->i4_last_value_one](pi2_vld_out,
    679                                                         ps_dec->ai2_idct_stg1,
    680                                                         pu1_pred,
    681                                                         pu1_out_p,
    682                                                         8,
    683                                                         u4_pred_strd,
    684                                                         ps_dec->u2_picture_width >> 1,
    685                                                         ~ps_dec->u4_non_zero_cols, ~ps_dec->u4_non_zero_rows);
    686 
    687             }
    688         }
    689 
    690 
    691         ps_dec->u2_num_mbs_left--;
    692         ps_dec->u2_first_mb = 0;
    693         ps_dec->u2_mb_x++;
    694 
    695         if(ps_dec->s_bit_stream.u4_offset > ps_dec->s_bit_stream.u4_max_offset)
    696         {
    697             return IMPEG2D_BITSTREAM_BUFF_EXCEEDED_ERR;
    698         }
    699         else if (ps_dec->u2_mb_x == ps_dec->u2_num_horiz_mb)
    700         {
    701             ps_dec->u2_mb_x = 0;
    702             ps_dec->u2_mb_y++;
    703 
    704         }
    705     }
    706     while(ps_dec->u2_num_mbs_left != 0 && impeg2d_bit_stream_nxt(&ps_dec->s_bit_stream,23) != 0x0);
    707     return e_error;
    708 }
    709