/src/libavc/decoder/svc/isvcd_parse_cavlc.c
Line | Count | Source |
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 | | * @file |
23 | | * isvcd_parse_cavlc.c |
24 | | * |
25 | | * @brief |
26 | | * This file contains UVLC related functions. |
27 | | * |
28 | | * @author |
29 | | * Kishore |
30 | | * |
31 | | * @par List of Functions: |
32 | | * - isvcd_parse_bmb_ref_index_cavlc_range1() |
33 | | * - isvcd_parse_bmb_ref_index_cavlc() |
34 | | * - isvcd_parse_pmb_ref_index_cavlc() |
35 | | * - isvcd_parse_pmb_ref_index_cavlc_range1() |
36 | | * |
37 | | * @remarks |
38 | | * None |
39 | | * |
40 | | ******************************************************************************* |
41 | | */ |
42 | | |
43 | | #include <string.h> |
44 | | #include <stdio.h> |
45 | | |
46 | | #include "ih264d_bitstrm.h" |
47 | | #include "isvcd_parse_cavlc.h" |
48 | | #include "ih264d_error_handler.h" |
49 | | #include "ih264d_defs.h" |
50 | | #include "ih264d_debug.h" |
51 | | #include "ih264d_cabac.h" |
52 | | #include "isvcd_structs.h" |
53 | | #include "ih264d_tables.h" |
54 | | #include "ih264d_tables.h" |
55 | | #include "ih264d_mb_utils.h" |
56 | | #include "ih264d_parse_cavlc.h" |
57 | | |
58 | | /*****************************************************************************/ |
59 | | /* */ |
60 | | /* Function Name : isvcd_parse_bmb_ref_index_cavlc_range1 */ |
61 | | /* */ |
62 | | /* Description : This function does the Cavlc TEV range > 1 parsing of */ |
63 | | /* reference index for a B MB. */ |
64 | | /* Range > 1 when num_ref_idx_active_minus1 > 0 */ |
65 | | /* */ |
66 | | /* Inputs : <What inputs does the function take?> */ |
67 | | /* Globals : <Does it use any global variables?> */ |
68 | | /* Processing : <Describe how the function operates - include algorithm */ |
69 | | /* description> */ |
70 | | /* Outputs : <What does the function produce?> */ |
71 | | /* Returns : <What does the function return?> */ |
72 | | /* */ |
73 | | /* Issues : <List any issues or problems with this function> */ |
74 | | /* */ |
75 | | /* Revision History: */ |
76 | | /* */ |
77 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
78 | | /* 19 09 2008 Jay Draft */ |
79 | | /* */ |
80 | | /*****************************************************************************/ |
81 | | |
82 | | void isvcd_parse_bmb_ref_index_cavlc_range1( |
83 | | UWORD32 u4_num_part, /* Number of partitions in MB */ |
84 | | dec_bit_stream_t *ps_bitstrm, /* Pointer to bitstream Structure. */ |
85 | | WORD8 *pi1_ref_idx, /* pointer to reference index array */ |
86 | | UWORD32 u4_num_ref_idx_active_minus1, /* Not used for range 1 */ |
87 | | UWORD8 *pu1_motion_prediction_flag /*motion_pred_flag */ |
88 | | |
89 | | ) |
90 | 5.72k | { |
91 | 5.72k | UWORD32 u4_i; |
92 | 5.72k | UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer; |
93 | 5.72k | UWORD32 *pu4_bitstream_off = &ps_bitstrm->u4_ofst; |
94 | 5.72k | UNUSED(u4_num_ref_idx_active_minus1); |
95 | 13.6k | for(u4_i = 0; u4_i < u4_num_part; u4_i++) |
96 | 7.91k | { |
97 | 7.91k | if(pi1_ref_idx[u4_i] > -1 && (((*pu1_motion_prediction_flag >> u4_i) & 0x01) == 0)) |
98 | 1.43k | { |
99 | 1.43k | UWORD32 u4_ref_idx; |
100 | 1.43k | u4_ref_idx = ih264d_tev_range1(pu4_bitstream_off, pu4_bitstrm_buf); |
101 | | |
102 | | /* Storing Reference Idx Information */ |
103 | 1.43k | pi1_ref_idx[u4_i] = (WORD8) u4_ref_idx; |
104 | 1.43k | } |
105 | 7.91k | } |
106 | 5.72k | } |
107 | | |
108 | | /*****************************************************************************/ |
109 | | /* */ |
110 | | /* Function Name : isvcd_parse_bmb_ref_index_cavlc */ |
111 | | /* */ |
112 | | /* Description : This function does the Cavlc TEV range > 1 parsing of */ |
113 | | /* reference index for a B MB. */ |
114 | | /* Range > 1 when num_ref_idx_active_minus1 > 0 */ |
115 | | /* */ |
116 | | /* Inputs : <What inputs does the function take?> */ |
117 | | /* Globals : <Does it use any global variables?> */ |
118 | | /* Processing : <Describe how the function operates - include algorithm */ |
119 | | /* description> */ |
120 | | /* Outputs : <What does the function produce?> */ |
121 | | /* Returns : <What does the function return?> */ |
122 | | /* */ |
123 | | /* Issues : <List any issues or problems with this function> */ |
124 | | /* */ |
125 | | /* Revision History: */ |
126 | | /* */ |
127 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
128 | | /* 19 09 2008 Jay Draft */ |
129 | | /* */ |
130 | | /*****************************************************************************/ |
131 | | WORD32 isvcd_parse_bmb_ref_index_cavlc( |
132 | | UWORD32 u4_num_part, /* Number of partitions in MB */ |
133 | | dec_bit_stream_t *ps_bitstrm, /* Pointer to bitstream Structure. */ |
134 | | WORD8 *pi1_ref_idx, /* pointer to reference index array */ |
135 | | UWORD32 u4_num_ref_idx_active_minus1, /* Number of active references - 1 */ |
136 | | UWORD8 *pu1_motion_prediction_flag /*motion_pred_flag */ |
137 | | ) |
138 | 14.1k | { |
139 | 14.1k | UWORD32 u4_i; |
140 | 14.1k | UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer; |
141 | 14.1k | UWORD32 *pu4_bitstream_off = &ps_bitstrm->u4_ofst; |
142 | | |
143 | 36.4k | for(u4_i = 0; u4_i < u4_num_part; u4_i++) |
144 | 24.6k | { |
145 | 24.6k | if(pi1_ref_idx[u4_i] > -1 && (((*pu1_motion_prediction_flag >> u4_i) & 0x01) == 0)) |
146 | 8.16k | { |
147 | 8.16k | UWORD32 u4_ref_idx; |
148 | | // inlining ih264d_uev |
149 | 8.16k | UWORD32 u4_bitstream_offset = *pu4_bitstream_off; |
150 | 8.16k | UWORD32 u4_word, u4_ldz; |
151 | | |
152 | | /***************************************************************/ |
153 | | /* Find leading zeros in next 32 bits */ |
154 | | /***************************************************************/ |
155 | 8.16k | NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf); |
156 | 8.16k | u4_ldz = CLZ(u4_word); |
157 | | /* Flush the ps_bitstrm */ |
158 | 8.16k | u4_bitstream_offset += (u4_ldz + 1); |
159 | | /* Read the suffix from the ps_bitstrm */ |
160 | 8.16k | u4_word = 0; |
161 | 8.16k | if(u4_ldz) GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, u4_ldz); |
162 | 8.16k | *pu4_bitstream_off = u4_bitstream_offset; |
163 | 8.16k | u4_ref_idx = ((1 << u4_ldz) + u4_word - 1); |
164 | | // inlining ih264d_uev |
165 | 8.16k | if(u4_ref_idx > u4_num_ref_idx_active_minus1) return ERROR_REF_IDX; |
166 | | |
167 | | /* Storing Reference Idx Information */ |
168 | 5.82k | pi1_ref_idx[u4_i] = (WORD8) u4_ref_idx; |
169 | 5.82k | } |
170 | 24.6k | } |
171 | 11.8k | return OK; |
172 | 14.1k | } |
173 | | |
174 | | /*****************************************************************************/ |
175 | | /* */ |
176 | | /* Function Name : isvcd_parse_pmb_ref_index_cavlc */ |
177 | | /* */ |
178 | | /* Description : This function does the Cavlc TEV range > 1 parsing of */ |
179 | | /* reference index for a P MB. */ |
180 | | /* Range > 1 when num_ref_idx_active_minus1 > 0 */ |
181 | | /* */ |
182 | | /* Inputs : <What inputs does the function take?> */ |
183 | | /* Globals : <Does it use any global variables?> */ |
184 | | /* Processing : <Describe how the function operates - include algorithm */ |
185 | | /* description> */ |
186 | | /* Outputs : <What does the function produce?> */ |
187 | | /* Returns : <What does the function return?> */ |
188 | | /* */ |
189 | | /* Issues : <List any issues or problems with this function> */ |
190 | | /* */ |
191 | | /* Revision History: */ |
192 | | /* */ |
193 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
194 | | /* 19 09 2008 Jay Draft */ |
195 | | /* */ |
196 | | /*****************************************************************************/ |
197 | | |
198 | | WORD32 isvcd_parse_pmb_ref_index_cavlc( |
199 | | UWORD32 u4_num_part, /* Number of partitions in MB */ |
200 | | dec_bit_stream_t *ps_bitstrm, /* Pointer to bitstream Structure. */ |
201 | | WORD8 *pi1_ref_idx, /* pointer to reference index array */ |
202 | | UWORD32 u4_num_ref_idx_active_minus1, /* Number of active references - 1 */ |
203 | | UWORD8 *pu1_motion_prediction_flag /*motion_pred_flag_l0 */ |
204 | | ) |
205 | 9.47k | { |
206 | 9.47k | UWORD32 u4_i; |
207 | 9.47k | UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer; |
208 | 9.47k | UWORD32 *pu4_bitstream_off = &ps_bitstrm->u4_ofst; |
209 | | |
210 | 24.5k | for(u4_i = 0; u4_i < u4_num_part; u4_i++) |
211 | 15.3k | { |
212 | 15.3k | if(((*pu1_motion_prediction_flag >> u4_i) & 0x01) == 0) |
213 | 7.67k | { |
214 | 7.67k | UWORD32 u4_ref_idx; |
215 | | // Inlined ih264d_uev |
216 | 7.67k | UWORD32 u4_bitstream_offset = *pu4_bitstream_off; |
217 | 7.67k | UWORD32 u4_word, u4_ldz; |
218 | | |
219 | | /***************************************************************/ |
220 | | /* Find leading zeros in next 32 bits */ |
221 | | /***************************************************************/ |
222 | 7.67k | NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf); |
223 | 7.67k | u4_ldz = CLZ(u4_word); |
224 | | /* Flush the ps_bitstrm */ |
225 | 7.67k | u4_bitstream_offset += (u4_ldz + 1); |
226 | | /* Read the suffix from the ps_bitstrm */ |
227 | 7.67k | u4_word = 0; |
228 | 7.67k | if(u4_ldz) GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, u4_ldz); |
229 | 7.67k | *pu4_bitstream_off = u4_bitstream_offset; |
230 | 7.67k | u4_ref_idx = ((1 << u4_ldz) + u4_word - 1); |
231 | | |
232 | | // Inlined ih264d_uev |
233 | 7.67k | if(u4_ref_idx > u4_num_ref_idx_active_minus1) return ERROR_REF_IDX; |
234 | | |
235 | | /* Storing Reference Idx Information */ |
236 | 7.41k | pi1_ref_idx[u4_i] = (WORD8) u4_ref_idx; |
237 | 7.41k | } |
238 | 15.3k | } |
239 | 9.21k | return OK; |
240 | 9.47k | } |
241 | | |
242 | | /*****************************************************************************/ |
243 | | /* */ |
244 | | /* Function Name : isvcd_parse_pmb_ref_index_cavlc_range1 */ |
245 | | /* */ |
246 | | /* Description : This function does the Cavlc TEV range =1 parsing of */ |
247 | | /* reference index for a P MB. Range is 1 when */ |
248 | | /* num_ref_idx_active_minus1 is 0 */ |
249 | | /* */ |
250 | | /* Inputs : <What inputs does the function take?> */ |
251 | | /* Globals : <Does it use any global variables?> */ |
252 | | /* Processing : <Describe how the function operates - include algorithm */ |
253 | | /* description> */ |
254 | | /* Outputs : <What does the function produce?> */ |
255 | | /* Returns : <What does the function return?> */ |
256 | | /* */ |
257 | | /* Issues : <List any issues or problems with this function> */ |
258 | | /* */ |
259 | | /* Revision History: */ |
260 | | /* */ |
261 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
262 | | /* 19 09 2008 Jay Draft */ |
263 | | /* */ |
264 | | /*****************************************************************************/ |
265 | | void isvcd_parse_pmb_ref_index_cavlc_range1( |
266 | | UWORD32 u4_num_part, /* Number of partitions in MB */ |
267 | | dec_bit_stream_t *ps_bitstrm, /* Pointer to bitstream Structure. */ |
268 | | WORD8 *pi1_ref_idx, /* pointer to reference index array */ |
269 | | UWORD32 u4_num_ref_idx_active_minus1, /* Not used for range 1 */ |
270 | | UWORD8 *pu1_motion_prediction_flag /*motion_pred_flag_l0 */ |
271 | | ) |
272 | 4.07k | { |
273 | 4.07k | UWORD32 u4_i; |
274 | 4.07k | UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer; |
275 | 4.07k | UWORD32 *pu4_bitstream_off = &ps_bitstrm->u4_ofst; |
276 | 4.07k | UNUSED(u4_num_ref_idx_active_minus1); |
277 | 11.2k | for(u4_i = 0; u4_i < u4_num_part; u4_i++) |
278 | 7.16k | { |
279 | 7.16k | if(((*pu1_motion_prediction_flag >> u4_i) & 0x01) == 0) |
280 | 2.43k | { |
281 | 2.43k | UWORD32 u4_ref_idx; |
282 | 2.43k | u4_ref_idx = ih264d_tev_range1(pu4_bitstream_off, pu4_bitstrm_buf); |
283 | | |
284 | | /* Storing Reference Idx Information */ |
285 | 2.43k | pi1_ref_idx[u4_i] = (WORD8) u4_ref_idx; |
286 | 2.43k | } |
287 | 7.16k | } |
288 | 4.07k | } |