omxVCM4P2_DecodeVLCZigzag_Inter.c revision 0c1bc742181ded4930842b46e9507372f0b1b963
10c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
20c1bc742181ded4930842b46e9507372f0b1b963James Dong *
30c1bc742181ded4930842b46e9507372f0b1b963James Dong * File Name:  omxVCM4P2_DecodeVLCZigzag_Inter.c
40c1bc742181ded4930842b46e9507372f0b1b963James Dong * OpenMAX DL: v1.0.2
50c1bc742181ded4930842b46e9507372f0b1b963James Dong * Revision:   9641
60c1bc742181ded4930842b46e9507372f0b1b963James Dong * Date:       Thursday, February 7, 2008
70c1bc742181ded4930842b46e9507372f0b1b963James Dong *
80c1bc742181ded4930842b46e9507372f0b1b963James Dong * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
90c1bc742181ded4930842b46e9507372f0b1b963James Dong *
100c1bc742181ded4930842b46e9507372f0b1b963James Dong *
110c1bc742181ded4930842b46e9507372f0b1b963James Dong *
120c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
130c1bc742181ded4930842b46e9507372f0b1b963James Dong * Contains modules for zigzag scanning and VLC decoding
140c1bc742181ded4930842b46e9507372f0b1b963James Dong * for inter block.
150c1bc742181ded4930842b46e9507372f0b1b963James Dong *
160c1bc742181ded4930842b46e9507372f0b1b963James Dong */
170c1bc742181ded4930842b46e9507372f0b1b963James Dong
180c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxtypes.h"
190c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armOMX.h"
200c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxVC.h"
210c1bc742181ded4930842b46e9507372f0b1b963James Dong
220c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armVC.h"
230c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armCOMM_Bitstream.h"
240c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armCOMM.h"
250c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armVCM4P2_Huff_Tables_VLC.h"
260c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armVCM4P2_ZigZag_Tables.h"
270c1bc742181ded4930842b46e9507372f0b1b963James Dong
280c1bc742181ded4930842b46e9507372f0b1b963James Dong
290c1bc742181ded4930842b46e9507372f0b1b963James Dong
300c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
310c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function:  omxVCM4P2_DecodeVLCZigzag_Inter   (6.2.5.2.3)
320c1bc742181ded4930842b46e9507372f0b1b963James Dong *
330c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
340c1bc742181ded4930842b46e9507372f0b1b963James Dong * Performs VLC decoding and inverse zigzag scan for one inter-coded block.
350c1bc742181ded4930842b46e9507372f0b1b963James Dong *
360c1bc742181ded4930842b46e9507372f0b1b963James Dong * Input Arguments:
370c1bc742181ded4930842b46e9507372f0b1b963James Dong *
380c1bc742181ded4930842b46e9507372f0b1b963James Dong *   ppBitStream - double pointer to the current byte in the stream buffer
390c1bc742181ded4930842b46e9507372f0b1b963James Dong *   pBitOffset - pointer to the next available bit in the current stream
400c1bc742181ded4930842b46e9507372f0b1b963James Dong *            byte referenced by *ppBitStream. The parameter *pBitOffset is
410c1bc742181ded4930842b46e9507372f0b1b963James Dong *            valid within the range [0-7].
420c1bc742181ded4930842b46e9507372f0b1b963James Dong *   shortVideoHeader - binary flag indicating presence of
430c1bc742181ded4930842b46e9507372f0b1b963James Dong *            short_video_header; escape modes 0-3 are used if
440c1bc742181ded4930842b46e9507372f0b1b963James Dong *            shortVideoHeader==0, and escape mode 4 is used when
450c1bc742181ded4930842b46e9507372f0b1b963James Dong *            shortVideoHeader==1.
460c1bc742181ded4930842b46e9507372f0b1b963James Dong *
470c1bc742181ded4930842b46e9507372f0b1b963James Dong * Output Arguments:
480c1bc742181ded4930842b46e9507372f0b1b963James Dong *
490c1bc742181ded4930842b46e9507372f0b1b963James Dong *   ppBitStream - *ppBitStream is updated after the block is decoded such
500c1bc742181ded4930842b46e9507372f0b1b963James Dong *            that it points to the current byte in the stream buffer
510c1bc742181ded4930842b46e9507372f0b1b963James Dong *   pBitOffset - *pBitOffset is updated after decoding such that it points
520c1bc742181ded4930842b46e9507372f0b1b963James Dong *            to the next available bit in the stream byte referenced by
530c1bc742181ded4930842b46e9507372f0b1b963James Dong *            *ppBitStream
540c1bc742181ded4930842b46e9507372f0b1b963James Dong *   pDst - pointer to the coefficient buffer of current block; must be
550c1bc742181ded4930842b46e9507372f0b1b963James Dong *            4-byte aligned.
560c1bc742181ded4930842b46e9507372f0b1b963James Dong *
570c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
580c1bc742181ded4930842b46e9507372f0b1b963James Dong *
590c1bc742181ded4930842b46e9507372f0b1b963James Dong *    OMX_Sts_BadArgErr - bad arguments:
600c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    At least one of the following pointers is NULL:
610c1bc742181ded4930842b46e9507372f0b1b963James Dong *         ppBitStream, *ppBitStream, pBitOffset, pDst
620c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    pDst is not 4-byte aligned
630c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -   *pBitOffset exceeds [0,7]
640c1bc742181ded4930842b46e9507372f0b1b963James Dong *    OMX_Sts_Err - status error, if:
650c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    At least one mark bit is equal to zero
660c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    Encountered an illegal stream code that cannot be found in the VLC table
670c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    Encountered an illegal code in the VLC FLC table
680c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    The number of coefficients is greater than 64
690c1bc742181ded4930842b46e9507372f0b1b963James Dong *
700c1bc742181ded4930842b46e9507372f0b1b963James Dong */
710c1bc742181ded4930842b46e9507372f0b1b963James Dong
720c1bc742181ded4930842b46e9507372f0b1b963James DongOMXResult omxVCM4P2_DecodeVLCZigzag_Inter(
730c1bc742181ded4930842b46e9507372f0b1b963James Dong     const OMX_U8 ** ppBitStream,
740c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_INT * pBitOffset,
750c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_S16 * pDst,
760c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_INT shortVideoHeader
770c1bc742181ded4930842b46e9507372f0b1b963James Dong)
780c1bc742181ded4930842b46e9507372f0b1b963James Dong{
790c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_U8  last,start = 0;
800c1bc742181ded4930842b46e9507372f0b1b963James Dong    const OMX_U8  *pZigzagTable = armVCM4P2_aClassicalZigzagScan;
810c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMXResult errorCode;
820c1bc742181ded4930842b46e9507372f0b1b963James Dong
830c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Argument error checks */
840c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(ppBitStream == NULL, OMX_Sts_BadArgErr);
850c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(*ppBitStream == NULL, OMX_Sts_BadArgErr);
860c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(pBitOffset == NULL, OMX_Sts_BadArgErr);
870c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr);
880c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(!armIs4ByteAligned(pDst), OMX_Sts_BadArgErr);
890c1bc742181ded4930842b46e9507372f0b1b963James Dong
900c1bc742181ded4930842b46e9507372f0b1b963James Dong    errorCode = armVCM4P2_GetVLCBits (
910c1bc742181ded4930842b46e9507372f0b1b963James Dong              ppBitStream,
920c1bc742181ded4930842b46e9507372f0b1b963James Dong              pBitOffset,
930c1bc742181ded4930842b46e9507372f0b1b963James Dong			  pDst,
940c1bc742181ded4930842b46e9507372f0b1b963James Dong			  shortVideoHeader,
950c1bc742181ded4930842b46e9507372f0b1b963James Dong              start,
960c1bc742181ded4930842b46e9507372f0b1b963James Dong			  &last,
970c1bc742181ded4930842b46e9507372f0b1b963James Dong			  11,
980c1bc742181ded4930842b46e9507372f0b1b963James Dong			  42,
990c1bc742181ded4930842b46e9507372f0b1b963James Dong			   2,
1000c1bc742181ded4930842b46e9507372f0b1b963James Dong			   5,
1010c1bc742181ded4930842b46e9507372f0b1b963James Dong              armVCM4P2_InterL0RunIdx,
1020c1bc742181ded4930842b46e9507372f0b1b963James Dong              armVCM4P2_InterVlcL0,
1030c1bc742181ded4930842b46e9507372f0b1b963James Dong			  armVCM4P2_InterL1RunIdx,
1040c1bc742181ded4930842b46e9507372f0b1b963James Dong              armVCM4P2_InterVlcL1,
1050c1bc742181ded4930842b46e9507372f0b1b963James Dong              armVCM4P2_InterL0LMAX,
1060c1bc742181ded4930842b46e9507372f0b1b963James Dong              armVCM4P2_InterL1LMAX,
1070c1bc742181ded4930842b46e9507372f0b1b963James Dong              armVCM4P2_InterL0RMAX,
1080c1bc742181ded4930842b46e9507372f0b1b963James Dong              armVCM4P2_InterL1RMAX,
1090c1bc742181ded4930842b46e9507372f0b1b963James Dong              pZigzagTable );
1100c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetDataErrIf((errorCode != OMX_Sts_NoErr), errorCode);
1110c1bc742181ded4930842b46e9507372f0b1b963James Dong
1120c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (last == 0)
1130c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1140c1bc742181ded4930842b46e9507372f0b1b963James Dong        return OMX_Sts_Err;
1150c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1160c1bc742181ded4930842b46e9507372f0b1b963James Dong    return OMX_Sts_NoErr;
1170c1bc742181ded4930842b46e9507372f0b1b963James Dong}
1180c1bc742181ded4930842b46e9507372f0b1b963James Dong
1190c1bc742181ded4930842b46e9507372f0b1b963James Dong/* End of file */
1200c1bc742181ded4930842b46e9507372f0b1b963James Dong
121