178e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar/*
278e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * Copyright (C) 2007-2008 ARM Limited
378e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *
478e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * Licensed under the Apache License, Version 2.0 (the "License");
578e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * you may not use this file except in compliance with the License.
678e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * You may obtain a copy of the License at
778e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *
878e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *      http://www.apache.org/licenses/LICENSE-2.0
978e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *
1078e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * Unless required by applicable law or agreed to in writing, software
1178e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * distributed under the License is distributed on an "AS IS" BASIS,
1278e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1378e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * See the License for the specific language governing permissions and
1478e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * limitations under the License.
1578e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *
1678e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar */
170c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
180c1bc742181ded4930842b46e9507372f0b1b963James Dong *
190c1bc742181ded4930842b46e9507372f0b1b963James Dong * File Name:  armCOMM_Bitstream.h
200c1bc742181ded4930842b46e9507372f0b1b963James Dong * OpenMAX DL: v1.0.2
210c1bc742181ded4930842b46e9507372f0b1b963James Dong * Revision:   12290
220c1bc742181ded4930842b46e9507372f0b1b963James Dong * Date:       Wednesday, April 9, 2008
230c1bc742181ded4930842b46e9507372f0b1b963James Dong *
240c1bc742181ded4930842b46e9507372f0b1b963James Dong *
250c1bc742181ded4930842b46e9507372f0b1b963James Dong *
260c1bc742181ded4930842b46e9507372f0b1b963James Dong *
270c1bc742181ded4930842b46e9507372f0b1b963James Dong * File: armCOMM_Bitstream.h
280c1bc742181ded4930842b46e9507372f0b1b963James Dong * Brief: Declares common API's/Data types used across the OpenMax Encoders/Decoders.
290c1bc742181ded4930842b46e9507372f0b1b963James Dong *
300c1bc742181ded4930842b46e9507372f0b1b963James Dong */
310c1bc742181ded4930842b46e9507372f0b1b963James Dong
320c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifndef _armCodec_H_
330c1bc742181ded4930842b46e9507372f0b1b963James Dong#define _armCodec_H_
340c1bc742181ded4930842b46e9507372f0b1b963James Dong
350c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxtypes.h"
360c1bc742181ded4930842b46e9507372f0b1b963James Dong
370c1bc742181ded4930842b46e9507372f0b1b963James Dongtypedef struct {
380c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_U8   codeLen;
390c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_U32	 codeWord;
400c1bc742181ded4930842b46e9507372f0b1b963James Dong} ARM_VLC32;
410c1bc742181ded4930842b46e9507372f0b1b963James Dong
420c1bc742181ded4930842b46e9507372f0b1b963James Dong/* The above should be renamed as "ARM_VLC32" */
430c1bc742181ded4930842b46e9507372f0b1b963James Dong
440c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
450c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armLookAheadBits()
460c1bc742181ded4930842b46e9507372f0b1b963James Dong *
470c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
480c1bc742181ded4930842b46e9507372f0b1b963James Dong * Get the next N bits from the bitstream without advancing the bitstream pointer
490c1bc742181ded4930842b46e9507372f0b1b963James Dong *
500c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
510c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]     **ppBitStream
520c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]     *pOffset
530c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]     N=1...32
540c1bc742181ded4930842b46e9507372f0b1b963James Dong *
550c1bc742181ded4930842b46e9507372f0b1b963James Dong * Returns  Value
560c1bc742181ded4930842b46e9507372f0b1b963James Dong */
570c1bc742181ded4930842b46e9507372f0b1b963James Dong
580c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_U32 armLookAheadBits(const OMX_U8 **ppBitStream, OMX_INT *pOffset, OMX_INT N);
590c1bc742181ded4930842b46e9507372f0b1b963James Dong
600c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
610c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armGetBits()
620c1bc742181ded4930842b46e9507372f0b1b963James Dong *
630c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
640c1bc742181ded4930842b46e9507372f0b1b963James Dong * Read N bits from the bitstream
650c1bc742181ded4930842b46e9507372f0b1b963James Dong *
660c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
670c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]     *ppBitStream
680c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]     *pOffset
690c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]     N=1..32
700c1bc742181ded4930842b46e9507372f0b1b963James Dong *
710c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out]    *ppBitStream
720c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out]    *pOffset
730c1bc742181ded4930842b46e9507372f0b1b963James Dong * Returns  Value
740c1bc742181ded4930842b46e9507372f0b1b963James Dong */
750c1bc742181ded4930842b46e9507372f0b1b963James Dong
760c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_U32 armGetBits(const OMX_U8 **ppBitStream, OMX_INT *pOffset, OMX_INT N);
770c1bc742181ded4930842b46e9507372f0b1b963James Dong
780c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
790c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armByteAlign()
800c1bc742181ded4930842b46e9507372f0b1b963James Dong *
810c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
820c1bc742181ded4930842b46e9507372f0b1b963James Dong * Align the pointer *ppBitStream to the next byte boundary
830c1bc742181ded4930842b46e9507372f0b1b963James Dong *
840c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
850c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]     *ppBitStream
860c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]     *pOffset
870c1bc742181ded4930842b46e9507372f0b1b963James Dong *
880c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out]    *ppBitStream
890c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out]    *pOffset
900c1bc742181ded4930842b46e9507372f0b1b963James Dong *
910c1bc742181ded4930842b46e9507372f0b1b963James Dong **/
920c1bc742181ded4930842b46e9507372f0b1b963James Dong
930c1bc742181ded4930842b46e9507372f0b1b963James DongOMXVoid armByteAlign(const OMX_U8 **ppBitStream,OMX_INT *pOffset);
940c1bc742181ded4930842b46e9507372f0b1b963James Dong
950c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
960c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armSkipBits()
970c1bc742181ded4930842b46e9507372f0b1b963James Dong *
980c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
990c1bc742181ded4930842b46e9507372f0b1b963James Dong * Skip N bits from the value at *ppBitStream
1000c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1010c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
1020c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]     *ppBitStream
1030c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]     *pOffset
1040c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]     N
1050c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1060c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out]    *ppBitStream
1070c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out]    *pOffset
1080c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1090c1bc742181ded4930842b46e9507372f0b1b963James Dong **/
1100c1bc742181ded4930842b46e9507372f0b1b963James Dong
1110c1bc742181ded4930842b46e9507372f0b1b963James DongOMXVoid armSkipBits(const OMX_U8 **ppBitStream,OMX_INT *pOffset,OMX_INT N);
1120c1bc742181ded4930842b46e9507372f0b1b963James Dong
1130c1bc742181ded4930842b46e9507372f0b1b963James Dong/***************************************
1140c1bc742181ded4930842b46e9507372f0b1b963James Dong * Variable bit length Decode
1150c1bc742181ded4930842b46e9507372f0b1b963James Dong ***************************************/
1160c1bc742181ded4930842b46e9507372f0b1b963James Dong
1170c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
1180c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armUnPackVLC32()
1190c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1200c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
1210c1bc742181ded4930842b46e9507372f0b1b963James Dong * Variable length decode of variable length symbol (max size 32 bits) read from
1220c1bc742181ded4930842b46e9507372f0b1b963James Dong * the bit stream pointed by *ppBitStream at *pOffset by using the table
1230c1bc742181ded4930842b46e9507372f0b1b963James Dong * pointed by pCodeBook
1240c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1250c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
1260c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]     **ppBitStream
1270c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]     *pOffset
1280c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]     pCodeBook
1290c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1300c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out]    **ppBitStream
1310c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out]    *pOffset
1320c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1330c1bc742181ded4930842b46e9507372f0b1b963James Dong * Returns : Code Book Index if successfull.
1340c1bc742181ded4930842b46e9507372f0b1b963James Dong *         : "ARM_NO_CODEBOOK_INDEX = 0xFFFF" if search fails.
1350c1bc742181ded4930842b46e9507372f0b1b963James Dong **/
1360c1bc742181ded4930842b46e9507372f0b1b963James Dong
1370c1bc742181ded4930842b46e9507372f0b1b963James Dong#define ARM_NO_CODEBOOK_INDEX (OMX_U16)(0xFFFF)
1380c1bc742181ded4930842b46e9507372f0b1b963James Dong
1390c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_U16 armUnPackVLC32(
1400c1bc742181ded4930842b46e9507372f0b1b963James Dong    const OMX_U8 **ppBitStream,
1410c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_INT *pOffset,
1420c1bc742181ded4930842b46e9507372f0b1b963James Dong    const ARM_VLC32 *pCodeBook
1430c1bc742181ded4930842b46e9507372f0b1b963James Dong);
1440c1bc742181ded4930842b46e9507372f0b1b963James Dong
1450c1bc742181ded4930842b46e9507372f0b1b963James Dong/***************************************
1460c1bc742181ded4930842b46e9507372f0b1b963James Dong * Fixed bit length Encode
1470c1bc742181ded4930842b46e9507372f0b1b963James Dong ***************************************/
1480c1bc742181ded4930842b46e9507372f0b1b963James Dong
1490c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
1500c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armPackBits
1510c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1520c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
1530c1bc742181ded4930842b46e9507372f0b1b963James Dong * Pack a VLC code word into the bitstream
1540c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1550c1bc742181ded4930842b46e9507372f0b1b963James Dong * Remarks:
1560c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1570c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
1580c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]	ppBitStream		pointer to the pointer to the current byte
1590c1bc742181ded4930842b46e9507372f0b1b963James Dong *                      in the bit stream.
1600c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]	pOffset	        pointer to the bit position in the byte
1610c1bc742181ded4930842b46e9507372f0b1b963James Dong *                      pointed by *ppBitStream. Valid within 0
1620c1bc742181ded4930842b46e9507372f0b1b963James Dong *                      to 7.
1630c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]	codeWord		Code word that need to be inserted in to the
1640c1bc742181ded4930842b46e9507372f0b1b963James Dong *                          bitstream
1650c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]	codeLength		Length of the code word valid range 1...32
1660c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1670c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out] ppBitStream	*ppBitStream is updated after the block is encoded,
1680c1bc742181ded4930842b46e9507372f0b1b963James Dong *	                        so that it points to the current byte in the bit
1690c1bc742181ded4930842b46e9507372f0b1b963James Dong *							stream buffer.
1700c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out] pBitOffset		*pBitOffset is updated so that it points to the
1710c1bc742181ded4930842b46e9507372f0b1b963James Dong *							current bit position in the byte pointed by
1720c1bc742181ded4930842b46e9507372f0b1b963James Dong *							*ppBitStream.
1730c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1740c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
1750c1bc742181ded4930842b46e9507372f0b1b963James Dong * Standard OMX_RESULT result. See enumeration for possible result codes.
1760c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1770c1bc742181ded4930842b46e9507372f0b1b963James Dong */
1780c1bc742181ded4930842b46e9507372f0b1b963James Dong
1790c1bc742181ded4930842b46e9507372f0b1b963James DongOMXResult armPackBits (
1800c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_U8  **ppBitStream,
1810c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_INT *pOffset,
1820c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_U32 codeWord,
1830c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_INT codeLength
1840c1bc742181ded4930842b46e9507372f0b1b963James Dong);
1850c1bc742181ded4930842b46e9507372f0b1b963James Dong
1860c1bc742181ded4930842b46e9507372f0b1b963James Dong/***************************************
1870c1bc742181ded4930842b46e9507372f0b1b963James Dong * Variable bit length Encode
1880c1bc742181ded4930842b46e9507372f0b1b963James Dong ***************************************/
1890c1bc742181ded4930842b46e9507372f0b1b963James Dong
1900c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
1910c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armPackVLC32
1920c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1930c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
1940c1bc742181ded4930842b46e9507372f0b1b963James Dong * Pack a VLC code word into the bitstream
1950c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1960c1bc742181ded4930842b46e9507372f0b1b963James Dong * Remarks:
1970c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1980c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
1990c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]	ppBitStream		pointer to the pointer to the current byte
2000c1bc742181ded4930842b46e9507372f0b1b963James Dong *                      in the bit stream.
2010c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]	pBitOffset	    pointer to the bit position in the byte
2020c1bc742181ded4930842b46e9507372f0b1b963James Dong *                      pointed by *ppBitStream. Valid within 0
2030c1bc742181ded4930842b46e9507372f0b1b963James Dong *                      to 7.
2040c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]	 code     		VLC code word that need to be inserted in to the
2050c1bc742181ded4930842b46e9507372f0b1b963James Dong *                      bitstream
2060c1bc742181ded4930842b46e9507372f0b1b963James Dong *
2070c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out] ppBitStream	*ppBitStream is updated after the block is encoded,
2080c1bc742181ded4930842b46e9507372f0b1b963James Dong *	                    so that it points to the current byte in the bit
2090c1bc742181ded4930842b46e9507372f0b1b963James Dong *						stream buffer.
2100c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out] pBitOffset		*pBitOffset is updated so that it points to the
2110c1bc742181ded4930842b46e9507372f0b1b963James Dong *						current bit position in the byte pointed by
2120c1bc742181ded4930842b46e9507372f0b1b963James Dong *						*ppBitStream.
2130c1bc742181ded4930842b46e9507372f0b1b963James Dong *
2140c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
2150c1bc742181ded4930842b46e9507372f0b1b963James Dong * Standard OMX_RESULT result. See enumeration for possible result codes.
2160c1bc742181ded4930842b46e9507372f0b1b963James Dong *
2170c1bc742181ded4930842b46e9507372f0b1b963James Dong */
2180c1bc742181ded4930842b46e9507372f0b1b963James Dong
2190c1bc742181ded4930842b46e9507372f0b1b963James DongOMXResult armPackVLC32 (
2200c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_U8 **ppBitStream,
2210c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_INT *pBitOffset,
2220c1bc742181ded4930842b46e9507372f0b1b963James Dong    ARM_VLC32 code
2230c1bc742181ded4930842b46e9507372f0b1b963James Dong);
2240c1bc742181ded4930842b46e9507372f0b1b963James Dong
2250c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif      /*_armCodec_H_*/
2260c1bc742181ded4930842b46e9507372f0b1b963James Dong
2270c1bc742181ded4930842b46e9507372f0b1b963James Dong/*End of File*/
228