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 ps_codec->au4_entropy_thread_active[ctxt_sel] = 0; \ 106 return ps_entropy->i4_error_code; \ 107 } 108 109 /*****************************************************************************/ 110 /* Extern Function Declarations */ 111 /*****************************************************************************/ 112 113 /** 114 ****************************************************************************** 115 * 116 * @brief Generates SPS (Sequence Parameter Set) 117 * 118 * @par Description 119 * This function generates Sequence Parameter Set header as per the spec 120 * 121 * @param[in] ps_bitstrm 122 * pointer to bitstream context (handle) 123 * 124 * @param[in] ps_sps 125 * pointer to structure containing SPS data 126 * 127 * @return success or failure error code 128 * 129 ****************************************************************************** 130 */ 131 WORD32 ih264e_generate_sps 132 ( 133 bitstrm_t *ps_bitstrm, 134 sps_t *ps_sps, 135 vui_t *ps_vui 136 ); 137 138 /** 139 ****************************************************************************** 140 * 141 * @brief Generates PPS (Picture Parameter Set) 142 * 143 * @par Description 144 * Generate Picture Parameter Set as per Section 7.3.2.2 145 * 146 * @param[in] ps_bitstrm 147 * pointer to bitstream context (handle) 148 * 149 * @param[in] ps_pps 150 * pointer to structure containing PPS data 151 * 152 * @return success or failure error code 153 * 154 ****************************************************************************** 155 */ 156 WORD32 ih264e_generate_pps 157 ( 158 bitstrm_t *ps_bitstrm, 159 pps_t *ps_pps, 160 sps_t *ps_sps 161 ); 162 163 /** 164 ****************************************************************************** 165 * 166 * @brief Generates SEI (Supplemental Enhancement Information) 167 * 168 * @par Description 169 * This function generates Supplemental Enhancement Information header as per the spec 170 * 171 * @param[in] ps_bitstrm 172 * pointer to bitstream context (handle) 173 * 174 * @param[in] ps_sei 175 * pointer to structure containing SEI data 176 * 177 * @return success or failure error code 178 * 179 ****************************************************************************** 180 */ 181 IH264E_ERROR_T ih264e_generate_sei 182 ( 183 bitstrm_t *ps_bitstrm, 184 sei_params_t *ps_sei, 185 UWORD32 u4_insert_per_idr 186 ); 187 188 /** 189 ****************************************************************************** 190 * 191 * @brief Generates Slice Header 192 * 193 * @par Description 194 * Generate Slice Header as per Section 7.3.5.1 195 * 196 * @param[inout] ps_bitstrm 197 * pointer to bitstream context for generating slice header 198 * 199 * @param[in] ps_slice_hdr 200 * pointer to slice header params 201 * 202 * @param[in] ps_pps 203 * pointer to pps params referred by slice 204 * 205 * @param[in] ps_sps 206 * pointer to sps params referred by slice 207 * 208 * @param[out] ps_dup_bit_strm_ent_offset 209 * Bitstream struct to store bitstream state 210 * 211 * @param[out] pu4_first_slice_start_offset 212 * first slice offset is returned 213 * 214 * @return success or failure error code 215 * 216 ****************************************************************************** 217 */ 218 WORD32 ih264e_generate_slice_header 219 ( 220 bitstrm_t *ps_bitstrm, 221 slice_header_t *ps_slice_hdr, 222 pps_t *ps_pps, 223 sps_t *ps_sps 224 ); 225 226 /** 227 ****************************************************************************** 228 * 229 * @brief Populates sps structure 230 * 231 * @par Description 232 * Populates sps structure for its use in header generation 233 * 234 * @param[in] ps_codec 235 * pointer to encoder context 236 * 237 * @param[out] ps_sps 238 * pointer to sps params that needs to be populated 239 * 240 * @return success or failure error code 241 * 242 ****************************************************************************** 243 */ 244 IH264E_ERROR_T ih264e_populate_sps 245 ( 246 codec_t *ps_codec, 247 sps_t *ps_sps 248 ); 249 250 /** 251 ****************************************************************************** 252 * 253 * @brief Populates pps structure 254 * 255 * @par Description 256 * Populates pps structure for its use in header generation 257 * 258 * @param[in] ps_codec 259 * pointer to encoder context 260 * 261 * @param[out] ps_pps 262 * pointer to pps params that needs to be populated 263 * 264 * @return success or failure error code 265 * 266 ****************************************************************************** 267 */ 268 IH264E_ERROR_T ih264e_populate_pps 269 ( 270 codec_t *ps_codec, 271 pps_t *ps_pps 272 ); 273 274 275 /** 276 ****************************************************************************** 277 * 278 * @brief Populates slice header structure 279 * 280 * @par Description 281 * Populates slice header structure for its use in header generation 282 * 283 * @param[in] ps_proc 284 * pointer to proc context 285 * 286 * @param[out] ps_slice_hdr 287 * pointer to slice header structure that needs to be populated 288 * 289 * @param[in] ps_pps 290 * pointer to pps params structure referred by the slice 291 * 292 * @param[in] ps_sps 293 * pointer to sps params referred by the pps 294 * 295 * @return success or failure error code 296 * 297 ****************************************************************************** 298 */ 299 WORD32 ih264e_populate_slice_header 300 ( 301 process_ctxt_t *ps_proc, 302 slice_header_t *ps_slice_hdr, 303 pps_t *ps_pps, 304 sps_t *ps_sps 305 ); 306 307 308 /** 309 ****************************************************************************** 310 * 311 * @brief inserts FILLER Nal Unit. 312 * 313 * @par Description 314 * In constant bit rate rc mode, when the bits generated by the codec is 315 * underflowing the target bit rate, the encoder library inserts filler nal unit. 316 * 317 * @param[in] ps_bitstrm 318 * pointer to bitstream context (handle) 319 * 320 * @param[in] insert_fill_bytes 321 * Number of fill bytes to be inserted 322 * 323 * @return success or failure error code 324 * 325 ****************************************************************************** 326 */ 327 IH264E_ERROR_T ih264e_add_filler_nal_unit 328 ( 329 bitstrm_t *ps_bitstrm, 330 WORD32 insert_fill_bytes 331 ); 332 333 334 #endif //IH264E_ENCODE_HEADER_H_ 335