videoeditorengine/avcedit/src/macroblock.cpp
changeset 0 951a5db380a0
equal deleted inserted replaced
-1:000000000000 0:951a5db380a0
       
     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 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "globals.h"
       
    21 #include "bitbuffer.h"
       
    22 #include "macroblock.h"
       
    23 #include "motcomp.h"
       
    24 #include "framebuffer.h"
       
    25 #include "vld.h"
       
    26 #include "parameterset.h"
       
    27 
       
    28 #ifdef USE_CLIPBUF
       
    29 #include "clipbuf.h"
       
    30 #endif
       
    31 
       
    32 /*
       
    33  * Static functions
       
    34  */
       
    35 
       
    36 static int getMacroblock(macroblock_s *mb, int numRefFrames,
       
    37                          int8 *ipTab, int8 **numCoefUpPred, int diffVecs[][2],
       
    38                          int picType, int chromaQpIdx, bitbuffer_s *bitbuf);
       
    39 
       
    40 static int getMbAvailability(macroblock_s *mb, mbAttributes_s *mbData,
       
    41                              int picWidth, int constrainedIntra);
       
    42 
       
    43 
       
    44 #ifdef USE_CLIPBUF
       
    45 const u_int8 *mcpGetClip8Buf()
       
    46 {
       
    47   return clip8Buf;
       
    48 }
       
    49 #endif
       
    50 
       
    51 /*
       
    52  *
       
    53  * getMacroblock:
       
    54  *
       
    55  * Parameters:
       
    56  *      mb                    Macroblock parameters
       
    57  *      multRef               1 -> multiple reference frames used
       
    58  *      ipTab                 Macroblock intra pred. modes
       
    59  *      numCoefUpPred         Block coefficient counts of upper MBs
       
    60  *      diffVecs              Macroblock delta motion vectors
       
    61  *      picType               Picture type (intra/inter)
       
    62  *      chromaQpIdx           Chroma QP index relative to luma QP
       
    63  *      bitbuf                Bitbuffer handle
       
    64  *
       
    65  * Function:
       
    66  *      Get macroblock parameters from bitbuffer
       
    67  *      
       
    68  * Returns:
       
    69  *      MBK_OK for no error, MBK_ERROR for error
       
    70  *
       
    71  */
       
    72 static int getMacroblock(macroblock_s *mb, int numRefFrames,
       
    73                          int8 *ipTab, int8 **numCoefUpPred, int diffVecs[][2],
       
    74                          int picType, int chromaQpIdx, bitbuffer_s *bitbuf)
       
    75 {
       
    76   vldMBtype_s hdr;
       
    77   int numVecs;
       
    78   int delta_qp;
       
    79   int i;
       
    80   int8 *numCoefPtrY, *numCoefPtrU, *numCoefPtrV;
       
    81   int retCode;
       
    82 
       
    83 
       
    84   numCoefPtrY = &numCoefUpPred[0][mb->blkX];
       
    85   numCoefPtrU = &numCoefUpPred[1][mb->blkX>>1];
       
    86   numCoefPtrV = &numCoefUpPred[2][mb->blkX>>1];
       
    87 
       
    88   /*
       
    89    * Get Macroblock type
       
    90    */
       
    91 
       
    92   /* Check if we have to fetch run indicator */
       
    93   if (IS_SLICE_P(picType) && mb->numSkipped < 0) {
       
    94 
       
    95     mb->numSkipped = vldGetRunIndicator(bitbuf);
       
    96 
       
    97     if (bibGetStatus(bitbuf) < 0)
       
    98       return MBK_ERROR;
       
    99   }
       
   100 
       
   101   if (IS_SLICE_P(picType) && mb->numSkipped > 0) {
       
   102 
       
   103     /* If skipped MBs, set MB to COPY */
       
   104     mb->type = MBK_INTER;
       
   105     mb->interMode = MOT_COPY;
       
   106     mb->refNum[0] = 0;
       
   107     mb->cbpY = mb->cbpChromaDC = mb->cbpC = 0;
       
   108     mb->numSkipped -= 1;
       
   109 
       
   110     vldGetZeroLumaCoeffs(numCoefPtrY, mb->numCoefLeftPred);
       
   111     vldGetZeroChromaCoeffs(numCoefPtrU, numCoefPtrV, mb->numCoefLeftPredC);
       
   112 
       
   113     return MBK_OK;
       
   114   }
       
   115   else {
       
   116 
       
   117     if (vldGetMBtype(bitbuf, &hdr, picType) < 0) {
       
   118       PRINT((_L("Error: illegal MB type\n")));     
       
   119       return MBK_ERROR;
       
   120     }
       
   121 
       
   122     mb->type        = hdr.type;
       
   123     mb->intraType   = hdr.intraType;
       
   124     mb->intraMode   = hdr.intraMode;
       
   125     mb->interMode   = hdr.interMode;
       
   126 
       
   127     for (i = 0; i < 4; i++)
       
   128       mb->inter8x8modes[i] = hdr.inter8x8modes[i];
       
   129 
       
   130     mb->cbpY        = hdr.cbpY;
       
   131     mb->cbpChromaDC = hdr.cbpChromaDC;
       
   132     mb->cbpC        = hdr.cbpC;
       
   133 
       
   134     mb->numSkipped -= 1;
       
   135   }
       
   136 
       
   137   if (mb->type == MBK_INTRA && mb->intraType == MBK_INTRA_TYPE_PCM) {
       
   138     vldGetAllCoeffs(numCoefPtrY, numCoefPtrU, numCoefPtrV,
       
   139                     mb->numCoefLeftPred, mb->numCoefLeftPredC);
       
   140     return MBK_OK;
       
   141   }
       
   142 
       
   143   /*
       
   144    * 4x4 intra prediction modes 
       
   145    */
       
   146   if (mb->type == MBK_INTRA && mb->intraType == MBK_INTRA_TYPE1) {
       
   147 
       
   148     if (vldGetIntraPred(bitbuf, ipTab) < 0) {
       
   149       PRINT((_L("Error: illegal intra pred\n")));     
       
   150       return MBK_ERROR;
       
   151     }
       
   152   }
       
   153 
       
   154   /*
       
   155    * 8x8 chroma intra prediction mode
       
   156    */
       
   157   if (mb->type == MBK_INTRA) {
       
   158 
       
   159     mb->intraModeChroma = vldGetChromaIntraPred(bitbuf);
       
   160 
       
   161     if (mb->intraModeChroma < 0) {
       
   162       PRINT((_L("Error: illegal chroma intra pred\n")));     
       
   163       return MBK_ERROR;
       
   164     }
       
   165   }
       
   166 
       
   167   /*
       
   168    * Reference frame number and motion vectors
       
   169    */
       
   170   if (mb->type == MBK_INTER) {
       
   171 
       
   172     numVecs = mcpGetNumMotVecs(mb->interMode, mb->inter8x8modes);
       
   173     mb->numMotVecs = numVecs;
       
   174 
       
   175     retCode = vldGetMotVecs(bitbuf, mb->interMode, numRefFrames,
       
   176                             mb->refNum, diffVecs, numVecs);
       
   177 
       
   178     if (retCode < 0) {
       
   179       PRINT((_L("Error: illegal motion vectors\n")));     
       
   180       return MBK_ERROR;
       
   181     }
       
   182   }
       
   183 
       
   184   /*
       
   185    * Coded block pattern
       
   186    */
       
   187   if (!(mb->type == MBK_INTRA && mb->intraType == MBK_INTRA_TYPE2)) {
       
   188 
       
   189     retCode = vldGetCBP(bitbuf, mb->type, &mb->cbpY, &mb->cbpChromaDC, &mb->cbpC);
       
   190 
       
   191     if (retCode < 0) {
       
   192       PRINT((_L("Error: illegal CBP\n")));     
       
   193       return MBK_ERROR;
       
   194     }
       
   195   }
       
   196 
       
   197 
       
   198   /* Delta QP */
       
   199   if ((mb->type == MBK_INTRA && mb->intraType == MBK_INTRA_TYPE2) || 
       
   200       (mb->cbpY | mb->cbpChromaDC | mb->cbpC) != 0)
       
   201   {
       
   202     retCode = vldGetDeltaqp(bitbuf, &delta_qp);
       
   203 
       
   204     if (retCode < 0 || delta_qp < -(MAX_QP-MIN_QP+1)/2 || delta_qp >= (MAX_QP-MIN_QP+1)/2) {
       
   205       PRINT((_L("Error: illegal delta qp\n")));     
       
   206       return MBK_ERROR;
       
   207     }
       
   208 
       
   209     if (delta_qp != 0) {
       
   210       int qp = mb->qp + delta_qp;
       
   211       if (qp < MIN_QP)
       
   212         qp += (MAX_QP-MIN_QP+1);
       
   213       if (qp > MAX_QP)
       
   214         qp -= (MAX_QP-MIN_QP+1);
       
   215       mb->qp = qp;
       
   216       mb->qpC = qpChroma[clip(MIN_QP, MAX_QP, mb->qp + chromaQpIdx)];
       
   217     }
       
   218   }
       
   219 
       
   220 
       
   221   /*
       
   222    * Get transform coefficients
       
   223    */
       
   224 
       
   225   /*
       
   226    * Luma DC coefficients (if 16x16 intra)
       
   227    */
       
   228   if (mb->type == MBK_INTRA && mb->intraType == MBK_INTRA_TYPE2) {
       
   229 
       
   230     retCode = vldGetLumaDCcoeffs(bitbuf, mb->dcCoefY, numCoefPtrY,
       
   231                              mb->numCoefLeftPred, mb->mbAvailBits);
       
   232     if (retCode < 0) {
       
   233       PRINT((_L("Error: illegal luma DC coefficient\n")));     
       
   234       return MBK_ERROR;
       
   235     }
       
   236   }
       
   237 
       
   238   /*
       
   239    * Luma AC coefficients
       
   240    */
       
   241   if (mb->cbpY != 0) {
       
   242 
       
   243     retCode = vldGetLumaCoeffs(bitbuf, mb->type, mb->intraType, &mb->cbpY,
       
   244                                mb->coefY, numCoefPtrY, mb->numCoefLeftPred,
       
   245                                mb->mbAvailBits);
       
   246     if (retCode < 0) {
       
   247       PRINT((_L("Error: illegal luma AC coefficient\n")));     
       
   248       return MBK_ERROR;
       
   249     } 
       
   250   }
       
   251   else
       
   252     vldGetZeroLumaCoeffs(numCoefPtrY, mb->numCoefLeftPred);
       
   253 
       
   254   /*
       
   255    * Chroma DC coefficients
       
   256    */
       
   257   if (mb->cbpChromaDC != 0) {
       
   258 
       
   259     retCode = vldGetChromaDCcoeffs(bitbuf, mb->dcCoefC, &mb->cbpChromaDC);
       
   260 
       
   261     if (retCode < 0) {
       
   262       PRINT((_L("Error: illegal chroma DC coefficient\n")));     
       
   263       return MBK_ERROR;
       
   264     }
       
   265   }
       
   266 
       
   267   /*
       
   268    * Chroma AC coefficients
       
   269    */
       
   270   if (mb->cbpC != 0) {
       
   271 
       
   272     retCode = vldGetChromaCoeffs(bitbuf, mb->coefC, &mb->cbpC, numCoefPtrU, numCoefPtrV,
       
   273                              mb->numCoefLeftPredC[0], mb->numCoefLeftPredC[1], mb->mbAvailBits);
       
   274     if (retCode < 0) {
       
   275       PRINT((_L("Error: illegal chroma AC coefficient\n")));     
       
   276       return MBK_ERROR;
       
   277     }
       
   278   }
       
   279   else {
       
   280     vldGetZeroChromaCoeffs(numCoefPtrU, numCoefPtrV, mb->numCoefLeftPredC);
       
   281   }
       
   282 
       
   283   return MBK_OK;
       
   284 }
       
   285 
       
   286 
       
   287 /*
       
   288  *
       
   289  * mbkSetInitialQP:
       
   290  *
       
   291  * Parameters:
       
   292  *      mb                    Macroblock object
       
   293  *      qp                    Quantization parameter
       
   294  *      chromaQpIdx           Chroma QP index relative to luma QP
       
   295  *
       
   296  * Function:
       
   297  *      Set macroblock qp.
       
   298  *      
       
   299  * Returns:
       
   300  *      -
       
   301  *
       
   302  */
       
   303 void mbkSetInitialQP(macroblock_s *mb, int qp, int chromaQpIdx)
       
   304 {
       
   305   mb->qp  = qp;
       
   306   mb->qpC = qpChroma[clip(MIN_QP, MAX_QP, qp + chromaQpIdx)];
       
   307 
       
   308   mb->numSkipped = -1;
       
   309 }
       
   310 
       
   311 
       
   312 /*
       
   313  *
       
   314  * getMbAvailability:
       
   315  *
       
   316  * Parameters:
       
   317  *      mb                    Macroblock object
       
   318  *      mbData                Buffers for for macroblock attributes
       
   319  *      picWidth              Picture width
       
   320  *      constrainedIntra      Constrained intra prediction flag
       
   321  *
       
   322  * Function:
       
   323  *      Get neighboring macroblock availability info
       
   324  *      
       
   325  * Returns:
       
   326  *      Macroblock availability bits:
       
   327  *        bit 0 : left macroblock
       
   328  *        bit 1 : upper macroblock
       
   329  *        bit 2 : upper-right macroblock
       
   330  *        bit 3 : upper-left macroblock
       
   331  *        bit 4 : left macroblock (intra)
       
   332  *        bit 5 : upper macroblock (intra)
       
   333  *        bit 6 : upper-right macroblock (intra)
       
   334  *        bit 7 : upper-left macroblock (intra)
       
   335  */
       
   336 static int getMbAvailability(macroblock_s *mb, mbAttributes_s *mbData,
       
   337                              int picWidth, int constrainedIntra)
       
   338 {
       
   339   int mbsPerLine;
       
   340   int mbAddr;
       
   341   int currSliceIdx;
       
   342   int *sliceMap;
       
   343   int8 *mbTypeTable;
       
   344   int mbAvailBits;
       
   345 
       
   346   mbsPerLine = picWidth/MBK_SIZE;
       
   347   mbAddr = mb->idxY*mbsPerLine+mb->idxX;
       
   348 
       
   349   sliceMap = & mbData->sliceMap[mbAddr];
       
   350   currSliceIdx = sliceMap[0];
       
   351 
       
   352   mbAvailBits = 0;
       
   353 
       
   354   /* Check availability of left macroblock */
       
   355   if (mb->idxX > 0 && sliceMap[-1] == currSliceIdx)
       
   356     mbAvailBits |= 0x11;
       
   357 
       
   358   /* Check availability of upper, upper-left and upper-right macroblocks */
       
   359 
       
   360   if (mb->idxY > 0) {
       
   361 
       
   362     sliceMap -= mbsPerLine;
       
   363 
       
   364     /* Check availability of upper macroblock */
       
   365     if (sliceMap[0] == currSliceIdx)
       
   366       mbAvailBits |= 0x22;
       
   367 
       
   368     /* Check availability of upper-right macroblock */
       
   369     if (mb->idxX+1 < mbsPerLine && sliceMap[1] == currSliceIdx)
       
   370       mbAvailBits |= 0x44;
       
   371 
       
   372     /* Check availability of upper-left macroblock */
       
   373     if (mb->idxX > 0 && sliceMap[-1] == currSliceIdx)
       
   374       mbAvailBits |= 0x88;
       
   375   }
       
   376 
       
   377 
       
   378   /*
       
   379    * Check availability of intra MB if constrained intra is enabled
       
   380    */
       
   381 
       
   382   if (constrainedIntra) {
       
   383 
       
   384      mbTypeTable = & mbData->mbTypeTable[mbAddr];
       
   385 
       
   386     /* Check availability of left intra macroblock */
       
   387     if ((mbAvailBits & 0x10) && mbTypeTable[-1] != MBK_INTRA)
       
   388       mbAvailBits &= ~0x10;
       
   389 
       
   390     /* Check availability of upper, upper-left and upper-right intra macroblocks */
       
   391 
       
   392     if (mbAvailBits & (0x20|0x40|0x80)) {
       
   393 
       
   394       mbTypeTable -= mbsPerLine;
       
   395 
       
   396       /* Check availability of upper intra macroblock */
       
   397       if ((mbAvailBits & 0x20) && mbTypeTable[0] != MBK_INTRA)
       
   398         mbAvailBits &= ~0x20;
       
   399 
       
   400       /* Check availability of upper-right intra macroblock */
       
   401       if ((mbAvailBits & 0x40) && mbTypeTable[1] != MBK_INTRA)
       
   402         mbAvailBits &= ~0x40;
       
   403 
       
   404       /* Check availability of upper-left intra macroblock */
       
   405       if ((mbAvailBits & 0x80) && mbTypeTable[-1] != MBK_INTRA)
       
   406         mbAvailBits &= ~0x80;
       
   407     }
       
   408   }
       
   409 
       
   410   return mbAvailBits;
       
   411 }
       
   412 
       
   413 
       
   414 // mbkParse
       
   415 // Parses the input macroblock. If PCM coding is used then re-aligns the byte 
       
   416 // alignment if previous (slice header) modifications have broken the alignment.
       
   417 TInt mbkParse(macroblock_s *mb, TInt numRefFrames, mbAttributes_s *mbData, 
       
   418 			  TInt picWidth, TInt picType, TInt constIpred, TInt chromaQpIdx,
       
   419               TInt mbIdxX, TInt mbIdxY, void *streamBuf, TInt aBitOffset)
       
   420 {
       
   421   	TInt8 ipTab[BLK_PER_MB*BLK_PER_MB];
       
   422   	TInt diffVecs[BLK_PER_MB*BLK_PER_MB][2];
       
   423 //  	TInt hasDc;
       
   424 //  	TInt pixOffset;
       
   425   	TInt constrainedIntra;
       
   426   	TInt copyMbFlag;
       
   427   	TInt mbAddr;
       
   428   	TInt pcmMbFlag;
       
   429   	TInt retCode;
       
   430 
       
   431   	mb->idxX = mbIdxX;
       
   432   	mb->idxY = mbIdxY;
       
   433 
       
   434   	mb->blkX = mbIdxX*BLK_PER_MB;
       
   435   	mb->blkY = mbIdxY*BLK_PER_MB;
       
   436 
       
   437   	mb->pixX = mbIdxX*MBK_SIZE;
       
   438   	mb->pixY = mbIdxY*MBK_SIZE;
       
   439 
       
   440   	mbAddr = mb->idxY*(picWidth/MBK_SIZE)+mb->idxX;
       
   441 
       
   442   	copyMbFlag = pcmMbFlag = 0;
       
   443 
       
   444   	constrainedIntra = constIpred && !(IS_SLICE_I(picType));
       
   445 
       
   446   	mb->mbAvailBits = getMbAvailability(mb, mbData, picWidth, constrainedIntra);
       
   447 
       
   448   	// Read macroblock bits
       
   449     retCode = getMacroblock(mb, numRefFrames, ipTab, mbData->numCoefUpPred, diffVecs,
       
   450                             picType, chromaQpIdx, (bitbuffer_s *)streamBuf);
       
   451 
       
   452   	if (retCode < 0)
       
   453 	    return retCode;
       
   454 
       
   455   	// Set PCM flag 
       
   456   	if (mb->type == MBK_INTRA && mb->intraType == MBK_INTRA_TYPE_PCM)
       
   457 	    pcmMbFlag = 1;
       
   458 
       
   459 
       
   460   	// Get intra/inter prediction
       
   461   	if (mb->type == MBK_INTRA) 
       
   462   	{
       
   463     	mbData->mbTypeTable[mbAddr] = MBK_INTRA;
       
   464 
       
   465     	if (pcmMbFlag) 
       
   466     	{
       
   467     		bitbuffer_s* tempBitBuffer = (bitbuffer_s *)streamBuf;
       
   468     		
       
   469     		// Synchronize bitbuffer bit position to get it between 1 and 8
       
   470 			syncBitBufferBitpos(tempBitBuffer);
       
   471 	
       
   472    			// To find out how much we have to shift to reach the byte alignment again,
       
   473    			// we have to first find out the old alignment
       
   474    			// oldAlignment is the place of the bitpos before the aBitOffset, i.e. it is
       
   475    			// the amount of zero alignment bits plus one
       
   476    			TInt oldAlignmentBits = tempBitBuffer->bitpos + aBitOffset - 1;
       
   477    			TInt shiftAmount;
       
   478 	   			
       
   479    		
       
   480    			// If Bit-wise shift, i.e. aBitOffset is zero, do nothing
       
   481     		// Fix the possible bit buffer byte alignment
       
   482     		if (aBitOffset > 0)
       
   483     		{
       
   484     		
       
   485     			// aBitOffset > 0 indicates a bitshift to the right
       
   486     			
       
   487     			// To counter the shift to right we have to shift left by the same amount 
       
   488     			// unless shift is larger than the number of original alignment bits in 
       
   489     			// which case we have to shift more to the right 
       
   490      			
       
   491 	   			// If the computed old alignment bits value is larger than eight, 
       
   492 	   			//the correct value is (computed value) % 8
       
   493 	   			oldAlignmentBits = oldAlignmentBits % 8;
       
   494 
       
   495     			if ( oldAlignmentBits < aBitOffset )
       
   496     			{
       
   497     				// When the amount of shift is larger than the number of original alignment bits,
       
   498     				// shift right to fill up the rest of the current byte with zeros
       
   499     				shiftAmount = 8 - aBitOffset;
       
   500 
       
   501    					// Here we can't shift back left since there were not enough alignment bits originally, 
       
   502    					// thus we have to shift right by new bit position - tempBitBuffer->bitpos
       
   503 
       
   504    					// E.g. original alignment bits 2, right shift by 4 bits:
       
   505    					/////////////////////////////////////////////////////////////////
       
   506 					// original             after bit shift      byte alignment reset
       
   507 					// 1. byte: 2. byte:    1. byte: 2. byte:    1. byte: 2. byte: 3. byte:
       
   508 					// xxxxxx00 yyyyyyyy -> xxxxxxxx xx00yyyy -> xxxxxxxx xx000000 yyyyyyyy
       
   509    					/////////////////////////////////////////////////////////////////
       
   510    					ShiftBitBufferBitsRight(tempBitBuffer, shiftAmount);
       
   511     			}
       
   512     			else
       
   513     			{
       
   514    					// In this case, the old alignment bits are more than enough 
       
   515    					// to shift back left by the aBitOffset amount
       
   516    					
       
   517    					// E.g. original alignment bits 4, right shift by 2 bits:
       
   518    					/////////////////////////////////////////////////////////////////
       
   519 					// original             after bit shift      byte alignment reset
       
   520    					// 1. byte: 2. byte:    1. byte: 2. byte:    1. byte: 2. byte:
       
   521    					// xxxx0000 yyyyyyyy -> xxxxxx00 00yyyyyy -> xxxxxx00 yyyyyyyy
       
   522    					/////////////////////////////////////////////////////////////////
       
   523    					ShiftBitBufferBitsLeft(tempBitBuffer, aBitOffset);
       
   524     			}
       
   525     		}
       
   526     		else if(aBitOffset < 0)
       
   527     		{
       
   528     			// There was a bit shift to left
       
   529     			// Change the aBitOffset sign to positive
       
   530     			aBitOffset = -aBitOffset;
       
   531     		
       
   532 				// If the computed alignment bits is negative the correct value is -(computed value)
       
   533 				if ( oldAlignmentBits < 0 )
       
   534 				{
       
   535 					oldAlignmentBits = -oldAlignmentBits;
       
   536 				}
       
   537     			
       
   538     			if ( oldAlignmentBits + aBitOffset >= 8 )
       
   539     			{
       
   540 					// When old alignment bits plus the shift are at least 8, then 
       
   541 					// we have to shift left by the 8 - shift to reach byte alignment. 
       
   542 	    			shiftAmount = 8 - aBitOffset;
       
   543 
       
   544    					// E.g. original alignment bits 6, left shift by 4 bits:
       
   545    					/////////////////////////////////////////////////////////////////
       
   546 					// original             after bit shift      byte alignment reset
       
   547 					// 1. byte: 2. byte:    1. byte: 2. byte:    1. byte: 2. byte: 
       
   548 					// xx000000 yyyyyyyy -> xxxxxx00 0000yyyy -> xxxxxx00 yyyyyyyy 
       
   549    					/////////////////////////////////////////////////////////////////
       
   550    					ShiftBitBufferBitsLeft(tempBitBuffer, shiftAmount);
       
   551     			}
       
   552     			else
       
   553     			{
       
   554 
       
   555    					// Here we can just shift right by the amount of bits shifted left to reach 
       
   556    					// the byte alignment
       
   557 
       
   558    					// E.g. original alignment bits 2, left shift by 4 bits:
       
   559    					/////////////////////////////////////////////////////////////////
       
   560 					// original             after bit shift      byte alignment reset
       
   561 					// 1. byte: 2. byte:    1. byte: 2. byte:    1. byte: 2. byte: 
       
   562 					// xxxxxx00 yyyyyyyy -> xx00yyyy yyyyyyyy -> xx000000 yyyyyyyy 
       
   563    					/////////////////////////////////////////////////////////////////
       
   564    					ShiftBitBufferBitsRight(tempBitBuffer, aBitOffset);
       
   565     			}
       
   566     		}
       
   567     	
       
   568     		return MBK_PCM_FOUND;
       
   569     	
       
   570     	}
       
   571   	}
       
   572   	else 
       
   573   	{
       
   574 
       
   575     	mbData->mbTypeTable[mbAddr] = (TInt8)(mb->interMode+1);
       
   576 
       
   577     	// If COPY MB, put skip motion vectors 
       
   578     	if (mb->interMode == MOT_COPY) 
       
   579     	{
       
   580       		mb->interMode = MOT_16x16;
       
   581     	}
       
   582 
       
   583   	}
       
   584 
       
   585 
       
   586   	// Decode prediction error & reconstruct MB
       
   587   	if (!copyMbFlag && !pcmMbFlag) 
       
   588   	{
       
   589 
       
   590     	// If 4x4 intra mode, luma prediction error is already transformed 
       
   591     	if (!(mb->type == MBK_INTRA && mb->intraType == MBK_INTRA_TYPE1)) 
       
   592     	{
       
   593 
       
   594 //      		hasDc = (mb->type == MBK_INTRA && mb->intraType == MBK_INTRA_TYPE2) ? 1 : 0;
       
   595 
       
   596     	}
       
   597 
       
   598 //    	pixOffset = ((mb->pixY*picWidth)>>2)+(mb->pixX>>1);
       
   599   	}
       
   600 
       
   601 
       
   602   	// Store qp and coded block pattern for current macroblock
       
   603 	if (pcmMbFlag)
       
   604 	    mbData->qpTable[mbAddr] = 0;
       
   605   	else
       
   606     	mbData->qpTable[mbAddr] = (TInt8)mb->qp;
       
   607 
       
   608   	mbData->cbpTable[mbAddr] = mb->cbpY;
       
   609 
       
   610   	return MBK_OK;
       
   611 }
       
   612