• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_cabac_structs.h
25  *
26  * @brief
27  *  This file contains cabac related macros, enums, tables and function
28  *declarations.
29  *
30  * @author
31  *  Doney Alex
32  *
33  * @remarks
34  *  none
35  *
36  *******************************************************************************
37  */
38 
39 #ifndef _ISVCE_CABAC_H_
40 #define _ISVCE_CABAC_H_
41 
42 #include "ih264e_cabac.h"
43 #include "isvce_cabac_structs.h"
44 #include "isvce_defs.h"
45 #include "isvce_structs.h"
46 
47 /*****************************************************************************/
48 /* Function Declarations                                                 */
49 /*****************************************************************************/
50 
51 /**
52  *******************************************************************************
53  *
54  * @brief
55  * Initialize default context values and pointers.
56  *
57  * @param[in] ps_ent_ctxt
58  *  Pointer to entropy context structure
59  *
60  * @returns
61  *
62  * @remarks
63  *  None
64  *
65  *******************************************************************************
66  */
67 void isvce_init_cabac_table(isvce_entropy_ctxt_t *ps_ent_ctxt);
68 
69 /**
70  *******************************************************************************
71  *
72  * @brief
73  * Initialize cabac context: Intitalize all contest with init values given in
74  *the spec. Called at the beginning of entropy coding of each slice for CABAC
75  *encoding.
76  *
77  * @param[in] ps_ent_ctxt
78  *  Pointer to entropy context structure
79  *
80  * @returns
81  *
82  * @remarks
83  *  None
84  *
85  *******************************************************************************
86  */
87 extern void isvce_init_cabac_ctxt(isvce_entropy_ctxt_t *ps_ent_ctxt, slice_header_t *ps_slice_hdr);
88 
89 /**
90  *******************************************************************************
91  *
92  * @brief
93  *  k-th order Exp-Golomb (UEGk) binarization process: Implements concatenated
94  *   unary/ k-th order Exp-Golomb  (UEGk) binarization process,
95  *   where k = 0 as defined in 9.3.2.3 of  ITU_T_H264-201402
96  *
97  * @param[in] i2_sufs
98  *  Suffix bit string
99  *
100  * @param[in] pi1_bins_len
101  *  Pointer to length of the string
102  *
103  * @returns Binarized value
104  *
105  * @remarks
106  *  None
107  *
108  *******************************************************************************
109  */
110 UWORD32 isvce_cabac_UEGk0_binarization(WORD16 i2_sufs, WORD8 *pi1_bins_len);
111 
112 /**
113  *******************************************************************************
114  *
115  * @brief
116  *  Get cabac context for the MB :calculates the pointers to Top and   left
117  *          cabac neighbor context depending upon neighbor  availability.
118  *
119  * @param[in] ps_ent_ctxt
120  *  Pointer to entropy context structure
121  *
122  * @param[in] u4_mb_type
123  *  Type of MB
124  *
125  * @returns
126  *
127  * @remarks
128  *  None
129  *
130  *******************************************************************************
131  */
132 void isvce_get_cabac_context(isvce_entropy_ctxt_t *ps_ent_ctxt, WORD32 u4_mb_type);
133 
134 /**
135  *******************************************************************************
136  * @brief
137  *  flushing at termination: Explained in flowchart 9-12(ITU_T_H264-201402).
138  *
139  *  @param[in]   ps_cabac_ctxt
140  *  pointer to cabac context (handle)
141  *
142  * @returns  none
143  *
144  * @remarks
145  *  None
146  *
147  *******************************************************************************
148  */
149 void isvce_cabac_flush(isvce_cabac_ctxt_t *ps_cabac_ctxt);
150 
151 /**
152  ******************************************************************************
153  *
154  *  @brief Puts new byte (and outstanding bytes) into bitstream after cabac
155  *         renormalization
156  *
157  *  @par   Description
158  *  1. Extract the leading byte of low(L)
159  *  2. If leading byte=0xff increment outstanding bytes and return
160  *     (as the actual bits depend on carry propogation later)
161  *  3. If leading byte is not 0xff check for any carry propogation
162  *  4. Insert the carry (propogated in previous byte) along with outstanding
163  *     bytes (if any) and leading byte
164  *
165  *
166  *  @param[inout]   ps_cabac_ctxt
167  *  pointer to cabac context (handle)
168  *
169  *  @return
170  *
171  ******************************************************************************
172  */
173 void isvce_cabac_put_byte(isvce_cabac_ctxt_t *ps_cabac_ctxt);
174 
175 /**
176  ******************************************************************************
177  *
178  *  @brief Codes a bin based on probablilty and mps packed context model
179  *
180  *  @par   Description
181  *  1. Apart from encoding bin, context model is updated as per state transition
182  *  2. Range and Low renormalization is done based on bin and original state
183  *  3. After renorm bistream is updated (if required)
184  *
185  *  @param[inout]   ps_cabac
186  *  pointer to cabac context (handle)
187  *
188  *  @param[in]   bin
189  *  bin(boolean) to be encoded
190  *
191  *  @param[in]  pu1_bin_ctxts
192  *  index of cabac context model containing pState[bits 5-0] | MPS[bit6]
193  *
194  *  @return
195  *
196  ******************************************************************************
197  */
198 void isvce_cabac_encode_bin(isvce_cabac_ctxt_t *ps_cabac, WORD32 bin,
199                             bin_ctxt_model *pu1_bin_ctxts);
200 
201 /**
202  *******************************************************************************
203  *
204  * @brief
205  *  Encoding process for a binary decision :implements encoding process of a
206  decision
207  *  as defined in 9.3.4.2 . This function encodes multiple bins, of a symbol.
208  Implements
209  *  flowchart Figure 9-7( ITU_T_H264-201402)
210  *
211  * @param[in] u4_bins
212  * array of bin values
213  *
214  * @param[in] i1_bins_len
215  *  Length of bins, maximum 32
216  *
217  * @param[in] u4_ctx_inc
218  *  CtxInc, byte0- bin0, byte1-bin1 ..
219  *
220  * @param[in] i1_valid_len
221  *  valid length of bins, after that CtxInc is constant
222  *
223  * @param[in] pu1_bin_ctxt_type
224  *  Pointer to binary contexts
225 
226  * @param[in] ps_cabac
227  *  Pointer to cabac_context_structure
228  *
229  * @returns
230  *
231  * @remarks
232  *  None
233  *
234  *******************************************************************************
235  */
236 void isvce_encode_decision_bins(UWORD32 u4_bins, WORD8 i1_bins_len, UWORD32 u4_ctx_inc,
237                                 WORD8 i1_valid_len, bin_ctxt_model *pu1_bin_ctxt_type,
238                                 isvce_cabac_ctxt_t *ps_cabac);
239 
240 /**
241  *******************************************************************************
242  * @brief
243  *  Encoding process for a binary decision before termination:Encoding process
244  *  of a termination(9.3.4.5 :ITU_T_H264-201402) . Explained in flowchart 9-11.
245  *
246  * @param[in] ps_cabac
247  *  Pointer to cabac structure
248  *
249  * @param[in] term_bin
250  *  Symbol value, end of slice or not, term_bin is binary
251  *
252  * @returns
253  *
254  * @remarks
255  *  None
256  *
257  *******************************************************************************
258  */
259 void isvce_cabac_encode_terminate(isvce_cabac_ctxt_t *ps_cabac, WORD32 term_bin);
260 
261 /**
262  *******************************************************************************
263  * @brief
264  * Bypass encoding process for binary decisions:  Explained (9.3.4.4
265  *:ITU_T_H264-201402) , flowchart 9-10.
266  *
267  *  @param[in]  ps_cabac : pointer to cabac context (handle)
268  *
269  *  @param[in]   bin :  bypass bin(0/1) to be encoded
270  *
271  *  @returns
272  *
273  *  @remarks
274  *  None
275  *
276  *******************************************************************************
277  */
278 
279 void isvce_cabac_encode_bypass_bin(isvce_cabac_ctxt_t *ps_cabac, WORD32 bin);
280 
281 /**
282  ******************************************************************************
283  *
284  *  @brief Encodes a series of bypass bins (FLC bypass bins)
285  *
286  *  @par   Description
287  *  This function is more optimal than calling isvce_cabac_encode_bypass_bin()
288  *  in a loop as cabac low, renorm and generating the stream (8bins at a time)
289  *  can be done in one operation
290  *
291  *  @param[inout]ps_cabac
292  *   pointer to cabac context (handle)
293  *
294  *  @param[in]   u4_bins
295  *   syntax element to be coded (as FLC bins)
296  *
297  *  @param[in]   num_bins
298  *   This is the FLC length for u4_sym
299  *
300  *  @return
301  *
302  ******************************************************************************
303  */
304 
305 void isvce_cabac_encode_bypass_bins(isvce_cabac_ctxt_t *ps_cabac, UWORD32 u4_bins, WORD32 num_bins);
306 
307 /**
308  *******************************************************************************
309  *
310  * @brief
311  *  This function generates CABAC coded bit stream for an Intra Slice.
312  *
313  * @description
314  *  The mb syntax layer for intra slices constitutes luma mb mode, luma sub
315  *modes (if present), mb qp delta, coded block pattern, chroma mb mode and
316  *  luma/chroma residue. These syntax elements are written as directed by table
317  *  7.3.5 of h264 specification.
318  *
319  * @param[in] ps_ent_ctxt
320  *  pointer to entropy context
321  *
322  * @returns error code
323  *
324  * @remarks none
325  *
326  *******************************************************************************
327  */
328 IH264E_ERROR_T isvce_write_islice_mb_cabac(isvce_entropy_ctxt_t *ps_ent_ctxt);
329 
330 /**
331  *******************************************************************************
332  *
333  * @brief
334  *  This function generates CABAC coded bit stream for Inter slices
335  *
336  * @description
337  *  The mb syntax layer for inter slices constitutes luma mb mode, luma sub
338  *modes (if present), mb qp delta, coded block pattern, chroma mb mode and
339  *  luma/chroma residue. These syntax elements are written as directed by table
340  *  7.3.5 of h264 specification
341  *
342  * @param[in] ps_ent_ctxt
343  *  pointer to entropy context
344  *
345  * @returns error code
346  *
347  * @remarks none
348  *
349  *******************************************************************************
350  */
351 IH264E_ERROR_T isvce_write_pslice_mb_cabac(isvce_entropy_ctxt_t *ps_ent_ctxt);
352 
353 /**
354  *******************************************************************************
355  *
356  * @brief
357  *  This function generates CABAC coded bit stream for B slices
358  *
359  * @description
360  *  The mb syntax layer for inter slices constitutes luma mb mode,
361  *  mb qp delta, coded block pattern, chroma mb mode and
362  *  luma/chroma residue. These syntax elements are written as directed by table
363  *  7.3.5 of h264 specification
364  *
365  * @param[in] ps_ent_ctxt
366  *  pointer to entropy context
367  *
368  * @returns error code
369  *
370  * @remarks none
371  *
372  *******************************************************************************
373  */
374 IH264E_ERROR_T isvce_write_bslice_mb_cabac(isvce_entropy_ctxt_t *ps_ent_ctxt);
375 
376 #if ENABLE_RE_ENC_AS_SKIP
377 IH264E_ERROR_T isvce_reencode_as_skip_frame_cabac(isvce_entropy_ctxt_t *ps_ent_ctxt);
378 #endif
379 
380 #endif
381