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             if ((u2_mb_addr_incr - 1) > ps_dec->u2_num_mbs_left)
    110             {
    111                 /* If the number of skip MBs are more than the number of MBs
    112                  * left, indicate error.
    113                  */
    114                 return IV_FAIL;
    115             }
    116 
    117             impeg2d_dec_skip_mbs(ps_dec, (UWORD16)(u2_mb_addr_incr - 1));
    118         }
    119 
    120     }
    121     u4_next_word = (UWORD16)impeg2d_bit_stream_nxt(ps_stream,16);
    122     /*-----------------------------------------------------------------------*/
    123     /* MB type                                                               */
    124     /*-----------------------------------------------------------------------*/
    125     {
    126         u2_mb_type   = ps_dec->pu2_mb_type[BITS((UWORD16)u4_next_word,15,10)];
    127         u2_len      = BITS(u2_mb_type,15,8);
    128         u2_total_len = u2_len;
    129         u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << u2_len);
    130     }
    131     /*-----------------------------------------------------------------------*/
    132     /* motion type                                                           */
    133     /*-----------------------------------------------------------------------*/
    134     {
    135         if((u2_mb_type & MB_FORW_OR_BACK) &&  ps_dec->u2_read_motion_type)
    136         {
    137             WORD32 i4_motion_type;
    138             ps_dec->u2_motion_type = BITS((UWORD16)u4_next_word,15,14);
    139             u2_total_len        += MB_MOTION_TYPE_LEN;
    140             u4_next_word        = (UWORD16)LSW((UWORD16)u4_next_word << MB_MOTION_TYPE_LEN);
    141             i4_motion_type     = ps_dec->u2_motion_type;
    142 
    143             if((i4_motion_type == 0) ||
    144                 (i4_motion_type == 4) ||
    145                 (i4_motion_type >  7))
    146             {
    147                 //TODO : VANG Check for validity
    148                 i4_motion_type = 1;
    149             }
    150 
    151         }
    152     }
    153     /*-----------------------------------------------------------------------*/
    154     /* dct type                                                              */
    155     /*-----------------------------------------------------------------------*/
    156     {
    157         if((u2_mb_type & MB_CODED) && ps_dec->u2_read_dct_type)
    158         {
    159             ps_dec->u2_field_dct = BIT((UWORD16)u4_next_word,15);
    160             u2_total_len += MB_DCT_TYPE_LEN;
    161             u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << MB_DCT_TYPE_LEN);
    162         }
    163     }
    164     /*-----------------------------------------------------------------------*/
    165     /* Quant scale code                                                      */
    166     /*-----------------------------------------------------------------------*/
    167     if(u2_mb_type & MB_QUANT)
    168     {
    169         UWORD16 u2_quant_scale_code;
    170         u2_quant_scale_code = BITS((UWORD16)u4_next_word,15,11);
    171 
    172         ps_dec->u1_quant_scale = (ps_dec->u2_q_scale_type) ?
    173             gau1_impeg2_non_linear_quant_scale[u2_quant_scale_code] : (u2_quant_scale_code << 1);
    174         u2_total_len += MB_QUANT_SCALE_CODE_LEN;
    175     }
    176     impeg2d_bit_stream_flush(ps_stream,u2_total_len);
    177     /*-----------------------------------------------------------------------*/
    178     /* Set the function pointers                                             */
    179     /*-----------------------------------------------------------------------*/
    180     ps_dec->u2_coded_mb    = (UWORD16)(u2_mb_type & MB_CODED);
    181 
    182     if(u2_mb_type & MB_FORW_OR_BACK)
    183     {
    184 
    185         UWORD16 refPic      = !(u2_mb_type & MB_MV_FORW);
    186         UWORD16 index       = (ps_dec->u2_motion_type);
    187         ps_dec->u2_prev_intra_mb    = 0;
    188         ps_dec->e_mb_pred         = (e_pred_direction_t)refPic;
    189         ps_dec_mb_params = &ps_dec->ps_func_forw_or_back[index];
    190         ps_dec->s_mb_type = ps_dec_mb_params->s_mb_type;
    191         if(NULL == ps_dec_mb_params->pf_func_mb_params)
    192             return -1;
    193         ps_dec_mb_params->pf_func_mb_params(ps_dec);
    194 
    195     }
    196     else if(u2_mb_type & MB_TYPE_INTRA)
    197     {
    198         ps_dec->u2_prev_intra_mb    = 1;
    199         impeg2d_dec_intra_mb(ps_dec);
    200 
    201     }
    202     else
    203     {
    204         ps_dec->u2_prev_intra_mb    = 0;
    205         ps_dec->e_mb_pred = FORW;
    206         ps_dec->u2_motion_type = 0;
    207         impeg2d_dec_0mv_coded_mb(ps_dec);
    208     }
    209 
    210     /*-----------------------------------------------------------------------*/
    211     /* decode cbp                                                            */
    212     /*-----------------------------------------------------------------------*/
    213     if((u2_mb_type & MB_TYPE_INTRA))
    214     {
    215         ps_dec->u2_cbp  = 0x3f;
    216         ps_dec->u2_prev_intra_mb    = 1;
    217     }
    218     else
    219     {
    220         ps_dec->u2_prev_intra_mb  = 0;
    221         ps_dec->u2_def_dc_pred[Y_LUMA] = 128 << ps_dec->u2_intra_dc_precision;
    222         ps_dec->u2_def_dc_pred[U_CHROMA] = 128 << ps_dec->u2_intra_dc_precision;
    223         ps_dec->u2_def_dc_pred[V_CHROMA] = 128 << ps_dec->u2_intra_dc_precision;
    224         if((ps_dec->u2_coded_mb))
    225         {
    226             UWORD16 cbpValue;
    227             cbpValue  = gau2_impeg2d_cbp_code[impeg2d_bit_stream_nxt(ps_stream,MB_CBP_LEN)];
    228             ps_dec->u2_cbp  = cbpValue & 0xFF;
    229             impeg2d_bit_stream_flush(ps_stream,(cbpValue >> 8) & 0x0FF);
    230         }
    231         else
    232         {
    233             ps_dec->u2_cbp  = 0;
    234         }
    235     }
    236     return 0;
    237 }
    238 
    239 
    240 /*******************************************************************************
    241 *
    242 *  Function Name   : impeg2d_dec_pnb_mb_params
    243 *
    244 *  Description     : Decodes the parameters for P and B pictures
    245 *
    246 *  Arguments       :
    247 *  dec             : Decoder context
    248 *
    249 *  Values Returned : None
    250 *******************************************************************************/
    251 WORD32 impeg2d_dec_pnb_mb_params(dec_state_t *ps_dec)
    252 {
    253     stream_t *ps_stream = &ps_dec->s_bit_stream;
    254     UWORD16 u2_mb_addr_incr;
    255     UWORD16 u2_total_len;
    256     UWORD16 u2_len;
    257     UWORD16 u2_mb_type;
    258     UWORD32 u4_next_word;
    259     const dec_mb_params_t *ps_dec_mb_params;
    260     if(impeg2d_bit_stream_nxt(ps_stream,1) == 1)
    261     {
    262         impeg2d_bit_stream_flush(ps_stream,1);
    263 
    264     }
    265     else
    266     {
    267         u2_mb_addr_incr = impeg2d_get_mb_addr_incr(ps_stream);
    268 
    269         if(ps_dec->u2_first_mb)
    270         {
    271             /****************************************************************/
    272             /* Section 6.3.17                                               */
    273             /* The first MB of a slice cannot be skipped                    */
    274             /* But the mb_addr_incr can be > 1, because at the beginning of */
    275             /* a slice, it indicates the offset from the last MB in the     */
    276             /* previous row. Hence for the first slice in a row, the        */
    277             /* mb_addr_incr needs to be 1.                                  */
    278             /****************************************************************/
    279             /* MB_x is set to zero whenever MB_y changes.                   */
    280             ps_dec->u2_mb_x = u2_mb_addr_incr - 1;
    281             /* For error resilience */
    282             ps_dec->u2_mb_x = MIN(ps_dec->u2_mb_x, (ps_dec->u2_num_horiz_mb - 1));
    283 
    284             /****************************************************************/
    285             /* mb_addr_incr is forced to 1 because in this decoder it is used */
    286             /* more as an indicator of the number of MBs skipped than the   */
    287             /* as defined by the standard (Section 6.3.17)                  */
    288             /****************************************************************/
    289             u2_mb_addr_incr = 1;
    290             ps_dec->u2_first_mb = 0;
    291         }
    292         else
    293         {
    294             /****************************************************************/
    295             /* In MPEG-2, the last MB of the row cannot be skipped and the  */
    296             /* mb_addr_incr cannot be such that it will take the current MB   */
    297             /* beyond the current row                                       */
    298             /* In MPEG-1, the slice could start and end anywhere and is not */
    299             /* restricted to a row like in MPEG-2. Hence this check should  */
    300             /* not be done for MPEG-1 streams.                              */
    301             /****************************************************************/
    302             if(ps_dec->u2_is_mpeg2 &&
    303                 ((ps_dec->u2_mb_x + u2_mb_addr_incr) > ps_dec->u2_num_horiz_mb))
    304             {
    305                 u2_mb_addr_incr    = ps_dec->u2_num_horiz_mb - ps_dec->u2_mb_x;
    306             }
    307 
    308             if ((u2_mb_addr_incr - 1) > ps_dec->u2_num_mbs_left)
    309             {
    310                 /* If the number of skip MBs are more than the number of MBs
    311                  * left, indicate error.
    312                  */
    313                 return IV_FAIL;
    314             }
    315 
    316             impeg2d_dec_skip_mbs(ps_dec, (UWORD16)(u2_mb_addr_incr - 1));
    317         }
    318 
    319     }
    320     u4_next_word = (UWORD16)impeg2d_bit_stream_nxt(ps_stream,16);
    321     /*-----------------------------------------------------------------------*/
    322     /* MB type                                                               */
    323     /*-----------------------------------------------------------------------*/
    324     {
    325         u2_mb_type   = ps_dec->pu2_mb_type[BITS((UWORD16)u4_next_word,15,10)];
    326         u2_len      = BITS(u2_mb_type,15,8);
    327         u2_total_len = u2_len;
    328         u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << u2_len);
    329     }
    330     /*-----------------------------------------------------------------------*/
    331     /* motion type                                                           */
    332     /*-----------------------------------------------------------------------*/
    333     {
    334         WORD32 i4_motion_type = ps_dec->u2_motion_type;
    335 
    336         if((u2_mb_type & MB_FORW_OR_BACK) &&  ps_dec->u2_read_motion_type)
    337         {
    338             ps_dec->u2_motion_type = BITS((UWORD16)u4_next_word,15,14);
    339             u2_total_len += MB_MOTION_TYPE_LEN;
    340             u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << MB_MOTION_TYPE_LEN);
    341             i4_motion_type     = ps_dec->u2_motion_type;
    342 
    343         }
    344 
    345 
    346         if ((u2_mb_type & MB_FORW_OR_BACK) &&
    347             ((i4_motion_type == 0) ||
    348             (i4_motion_type == 3) ||
    349             (i4_motion_type == 4) ||
    350             (i4_motion_type >= 7)))
    351         {
    352             //TODO: VANG Check for validity
    353             i4_motion_type = 1;
    354         }
    355 
    356     }
    357     /*-----------------------------------------------------------------------*/
    358     /* dct type                                                              */
    359     /*-----------------------------------------------------------------------*/
    360     {
    361         if((u2_mb_type & MB_CODED) && ps_dec->u2_read_dct_type)
    362         {
    363             ps_dec->u2_field_dct = BIT((UWORD16)u4_next_word,15);
    364             u2_total_len += MB_DCT_TYPE_LEN;
    365             u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << MB_DCT_TYPE_LEN);
    366         }
    367     }
    368     /*-----------------------------------------------------------------------*/
    369     /* Quant scale code                                                      */
    370     /*-----------------------------------------------------------------------*/
    371     if(u2_mb_type & MB_QUANT)
    372     {
    373         UWORD16 u2_quant_scale_code;
    374         u2_quant_scale_code = BITS((UWORD16)u4_next_word,15,11);
    375 
    376         ps_dec->u1_quant_scale = (ps_dec->u2_q_scale_type) ?
    377             gau1_impeg2_non_linear_quant_scale[u2_quant_scale_code] : (u2_quant_scale_code << 1);
    378         u2_total_len += MB_QUANT_SCALE_CODE_LEN;
    379     }
    380     impeg2d_bit_stream_flush(ps_stream,u2_total_len);
    381     /*-----------------------------------------------------------------------*/
    382     /* Set the function pointers                                             */
    383     /*-----------------------------------------------------------------------*/
    384     ps_dec->u2_coded_mb    = (UWORD16)(u2_mb_type & MB_CODED);
    385 
    386     if(u2_mb_type & MB_BIDRECT)
    387     {
    388         UWORD16 u2_index       = (ps_dec->u2_motion_type);
    389 
    390         ps_dec->u2_prev_intra_mb    = 0;
    391         ps_dec->e_mb_pred         = BIDIRECT;
    392         ps_dec_mb_params = &ps_dec->ps_func_bi_direct[u2_index];
    393         ps_dec->s_mb_type = ps_dec_mb_params->s_mb_type;
    394         if(NULL == ps_dec_mb_params->pf_func_mb_params)
    395             return -1;
    396         ps_dec_mb_params->pf_func_mb_params(ps_dec);
    397     }
    398     else if(u2_mb_type & MB_FORW_OR_BACK)
    399     {
    400 
    401         UWORD16 u2_refPic      = !(u2_mb_type & MB_MV_FORW);
    402         UWORD16 u2_index       = (ps_dec->u2_motion_type);
    403         ps_dec->u2_prev_intra_mb    = 0;
    404         ps_dec->e_mb_pred         = (e_pred_direction_t)u2_refPic;
    405         ps_dec_mb_params = &ps_dec->ps_func_forw_or_back[u2_index];
    406         ps_dec->s_mb_type = ps_dec_mb_params->s_mb_type;
    407         if(NULL == ps_dec_mb_params->pf_func_mb_params)
    408             return -1;
    409         ps_dec_mb_params->pf_func_mb_params(ps_dec);
    410 
    411     }
    412     else if(u2_mb_type & MB_TYPE_INTRA)
    413     {
    414         ps_dec->u2_prev_intra_mb    = 1;
    415         impeg2d_dec_intra_mb(ps_dec);
    416 
    417     }
    418     else
    419     {
    420         ps_dec->u2_prev_intra_mb =0;
    421         ps_dec->e_mb_pred = FORW;
    422         ps_dec->u2_motion_type = 0;
    423         impeg2d_dec_0mv_coded_mb(ps_dec);
    424     }
    425 
    426     /*-----------------------------------------------------------------------*/
    427     /* decode cbp                                                            */
    428     /*-----------------------------------------------------------------------*/
    429     if((u2_mb_type & MB_TYPE_INTRA))
    430     {
    431         ps_dec->u2_cbp  = 0x3f;
    432         ps_dec->u2_prev_intra_mb    = 1;
    433     }
    434     else
    435     {
    436         ps_dec->u2_prev_intra_mb  = 0;
    437         ps_dec->u2_def_dc_pred[Y_LUMA] = 128 << ps_dec->u2_intra_dc_precision;
    438         ps_dec->u2_def_dc_pred[U_CHROMA] = 128 << ps_dec->u2_intra_dc_precision;
    439         ps_dec->u2_def_dc_pred[V_CHROMA] = 128 << ps_dec->u2_intra_dc_precision;
    440         if((ps_dec->u2_coded_mb))
    441         {
    442             UWORD16 cbpValue;
    443             cbpValue  = gau2_impeg2d_cbp_code[impeg2d_bit_stream_nxt(ps_stream,MB_CBP_LEN)];
    444             ps_dec->u2_cbp  = cbpValue & 0xFF;
    445             impeg2d_bit_stream_flush(ps_stream,(cbpValue >> 8) & 0x0FF);
    446         }
    447         else
    448         {
    449             ps_dec->u2_cbp  = 0;
    450         }
    451     }
    452     return 0;
    453 }
    454 
    455 /*******************************************************************************
    456 *  Function Name   : impeg2d_dec_p_b_slice
    457 *
    458 *  Description     : Decodes P and B slices
    459 *
    460 *  Arguments       :
    461 *  dec             : Decoder state
    462 *
    463 *  Values Returned : None
    464 *******************************************************************************/
    465 IMPEG2D_ERROR_CODES_T impeg2d_dec_p_b_slice(dec_state_t *ps_dec)
    466 {
    467     WORD16 *pi2_vld_out;
    468     UWORD32 i;
    469     yuv_buf_t *ps_cur_frm_buf      = &ps_dec->s_cur_frm_buf;
    470 
    471     UWORD32 u4_frm_offset          = 0;
    472     const dec_mb_params_t *ps_dec_mb_params;
    473     IMPEG2D_ERROR_CODES_T e_error   = (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
    474 
    475     pi2_vld_out = ps_dec->ai2_vld_buf;
    476     memset(ps_dec->ai2_pred_mv,0,sizeof(ps_dec->ai2_pred_mv));
    477 
    478     ps_dec->u2_prev_intra_mb    = 0;
    479     ps_dec->u2_first_mb       = 1;
    480 
    481     ps_dec->u2_picture_width = ps_dec->u2_frame_width;
    482 
    483     if(ps_dec->u2_picture_structure != FRAME_PICTURE)
    484     {
    485         ps_dec->u2_picture_width <<= 1;
    486         if(ps_dec->u2_picture_structure == BOTTOM_FIELD)
    487         {
    488             u4_frm_offset = ps_dec->u2_frame_width;
    489         }
    490     }
    491 
    492     do
    493     {
    494         UWORD32 u4_x_offset, u4_y_offset;
    495         WORD32 ret;
    496 
    497 
    498         UWORD32 u4_x_dst_offset = 0;
    499         UWORD32 u4_y_dst_offset = 0;
    500         UWORD8  *pu1_out_p;
    501         UWORD8  *pu1_pred;
    502         WORD32 u4_pred_strd;
    503 
    504         IMPEG2D_TRACE_MB_START(ps_dec->u2_mb_x, ps_dec->u2_mb_y);
    505 
    506         if(ps_dec->e_pic_type == B_PIC)
    507             ret = impeg2d_dec_pnb_mb_params(ps_dec);
    508         else
    509             ret = impeg2d_dec_p_mb_params(ps_dec);
    510 
    511         if(ret)
    512             return IMPEG2D_MB_TEX_DECODE_ERR;
    513         IMPEG2D_TRACE_MB_START(ps_dec->u2_mb_x, ps_dec->u2_mb_y);
    514 
    515         u4_x_dst_offset = u4_frm_offset + (ps_dec->u2_mb_x << 4);
    516         u4_y_dst_offset = (ps_dec->u2_mb_y << 4) * ps_dec->u2_picture_width;
    517         pu1_out_p = ps_cur_frm_buf->pu1_y + u4_x_dst_offset + u4_y_dst_offset;
    518         if(ps_dec->u2_prev_intra_mb == 0)
    519         {
    520             UWORD32 offset_x, offset_y, stride;
    521             UWORD16 index = (ps_dec->u2_motion_type);
    522             /*only for non intra mb's*/
    523             if(ps_dec->e_mb_pred == BIDIRECT)
    524             {
    525                 ps_dec_mb_params = &ps_dec->ps_func_bi_direct[index];
    526             }
    527             else
    528             {
    529                 ps_dec_mb_params = &ps_dec->ps_func_forw_or_back[index];
    530             }
    531 
    532             stride = ps_dec->u2_picture_width;
    533 
    534             offset_x = u4_frm_offset + (ps_dec->u2_mb_x << 4);
    535 
    536             offset_y = (ps_dec->u2_mb_y << 4);
    537 
    538             ps_dec->s_dest_buf.pu1_y = ps_cur_frm_buf->pu1_y + offset_y * stride + offset_x;
    539 
    540             stride = stride >> 1;
    541 
    542             ps_dec->s_dest_buf.pu1_u = ps_cur_frm_buf->pu1_u + (offset_y >> 1) * stride
    543                             + (offset_x >> 1);
    544 
    545             ps_dec->s_dest_buf.pu1_v = ps_cur_frm_buf->pu1_v + (offset_y >> 1) * stride
    546                             + (offset_x >> 1);
    547 
    548             PROFILE_DISABLE_MC_IF0
    549             ps_dec_mb_params->pf_mc(ps_dec);
    550 
    551         }
    552         for(i = 0; i < NUM_LUMA_BLKS; ++i)
    553         {
    554             if((ps_dec->u2_cbp & (1 << (BLOCKS_IN_MB - 1 - i))) != 0)
    555             {
    556                 e_error = ps_dec->pf_vld_inv_quant(ps_dec, pi2_vld_out, ps_dec->pu1_inv_scan_matrix,
    557                               ps_dec->u2_prev_intra_mb, Y_LUMA, 0);
    558                 if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
    559                 {
    560                     return e_error;
    561                 }
    562 
    563                 u4_x_offset = gai2_impeg2_blk_x_off[i];
    564 
    565                 if(ps_dec->u2_field_dct == 0)
    566                     u4_y_offset = gai2_impeg2_blk_y_off_frm[i] ;
    567                 else
    568                     u4_y_offset = gai2_impeg2_blk_y_off_fld[i] ;
    569 
    570 
    571 
    572 
    573 
    574                 IMPEG2D_IDCT_INP_STATISTICS(pi2_vld_out, ps_dec->u4_non_zero_cols, ps_dec->u4_non_zero_rows);
    575 
    576                 PROFILE_DISABLE_IDCT_IF0
    577                 {
    578                     WORD32 idx;
    579                     if(1 == (ps_dec->u4_non_zero_cols | ps_dec->u4_non_zero_rows))
    580                         idx = 0;
    581                     else
    582                         idx = 1;
    583 
    584                     if(0 == ps_dec->u2_prev_intra_mb)
    585                     {
    586                         pu1_pred = pu1_out_p + u4_y_offset * ps_dec->u2_picture_width + u4_x_offset;
    587                         u4_pred_strd = ps_dec->u2_picture_width << ps_dec->u2_field_dct;
    588                     }
    589                     else
    590                     {
    591                         pu1_pred = (UWORD8 *)gau1_impeg2_zerobuf;
    592                         u4_pred_strd = 8;
    593                     }
    594 
    595                     ps_dec->pf_idct_recon[idx * 2 + ps_dec->i4_last_value_one](pi2_vld_out,
    596                                                             ps_dec->ai2_idct_stg1,
    597                                                             pu1_pred,
    598                                                             pu1_out_p + u4_y_offset * ps_dec->u2_picture_width + u4_x_offset,
    599                                                             8,
    600                                                             u4_pred_strd,
    601                                                             ps_dec->u2_picture_width << ps_dec->u2_field_dct,
    602                                                             ~ps_dec->u4_non_zero_cols, ~ps_dec->u4_non_zero_rows);
    603                 }
    604             }
    605 
    606         }
    607 
    608         /* For U and V blocks, divide the x and y offsets by 2. */
    609         u4_x_dst_offset >>= 1;
    610         u4_y_dst_offset >>= 2;
    611 
    612 
    613         /* In case of chrominance blocks the DCT will be frame DCT */
    614         /* i = 0, U component and i = 1 is V componet */
    615         if((ps_dec->u2_cbp & 0x02) != 0)
    616         {
    617             pu1_out_p = ps_cur_frm_buf->pu1_u + u4_x_dst_offset + u4_y_dst_offset;
    618             e_error = ps_dec->pf_vld_inv_quant(ps_dec, pi2_vld_out, ps_dec->pu1_inv_scan_matrix,
    619                           ps_dec->u2_prev_intra_mb, U_CHROMA, 0);
    620             if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
    621             {
    622                 return e_error;
    623             }
    624 
    625 
    626             IMPEG2D_IDCT_INP_STATISTICS(pi2_vld_out, ps_dec->u4_non_zero_cols, ps_dec->u4_non_zero_rows);
    627 
    628             PROFILE_DISABLE_IDCT_IF0
    629             {
    630                 WORD32 idx;
    631                 if(1 == (ps_dec->u4_non_zero_cols | ps_dec->u4_non_zero_rows))
    632                     idx = 0;
    633                 else
    634                     idx = 1;
    635 
    636                 if(0 == ps_dec->u2_prev_intra_mb)
    637                 {
    638                     pu1_pred = pu1_out_p;
    639                     u4_pred_strd = ps_dec->u2_picture_width >> 1;
    640                 }
    641                 else
    642                 {
    643                     pu1_pred = (UWORD8 *)gau1_impeg2_zerobuf;
    644                     u4_pred_strd = 8;
    645                 }
    646 
    647                 ps_dec->pf_idct_recon[idx * 2 + ps_dec->i4_last_value_one](pi2_vld_out,
    648                                                         ps_dec->ai2_idct_stg1,
    649                                                         pu1_pred,
    650                                                         pu1_out_p,
    651                                                         8,
    652                                                         u4_pred_strd,
    653                                                         ps_dec->u2_picture_width >> 1,
    654                                                         ~ps_dec->u4_non_zero_cols, ~ps_dec->u4_non_zero_rows);
    655 
    656             }
    657 
    658         }
    659 
    660 
    661         if((ps_dec->u2_cbp & 0x01) != 0)
    662         {
    663             pu1_out_p = ps_cur_frm_buf->pu1_v + u4_x_dst_offset + u4_y_dst_offset;
    664             e_error = ps_dec->pf_vld_inv_quant(ps_dec, pi2_vld_out, ps_dec->pu1_inv_scan_matrix,
    665                           ps_dec->u2_prev_intra_mb, V_CHROMA, 0);
    666             if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
    667             {
    668                 return e_error;
    669             }
    670 
    671 
    672             IMPEG2D_IDCT_INP_STATISTICS(pi2_vld_out, ps_dec->u4_non_zero_cols, ps_dec->u4_non_zero_rows);
    673 
    674             PROFILE_DISABLE_IDCT_IF0
    675             {
    676                 WORD32 idx;
    677                 if(1 == (ps_dec->u4_non_zero_cols | ps_dec->u4_non_zero_rows))
    678                     idx = 0;
    679                 else
    680                     idx = 1;
    681                 if(0 == ps_dec->u2_prev_intra_mb)
    682                 {
    683                     pu1_pred = pu1_out_p;
    684                     u4_pred_strd = ps_dec->u2_picture_width >> 1;
    685                 }
    686                 else
    687                 {
    688                     pu1_pred = (UWORD8 *)gau1_impeg2_zerobuf;
    689                     u4_pred_strd = 8;
    690                 }
    691 
    692                 ps_dec->pf_idct_recon[idx * 2 + ps_dec->i4_last_value_one](pi2_vld_out,
    693                                                         ps_dec->ai2_idct_stg1,
    694                                                         pu1_pred,
    695                                                         pu1_out_p,
    696                                                         8,
    697                                                         u4_pred_strd,
    698                                                         ps_dec->u2_picture_width >> 1,
    699                                                         ~ps_dec->u4_non_zero_cols, ~ps_dec->u4_non_zero_rows);
    700 
    701             }
    702         }
    703 
    704         ps_dec->u2_num_mbs_left--;
    705         ps_dec->u2_first_mb = 0;
    706         ps_dec->u2_mb_x++;
    707 
    708         if(ps_dec->s_bit_stream.u4_offset > ps_dec->s_bit_stream.u4_max_offset)
    709         {
    710             return IMPEG2D_BITSTREAM_BUFF_EXCEEDED_ERR;
    711         }
    712         else if (ps_dec->u2_mb_x == ps_dec->u2_num_horiz_mb)
    713         {
    714             ps_dec->u2_mb_x = 0;
    715             ps_dec->u2_mb_y++;
    716 
    717         }
    718     }
    719     while(ps_dec->u2_num_mbs_left != 0 && impeg2d_bit_stream_nxt(&ps_dec->s_bit_stream,23) != 0x0);
    720     return e_error;
    721 }
    722