1 /****************************************************************************** 2 * 3 * Copyright (C) 2022 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 * isvce_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 _ISVCE_ENCODE_HEADER_H_ 40 #define _ISVCE_ENCODE_HEADER_H_ 41 42 #include "ih264_typedefs.h" 43 44 /* Dependencies of ih264e_bitstream.h */ 45 #include "ih264e_error.h" 46 47 #include "ih264e_bitstream.h" 48 #include "ih264e_trace.h" 49 #include "isvce_structs.h" 50 51 /** 52 ****************************************************************************** 53 * @brief Macro to put a code with specified number of bits into the 54 * bitstream 55 ****************************************************************************** 56 */ 57 #define PUT_BITS(ps_bitstrm, code_val, code_len, ret_val, syntax_string) \ 58 { \ 59 ENTROPY_TRACE(syntax_string, code_val); \ 60 ret_val = ih264e_put_bits((ps_bitstrm), (code_val), (code_len)); \ 61 if(ret_val != IH264E_SUCCESS) \ 62 { \ 63 return ret_val; \ 64 } \ 65 } 66 67 /** 68 ****************************************************************************** 69 * @brief Macro to put a code with specified number of bits into the 70 * bitstream using 0th order exponential Golomb encoding for 71 * signed numbers 72 ****************************************************************************** 73 */ 74 #define PUT_BITS_UEV(ps_bitstrm, code_val, ret_val, syntax_string) \ 75 { \ 76 ENTROPY_TRACE(syntax_string, code_val); \ 77 ret_val = ih264e_put_uev((ps_bitstrm), (code_val)); \ 78 if(ret_val != IH264E_SUCCESS) \ 79 { \ 80 return ret_val; \ 81 } \ 82 } 83 /** 84 ****************************************************************************** 85 * @brief Macro to put a code with specified number of bits into the 86 * bitstream using 0th order exponential Golomb encoding for 87 * signed numbers 88 ****************************************************************************** 89 */ 90 #define PUT_BITS_SEV(ps_bitstrm, code_val, ret_val, syntax_string) \ 91 { \ 92 ENTROPY_TRACE(syntax_string, code_val); \ 93 ret_val = ih264e_put_sev((ps_bitstrm), (code_val)); \ 94 if(ret_val != IH264E_SUCCESS) \ 95 { \ 96 return ret_val; \ 97 } \ 98 } 99 100 /** 101 ****************************************************************************** 102 * @brief Macro to set active entropy threads to zero and return 103 * in case of errors 104 ****************************************************************************** 105 */ 106 #define RETURN_ENTROPY_IF_ERROR(ps_codec, ps_entropy, ctxt_sel) \ 107 if(ps_entropy->i4_error_code != IH264E_SUCCESS) \ 108 { \ 109 DATA_SYNC(); \ 110 ps_codec->ae_entropy_thread_exit_state[ctxt_sel] = ERRONEOUS_EXIT; \ 111 return ps_entropy->i4_error_code; \ 112 } 113 114 /*****************************************************************************/ 115 /* Extern Function Declarations */ 116 /*****************************************************************************/ 117 extern WORD32 ih264e_generate_nal_unit_header(bitstrm_t *ps_bitstrm, WORD32 nal_unit_type, 118 WORD32 nal_ref_idc); 119 120 extern WORD32 ih264e_generate_vui(bitstrm_t *ps_bitstrm, vui_t *ps_vui); 121 122 extern IH264E_ERROR_T ih264e_generate_sei(bitstrm_t *ps_bitstrm, sei_params_t *ps_sei, 123 UWORD32 u4_insert_per_idr); 124 125 extern IH264E_ERROR_T ih264e_add_filler_nal_unit(bitstrm_t *ps_bitstrm, WORD32 insert_fill_bytes); 126 127 /** 128 ****************************************************************************** 129 * 130 * @brief Generates SPS (Sequence Parameter Set) 131 * 132 * @par Description 133 * This function generates Sequence Parameter Set header as per the spec 134 * 135 * @param[in] ps_bitstrm 136 * pointer to bitstream context (handle) 137 * 138 * @param[in] ps_sps 139 * pointer to structure containing SPS data 140 * 141 * @return success or failure error code 142 * 143 ****************************************************************************** 144 */ 145 WORD32 isvce_generate_sps(bitstrm_t *ps_bitstrm, sps_t *ps_sps, NAL_UNIT_TYPE_T nal_type); 146 147 /** 148 ****************************************************************************** 149 * 150 * @brief Generates PPS (Picture Parameter Set) 151 * 152 * @par Description 153 * Generate Picture Parameter Set as per Section 7.3.2.2 154 * 155 * @param[in] ps_bitstrm 156 * pointer to bitstream context (handle) 157 * 158 * @param[in] ps_pps 159 * pointer to structure containing PPS data 160 * 161 * @return success or failure error code 162 * 163 ****************************************************************************** 164 */ 165 WORD32 isvce_generate_pps(bitstrm_t *ps_bitstrm, pps_t *ps_pps, sps_t *ps_sps); 166 167 /** 168 ****************************************************************************** 169 * 170 * @brief Generates Slice Header 171 * 172 * @par Description 173 * Generate Slice Header as per Section 7.3.5.1 174 * 175 * @param[inout] ps_bitstrm 176 * pointer to bitstream context for generating slice header 177 * 178 * @param[in] ps_slice_hdr 179 * pointer to slice header params 180 * 181 * @param[in] ps_pps 182 * pointer to pps params referred by slice 183 * 184 * @param[in] ps_sps 185 * pointer to sps params referred by slice 186 * 187 * @param[out] ps_dup_bit_strm_ent_offset 188 * Bitstream struct to store bitstream state 189 * 190 * @param[out] pu4_first_slice_start_offset 191 * first slice offset is returned 192 * 193 * @return success or failure error code 194 * 195 ****************************************************************************** 196 */ 197 WORD32 isvce_generate_slice_header(bitstrm_t *ps_bitstrm, slice_header_t *ps_slice_hdr, 198 pps_t *ps_pps, sps_t *ps_sps, UWORD8 u1_idr_flag); 199 /** 200 ****************************************************************************** 201 * 202 * @brief Populates sps structure 203 * 204 * @par Description 205 * Populates sps structure for its use in header generation 206 * 207 * @param[in] ps_codec 208 * pointer to encoder context 209 * 210 * @param[out] ps_sps 211 * pointer to sps params that needs to be populated 212 * 213 * @return success or failure error code 214 * 215 ****************************************************************************** 216 */ 217 IH264E_ERROR_T isvce_populate_sps(isvce_codec_t *ps_codec, sps_t *ps_sps, UWORD8 u1_sps_id, 218 UWORD8 u1_profile_idc, isvce_inp_buf_t *ps_inp_buf, 219 UWORD8 u1_spatial_layer_id); 220 221 /** 222 ****************************************************************************** 223 * 224 * @brief Populates pps structure 225 * 226 * @par Description 227 * Populates pps structure for its use in header generation 228 * 229 * @param[in] ps_codec 230 * pointer to encoder context 231 * 232 * @param[out] ps_pps 233 * pointer to pps params that needs to be populated 234 * 235 * @return success or failure error code 236 * 237 ****************************************************************************** 238 */ 239 IH264E_ERROR_T isvce_populate_pps(isvce_codec_t *ps_codec, pps_t *ps_pps, UWORD8 u1_sps_id, 240 UWORD8 u1_pps_id, UWORD8 u1_spatial_layer_id); 241 242 /** 243 ****************************************************************************** 244 * 245 * @brief Populates slice header structure 246 * 247 * @par Description 248 * Populates slice header structure for its use in header generation 249 * 250 * @param[in] ps_proc 251 * pointer to proc context 252 * 253 * @param[out] ps_slice_hdr 254 * pointer to slice header structure that needs to be populated 255 * 256 * @param[in] ps_pps 257 * pointer to pps params structure referred by the slice 258 * 259 * @param[in] ps_sps 260 * pointer to sps params referred by the pps 261 * 262 * @return success or failure error code 263 * 264 ****************************************************************************** 265 */ 266 WORD32 isvce_populate_slice_header(isvce_process_ctxt_t *ps_proc, slice_header_t *ps_slice_hdr, 267 pps_t *ps_pps, sps_t *ps_sps, UWORD8 u1_is_idr); 268 269 extern WORD32 isvce_populate_svc_nalu_extension(isvce_process_ctxt_t *ps_proc, 270 svc_nalu_ext_t *ps_svc_nalu_ext, 271 NAL_UNIT_TYPE_T nalu_type, UWORD8 u1_idr_flag); 272 273 extern WORD32 isvce_generate_svc_nalu_extension(bitstrm_t *ps_bitstrm, 274 svc_nalu_ext_t *ps_svc_nalu_ext, UWORD8 u1_nalu_id); 275 276 extern WORD32 isvce_populate_svc_slice(isvce_process_ctxt_t *ps_proc, 277 svc_slice_header_t *ps_svc_slice_hdr, pps_t *ps_pps, 278 subset_sps_t *ps_subset_sps, 279 svc_nalu_ext_t *ps_svc_nalu_ext); 280 281 extern WORD32 isvce_populate_subset_sps(isvce_codec_t *ps_codec, subset_sps_t *ps_subset_sps, 282 UWORD8 u1_sps_id, isvce_inp_buf_t *ps_inp_buf, 283 UWORD8 u1_spatial_layer_id); 284 285 extern WORD32 isvce_generate_prefix_nal(bitstrm_t *ps_bitstrm, svc_nalu_ext_t *ps_svc_nalu_ext, 286 slice_header_t *ps_slice_header, 287 UWORD8 u1_max_num_ref_frames, UWORD8 u1_num_spatial_layers); 288 289 extern WORD32 isvce_generate_slice_header_svc(bitstrm_t *ps_bitstrm, pps_t *ps_pps, 290 svc_nalu_ext_t *ps_svc_nalu_ext, 291 svc_slice_header_t *ps_svc_slice_hdr, 292 subset_sps_t *ps_subset_sps); 293 294 extern WORD32 isvce_generate_subset_sps(bitstrm_t *ps_bitstrm, subset_sps_t *ps_subset_sps); 295 296 #endif 297