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 ENTROPY_TRACE(syntax_string, code_val);\ 54 ret_val |= ih264e_put_bits((ps_bitstrm), (code_val), (code_len)) 55 56 /** 57 ****************************************************************************** 58 * @brief Macro to put a code with specified number of bits into the 59 * bitstream using 0th order exponential Golomb encoding for 60 * signed numbers 61 ****************************************************************************** 62 */ 63 #define PUT_BITS_UEV(ps_bitstrm, code_val, ret_val, syntax_string) \ 64 ENTROPY_TRACE(syntax_string, code_val);\ 65 ret_val |= ih264e_put_uev((ps_bitstrm), (code_val)) 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_SEV(ps_bitstrm, code_val, ret_val, syntax_string) \ 75 ENTROPY_TRACE(syntax_string, code_val);\ 76 ret_val |= ih264e_put_sev((ps_bitstrm), (code_val)) 77 78 79 /*****************************************************************************/ 80 /* Extern Function Declarations */ 81 /*****************************************************************************/ 82 83 /** 84 ****************************************************************************** 85 * 86 * @brief Generates SPS (Sequence Parameter Set) 87 * 88 * @par Description 89 * This function generates Sequence Parameter Set header as per the spec 90 * 91 * @param[in] ps_bitstrm 92 * pointer to bitstream context (handle) 93 * 94 * @param[in] ps_sps 95 * pointer to structure containing SPS data 96 * 97 * @return success or failure error code 98 * 99 ****************************************************************************** 100 */ 101 WORD32 ih264e_generate_sps 102 ( 103 bitstrm_t *ps_bitstrm, 104 sps_t *ps_sps 105 ); 106 107 /** 108 ****************************************************************************** 109 * 110 * @brief Generates PPS (Picture Parameter Set) 111 * 112 * @par Description 113 * Generate Picture Parameter Set as per Section 7.3.2.2 114 * 115 * @param[in] ps_bitstrm 116 * pointer to bitstream context (handle) 117 * 118 * @param[in] ps_pps 119 * pointer to structure containing PPS data 120 * 121 * @return success or failure error code 122 * 123 ****************************************************************************** 124 */ 125 WORD32 ih264e_generate_pps 126 ( 127 bitstrm_t *ps_bitstrm, 128 pps_t *ps_pps, 129 sps_t *ps_sps 130 ); 131 132 /** 133 ****************************************************************************** 134 * 135 * @brief Generates Slice Header 136 * 137 * @par Description 138 * Generate Slice Header as per Section 7.3.5.1 139 * 140 * @param[inout] ps_bitstrm 141 * pointer to bitstream context for generating slice header 142 * 143 * @param[in] ps_slice_hdr 144 * pointer to slice header params 145 * 146 * @param[in] ps_pps 147 * pointer to pps params referred by slice 148 * 149 * @param[in] ps_sps 150 * pointer to sps params referred by slice 151 * 152 * @param[out] ps_dup_bit_strm_ent_offset 153 * Bitstream struct to store bitstream state 154 * 155 * @param[out] pu4_first_slice_start_offset 156 * first slice offset is returned 157 * 158 * @return success or failure error code 159 * 160 ****************************************************************************** 161 */ 162 WORD32 ih264e_generate_slice_header 163 ( 164 bitstrm_t *ps_bitstrm, 165 slice_header_t *ps_slice_hdr, 166 pps_t *ps_pps, 167 sps_t *ps_sps 168 ); 169 170 /** 171 ****************************************************************************** 172 * 173 * @brief Populates sps structure 174 * 175 * @par Description 176 * Populates sps structure for its use in header generation 177 * 178 * @param[in] ps_codec 179 * pointer to encoder context 180 * 181 * @param[out] ps_sps 182 * pointer to sps params that needs to be populated 183 * 184 * @return success or failure error code 185 * 186 ****************************************************************************** 187 */ 188 IH264E_ERROR_T ih264e_populate_sps 189 ( 190 codec_t *ps_codec, 191 sps_t *ps_sps 192 ); 193 194 /** 195 ****************************************************************************** 196 * 197 * @brief Populates pps structure 198 * 199 * @par Description 200 * Populates pps structure for its use in header generation 201 * 202 * @param[in] ps_codec 203 * pointer to encoder context 204 * 205 * @param[out] ps_pps 206 * pointer to pps params that needs to be populated 207 * 208 * @return success or failure error code 209 * 210 ****************************************************************************** 211 */ 212 IH264E_ERROR_T ih264e_populate_pps 213 ( 214 codec_t *ps_codec, 215 pps_t *ps_pps 216 ); 217 218 219 /** 220 ****************************************************************************** 221 * 222 * @brief Populates slice header structure 223 * 224 * @par Description 225 * Populates slice header structure for its use in header generation 226 * 227 * @param[in] ps_proc 228 * pointer to proc context 229 * 230 * @param[out] ps_slice_hdr 231 * pointer to slice header structure that needs to be populated 232 * 233 * @param[in] ps_pps 234 * pointer to pps params structure referred by the slice 235 * 236 * @param[in] ps_sps 237 * pointer to sps params referred by the pps 238 * 239 * @return success or failure error code 240 * 241 ****************************************************************************** 242 */ 243 WORD32 ih264e_populate_slice_header 244 ( 245 process_ctxt_t *ps_proc, 246 slice_header_t *ps_slice_hdr, 247 pps_t *ps_pps, 248 sps_t *ps_sps 249 ); 250 251 252 /** 253 ****************************************************************************** 254 * 255 * @brief inserts FILLER Nal Unit. 256 * 257 * @par Description 258 * In constant bit rate rc mode, when the bits generated by the codec is 259 * underflowing the target bit rate, the encoder library inserts filler nal unit. 260 * 261 * @param[in] ps_bitstrm 262 * pointer to bitstream context (handle) 263 * 264 * @param[in] insert_fill_bytes 265 * Number of fill bytes to be inserted 266 * 267 * @return success or failure error code 268 * 269 ****************************************************************************** 270 */ 271 IH264E_ERROR_T ih264e_add_filler_nal_unit 272 ( 273 bitstrm_t *ps_bitstrm, 274 WORD32 insert_fill_bytes 275 ); 276 277 278 #endif //IH264E_ENCODE_HEADER_H_ 279