1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16/**
17 ************************************************************************
18 * @file   M4_BitStreamParser.h
19 * @brief  MPEG-4 File Format bit stream utility
20 * @note   This file contains utility functions used to parse MPEG specific
21 *         data structures.
22 ************************************************************************
23*/
24#ifndef __M4_BITSTREAMPARSER_H__
25#define __M4_BITSTREAMPARSER_H__
26
27#include "M4OSA_Types.h"
28
29/**
30* M4_BitStreamParser_Init.
31*
32* Allocates the context and initializes internal data
33*
34* @param pContext   : A pointer to the context internally used by the package - ALLOCATED BY THE
35*                    FUNCTION (M4OSA_NULL if allocation fails)
36* @param bitStream  : A pointer to the bitstream - must be 32 bits as access are 32 bits
37* @param size        : The size of the bitstream in bytes
38*
39*/
40void M4_BitStreamParser_Init(void** pContext, void* pBitStream, M4OSA_Int32 size);
41
42/**
43 ************************************************************************
44 * @brief    Clean up context
45 * @param    pContext    (IN/OUT)  M4_BitStreamParser context.
46 ************************************************************************
47*/
48void M4_BitStreamParser_CleanUp(void* pContext);
49
50/**
51 ************************************************************************
52 * @brief    Read the next <length> bits in the bitstream.
53 * @note    The function does not update the bitstream pointer.
54 * @param    pContext    (IN/OUT) M4_BitStreamParser context.
55 * @param    length        (IN) The number of bits to extract from the bitstream
56 * @return    the read bits
57 ************************************************************************
58*/
59M4OSA_UInt32 M4_BitStreamParser_ShowBits(void* pContext, M4OSA_Int32 length);
60
61/**
62 ************************************************************************
63 * @brief    Increment the bitstream pointer of <length> bits.
64 * @param    pContext    (IN/OUT) M4_BitStreamParser context.
65 * @param    length        (IN) The number of bit to shift the bitstream
66 ************************************************************************
67*/
68void M4_BitStreamParser_FlushBits(void* pContext, M4OSA_Int32 length);
69
70/**
71 ************************************************************************
72 * @brief    Get a pointer to the current byte pointed by the bitstream pointer.
73 * It does not update the bitstream pointer
74 *
75 * @param pContext   : A pointer to the context internally used by the package
76 * @param length        : The number of bit to extract from the bitstream
77 *
78 * @returns the read bits
79*/
80M4OSA_UInt32 M4_BitStreamParser_GetBits(void* pContext,M4OSA_Int32 bitPos, M4OSA_Int32 length);
81
82/**
83* M4_BitStreamParser_Restart resets the bitstream indexes.
84*
85* @param pContext   : A pointer to the context internally used by the package
86*
87*/
88void M4_BitStreamParser_Restart(void* pContext);
89
90/**
91 ************************************************************************
92 * @brief    Get a pointer to the current byte pointed by the bitstream pointer.
93 * @returns pointer to the current location in the bitstream
94 * @note    It should be used carefully as the pointer is in the bitstream itself
95 *            and no copy is made.
96 * @param    pContext    (IN/OUT)  M4_BitStreamParser context.
97*/
98M4OSA_UInt8*  M4_BitStreamParser_GetCurrentbitStreamPointer(void* pContext);
99
100/**
101* M4_BitStreamParser_GetSize gets the size of the bitstream in bytes
102*
103* @param pContext   : A pointer to the context internally used by the package
104*
105* @returns the size of the bitstream in bytes
106*/
107M4OSA_Int32 M4_BitStreamParser_GetSize(void* pContext);
108
109void M4_MPEG4BitStreamParser_Init(void** pContext, void* pBitStream, M4OSA_Int32 size);
110
111/**
112* getMpegLengthFromInteger returns a decoded size value from an encoded one (SDL)
113*
114* @param pContext   : A pointer to the context internally used by the package
115* @param val : encoded value
116*
117* @returns size in a human readable form
118*/
119
120M4OSA_Int32 M4_MPEG4BitStreamParser_GetMpegLengthFromInteger(void* pContext, M4OSA_UInt32 val);
121
122
123/**
124 ************************************************************************
125 * @brief    Decode an MPEG4 Systems descriptor size from an encoded SDL size data.
126 * @note    The value is read from the current bitstream location.
127 * @param    pContext    (IN/OUT)  M4_BitStreamParser context.
128 * @return    Size in a human readable form
129 ************************************************************************
130*/
131M4OSA_Int32 M4_MPEG4BitStreamParser_GetMpegLengthFromStream(void* pContext);
132
133#endif /*__M4_BITSTREAMPARSER_H__*/
134
135