omxVCM4P2_EncodeVLCZigzag_Inter.c revision 78e52bfac041d71ce53b5b13c2abf78af742b09d
146f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham/*
246f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham * Copyright (C) 2007-2008 ARM Limited
346f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *
446f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham * Licensed under the Apache License, Version 2.0 (the "License");
546f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham * you may not use this file except in compliance with the License.
646f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham * You may obtain a copy of the License at
746f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *
846f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *      http://www.apache.org/licenses/LICENSE-2.0
946f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *
1046f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham * Unless required by applicable law or agreed to in writing, software
1146f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham * distributed under the License is distributed on an "AS IS" BASIS,
1246f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1346f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham * See the License for the specific language governing permissions and
1446f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham * limitations under the License.
1546f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *
1646f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham */
1746f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham/**
1846f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *
1946f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham * File Name:  omxVCM4P2_EncodeVLCZigzag_Inter.c
2013f378e738746800517f98b8561da315993c240aRoshan Pius * OpenMAX DL: v1.0.2
2146f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham * Revision:   9641
2246f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham * Date:       Thursday, February 7, 2008
2346f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *
2446f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *
2546f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *
2646f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *
2746f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham * Description:
2846f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham * Contains modules for zigzag scanning and VLC encoding
2946f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham * for inter block.
3046f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *
3146f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham */
3246f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham
3346f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham#include "omxtypes.h"
3446f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham#include "armOMX.h"
3546f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham#include "omxVC.h"
3646f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham
3746f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham#include "armVC.h"
3846f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham#include "armCOMM_Bitstream.h"
3946f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham#include "armCOMM.h"
4046f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham#include "armVCM4P2_Huff_Tables_VLC.h"
4146f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham#include "armVCM4P2_ZigZag_Tables.h"
4246f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham
4346f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham
4446f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham
4546f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham/**
4646f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham * Function:  omxVCM4P2_EncodeVLCZigzag_Inter   (6.2.4.5.3)
4746f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *
4846f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham * Description:
4946f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham * Performs classical zigzag scanning and VLC encoding for one inter block.
5046f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *
5146f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham * Input Arguments:
5246f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *
5346f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *   ppBitStream - pointer to the pointer to the current byte in the bit
5446f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *            stream
5513f378e738746800517f98b8561da315993c240aRoshan Pius *   pBitOffset - pointer to the bit position in the byte pointed by
5613f378e738746800517f98b8561da315993c240aRoshan Pius *            *ppBitStream. Valid within 0 to 7
5746f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *   pQDctBlkCoef - pointer to the quantized DCT coefficient
5846f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *   pattern - block pattern which is used to decide whether this block is
5946f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *            encoded
6046f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *   shortVideoHeader - binary flag indicating presence of
6146f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *            short_video_header; escape modes 0-3 are used if
6246f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *            shortVideoHeader==0, and escape mode 4 is used when
6346f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *            shortVideoHeader==1.
6446f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *
6546f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham * Output Arguments:
6646f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *
6746f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *   ppBitStream - *ppBitStream is updated after the block is encoded so that
6846f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *            it points to the current byte in the bit stream buffer.
6946f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *   pBitOffset - *pBitOffset is updated so that it points to the current bit
7046f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *            position in the byte pointed by *ppBitStream.
7146f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *
7246f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham * Return Value:
7346f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *
7446f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *    OMX_Sts_NoErr - no error
7546f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *    OMX_Sts_BadArgErr - Bad arguments
7646f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *    -    At least one of the pointers: is NULL: ppBitStream, *ppBitStream,
7746f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *              pBitOffset, pQDctBlkCoef
7846f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *    -   *pBitOffset < 0, or *pBitOffset >7.
7946f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham *
8046f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham */
8146f5f53d2838ec6f265c168100e21a22f990a97dPrerepa ViswanadhamOMXResult omxVCM4P2_EncodeVLCZigzag_Inter(
8246f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham     OMX_U8 **ppBitStream,
8313f378e738746800517f98b8561da315993c240aRoshan Pius     OMX_INT * pBitOffset,
8413f378e738746800517f98b8561da315993c240aRoshan Pius     const OMX_S16 *pQDctBlkCoef,
8513f378e738746800517f98b8561da315993c240aRoshan Pius     OMX_U8 pattern,
8613f378e738746800517f98b8561da315993c240aRoshan Pius	 OMX_INT shortVideoHeader
8713f378e738746800517f98b8561da315993c240aRoshan Pius)
8813f378e738746800517f98b8561da315993c240aRoshan Pius{
8913f378e738746800517f98b8561da315993c240aRoshan Pius    OMX_U8 start = 0;
9046f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham    const OMX_U8  *pZigzagTable = armVCM4P2_aClassicalZigzagScan;
9146f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham
9246f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham    /* Argument error checks */
9346f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham    armRetArgErrIf(ppBitStream == NULL, OMX_Sts_BadArgErr);
9446f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham    armRetArgErrIf(*ppBitStream == NULL, OMX_Sts_BadArgErr);
9546f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham    armRetArgErrIf(pBitOffset == NULL, OMX_Sts_BadArgErr);
9646f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham    armRetArgErrIf(pQDctBlkCoef == NULL, OMX_Sts_BadArgErr);
9746f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham    armRetArgErrIf((*pBitOffset < 0) || (*pBitOffset >7), OMX_Sts_BadArgErr);
9846f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham
9946f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham    if (pattern)
10046f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham    {
10146f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham        armVCM4P2_PutVLCBits (
10246f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham              ppBitStream,
10346f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham              pBitOffset,
10446f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham              pQDctBlkCoef,
10546f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham              shortVideoHeader,
10646f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham              start,
10746f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham              26,
10846f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham              40,
10946f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham              10,
11046f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham              1,
11146f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham              armVCM4P2_InterL0RunIdx,
11246f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham              armVCM4P2_InterVlcL0,
11346f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham			  armVCM4P2_InterL1RunIdx,
11446f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham              armVCM4P2_InterVlcL1,
11546f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham              armVCM4P2_InterL0LMAX,
11646f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham              armVCM4P2_InterL1LMAX,
11746f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham              armVCM4P2_InterL0RMAX,
11846f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham              armVCM4P2_InterL1RMAX,
11946f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham              pZigzagTable
12046f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham        );
12146f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham    } /* Pattern check ends*/
12246f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham
12313f378e738746800517f98b8561da315993c240aRoshan Pius    return OMX_Sts_NoErr;
12413f378e738746800517f98b8561da315993c240aRoshan Pius
12546f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham}
12646f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham
12746f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham/* End of file */
12846f5f53d2838ec6f265c168100e21a22f990a97dPrerepa Viswanadham