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 #include <string.h>
21 #include <stdio.h>
22
23 #include "iv_datatypedef.h"
24 #include "iv.h"
25 #include "ivd.h"
26 #include "impeg2d.h"
27
28 #include "impeg2_buf_mgr.h"
29 #include "impeg2_disp_mgr.h"
30 #include "impeg2_macros.h"
31 #include "impeg2_defs.h"
32 #include "impeg2_platform_macros.h"
33 #include "impeg2_inter_pred.h"
34 #include "impeg2_idct.h"
35 #include "impeg2_format_conv.h"
36 #include "impeg2_mem_func.h"
37 #include "impeg2_globals.h"
38
39 #include "impeg2d_bitstream.h"
40 #include "impeg2d_api.h"
41 #include "impeg2d_structs.h"
42 #include "impeg2d_debug.h"
43
44 #if STATISTICS
45 WORD32 gai4_impeg2d_idct_inp_last_nonzero_histogram[64] = {0};
46 WORD32 gai4_impeg2d_idct_inp_num_nonzero_histogram[64] = {0};
47 WORD32 gai4_impeg2d_idct_inp_last_non_zero_row_histogram[8] = {0};
48
49 WORD32 gai4_impeg2d_iqnt_inp_last_nonzero_histogram[64] = {0};
50 WORD32 gai4_impeg2d_iqnt_inp_num_nonzero_histogram[64] = {0};
51 WORD32 gai4_impeg2d_iqnt_inp_last_non_zero_row_histogram[8] = {0};
52
53 WORD32 gi4_impeg2d_idct_inp_only_first_coeff = 0;
54 WORD32 gi4_impeg2d_idct_inp_only_last_coeff = 0;
55 WORD32 gi4_impeg2d_idct_inp_only_first_n_last_coeff = 0;
56 WORD32 gi4_impeg2d_idct_cnt = 0;
57
58
59 WORD32 gi4_impeg2d_iqnt_inp_only_first_coeff = 0;
60 WORD32 gi4_impeg2d_iqnt_inp_only_last_coeff = 0;
61 WORD32 gi4_impeg2d_iqnt_inp_only_first_n_last_coeff = 0;
62 WORD32 gi4_impeg2d_iqnt_cnt = 0;
63
64
impeg2d_iqnt_inp_statistics(WORD16 * pi2_iqnt_inp,WORD32 i4_non_zero_cols,WORD32 i4_non_zero_rows)65 void impeg2d_iqnt_inp_statistics(WORD16 *pi2_iqnt_inp,
66 WORD32 i4_non_zero_cols,
67 WORD32 i4_non_zero_rows)
68 {
69 WORD32 i, j;
70 WORD32 i4_last_row = 0, i4_last_col = 0;
71 WORD32 i4_num_non_zero = 0;
72 WORD32 i4_non_zero_cols_computed = 0;
73 WORD32 i4_non_zero_rows_computed = 0;
74
75 for(i = 0; i < 8; i++)
76 {
77 for(j = 0; j < 8; j++)
78 {
79 if(pi2_iqnt_inp[i * 8 + j])
80 {
81 i4_non_zero_cols_computed |= (1 << j);
82 i4_non_zero_rows_computed |= (1 << i);
83 }
84 }
85 }
86
87 if(i4_non_zero_cols_computed != i4_non_zero_cols)
88 {
89 printf("IQ Input: Invalid non_zero_cols 0x%x non_zero_cols_computed 0x%x\n", i4_non_zero_cols, i4_non_zero_cols_computed);
90 }
91 if(i4_non_zero_rows_computed != i4_non_zero_rows)
92 {
93 printf("IQ Input: Invalid non_zero_rows 0x%x non_zero_rows_computed 0x%x\n", i4_non_zero_rows, i4_non_zero_rows_computed);
94 }
95 {
96 WORD32 last_non_zero_row = 32 - CLZ(i4_non_zero_rows);
97 gai4_impeg2d_iqnt_inp_last_non_zero_row_histogram[last_non_zero_row - 1]++;
98 }
99 for(i = 0; i < 8; i++)
100 {
101 for(j = 0; j < 8; j++)
102 {
103 if(pi2_iqnt_inp[i * 8 + j])
104 {
105 i4_last_col = MAX(i4_last_col, j);
106 i4_last_row = MAX(i4_last_row, i);
107 i4_num_non_zero++;
108 }
109 }
110 }
111 gai4_impeg2d_iqnt_inp_last_nonzero_histogram[i4_last_row * 8 + i4_last_col]++;
112 gai4_impeg2d_iqnt_inp_num_nonzero_histogram[i4_num_non_zero]++;
113 gi4_impeg2d_iqnt_cnt++;
114 /* Check if only (0,0) and (7,7) are non zero */
115 if(i4_num_non_zero == 1)
116 {
117 if(pi2_iqnt_inp[7 * 8 + 7])
118 gi4_impeg2d_iqnt_inp_only_last_coeff++;
119 }
120 if(i4_num_non_zero == 1)
121 {
122 if(pi2_iqnt_inp[0])
123 gi4_impeg2d_iqnt_inp_only_first_coeff++;
124 }
125
126 if(i4_num_non_zero == 2)
127 {
128 if((pi2_iqnt_inp[0]) && (1 == pi2_iqnt_inp[7 * 8 + 7]))
129 gi4_impeg2d_iqnt_inp_only_first_n_last_coeff++;
130 }
131 }
132
impeg2d_idct_inp_statistics(WORD16 * pi2_idct_inp,WORD32 i4_non_zero_cols,WORD32 i4_non_zero_rows)133 void impeg2d_idct_inp_statistics(WORD16 *pi2_idct_inp,
134 WORD32 i4_non_zero_cols,
135 WORD32 i4_non_zero_rows)
136 {
137 WORD32 i, j;
138 WORD32 i4_last_row = 0, i4_last_col = 0;
139 WORD32 i4_num_non_zero = 0;
140 WORD32 i4_non_zero_cols_computed = 0;
141 WORD32 i4_non_zero_rows_computed = 0;
142
143 for(i = 0; i < 8; i++)
144 {
145 for(j = 0; j < 8; j++)
146 {
147 if(pi2_idct_inp[i * 8 + j])
148 {
149 i4_non_zero_cols_computed |= (1 << j);
150 i4_non_zero_rows_computed |= (1 << i);
151 }
152 }
153 }
154
155 if(i4_non_zero_cols_computed != i4_non_zero_cols)
156 {
157 printf("IDCT Input: Invalid non_zero_cols 0x%x non_zero_cols_computed 0x%x\n", i4_non_zero_cols, i4_non_zero_cols_computed);
158 }
159 if(i4_non_zero_rows_computed != i4_non_zero_rows)
160 {
161 printf("IDCT Input: Invalid non_zero_rows 0x%x non_zero_rows_computed 0x%x\n", i4_non_zero_rows, i4_non_zero_rows_computed);
162 }
163
164 {
165 WORD32 last_non_zero_row = 32 - CLZ(i4_non_zero_rows);
166 gai4_impeg2d_idct_inp_last_non_zero_row_histogram[last_non_zero_row - 1]++;
167 }
168
169 for(i = 0; i < 8; i++)
170 {
171 for(j = 0; j < 8; j++)
172 {
173 if(pi2_idct_inp[i * 8 + j])
174 {
175 i4_last_col = MAX(i4_last_col, j);
176 i4_last_row = MAX(i4_last_row, i);
177 i4_num_non_zero++;
178 }
179 }
180 }
181 gai4_impeg2d_idct_inp_last_nonzero_histogram[i4_last_row * 8 + i4_last_col]++;
182 gai4_impeg2d_idct_inp_num_nonzero_histogram[i4_num_non_zero]++;
183 gi4_impeg2d_idct_cnt++;
184 /* Check if only (0,0) and (7,7) are non zero */
185 if(i4_num_non_zero == 1)
186 {
187 if(pi2_idct_inp[7 * 8 + 7])
188 gi4_impeg2d_idct_inp_only_last_coeff++;
189 }
190 if(i4_num_non_zero == 1)
191 {
192 if(pi2_idct_inp[0])
193 gi4_impeg2d_idct_inp_only_first_coeff++;
194 }
195
196 if(i4_num_non_zero == 2)
197 {
198 if((pi2_idct_inp[0]) && (1 == pi2_idct_inp[7 * 8 + 7]))
199 gi4_impeg2d_idct_inp_only_first_n_last_coeff++;
200 }
201 }
impeg2d_print_idct_inp_statistics()202 void impeg2d_print_idct_inp_statistics()
203 {
204 WORD32 i, j;
205 WORD32 i4_sum;
206 WORD32 i4_accumulator;
207 i4_sum = 0;
208 for(i = 0; i < 8; i++)
209 {
210 for(j = 0; j < 8; j++)
211 {
212 i4_sum += gai4_impeg2d_idct_inp_last_nonzero_histogram[i * 8 + j];
213 }
214 }
215 printf("IDCT input : Only last coeff non-zero %8.2f\n", (gi4_impeg2d_idct_inp_only_last_coeff * 100.0) / gi4_impeg2d_idct_cnt);
216 printf("IDCT input : Only first coeff non-zero (Includes DC + mismatch) %8.2f\n", (gi4_impeg2d_idct_inp_only_first_coeff * 100.0) / gi4_impeg2d_idct_cnt);
217
218 printf("IDCT input : Last non-zero coeff histogram\n");
219 for(i = 0; i < 8; i++)
220 {
221 for(j = 0; j < 8; j++)
222 {
223 double val = gai4_impeg2d_idct_inp_last_nonzero_histogram[i * 8 + j] * 100.0 / i4_sum;
224 printf("%8.2f \t", val);
225
226 }
227 printf("\n");
228 }
229
230 printf("IDCT input : Cumulative Last non-zero coeff histogram\n");
231 i4_accumulator = 0;
232 for(i = 0; i < 8; i++)
233 {
234 for(j = 0; j < 8; j++)
235 {
236 double val;
237 i4_accumulator += gai4_impeg2d_idct_inp_last_nonzero_histogram[i * 8 + j];
238 val = i4_accumulator * 100.0 / i4_sum;
239
240 printf("%8.2f \t", val);
241
242 }
243 printf("\n");
244 }
245
246
247
248 printf("IDCT input : Number of non-zero coeff histogram\n");
249 i4_sum = 0;
250 for(i = 0; i < 8; i++)
251 {
252 for(j = 0; j < 8; j++)
253 {
254 i4_sum += gai4_impeg2d_idct_inp_num_nonzero_histogram[i * 8 + j];
255 }
256 }
257 for(i = 0; i < 8; i++)
258 {
259 for(j = 0; j < 8; j++)
260 {
261 double val = gai4_impeg2d_idct_inp_num_nonzero_histogram[i * 8 + j] * 100.0 / i4_sum;
262 printf("%8.2f \t", val);
263
264 }
265 printf("\n");
266 }
267
268 printf("IDCT input : Cumulative number of non-zero coeffs histogram\n");
269 i4_accumulator = 0;
270 for(i = 0; i < 8; i++)
271 {
272 for(j = 0; j < 8; j++)
273 {
274 double val;
275 i4_accumulator += gai4_impeg2d_idct_inp_num_nonzero_histogram[i * 8 + j];
276 val = i4_accumulator * 100.0 / i4_sum;
277 printf("%8.2f \t", val);
278
279 }
280 printf("\n");
281 }
282
283 printf("IDCT input : Last non-zero row histogram\n");
284
285
286 {
287 i4_accumulator = 0;
288 for(i = 0; i < 8; i++)
289 {
290 i4_accumulator += gai4_impeg2d_idct_inp_last_non_zero_row_histogram[i];
291 }
292 for(i = 0; i < 8; i++)
293 {
294 double val = gai4_impeg2d_idct_inp_last_non_zero_row_histogram[i] * 100.0 / i4_accumulator;
295 printf("%8.2f \t", val);
296 }
297 printf("\n");
298 }
299
300
301
302
303 }
304
impeg2d_print_iqnt_inp_statistics()305 void impeg2d_print_iqnt_inp_statistics()
306 {
307 WORD32 i, j;
308 WORD32 i4_sum;
309 WORD32 i4_accumulator;
310 i4_sum = 0;
311 for(i = 0; i < 8; i++)
312 {
313 for(j = 0; j < 8; j++)
314 {
315 i4_sum += gai4_impeg2d_iqnt_inp_last_nonzero_histogram[i * 8 + j];
316 }
317 }
318 printf("IQnt input : Only last coeff non-zero %8.2f\n", (gi4_impeg2d_iqnt_inp_only_last_coeff * 100.0) / gi4_impeg2d_iqnt_cnt);
319 printf("IQnt input : Only first coeff non-zero (Includes DC + mismatch) %8.2f\n", (gi4_impeg2d_iqnt_inp_only_first_coeff * 100.0) / gi4_impeg2d_idct_cnt);
320
321 printf("IQnt input : Last non-zero coeff histogram\n");
322 for(i = 0; i < 8; i++)
323 {
324 for(j = 0; j < 8; j++)
325 {
326 double val = gai4_impeg2d_iqnt_inp_last_nonzero_histogram[i * 8 + j] * 100.0 / i4_sum;
327 printf("%8.2f \t", val);
328
329 }
330 printf("\n");
331 }
332
333 printf("IQnt input : Cumulative Last non-zero coeff histogram\n");
334 i4_accumulator = 0;
335 for(i = 0; i < 8; i++)
336 {
337 for(j = 0; j < 8; j++)
338 {
339 double val;
340 i4_accumulator += gai4_impeg2d_iqnt_inp_last_nonzero_histogram[i * 8 + j];
341 val = i4_accumulator * 100.0 / i4_sum;
342
343 printf("%8.2f \t", val);
344
345 }
346 printf("\n");
347 }
348
349
350
351 printf("IQnt input : Number of non-zero coeff histogram\n");
352 i4_sum = 0;
353 for(i = 0; i < 8; i++)
354 {
355 for(j = 0; j < 8; j++)
356 {
357 i4_sum += gai4_impeg2d_iqnt_inp_num_nonzero_histogram[i * 8 + j];
358 }
359 }
360 for(i = 0; i < 8; i++)
361 {
362 for(j = 0; j < 8; j++)
363 {
364 double val = gai4_impeg2d_iqnt_inp_num_nonzero_histogram[i * 8 + j] * 100.0 / i4_sum;
365 printf("%8.2f \t", val);
366
367 }
368 printf("\n");
369 }
370
371 printf("IQnt input : Cumulative number of non-zero coeffs histogram\n");
372 i4_accumulator = 0;
373 for(i = 0; i < 8; i++)
374 {
375 for(j = 0; j < 8; j++)
376 {
377 double val;
378 i4_accumulator += gai4_impeg2d_iqnt_inp_num_nonzero_histogram[i * 8 + j];
379 val = i4_accumulator * 100.0 / i4_sum;
380 printf("%8.2f \t", val);
381
382 }
383 printf("\n");
384 }
385
386 printf("IQnt input : Last non-zero row histogram\n");
387
388
389 {
390 i4_accumulator = 0;
391 for(i = 0; i < 8; i++)
392 {
393 i4_accumulator += gai4_impeg2d_iqnt_inp_last_non_zero_row_histogram[i];
394 }
395 for(i = 0; i < 8; i++)
396 {
397 double val = gai4_impeg2d_iqnt_inp_last_non_zero_row_histogram[i] * 100.0 / i4_accumulator;
398 printf("%8.2f \t", val);
399 }
400 printf("\n");
401 }
402
403 }
404
impeg2d_print_statistics()405 void impeg2d_print_statistics()
406 {
407 impeg2d_print_idct_inp_statistics();
408 impeg2d_print_iqnt_inp_statistics();
409 }
410
411
412 #endif
413
414 #if DEBUG_MB
415
416 static UWORD32 u4_debug_frm = 12;
417 static UWORD32 u4_debug_mb_x = 3;
418 static UWORD32 u4_debug_mb_y = 0;
419
420 static UWORD32 u4_debug_frm_num = 0;
421
422 /*****************************************************************************/
423 /* */
424 /* Function Name : example_of_a_function */
425 /* */
426 /* Description : This function illustrates the use of C coding standards. */
427 /* switch/case, if, for, block comments have been shown */
428 /* here. */
429 /* Inputs : <What inputs does the function take?> */
430 /* Globals : <Does it use any global variables?> */
431 /* Processing : <Describe how the function operates - include algorithm */
432 /* description> */
433 /* Outputs : <What does the function produce?> */
434 /* Returns : <What does the function return?> */
435 /* */
436 /* Issues : <List any issues or problems with this function> */
437 /* */
438 /* Revision History: */
439 /* */
440 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
441 /* 13 07 2002 Ittiam Draft */
442 /* */
443 /*****************************************************************************/
impeg2d_trace_mb_start(UWORD32 u4_mb_x,UWORD32 u4_mb_y)444 void impeg2d_trace_mb_start(UWORD32 u4_mb_x, UWORD32 u4_mb_y)
445 {
446 UWORD32 u4_frm_num = impeg2d_frm_num_get();
447
448 if(u4_frm_num == u4_debug_frm && u4_mb_x == u4_debug_mb_x && u4_mb_y == u4_debug_mb_y)
449 {
450 // printf("");
451 }
452 }
453
454 /*****************************************************************************/
455 /* */
456 /* Function Name : example_of_a_function */
457 /* */
458 /* Description : This function illustrates the use of C coding standards. */
459 /* switch/case, if, for, block comments have been shown */
460 /* here. */
461 /* Inputs : <What inputs does the function take?> */
462 /* Globals : <Does it use any global variables?> */
463 /* Processing : <Describe how the function operates - include algorithm */
464 /* description> */
465 /* Outputs : <What does the function produce?> */
466 /* Returns : <What does the function return?> */
467 /* */
468 /* Issues : <List any issues or problems with this function> */
469 /* */
470 /* Revision History: */
471 /* */
472 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
473 /* 13 07 2002 Ittiam Draft */
474 /* */
475 /*****************************************************************************/
impeg2d_frm_num_set(void)476 void impeg2d_frm_num_set(void)
477 {
478 u4_debug_frm_num++;
479 }
480
481
482 /*****************************************************************************/
483 /* */
484 /* Function Name : example_of_a_function */
485 /* */
486 /* Description : This function illustrates the use of C coding standards. */
487 /* switch/case, if, for, block comments have been shown */
488 /* here. */
489 /* Inputs : <What inputs does the function take?> */
490 /* Globals : <Does it use any global variables?> */
491 /* Processing : <Describe how the function operates - include algorithm */
492 /* description> */
493 /* Outputs : <What does the function produce?> */
494 /* Returns : <What does the function return?> */
495 /* */
496 /* Issues : <List any issues or problems with this function> */
497 /* */
498 /* Revision History: */
499 /* */
500 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
501 /* 13 07 2002 Ittiam Draft */
502 /* */
503 /*****************************************************************************/
impeg2d_frm_num_get(void)504 UWORD32 impeg2d_frm_num_get(void)
505 {
506 return(u4_debug_frm_num);
507 }
508
509 #endif
510