summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/codecs/avc/dec/src/avcdec_bitstream.h
blob: bd1bc59327230c3832577ad8b8347eeb660798d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* ------------------------------------------------------------------
 * Copyright (C) 1998-2009 PacketVideo
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 * -------------------------------------------------------------------
 */
/**
This file contains bitstream related functions.
@publishedAll
*/

#ifndef _AVCDEC_BITSTREAM_H_
#define _AVCDEC_BITSTREAM_H_

#include "avcdec_lib.h"

#define WORD_SIZE   32  /* this can vary, default to 32 bit for now */

#ifndef __cplusplus

#define AVC_GETDATA(x,y)   userData->AVC_GetData(x,y)

#endif

#ifdef __cplusplus
extern "C"
{
#endif
#define BitstreamFlushBits(A,B)     {(A)->bitcnt += (B); (A)->incnt -= (B); (A)->curr_word <<= (B);}

    AVCDec_Status AVC_BitstreamFillCache(AVCDecBitstream *stream);
    /**
    This function populates bitstream structure.
    \param "stream" "Pointer to bitstream structure."
    \param "buffer" "Pointer to the bitstream buffer."
    \param "size"   "Size of the buffer."
    \param "nal_size"   "Size of the NAL unit."
    \param "resetall"   "Flag for reset everything."
    \return "AVCDEC_SUCCESS for success and AVCDEC_FAIL for fail."
    */
    AVCDec_Status BitstreamInit(AVCDecBitstream *stream, uint8 *buffer, int size);

    /**
    This function reads next aligned word and remove the emulation prevention code
    if necessary.
    \param "stream" "Pointer to bitstream structure."
    \return "Next word."
    */
    uint BitstreamNextWord(AVCDecBitstream *stream);

    /**
    This function reads nBits bits from the current position and advance the pointer.
    \param "stream" "Pointer to bitstream structure."
    \param "nBits" "Number of bits to be read."
    \param "code"   "Point to the read value."
    \return "AVCDEC_SUCCESS if successed, AVCDEC_FAIL if number of bits
                is greater than the word-size, AVCDEC_PACKET_LOSS or
                AVCDEC_NO_DATA if callback to get data fails."
    */
    AVCDec_Status BitstreamReadBits(AVCDecBitstream *stream, int nBits, uint *code);

    /**
    This function shows nBits bits from the current position without advancing the pointer.
    \param "stream" "Pointer to bitstream structure."
    \param "nBits" "Number of bits to be read."
    \param "code"   "Point to the read value."
    \return "AVCDEC_SUCCESS if successed, AVCDEC_FAIL if number of bits
                    is greater than the word-size, AVCDEC_NO_DATA if it needs
                    to callback to get data."
    */
    AVCDec_Status BitstreamShowBits(AVCDecBitstream *stream, int nBits, uint *code);


    /**
    This function flushes nBits bits from the current position.
    \param "stream" "Pointer to bitstream structure."
    \param "nBits" "Number of bits to be read."
    \return "AVCDEC_SUCCESS if successed, AVCDEC_FAIL if number of bits
                    is greater than the word-size It will not call back to get
                   more data. Users should call BitstreamShowBits to determine
                   how much they want to flush."
    */

    /**
    This function read 1 bit from the current position and advance the pointer.
    \param "stream" "Pointer to bitstream structure."
    \param "nBits" "Number of bits to be read."
    \param "code"   "Point to the read value."
    \return "AVCDEC_SUCCESS if successed, AVCDEC_FAIL if number of bits
                is greater than the word-size, AVCDEC_PACKET_LOSS or
                AVCDEC_NO_DATA if callback to get data fails."
    */
    AVCDec_Status BitstreamRead1Bit(AVCDecBitstream *stream, uint *code);

    /**
    This function checks whether the current bit position is byte-aligned or not.
    \param "stream" "Pointer to the bitstream structure."
    \return "TRUE if byte-aligned, FALSE otherwise."
    */
    bool byte_aligned(AVCDecBitstream *stream);
    AVCDec_Status BitstreamByteAlign(AVCDecBitstream  *stream);
    /**
    This function checks whether there are more RBSP data before the trailing bits.
    \param "stream" "Pointer to the bitstream structure."
    \return "TRUE if yes, FALSE otherwise."
    */
    bool more_rbsp_data(AVCDecBitstream *stream);


#ifdef __cplusplus
}
#endif /* __cplusplus  */

#endif /* _AVCDEC_BITSTREAM_H_ */