aboutsummaryrefslogtreecommitdiff
path: root/encoder/ih264e_encode_header.h
blob: c4876b38cccbea6d0a4921bebadfefbbb2306b76 (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/******************************************************************************
 *
 * Copyright (C) 2015 The Android Open Source Project
 *
 * 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.
 *
 *****************************************************************************
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
*/

/**
******************************************************************************
* @file
*  ih264e_encode_header.h
*
* @brief
*  This file contains structures and interface prototypes for h264 bitstream
*  header encoding
*
* @author
*  ittiam
*
* @remarks
*  None
*
*******************************************************************************
*/

#ifndef IH264E_ENCODE_HEADER_H_
#define IH264E_ENCODE_HEADER_H_

/*****************************************************************************/
/* Function Macros                                                           */
/*****************************************************************************/

/**
******************************************************************************
 *  @brief   Macro to put a code with specified number of bits into the
 *           bitstream
******************************************************************************
 */
#define PUT_BITS(ps_bitstrm, code_val, code_len, ret_val, syntax_string)     \
        {                                                                    \
            ENTROPY_TRACE(syntax_string, code_val);                          \
            ret_val = ih264e_put_bits((ps_bitstrm), (code_val), (code_len)); \
            if(ret_val != IH264E_SUCCESS)                                    \
            {                                                                \
                return ret_val;                                              \
            }                                                                \
        }

/**
******************************************************************************
 *  @brief   Macro to put a code with specified number of bits into the
 *           bitstream using 0th order exponential Golomb encoding for
 *           signed numbers
******************************************************************************
 */
#define PUT_BITS_UEV(ps_bitstrm, code_val, ret_val, syntax_string)           \
        {                                                                    \
            ENTROPY_TRACE(syntax_string, code_val);                          \
            ret_val = ih264e_put_uev((ps_bitstrm), (code_val));              \
            if(ret_val != IH264E_SUCCESS)                                    \
            {                                                                \
                return ret_val;                                              \
            }                                                                \
        }
/**
******************************************************************************
 *  @brief   Macro to put a code with specified number of bits into the
 *           bitstream using 0th order exponential Golomb encoding for
 *           signed numbers
******************************************************************************
 */
#define PUT_BITS_SEV(ps_bitstrm, code_val, ret_val, syntax_string)           \
        {                                                                    \
            ENTROPY_TRACE(syntax_string, code_val);                          \
            ret_val = ih264e_put_sev((ps_bitstrm), (code_val));              \
            if(ret_val != IH264E_SUCCESS)                                    \
            {                                                                \
                return ret_val;                                              \
            }                                                                \
        }

/**
******************************************************************************
 *  @brief   Macro to set active entropy threads to zero and return
 *           in case of errors
******************************************************************************
 */
#define RETURN_ENTROPY_IF_ERROR(ps_codec, ps_entropy, ctxt_sel)              \
        if(ps_entropy->i4_error_code != IH264E_SUCCESS)                      \
        {                                                                    \
            DATA_SYNC();                                                     \
            return ps_entropy->i4_error_code;                                \
        }

/*****************************************************************************/
/* Extern Function Declarations                                              */
/*****************************************************************************/

/**
******************************************************************************
*
* @brief Generates SPS (Sequence Parameter Set)
*
* @par   Description
*  This function generates Sequence Parameter Set header as per the spec
*
* @param[in]   ps_bitstrm
*  pointer to bitstream context (handle)
*
* @param[in]   ps_sps
*  pointer to structure containing SPS data
*
* @return      success or failure error code
*
******************************************************************************
*/
WORD32      ih264e_generate_sps
    (
        bitstrm_t   *ps_bitstrm,
        sps_t       *ps_sps,
        vui_t       *ps_vui
    );

/**
******************************************************************************
*
* @brief Generates PPS (Picture Parameter Set)
*
* @par   Description
*  Generate Picture Parameter Set as per Section 7.3.2.2
*
* @param[in]   ps_bitstrm
*  pointer to bitstream context (handle)
*
* @param[in]   ps_pps
*  pointer to structure containing PPS data
*
* @return      success or failure error code
*
******************************************************************************
*/
WORD32      ih264e_generate_pps
    (
        bitstrm_t   *ps_bitstrm,
        pps_t       *ps_pps,
        sps_t       *ps_sps
    );

/**
******************************************************************************
*
* @brief Generates SEI (Supplemental Enhancement Information)
*
* @par   Description
*  This function generates Supplemental Enhancement Information header as per the spec
*
* @param[in]   ps_bitstrm
*  pointer to bitstream context (handle)
*
* @param[in]   ps_sei
*  pointer to structure containing SEI data
*
* @return      success or failure error code
*
******************************************************************************
*/
IH264E_ERROR_T      ih264e_generate_sei
    (
        bitstrm_t     *ps_bitstrm,
        sei_params_t  *ps_sei,
        UWORD32        u4_insert_per_idr
    );

/**
******************************************************************************
*
* @brief Generates Slice Header
*
* @par   Description
*  Generate Slice Header as per Section 7.3.5.1
*
* @param[inout]   ps_bitstrm
*  pointer to bitstream context for generating slice header
*
* @param[in]   ps_slice_hdr
*  pointer to slice header params
*
* @param[in]   ps_pps
*  pointer to pps params referred by slice
*
* @param[in]   ps_sps
*  pointer to sps params referred by slice
*
* @param[out]   ps_dup_bit_strm_ent_offset
*  Bitstream struct to store bitstream state
*
* @param[out]   pu4_first_slice_start_offset
*  first slice offset is returned
*
* @return      success or failure error code
*
******************************************************************************
*/
WORD32      ih264e_generate_slice_header
    (
        bitstrm_t       *ps_bitstrm,
        slice_header_t  *ps_slice_hdr,
        pps_t           *ps_pps,
        sps_t           *ps_sps
    );

/**
******************************************************************************
*
* @brief Populates sps structure
*
* @par   Description
*  Populates sps structure for its use in header generation
*
* @param[in]   ps_codec
*  pointer to encoder context
*
* @param[out]  ps_sps
*  pointer to sps params that needs to be populated
*
* @return      success or failure error code
*
******************************************************************************
*/
IH264E_ERROR_T      ih264e_populate_sps
        (
            codec_t *ps_codec,
            sps_t   *ps_sps
        );

/**
******************************************************************************
*
* @brief Populates pps structure
*
* @par   Description
*  Populates pps structure for its use in header generation
*
* @param[in]   ps_codec
*  pointer to encoder context
*
* @param[out]  ps_pps
*  pointer to pps params that needs to be populated
*
* @return      success or failure error code
*
******************************************************************************
*/
IH264E_ERROR_T ih264e_populate_pps
        (
            codec_t *ps_codec,
            pps_t *ps_pps
        );


/**
******************************************************************************
*
* @brief Populates slice header structure
*
* @par   Description
*  Populates slice header structure for its use in header generation
*
* @param[in]  ps_proc
*  pointer to proc context
*
* @param[out]  ps_slice_hdr
*  pointer to slice header structure that needs to be populated
*
* @param[in]  ps_pps
*  pointer to pps params structure referred by the slice
*
* @param[in]   ps_sps
*  pointer to sps params referred by the pps
*
* @return      success or failure error code
*
******************************************************************************
*/
WORD32 ih264e_populate_slice_header
        (
            process_ctxt_t *ps_proc,
            slice_header_t *ps_slice_hdr,
            pps_t *ps_pps,
            sps_t *ps_sps
        );


/**
******************************************************************************
*
* @brief inserts FILLER Nal Unit.
*
* @par   Description
*  In constant bit rate rc mode, when the bits generated by the codec is
*  underflowing the target bit rate, the encoder library inserts filler nal unit.
*
* @param[in]    ps_bitstrm
*  pointer to bitstream context (handle)
*
* @param[in]    insert_fill_bytes
*  Number of fill bytes to be inserted
*
* @return      success or failure error code
*
******************************************************************************
*/
IH264E_ERROR_T ih264e_add_filler_nal_unit
        (
            bitstrm_t   *ps_bitstrm,
            WORD32      insert_fill_bytes
        );


#endif //IH264E_ENCODE_HEADER_H_