videoeditorengine/h263decoder/src/decmbdct.cpp
branchRCL_3
changeset 3 e0b5df5c0969
parent 0 951a5db380a0
child 7 4c409de21d23
equal deleted inserted replaced
0:951a5db380a0 3:e0b5df5c0969
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - Initial contribution
       
    11 *
       
    12 * Contributors:
       
    13 * Ixonos Plc
       
    14 *
       
    15 * Description:  
       
    16 * Prediction error block decoding functions.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 /*
       
    23  * Includes 
       
    24  */
       
    25 #include "h263dConfig.h"
       
    26 #include "decmbdct.h"
       
    27 #include "decblock.h"
       
    28 #include "block.h"
       
    29 #include "viddemux.h"
       
    30 /* MVE */
       
    31 #include "MPEG4Transcoder.h"
       
    32 
       
    33 /*
       
    34  * Globals
       
    35  */
       
    36 
       
    37 /* New chroma QP values in MQ mode. See Table T.1/H.263 */
       
    38 static const u_char dmdMQChromaTab[32] = {0,1,2,3,4,5,6,6,7,8,9,9,10,10,
       
    39                                           11,11,12,12,12,13,13,13,14,14,
       
    40                                           14,14,14,15,15,15,15,15};
       
    41 
       
    42 
       
    43 /*
       
    44  * Global functions
       
    45  */
       
    46 
       
    47 
       
    48 /* {{-output"dmdGetAndDecodeIMBBlocks.txt"}} */
       
    49 /*
       
    50  * dmdGetAndDecodeIMBBlocks
       
    51  *    
       
    52  *
       
    53  * Parameters:
       
    54  *    param                   parameters needed in this function
       
    55  *
       
    56  * Function:
       
    57  *    This function gets the DCT coefficients of an INTRA macroblock
       
    58  *    from the bitstream, reconstructs the corresponding
       
    59  *    pixel-domain blocks and puts the blocks to the output frame.
       
    60  *
       
    61  * Returns:
       
    62  *    >= 0                       the function was successful
       
    63  *    < 0                        an error occured when accessing bit buffer
       
    64  *
       
    65  */
       
    66 
       
    67 int dmdGetAndDecodeIMBBlocks(
       
    68    dmdIParam_t *param, CMPEG4Transcoder *hTranscoder)
       
    69 /* {{-output"dmdGetAndDecodeIMBBlocks.txt"}} */
       
    70 {
       
    71    bibBuffer_t 
       
    72       *inBuffer;        /* Input bit buffer instance */
       
    73 
       
    74    TBool getDecodedFrame;
       
    75 
       
    76 
       
    77    int 
       
    78       cWidth,           /* Chrominance image width in pixels */
       
    79       block[64],        /* Temporal 8 x 8 block of pixels */
       
    80       i,                /* Loop variable */
       
    81       chrQuant,         /* Quantization parameter for chroma */
       
    82       bitErrorIndication = 0, 
       
    83                         /* Carries bit error indication information returned
       
    84                            by the video demultiplexer module */
       
    85       ret = 0;          /* Used to check return values of function calls */
       
    86 
       
    87    u_char 
       
    88       *yBlockInFrame;   /* Points to top-left corner of the current block
       
    89                            inside the current frame */
       
    90 
       
    91    inBuffer = param->inBuffer;
       
    92 
       
    93    getDecodedFrame = param->iGetDecodedFrame;
       
    94 
       
    95 
       
    96    yBlockInFrame = param->yMBInFrame;
       
    97    cWidth = param->yWidth / 2;
       
    98 
       
    99 
       
   100    /* Luminance blocks */
       
   101    for (i=0; i<4; i++) 
       
   102      {
       
   103          /* MVE */
       
   104         hTranscoder->BeginOneBlock(i);
       
   105          
       
   106         bitErrorIndication = 0;
       
   107          
       
   108          /* Get DCT coefficients */
       
   109          ret = vdxGetIntraDCTBlock(inBuffer, vdxIsYCoded(param->cbpy, i + 1), 
       
   110              block, &bitErrorIndication, param->fMQ, param->quant);
       
   111          if ( ret < 0 )
       
   112              return DMD_ERR;
       
   113          else if ( ret == VDX_OK_BUT_BIT_ERROR )
       
   114              goto corruptedMB;
       
   115          
       
   116          /* MVE */
       
   117          hTranscoder->AddOneBlockDataToMB(i, block);             
       
   118          if(getDecodedFrame || hTranscoder->NeedDecodedYUVFrame()) // we need the YUV frames.
       
   119          {
       
   120 
       
   121              dblIdctAndDequant(block, param->quant, 1);
       
   122              blcBlockToFrame(block, yBlockInFrame, param->yWidth);
       
   123              yBlockInFrame += 8;
       
   124              if (i & 1)
       
   125                  yBlockInFrame += 8 * param->yWidth - 16;
       
   126          }
       
   127 
       
   128    } /* for (y blocks) */
       
   129 
       
   130     /* MVE */
       
   131     hTranscoder->BeginOneBlock(4);
       
   132 
       
   133    /* Chrominance blocks (U) */
       
   134    bitErrorIndication = 0;
       
   135    /* Find out the value of QP for chrominance block. */
       
   136    chrQuant = (param->fMQ)?dmdMQChromaTab[param->quant]:param->quant;
       
   137 
       
   138    /* Get DCT coefficients */
       
   139    ret = vdxGetIntraDCTBlock(inBuffer, vdxIsUCoded(param->cbpc), 
       
   140      block, &bitErrorIndication, param->fMQ, chrQuant);
       
   141    if ( ret < 0 )
       
   142      return DMD_ERR;
       
   143    else if ( ret == VDX_OK_BUT_BIT_ERROR )
       
   144      goto corruptedMB;
       
   145 
       
   146     /* MVE */
       
   147     hTranscoder->AddOneBlockDataToMB(4, block);          
       
   148     hTranscoder->BeginOneBlock(5);
       
   149    if(getDecodedFrame || hTranscoder->NeedDecodedYUVFrame()) 
       
   150      {
       
   151          dblIdctAndDequant(block, chrQuant, 1);
       
   152          blcBlockToFrame(block, param->uBlockInFrame, cWidth);
       
   153      }
       
   154 
       
   155    /* (V) */
       
   156    bitErrorIndication = 0;
       
   157    /* Get DCT coefficients */
       
   158    ret = vdxGetIntraDCTBlock(inBuffer, vdxIsVCoded(param->cbpc),
       
   159      block, &bitErrorIndication, param->fMQ, chrQuant);
       
   160    if ( ret < 0 )
       
   161      return DMD_ERR;
       
   162    else if ( ret == VDX_OK_BUT_BIT_ERROR )
       
   163      goto corruptedMB;
       
   164 
       
   165     /* MVE */
       
   166     hTranscoder->AddOneBlockDataToMB(5, block);          
       
   167     if ( hTranscoder->TranscodingOneMB(NULL) != DMD_OK )
       
   168         {
       
   169         return DMD_ERR;
       
   170         }
       
   171     if(getDecodedFrame || hTranscoder->NeedDecodedYUVFrame())
       
   172      {
       
   173          
       
   174          dblIdctAndDequant(block, chrQuant, 1);
       
   175          blcBlockToFrame(block, param->vBlockInFrame, cWidth);
       
   176          
       
   177      }
       
   178 
       
   179    return DMD_OK;
       
   180 
       
   181 corruptedMB:
       
   182 
       
   183    return DMD_BIT_ERR;
       
   184 }
       
   185 
       
   186 
       
   187 /* {{-output"dmdGetAndDecodePMBBlocks.txt"}} */
       
   188 /*
       
   189  * dmdGetAndDecodePMBBlocks
       
   190  *    
       
   191  *
       
   192  * Parameters:
       
   193  *    param                      parameters needed in this function
       
   194  *
       
   195  * Function:
       
   196  *    This function gets the DCT coefficients of an INTER macroblock
       
   197  *    from the bitstream, reconstructs the corresponding
       
   198  *    pixel-domain blocks and adds the blocks to the prediction frame.
       
   199  *
       
   200  * Returns:
       
   201  *    >= 0                       the function was successful
       
   202  *    < 0                        an error occured when accessing bit buffer
       
   203  *
       
   204  */
       
   205 
       
   206 int dmdGetAndDecodePMBBlocks(
       
   207    dmdPParam_t *param, CMPEG4Transcoder *hTranscoder)
       
   208 /* {{-output"dmdGetAndDecodePMBBlocks.txt"}} */
       
   209 {
       
   210    bibBuffer_t 
       
   211       *inBuffer;        /* Input bit buffer instance */
       
   212 
       
   213 
       
   214      TBool getDecodedFrame;
       
   215 
       
   216         int 
       
   217       yWidth,           /* Luminance image width in pixels */
       
   218       block[64],        /* Temporal 8 x 8 block of pixels */
       
   219       i,                /* Loop variable */
       
   220       chrQuant,         /* Quantization parameter for chroma */
       
   221       bitErrorIndication = 0, 
       
   222                         /* Carries bit error indication information returned
       
   223                            by the video demultiplexer module */
       
   224       ret = 0;          /* Used to check return values of function calls */
       
   225 
       
   226    u_char 
       
   227       *yBlockInFrame;   /* Points to top-left corner of the current block
       
   228                            inside the current frame */
       
   229 
       
   230    inBuffer = param->inBuffer;
       
   231 
       
   232 
       
   233    getDecodedFrame = param->iGetDecodedFrame;
       
   234 
       
   235 
       
   236    yWidth = param->uvWidth * 2;
       
   237    yBlockInFrame = param->currYMBInFrame;
       
   238 
       
   239 
       
   240    int fEscapeCodeUsed = 0;
       
   241 
       
   242    /* Luminance blocks */
       
   243    for (i = 0; i < 4; i++) {
       
   244    
       
   245          hTranscoder->BeginOneBlock(i);
       
   246 
       
   247          if (vdxIsYCoded(param->cbpy, i + 1)) 
       
   248          {
       
   249              /* Get DCT coefficients */
       
   250              ret = vdxGetDCTBlock(inBuffer, 0, 0, block, 
       
   251                  &bitErrorIndication, 0, param->quant, &fEscapeCodeUsed);
       
   252              if ( ret < 0 )
       
   253                  return DMD_ERR;
       
   254              else if ( ret == VDX_OK_BUT_BIT_ERROR )
       
   255                  return DMD_BIT_ERR;
       
   256              
       
   257              /* MVE */
       
   258              hTranscoder->H263EscapeCoding(i, fEscapeCodeUsed);
       
   259              hTranscoder->AddOneBlockDataToMB(i, block);             
       
   260              if(getDecodedFrame || hTranscoder->NeedDecodedYUVFrame())
       
   261              {
       
   262                  
       
   263                  dblIdctAndDequant(block, param->quant, 0);
       
   264                  
       
   265                  blcAddBlock(block, yBlockInFrame,
       
   266                      yWidth, param->mbPlace,
       
   267                      (u_char) param->fAdvancedPrediction, param->diffMB->block[i]);        
       
   268              }
       
   269          }
       
   270 
       
   271          /* MVE */
       
   272          else
       
   273          {
       
   274              hTranscoder->H263EscapeCoding(i, fEscapeCodeUsed);
       
   275              hTranscoder->AddOneBlockDataToMB(i, NULL);          
       
   276          }
       
   277 
       
   278      yBlockInFrame += 8;
       
   279      if (i & 1)
       
   280        yBlockInFrame += ((/*8 **/ yWidth<<3) - 16);
       
   281    } /* for (y blocks) */
       
   282 
       
   283    /* Find out the value of QP for chrominance block. */
       
   284    chrQuant = param->quant;
       
   285 
       
   286    hTranscoder->BeginOneBlock(4);
       
   287 
       
   288    /* Chrominance blocks (U) */
       
   289    if (vdxIsUCoded(param->cbpc)) 
       
   290      {
       
   291      /* Get DCT coefficients */
       
   292      ret = vdxGetDCTBlock(inBuffer, 0, 0, block, 
       
   293              &bitErrorIndication, 0, param->quant, &fEscapeCodeUsed);
       
   294          if ( ret < 0 )
       
   295              return DMD_ERR;
       
   296          else if ( ret == VDX_OK_BUT_BIT_ERROR )
       
   297              return DMD_BIT_ERR;
       
   298          
       
   299          hTranscoder->H263EscapeCoding(4, fEscapeCodeUsed);
       
   300          hTranscoder->AddOneBlockDataToMB(4, block);             
       
   301          if(getDecodedFrame || hTranscoder->NeedDecodedYUVFrame())
       
   302          {  
       
   303              
       
   304              dblIdctAndDequant(block, chrQuant,0);
       
   305              blcAddBlock(block, param->currUBlkInFrame, param->uvWidth, 0, 0, 0);
       
   306          }
       
   307    }
       
   308 
       
   309    else
       
   310    {
       
   311          hTranscoder->H263EscapeCoding(4, fEscapeCodeUsed);
       
   312          hTranscoder->AddOneBlockDataToMB(4, NULL);          
       
   313    }
       
   314 
       
   315    hTranscoder->BeginOneBlock(5);
       
   316 
       
   317    /* (V) */
       
   318    if (vdxIsVCoded(param->cbpc)) 
       
   319      {
       
   320          /* Get DCT coefficients */
       
   321          ret = vdxGetDCTBlock(inBuffer, 0, 0, block, 
       
   322              &bitErrorIndication, 0, param->quant, &fEscapeCodeUsed);
       
   323          if ( ret < 0 )
       
   324              return DMD_ERR;
       
   325          else if ( ret == VDX_OK_BUT_BIT_ERROR )
       
   326              return DMD_BIT_ERR;
       
   327          
       
   328          /* MVE */
       
   329          hTranscoder->H263EscapeCoding(5, fEscapeCodeUsed);
       
   330          hTranscoder->AddOneBlockDataToMB(5, block);             
       
   331          if(getDecodedFrame || hTranscoder->NeedDecodedYUVFrame())
       
   332          {
       
   333          
       
   334              dblIdctAndDequant(block, chrQuant,0);
       
   335              blcAddBlock(block, param->currVBlkInFrame, param->uvWidth, 0, 0, 0);
       
   336          }
       
   337    }
       
   338    else
       
   339    {
       
   340          hTranscoder->H263EscapeCoding(5, fEscapeCodeUsed);
       
   341          hTranscoder->AddOneBlockDataToMB(5, NULL);          
       
   342    }
       
   343 
       
   344    if ( hTranscoder->TranscodingOneMB(param) != TX_OK )
       
   345     {
       
   346     return DMD_ERR;
       
   347     }
       
   348    return DMD_OK;
       
   349    
       
   350 }
       
   351 
       
   352 // End of File