• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_cabac_init.c
25 *
26 * @brief
27 *  Contains all initialization functions for cabac contexts
28 *
29 * @author
30 *  Doney Alex
31 *
32 * @par List of Functions:
33 *
34 *
35 * @remarks
36 *  None
37 *
38 *******************************************************************************
39 */
40 
41 /*****************************************************************************/
42 /* File Includes                                                             */
43 /*****************************************************************************/
44 
45 /* System include files */
46 #include <stdio.h>
47 #include <stddef.h>
48 #include <stdlib.h>
49 #include <string.h>
50 #include <limits.h>
51 #include <assert.h>
52 
53 /* User include files */
54 #include "ih264_typedefs.h"
55 #include "iv2.h"
56 #include "ive2.h"
57 #include "ih264_defs.h"
58 #include "ih264_debug.h"
59 #include "ime_distortion_metrics.h"
60 #include "ime_defs.h"
61 #include "ime_structs.h"
62 #include "ih264_error.h"
63 #include "ih264_structs.h"
64 #include "ih264_trans_quant_itrans_iquant.h"
65 #include "ih264_inter_pred_filters.h"
66 #include "ih264_mem_fns.h"
67 #include "ih264_padding.h"
68 #include "ih264_intra_pred_filters.h"
69 #include "ih264_deblk_edge_filters.h"
70 #include "ih264_platform_macros.h"
71 #include "ih264_macros.h"
72 #include "ih264_buf_mgr.h"
73 #include "ih264e_error.h"
74 #include "ih264e_bitstream.h"
75 #include "ih264_common_tables.h"
76 #include "ih264_cabac_tables.h"
77 #include "ih264_list.h"
78 #include "ih264e_defs.h"
79 #include "irc_cntrl_param.h"
80 #include "irc_frame_info_collector.h"
81 #include "ih264e_rate_control.h"
82 #include "ih264e_cabac_structs.h"
83 #include "ih264e_structs.h"
84 #include "ih264e_cabac.h"
85 #include "ih264e_process.h"
86 #include "ithread.h"
87 #include "ih264e_intra_modes_eval.h"
88 #include "ih264e_encode_header.h"
89 #include "ih264e_globals.h"
90 #include "ih264e_config.h"
91 #include "ih264e_trace.h"
92 #include "ih264e_statistics.h"
93 #include "ih264_cavlc_tables.h"
94 #include "ih264e_deblk.h"
95 #include "ih264e_me.h"
96 #include "ih264e_debug.h"
97 #include "ih264e_master.h"
98 #include "ih264e_utils.h"
99 #include "irc_mem_req_and_acq.h"
100 #include "irc_rate_control_api.h"
101 #include "ih264e_platform_macros.h"
102 #include "ime_statistics.h"
103 
104 
105 
106 /*****************************************************************************/
107 /*  Function definitions .                                                   */
108 /*****************************************************************************/
109 
110 /**
111  *******************************************************************************
112  *
113  * @brief
114  * Initialize cabac encoding environment
115  *
116  * @param[in] ps_cab_enc_env
117  *  Pointer to encoding_envirnoment_t structure
118  *
119  * @returns
120  *
121  * @remarks
122  *  None
123  *
124  *******************************************************************************
125 */
ih264e_init_cabac_enc_envirnoment(encoding_envirnoment_t * ps_cab_enc_env)126 static void ih264e_init_cabac_enc_envirnoment(encoding_envirnoment_t *ps_cab_enc_env)
127 {
128     ps_cab_enc_env->u4_code_int_low = 0;
129     ps_cab_enc_env->u4_code_int_range = 0x1fe;
130     ps_cab_enc_env->u4_out_standing_bytes = 0;
131     ps_cab_enc_env->u4_bits_gen = 0;
132 }
133 
134 
135 /**
136  *******************************************************************************
137  *
138  * @brief
139  * Initialize default context values and pointers (Called once at the beginning of encoding).
140  *
141  * @param[in] ps_ent_ctxt
142  *  Pointer to entropy context structure
143  *
144  * @returns
145  *
146  * @remarks
147  *  None
148  *
149  *******************************************************************************
150 */
ih264e_init_cabac_table(entropy_ctxt_t * ps_ent_ctxt)151 void ih264e_init_cabac_table(entropy_ctxt_t *ps_ent_ctxt)
152 {
153     /* CABAC context */
154     cabac_ctxt_t *ps_cabac_ctxt = ps_ent_ctxt->ps_cabac;
155     ps_cabac_ctxt->ps_mb_map_ctxt_inc = ps_cabac_ctxt->ps_mb_map_ctxt_inc_base + 1;
156     ps_cabac_ctxt->ps_lft_csbp = &ps_cabac_ctxt->s_lft_csbp;
157     ps_cabac_ctxt->ps_bitstrm = ps_ent_ctxt->ps_bitstrm;
158 
159     {
160         /* 0th entry of mb_map_ctxt_inc will be always be containing default values */
161         /* for CABAC context representing MB not available                       */
162         mb_info_ctxt_t *ps_def_ctxt = ps_cabac_ctxt->ps_mb_map_ctxt_inc - 1;
163 
164         ps_def_ctxt->u1_mb_type = CAB_SKIP;
165         ps_def_ctxt->u1_cbp = 0x0f;
166         ps_def_ctxt->u1_intrapred_chroma_mode = 0;
167 
168         memset(ps_def_ctxt->i1_ref_idx, 0, sizeof(ps_def_ctxt->i1_ref_idx));
169         memset(ps_def_ctxt->u1_mv, 0, sizeof(ps_def_ctxt->u1_mv));
170         ps_cabac_ctxt->ps_def_ctxt_mb_info = ps_def_ctxt;
171     }
172 }
173 
174 
175 /**
176  *******************************************************************************
177  *
178  * @brief
179  * Initialize cabac context: Initialize all contest with init values given in the spec.
180  * Called at the beginning of entropy coding of each slice for CABAC encoding.
181  *
182  * @param[in] ps_ent_ctxt
183  *  Pointer to entropy context structure
184  *
185  * @returns
186  *
187  * @remarks
188  *  None
189  *
190  *******************************************************************************
191  */
ih264e_init_cabac_ctxt(entropy_ctxt_t * ps_ent_ctxt)192 void ih264e_init_cabac_ctxt(entropy_ctxt_t *ps_ent_ctxt)
193 {
194     /* CABAC context */
195     cabac_ctxt_t *ps_cabac_ctxt = ps_ent_ctxt->ps_cabac;
196 
197     /* slice header */
198     slice_header_t *ps_slice_hdr = ps_ent_ctxt->ps_slice_hdr_base;
199     const UWORD8 u1_slice_type = ps_slice_hdr->u1_slice_type;
200     WORD8 i1_cabac_init_idc = 0;
201     bin_ctxt_model *au1_cabac_ctxt_table = ps_cabac_ctxt->au1_cabac_ctxt_table;
202     UWORD8 u1_qp_y = ps_slice_hdr->i1_slice_qp;
203 
204     ih264e_init_cabac_enc_envirnoment(&ps_cabac_ctxt->s_cab_enc_env);
205 
206     ps_cabac_ctxt->i1_prevps_mb_qp_delta_ctxt = 0;
207 
208     if (ISLICE != u1_slice_type)
209     {
210         i1_cabac_init_idc = ps_slice_hdr->i1_cabac_init_idc;
211     }
212     else
213     {
214         i1_cabac_init_idc = 3;
215 
216     }
217 
218     memcpy(au1_cabac_ctxt_table,
219            gau1_ih264_cabac_ctxt_init_table[i1_cabac_init_idc][u1_qp_y],
220            NUM_CABAC_CTXTS * sizeof(bin_ctxt_model));
221 
222 }
223