xref: /aosp_15_r20/external/libavc/encoder/ih264e_encode_header.h (revision 495ae853bb871d1e5a258cb02c2cc13cde8ddb9a)
1 /******************************************************************************
2  *
3  * Copyright (C) 2015 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 
21 /**
22 ******************************************************************************
23 * @file
24 *  ih264e_encode_header.h
25 *
26 * @brief
27 *  This file contains structures and interface prototypes for h264 bitstream
28 *  header encoding
29 *
30 * @author
31 *  ittiam
32 *
33 * @remarks
34 *  none
35 *
36 *******************************************************************************
37 */
38 
39 #ifndef _IH264E_ENCODE_HEADER_H_
40 #define _IH264E_ENCODE_HEADER_H_
41 
42 /*****************************************************************************/
43 /* Function Macros                                                           */
44 /*****************************************************************************/
45 
46 /**
47 ******************************************************************************
48  *  @brief   Macro to put a code with specified number of bits into the
49  *           bitstream
50 ******************************************************************************
51  */
52 #define PUT_BITS(ps_bitstrm, code_val, code_len, ret_val, syntax_string)     \
53         {                                                                    \
54             ENTROPY_TRACE(syntax_string, code_val);                          \
55             ret_val = ih264e_put_bits((ps_bitstrm), (code_val), (code_len)); \
56             if(ret_val != IH264E_SUCCESS)                                    \
57             {                                                                \
58                 return ret_val;                                              \
59             }                                                                \
60         }
61 
62 /**
63 ******************************************************************************
64  *  @brief   Macro to put a code with specified number of bits into the
65  *           bitstream using 0th order exponential Golomb encoding for
66  *           signed numbers
67 ******************************************************************************
68  */
69 #define PUT_BITS_UEV(ps_bitstrm, code_val, ret_val, syntax_string)           \
70         {                                                                    \
71             ENTROPY_TRACE(syntax_string, code_val);                          \
72             ret_val = ih264e_put_uev((ps_bitstrm), (code_val));              \
73             if(ret_val != IH264E_SUCCESS)                                    \
74             {                                                                \
75                 return ret_val;                                              \
76             }                                                                \
77         }
78 /**
79 ******************************************************************************
80  *  @brief   Macro to put a code with specified number of bits into the
81  *           bitstream using 0th order exponential Golomb encoding for
82  *           signed numbers
83 ******************************************************************************
84  */
85 #define PUT_BITS_SEV(ps_bitstrm, code_val, ret_val, syntax_string)           \
86         {                                                                    \
87             ENTROPY_TRACE(syntax_string, code_val);                          \
88             ret_val = ih264e_put_sev((ps_bitstrm), (code_val));              \
89             if(ret_val != IH264E_SUCCESS)                                    \
90             {                                                                \
91                 return ret_val;                                              \
92             }                                                                \
93         }
94 
95 /**
96 ******************************************************************************
97  *  @brief   Macro to set active entropy threads to zero and return
98  *           in case of errors
99 ******************************************************************************
100  */
101 #define RETURN_ENTROPY_IF_ERROR(ps_codec, ps_entropy, ctxt_sel)              \
102         if(ps_entropy->i4_error_code != IH264E_SUCCESS)                      \
103         {                                                                    \
104             DATA_SYNC();                                                     \
105             return ps_entropy->i4_error_code;                                \
106         }
107 
108 /*****************************************************************************/
109 /* Function Declarations                                                     */
110 /*****************************************************************************/
111 
112 WORD32 ih264e_generate_sps(bitstrm_t *ps_bitstrm, sps_t *ps_sps, vui_t *ps_vui);
113 
114 WORD32 ih264e_generate_pps(bitstrm_t *ps_bitstrm, pps_t *ps_pps, sps_t *ps_sps);
115 
116 IH264E_ERROR_T ih264e_generate_sei(bitstrm_t *ps_bitstrm,
117                                    sei_params_t *ps_sei,
118                                    UWORD32 u4_insert_per_idr);
119 
120 WORD32 ih264e_generate_slice_header(bitstrm_t *ps_bitstrm,
121                                     slice_header_t *ps_slice_hdr,
122                                     pps_t *ps_pps,
123                                     sps_t *ps_sps);
124 
125 IH264E_ERROR_T ih264e_populate_sps(codec_t *ps_codec, sps_t *ps_sps);
126 
127 IH264E_ERROR_T ih264e_populate_pps(codec_t *ps_codec, pps_t *ps_pps);
128 
129 WORD32 ih264e_populate_slice_header(process_ctxt_t *ps_proc,
130                                     slice_header_t *ps_slice_hdr,
131                                     pps_t *ps_pps,
132                                     sps_t *ps_sps);
133 
134 IH264E_ERROR_T ih264e_add_filler_nal_unit(bitstrm_t *ps_bitstrm,
135                                           WORD32 insert_fill_bytes);
136 
137 
138 #endif /* _IH264E_ENCODE_HEADER_H_ */
139