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_utils.h
25 *
26 * @brief
27 * Contains function declarations for function declared in ih264e_svc_utils.c
28 *
29 * @author
30 * ittiam
31 *
32 * @remarks
33 * None
34 *
35 *******************************************************************************
36 */
37
38 #ifndef _ISVCE_UTILS_H_
39 #define _ISVCE_UTILS_H_
40
41 #include <stdio.h>
42 #include <stddef.h>
43 #include <stdlib.h>
44 #include <string.h>
45 #include <assert.h>
46
47 #include "ih264_typedefs.h"
48 #include "ih264e_bitstream.h"
49 #include "isvc_macros.h"
50 #include "isvc_structs.h"
51 #include "isvce_defs.h"
52 #include "isvce_globals.h"
53 #include "isvce_interface_structs.h"
54 #include "isvce_structs.h"
55
isvce_svc_au_buf_init(svc_au_buf_t * ps_svc_pic_buf,svc_params_t * ps_svc_params)56 static FORCEINLINE void isvce_svc_au_buf_init(svc_au_buf_t *ps_svc_pic_buf,
57 svc_params_t *ps_svc_params)
58 {
59 ps_svc_pic_buf->i1_temporal_id = -1;
60 ps_svc_pic_buf->u1_num_spatial_layers = ps_svc_params->u1_num_spatial_layers;
61 ps_svc_pic_buf->d_spatial_res_ratio = ps_svc_params->d_spatial_res_ratio;
62 }
63
isvce_svc_temporal_id_compute(WORD32 i4_poc,UWORD8 u1_num_temporal_layers,PIC_TYPE_T e_pic_type)64 static FORCEINLINE WORD8 isvce_svc_temporal_id_compute(WORD32 i4_poc, UWORD8 u1_num_temporal_layers,
65 PIC_TYPE_T e_pic_type)
66 {
67 if(e_pic_type == PIC_IDR)
68 {
69 return 0;
70 }
71 else
72 {
73 return i4_poc % u1_num_temporal_layers;
74 }
75 }
76
isvcd_get_ceil_log2(WORD32 i4_input)77 static FORCEINLINE WORD32 isvcd_get_ceil_log2(WORD32 i4_input)
78 {
79 WORD32 i4_bits = 0;
80
81 /* check for negative number */
82 ASSERT(i4_input >= 0);
83
84 i4_input--;
85
86 while(i4_input > 0)
87 {
88 i4_bits++;
89 i4_input >>= 1;
90 }
91
92 return (i4_bits);
93 }
94 /**
95 *******************************************************************************
96 *
97 * @brief calculate coded subblock pattern from nnz
98 *
99 * @par Description:
100 * calculate coded subblock pattern from nnz
101 *
102 * @param[in] ps_proc
103 * process context
104 *
105 * @returns csbp
106 *
107 * @remarks none
108 *
109 *******************************************************************************
110 */
isvce_calculate_csbp(isvce_process_ctxt_t * ps_proc)111 static FORCEINLINE UWORD32 isvce_calculate_csbp(isvce_process_ctxt_t *ps_proc)
112 {
113 WORD32 i;
114
115 UWORD8 *pu1_curr_nnz = ((UWORD8 *) ps_proc->au4_nnz) + 1;
116 UWORD32 u4_csbp = 0;
117
118 for(i = 0; i < 16; i++)
119 {
120 UWORD8 u1_zscan_idx = gau1_raster_to_zscan_map[i];
121
122 u4_csbp |= ((!!pu1_curr_nnz[i]) << u1_zscan_idx);
123 }
124
125 return u4_csbp;
126 }
127
isvce_check_identical_mv(isvce_enc_pu_mv_t * ps_mv1,isvce_enc_pu_mv_t * ps_mv2,PRED_MODE_T e_pred_mode)128 static FORCEINLINE UWORD8 isvce_check_identical_mv(isvce_enc_pu_mv_t *ps_mv1,
129 isvce_enc_pu_mv_t *ps_mv2,
130 PRED_MODE_T e_pred_mode)
131 {
132 if(e_pred_mode != L0)
133 {
134 if(!((ps_mv1[L1].i1_ref_idx == ps_mv2[L1].i1_ref_idx) &&
135 (ps_mv1[L1].s_mv.i2_mvx == ps_mv2[L1].s_mv.i2_mvx) &&
136 (ps_mv1[L1].s_mv.i2_mvy == ps_mv2[L1].s_mv.i2_mvy)))
137 {
138 return 0;
139 }
140 }
141
142 if(e_pred_mode != L1)
143 {
144 if(!((ps_mv1[L0].i1_ref_idx == ps_mv2[L0].i1_ref_idx) &&
145 (ps_mv1[L0].s_mv.i2_mvx == ps_mv2[L0].s_mv.i2_mvx) &&
146 (ps_mv1[L0].s_mv.i2_mvy == ps_mv2[L0].s_mv.i2_mvy)))
147 {
148 return 0;
149 }
150 }
151
152 return 1;
153 }
154
isvce_get_num_bits(bitstrm_t * ps_bitstream)155 static FORCEINLINE WORD32 isvce_get_num_bits(bitstrm_t *ps_bitstream)
156 {
157 return GET_NUM_BITS(ps_bitstream);
158 }
159
160 extern WORD32 ih264e_get_min_level(WORD32 wd, WORD32 ht);
161
162 extern WORD32 isvce_svc_au_props_validate(svc_inp_params_t *ps_svc_inp_params, UWORD32 u4_inp_wd,
163 UWORD32 u4_inp_ht, UWORD32 u4_svc_comp_wd,
164 UWORD32 u4_svc_comp_ht);
165
166 extern WORD32 isvce_svc_inp_params_validate(isvce_init_ip_t *ps_ip, isvce_cfg_params_t *ps_cfg);
167
168 extern WORD32 isvce_get_total_svc_au_buf_size(svc_inp_params_t *ps_svc_inp_params,
169 WORD32 i4_pic_size, WORD32 i4_level,
170 WORD32 i4_horz_pad, WORD32 i4_vert_pad,
171 WORD32 i4_num_ref_frames,
172 WORD32 i4_num_reorder_frames);
173
174 extern UWORD32 isvce_get_total_svc_au_data_size(WORD32 i4_num_luma_samples,
175 UWORD8 u1_num_spatial_layers,
176 DOUBLE d_spatial_res_ratio);
177
178 extern IH264E_ERROR_T isvce_svc_au_data_mgr_add_bufs(isvce_codec_t *ps_codec);
179
180 extern IH264E_ERROR_T isvce_svc_au_buf_mgr_add_bufs(isvce_codec_t *ps_codec);
181
182 extern UWORD32 isvce_get_svc_inp_buf_size(UWORD8 u1_num_spatial_layers, DOUBLE d_spatial_res_ratio,
183 UWORD32 u4_wd, UWORD32 u4_ht);
184
185 extern void isvce_svc_inp_buf_init(isvce_codec_t *ps_codec, iv_mem_rec_t *ps_mem_rec);
186
187 extern void isvce_init_svc_dimension(isvce_inp_buf_t *ps_inp);
188
189 extern void isvce_svc_inp_buf_populate(isvce_codec_t *ps_codec, isvce_inp_buf_t *ps_inp);
190
191 extern void isvce_get_svc_compliant_dimensions(UWORD8 u1_num_spatial_layers,
192 DOUBLE d_scaling_factor, UWORD32 u4_wd,
193 UWORD32 u4_ht, UWORD32 *pu4_svc_comp_wd,
194 UWORD32 *pu4_svc_comp_ht);
195
196 extern UWORD32 isvce_get_svc_nbr_info_buf_size(UWORD8 u1_num_spatial_layers,
197 DOUBLE d_spatial_res_ratio, UWORD32 u4_wd,
198 UWORD32 u4_ht);
199
200 extern void isvce_svc_nbr_info_buf_init(isvce_codec_t *ps_codec, iv_mem_rec_t *ps_mem_rec);
201
202 extern IH264E_ERROR_T isvce_svc_au_init(isvce_codec_t *ps_codec, isvce_inp_buf_t *ps_inp_buf);
203
204 extern IH264E_ERROR_T isvce_svc_layer_pic_init(isvce_codec_t *ps_codec, isvce_inp_buf_t *ps_inp_buf,
205 UWORD8 u1_spatial_layer_id);
206
207 extern IH264E_ERROR_T isvce_init_layer_proc_ctxt(isvce_process_ctxt_t *ps_proc);
208
209 extern UWORD32 isvce_get_svc_ilp_buf_size(UWORD8 u1_num_spatial_layers, DOUBLE d_spatial_res_ratio,
210 UWORD32 u4_wd, UWORD32 u4_ht);
211
212 extern void isvce_svc_ilp_buf_init(isvce_codec_t *ps_codec, iv_mem_rec_t *ps_mem_rec);
213
214 extern void isvce_svc_ilp_buf_update(isvce_process_ctxt_t *ps_proc);
215
216 extern void isvce_svc_pad_frame(isvce_process_ctxt_t *ps_proc);
217
218 extern IH264E_ERROR_T isvce_init_air_map(isvce_codec_t *ps_codec);
219
220 extern void isvce_derive_nghbr_avbl_of_mbs(isvce_process_ctxt_t *ps_proc);
221
222 extern void isvce_init_quant_params(isvce_process_ctxt_t *ps_proc, WORD32 qp);
223
224 extern IH264E_ERROR_T isvce_codec_init(isvce_codec_t *ps_codec);
225
226 extern IH264E_ERROR_T isvce_codec_update_config(isvce_codec_t *ps_codec,
227 isvce_cfg_params_t *ps_cfg);
228
229 extern WORD32 isvce_input_queue_update(isvce_codec_t *ps_codec, ive_video_encode_ip_t *ps_ive_ip,
230 isvce_inp_buf_t *ps_enc_buff, WORD8 i1_layer_id);
231
232 extern void isvce_join_threads(isvce_codec_t *ps_codec);
233
234 extern UWORD32 isvce_get_min_outbuf_size(UWORD32 u4_wd, UWORD32 u4_ht,
235 UWORD8 u1_num_spatial_layers);
236
237 #endif
238