aboutsummaryrefslogtreecommitdiff
path: root/encoder/svc/isvce_encode_header.h
blob: c443ed038139771fa00cea00e42b0ad7fc720f80 (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
/******************************************************************************
 *
 * Copyright (C) 2022 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
*  isvce_encode_header.h
*
* @brief
*  This file contains structures and interface prototypes for h264 bitstream
*  header encoding
*
* @author
*  ittiam
*
* @remarks
*  None
*
*******************************************************************************
*/

#ifndef _ISVCE_ENCODE_HEADER_H_
#define _ISVCE_ENCODE_HEADER_H_

#include "ih264_typedefs.h"

/* Dependencies of ih264e_bitstream.h */
#include "ih264e_error.h"

#include "ih264e_bitstream.h"
#include "ih264e_trace.h"
#include "isvce_structs.h"

/**
******************************************************************************
*  @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();                                            \
        ps_codec->au4_entropy_thread_active[ctxt_sel] = 0;      \
        return ps_entropy->i4_error_code;                       \
    }

/*****************************************************************************/
/* Extern Function Declarations                                              */
/*****************************************************************************/
extern WORD32 ih264e_generate_nal_unit_header(bitstrm_t *ps_bitstrm, WORD32 nal_unit_type,
                                              WORD32 nal_ref_idc);

extern WORD32 ih264e_generate_vui(bitstrm_t *ps_bitstrm, vui_t *ps_vui);

extern IH264E_ERROR_T ih264e_generate_sei(bitstrm_t *ps_bitstrm, sei_params_t *ps_sei,
                                          UWORD32 u4_insert_per_idr);

extern IH264E_ERROR_T ih264e_add_filler_nal_unit(bitstrm_t *ps_bitstrm, WORD32 insert_fill_bytes);

/**
******************************************************************************
*
* @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 isvce_generate_sps(bitstrm_t *ps_bitstrm, sps_t *ps_sps, NAL_UNIT_TYPE_T nal_type);

/**
******************************************************************************
*
* @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 isvce_generate_pps(bitstrm_t *ps_bitstrm, pps_t *ps_pps, sps_t *ps_sps);

/**
******************************************************************************
*
* @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 isvce_generate_slice_header(bitstrm_t *ps_bitstrm, slice_header_t *ps_slice_hdr,
                                   pps_t *ps_pps, sps_t *ps_sps, UWORD8 u1_idr_flag);
/**
******************************************************************************
*
* @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 isvce_populate_sps(isvce_codec_t *ps_codec, sps_t *ps_sps, UWORD8 u1_sps_id,
                                  UWORD8 u1_profile_idc, isvce_inp_buf_t *ps_inp_buf,
                                  UWORD8 u1_spatial_layer_id);

/**
******************************************************************************
*
* @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 isvce_populate_pps(isvce_codec_t *ps_codec, pps_t *ps_pps, UWORD8 u1_sps_id,
                                  UWORD8 u1_pps_id, UWORD8 u1_spatial_layer_id);

/**
******************************************************************************
*
* @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 isvce_populate_slice_header(isvce_process_ctxt_t *ps_proc, slice_header_t *ps_slice_hdr,
                                   pps_t *ps_pps, sps_t *ps_sps, UWORD8 u1_is_idr);

extern WORD32 isvce_populate_svc_nalu_extension(isvce_process_ctxt_t *ps_proc,
                                                svc_nalu_ext_t *ps_svc_nalu_ext,
                                                NAL_UNIT_TYPE_T nalu_type, UWORD8 u1_idr_flag);

extern WORD32 isvce_generate_svc_nalu_extension(bitstrm_t *ps_bitstrm,
                                                svc_nalu_ext_t *ps_svc_nalu_ext, UWORD8 u1_nalu_id);

extern WORD32 isvce_populate_svc_slice(isvce_process_ctxt_t *ps_proc,
                                       svc_slice_header_t *ps_svc_slice_hdr, pps_t *ps_pps,
                                       subset_sps_t *ps_subset_sps,
                                       svc_nalu_ext_t *ps_svc_nalu_ext);

extern WORD32 isvce_populate_subset_sps(isvce_codec_t *ps_codec, subset_sps_t *ps_subset_sps,
                                        UWORD8 u1_sps_id, isvce_inp_buf_t *ps_inp_buf,
                                        UWORD8 u1_spatial_layer_id);

extern WORD32 isvce_generate_prefix_nal(bitstrm_t *ps_bitstrm, svc_nalu_ext_t *ps_svc_nalu_ext,
                                        slice_header_t *ps_slice_header,
                                        UWORD8 u1_max_num_ref_frames, UWORD8 u1_num_spatial_layers);

extern WORD32 isvce_generate_slice_header_svc(bitstrm_t *ps_bitstrm, pps_t *ps_pps,
                                              svc_nalu_ext_t *ps_svc_nalu_ext,
                                              svc_slice_header_t *ps_svc_slice_hdr,
                                              subset_sps_t *ps_subset_sps);

extern WORD32 isvce_generate_subset_sps(bitstrm_t *ps_bitstrm, subset_sps_t *ps_subset_sps);

#endif